From ab21253e920dd064b33393a0dd5a4c919eacf79b Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 19 Jul 2024 12:41:17 +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=BC=D0=B5=D0=BB=D0=BA=D0=BE=20=D0=BF?= =?utf8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BF=D0=BB?= =?utf8?q?=D0=B0=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../timetable/StartShiftStepOneAction.php | 2 +- .../timetable/StartShiftStepThreeAction.php | 10 ++-------- .../timetable/StartShiftStepTwoAction.php | 2 +- erp24/records/TimetableFactModel.php | 17 ++++++++++------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/erp24/actions/timetable/StartShiftStepOneAction.php b/erp24/actions/timetable/StartShiftStepOneAction.php index 9e1f5b69..5a6f14ec 100755 --- a/erp24/actions/timetable/StartShiftStepOneAction.php +++ b/erp24/actions/timetable/StartShiftStepOneAction.php @@ -30,7 +30,7 @@ class StartShiftStepOneAction extends Action return $this->controller->redirect('/'); } - $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d')); + $fact = TimetableFactModel::getLast($userModel->id, date('Y-m-d')); $plan = Timetable::find() ->andWhere(['admin_id' => $userModel->id]) ->andWhere(['date' => date('Y-m-d')]) diff --git a/erp24/actions/timetable/StartShiftStepThreeAction.php b/erp24/actions/timetable/StartShiftStepThreeAction.php index 204b4700..133de72d 100755 --- a/erp24/actions/timetable/StartShiftStepThreeAction.php +++ b/erp24/actions/timetable/StartShiftStepThreeAction.php @@ -37,16 +37,10 @@ class StartShiftStepThreeAction extends Action ->one(); //отрабатывает только для открытия - $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d')); + $fact = TimetableFactModel::getLast($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(); + $fact = TimetableFactModel::getLast($userModel->id, date('Y-m-d'), false); } if ($request->isAjax diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index afc62b78..7d998e84 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -52,7 +52,7 @@ class StartShiftStepTwoAction extends Action ->andWhere(['tabel' => 0]) ->orderBy('id desc') ->one(); - $fact = TimetableFactModel::getOpening($userModel->id, date('Y-m-d')); + $fact = TimetableFactModel::getLast($userModel->id, date('Y-m-d')); $adminStoreId = null; diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index a6aa68df..0b5a646d 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -112,7 +112,7 @@ class TimetableFactModel extends ActiveRecord */ public static function setValues($adminCheckin, $is_start = true) { - $model = self::getOpening($adminCheckin->admin_id, $adminCheckin->date); + $model = self::getLast($adminCheckin->admin_id, $adminCheckin->date); /** @var $model TimetableFactModel */ if ($model) { @@ -175,15 +175,18 @@ class TimetableFactModel extends ActiveRecord * @param $date * @return array|ActiveRecord|null */ - public static function getOpening(int $adminId, $date) { - return self::find() - ->andWhere(['admin_id' => $adminId]) - ->andWhere(['is_opening' => true]) - ->andWhere([ + public static function getLast(int $adminId, $date, $opening = true) + { + $fact = self::find() + ->andWhere(['admin_id' => $adminId])->andWhere([ 'OR', ['date_shift' => $date], ['date_shift' => date('Y-m-d', strtotime('-1 day'))], - ]) + ]); + + $opening ? $fact->andWhere(['is_opening' => true]) : $fact->andWhere(['is_close' => true]); + + return $fact ->orderBy('id desc') ->one(); } -- 2.39.5