From 137d6015e78038a7d01d07b4fd97af1fd3b8e5a8 Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 19 Jul 2024 10:09:32 +0300 Subject: [PATCH] =?utf8?q?ERP-115=20=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0?= =?utf8?q?=D0=B1=D0=BE=D1=82=D0=B0=D1=82=D1=8C=20=D0=BE=D1=82=D0=BA=D1=80?= =?utf8?q?=D1=8B=D1=82=D0=B8=D0=B5/=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D1=82?= =?utf8?q?=D0=B8=D0=B5=20=D1=81=D0=BC=D0=B5=D0=BD=20=D1=83=20=D0=B0=D0=B4?= =?utf8?q?=D0=BC=D0=B8=D0=BD=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=BE?= =?utf8?q?=D1=80=D0=BE=D0=B2=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?= =?utf8?q?=D0=B8=20=D1=82=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20=D1=88=D0=B0?= =?utf8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../timetable/StartShiftStepThreeAction.php | 26 +++---- .../timetable/StartShiftStepTwoAction.php | 68 ++++++++++--------- erp24/records/TimetableFactModel.php | 10 ++- .../timetable/start_shift_step_three.php | 22 +++--- .../views/timetable/start_shift_step_two.php | 25 +++---- 5 files changed, 74 insertions(+), 77 deletions(-) diff --git a/erp24/actions/timetable/StartShiftStepThreeAction.php b/erp24/actions/timetable/StartShiftStepThreeAction.php index c677fe6c..204b4700 100755 --- a/erp24/actions/timetable/StartShiftStepThreeAction.php +++ b/erp24/actions/timetable/StartShiftStepThreeAction.php @@ -9,6 +9,7 @@ use yii\web\Response; use yii_app\forms\timetable\StartForm; use yii_app\records\Admin; use yii_app\records\AdminCheckin; +use yii_app\records\TimetableFactModel; class StartShiftStepThreeAction extends Action { @@ -35,19 +36,18 @@ class StartShiftStepThreeAction extends Action ->andWhere(['id' => $model->checkin_id]) ->one(); - /** @var AdminCheckin[] $dayCheckins */ - $dayCheckinsQuery = AdminCheckin::find() - ->andWhere(['admin_id' => $userModel->id]) - ->andWhere(['>', 'time', date('Y-m-d H:i:s', strtotime('-1 day'))]); - - if (!empty($currentCheckin)) { - $dayCheckinsQuery->andWhere(['!=', 'id', $model->checkin_id]); + //отрабатывает только для открытия + $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d')); + + //делается для того что при закрытии нужны дата и время фактического закрытия + if (!$fact) { + $fact = TimetableFactModel::find() + ->andWhere(['admin_id' => $userModel->id]) + ->andWhere(['date_shift' => date('Y-m-d')]) + ->andWhere(['is_close' => true]) + ->orderBy('id desc') + ->one(); } - - $dayCheckinsQuery->orderBy(['time' => SORT_ASC]); - - $dayCheckins = $dayCheckinsQuery->all(); - $lastCheckin = end($dayCheckins); if ($request->isAjax && @@ -82,7 +82,7 @@ class StartShiftStepThreeAction extends Action return $this->controller->render('/timetable/start_shift_step_three.php', [ 'userModel' => $userModel, - 'lastCheckin' => $lastCheckin, + 'fact' => $fact, 'currentCheckin' => $currentCheckin, 'model' => $model, diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index ef031243..0cc6fd4e 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -4,6 +4,7 @@ declare(strict_types = 1); namespace yii_app\actions\timetable; use yii_app\records\AdminGroup; +use yii_app\records\Timetable; use yii_app\records\TimetableFactModel; use Yii; use yii\base\Action; @@ -40,7 +41,16 @@ class StartShiftStepTwoAction extends Action ->andWhere(['>', 'time', date('Y-m-d H:i:s', strtotime('-1 day'))]) ->orderBy(['time' => SORT_ASC]) ->all(); - $lastCheckin = end($dayCheckins); + + $plan = Timetable::find() + ->andWhere(['admin_id' => $userModel->id]) + ->andWhere([ + 'OR', + ['date' => date('Y-m-d')], + ['date' => date('Y-m-d', strtotime('-1 day'))], + ]) + ->one(); + $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d')); $adminStoreId = null; @@ -61,23 +71,15 @@ class StartShiftStepTwoAction extends Action $model->admin_id = $userModel->id; $model->d_id = $userModel->group_id; $model->ball = 5; - $model->shift_id = $request->getBodyParam('shift_id'); - if (empty($model->store_id)) { - $model->store_id = (!empty($adminStoreId)) ? $adminStoreId : $device->store_id; - } $model->device_id = $device->id; $model->time = date('Y-m-d H:i:s'); - $model->type_id = (function () use ($userModel, $lastCheckin) { - if ($userModel->adminGroup->isRoaming()) { - return AdminCheckin::TYPE_APPEAR; - } - if ($lastCheckin && $lastCheckin->isStart()) { + $model->type_id = (function () use ($userModel, $fact) { + if ($fact) { return AdminCheckin::TYPE_END; } return AdminCheckin::TYPE_START; })(); - /** @var TimetablePlan[] $planSlots */ $planSlots = TimetablePlan::find() ->andWhere( @@ -92,13 +94,26 @@ class StartShiftStepTwoAction extends Action ]) ->all(); - if ($lastCheckin && $lastCheckin->isStart()) { - $model->plan_id = $lastCheckin->plan_id; - $model->replaced_admin_id = $lastCheckin->replaced_admin_id; - $model->date = $lastCheckin->date; - $model->d_id = $lastCheckin->d_id; + $model->shift_id = $request->getBodyParam('shift_id'); + $model->store_id = $request->getBodyParam('store_id'); + + if ($plan) { + $model->shift_id = $plan->shift_id; + $model->store_id = $plan->store_id; + } + + if ($fact) { + $model->shift_id = $fact->shift_id; + $model->store_id = $fact->store_id; + } + + if ($fact) { + $model->plan_id = $fact->plan_id; + $model->replaced_admin_id = $fact->admin_id_add; + $model->date = $fact->date_shift; + $model->d_id = $fact->d_id; } else { - if ($device->isFixedStore() && !$userModel->adminGroup->isRoaming()) { + if ($device->isFixedStore()) { /** @var TimetablePlan[] $planSlotsByAdminId */ $planSlotsByAdminId = ArrayHelper::index($planSlots, 'admin_id'); if (array_key_exists($model->admin_id, $planSlotsByAdminId)) { @@ -120,10 +135,6 @@ class StartShiftStepTwoAction extends Action $model->date = date('Y-m-d'); } - $adminStoreArrayPrepared = CityStore::getNames([$model->store_id]); - $adminStoreArray = array_values($adminStoreArrayPrepared); - $adminStoreName = $adminStoreArray[array_key_first($adminStoreArray)]; - if ($this->controller->request->getIsPost() && !$firstRun) { $model->load($this->controller->request->post()); $model->photo = UploadedFile::getInstance($model, 'photo'); @@ -133,11 +144,7 @@ class StartShiftStepTwoAction extends Action $model->checkin_id = $model->checkinModel->id; $model->id = $model->checkinModel->id; - $is_start = ($model->d_id == AdminGroup::GROUP_ADMINISTRATORS) ? - (count($dayCheckins) % 2 == 0 ? true : false) : - ($model->checkinModel->type_id == AdminCheckin::TYPE_START ? true : false); - - TimetableFactModel::setValues($model, $is_start); + TimetableFactModel::setValues($model, empty($fact)); if ($this->controller->request->getHeaders()->get('Accept') == 'application/json') { $this->controller->response->format = Response::FORMAT_JSON; @@ -153,10 +160,7 @@ class StartShiftStepTwoAction extends Action 'userModel' => $userModel, 'model' => $model, 'modelId' => $model->id, - 'adminStoreName' => $adminStoreName, 'device' => $device, - 'dayCheckins' => $dayCheckins, - 'lastCheckin' => $lastCheckin, 'planSlots' => $planSlots, ]); } @@ -165,11 +169,11 @@ class StartShiftStepTwoAction extends Action return $this->controller->render('/timetable/start_shift_step_two.php', [ 'userModel' => $userModel, 'model' => $model, - 'adminStoreName' => $adminStoreName, 'device' => $device, - 'dayCheckins' => $dayCheckins, - 'lastCheckin' => $lastCheckin, 'planSlots' => $planSlots, + 'fact' => $fact, + 'plan' => $plan, + 'dayCheckins' => $dayCheckins, ]); } } \ No newline at end of file diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 5183cd10..8262672f 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -177,9 +177,13 @@ class TimetableFactModel extends ActiveRecord */ 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)]) + ->andWhere(['admin_id' => $adminId]) + ->andWhere(['is_opening' => true]) + ->andWhere([ + 'OR', + ['date_shift' => $date], + ['date_shift' => date('Y-m-d', strtotime('-1 day'))], + ]) ->orderBy('id desc') ->one(); } diff --git a/erp24/views/timetable/start_shift_step_three.php b/erp24/views/timetable/start_shift_step_three.php index 1d642327..e7535b90 100644 --- a/erp24/views/timetable/start_shift_step_three.php +++ b/erp24/views/timetable/start_shift_step_three.php @@ -10,6 +10,7 @@ * @var AdminCheckin $currentCheckin * @var string $adminStoreName * @var TimetablePlan[] $planSlots + * @var \yii_app\records\TimetableFactModel $fact */ @@ -34,25 +35,18 @@ $dateTimeHoursInfo = ''; $currentCheckinTimeHours = date("H:i", strtotime($currentCheckin->time)); $currentCheckinDate = date("d.m.Y", strtotime($currentCheckin->time)); -if ($userModel->adminGroup->isRoaming()) { - $textButton = 'Отметится'; - $textInfo = 'Вы успешно отметились'; -} else { +if ($fact->is_opening) { $textButton = 'Открытие смены'; $textInfo = 'Смена успешно открыта'; - if (!empty($lastCheckin)) { - if ($lastCheckin->isStart()) { - $textButton = 'Закрытие смены'; - $textInfo = 'Смена успешно закрыта'; - $flowersStyleClass = 'closure-flower'; - $lastCheckinTimeHours = date("d.m.Y H:i", strtotime($lastCheckin->time)); - $dateTimeHoursInfo = $lastCheckinTimeHours . ' - ' . date("H:i d.m.Y", strtotime($currentCheckin->time)); - } - } +} else { + $textButton = 'Закрытие смены'; + $textInfo = 'Смена успешно закрыта'; + $flowersStyleClass = 'closure-flower'; + $lastCheckinTimeHours = date("H:i d.m.Y", strtotime($fact->time_start . $fact->date_start)); + $dateTimeHoursInfo = $lastCheckinTimeHours . ' - ' . date("H:i d.m.Y", strtotime($fact->time_end . $fact->date_end)); } - $timeInfo = 1; ?>
diff --git a/erp24/views/timetable/start_shift_step_two.php b/erp24/views/timetable/start_shift_step_two.php index 8c527b7c..73d076a1 100644 --- a/erp24/views/timetable/start_shift_step_two.php +++ b/erp24/views/timetable/start_shift_step_two.php @@ -8,12 +8,14 @@ * @var AdminCheckin $lastCheckin * @var string $adminStoreName * @var TimetablePlan[] $planSlots + * @var \yii_app\records\TimetableFactModel $fact */ use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii_app\forms\timetable\StartForm; use yii_app\records\AdminCheckin; +use yii_app\records\CityStore; use yii_app\records\Shift; use yii_app\records\TimetablePlan; @@ -36,12 +38,12 @@ foreach ($userModel->getStores() as $store) { 'name' => $store->name, ]; } -$this->registerJsVar('isRoam', $userModel->adminGroup->isRoaming() || !$device->isFixedStore()); +//$this->registerJsVar('isRoam', $userModel->adminGroup->isRoaming() || !$device->isFixedStore()); $this->registerJsVar('settings', [ 'planSlots' => $planSlots, 'model' => $model, 'modelPlanSlot' => $model->planSlot, - 'startShiftTime' => $model->isEnd() ? ((int) $lastCheckin->dateTime()->getTimestamp() * 1000) : null, + 'startShiftTime' => $model->isEnd() ? ((int) $fact->time_start * 1000) : null, 'fieldNames' => $formNames, 'stores' => $stores, ]); @@ -52,17 +54,12 @@ $this->registerJsVar('settings', [ /** @var AdminCheckin[][] $checkinsByDate */ $checkinsByDate = ArrayHelper::index($dayCheckins, 'type_id', ['date']); - - $textButton = ''; -if ($userModel->adminGroup->isRoaming()) { - $textButton = 'Отметится'; + +if ($fact) { + $textButton = 'Закрытие смены'; } else { - if (!empty($lastCheckin)) { - $textButton = ($lastCheckin->isStart()) ? 'Закрытие смены' : 'Открытие смены'; - } else { - $textButton = 'Открытие смены'; - } + $textButton = 'Открытие смены'; } ?> @@ -199,12 +196,12 @@ if ($userModel->adminGroup->isRoaming()) {
-
+
store->name ?? $plan->store->name ?? $model->store->name ?>
-
shift_id)) ? $shift->name : null?>
+
shift->name ?? $plan->shift->name ??!empty($model->shift_id) ? Shift::findOne($model->shift_id)->name : null ?>
@@ -217,8 +214,6 @@ if ($userModel->adminGroup->isRoaming()) {