/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($invoice_id, $invoice_number, $amount) { //$this->layout = '//layouts/print'; //$model=$this->loadModel($invoice_id); $model = InvoicePayment::model()->find('invoice_id=:invoiceID', array(':invoiceID' => $invoice_id)); if ($model === null) { $model = new InvoicePayment(); $model->invoice_id = $invoice_id; $model->invoice_number = $invoice_number; $model->date_paid = date('Y-m-d'); } $model->amount = $amount; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['InvoicePayment'])) { $model->attributes = $_POST['InvoicePayment']; if ($model->save()) { if (Yii::app()->request->isAjaxRequest) { Yii::app()->clientScript->scriptMap['jquery.js'] = false; echo CJSON::encode(array('status' => 'success', 'div' => "<div class=alert alert-info fade in> Successfully added ! </div>")); Yii::app()->end(); } else { $this->redirect(array('invoice/admin')); } } } if (Yii::app()->request->isAjaxRequest) { $cs = Yii::app()->clientScript; $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false); echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, true))); Yii::app()->end(); } else { $this->render('create', array('model' => $model)); } }
/** * Update existing payment * * @param void * @return null */ function edit() { if ($this->active_invoice->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($this->active_invoice_payment->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_invoice_payment->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $invoice_payment_data = $this->request->post('invoice_payment'); if (!is_array($invoice_payment_data)) { $invoice_payment_data = array('amount' => $this->active_invoice_payment->getAmount(), 'paid_on' => $this->active_invoice_payment->getPaidOn(), 'comment' => $this->active_invoice_payment->getComment()); } // if $this->smarty->assign('invoice_payment_data', $invoice_payment_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_amount = $this->active_invoice_payment->getAmount(); $this->active_invoice_payment->setAttributes($invoice_payment_data); $this->active_invoice_payment->setAmount($old_amount); // don't allow overwrite $this->active_invoice_payment->setInvoiceId($this->active_invoice->getId()); $save = $this->active_invoice_payment->save(); if ($save && !is_error($save)) { db_commit(); flash_success('Payment #:id has been updated', array('id' => $this->active_invoice_payment->getId())); $this->redirectToUrl($this->active_invoice->getViewUrl()); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } // if }