/** * Creates a new InvoiceHdr model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new InvoiceHdr(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_invoice]); } else { return $this->render('create', ['model' => $model]); } }
protected function createInvoice($params) { $invoice = new InvoiceHdr(); $invoice->id_vendor = $params['id_vendor']; $invoice->inv_date = $params['date']; $invoice->inv_value = $params['value']; $invoice->type = $params['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())); } }