/**
  * 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_invoice]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 2
0
 protected function createInvoice($params)
 {
     $invoice = new Invoice();
     $invoice->id_vendor = $params['id_vendor'];
     $invoice->invoice_date = $params['date'];
     $invoice->invoice_value = $params['value'];
     $invoice->invoice_type = $params['invoice_type'];
     $invoice->due_date = date('Y-m-d', strtotime('+1 month'));
     $invoice->status = 0;
     if (!$invoice->save()) {
         throw new UserException(implode("\n", $invoice->getFirstErrors()));
     }
     $invDtl = new InvoiceDtl();
     $invDtl->id_invoice = $invoice->id_invoice;
     $invDtl->id_reff = $params['id_ref'];
     $invDtl->trans_value = $params['value'];
     if (!$invDtl->save()) {
         throw new UserException(implode("\n", $invDtl->getFirstErrors()));
     }
 }