From a70a647dc521fbf1ef3a5fbd4439d9dc95f211d9 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 2 Jul 2024 17:54:16 +0300 Subject: [PATCH] =?utf8?q?Revert=20"Revert=20"=D0=94=D0=BE=D0=B1=D0=B0?= =?utf8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=84=D0=B0=D0=BA=D1=82=20?= =?utf8?q?=D1=81=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=B2=20/timetable/plan""?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts commit d039a031192617d2639e9c56fce57d577c288453. --- erp24/actions/timetable/EditPlanAction.php | 3 + erp24/actions/timetable/PlanAction.php | 5 ++ erp24/forms/timetable/TabelSearchForm.php | 36 +++++---- erp24/records/Timetable.php | 1 + erp24/records/TimetableFactModel.php | 4 + erp24/views/timetable/plan.php | 16 +++- erp24/views/timetable/tabel_edit.php | 87 ++++++++++++++++++++++ 7 files changed, 135 insertions(+), 17 deletions(-) diff --git a/erp24/actions/timetable/EditPlanAction.php b/erp24/actions/timetable/EditPlanAction.php index 652c481d..f5c5105f 100755 --- a/erp24/actions/timetable/EditPlanAction.php +++ b/erp24/actions/timetable/EditPlanAction.php @@ -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, ]); } diff --git a/erp24/actions/timetable/PlanAction.php b/erp24/actions/timetable/PlanAction.php index d3a5858b..3fc4a8ee 100755 --- a/erp24/actions/timetable/PlanAction.php +++ b/erp24/actions/timetable/PlanAction.php @@ -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, ]); } diff --git a/erp24/forms/timetable/TabelSearchForm.php b/erp24/forms/timetable/TabelSearchForm.php index 77716c20..1acbf3f3 100755 --- a/erp24/forms/timetable/TabelSearchForm.php +++ b/erp24/forms/timetable/TabelSearchForm.php @@ -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() diff --git a/erp24/records/Timetable.php b/erp24/records/Timetable.php index 4e87777e..7cdc8521 100755 --- a/erp24/records/Timetable.php +++ b/erp24/records/Timetable.php @@ -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; diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index baa53447..7cb99e96 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -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, diff --git a/erp24/views/timetable/plan.php b/erp24/views/timetable/plan.php index 1b089084..9fe4af28 100755 --- a/erp24/views/timetable/plan.php +++ b/erp24/views/timetable/plan.php @@ -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; 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; slot_type_id]?? '#'; ?> isWorkSlot()) { ?>+work_time; ?> - isWorkSlot()) { ?> -
Ф+work_time ?>
+ isWorkSlot()) { ?> + work_time ?? 0; } ?> +
1 ? 'style="background: yellow"' : '' ?>>Ф+
diff --git a/erp24/views/timetable/tabel_edit.php b/erp24/views/timetable/tabel_edit.php index fdc38e26..85444957 100755 --- a/erp24/views/timetable/tabel_edit.php +++ b/erp24/views/timetable/tabel_edit.php @@ -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)) { + +

Факты смены:

+ +
+ $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 . "
" . $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') . "
" . + 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') . "
" . + 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 ''; + }, + ], + ], +]); ?> +
\ No newline at end of file -- 2.39.5