]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Revert "Revert "Добавлены факт смены в /timetable/plan""
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 2 Jul 2024 14:54:16 +0000 (17:54 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 2 Jul 2024 14:54:16 +0000 (17:54 +0300)
This reverts commit d039a031192617d2639e9c56fce57d577c288453.

erp24/actions/timetable/EditPlanAction.php
erp24/actions/timetable/PlanAction.php
erp24/forms/timetable/TabelSearchForm.php
erp24/records/Timetable.php
erp24/records/TimetableFactModel.php
erp24/views/timetable/plan.php
erp24/views/timetable/tabel_edit.php

index 652c481dae3b56f31b9041381ad209d3be04d8d6..f5c5105f53c3431a071588d2b53d3eceb51f6c3c 100755 (executable)
@@ -6,6 +6,7 @@ namespace yii_app\actions\timetable;
 use yii_app\records\TimetableFactModel;
 use Yii;
 use yii\base\Action;
+use yii\data\ActiveDataProvider;
 use yii\web\Response;
 use yii_app\records\Admin;
 use yii_app\records\Timetable;
@@ -64,9 +65,11 @@ class EditPlanAction extends Action
             $slot->time_end = $slot->shift ? $slot->shift->end_time : null;
         }
         $fact = TimetableFact::find()->andWhere(['plan_id' => $slot->id])->one();
+        $dataProvider = new ActiveDataProvider(['query' => TimetableFactModel::find()->where(['admin_id' => $row['admin_id'], 'store_id' => $row['store_id'], 'date_shift' => $row['date']])]);
         return $this->controller->renderPartial('/timetable/tabel_edit.php', [
             'slot' => $slot,
             'fact' => $fact,
+            'dataProvider' => $dataProvider,
             'success' => $success ?? false,
         ]);
     }
index d3a5858bab86de0175d9a8bc16fb3da30d3c990f..3fc4a8eef451f6149b6564ce530591dec0f8a8a1 100755 (executable)
@@ -3,6 +3,7 @@ declare(strict_types = 1);
 
 namespace yii_app\actions\timetable;
 
+use yii_app\records\TimetableFactModel;
 use yii\base\Action;
 use yii\helpers\ArrayHelper;
 use yii_app\forms\timetable\TabelSearchForm;
@@ -22,6 +23,7 @@ class PlanAction extends Action
                 'tabelForm' => $tabelForm,
                 'timetablePlan' => [],
                 'timetableFact' => [],
+                'timetableFactModel' => [],
             ]);
         }
 
@@ -50,10 +52,13 @@ class PlanAction extends Action
         /** @var TimetableFact[] $timetablePlan */
         $timetableFact = array_filter(ArrayHelper::getColumn($timetablePlan, 'fact'));
 
+        $timetableFactModel = $tabelForm->search(Timetable::TABLE_FACT_NEW)->all();
+
         return $this->controller->render('/timetable/plan.php', [
             'tabelForm' => $tabelForm,
             'timetablePlan' => $timetablePlan,
             'timetableFact' => $timetableFact,
+            'timetableFactModel' => $timetableFactModel,
         ]);
     }
 
index 77716c206724a4d61a32aab3513e3db49626727d..1acbf3f311e818756eed395d5447029ee965d9f4 100755 (executable)
@@ -3,6 +3,7 @@ declare(strict_types = 1);
 
 namespace yii_app\forms\timetable;
 
+use yii_app\records\TimetableFactModel;
 use yii\base\Model;
 use yii\db\ActiveQuery;
 use yii\db\Expression;
@@ -104,25 +105,32 @@ class TabelSearchForm extends Model
         $classes = [
             Timetable::TABLE_PLAN => TimetablePlan::class,
             Timetable::TABLE_FACT => TimetableFact::class,
+            Timetable::TABLE_FACT_NEW => TimetableFactModel::class,
         ];
         if (!isset($classes[$tabel])) {
             throw new \Exception('Unknown type');
         }
-        /** @var TimetablePlan | TimetableFact $class */
+        /** @var TimetablePlan | TimetableFact | TimetableFactModel $class */
         $class = $classes[$tabel];
-        return $class::find()
-            ->andWhere([
-                'admin_group_id' => array_keys(AdminGroup::groupsWithShift()),
-                'store_id' => array_keys(self::stores()),
-            ])
-            ->andFilterWhere([
-                'admin_group_id' => $this->adminGroupId,
-                'store_id' => $this->storeId,
-                'status' => $this->status,
-            ])
-            ->andFilterWhere(['>=', 'date', $this->start])
-            ->andFilterWhere(['<=', 'date', $this->end])
-            ;
+        if (in_array($tabel, [Timetable::TABLE_PLAN, Timetable::TABLE_FACT])) {
+            return $class::find()
+                ->andWhere([
+                    'admin_group_id' => array_keys(AdminGroup::groupsWithShift()),
+                    'store_id' => array_keys(self::stores()),
+                ])
+                ->andFilterWhere([
+                    'admin_group_id' => $this->adminGroupId,
+                    'store_id' => $this->storeId,
+                    'status' => $this->status,
+                ])
+                ->andFilterWhere(['>=', 'date', $this->start])
+                ->andFilterWhere(['<=', 'date', $this->end]);
+        } else {
+            return $class::find()
+                ->andWhere(['store_id' => array_keys(self::stores())])
+                ->andFilterWhere(['>=', 'date_shift', $this->start])
+                ->andFilterWhere(['<=', 'date_shift', $this->end]);
+        }
     }
 
     public function holidays()
index 4e87777e3cb46a184226a81e10fedb236acb26de..7cdc852102b54d4d2431a8ca23130049bb2696d2 100755 (executable)
@@ -43,6 +43,7 @@ class Timetable extends ActiveRecord
 
     const TABLE_PLAN = 0;
     const TABLE_FACT = 1;
+    const TABLE_FACT_NEW = 2;
 
     const TIMESLOT_WORK = 1;
     const TIMESLOT_VACATION = 2;
index baa534479408fb7a718150d65856a43d3ff1f3dc..7cb99e960e01f334779dd72576a860cc2bc9f7fa 100644 (file)
@@ -208,6 +208,10 @@ class TimetableFactModel extends ActiveRecord
         return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']);
     }
 
+    public function isWorkSlot() {
+        return true;
+    }
+
     public static function getClosedShiftData($admin_id, $date_start, $date_end) {
         $timetableFactModels = TimetableFactModel::find()->where([
                 'admin_id' => $admin_id,
index 1b08908425b4a2421f5f2e5e4e2b2a5cd649e0e5..9fe4af28ece4e42b6e14c52cf50491b56a5aff60 100755 (executable)
@@ -4,10 +4,12 @@
  * @var TabelSearchForm $tabelForm
  * @var Timetable[] $timetablePlan
  * @var Timetable[] $timetableFact
+ * @var TimetableFactModel[] $timetableFactModel
  * @var array $userSummaryPlan
  * @var array $userSummaryFact
  */
 
+use yii_app\records\TimetableFactModel;
 use yii\helpers\ArrayHelper;
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
@@ -26,7 +28,7 @@ $holidays = ArrayHelper::index($tabelForm->holidays(), 'date');
 
 $getUserSummary = function (array $timetable) {
     $userSummary = [];
-    /** @var TimetablePlan[] $timetable */
+    /** @var TimetablePlan[] | TimetableFactModel $timetable */
     foreach ($timetable as $slot) {
         $userSummary[$slot->admin_id] ??= [
             'time' => 0,
@@ -41,6 +43,7 @@ $getUserSummary = function (array $timetable) {
 };
 $userSummaryPlan = $getUserSummary($timetablePlan);
 $userSummaryFact = $getUserSummary($timetableFact);
+$userSummaryFactModel = $getUserSummary($timetableFactModel);
 
 $allShifts = \yii_app\records\Shift::all();
 $adminGroups = AdminGroup::groupsWithShift();
@@ -187,6 +190,11 @@ $users = $tabelForm->admins();
 $regroupedTimetablePlan = ArrayHelper::index($timetablePlan, 'date', ['admin_id']);
 /** @var Timetable[][] $regroupedTimetableFact */
 $regroupedTimetableFact = ArrayHelper::index($timetableFact, 'date', ['admin_id']);
+/** @var TimetableFactModel[][] $regroupedTimetableFactModel */
+$regroupedTimetableFactModel = [];
+foreach($timetableFactModel as $ttfm) {
+    $regroupedTimetableFactModel[$ttfm->admin_id][$ttfm->date_shift][] = $ttfm;
+}
 
 $rowNumber = 0;
 ?>
@@ -208,6 +216,7 @@ $rowNumber = 0;
 <?php
         $recordPlan = $regroupedTimetablePlan[$idu][$date->format('Y-m-d')] ?? null;
         $recordFact = $regroupedTimetableFact[$idu][$date->format('Y-m-d')] ?? null;
+        $recordFactModels = $regroupedTimetableFactModel[$idu][$date->format('Y-m-d')] ?? null;
         $attributes = [
             'class' => ['day' . $date->format('N')],
             'data-user-id' => $user->id,
@@ -232,8 +241,9 @@ $rowNumber = 0;
                 <?= $slotTypeLetters[$recordPlan->slot_type_id]?? '#'; ?>
 <?php if ($recordPlan->isWorkSlot()) { ?><span class="color-success">+<?= $recordPlan->work_time; ?></span>
                 <?php } ?>
-                <?php if ($recordFact && $recordPlan->isWorkSlot()) { ?>
-                <div class="hours">Ф+<?= $recordFact->work_time ?></div>
+                <?php if ($recordFactModels  && $recordPlan->isWorkSlot()) { ?>
+                <?php $rfm_work_time = 0; foreach ($recordFactModels as $rfm) { $rfm_work_time += $rfm->work_time ?? 0; } ?>
+                <div class="hours" <?= count($recordFactModels) > 1 ? 'style="background: yellow"' : '' ?>>Ф+<?= $rfm_work_time ?></div>
                 <?php } ?>
             <?php } ?>
             </div>
index fdc38e2612858500b6c5791b57dd2350a9f41263..8544495730fabd2915b5c3bb423e1fc8f31c8235 100755 (executable)
@@ -2,9 +2,12 @@
 /**
  * @var \yii_app\records\Timetable $slot
  * @var \yii_app\records\TimetableFact $fact
+ * @var \yii\data\ActiveDataProvider $dataProvider
  * @var bool $success
  */
 
+use yii\grid\ActionColumn;
+use yii\helpers\Html;
 use yii\helpers\ArrayHelper;
 use yii_app\records\AdminGroup;
 use yii_app\records\Timetable;
@@ -98,3 +101,87 @@ if (Timetable::getAllowEditShift($slot->date, $numDay)) {
     <?php
 } ?>
 <?php $form::end() ?>
+
+<h3 class="m-2">Факты смены:</h3>
+
+<div class="table-responsive">
+<?= \yii\grid\GridView::widget([
+    'dataProvider' => $dataProvider,
+    'columns' => [
+        ['class' => 'yii\grid\SerialColumn'],
+        [
+            'attribute' => 'admin_id',
+            'label' => 'Пользователь',
+            'value' => function ($data) {
+                return $data->admin->name;
+            }
+        ],
+        [
+            'attribute' => 'store_id',
+            'label' => 'Магазин, Должность',
+            'format' => 'raw',
+            'value' => function ($data) {
+                return $data->store->name . "<br>" . $data->adminGroup->name;
+            }
+        ],
+        [
+            'label' => 'Тип смены',
+            'attribute' => 'shift_id',
+            'format' => 'raw',
+            'value' => function ($model) {
+                return $model->shift_id ? $model->shift->name : null;
+            },
+        ],
+        [
+            'attribute' => 'work_time',
+            'format' => 'raw',
+            'value' => function ($model) {
+                return $model->work_time;
+            },
+        ],
+        [
+            'label' => 'Дата смены',
+            'attribute' => 'date_shift',
+            'format' => ['date', 'php:d.m.Y'],
+        ],
+        [
+            'label' => 'Начало',
+            'attribute' => 'date_start',
+            'format' => 'raw',
+            'value' => function ($model) {
+                return Yii::$app->formatter->asDatetime($model->date_start, 'php:d.m.Y') . "<br>" .
+                    Yii::$app->formatter->asDatetime($model->time_start, 'php:H:i:s');
+            },
+        ],
+        [
+            'label' => 'Конец',
+            'attribute' => 'date_end',
+            'format' => 'raw',
+            'value' => function ($model) {
+                return !empty($model->date_end) ? Yii::$app->formatter->asDatetime($model->date_end, 'php:d.m.Y') . "<br>" .
+                    Yii::$app->formatter->asDatetime($model->time_end, 'php:H:i:s') : 'Работает';
+            },
+        ],
+        [
+            'label' => 'Отметка о начале',
+            'format' => 'raw',
+            'value' => function ($model) {
+                if (!empty($model->checkin_start_id)) {
+                    return !empty($photo = $model->checkinStart->photo) ? Html::img("/$photo", ['alt' => 'selfie', 'style' => 'min-width: 200px']) : null;
+                };
+                return '';
+            },
+        ],
+        [
+            'label' => 'Отметка о конце',
+            'format' => 'raw',
+            'value' => function ($model) {
+                if (!empty($model->checkin_end_id)) {
+                    return !empty($photo = $model->checkinEnd->photo) ? Html::img("/$photo", ['alt' => 'selfie', 'style' => 'min-width: 200px']) : null;
+                };
+                return '';
+            },
+        ],
+    ],
+]); ?>
+</div>
\ No newline at end of file