예제 #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 search($params)
 {
     $query = CashdrawerModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id_cashdrawer' => $this->id_cashdrawer, 'client_machine' => $this->client_machine, 'id_branch' => $this->id_branch, 'cashier_no' => $this->cashier_no, 'id_user' => $this->id_user, 'init_cash' => $this->init_cash, 'close_cash' => $this->close_cash, 'variants' => $this->variants, 'status' => $this->status, 'create_at' => $this->create_at, 'create_by' => $this->create_by, 'update_at' => $this->update_at, 'update_by' => $this->update_by]);
     return $dataProvider;
 }
예제 #3
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'];
 }