/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return SalePayment the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SalePayment::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function copyEntireSuspendSale($sale_id) { $this->clearAll(); $sale = Sale::model()->findbyPk($sale_id); $sale_item = SaleItem::model()->getSaleItem($sale_id); $payments = SalePayment::model()->getPayment($sale_id); foreach ($sale_item as $row) { if ($row->discount_type == '$') { $discount_amount = $row->discount_type . $row->discount_amount; } else { $discount_amount = $row->discount_amount; } $this->addItem($row->item_id, $row->quantity, $discount_amount, $row->price, $row->description); } foreach ($payments as $row) { $this->addPayment($row->payment_type, $row->payment_amount); } $this->setCustomer($sale->client_id); $this->setComment($sale->remark); $this->setTotalDiscount($sale->discount_amount); $this->setSaleId($sale_id); }
public function getPayment($sale_id) { $model = SalePayment::model()->findAll('sale_id=:saleId', array(':saleId' => (int) $sale_id)); return $model; }
public function saveSale($in_sale_id, $items, $payments, $payment_received, $customer_id, $employee_id, $sub_total, $total, $comment, $status = self::sale_complete_status, $discount_amount, $discount_symbol, $gst_amount, $sale_rep_id) { if (count($items) == 0) { return '-1'; } $message = ""; //Check if invoice already exists $model = Sale::model()->findSale($in_sale_id); $payment_types = ''; foreach ($payments as $payment_id => $payment) { $payment_types = $payment_types . $payment['payment_type'] . ': ' . $payment['payment_amount'] . '<br />'; } $transaction = Yii::app()->db->beginTransaction(); try { // Transaction Date for Inventory, Payment and sale trans date $trans_date = date('Y-m-d H:i:s'); // Getting Customer Account Info $account = Account::model()->getAccountInfo($customer_id); $old_total = $this->getOldSaleTotal($in_sale_id); //Rolling back the Sale Total of old / previous Sale & Saving Change / Edit Sale into [account receivable] table if ($account && $in_sale_id) { AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $in_sale_id, -$old_total, $trans_date, 'Edit Sale', 'CHASALE', 'R'); Account::model()->withdrawAccountBal($account, $old_total); } //Saving existing Sale Item to Inventory table and removing it out $this->updateSale($in_sale_id, $employee_id, $trans_date); $model->client_id = $customer_id; $model->employee_id = $employee_id; $model->payment_type = $payment_types; $model->remark = $comment; $model->sub_total = $sub_total; $model->status = $status; $model->discount_amount = $discount_amount === null ? 0 : $discount_amount; $model->discount_type = $discount_symbol === null ? '%' : $discount_symbol; $model->vat = $gst_amount == null ? 0 : $gst_amount; $model->salerep_id = $sale_rep_id; if ($model->save()) { $sale_id = $model->id; $date_paid = $trans_date; $trans_code = 'CHSALE'; $trans_status = $total > 0 ? 'N' : 'R'; // If Return Sale Transaction Type = 'CHSALE' same but Transaction Status = 'R' reverse // Saving Sale Item (Sale & Sale Item gotta save firstly even for Suspended Sale) $this->saveSaleItem($items, $sale_id, $employee_id); // We only save Sale Payment, Account Receivable transaction and update Account (outstanding balance) of completed sale transaction if ($status == self::sale_complete_status) { //$account = Account::model()->getAccountInfo($customer_id); if ($account) { // Add hot bill before proceed payment Account::model()->depositAccountBal($account, $total); SalePayment::model()->batchPayment($customer_id, $employee_id, $account, $payment_received, $date_paid, $comment); //Saving Account Receivable for Sale transaction code = 'CHSALE' AccountReceivable::model()->saveAccountRecv($account->id, $employee_id, $sale_id, $total, $trans_date, $comment, $trans_code, $trans_status); } else { // If no customer selected only Sale Payment History PaymentHistory::model()->savePaymentHistory($customer_id, $payment_received, $date_paid, $employee_id, $comment); } } $message = $sale_id; $transaction->commit(); } } catch (Exception $e) { $transaction->rollback(); $message = '-1' . $e->getMessage(); } return $message; }
public function actionsavePayment() { $data = $this->sessionInfo(); if (Yii::app()->user->checkAccess('payment.index')) { if (isset($_POST['SalePayment'])) { $data['model']->attributes = $_POST['SalePayment']; if ($data['model']->validate()) { $paid_amount = $_POST['SalePayment']['payment_amount']; $paid_date = Date('Y-m-d H:i:s'); //$_POST['SalePayment']['date_paid']; $note = $_POST['SalePayment']['note']; if ($paid_amount <= $data['balance']) { $data['payment_id'] = SalePayment::model()->batchPayment($data['client_id'], $data['employee_id'], $data['account'], $paid_amount, $paid_date, $note); if (substr($data['payment_id'], 0, 2) == '-1') { $data['warning'] = $data['payment_id']; } else { $data = $this->sessionInfo(); $data['warning'] = $data['cust_fullname'] . ' Successfully paid '; $this->renderPartial('_payment_success', $data); //$this->redirect(array('salePayment/successPayment','cust_fullname'=>$data['cust_ful'])); //Yii::app()->paymentCart->clearAll(); exit; } } else { $data['model']->addError('payment_amount', Yii::t('app', 'Total amount to paid is only') . ' <strong>' . number_format($data['balance'], Yii::app()->shoppingCart->getDecimalPlace()) . '</strong>'); } } } } else { throw new CHttpException(403, 'You are not authorized to perform this action'); } if (Yii::app()->request->isAjaxRequest) { Yii::app()->clientScript->scriptMap['*.js'] = false; Yii::app()->clientScript->scriptMap['jquery-ui.css'] = false; Yii::app()->clientScript->scriptMap['box.css'] = false; $this->renderPartial('_payment', $data, false, true); } else { $this->render('_payment', $data); } }