示例#1
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $state_max_id = \backend\models\State::find()->max('id');
         $state_model_with_max_id = \backend\models\State::findOne($state_max_id);
         if ($this->isNewRecord) {
             $old_shop_state = $state_model_with_max_id->shop_state;
             $new_state = new \backend\models\State();
             $new_state->shop_state = $old_shop_state - $this->revenue;
             $new_state->cash_register_start = $state_model_with_max_id->cash_register_end;
             $new_state->cash_register_end = $state_model_with_max_id->cash_register_end + $this->revenue;
             $new_state->output = $this->revenue;
             $new_state->input = 0;
             $new_state->save();
         } else {
             $updating_model = $state_model_with_max_id;
             $previous_id = \backend\models\State::find()->select('max(id)')->andWhere(['<', 'id', $state_max_id]);
             $previous_model = \backend\models\State::findOne($previous_id);
             $updating_model->shop_state = $previous_model->shop_state - $this->revenue;
             $updating_model->cash_register_start = $previous_model->cash_register_end;
             $updating_model->cash_register_end = $previous_model->cash_register_end + $this->revenue;
             $updating_model->output = $this->revenue;
             $updating_model->input = 0;
             $updating_model->save();
         }
         return true;
     } else {
         return false;
     }
 }
示例#2
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $state_max_id = \backend\models\State::find()->max('id');
         $state_model_with_max_id = \backend\models\State::findOne($state_max_id);
         $old_shop_state = $state_model_with_max_id->shop_state;
         $new_state = new State();
         $new_state->shop_state = $old_shop_state + $this->increment_price;
         $new_state->cash_register_start = $state_model_with_max_id->cash_register_end;
         $new_state->cash_register_end = $state_model_with_max_id->cash_register_end - $this->increment_price;
         $new_state->output = 0;
         $new_state->input = $this->increment_price;
         $new_state->save();
         return true;
     } else {
         return false;
     }
 }
 /**
  * Deletes an existing Orders model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $orders_max_id = \backend\models\Orders::find()->max('id');
     $state_max_id = \backend\models\State::find()->max('id');
     $state_model_with_max_id = \backend\models\State::findOne($state_max_id);
     /*
      * if $state_model_with_max_id->output == 0 , 
      * then the last model in the state table is an order
      * otherwise it would have been a report
      */
     if ($id == $orders_max_id && $state_model_with_max_id->output == 0) {
         /*TRANSACTION*/
         $ordersItems = \backend\models\OrderItems::find()->where(['order_id' => $id])->all();
         //delete order items, then delete the order itself and then delete the last state model
         foreach ($ordersItems as $ordersItem) {
             $ordersItem->delete();
         }
         $this->findModel($id)->delete();
         $state_model_with_max_id->delete();
         /* TRANSACTION*/
         return $this->redirect(['index']);
     } else {
         throw new \yii\web\ForbiddenHttpException('You can NOT delete this order! ' . 'Please, contact the Admin for more information.');
     }
 }
示例#4
0
?>
</title>
        <?php 
$this->head();
?>
    </head>
    <body>
<?php 
$this->beginBody();
?>
        <div class="wrap">
        <?php 
$is_admin = ValueHelpers::getRoleValue('Admin');
if (!Yii::$app->user->isGuest) {
    $state_max_id = \backend\models\State::find()->max('id');
    $state_model_with_max_id = \backend\models\State::findOne($state_max_id);
    $shop_state = number_format($state_model_with_max_id->shop_state);
    NavBar::begin(['brandLabel' => 'Market <i class="fa fa-shopping-cart"></i> Admin &nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-eur"></i>  ' . $shop_state, 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
} else {
    NavBar::begin(['brandLabel' => 'Market <i class="fa fa-shopping-cart"></i>', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
}
if (!Yii::$app->user->isGuest && Yii::$app->user->identity->role_id >= $is_admin) {
    $menuItems[] = ['label' => '', 'url' => ['/site/index'], 'linkOptions' => ['class' => 'fa fa-gears']];
    $menuItems[] = ['label' => '', 'url' => ['user/index'], 'linkOptions' => ['class' => 'fa fa-users']];
    $menuItems[] = ['label' => 'Profiles', 'url' => ['profile/index']];
    $menuItems[] = ['label' => 'Roles', 'url' => ['/role/index']];
    $menuItems[] = ['label' => 'User Types', 'url' => ['/user-type/index']];
    $menuItems[] = ['label' => 'Statuses', 'url' => ['/status/index']];
}
if (Yii::$app->user->isGuest) {
    $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
 /**
  * Deletes an existing Reports model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $report_max_id = Reports::find()->max('id');
     $state_max_id = \backend\models\State::find()->max('id');
     $state_model_with_max_id = \backend\models\State::findOne($state_max_id);
     /*
      * if $state_model_with_max_id->input == 0 , 
      * then the last model in the state table is a report
      * otherwise it would have been an order
      */
     if ($id == $report_max_id && $state_model_with_max_id->input == 0) {
         /*
          * TRANSACTION
          */
         $this->findModel($id)->delete();
         $state_model_with_max_id->delete();
         /*
          * TRANSACTION
          */
         return $this->redirect(['index']);
     } else {
         throw new \yii\web\ForbiddenHttpException('You can NOT delete this report! ' . 'Please, contact the Admin for more information.');
     }
 }