]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-175 Исправить ошибки ворк-бота
authormarina <m.zozirova@gmail.com>
Tue, 17 Sep 2024 14:02:22 +0000 (17:02 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 17 Sep 2024 14:02:22 +0000 (17:02 +0300)
erp24/api3/core/services/TimetableService.php
erp24/api3/modules/v1/controllers/timetable/PlanController.php
erp24/records/TimetableFactModel.php

index 59e859f3f21d4fd85b4392d7be272223baefcea3..197e4047fa759aacb2f10d3f8216fdddcea81f31 100644 (file)
@@ -131,37 +131,17 @@ class TimetableService
     {
         /** @var $data Fact */
 
-        if ($data->plan_id) {
-            $timetable = Timetable::findOne(['plan_id' => $data->plan_id, 'tabel' => 1]);
-            if (!$timetable) {
-                throw new NotFoundHttpException("Факт не найден");
-            }
-        }
+        $fact = TimetableFactModel::getLast($data->admin_id, date('Y-m-d'));
 
         $currentDate = date('Y-m-d H:i:s');
-        $admin_id = $data->plan_id ? $timetable->admin_id : $data->admin_id;
+        $admin_id = $data->admin_id;
 
-        //убрать после согласования оплаты подработчиков
-        if (Admin::findOne($admin_id)->group_id === AdminGroup::GROUP_WORKERS && !$data->plan_id) {
-            throw new \InvalidArgumentException('Подработчики не могут открыть смены без плана!');
-        }
-
-        $checkInFirst = $data->plan_id ?
-            AdminCheckin::find()->where(['plan_id' => $timetable->plan_id])->orderBy(['time' => SORT_ASC])->one() :
-            AdminCheckin::find()->where(['admin_id' => $admin_id])->orderBy(['id' => SORT_DESC])->one();
+        $checkInFirst = AdminCheckin::findOne($fact->checkin_start_id);
 
         if ($checkInFirst && (strtotime($checkInFirst->time) + 60 * 60 > strtotime($currentDate))) {
             throw new InvalidArgumentException("Между началом и концом смены должно пройти минимум один час");
         }
 
-        if ($data->plan_id) {
-            $timetable->datetime_end = $currentDate;
-            $timetable->save();
-            if ($timetable->getErrors()) {
-                throw new \Exception(Json::encode($timetable->getErrors()));
-            }
-        }
-
         $imagePath = $data->uploadImage($admin_id);
         if (!$imagePath) {
             throw new InvalidArgumentException("Не удалось загрузить картинку");
@@ -169,28 +149,17 @@ class TimetableService
 
         $checkIn = new AdminCheckin();
 
-        if ($data->plan_id) {
-            $checkIn->plan_id = $timetable->plan_id;
-            $checkIn->store_id = $timetable->store_id;
-            $checkIn->d_id = $timetable->admin->group_id;
-            $checkIn->date = $timetable->date;
-        } else {
-
-            //остается буквально на день чтобы не посыпались ошибки из-за открытых смен до выката функционала
-            $plan = Timetable::find()
-                ->andWhere(['admin_id' => $admin_id])
-                ->andWhere(['between', 'date', date('Y-m-d', strtotime('-1 day')), date('Y-m-d')])
-                ->andWhere(['tabel' => 1])
-                ->orderBy('id desc')
-                ->one();
-            $checkIn->shift_id = !empty($plan) ? $plan->shift_id : null;
-
-            $checkIn->plan_id = null;
-            $checkIn->store_id = $checkInFirst->store_id;
-            $checkIn->d_id = $checkInFirst->d_id;
-            $checkIn->date = $checkInFirst->date;
-        }
-
+        $timetable = Timetable::find()
+            ->andWhere(['admin_id' => $admin_id])
+            ->andWhere(['between', 'date', date('Y-m-d', strtotime('-1 day')), date('Y-m-d')])
+//            ->andWhere(['tabel' => 1])
+            ->orderBy('id desc')
+            ->one();
+
+        $checkIn->plan_id = $timetable->plan_id;
+        $checkIn->store_id = $timetable->store_id;
+        $checkIn->d_id = $timetable->admin->group_id;
+        $checkIn->date = $timetable->date;
         $checkIn->ball = 5;
         $checkIn->comment = "";
         $checkIn->admin_id = $admin_id;
index 51e920a4cde7fc4aec80e8817a38f3a1ffa516da..2ae7b68e7c128a36fd8dc32b4fbefd8a4eaeea3b 100644 (file)
@@ -19,7 +19,7 @@ class PlanController extends \yii_app\api3\controllers\ActiveController
 {
     use ServiceTrait;
 
-//    public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class;
+
     public $modelClass = TimetableFactModel::class;
 
 
@@ -32,11 +32,22 @@ class PlanController extends \yii_app\api3\controllers\ActiveController
             'pageSizeLimit' => [1, 50],
         ];
 
+        $request = Yii::$app->request->post()['filter'];
+
+        $fact = TimetableFactModel::find()
+            ->andWhere(['admin_id' => $request['admin_id']])
+            ->andWhere(['date_shift' => $request['date']])
+            ->one();
+
+        if (true) {
+            $this->modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class;
+        }
+
         $actions['index']['dataFilter'] = [
             'class' => \yii\data\ActiveDataFilter::class,
-            'searchModel' => $this->modelClass
+            'searchModel' => $actions['index']['modelClass']
         ];
-
+        var_dump($actions['index']);die();
         unset($actions['delete']);
 
         return $actions;
index fb95f1d5183f9520b4a1346017668649f3d6ffc9..6c0c56bd300c36e0ef89b1f2bc8a25aade5b618c 100644 (file)
@@ -201,7 +201,7 @@ class TimetableFactModel extends ActiveRecord
             'salary_shift',
             // 'price' => fn($x) => $x->shift_id == 2 ? 140 : 125,
             'tabel',
-            'date_shift',
+            'date' => fn($x) => $x->date_shift,
             'date_start' =>  fn($x) => $x->date_start . ' ' .$x->time_start,
             'date_end' => fn($x) => !empty($x->date_end) ? $x->date_end . ' ' .$x->time_end : null,
             'time_start',