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

index 9501da653724ebc094d1f41a0eb8ad0625c4aeff..51e920a4cde7fc4aec80e8817a38f3a1ffa516da 100644 (file)
@@ -5,9 +5,12 @@ namespace yii_app\api3\modules\v1\controllers\timetable;
 use Yii;
 use yii\base\DynamicModel;
 use yii\db\Expression;
+use yii\helpers\Json;
 use yii_app\api3\core\exceptions\ErrorException;
 use yii_app\api3\core\services\TimetableService;
 use yii_app\api3\core\traits\ServiceTrait;
+use yii_app\api3\modules\v1\models\timetable\Timetable;
+use yii_app\records\TimetableFactModel;
 
 /**
  * @property TimetableService $timetableService
@@ -16,13 +19,14 @@ class PlanController extends \yii_app\api3\controllers\ActiveController
 {
     use ServiceTrait;
 
-    public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class;
+//    public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class;
+    public $modelClass = TimetableFactModel::class;
+
 
     public function actions()
     {
         $actions = parent::actions();
 
-        // $actions['index']['sort'] = ['defaultOrder' => ['date' => SORT_ASC]];
         $actions['index']['pagination'] = [
             'defaultPageSize' => 50,
             'pageSizeLimit' => [1, 50],
@@ -33,14 +37,6 @@ class PlanController extends \yii_app\api3\controllers\ActiveController
             'searchModel' => $this->modelClass
         ];
 
-        /*$actions['index']['prepareSearchQuery'] = function($query, $requestParams) {
-            if(isset($requestParams['filter']['checks'])) {
-                $query = $query->select(new Expression('*, (SELECT COUNT(*) FROM admin_checkin WHERE plan_id = {{timetable}}.plan_id) checks'));
-            }
-
-            return $query;
-        };*/
-
         unset($actions['delete']);
 
         return $actions;
index 240e04910b5fc03ebb2363e3ee407bbc73384f46..e380916d308baf8a73a391f21d0ed4ff1a4cb892 100644 (file)
@@ -43,7 +43,6 @@ class Timetable extends \yii_app\records\TimetableV3
     {
         \Yii::debug($this->datetime_start);
         \Yii::debug($this->datetime_end);
-
         if (empty($this->datetime_start) && empty($this->datetime_end)) {
             return;
         }
@@ -186,27 +185,16 @@ class Timetable extends \yii_app\records\TimetableV3
 
     public function getCheckIns()
     {
-        if (!empty($this->plan_id)) {
-            return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']);
-        } else {
-            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')]);
+        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'))]);
 
-//           return $this->hasOne(AdminCheckin::class, ['admin_id' => 'id'])
-//                ->andWhere(['>=', 'date', date('Y-m-d 00:00:00')])
-//                ->andWhere(['<=', 'date', date('Y-m-d 23:59:59')]);
-        }
     }
 
     public function getCheckInCount()
     {
-        if (!empty($this->plan_id)) {
-            return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count();
-        } else {
-            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();
-        }
+        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();
+
     }
 }
\ No newline at end of file
index 0b5a646d025964b773f708d8f3a26aaae54daaae..fb95f1d5183f9520b4a1346017668649f3d6ffc9 100644 (file)
@@ -191,6 +191,68 @@ 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_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'])
+            ->andWhere(['BETWEEN', 'time',
+                date('Y-m-d H:i:s', strtotime($this->date_start . ' ' . $this->time_start)),
+                date('Y-m-d H:i:s', strtotime($this->date_end . ' ' . $this->time_end))]);
+    }
+
+    public function getCheckInCount()
+    {
+        return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])
+            ->andWhere(['BETWEEN', 'time',
+                date('Y-m-d H:i:s', strtotime($this->date_start . ' ' . $this->time_start)),
+                date('Y-m-d H:i:s', strtotime($this->date_end . ' ' . $this->time_end))])
+            ->count();
+    }
+
     public function getAdmin()
     {
         return $this->hasOne(Admin::class, ['id' => 'admin_id']);
@@ -236,15 +298,17 @@ class TimetableFactModel extends ActiveRecord
         return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']);
     }
 
-    public function isWorkSlot() {
+    public function isWorkSlot()
+    {
         return true;
     }
 
-    public static function getClosedShiftData($admin_id, $date_start, $date_end) {
+    public static function getClosedShiftData($admin_id, $date_start, $date_end)
+    {
         $timetableFactModels = TimetableFactModel::find()->where([
-                'admin_id' => $admin_id,
-                'status' => AdminCheckin::TYPE_END,
-            ])
+            'admin_id' => $admin_id,
+            'status' => AdminCheckin::TYPE_END,
+        ])
             ->andWhere(['>=', 'date_start', date('Y-m-d', strtotime($date_start))])
             ->andWhere(['<=', 'date_end', date('Y-m-d', strtotime($date_end))])
             ->all();