From: Aleksey Filippov Date: Wed, 7 Aug 2024 13:26:43 +0000 (+0300) Subject: Правки по подсчёту оклада Администратора не на смене X-Git-Tag: 1.4~47^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=487d6c18f6cbcc4b223198a90197fdc3083daaf4;p=erp24_rep%2Fyii-erp24%2F.git Правки по подсчёту оклада Администратора не на смене --- diff --git a/erp24/services/CabinetService.php b/erp24/services/CabinetService.php index ccc1a9ce..6ea6cce9 100755 --- a/erp24/services/CabinetService.php +++ b/erp24/services/CabinetService.php @@ -3883,9 +3883,151 @@ Group BY admin_id return $query->asArray()->all(); } - public function getTimetableAdministratorData($adminId, $storeId, $dateFrom, $dateTo, bool $notInStore = false): array + public function getTimetableAdministratorFactData($adminId, $storeId, $dateFrom, $dateTo, bool $notInStore): array { + $shiftId = 1; + + $dict = [ + 1 => [ 1, 5, 7, 8], + 2 => [ 2], + 5 => [ 1, 5, 7, 8], + 7 => [ 1, 5, 7, 8], + 8 => [ 1, 5, 7, 8], + ]; + + $shiftIdForDict = ArrayHelper::getValue($dict, $shiftId); + + $query = TimetableFactModel::find() + ->joinWith('admin') + ->andWhere(['>=', 'date_shift', $dateFrom]) + ->andWhere(['<=', 'date_shift', $dateTo]) + ->andWhere(['<>','admin.group_id', -1]) + ->andWhere(['admin_id' => $adminId]) + ->andWhere(['shift_id' => $shiftIdForDict]) + ; + + if (!empty($storeId)) { + if (!$notInStore) { + $query->andWhere(['=', 'timetable_fact.store_id', $storeId]); + } else { + $query->andWhere(['<>', 'timetable_fact.store_id', $storeId]); + } + } + + $query->indexBy(['id']); + + $adminTable = $query->asArray()->all(); + $adminTableDateColumn = array_values(ArrayHelper::getColumn($adminTable, 'date_shift')); + $adminTableDays = array_unique(array_values($adminTableDateColumn)); + sort($adminTableDays); + + /** @var TimetableFactModel[] $timetable */ + $queryOtherAdminDay = TimetableFactModel::find() + ->select(['date_shift' => new \yii\db\Expression("DISTINCT(date_shift)"), 'id']) + ->andWhere(['>=', 'date_shift', $dateFrom]) + ->andWhere(['<=', 'date_shift', $dateTo]) + ->andWhere(['not in', 'date_shift', $adminTableDays]) + ->andWhere(['<>', 'admin_id', $adminId]) + ->andWhere(['shift_id' => $shiftIdForDict]) + ; + + if (!empty($storeId)) { + if (!$notInStore) { + $queryOtherAdminDay->andWhere(['=', 'timetable_fact.store_id', $storeId]); + } else { + $queryOtherAdminDay->andWhere(['<>', 'timetable_fact.store_id', $storeId]); + } + } + + $adminTablePrepared2 = $queryOtherAdminDay->asArray()->all(); + + $dateArray = []; + + $adminTable2 = []; + + foreach ($adminTablePrepared2 as $item) { + if (in_array($item['date_shift'], $dateArray)) { + continue; + } else { + $dateArray[] = $item['date_shift']; + $adminTable2[] = $item; + } + } + + $adminTableDateColumn2 = array_values(ArrayHelper::getColumn($adminTable2, 'date_shift')); + $adminTableIdDay = array_values(ArrayHelper::getColumn($adminTable2, 'id')); + $adminTableNight = array_values($adminTableDateColumn2); + + $adminTableDaysLast = array_unique(array_merge($adminTableNight, $adminTableDays)); + sort($adminTableDaysLast); + + /** @var TimetableFactModel[] $timetable */ + $queryOtherAdminNight = TimetableFactModel::find() + ->select(['date_shift' => new \yii\db\Expression("DISTINCT(date_shift)"), 'id']) + ->andWhere(['>=', 'date_shift', $dateFrom]) + ->andWhere(['<=', 'date_shift', $dateTo]) + ->andWhere(['not in', 'date_shift', $adminTableDaysLast]) + ->andWhere(['<>', 'admin_id', $adminId]) + ->andWhere(['shift_id' => $shiftIdForDict]) + ; + if (!empty($storeId)) { + if (!$notInStore) { + $queryOtherAdminNight->andWhere(['=', 'timetable_fact.store_id', $storeId]); + } else { + $queryOtherAdminNight->andWhere(['<>', 'timetable_fact.store_id', $storeId]); + } + } + + $adminTable3 = $queryOtherAdminNight->asArray()->all(); + $adminTableIdNight = array_values(ArrayHelper::getColumn($adminTable3, 'id')); + + $adminTableIds = array_merge($adminTableIdDay, $adminTableIdNight); + + /** @var TimetableFactModel[] $timetable */ + $query = TimetableFactModel::find() + ->indexBy('id') + ->with('admin') + ->andWhere(['>=', 'date_shift', $dateFrom]) + ->andWhere(['<=', 'date_shift', $dateTo]) + ->andWhere(['id' => $adminTableIds]) + ->andWhere(['shift_id' => $shiftIdForDict]) + ; + + if (!empty($storeId)) { + if (!$notInStore) { + $query->andWhere(['=', 'timetable_fact.store_id', $storeId]); + } else { + $query->andWhere(['<>', 'timetable_fact.store_id', $storeId]); + } + } + + $adminTableOtherAdmin = $query->asArray()->all(); + + $resultArray = array_merge($adminTable, $adminTableOtherAdmin); + $resultIds = ArrayHelper::getColumn($resultArray, 'id'); + $result = array_combine($resultIds, $resultArray); + + if (!empty($result)) { + // Сортировка по убыванию процентов + uasort( + $result, + + function ($a, $b) { + return (strtotime($a['date_shift']) - strtotime($b['date_shift'])); + } + ); + } + + foreach ($result as $key => $row) { + $result[$key]['date'] = $result[$key]['date_shift']; + } + + return $result; + } + + public function getTimetableAdministratorPlanData($adminId, $storeId, $dateFrom, $dateTo, bool $notInStore): array + { $slotTypeId = [ Timetable::TIMESLOT_WORK, // "работа" Timetable::TIMESLOT_SICK_LEAVE, // "больничный" @@ -3908,8 +4050,6 @@ Group BY admin_id ->andWhere(['tabel' => 0]) ; - - if (!empty($storeId)) { if (!$notInStore) { $query->andWhere(['=', 'store_id', $storeId]); @@ -4005,8 +4145,6 @@ Group BY admin_id ->andWhere(['tabel' => 0]) ; - - if (!empty($storeId)) { if (!$notInStore) { $query->andWhere(['=', 'store_id', $storeId]); @@ -4035,6 +4173,17 @@ Group BY admin_id return $result; } + public function getTimetableAdministratorData($adminId, $storeId, $dateFrom, $dateTo, bool $notInStore = false): array + { + if ($dateFrom >= '2024-07-01') { + $result = $this->getTimetableAdministratorFactData($adminId, $storeId, $dateFrom, $dateTo, $notInStore); + } else { + $result = $this->getTimetableAdministratorPlanData($adminId, $storeId, $dateFrom, $dateTo, $notInStore); + } + + return $result; + } + /** * @param $timeTabelType * @param $dateFrom