예제 #1
0
 /**
  * Finds the Cashdrawer model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param  integer               $id
  * @return Cashdrawer            the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Cashdrawer::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 public function actionSavePos()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $post = Yii::$app->request->post();
     try {
         $transaction = Yii::$app->db->beginTransaction();
         $drawer = Cashdrawer::findOne(['id_cashdrawer' => $post['id_drawer']]);
         $hdr = new Sales(['id_cashdrawer' => $post['id_drawer'], 'id_branch' => $drawer->id_branch, 'create_by' => $drawer->id_user]);
         $total = 0.0;
         $dtls = [];
         foreach ($post['detail'] as $detail) {
             $cogs = Cogs::findOne(['id_product' => $detail['id_product']]);
             $dtl = new SalesDtl(['id_product' => $detail['id_product'], 'id_uom' => $detail['id_uom'], 'sales_price' => $detail['price'], 'sales_qty' => $detail['qty'], 'discount' => $detail['discon'], 'cogs' => $cogs ? $cogs->cogs : 0]);
             $total += $detail['qty'] * $detail['price'] * (1 - 0.01 * $detail['discon']);
             $dtls[] = $dtl;
         }
         $transaction->commit();
     } catch (\Exception $exc) {
         $transaction->rollback();
     }
     return ['type' => 'E'];
 }