/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     try {
         $model = $this->loadModel($id);
         $model->scenario = 'update';
         $model->aModelDetail = $model->rDetail;
         if (!FiInvoice::CanUpdate($model)) {
             $this->redirect(array('index'));
         }
         if (isset($_POST['FiInvoice'])) {
             $model->attributes = $_POST['FiInvoice'];
             if ($model->save()) {
                 FiInvoiceDetail::deleteDetail($model);
                 FiInvoiceDetail::fnUpdateInvoiceId($_POST['FiInvoiceDetail']['id'], $model->id);
                 FiInvoiceDetail::fnUpdateAmount($model);
                 FiInvoice::fnUpdateTotalAmount($model);
                 $this->redirect(array('view', 'id' => $model->id));
                 //                    $this->redirect(array('update','id'=>$model->id));
             }
         }
         $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess));
     } catch (Exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }
Beispiel #2
0
 public function searchMixed()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('t.id', $this->id, true);
     $criteria->compare('t.invoice_no', trim($this->invoice_no), true);
     $criteria->compare('t.transactions_no', trim($this->transactions_no), true);
     $criteria->compare('t.bill_to', $this->bill_to);
     $criteria->compare('t.user_id', $this->user_id, true);
     $criteria->compare('t.user_name', $this->user_name, true);
     $criteria->compare('t.user_billing_address', $this->user_billing_address, true);
     $criteria->compare('t.user_postal_code', $this->user_postal_code, true);
     $criteria->compare('t.total_amount_due', $this->total_amount_due, true);
     $criteria->compare('t.status', $this->status);
     $date_from = '';
     $date_to = '';
     if (!empty($this->date_from)) {
         $date_from = MyFormat::dateConverDmyToYmdForSeach($this->date_from) . " 00:00:00";
     }
     if (!empty($this->date_to)) {
         $date_to = MyFormat::dateConverDmyToYmdForSeach($this->date_to) . " 23:59:00";
     }
     if (!empty($date_from) && empty($date_to)) {
         $criteria->addCondition("t.created_date>='{$date_from}'");
     }
     if (empty($date_from) && !empty($date_to)) {
         $criteria->addCondition("t.created_date<='{$date_to}'");
     }
     if (!empty($date_from) && !empty($date_to)) {
         $criteria->addBetweenCondition("t.created_date", $date_from, $date_to);
     }
     if (!empty($this->keyword)) {
         $criteria->compare('rDetail.description', $this->keyword, true);
         $criteria->with = array('rDetail');
         $criteria->together = true;
     }
     $criteria->order = "t.created_date desc";
     $fiInvoices = static::model()->findAll($criteria);
     $c2 = new CDbCriteria();
     $c2->compare('invoice_number', trim($this->invoice_no), true);
     $c2->compare('invoice_type', ProTransactionsInvoice::TYPE_INVOICE);
     $c2->order = 'created_date desc';
     $invoices = ProTransactionsInvoice::model()->findAll($c2);
     $mixedInvoice = array();
     $f = Yii::app()->format;
     foreach ($fiInvoices as $invoice) {
         $data = array('id' => $invoice->id, 'invoice_no' => $invoice->invoice_no, 'created_date' => $invoice->created_date, 'transactions_no' => $invoice->transactions_no, 'property_address' => $f->formatInvoicePropertyAddress($invoice), 'total_amount_due_gst' => $f->formatPrice($invoice->total_amount_due_gst), 'status' => FiInvoice::$STA_STATUS[$invoice->status], 'receipt' => $f->formatInvoiceGenReceipt($invoice), 'viewUrl' => Yii::app()->createAbsoluteUrl('admin/fiInvoice/view', array('id' => $invoice->id)), 'deleteUrl' => Yii::app()->createAbsoluteUrl('admin/fiInvoice/delete', array('id' => $invoice->id)));
         if (FiInvoice::CanUpdate($invoice)) {
             $data['updateUrl'] = Yii::app()->createAbsoluteUrl('admin/fiInvoice/update', array('id' => $invoice->id));
         }
         $mixedInvoice[] = $data;
     }
     foreach ($invoices as $invoice) {
         $mixedInvoice[] = array('id' => $invoice->id + 200000, 'invoice_no' => $invoice->invoice_number, 'created_date' => $invoice->created_date, 'transactions_no' => $invoice->rTransaction->transactions_no, 'property_address' => $invoice->rTransaction->rPropertyDetail->property_name_or_address, 'total_amount_due_gst' => $f->formatTransactionPropertyPrice($invoice->rTransaction), 'viewUrl' => Yii::app()->createAbsoluteUrl('admin/transactions/viewInvoice', array('id' => $invoice->id)));
     }
     return new CArrayDataProvider($mixedInvoice, array('sort' => array('defaultOrder' => 'created_date DESC', 'attributes' => array('created_date', 'invoice_no')), 'pagination' => array('pageSize' => Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']))));
 }