/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Receiving(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Receiving'])) { $model->attributes = $_POST['Receiving']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function saveRevc($items, $payments, $supplier_id, $employee_id, $sub_total, $total, $comment, $trans_mode, $discount_amount, $discount_type) { if (count($items) == 0) { return '-1'; } $model = new Receiving(); $payment_types = ''; foreach ($payments as $payment_id => $payment) { $payment_types = $payment_types . $payment['payment_type'] . ': ' . $payment['payment_amount'] . '<br />'; } $transaction = $model->dbConnection->beginTransaction(); try { $model->supplier_id = $supplier_id; $model->employee_id = $employee_id; $model->payment_type = $payment_types; $model->remark = $comment; $model->sub_total = $sub_total; $model->status = $this->transactionHeader(); $model->discount_amount = $discount_amount === null ? 0 : $discount_amount; $model->discount_type = $discount_type === null ? '%' : $discount_type; if ($model->save()) { $receiving_id = $model->id; $trans_date = date('Y-m-d H:i:s'); // Saving & Updating Account and Account Receivable either transaction 'receive' or 'return' $this->saveAccountAR($employee_id, $receiving_id, $supplier_id, $total, $trans_date, $trans_mode); // Saving receiving item to receiving_item table $this->saveReceiveItem($items, $receiving_id, $employee_id, $trans_date); $message = $receiving_id; $transaction->commit(); } } catch (Exception $e) { $transaction->rollback(); $message = '-1' . $e; } return $message; }