From 05baa35d919bd0f4ec21b48d01348f678d01a8d9 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Sep 2024 17:02:22 +0300 Subject: [PATCH] =?utf8?q?ERP-175=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=B8=D1=82=D1=8C=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?utf8?q?=D0=B2=D0=BE=D1=80=D0=BA-=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api3/core/services/TimetableService.php | 59 +++++-------------- .../controllers/timetable/PlanController.php | 17 +++++- erp24/records/TimetableFactModel.php | 2 +- 3 files changed, 29 insertions(+), 49 deletions(-) diff --git a/erp24/api3/core/services/TimetableService.php b/erp24/api3/core/services/TimetableService.php index 59e859f3..197e4047 100644 --- a/erp24/api3/core/services/TimetableService.php +++ b/erp24/api3/core/services/TimetableService.php @@ -131,37 +131,17 @@ class TimetableService { /** @var $data Fact */ - if ($data->plan_id) { - $timetable = Timetable::findOne(['plan_id' => $data->plan_id, 'tabel' => 1]); - if (!$timetable) { - throw new NotFoundHttpException("Факт не найден"); - } - } + $fact = TimetableFactModel::getLast($data->admin_id, date('Y-m-d')); $currentDate = date('Y-m-d H:i:s'); - $admin_id = $data->plan_id ? $timetable->admin_id : $data->admin_id; + $admin_id = $data->admin_id; - //убрать после согласования оплаты подработчиков - if (Admin::findOne($admin_id)->group_id === AdminGroup::GROUP_WORKERS && !$data->plan_id) { - throw new \InvalidArgumentException('Подработчики не могут открыть смены без плана!'); - } - - $checkInFirst = $data->plan_id ? - AdminCheckin::find()->where(['plan_id' => $timetable->plan_id])->orderBy(['time' => SORT_ASC])->one() : - AdminCheckin::find()->where(['admin_id' => $admin_id])->orderBy(['id' => SORT_DESC])->one(); + $checkInFirst = AdminCheckin::findOne($fact->checkin_start_id); if ($checkInFirst && (strtotime($checkInFirst->time) + 60 * 60 > strtotime($currentDate))) { throw new InvalidArgumentException("Между началом и концом смены должно пройти минимум один час"); } - if ($data->plan_id) { - $timetable->datetime_end = $currentDate; - $timetable->save(); - if ($timetable->getErrors()) { - throw new \Exception(Json::encode($timetable->getErrors())); - } - } - $imagePath = $data->uploadImage($admin_id); if (!$imagePath) { throw new InvalidArgumentException("Не удалось загрузить картинку"); @@ -169,28 +149,17 @@ class TimetableService $checkIn = new AdminCheckin(); - if ($data->plan_id) { - $checkIn->plan_id = $timetable->plan_id; - $checkIn->store_id = $timetable->store_id; - $checkIn->d_id = $timetable->admin->group_id; - $checkIn->date = $timetable->date; - } else { - - //остается буквально на день чтобы не посыпались ошибки из-за открытых смен до выката функционала - $plan = Timetable::find() - ->andWhere(['admin_id' => $admin_id]) - ->andWhere(['between', 'date', date('Y-m-d', strtotime('-1 day')), date('Y-m-d')]) - ->andWhere(['tabel' => 1]) - ->orderBy('id desc') - ->one(); - $checkIn->shift_id = !empty($plan) ? $plan->shift_id : null; - - $checkIn->plan_id = null; - $checkIn->store_id = $checkInFirst->store_id; - $checkIn->d_id = $checkInFirst->d_id; - $checkIn->date = $checkInFirst->date; - } - + $timetable = Timetable::find() + ->andWhere(['admin_id' => $admin_id]) + ->andWhere(['between', 'date', date('Y-m-d', strtotime('-1 day')), date('Y-m-d')]) +// ->andWhere(['tabel' => 1]) + ->orderBy('id desc') + ->one(); + + $checkIn->plan_id = $timetable->plan_id; + $checkIn->store_id = $timetable->store_id; + $checkIn->d_id = $timetable->admin->group_id; + $checkIn->date = $timetable->date; $checkIn->ball = 5; $checkIn->comment = ""; $checkIn->admin_id = $admin_id; diff --git a/erp24/api3/modules/v1/controllers/timetable/PlanController.php b/erp24/api3/modules/v1/controllers/timetable/PlanController.php index 51e920a4..2ae7b68e 100644 --- a/erp24/api3/modules/v1/controllers/timetable/PlanController.php +++ b/erp24/api3/modules/v1/controllers/timetable/PlanController.php @@ -19,7 +19,7 @@ class PlanController extends \yii_app\api3\controllers\ActiveController { use ServiceTrait; -// public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class; + public $modelClass = TimetableFactModel::class; @@ -32,11 +32,22 @@ class PlanController extends \yii_app\api3\controllers\ActiveController 'pageSizeLimit' => [1, 50], ]; + $request = Yii::$app->request->post()['filter']; + + $fact = TimetableFactModel::find() + ->andWhere(['admin_id' => $request['admin_id']]) + ->andWhere(['date_shift' => $request['date']]) + ->one(); + + if (true) { + $this->modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class; + } + $actions['index']['dataFilter'] = [ 'class' => \yii\data\ActiveDataFilter::class, - 'searchModel' => $this->modelClass + 'searchModel' => $actions['index']['modelClass'] ]; - + var_dump($actions['index']);die(); unset($actions['delete']); return $actions; diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index fb95f1d5..6c0c56bd 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -201,7 +201,7 @@ class TimetableFactModel extends ActiveRecord 'salary_shift', // 'price' => fn($x) => $x->shift_id == 2 ? 140 : 125, 'tabel', - 'date_shift', + 'date' => fn($x) => $x->date_shift, 'date_start' => fn($x) => $x->date_start . ' ' .$x->time_start, 'date_end' => fn($x) => !empty($x->date_end) ? $x->date_end . ' ' .$x->time_end : null, 'time_start', -- 2.39.5