]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правка того что не у всех нормально открывались смены fix_shift_opening origin/fix_shift_opening
authormarina <m.zozirova@gmail.com>
Wed, 17 Jul 2024 08:27:48 +0000 (11:27 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 17 Jul 2024 08:27:48 +0000 (11:27 +0300)
erp24/commands/TimetableController.php
erp24/records/TimetableFactModel.php

index ed2f7fb60a22e3114ff2cd18a4900f583b142b3d..e3ce4e3b7891da79163f83009e4341f00ac0d0c6 100644 (file)
@@ -14,7 +14,8 @@ class TimetableController extends Controller
         $timetableFactModels = TimetableFactModel::find()
             ->with(['checkinStart'])
             ->andWhere(['!=', 'is_close', true])
-            ->andWhere(['<=', new Expression('CONCAT(date_start, \' \', time_start)'), date('Y-m-d H:i:s', strtotime('-14 hours', time()))])->all();
+            ->andWhere(['<=', new Expression('CONCAT(date_start, \' \', time_start)'), date('Y-m-d H:i:s', strtotime('-14 hours', time()))])
+            ->all();
 
         foreach ($timetableFactModels as $timetableFactModel) {
             /** @var $timetableFactModel TimetableFactModel */
index 734563ad0acc3a0431a5d9e8a90148c7e5e20bba..5183cd1052253b6bf3957f0979dcfe71c822cb79 100644 (file)
@@ -105,16 +105,17 @@ class TimetableFactModel extends ActiveRecord
     //is_start моя пометка для выравнивания открытия/закрытия натыканных флористами смен
 
     /**
+     * @param $adminCheckin
+     * @param $is_start
+     * @return void
      * @throws \Exception
      */
     public static function setValues($adminCheckin, $is_start = true)
     {
-        if ($model = self::find()
-            ->where(['admin_id' => $adminCheckin->admin_id, 'is_opening' => true])
-            ->andWhere(['between', 'date_shift', date('Y-m-d', strtotime($adminCheckin->date . ' -1 day')), date('Y-m-d', strtotime($adminCheckin->date))])
-            ->andWhere(['status' => array(AdminCheckin::TYPE_START, AdminCheckin::TYPE_APPEAR)])
-            ->one()) {
+        $model = self::getOpening($adminCheckin->admin_id, $adminCheckin->date);
 
+        /** @var $model TimetableFactModel */
+        if ($model) {
             $model->date_end = date("Y-m-d", strtotime($adminCheckin->time));
             $model->time_end = date("H:i:s", strtotime($adminCheckin->time));
             $model->work_time = min(abs(strtotime($model->date_end . $model->time_end) + 600 - strtotime($model->date_start . $model->time_start)) / 3600, self::WORK_HOURS_TIME);
@@ -168,6 +169,20 @@ class TimetableFactModel extends ActiveRecord
         }
     }
 
+    /**
+     * Проверка на то есть ли открытый факт
+     * @param int $adminId
+     * @param $date
+     * @return array|ActiveRecord|null
+     */
+    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)])
+            ->orderBy('id desc')
+            ->one();
+    }
 
     public function getAdmin()
     {