From 0717ef3fec2038f0ec6b993a0fe8f00048e43d0b Mon Sep 17 00:00:00 2001 From: Marina Zozirova Date: Thu, 19 Sep 2024 11:05:13 +0000 Subject: [PATCH] =?utf8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20can=5Fopen=20Timetable.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api3/core/services/IncomeService.php | 30 +++++++------------ .../controllers/timetable/PlanController.php | 5 +++- .../modules/v1/models/timetable/Timetable.php | 4 +-- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/erp24/api3/core/services/IncomeService.php b/erp24/api3/core/services/IncomeService.php index dc63bbdb..659ce00f 100644 --- a/erp24/api3/core/services/IncomeService.php +++ b/erp24/api3/core/services/IncomeService.php @@ -12,6 +12,7 @@ use yii_app\records\Products1c; use yii_app\records\ProductsClass; use yii_app\records\Sales; use yii_app\records\SalesProducts; +use yii_app\records\TimetableFactModel; use yii_app\records\TimetableV3; class IncomeService @@ -21,31 +22,22 @@ class IncomeService * @throws Exception */ public function show($data) { - // берём планы по флористу в указанном промежутке времени - $plans = Timetable::find()->with(['checkIns'])->where(['admin_id' => $data->admin_id, 'tabel' => 0]) - ->andWhere(['slot_type_id' => Timetable::TIMESLOT_WORK]) + // берём факты по флористу в указанном промежутке времени + $facts = TimetableFactModel::find()->where(['admin_id' => $data->admin_id]) ->andWhere(['>=', 'date', date("Y-m-d", strtotime($data->date_from))]) ->andWhere(['<=', 'date', date("Y-m-d", strtotime($data->date_to))]) ->all(); - $plan_ids = ArrayHelper::getColumn($plans, 'id'); - // берём факты, которые указывают на выбранные ранее планы - $facts = Timetable::find()->where(['plan_id' => $plan_ids])->all(); - // извлекаем отработанное время из фактов - $workHoursPerPlanId = ArrayHelper::map($facts, 'plan_id', 'work_time'); + $baseIncome = []; - foreach ($plans as $plan) { - /* @var $plan Timetable */ - if (!isset($workHoursPerPlanId[$plan->id])) { - continue; - } + foreach ($facts as $fact) { // получаем отработку со временем для каждой запланированной смены $baseIncome [] = [ - 'date' => $plan->date, - 'shift_id' => $plan->shift_id, - 'salary_shift' => $plan->salary_shift, - 'price' => $plan->shift_id == 1 ? 125 : 145, - 'work_hours' => $workHoursPerPlanId[$plan->id] ?? 0, // если план есть, а факта нет, то 0 чаов отработано - 'in_shift' => count($plan->checkIns) == 1, + 'date' => $fact->date, + 'shift_id' => $fact->shift_id, + 'salary_shift' => $fact->salary_shift, + 'price' => $fact->shift_id == 1 ? 125 : 145, + 'work_hours' => $fact->work_time, + 'in_shift' => count($fact->checkIns) == 1, ]; } $admin = Admin::findOne($data->admin_id); diff --git a/erp24/api3/modules/v1/controllers/timetable/PlanController.php b/erp24/api3/modules/v1/controllers/timetable/PlanController.php index b308e583..208d7f9c 100644 --- a/erp24/api3/modules/v1/controllers/timetable/PlanController.php +++ b/erp24/api3/modules/v1/controllers/timetable/PlanController.php @@ -42,7 +42,10 @@ class PlanController extends \yii_app\api3\controllers\ActiveController ->andWhere(['admin_id' => $requestParams['filter']['admin_id']]) ->select('plan_id') ->column(); - return $query->andFilterWhere(['not in', 'id', $plans]); + + $query->andFilterWhere(['not in', 'id', $plans]); + $query->andFilterWhere(['tabel' => 0]); + return $query; }; unset($actions['delete']); diff --git a/erp24/api3/modules/v1/models/timetable/Timetable.php b/erp24/api3/modules/v1/models/timetable/Timetable.php index 28878b97..8c483411 100644 --- a/erp24/api3/modules/v1/models/timetable/Timetable.php +++ b/erp24/api3/modules/v1/models/timetable/Timetable.php @@ -153,10 +153,10 @@ class Timetable extends \yii_app\records\TimetableV3 'time_end', 'work_time', 'status', - 'checkInCount', + 'checkInCount', 'can_open' => fn($x) => !TimetableFactModel::find() ->andWhere(['is_close' => false]) - ->andWhere(['plan_id' => $x->id])->exists() && ($x->date == date('Y-m-d')) + ->andWhere(['plan_id' => $x->id])->exists() && ($x->date == date('Y-m-d')) && $x->tabel == 0 && $x->plan_id == null ]; return $fields; -- 2.39.5