/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($recv_mode = 'N', $trans_mode = null)
 {
     $model = new Supplier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (Yii::app()->user->checkAccess('supplier.create')) {
         if (isset($_POST['Supplier'])) {
             $model->attributes = $_POST['Supplier'];
             if ($model->validate()) {
                 $transaction = Yii::app()->db->beginTransaction();
                 try {
                     if ($model->save()) {
                         AccountSupplier::model()->saveAccount($model->id, $model->company_name);
                         $transaction->commit();
                         if ($recv_mode == 'N') {
                             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Supplier : <strong>' . $model->company_name . '</strong> have been saved successfully!');
                             $this->redirect(array('create'));
                         } else {
                             Yii::app()->receivingCart->setSupplier($model->id);
                             $this->redirect(array('receivingItem/index', 'trans_mode' => $trans_mode));
                         }
                         /*
                         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();
                          * 
                         */
                     }
                 } catch (CDbException $e) {
                     $transaction->rollback();
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_WARNING, 'Oop something wrong : <strong>' . $e->getMessage());
                 }
             }
         }
     } else {
         throw new CHttpException(403, 'You are not authorized to perform this action');
     }
     if (Yii::app()->request->isAjaxRequest) {
         Yii::app()->clientScript->scriptMap['*.js'] = false;
         echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, false)));
         Yii::app()->end();
     } else {
         $this->render('create', array('model' => $model));
     }
 }
示例#2
0
 public static function getAccountInfo($supplier_id)
 {
     return AccountSupplier::model()->find('supplier_id=:supplier_id', array(':supplier_id' => $supplier_id));
 }
 protected function sessionInfo($data = array())
 {
     $model = new ReceivingPayment();
     $data['model'] = $model;
     $data['supplier_id'] = Yii::app()->rpaymentCart->getSupplierId();
     $data['employee_id'] = Yii::app()->session['employeeid'];
     if ($data['supplier_id'] !== null) {
         $account = AccountSupplier::model()->getAccountInfo($data['supplier_id']);
         $data['account'] = $account;
         $data['balance'] = $account->current_balance;
         $supplier = Supplier::model()->findbyPk($data['supplier_id']);
         $data['fullname'] = $supplier->company_name . ' [ ' . $supplier->first_name . ' ' . $supplier->last_name . ' ] ';
         $data['save_button'] = false;
     } else {
         $data['fullname'] = '';
         $data['balance'] = 0;
         $data['save_button'] = true;
     }
     return $data;
 }
示例#4
0
 protected function updateAccount($supplier_id, $purchase_amount)
 {
     $account = AccountSupplier::model()->find('supplier_id=:supplier_id', array(':supplier_id' => (int) $supplier_id));
     if ($account) {
         $account->current_balance = $account->current_balance + $purchase_amount;
         $account->save();
     }
     return $account;
 }
示例#5
0
 public function batchPayment($supplier_id, $employee_id, $account, $total_paid, $paid_date, $note)
 {
     $sql = "SELECT receive_id,receive_time,supplier_name,amount_to_paid\n                FROM (\n                    SELECT t1.receive_id,receive_time,supplier_name,(t1.`sub_total`-IFNULL(t2.payment_amount,0)) amount_to_paid\n                    FROM\n                    (SELECT r.id receive_id,r.`receive_time`,CONCAT(s.first_name,' ',last_name) supplier_name,r.`sub_total`\n                        FROM `receiving` r, `supplier` s\n                        WHERE r.`supplier_id` = s.id\n                        AND s.id=:supplier_id) t1 LEFT JOIN `v_receiving_payment` t2 ON t2.receive_id=t1.receive_id\n                    ) AS t\n                WHERE amount_to_paid>0\n                ORDER BY receive_time";
     $result = Yii::app()->db->createCommand($sql)->queryAll(true, array(':supplier_id' => $supplier_id));
     $paid_amount = $total_paid;
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $payment_id = PaymentHistoryRecv::model()->savePaymentHistory($supplier_id, $total_paid, $paid_date, $employee_id, $note);
         foreach ($result as $record) {
             if ($paid_amount <= $record["amount_to_paid"]) {
                 $payment_amount = $paid_amount;
                 $this->saveReceivePayment($record["receive_id"], $payment_id, $payment_amount, $paid_date, $note);
                 $this->saveAccountRecv($account->id, $employee_id, $record["receive_id"], $payment_amount, $paid_date, $note);
                 break;
             } else {
                 $paid_amount = $paid_amount - $record["amount_to_paid"];
                 $payment_amount = $record["amount_to_paid"];
                 $this->saveReceivePayment($record["receive_id"], $payment_id, $payment_amount, $paid_date, $note);
                 $this->saveAccountRecv($account->id, $employee_id, $record["receive_id"], $payment_amount, $paid_date, $note);
             }
         }
         AccountSupplier::model()->updateAccountBal($account, $total_paid);
         $transaction->commit();
         $message = $payment_id;
     } catch (Exception $e) {
         $transaction->rollback();
         $message = '-1' . $e->getMessage();
     }
     return $message;
 }