/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model = SaleSuspended::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionUnsuspendRecv($sale_id) { Yii::app()->receivingCart->clearAll(); Yii::app()->receivingCart->copyEntireSuspendSale($sale_id); SaleSuspended::model()->deleteSale($sale_id); //$this->reload(); $this->redirect('index'); }
public function copyEntireSuspendSale($sale_id) { $this->clearAll(); $sale = SaleSuspended::model()->findbyPk($sale_id); $sale_item = SaleSuspendedItem::model()->getSaleItem($sale_id); $payments = SaleSuspendedPayment::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); }
public function deleteSale($sale_id) { $model = new SaleSuspended(); $transaction = $model->dbConnection->beginTransaction(); try { $sale_suspend = SaleSuspended::model()->findbyPk($sale_id); $sale_suspend->delete(); // use constraint PK on cascade delete no need to select item & payment table $transaction->commit(); } catch (Exception $e) { return -1; $transaction->rollback(); } }