]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-115 Переработать открытие/закрытие смен у администраторов
authormarina <m.zozirova@gmail.com>
Fri, 19 Jul 2024 07:09:32 +0000 (10:09 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 19 Jul 2024 07:09:32 +0000 (10:09 +0300)
второй и третий шаг

erp24/actions/timetable/StartShiftStepThreeAction.php
erp24/actions/timetable/StartShiftStepTwoAction.php
erp24/records/TimetableFactModel.php
erp24/views/timetable/start_shift_step_three.php
erp24/views/timetable/start_shift_step_two.php

index c677fe6c32959dcaa5e387b0e401b364748d0327..204b470009643db48127a0e63c7aef088332ddee 100755 (executable)
@@ -9,6 +9,7 @@ use yii\web\Response;
 use yii_app\forms\timetable\StartForm;
 use yii_app\records\Admin;
 use yii_app\records\AdminCheckin;
+use yii_app\records\TimetableFactModel;
 
 class StartShiftStepThreeAction extends Action
 {
@@ -35,19 +36,18 @@ class StartShiftStepThreeAction extends Action
             ->andWhere(['id' => $model->checkin_id])
             ->one();
 
-        /** @var AdminCheckin[] $dayCheckins */
-        $dayCheckinsQuery = AdminCheckin::find()
-            ->andWhere(['admin_id' => $userModel->id])
-            ->andWhere(['>', 'time', date('Y-m-d H:i:s', strtotime('-1 day'))]);
-
-        if (!empty($currentCheckin)) {
-            $dayCheckinsQuery->andWhere(['!=', 'id', $model->checkin_id]);
+        //отрабатывает только для открытия
+        $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d'));
+
+        //делается для того что при закрытии нужны дата и время фактического закрытия
+        if (!$fact) {
+            $fact = TimetableFactModel::find()
+                ->andWhere(['admin_id' => $userModel->id])
+                ->andWhere(['date_shift' => date('Y-m-d')])
+                ->andWhere(['is_close' => true])
+                ->orderBy('id desc')
+                ->one();
         }
-        
-        $dayCheckinsQuery->orderBy(['time' => SORT_ASC]);
-
-        $dayCheckins = $dayCheckinsQuery->all();
-        $lastCheckin = end($dayCheckins);
 
         if ($request->isAjax
             &&
@@ -82,7 +82,7 @@ class StartShiftStepThreeAction extends Action
 
         return $this->controller->render('/timetable/start_shift_step_three.php', [
             'userModel' => $userModel,
-            'lastCheckin' => $lastCheckin,
+            'fact' => $fact,
             'currentCheckin' => $currentCheckin,
             'model' => $model,
 
index ef03124331000d5a1d47623b68d2726b36ddb1b3..0cc6fd4e2cb72b7a3ff1e43ae8ffce49b6961631 100755 (executable)
@@ -4,6 +4,7 @@ declare(strict_types = 1);
 namespace yii_app\actions\timetable;
 
 use yii_app\records\AdminGroup;
+use yii_app\records\Timetable;
 use yii_app\records\TimetableFactModel;
 use Yii;
 use yii\base\Action;
@@ -40,7 +41,16 @@ class StartShiftStepTwoAction extends Action
             ->andWhere(['>', 'time', date('Y-m-d H:i:s', strtotime('-1 day'))])
             ->orderBy(['time' => SORT_ASC])
             ->all();
-        $lastCheckin = end($dayCheckins);
+
+        $plan = Timetable::find()
+            ->andWhere(['admin_id' => $userModel->id])
+            ->andWhere([
+                'OR',
+                ['date' => date('Y-m-d')],
+                ['date' => date('Y-m-d', strtotime('-1 day'))],
+            ])
+            ->one();
+        $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d'));
 
         $adminStoreId = null;
 
@@ -61,23 +71,15 @@ class StartShiftStepTwoAction extends Action
         $model->admin_id = $userModel->id;
         $model->d_id = $userModel->group_id;
         $model->ball = 5;
-        $model->shift_id = $request->getBodyParam('shift_id');
-        if (empty($model->store_id)) {
-            $model->store_id = (!empty($adminStoreId)) ? $adminStoreId : $device->store_id;
-        }
         $model->device_id = $device->id;
         $model->time = date('Y-m-d H:i:s');
-        $model->type_id = (function () use ($userModel, $lastCheckin) {
-            if ($userModel->adminGroup->isRoaming()) {
-                return AdminCheckin::TYPE_APPEAR;
-            }
-            if ($lastCheckin && $lastCheckin->isStart()) {
+        $model->type_id = (function () use ($userModel, $fact) {
+            if ($fact) {
                 return AdminCheckin::TYPE_END;
             }
              return AdminCheckin::TYPE_START;
         })();
 
-
         /** @var TimetablePlan[] $planSlots */
         $planSlots = TimetablePlan::find()
             ->andWhere(
@@ -92,13 +94,26 @@ class StartShiftStepTwoAction extends Action
             ])
             ->all();
 
-        if ($lastCheckin && $lastCheckin->isStart()) {
-            $model->plan_id = $lastCheckin->plan_id;
-            $model->replaced_admin_id = $lastCheckin->replaced_admin_id;
-            $model->date = $lastCheckin->date;
-            $model->d_id = $lastCheckin->d_id;
+        $model->shift_id = $request->getBodyParam('shift_id');
+        $model->store_id = $request->getBodyParam('store_id');
+
+        if ($plan) {
+            $model->shift_id = $plan->shift_id;
+            $model->store_id = $plan->store_id;
+        }
+
+        if ($fact) {
+            $model->shift_id = $fact->shift_id;
+            $model->store_id = $fact->store_id;
+        }
+
+        if ($fact) {
+            $model->plan_id = $fact->plan_id;
+            $model->replaced_admin_id = $fact->admin_id_add;
+            $model->date = $fact->date_shift;
+            $model->d_id = $fact->d_id;
         } else {
-            if ($device->isFixedStore() && !$userModel->adminGroup->isRoaming()) {
+            if ($device->isFixedStore()) {
                 /** @var TimetablePlan[] $planSlotsByAdminId */
                 $planSlotsByAdminId = ArrayHelper::index($planSlots, 'admin_id');
                 if (array_key_exists($model->admin_id, $planSlotsByAdminId)) {
@@ -120,10 +135,6 @@ class StartShiftStepTwoAction extends Action
             $model->date = date('Y-m-d');
         }
 
-        $adminStoreArrayPrepared = CityStore::getNames([$model->store_id]);
-        $adminStoreArray = array_values($adminStoreArrayPrepared);
-        $adminStoreName = $adminStoreArray[array_key_first($adminStoreArray)];
-
         if ($this->controller->request->getIsPost() && !$firstRun) {
             $model->load($this->controller->request->post());
             $model->photo = UploadedFile::getInstance($model, 'photo');
@@ -133,11 +144,7 @@ class StartShiftStepTwoAction extends Action
                 $model->checkin_id = $model->checkinModel->id;
                 $model->id = $model->checkinModel->id;
 
-                $is_start = ($model->d_id == AdminGroup::GROUP_ADMINISTRATORS) ?
-                    (count($dayCheckins) % 2 == 0 ? true : false) :
-                    ($model->checkinModel->type_id == AdminCheckin::TYPE_START ? true : false);
-
-                TimetableFactModel::setValues($model, $is_start);
+                TimetableFactModel::setValues($model, empty($fact));
 
                 if ($this->controller->request->getHeaders()->get('Accept') == 'application/json') {
                     $this->controller->response->format = Response::FORMAT_JSON;
@@ -153,10 +160,7 @@ class StartShiftStepTwoAction extends Action
                     'userModel' => $userModel,
                     'model' => $model,
                     'modelId' => $model->id,
-                    'adminStoreName' => $adminStoreName,
                     'device' => $device,
-                    'dayCheckins' => $dayCheckins,
-                    'lastCheckin' => $lastCheckin,
                     'planSlots' => $planSlots,
                 ]);
             }
@@ -165,11 +169,11 @@ class StartShiftStepTwoAction extends Action
         return $this->controller->render('/timetable/start_shift_step_two.php', [
             'userModel' => $userModel,
             'model' => $model,
-            'adminStoreName' => $adminStoreName,
             'device' => $device,
-            'dayCheckins' => $dayCheckins,
-            'lastCheckin' => $lastCheckin,
             'planSlots' => $planSlots,
+            'fact' => $fact,
+            'plan' => $plan,
+            'dayCheckins' => $dayCheckins,
         ]);
     }
 }
\ No newline at end of file
index 5183cd1052253b6bf3957f0979dcfe71c822cb79..8262672f643ef438f16b009ae1528331a63efd2e 100644 (file)
@@ -177,9 +177,13 @@ class TimetableFactModel extends ActiveRecord
      */
     public static function getOpening(int $adminId, $date) {
         return self::find()
-            ->where(['admin_id' => $adminId, 'is_opening' => true])
-            ->andWhere(['date_shift' => $date])
-//            ->andWhere(['status' => array(AdminCheckin::TYPE_START, AdminCheckin::TYPE_APPEAR)])
+            ->andWhere(['admin_id' => $adminId])
+            ->andWhere(['is_opening' => true])
+            ->andWhere([
+                'OR',
+                ['date_shift' => $date],
+                ['date_shift' => date('Y-m-d', strtotime('-1 day'))],
+            ])
             ->orderBy('id desc')
             ->one();
     }
index 1d64232780c100676c2b58a441ce9f7657b3773c..e7535b909620dbe681db804046ddaaf5d8775e0a 100644 (file)
@@ -10,6 +10,7 @@
  * @var AdminCheckin $currentCheckin\r
  * @var string $adminStoreName\r
  * @var TimetablePlan[] $planSlots\r
+ * @var \yii_app\records\TimetableFactModel $fact\r
  */\r
 \r
 \r
@@ -34,25 +35,18 @@ $dateTimeHoursInfo = '';
 $currentCheckinTimeHours = date("H:i", strtotime($currentCheckin->time));\r
 $currentCheckinDate = date("d.m.Y", strtotime($currentCheckin->time));\r
 \r
-if ($userModel->adminGroup->isRoaming()) {\r
-    $textButton = 'Отметится';\r
-    $textInfo = 'Вы успешно отметились';\r
-} else {\r
+if ($fact->is_opening) {\r
     $textButton = 'Открытие смены';\r
     $textInfo = 'Смена успешно открыта';\r
-    if (!empty($lastCheckin)) {\r
-        if ($lastCheckin->isStart()) {\r
-            $textButton = 'Закрытие смены';\r
-            $textInfo = 'Смена успешно закрыта';\r
-            $flowersStyleClass = 'closure-flower';\r
-            $lastCheckinTimeHours = date("d.m.Y H:i", strtotime($lastCheckin->time));\r
-            $dateTimeHoursInfo = $lastCheckinTimeHours . ' - ' . date("H:i d.m.Y", strtotime($currentCheckin->time));\r
-        }\r
-    }\r
+} else {\r
+    $textButton = 'Закрытие смены';\r
+    $textInfo = 'Смена успешно закрыта';\r
+    $flowersStyleClass = 'closure-flower';\r
+    $lastCheckinTimeHours = date("H:i d.m.Y", strtotime($fact->time_start . $fact->date_start));\r
+    $dateTimeHoursInfo = $lastCheckinTimeHours . ' - ' . date("H:i d.m.Y", strtotime($fact->time_end . $fact->date_end));\r
 }\r
 \r
 \r
-\r
 $timeInfo = 1;\r
 ?>\r
     <div class="container background-site-color pb-5">\r
index 8c527b7c8d334ad7102804921b410489145dd38d..73d076a17c3009e84d52e904c3fff995e8e9cba6 100644 (file)
@@ -8,12 +8,14 @@
  * @var AdminCheckin $lastCheckin\r
  * @var string $adminStoreName\r
  * @var TimetablePlan[] $planSlots\r
+ * @var \yii_app\records\TimetableFactModel $fact\r
  */\r
 \r
 use yii\helpers\ArrayHelper;\r
 use yii\helpers\Html;\r
 use yii_app\forms\timetable\StartForm;\r
 use yii_app\records\AdminCheckin;\r
+use yii_app\records\CityStore;\r
 use yii_app\records\Shift;\r
 use yii_app\records\TimetablePlan;\r
 \r
@@ -36,12 +38,12 @@ foreach ($userModel->getStores() as $store) {
         'name' => $store->name,\r
     ];\r
 }\r
-$this->registerJsVar('isRoam', $userModel->adminGroup->isRoaming() || !$device->isFixedStore());\r
+//$this->registerJsVar('isRoam', $userModel->adminGroup->isRoaming() || !$device->isFixedStore());\r
 $this->registerJsVar('settings', [\r
     'planSlots' => $planSlots,\r
     'model' => $model,\r
     'modelPlanSlot' => $model->planSlot,\r
-    'startShiftTime' => $model->isEnd() ? ((int) $lastCheckin->dateTime()->getTimestamp() * 1000) : null,\r
+    'startShiftTime' => $model->isEnd() ? ((int) $fact->time_start * 1000) : null,\r
     'fieldNames' => $formNames,\r
     'stores' => $stores,\r
 ]);\r
@@ -52,17 +54,12 @@ $this->registerJsVar('settings', [
 /** @var AdminCheckin[][] $checkinsByDate */\r
 $checkinsByDate = ArrayHelper::index($dayCheckins, 'type_id', ['date']);\r
 \r
-\r
-\r
 $textButton = '';\r
-if ($userModel->adminGroup->isRoaming()) {\r
-    $textButton = 'Отметится';\r
+\r
+if ($fact) {\r
+    $textButton = 'Закрытие смены';\r
 } else {\r
-    if (!empty($lastCheckin)) {\r
-        $textButton = ($lastCheckin->isStart()) ? 'Закрытие смены' : 'Открытие смены';\r
-    } else {\r
-        $textButton = 'Открытие смены';\r
-    }\r
+    $textButton = 'Открытие смены';\r
 }\r
 \r
 ?>\r
@@ -199,12 +196,12 @@ if ($userModel->adminGroup->isRoaming()) {
                                     <div\r
                                             class="d-flex gap-3 justify-content-left justify-content-lg-start align-items-lg-end"\r
                                     >\r
-                                        <div class="fs-5"><?= $adminStoreName?></div>\r
+                                        <div class="fs-5"><?= $fact->store->name ?? $plan->store->name ?? $model->store->name ?></div>\r
                                     </div>\r
                                     <div\r
                                             class="d-flex gap-3 justify-content-left justify-content-lg-start align-items-lg-end my-3"\r
                                     >\r
-                                        <div class="fs-5"><?= !empty($shift = Shift::findOne($model->shift_id)) ? $shift->name : null?></div>\r
+                                        <div class="fs-5"><?= $fact->shift->name ?? $plan->shift->name ??!empty($model->shift_id) ? Shift::findOne($model->shift_id)->name : null ?></div>\r
                                     </div>\r
                                 </div>\r
                                 </div>\r
@@ -217,8 +214,6 @@ if ($userModel->adminGroup->isRoaming()) {
                                         <button type="submit" id="start_smena" class="btn btn-bd-primary ps-3 pe-3" disabled>\r
                                             <?php if ($model->isStart()) { ?>\r
                                                 Открыть смену\r
-                                            <?php } elseif ($model->isAppear()) { ?>\r
-                                                Отметиться\r
                                             <?php } elseif ($model->isEnd()) { ?>\r
                                                 Закрыть смену\r
                                             <?php } ?>\r