/**
  * Creates a new EntpInvoice model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Invoice();
     //$model = new NewInvoice();
     if ($model->load(Yii::$app->request->post())) {
         //            if ($invoice = $model->addInvoice()) {
         //                Yii::$app->session->setFlash('success','New Invoice Added');
         //                return $this->redirect(['index']);
         //                //return $this->goHome();
         //            }
         $model->loadDefaultValues();
         $model->save();
         if ($model->save()) {
             $invoice = new EntpInvoice();
             $invoice->entrepreneur_user_id = Yii::$app->user->id;
             $invoice->link('invoice', $model);
         }
         Yii::$app->session->setFlash('success', 'New Invoice Added');
         //return $this->redirect(['index']);
         //
         return $this->redirect(['view', 'entrepreneur_user_id' => Yii::$app->user->id, 'invoice_id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 /**
  * Creates a new Invoice model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Invoice();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #3
0
 /**
  * Creates a new Invoice model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param integer $id  The Current Invoice ID to create the new invoice from
  * @return mixed
  */
 public function actionCreate($id)
 {
     $currentInvoice = $this->findModel($id, false);
     $ticketsIds = ArrayHelper::getColumn($currentInvoice->getTickets()->closed(true)->all(), 'id');
     $billableLaborTotal = Labor::find()->ticket($ticketsIds)->hourly()->total(true);
     $purchaseTotal = PurchasedItem::find()->ticket($ticketsIds)->total();
     $travelFeeTotal = Travel::find()->invoice($id)->before()->totalFee();
     $model = new Invoice();
     $model->loadDefaultValues();
     $model->location_id = $currentInvoice->location_id;
     $model->total = $billableLaborTotal + $purchaseTotal + $travelFeeTotal;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Ticket::updateAll(['invoice_id' => $model->id], ['id' => $ticketsIds]);
         Schedule::updateAll(['invoice_id' => $model->id], ['and', 'invoice_id=:invoice_id', 'start_time<:start_time'], [':invoice_id' => $model->location_id, ':start_time' => date(Invoice::BILLING_CUTOFF_DAY)]);
         return $this->redirect(['view', 'id' => $model->id]);
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     }
     return $this->render('create', ['model' => $model]);
 }