]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Bug zozirova erp 175 fixes for tg bot
authorMarina Zozirova <marina.zozirova@erp-flowers.ru>
Wed, 18 Sep 2024 09:34:26 +0000 (09:34 +0000)
committerAleksey Filippov <aleksey.filippov@erp-flowers.ru>
Wed, 18 Sep 2024 09:34:26 +0000 (09:34 +0000)
erp24/api3/core/services/TimetableService.php
erp24/api3/modules/v1/controllers/timetable/FactController.php
erp24/api3/modules/v1/controllers/timetable/PlanController.php
erp24/api3/modules/v1/models/timetable/Timetable.php
erp24/records/AdminCheckin.php
erp24/records/TimetableFactModel.php

index 59e859f3f21d4fd85b4392d7be272223baefcea3..a4a04520f90131045e65421632d008c80390b778 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,10 @@ 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;
-        }
-
+        $checkIn->plan_id = $fact->plan_id;
+        $checkIn->store_id = $fact->store_id;
+        $checkIn->d_id = $fact->admin->group_id;
+        $checkIn->date = $fact->date_shift;
         $checkIn->ball = 5;
         $checkIn->comment = "";
         $checkIn->admin_id = $admin_id;
index 6585682a869f5bbca7d8f1030d6d74622c21d9ee..93de0f5a464accd98cac55e53731dd2d42e66ff4 100644 (file)
@@ -7,6 +7,7 @@ use yii_app\api3\controllers\ActiveController;
 use yii_app\api3\core\services\TimetableService;
 use yii_app\api3\core\traits\ServiceTrait;
 use yii_app\api3\modules\v1\requests\timetable\Fact;
+use yii_app\records\TimetableFactModel;
 
 /**
  * @property TimetableService $timetableService
@@ -15,7 +16,7 @@ class FactController extends ActiveController
 {
     use ServiceTrait;
 
-    public $modelClass = \yii_app\api3\modules\v1\requests\timetable\Fact::class;
+    public $modelClass = TimetableFactModel::class;
 
     public function actions()
     {
index 617d8c3123d129d747a0db37fa96d3dace00c5f8..4508a23da6c6766c0509d7f000784b340e46c0b4 100644 (file)
@@ -19,8 +19,8 @@ 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;
+
+    public $modelClass = Timetable::class;
 
 
     public function actions()
@@ -34,7 +34,7 @@ class PlanController extends \yii_app\api3\controllers\ActiveController
 
         $actions['index']['dataFilter'] = [
             'class' => \yii\data\ActiveDataFilter::class,
-            'searchModel' => $this->modelClass
+            'searchModel' => $this->modelClass,
         ];
 
         unset($actions['delete']);
index e380916d308baf8a73a391f21d0ed4ff1a4cb892..c9681b24954a987f33be13436d8b7889aa3224d7 100644 (file)
@@ -182,19 +182,11 @@ class Timetable extends \yii_app\records\TimetableV3
     {
         return $this->hasOne(CityStore::class, ['id' => 'store_id']);
     }
-
-    public function getCheckIns()
-    {
-        return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])
-            ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s', strtotime('+6 hour'))]);
-
+    public function getCheckIns() {
+        return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']);
     }
 
-    public function getCheckInCount()
-    {
-        return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])
-            ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))])
-            ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')])->count();
-
+    public function getCheckInCount() {
+        return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count();
     }
 }
\ No newline at end of file
index 91f32ea73ab58dc484c103bd0017beac91bd81f4..329b2e83d59ea5886d178b80c2823142b1a9eac8 100755 (executable)
@@ -87,9 +87,9 @@ class AdminCheckin extends ActiveRecord
     public function rules()
     {
         return [
-            [['admin_id', 'device_id', 'replaced_admin_id', 'plan_id', 'store_id', 'type_id', 'd_id', 'ball', 'status'], 'integer'],
+            [['admin_id', 'device_id', 'replaced_admin_id', 'store_id', 'type_id', 'd_id', 'ball', 'status'], 'integer'],
             [['lat', 'lon'], 'double'],
-            [['shift_id'], 'safe'],
+            [['shift_id', 'plan_id'], 'safe'],
             [['comment', 'photo'], 'string'],
             [['date'], 'date', 'format' => 'yyyy-M-d'],
 //            [['time'], 'date', 'format' => 'yyyy-M-d HH:mm:ss'],
index 0fc5a00706aefb3c5369aacf59f75a6d4d885093..6c0c56bd300c36e0ef89b1f2bc8a25aade5b618c 100644 (file)
@@ -191,6 +191,51 @@ class TimetableFactModel extends ActiveRecord
             ->one();
     }
 
+    public function fields()
+    {
+        $fields = [
+            'id',
+            'admin_id',
+            'store_id',
+            'shift_id',
+            'salary_shift',
+            // 'price' => fn($x) => $x->shift_id == 2 ? 140 : 125,
+            'tabel',
+            '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',
+            'time_end',
+            'work_time',
+            'status',
+            'checkInCount',
+            'can_open' => fn($x) => $this->is_opening === false && $this->is_close === true,
+        ];
+
+        return $fields;
+    }
+
+    public function extraFields()
+    {
+        return [
+            'admin' => fn($x) => [
+                'id' => $x->admin->id,
+                'name' => $x->admin->name,
+                'guid' => $x->admin->guid,
+                'group' => [
+                    'id' => $x->admin->group_id,
+                    'name' => $x->admin->group_name,
+                ],
+            ],
+            'store' => fn($x) => [
+                'id' => $x->store->id,
+                'name' => $x->store->name,
+                'name_full' => $x->store->name_full,
+            ],
+            'checkIns'
+        ];
+    }
+
     public function getCheckIns()
     {
         return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])