/** * 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]); } }
public function record() { $user = Yii::$app->session->get('user'); $invoice = Invoice::findApplyingByUser($user['userId']); if ($invoice) { return false; } $invoice = new Invoice(); $user = Yii::$app->session->get('user'); $invoice->userId = $user['userId']; $invoice->money = $this->money; $invoice->address = $user['address']; $invoice->createDate = DateFunctions::getCurrentDate(); $invoice->state = Invoice::STATE_ING; $invoice->address = $this->address; if (!$invoice->save()) { throw new Exception("Invoice save error"); } return true; }
public function record() { $user = Yii::$app->session->get('user'); $invoice = Invoice::findApplyingByUser($user['userId']); if ($invoice) { CommonFunctions::createAlertMessage("发票申请失败,您已经有正在申请中的发票了,一次只能申请一张", "error"); return false; } else { $invoice = new Invoice(); $invoice->userId = $user['userId']; $invoice->address = $this->address; $invoice->money = $this->money; $invoice->description = $this->description; $invoice->createDate = DateFunctions::getCurrentDate(); $invoice->state = Invoice::STATE_ING; if (!$invoice->save()) { throw new Exception("Apply Invoice save error"); } return true; } }
public function addInvoice() { if ($this->validate()) { $invoice = new Invoice(); $invoice->invoice_no = $this->invoice_no; $invoice->due_date = $this->due_date; $invoice->bank_name = $this->bank_name; $invoice->account_no = $this->account_no; $invoice->customer = $this->customer; $invoice->address = $this->address; $invoice->telephone = $this->telephone; $invoice->fax = $this->fax; $invoice->pic = $this->pic; $invoice->mobile = $this->mobile; if ($invoice->save()) { $entpinvoice = new EntpInvoice(); $entpinvoice->entrepreneur_user_id = Yii::$app->user->id; $entpinvoice->link('invoice', $invoice); } return $invoice; } return null; }
public function save() { $invoice = Invoice::findOne(['id' => $this->id]); if (empty($invoice)) { $invoice = new Invoice(); $invoice->user_id = $this->user_id; $invoice->status = $this->status; $invoice->data = json_encode($this->data); $invoice->payment_type = $this->payment_type; $invoice->currency = $this->currency; $invoice->total = $this->total; $invoice->delivery_address = $this->delivery_address; Yii::getLogger()->log('save:', YII_DEBUG); if ($invoice->save()) { $this->id = $invoice->id; return $invoice; } else { Yii::getLogger()->log('save error', YII_DEBUG); } } else { $invoice->user_id = $this->user_id; $invoice->status = $this->status; $invoice->data = json_encode($this->data); $invoice->payment_type = $this->payment_type; $invoice->currency = $this->currency; $invoice->total = $this->total; $invoice->delivery_address = $this->delivery_address; Yii::getLogger()->log('update:', YII_DEBUG); if ($invoice->update()) { return $invoice; } else { Yii::getLogger()->log('update error:' . print_r($invoice, true), YII_DEBUG); } } return null; }
/** * 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]); } }
/** * 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]); }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if ($insert || empty($this->currentInvoice)) { $invoice = new Invoice(['scenario' => Invoice::SCENARIO_CURRENT, 'location_id' => $this->id]); $invoice->save(); } }