From: pavlikov_maxim Date: Thu, 23 May 2024 10:34:32 +0000 (+0300) Subject: изменение логики расчета зп, если был переход на др должность X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=refs%2Fheads%2Ffeature_pavlikov_20242305_payment_calculating;p=yii-erp24%2F.git изменение логики расчета зп, если был переход на др должность --- diff --git a/erp24/services/CabinetService.php b/erp24/services/CabinetService.php index f7274f2..de4a1e6 100755 --- a/erp24/services/CabinetService.php +++ b/erp24/services/CabinetService.php @@ -11,6 +11,8 @@ use yii_app\helpers\DateHelper; use yii_app\helpers\HtmlHelper; use yii_app\helpers\SalaryHelper; use yii_app\records\Admin; +use yii_app\records\AdminDynamic; +use yii_app\records\AdminGroup; use yii_app\records\AdminGroupDynamic; use yii_app\records\AdminPayroll; use yii_app\records\AdminPayrollValues; @@ -46,7 +48,8 @@ class CabinetService public bool $newVersion = false; public array $timeTableAdmin = []; - public function __construct($config = []) { + public function __construct($config = []) + { $this->salesService = new SalesService(); $this->ratingService = new RatingService(); $this->storePlanService = new StorePlanService(); @@ -172,7 +175,7 @@ class CabinetService ], ]; - private static function allowAddBonus($isAdministrator, $anotherStore, $changeGroup) : bool + private static function allowAddBonus($isAdministrator, $anotherStore, $changeGroup): bool { $result = true; @@ -187,7 +190,7 @@ class CabinetService return $result; } - private static function allowAddPersonBonus($adminGuid, $date, $isAdministrator, $adminDate) : bool + private static function allowAddPersonBonus($adminGuid, $date, $isAdministrator, $adminDate): bool { $result = true; @@ -387,7 +390,6 @@ class CabinetService } - public function getDataStatic( $employeeId, $employeeSelect, @@ -409,7 +411,7 @@ class CabinetService $employeePosition, $employeeAdminGroup, $cityStoreNames, - $paramDynamic) : array + $paramDynamic): array { if (!empty($employeeSelect['store_id'])) { @@ -430,7 +432,7 @@ class CabinetService } } - if (!array_key_exists($employeeId, $exportAdmin)){ + if (!array_key_exists($employeeId, $exportAdmin)) { $errorText = 'У сотрудника "' . $employeeSelect['name_full'] . '" в ERP нет данных GUID из 1с employee_id : ' . $employeeId . '
'; $errorText .= 'Связь с 1с нужна для того, что бы посчитать продажи смены.
Обратитесь в HR отдел'; $outputCheckError = $this->outputCheckError($errorText, '', $controller); @@ -445,7 +447,7 @@ class CabinetService $employeeSelectStore = CityStore::getCityStoreById($employeeSelectStoreId); - if (!array_key_exists($employeeSelectStoreId, $exportCityStore)){ + if (!array_key_exists($employeeSelectStoreId, $exportCityStore)) { $errorText = 'По сотруднику "' . $employeeSelect['name_full'] . '" не найдена связь с магазином в 1с : id ' . $employeeSelectStoreId . '
'; $errorText .= 'Связь с магазином 1с нужна для того, что бы получить его планы'; @@ -492,21 +494,19 @@ class CabinetService } - $adminPayroll = AdminPayroll::find() ->andWhere(['admin_id' => $employeeId]) ->andWhere(['year' => $yearSelect]) ->andWhere(['month' => $monthSelect]) ->limit(1) - ->one() - ; + ->one(); $payrollId = $adminPayroll->getId(); $paramPayroll = AdminPayroll::getValues($payrollId); $paramDynamicTmp = $paramHybrid = $paramDynamic; $diffKeys = []; - foreach($paramDynamicTmp as $keyRow => $row) { + foreach ($paramDynamicTmp as $keyRow => $row) { if (array_key_exists($keyRow, $paramPayroll)) { if ($paramDynamic[$keyRow] != $paramPayroll[$keyRow]) { $diffKeys[] = $keyRow; @@ -589,7 +589,7 @@ class CabinetService } } - if (!array_key_exists($employeeId, $exportAdmin)){ + if (!array_key_exists($employeeId, $exportAdmin)) { $errorText = 'У сотрудника "' . $employeeSelect['name_full'] . '" в ERP нет данных GUID из 1с employee_id : ' . $employeeId . '
'; $errorText .= 'Связь с 1с нужна для того, что бы посчитать продажи смены.
Обратитесь в HR отдел'; $outputCheckError = $this->outputCheckError($errorText, '', $controller); @@ -600,11 +600,11 @@ class CabinetService } } - $adminGuid = $exportAdmin[$employeeId]; + $adminGuid = $exportAdmin[$employeeId]; $employeeSelectStore = CityStore::getCityStoreById($employeeSelectStoreId); - if (!array_key_exists($employeeSelectStoreId, $exportCityStore)){ + if (!array_key_exists($employeeSelectStoreId, $exportCityStore)) { $errorText = 'По сотруднику "' . $employeeSelect['name_full'] . '" не найдена связь с магазином в 1с : id ' . $employeeSelectStoreId . '
'; $errorText .= 'Связь с магазином 1с нужна для того, что бы получить его планы'; @@ -653,7 +653,7 @@ class CabinetService $salesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); $salesSummCurrentMonth = $this->getSalesSaleSum($dateFromBeginMonth, $dateToEndMonth, $entityCityStoreEmployeeSelect); - $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect,true); + $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect, true); $amountWriteOff = WriteOffs::getWriteOffByStore($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); @@ -701,7 +701,7 @@ class CabinetService $planPercent = 0; $planStoreMonthCalculatePercent = 0; if (!empty($salesByStore) && !empty($planMonthByStore)) { - $planPercent=round(100 * $salesByStore/$planMonthByStore,1); + $planPercent = round(100 * $salesByStore / $planMonthByStore, 1); } //sales_avg_check @@ -712,7 +712,6 @@ class CabinetService $salesListAvgCheck = $this->getSumListAvgCheck($employeeSelectStoreId, $dateFrom, $dateTo); - $timetableForMonth = $this->getTimetableData($employeeId, $employeeSelectStoreId, $dateFromBeginMonth, $dateTo); $allowedDate = ($dateFrom >= '2022-12-01'); @@ -750,11 +749,11 @@ class CabinetService $errorText .= 'за выбранный интервал с ' . $dateFrom . ' по ' . $dateTo . '
'; $errorText .= 'в графике смен не найдено cs1'; - $dateFromInfo=date("Y-m-d",time()-7*86400+7200); - $dateToInfo=date("Y-m-d",time()); + $dateFromInfo = date("Y-m-d", time() - 7 * 86400 + 7200); + $dateToInfo = date("Y-m-d", time()); $buttonParams = [ - 'url' => "/cabinet/person?DaysSearchForm[employeeId]=" . $employeeId . "&DaysSearchForm[dateFrom]=" . $dateFromInfo. "&DaysSearchForm[dateTo]=" . $dateToInfo, + 'url' => "/cabinet/person?DaysSearchForm[employeeId]=" . $employeeId . "&DaysSearchForm[dateFrom]=" . $dateFromInfo . "&DaysSearchForm[dateTo]=" . $dateToInfo, 'name' => 'за неделю', ]; @@ -840,7 +839,7 @@ class CabinetService } } - $planByDayFromRateInfo = min(ArrayHelper::getColumn($rateInfo,'condition')); + $planByDayFromRateInfo = min(ArrayHelper::getColumn($rateInfo, 'condition')); $planMonthFlorist = 0; $salaryFloristByDay = 0; @@ -862,7 +861,7 @@ class CabinetService $normalCountShiftArray = SalaryHelper::$normalCountShift; if (!empty($employeeSelect["group_id"])) { - if (Admin::ADMINISTRATOR_GROUP_ID == $employeeSelect["group_id"]){ + if (Admin::ADMINISTRATOR_GROUP_ID == $employeeSelect["group_id"]) { // у Администратора число смен равно количеству рабочих дней в месяце $normalCountShift = HtmlHelper::getWorkDays($monthSelect, $yearSelect); @@ -892,8 +891,8 @@ class CabinetService $leftWorkDayForMonth = $normalCountShiftValue - $worksDayByTableFromBeginMonth; } - if ($leftWorkDayForMonth > 0 ) { - $planAdminByDay = round(($planMonthFlorist - $salaryByAdminFromBeginMonth ) / $leftWorkDayForMonth, 1); + if ($leftWorkDayForMonth > 0) { + $planAdminByDay = round(($planMonthFlorist - $salaryByAdminFromBeginMonth) / $leftWorkDayForMonth, 1); } if (!empty($worksDayByTableFromBeginMonth)) { $salaryFloristByDay = round($salaryByAdminFromBeginMonth / $worksDayByTableFromBeginMonth, 1); @@ -901,7 +900,7 @@ class CabinetService $salaryFloristByDay = $salaryByAdminFromBeginMonth; } $planMonthCalculate = round($salaryFloristByDay * $normalCountShiftValue, 1); - $planMonthCalculatePercent = round(100 * $planMonthCalculate /$planMonthFlorist,1); + $planMonthCalculatePercent = round(100 * $planMonthCalculate / $planMonthFlorist, 1); } else { $leftWorkDayForMonth = 23; $normalCountShiftValue = 21; @@ -919,8 +918,8 @@ class CabinetService $leftWorkDayForMonth = $normalCountShiftValue - $worksDayByTableFromBeginMonth; } - if ($leftWorkDayForMonth > 0 ) { - $planAdminByDay = round(($planMonthAdministrator - $salaryByAdminFromBeginMonth ) / $leftWorkDayForMonth, 1); + if ($leftWorkDayForMonth > 0) { + $planAdminByDay = round(($planMonthAdministrator - $salaryByAdminFromBeginMonth) / $leftWorkDayForMonth, 1); } if (!empty($worksDayByTableFromBeginMonth)) { $salaryAdministratorByDay = round($salaryByAdminFromBeginMonth / $worksDayByTableFromBeginMonth, 1); @@ -928,7 +927,7 @@ class CabinetService $salaryAdministratorByDay = $salaryByAdmin; } $planMonthCalculate = round($salaryAdministratorByDay * $normalCountShiftValue, 1); - $planMonthCalculatePercent = round(100 * $planMonthCalculate /$planMonthAdministrator,1); + $planMonthCalculatePercent = round(100 * $planMonthCalculate / $planMonthAdministrator, 1); $administratorOklad = $this->bonusService->getAdministratorOklad($planMonthCalculate); } @@ -939,7 +938,7 @@ class CabinetService && $monthSelect == date("n") ) { $showBlockForecast = true; - $dayPastCurrentMonth = (int) date("d"); + $dayPastCurrentMonth = (int)date("d"); $daysRemainsInSelectMonth = $daysInSelectMonth - $dayPastCurrentMonth; if (!empty($planMonthByStore)) { @@ -949,10 +948,10 @@ class CabinetService if (isset($salesByStore) && !empty($planMonthByStore)) { $saleByDayCalculate = round($salesByStore / $dayPastCurrentMonth, 1); $saleByMonthCalculate = $saleByDayCalculate * $daysInSelectMonth; - $planStoreMonthCalculatePercent = round(100 * $saleByMonthCalculate/$planMonthByStore,1); + $planStoreMonthCalculatePercent = round(100 * $saleByMonthCalculate / $planMonthByStore, 1); - if ($daysRemainsInSelectMonth > 0 ) { - $needSaleByDayCalculate = round(($planMonthByStore - $salesByStore ) / $daysRemainsInSelectMonth, 1); + if ($daysRemainsInSelectMonth > 0) { + $needSaleByDayCalculate = round(($planMonthByStore - $salesByStore) / $daysRemainsInSelectMonth, 1); } } @@ -966,7 +965,7 @@ class CabinetService $showBlockForecast = true; if (isset($salesByStore) && !empty($planMonthByStore)) { - $planStoreMonthCalculatePercent = round(100 * $salesByStore/$planMonthByStore,1); + $planStoreMonthCalculatePercent = round(100 * $salesByStore / $planMonthByStore, 1); } } @@ -1098,10 +1097,10 @@ class CabinetService $deltaYearToYearByMonthSalesSummPercent = ArrayHelper::getValue($deltaYearToYearByMonthSalesSummValues, 'deltaPercent'); $salesSummPastYearMonth = ArrayHelper::getValue($deltaYearToYearByMonthSalesSummValues, 'salesSummPastYearMonth'); - $dateCurrent = date("Y-m-d",time()); + $dateCurrent = date("Y-m-d", time()); - $yearCurrent = date("Y",strtotime($dateCurrent)); - $monthCurrent = date("n",strtotime($dateCurrent)); + $yearCurrent = date("Y", strtotime($dateCurrent)); + $monthCurrent = date("n", strtotime($dateCurrent)); // Возможное депремирование администратору @@ -1220,7 +1219,7 @@ class CabinetService if (!empty($personColorRubleBonuses)) { $personColorRubleBonusesValues = [ - ' премия в цвето-рублях' => (int) $personColorRubleBonuses, + ' премия в цвето-рублях' => (int)$personColorRubleBonuses, ]; } @@ -1240,7 +1239,6 @@ class CabinetService $adminSumGameAvgSum = ArrayHelper::getValue($adminSumGameBonusArrayMainStoreWithPersonalBonuses, 'adminSumGameAvgSumTotal'); - $adminSumGameBonusArray = $adminSumGameBonusArrayMainStoreWithPersonalBonuses; if (!empty($timetableAdminAnotherStore) && !empty($adminSumGameBonusArrayMainStoreWithPersonalBonuses)) { @@ -1279,7 +1277,7 @@ class CabinetService && count($timetableAdmin) >= 7 ) { - $this->ratingService->setRatingValue($employeeId, $adminSumGameBonusArrayMainStoreWithPersonalBonuses, $ratingId, $yearSelect, $monthSelect,$monthWithZeroSelect); + $this->ratingService->setRatingValue($employeeId, $adminSumGameBonusArrayMainStoreWithPersonalBonuses, $ratingId, $yearSelect, $monthSelect, $monthWithZeroSelect); if ($calculatePersonalRating) { $this->ratingService->calculateRating($yearSelect, $monthWithZeroSelect); } @@ -1294,39 +1292,39 @@ class CabinetService $isShowBonusOtherItems = ($dateFrom >= $dateStartBonusOtherItems); - $arrayTypes = ["wrap", "potted", "related","services","salut"]; + $arrayTypes = ["wrap", "potted", "related", "services", "salut"]; if ($isShowBonusOtherItems) { $arrayTypes = array_merge($arrayTypes, ["other_items"]); } - $arrayProducts= Products1c::getProductsFromClass($arrayTypes); + $arrayProducts = Products1c::getProductsFromClass($arrayTypes); $this->arr = [$adminGuid]; $adminGuidArr = $this->arr; if (!empty($arrayProducts["services"])) { - $arrUsersSalaryServicesPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["services"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); + $arrUsersSalaryServicesPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["services"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); $arrUsersSalaryServices = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'bonus'); $arrUsersSalaryServicesCheck = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'check'); } if (!empty($arrayProducts["related"])) { - $arrUsersSalaryRelatedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["related"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); + $arrUsersSalaryRelatedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["related"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); $arrUsersSalaryRelated = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'bonus'); $arrUsersSalaryRelatedCheck = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'check'); } if (!empty($arrayProducts["potted"])) { - $arrUsersSalaryPottedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["potted"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); + $arrUsersSalaryPottedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["potted"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); $arrUsersSalaryPotted = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'bonus'); $arrUsersSalaryPottedCheck = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'check'); } if (!empty($arrayProducts["wrap"])) { - $arrUsersSalaryWrapPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["wrap"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); + $arrUsersSalaryWrapPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["wrap"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); $arrUsersSalaryWrap = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'bonus'); $arrUsersSalaryWrapCheck = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'check'); } if (!empty($arrayProducts["other_items"])) { - $arrUsersSalaryOtherItemsPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["other_items"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); + $arrUsersSalaryOtherItemsPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["other_items"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator); $arrUsersSalaryOtherItems = ArrayHelper::getColumn($arrUsersSalaryOtherItemsPrepared, 'bonus'); $arrUsersSalaryOtherItemsCheck = ArrayHelper::getColumn($arrUsersSalaryOtherItemsPrepared, 'check'); } @@ -1338,7 +1336,7 @@ class CabinetService $dateToSalutInterval = ArrayHelper::getValue($dateFromToSalutArray, 'dateTo'); if (!empty($dateFromSalutInterval) && !empty($dateToSalutInterval)) { - $arrUsersSalarySalut = SalaryHelper::getSalaryBonusSalut($arrayProducts["salut"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator, $employeeSelectStoreId); + $arrUsersSalarySalut = SalaryHelper::getSalaryBonusSalut($arrayProducts["salut"], $adminGuidArr, $dateFrom, $dateTo, $exportAdmin, $isAdministrator, $employeeSelectStoreId); } } } @@ -1396,9 +1394,9 @@ class CabinetService $userSalaryPottedPremium = round($userSalaryPotted * 0.05); $userSalaryWrapPremium = round($userSalaryWrap * 0.05); // 5% за личные продажи упаковки - $userSalarySalutPremium = round($userSalarySalut * 0.05); // 5% за личные продажи пиротехники + $userSalarySalutPremium = round($userSalarySalut * 0.05); // 5% за личные продажи пиротехники - $userSalaryOtherItemsPremium = round($userSalaryOtherItems * 0.01); // 1% за личные продажи не фокусной продукции (Другме товары) + $userSalaryOtherItemsPremium = round($userSalaryOtherItems * 0.01); // 1% за личные продажи не фокусной продукции (Другме товары) //Букеты по матрице $enableTransform = ($dateFrom < '2022-12-07' && $dateTo > '2022-12-07'); @@ -1408,13 +1406,13 @@ class CabinetService $salesMatrixPart2 = $this->salesService->getMatrixSalesProducts($adminGuid, '2022-12-08', $dateTo, $isAdministrator); $salesMatrix = array_merge($salesMatrixPart1, $salesMatrixPart2); } else { - $salesMatrix = $this->salesService->getMatrixSalesProducts($adminGuid, $dateFrom, $dateTo, $isAdministrator); + $salesMatrix = $this->salesService->getMatrixSalesProducts($adminGuid, $dateFrom, $dateTo, $isAdministrator); } $salesMatrixProductGuids = ArrayHelper::getColumn($salesMatrix, 'product_guid'); $salesMatrixProducts = Products1c::getProducts1cByType('products', $salesMatrixProductGuids); - $salesMatrixProductNames = ArrayHelper::map($salesMatrixProducts, 'id','name'); + $salesMatrixProductNames = ArrayHelper::map($salesMatrixProducts, 'id', 'name'); $salaryMatrix = 0; $bonusSalaryMatrix = 0; @@ -1423,10 +1421,10 @@ class CabinetService $matrixBonusCoefficientRow = $this->bonusService->getMatrixBonusCoefficient($row['date']); $rowBonus = $row["summ"] * $matrixBonusCoefficientRow; $salesMatrix[$keySalesMatrix]["bonus"] = $rowBonus; - if($row["operation"] == Sales::OPERATION_SALE) { + if ($row["operation"] == Sales::OPERATION_SALE) { $salaryMatrix += $row["summ"]; $bonusSalaryMatrix += $rowBonus; - } elseif($row["operation"] == Sales::OPERATION_RETURN) { + } elseif ($row["operation"] == Sales::OPERATION_RETURN) { $salaryMatrix -= $row["summ"]; $bonusSalaryMatrix -= $rowBonus; } @@ -1444,12 +1442,12 @@ class CabinetService $makeMatrixPart2 = $this->salesService->getMatrixMakeProducts($adminGuid, '2022-12-08', $dateTo, $isAdministrator); $makeMatrix = array_merge($makeMatrixPart1, $makeMatrixPart2); } else { - $makeMatrix = $this->salesService->getMatrixMakeProducts($adminGuid, $dateFrom, $dateTo, $isAdministrator); + $makeMatrix = $this->salesService->getMatrixMakeProducts($adminGuid, $dateFrom, $dateTo, $isAdministrator); } $makeMatrixProductGuids = ArrayHelper::getColumn($makeMatrix, 'product_guid'); $makeMatrixProducts = Products1c::getProducts1cByType('products', $makeMatrixProductGuids); - $makeMatrixProductNames = ArrayHelper::map($makeMatrixProducts, 'id','name'); + $makeMatrixProductNames = ArrayHelper::map($makeMatrixProducts, 'id', 'name'); $salaryMakeMatrix = 0; $bonusMakeMatrix = 0; @@ -1458,10 +1456,10 @@ class CabinetService $matrixBonusCoefficientRow = $this->bonusService->getMatrixBonusCoefficient($row['date']); $rowBonus = $row["summ"] * $matrixBonusCoefficientRow; $makeMatrix[$kayMakeMatrix]["bonus"] = $rowBonus; - if($row["operation"] == Sales::OPERATION_SALE) { + if ($row["operation"] == Sales::OPERATION_SALE) { $salaryMakeMatrix += $row["summ"]; $bonusMakeMatrix += $rowBonus; - } elseif($row["operation"] == Sales::OPERATION_RETURN) { + } elseif ($row["operation"] == Sales::OPERATION_RETURN) { $salaryMakeMatrix -= $row["summ"]; $bonusMakeMatrix -= $rowBonus; } @@ -1517,7 +1515,7 @@ class CabinetService if ($isAdministrator) { $arrayColumnWages = array( - 'Оклад за смены' => $sumColumnWages, + 'Оклад за смены' => $sumColumnWages, ); $sumValuesAdminAnotherStore = []; @@ -1526,7 +1524,7 @@ class CabinetService foreach ($wagesAdminAnotherStore as $storeKey => $item) { $storeNameRow = $storeKey; - if (array_key_exists($storeKey ,$cityStoreNames)) { + if (array_key_exists($storeKey, $cityStoreNames)) { $storeNameRow = $cityStoreNames[$storeKey]; } @@ -1537,14 +1535,14 @@ class CabinetService if (!empty($personBonuses)) { $personBonusesArrayInfo = [ - 'Персональная премия' => (int) $personBonuses, + 'Персональная премия' => (int)$personBonuses, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } if (!empty($personVacationPay)) { $personBonusesArrayInfo = [ - 'Оплата за отпуск ' . $personVacationDay. ' дня' => $personVacationPay, + 'Оплата за отпуск ' . $personVacationDay . ' дня' => $personVacationPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } @@ -1562,7 +1560,7 @@ class CabinetService // Премия администратору за переменные показатели //заплатка на бонус за процент списания 2022 12 - if ($yearSelect == 2022 && $monthSelect == 12 ) { + if ($yearSelect == 2022 && $monthSelect == 12) { $configBonusPercentLoss202212 = [ 29 => 0, // ул. Страж Революции, 1А 30 => 0, // ул. Пискунова 26/12 @@ -1576,10 +1574,10 @@ class CabinetService } $possibleSumValuesAdministrator = array( - 'Возможная премия за процент списания (' . $bonusByPercentLoss .' * ' . $coefficientPremium . ')' => $bonusByPercentLoss * $coefficientPremium, - 'Возможная премия администратору за выполнение плана салона (' . $bonusByPlanPercent .' * ' . $coefficientPremium . ')' => $bonusByPlanPercent * $coefficientPremium, - 'Возможная премия администратору за конверсию (' . $bonusByConvertionPercent .' * ' . $coefficientPremium . ')' => $bonusByConvertionPercent * $coefficientPremium, - 'Возможная премия администратору за рост покупок постоянными клиентами (' . $sumPrimeForLvtClients .' * ' . $coefficientPremium . ')' => $sumPrimeForLvtClients * $coefficientPremium, + 'Возможная премия за процент списания (' . $bonusByPercentLoss . ' * ' . $coefficientPremium . ')' => $bonusByPercentLoss * $coefficientPremium, + 'Возможная премия администратору за выполнение плана салона (' . $bonusByPlanPercent . ' * ' . $coefficientPremium . ')' => $bonusByPlanPercent * $coefficientPremium, + 'Возможная премия администратору за конверсию (' . $bonusByConvertionPercent . ' * ' . $coefficientPremium . ')' => $bonusByConvertionPercent * $coefficientPremium, + 'Возможная премия администратору за рост покупок постоянными клиентами (' . $sumPrimeForLvtClients . ' * ' . $coefficientPremium . ')' => $sumPrimeForLvtClients * $coefficientPremium, ); $allPossibleSumValuesAdministrator = array_sum($possibleSumValuesAdministrator); @@ -1696,7 +1694,7 @@ class CabinetService if (!empty($personVacationPay)) { $personBonusesArrayInfo = [ - 'Оплата за отпуск ' . $personVacationDay. ' дня' => $personVacationPay, + 'Оплата за отпуск ' . $personVacationDay . ' дня' => $personVacationPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } @@ -1715,7 +1713,7 @@ class CabinetService foreach ($wagesBonusNormaSmenaAnotherStore as $storeKey => $item) { $storeNameRow = $storeKey; - if (array_key_exists($storeKey ,$cityStoreNames)) { + if (array_key_exists($storeKey, $cityStoreNames)) { $storeNameRow = $cityStoreNames[$storeKey]; } @@ -1769,7 +1767,7 @@ class CabinetService $showRaznicaDoPlanaPerson = false; - if (1 === (int) date('d', strtotime($dateFrom))) { + if (1 === (int)date('d', strtotime($dateFrom))) { $showRaznicaDoPlanaPerson = true; } @@ -1819,7 +1817,7 @@ class CabinetService ]; $minusSum = array_merge($alreadyPay, $personRetentionArray); - $minusSumValue = array_sum($minusSum); + $minusSumValue = array_sum($minusSum); $toPayoff = $allTotalPayroll - $minusSumValue; return [ 'dateFrom' => $dateFrom, @@ -1915,7 +1913,7 @@ class CabinetService 'administratorOklad' => $administratorOklad, - 'planMonthFlorist' => $planMonthFlorist ?? 0 , + 'planMonthFlorist' => $planMonthFlorist ?? 0, 'salesMatrix' => $salesMatrix ?? [], 'salaryMatrix' => $salaryMatrix ?? 0, @@ -2107,7 +2105,7 @@ class CabinetService } } - if (!array_key_exists($employeeId, $exportAdmin)){ + if (!array_key_exists($employeeId, $exportAdmin)) { $errorText = 'У сотрудника "' . $employeeSelect['name_full'] . '" в ERP нет данных GUID из 1с employee_id : ' . $employeeId . '
'; $errorText .= 'Связь с 1с нужна для того, что бы посчитать продажи смены.
Обратитесь в HR отдел'; $outputCheckError = $this->outputCheckError($errorText, '', $controller); @@ -2122,7 +2120,7 @@ class CabinetService $employeeSelectStore = CityStore::getCityStoreById($employeeSelectStoreId); - if (!array_key_exists($employeeSelectStoreId, $exportCityStore)){ + if (!array_key_exists($employeeSelectStoreId, $exportCityStore)) { $errorText = 'По сотруднику "' . $employeeSelect['name_full'] . '" не найдена связь с магазином в 1с : id ' . $employeeSelectStoreId . '
'; $errorText .= 'Связь с магазином 1с нужна для того, что бы получить его планы'; @@ -2150,8 +2148,10 @@ class CabinetService } + $monthlySalary = EmployeePayment::getMonthlySalary($employeeId, $dateFrom); + // todo use method if (empty($monthlySalary)) { $errorText = 'У сотрудника "' . $employeeSelect['name_full'] . '" id ' . $employeeId . ' не указан оклад - обратитесь в HR отдел'; $errorText .= '
Оклад и стоимость рабочего дня'; @@ -2163,6 +2163,20 @@ class CabinetService } } + [$salary, $error] = $this->getChangingSalary($dateFrom, $dateTo, $employeeId); + if ($salary) { + $monthlySalary['monthly_salary'] = $salary; + } + if ($error) { + $outputCheckError = $this->outputCheckError($error, '', $controller); + if (array_key_exists('errorText', $outputCheckError)) { + return [ + 'errorText' => $outputCheckError['errorText'], + ]; + } + } + + $showPlanLeft = true; if ($dateTo > $dateToEndMonth) { $showPlanLeft = false; @@ -2171,7 +2185,7 @@ class CabinetService $salesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); $salesSummCurrentMonth = $this->getSalesSaleSum($dateFromBeginMonth, $dateToEndMonth, $entityCityStoreEmployeeSelect); - $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect,true); + $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect, true); $amountWriteOff = WriteOffs::getWriteOffByStore($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); @@ -2219,7 +2233,7 @@ class CabinetService $planPercent = 0; $planStoreMonthCalculatePercent = 0; if (!empty($salesByStore) && !empty($planMonthByStore)) { - $planPercent=round(100 * $salesByStore/$planMonthByStore,1); + $planPercent = round(100 * $salesByStore / $planMonthByStore, 1); } //sales_avg_check @@ -2230,7 +2244,6 @@ class CabinetService $salesListAvgCheck = $this->getSumListAvgCheck($employeeSelectStoreId, $dateFrom, $dateTo); - $timetableForMonth = $this->getTimetableData($employeeId, $employeeSelectStoreId, $dateFromBeginMonth, $dateTo); $allowedDate = ($dateFrom >= '2022-12-01'); @@ -2268,11 +2281,11 @@ class CabinetService $errorText .= 'за выбранный интервал с ' . $dateFrom . ' по ' . $dateTo . '
'; $errorText .= 'в графике смен не найдено cs1'; - $dateFromInfo=date("Y-m-d",time()-7*86400+7200); - $dateToInfo=date("Y-m-d",time()); + $dateFromInfo = date("Y-m-d", time() - 7 * 86400 + 7200); + $dateToInfo = date("Y-m-d", time()); $buttonParams = [ - 'url' => "/cabinet/person?DaysSearchForm[employeeId]=" . $employeeId . "&DaysSearchForm[dateFrom]=" . $dateFromInfo. "&DaysSearchForm[dateTo]=" . $dateToInfo, + 'url' => "/cabinet/person?DaysSearchForm[employeeId]=" . $employeeId . "&DaysSearchForm[dateFrom]=" . $dateFromInfo . "&DaysSearchForm[dateTo]=" . $dateToInfo, 'name' => 'за неделю', ]; @@ -2348,7 +2361,7 @@ class CabinetService $rateInfo = $this->rateStoreCategoryService->getRateInfo($employeeSelectStoreId, $employeeGroupId, $dateFrom, $dateTo); if (!empty($rateInfo)) { - $planByDayFromRateInfo = min(ArrayHelper::getColumn($rateInfo,'condition')); + $planByDayFromRateInfo = min(ArrayHelper::getColumn($rateInfo, 'condition')); } else { $planByDayFromRateInfo = 1; } @@ -2419,8 +2432,8 @@ class CabinetService $leftWorkDayForMonth = $normalCountShiftValue - $worksDayByTableFromBeginMonth; } - if ($leftWorkDayForMonth > 0 ) { - $planAdminByDay = round(($planMonthFlorist - $salaryByAdminFromBeginMonth ) / $leftWorkDayForMonth, 1); + if ($leftWorkDayForMonth > 0) { + $planAdminByDay = round(($planMonthFlorist - $salaryByAdminFromBeginMonth) / $leftWorkDayForMonth, 1); } if (!empty($worksDayByTableFromBeginMonth)) { $salaryFloristByDay = round($salaryByAdminFromBeginMonth / $worksDayByTableFromBeginMonth, 1); @@ -2428,7 +2441,7 @@ class CabinetService $salaryFloristByDay = $salaryByAdminFromBeginMonth; } $planMonthCalculate = round($salaryFloristByDay * $normalCountShiftValue, 1); - $planMonthCalculatePercent = round(100 * $planMonthCalculate /$planMonthFlorist,1); + $planMonthCalculatePercent = round(100 * $planMonthCalculate / $planMonthFlorist, 1); } else { $leftWorkDayForMonth = 23; $normalCountShiftValue = 21; @@ -2446,8 +2459,8 @@ class CabinetService $leftWorkDayForMonth = $normalCountShiftValue - $worksDayByTableFromBeginMonth; } - if ($leftWorkDayForMonth > 0 ) { - $planAdminByDay = round(($planMonthAdministrator - $salaryByAdminFromBeginMonth ) / $leftWorkDayForMonth, 1); + if ($leftWorkDayForMonth > 0) { + $planAdminByDay = round(($planMonthAdministrator - $salaryByAdminFromBeginMonth) / $leftWorkDayForMonth, 1); } if (!empty($worksDayByTableFromBeginMonth)) { $salaryAdministratorByDay = round($salaryByAdminFromBeginMonth / $worksDayByTableFromBeginMonth, 1); @@ -2455,7 +2468,7 @@ class CabinetService $salaryAdministratorByDay = $salaryByAdmin; } $planMonthCalculate = round($salaryAdministratorByDay * $normalCountShiftValue, 1); - $planMonthCalculatePercent = round(100 * $planMonthCalculate /$planMonthAdministrator,1); + $planMonthCalculatePercent = round(100 * $planMonthCalculate / $planMonthAdministrator, 1); $administratorOklad = $this->getAdministratorSalaryShift($employeeId, $dateFrom, $planMonthCalculate); } @@ -2466,7 +2479,7 @@ class CabinetService && $monthSelect == date("n") ) { $showBlockForecast = true; - $dayPastCurrentMonth = (int) date("d"); + $dayPastCurrentMonth = (int)date("d"); $daysRemainsInSelectMonth = $daysInSelectMonth - $dayPastCurrentMonth; if (!empty($planMonthByStore)) { @@ -2476,10 +2489,10 @@ class CabinetService if (isset($salesByStore) && !empty($planMonthByStore)) { $saleByDayCalculate = round($salesByStore / $dayPastCurrentMonth, 1); $saleByMonthCalculate = $saleByDayCalculate * $daysInSelectMonth; - $planStoreMonthCalculatePercent = round(100 * $saleByMonthCalculate/$planMonthByStore,1); + $planStoreMonthCalculatePercent = round(100 * $saleByMonthCalculate / $planMonthByStore, 1); - if ($daysRemainsInSelectMonth > 0 ) { - $needSaleByDayCalculate = round(($planMonthByStore - $salesByStore ) / $daysRemainsInSelectMonth, 1); + if ($daysRemainsInSelectMonth > 0) { + $needSaleByDayCalculate = round(($planMonthByStore - $salesByStore) / $daysRemainsInSelectMonth, 1); } } @@ -2493,7 +2506,7 @@ class CabinetService $showBlockForecast = true; if (isset($salesByStore) && !empty($planMonthByStore)) { - $planStoreMonthCalculatePercent = round(100 * $salesByStore/$planMonthByStore,1); + $planStoreMonthCalculatePercent = round(100 * $salesByStore / $planMonthByStore, 1); } } @@ -2644,10 +2657,10 @@ class CabinetService $deltaYearToYearByMonthSalesSummPercent = ArrayHelper::getValue($deltaYearToYearByMonthSalesSummValues, 'deltaPercent'); $salesSummPastYearMonth = ArrayHelper::getValue($deltaYearToYearByMonthSalesSummValues, 'salesSummPastYearMonth'); - $dateCurrent = date("Y-m-d",time()); + $dateCurrent = date("Y-m-d", time()); - $yearCurrent = date("Y",strtotime($dateCurrent)); - $monthCurrent = date("n",strtotime($dateCurrent)); + $yearCurrent = date("Y", strtotime($dateCurrent)); + $monthCurrent = date("n", strtotime($dateCurrent)); // Возможное депремирование администратору @@ -2754,7 +2767,7 @@ class CabinetService if (!empty($personColorRubleBonuses)) { $personColorRubleBonusesValues = [ - ' премия в цвето-рублях' => (int) $personColorRubleBonuses, + ' премия в цвето-рублях' => (int)$personColorRubleBonuses, ]; } @@ -2766,8 +2779,8 @@ class CabinetService // Командный бонус - $teamBonus = $this->bonusService->getTeamBonus( $employeeId, $employeeSelectStoreId, $entityCityStoreEmployeeSelect, $dateFrom, $dateToEndMonth); - $teamBonusDetail = json_encode($teamBonus,JSON_UNESCAPED_UNICODE); + $teamBonus = $this->bonusService->getTeamBonus($employeeId, $employeeSelectStoreId, $entityCityStoreEmployeeSelect, $dateFrom, $dateToEndMonth); + $teamBonusDetail = json_encode($teamBonus, JSON_UNESCAPED_UNICODE); $teamBonusValuePrepared = ArrayHelper::getValue($teamBonus, 'personPrimeFondStore'); $teamBonusValue = ($teamBonusValuePrepared > 0) ? $teamBonusValuePrepared : 0; @@ -2786,15 +2799,15 @@ class CabinetService $userQualityPremium = $this->bonusService->getBonusForQuality($userQualityPercent); - $arrayTypes = ["wrap", "potted", "related","services","salut","other_items"]; + $arrayTypes = ["wrap", "potted", "related", "services", "salut", "other_items"]; - $arrayProducts= Products1c::getProductsFromClass($arrayTypes); + $arrayProducts = Products1c::getProductsFromClass($arrayTypes); $this->arr = [$adminGuid]; $adminGuidArr = $this->arr; /**/ - $showHolidayVersion = HolidayService::getHolidayVersionShow($dateFrom, $dateTo); + $showHolidayVersion = HolidayService::getHolidayVersionShow($dateFrom, $dateTo); // $showHolidayVersion = false; /**/ @@ -2814,7 +2827,7 @@ class CabinetService $arrUsersSalary = ArrayHelper::getValue($arrResSalariesByFocusGroup, 'arrUsersSalary'); $arrUsersSalaryCheck = ArrayHelper::getValue($arrResSalariesByFocusGroup, 'arrUsersSalaryCheck'); - $premiumByFocusGroups = $this->getPremiumByFocusGroups($adminGuid, $arrUsersSalary, $dateFrom, $dateTo, $isAdministrator); + $premiumByFocusGroups = $this->getPremiumByFocusGroups($adminGuid, $arrUsersSalary, $dateFrom, $dateTo, $isAdministrator); $userSalaryServices = ArrayHelper::getValue($premiumByFocusGroups, 'userSalaryServices'); $userSalaryServicesPremium = ArrayHelper::getValue($premiumByFocusGroups, 'userSalaryServicesPremium'); @@ -2873,7 +2886,7 @@ class CabinetService $isAdministrator, $employeeSelectStoreId, $showHolidayVersion, -false + false ); $consolidatedArrUsersSalary = ArrayHelper::getValue($consolidatedArrResSalariesByFocusGroup, 'arrUsersSalary'); @@ -2881,7 +2894,7 @@ false $consolidatedAdminGuidDateArrByFocusGroup = ArrayHelper::getValue($consolidatedArrResSalariesByFocusGroup, 'adminGuidDateArrByFocusGroup'); - $consolidatedPremiumByFocusGroups = $this->getPremiumByFocusGroups($adminGuid, $consolidatedArrUsersSalary, $dateFrom, $dateTo, $isAdministrator); + $consolidatedPremiumByFocusGroups = $this->getPremiumByFocusGroups($adminGuid, $consolidatedArrUsersSalary, $dateFrom, $dateTo, $isAdministrator); $consolidatedUserSalaryServices = ArrayHelper::getValue($consolidatedPremiumByFocusGroups, 'userSalaryServices'); $consolidatedUserSalaryServicesPremium = ArrayHelper::getValue($consolidatedPremiumByFocusGroups, 'userSalaryServicesPremium'); @@ -2904,7 +2917,6 @@ false $consolidatedUserSalaryPremiumSum = ArrayHelper::getValue($consolidatedPremiumByFocusGroups, 'userSalaryPremiumSum'); - $adminGuidNames = Admin::getAdminGuidNames(); $consolidatedArrUsersSalaryCheckTmp = $consolidatedArrUsersSalaryCheck; @@ -2943,7 +2955,7 @@ false foreach ($consolidatedAdminGuidDateArrByFocusGroup as $subKey => $users) { $shiftCount[] = count($users); foreach ($users as $user) { - if (array_key_exists($user, $countByUser)){ + if (array_key_exists($user, $countByUser)) { ++$countByUser[$user]; } else { $countByUser[$user] = 1; @@ -2951,8 +2963,8 @@ false } } - $adminsHolidayShiftCount = array_sum($shiftCount) ; - $personHolidayShiftCount = $countByUser[$adminGuid] ?? 0; + $adminsHolidayShiftCount = array_sum($shiftCount); + $personHolidayShiftCount = $countByUser[$adminGuid] ?? 0; if (!empty($adminsHolidayShiftCount)) { $onePartHolidayPremium = $consolidatedPremiumByStore / $adminsHolidayShiftCount; } @@ -3005,7 +3017,7 @@ false foreach ($wagesAdminAnotherStore as $storeKey => $item) { $storeNameRow = $storeKey; - if (array_key_exists($storeKey ,$cityStoreNames)) { + if (array_key_exists($storeKey, $cityStoreNames)) { $storeNameRow = $cityStoreNames[$storeKey]; } @@ -3016,21 +3028,21 @@ false if (!empty($personBonuses)) { $personBonusesArrayInfo = [ - 'Персональная премия' => (int) $personBonuses, + 'Персональная премия' => (int)$personBonuses, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } if (!empty($personPartTimeJobHoursPay)) { $personBonusesArrayInfo = [ - 'Оплата подработок по часам' . ' ('. $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => (int) $personPartTimeJobHoursPay, + 'Оплата подработок по часам' . ' (' . $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => (int)$personPartTimeJobHoursPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } if (!empty($personVacationPay)) { $personBonusesArrayInfo = [ - 'Оплата за отпуск ' . $personVacationDay. ' дня' => $personVacationPay, + 'Оплата за отпуск ' . $personVacationDay . ' дня' => $personVacationPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } @@ -3048,7 +3060,7 @@ false // Премия администратору за переменные показатели //заплатка на бонус за процент списания 2022 12 - if ($yearSelect == 2022 && $monthSelect == 12 ) { + if ($yearSelect == 2022 && $monthSelect == 12) { $configBonusPercentLoss202212 = [ 29 => 0, // ул. Страж Революции, 1А 30 => 0, // ул. Пискунова 26/12 @@ -3061,8 +3073,7 @@ false } } - $possibleSumValuesAdministrator = array( - ); + $possibleSumValuesAdministrator = array(); $allPossibleSumValuesAdministrator = array_sum($possibleSumValuesAdministrator); @@ -3090,7 +3101,6 @@ false } - $allVariableSumValuesAdministrator = array_sum($variableSumValuesAdministrator); // Постоянные премии администратору @@ -3127,7 +3137,6 @@ false } - $bonusVariable = [ 'Премия за продажи услуг' => $userSalaryServicesPremium, // 'Премия за продажи сопутки' => $userSalaryRelatedPremium, // @@ -3162,7 +3171,7 @@ false if (!empty($personPartTimeJobHoursPay)) { $personBonusesArrayInfo = [ - 'Оплата подработок по часам' . ' ('. $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)'=> $personPartTimeJobHoursPay, + 'Оплата подработок по часам' . ' (' . $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => $personPartTimeJobHoursPay, ]; $bonusVariableByMonth = array_merge($personBonusesArrayInfo, $bonusVariableByMonth); } @@ -3218,14 +3227,14 @@ false if (!empty($personPartTimeJobHoursPay)) { $personBonusesArrayInfo = [ - 'Оплата подработок по часам' . ' ('. $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => (int) $personPartTimeJobHoursPay, + 'Оплата подработок по часам' . ' (' . $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => (int)$personPartTimeJobHoursPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } if (!empty($personVacationPay)) { $personBonusesArrayInfo = [ - 'Оплата за отпуск ' . $personVacationDay. ' дня' => $personVacationPay, + 'Оплата за отпуск ' . $personVacationDay . ' дня' => $personVacationPay, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } @@ -3244,7 +3253,7 @@ false foreach ($wagesBonusNormaSmenaAnotherStore as $storeKey => $item) { $storeNameRow = $storeKey; - if (array_key_exists($storeKey ,$cityStoreNames)) { + if (array_key_exists($storeKey, $cityStoreNames)) { $storeNameRow = $cityStoreNames[$storeKey]; } @@ -3269,8 +3278,6 @@ false ]; - - $bonusVariable = [ 'Премия за продажи услуг' => $userSalaryServicesPremium, // 'Премия за продажи сопутки' => $userSalaryRelatedPremium, // @@ -3306,7 +3313,7 @@ false if (!empty($personPartTimeJobHoursPay)) { $personBonusesArrayInfo = [ - 'Оплата подработок по часам' . ' ('. $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => $personPartTimeJobHoursPay, + 'Оплата подработок по часам' . ' (' . $personPartTimeJobHours . '*' . $hourPayment . ' руб/час из оклада)' => $personPartTimeJobHoursPay, ]; $bonusVariableByMonth = array_merge($personBonusesArrayInfo, $bonusVariableByMonth); } @@ -3325,7 +3332,7 @@ false $showRaznicaDoPlanaPerson = false; - if (1 === (int) date('d', strtotime($dateFrom))) { + if (1 === (int)date('d', strtotime($dateFrom))) { $showRaznicaDoPlanaPerson = true; } @@ -3365,10 +3372,10 @@ false $alreadyPaySum = array_sum($alreadyPay); $minusSum = array_merge($alreadyPay, $personRetentionArray); - $minusSumValue = array_sum($minusSum); + $minusSumValue = array_sum($minusSum); $toPayoff = $allTotalPayroll - $minusSumValue; - $allowShowPersonRetention = date('Y-m-d',time()) >= date('Y-m-t',strtotime($dateFrom)); + $allowShowPersonRetention = date('Y-m-d', time()) >= date('Y-m-t', strtotime($dateFrom)); return [ 'allowShowPersonRetention' => $allowShowPersonRetention, @@ -3475,7 +3482,7 @@ false 'administratorOklad' => $administratorOklad, - 'planMonthFlorist' => $planMonthFlorist ?? 0 , + 'planMonthFlorist' => $planMonthFlorist ?? 0, 'salesMatrix' => $salesMatrix ?? [], 'salaryMatrix' => $salaryMatrix ?? 0, @@ -3671,8 +3678,7 @@ false ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['admin_id' => $adminId]) ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); if (!empty($storeId)) { if (!$notInStore) { @@ -3702,17 +3708,14 @@ false /** @var Timetable[] $timetable */ $query = Timetable::find() - ->select([ 'admin_id', 'cnt' => new \yii\db\Expression(" COUNT(*) "), - ]) + ]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) - ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); if (!empty($adminId)) { $query->andWhere(['admin_id' => $adminId]); @@ -3723,6 +3726,7 @@ false return $query->asArray()->all(); } + public function getTimetableDataList($dateFrom, $dateTo, $adminId = null): array { @@ -3734,16 +3738,13 @@ false /** @var Timetable[] $timetable */ $query = Timetable::find() - ->select([ 'admin_id' - ]) + ]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) - ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); if (!empty($adminId)) { $query->andWhere(['admin_id' => $adminId]); @@ -3753,6 +3754,87 @@ false return $query->asArray()->all(); } + + /** + * Проверяет, что у сотрудника была смена должности в рамках периода + * Если смена была, то считает зп по дням, по каждой должности что были + * + * @param $dateFrom string + * @param $dateTo string + * @param $adminId int|string + * @return array + */ + private function getChangingSalary($dateFrom, $dateTo, $adminId) + { + $summary_salary = 0; + $error = ''; + $positions_history = []; + + // https://erp.erp-flowers.ru/crud/employee-payment/ + // если дата > месяца, то убирать кнопку редактирования + + // Проверяем наличие перехода в admin_dynamic + $positions = AdminDynamic::find()->where(['admin_id' => $adminId])->where(['category_id' => 1]) + ->where(['or', ['between', 'date_to', $dateFrom, $dateTo],['between', 'date_from', $dateFrom, $dateTo]])->asArray()->all(); + echo $adminId . '
' . print_r($positions, true) . '
'; +echo $dateFrom; +echo $dateTo; + if (count($positions)) { + // разбиваем период по дням, способ не самый быстрый, но лучший для подсчета + $date_list = $this->period_explode($dateFrom, $dateTo); + foreach ($date_list as $date) { + // проверяем, что в этот день у сотрудника была смена + $shift = Timetable::find()->where(['admin_id' => $adminId])->where(['date' => $date])->asArray()->one(); + if ($shift) { + // если была, то смотрим его ставку за день + // берем ближайшую запись + $daily_payment = EmployeePayment::find() + ->where(['admin_id' => $adminId])->where(['<=', 'date', $date]) + ->orderBy(['date' => SORT_DESC])->asArray()->one(); + if ($daily_payment) { + foreach ($positions as $position) { + if ($position['date_from'] <= $date && $position['date_to'] >= $date) { + $group = AdminGroup::find()->where(['id' =>$position['value_id']]); + $positions_history[] = [ + 'date' => $date, + + ]; + } + } + // плюсуем к общей зп + $summary_salary += $daily_payment['daily_payment']; + } else { + $error = 'По одной из должностей сотрудника не был найден оклад'; + } + } + } + } + + return [$summary_salary, $error]; + } + + /** + * Разбивает период дат по дням + * + * @param $dateFrom string + * @param $dateTo string + * @return array + */ + private function period_explode($dateFrom, $dateTo) + { + $dates_array = []; + $dates_array[] = $dateFrom; + $dateFrom = DateTime::createFromFormat('Y-m-d', $dateFrom); + $dateTo = DateTime::createFromFormat('Y-m-d', $dateTo); + + while ($dateFrom->getTimestamp() <= $dateTo->getTimestamp()) { + $dateFrom->modify('+1 day'); + $dates_array[] = $dateFrom->format('Y-m-d'); + } + + return $dates_array; + } + public function getTimetableAdminDataList($dateFrom, $dateTo, $adminId = null): array { @@ -3764,36 +3846,33 @@ false /** @var Timetable[] $timetable */ $query = Timetable::find() - ->select([ 'admin_id', 'date' - ]) + ]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) - ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); if (!empty($adminId)) { $query->andWhere(['admin_id' => $adminId]); } - $query->groupBy(['admin_id','date']); + $query->groupBy(['admin_id', 'date']); return $query->asArray()->all(); } public function getTimetableLastShift($adminGroupId = Admin::PART_TIME_WORKER_GROUP_ID) { - /* - * - SELECT admin_id,MAX(date) FROM timetable WHERE admin_group_id = 45 + /* + * + SELECT admin_id,MAX(date) FROM timetable WHERE admin_group_id = 45 -Group BY admin_id - * */ + Group BY admin_id + * */ /** @var Timetable[] $timetable */ $query = Timetable::find() @@ -3804,8 +3883,7 @@ Group BY admin_id ]]) ->andWhere(['tabel' => 0]) ->groupBy(['admin_id']) - ->indexBy(['admin_id']) - ; + ->indexBy(['admin_id']); $action = $query->createCommand()->getRawSql(); return $query->asArray()->all(); @@ -3833,9 +3911,7 @@ Group BY admin_id ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['admin_id' => $adminId]) ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; - + ->andWhere(['tabel' => 0]); if (!empty($storeId)) { @@ -3860,8 +3936,7 @@ Group BY admin_id ->andWhere(['<>', 'admin_id', $adminId]) ->andWhere(['slot_type_id' => $slotTypeId]) ->andWhere(['shift_id' => Shift::DAY]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); // $isNight = Shift::isNight($row['shift_id']); @@ -3904,8 +3979,7 @@ Group BY admin_id ->andWhere(['<>', 'admin_id', $adminId]) ->andWhere(['slot_type_id' => $slotTypeId]) ->andWhere(['shift_id' => Shift::NIGHT]) - ->andWhere(['tabel' => 0]) - ; + ->andWhere(['tabel' => 0]); // $isNight = Shift::isNight($row['shift_id']); @@ -3930,9 +4004,7 @@ Group BY admin_id ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['id' => $adminTableIds]) ->andWhere(['slot_type_id' => $slotTypeId]) - ->andWhere(['tabel' => 0]) - ; - + ->andWhere(['tabel' => 0]); if (!empty($storeId)) { @@ -3946,7 +4018,7 @@ Group BY admin_id $adminTableOtherAdmin = $query->asArray()->all(); $resultArray = array_merge($adminTable, $adminTableOtherAdmin); - $resultIds = ArrayHelper::getColumn($resultArray, 'id'); + $resultIds = ArrayHelper::getColumn($resultArray, 'id'); $result = array_combine($resultIds, $resultArray); if (!empty($result)) { @@ -3974,11 +4046,11 @@ Group BY admin_id $timetable = []; $dict = [ - 1 => [ 1, 5, 7, 8], - 2 => [ 2], - 5 => [ 1, 5, 7, 8], - 7 => [ 1, 5, 7, 8], - 8 => [ 1, 5, 7, 8], + 1 => [1, 5, 7, 8], + 2 => [2], + 5 => [1, 5, 7, 8], + 7 => [1, 5, 7, 8], + 8 => [1, 5, 7, 8], ]; $slotTypeId = [ @@ -3999,14 +4071,13 @@ Group BY admin_id $timetable = Timetable::find() ->joinWith('admin') ->andWhere(['date' => $date]) - ->andWhere(['<>','admin.group_id', -1]) + ->andWhere(['<>', 'admin.group_id', -1]) ->andWhere(['shift_id' => $shiftIdForDict]) ->andWhere(['timetable.store_id' => $storeId]) ->andWhere(['slot_type_id' => $slotTypeId]) ->andWhere(['tabel' => 0]) ->asArray() - ->all() - ; + ->all(); } return $timetable; @@ -4043,8 +4114,7 @@ Group BY admin_id ->andWhere(['tabel' => 0]) ->orderBy(new Expression('random()')) ->asArray() - ->one() - ; + ->one(); return $timetable; } @@ -4062,7 +4132,7 @@ Group BY admin_id * @return array * @throws \Exception */ - public function getTimetableRate($timetable ,$employeeId , $adminGuid, array $storeAdminsGuids, $dateFrom, $dateTo, $normalCostShift, bool $isAdministrator, $entityCityStoreEmployeeSelect = null): array + public function getTimetableRate($timetable, $employeeId, $adminGuid, array $storeAdminsGuids, $dateFrom, $dateTo, $normalCostShift, bool $isAdministrator, $entityCityStoreEmployeeSelect = null): array { $rateDict = RateDict::find() ->indexBy('id') @@ -4076,7 +4146,7 @@ Group BY admin_id $salesForAdmin = $this->getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator); $salesForStore = []; - if ($isAdministrator && $dateFrom >= '2023-09-01' ) { + if ($isAdministrator && $dateFrom >= '2023-09-01') { $salesForStore = $this->getSaluryStoreSum($entityCityStoreEmployeeSelect, $dateFrom, $dateTo, $isAdministrator); } @@ -4104,10 +4174,10 @@ Group BY admin_id $avgCheckByDay = []; foreach ($sales as $rowDate => $sale) { - if (!array_key_exists($rowDate, $avgCheckByDay)) { - $avgCheckByDay[$rowDate] = 0; - } - if($sale > 0 && $countByDate[$rowDate] > 0) { + if (!array_key_exists($rowDate, $avgCheckByDay)) { + $avgCheckByDay[$rowDate] = 0; + } + if ($sale > 0 && $countByDate[$rowDate] > 0) { $avgCheckByDay[$rowDate] = round($sale / $countByDate[$rowDate], 2); } } @@ -4115,7 +4185,7 @@ Group BY admin_id $adminIds = array_keys($storeAdminsGuids); $admins = Admin::find() - ->select(['id','store_id','group_id','name_full']) + ->select(['id', 'store_id', 'group_id', 'name_full']) ->indexBy('id') ->andWhere(['id' => $adminIds]) ->asArray() @@ -4128,7 +4198,7 @@ Group BY admin_id if (!empty($allStoreCategory[$storeKey])) { $storeCategoryId = $allStoreCategory[$storeKey]['category_id']; } else { - $errorText = 'Нет данных о категории магазина (rate_store_category) : ' . $storeKey ; + $errorText = 'Нет данных о категории магазина (rate_store_category) : ' . $storeKey; $errorText .= ' Попробуйте сократить интервал поиска до одного месяца, возможно был переход на новую нормо смену. '; $controller = Yii::$app->controller; $outputCheckError = $this->outputCheckError($errorText, '', $controller); @@ -4144,7 +4214,7 @@ Group BY admin_id $adminGroupIdRow = AdminGroupDynamic::getGroupByDate($adminId, $dateFrom, $dateTo); - if ( -1 === (int) $adminGroupIdRow ) { + if (-1 === (int)$adminGroupIdRow) { $adminGroupIdRow = Users::DAY_FLORIST_ID; } @@ -4180,7 +4250,7 @@ Group BY admin_id if (!empty($allStoreCategory[$row['store_id']])) { $storeCategoryId = $allStoreCategory[$row['store_id']]['category_id']; } else { - $errorText = 'Нет данных о категории магазина (rate_store_category) : ' . $row['store_id'] ; + $errorText = 'Нет данных о категории магазина (rate_store_category) : ' . $row['store_id']; $controller = Yii::$app->controller; $outputCheckError = $this->outputCheckError($errorText, '', $controller); if (array_key_exists('errorText', $outputCheckError)) { @@ -4333,7 +4403,7 @@ Group BY admin_id $adminsSalesSum = 0; - if ($isAdministrator && $row['date'] >= '2023-09-01' ) { + if ($isAdministrator && $row['date'] >= '2023-09-01') { if (!empty($salesForStore) && array_key_exists($row['date'], $salesForStore)) { $adminsSalesSum = $salesForStore[$row['date']]; } @@ -4411,7 +4481,7 @@ Group BY admin_id $timetable[$keyTimetable]['percentMatrixSalaryShiftStore'] = $percentMatrixSalaryShiftStore; $adminNameWithRateColumn = ArrayHelper::getColumn($rateTimetableAdminsNames, 'name_with_rate'); - $adminNameWithRateList = implode(',
' , $adminNameWithRateColumn); + $adminNameWithRateList = implode(',
', $adminNameWithRateColumn); $timetable[$keyTimetable]['typeSmena'] = $typeSmena; $timetable[$keyTimetable]['typeSmenaInt'] = $typeSmenaInt; @@ -4423,7 +4493,7 @@ Group BY admin_id $timetable[$keyTimetable]['firstNormaSmenaAdminSum'] = $firstNormaSmenaAdminSum; $timetable[$keyTimetable]['normaSmenaAdminsSumByLevel'] = $normaSmenaAdminsSumByLevel; - $normaSmenaAdminsSumByLevelList = implode(',
' , $normaSmenaAdminsSumByLevel); + $normaSmenaAdminsSumByLevelList = implode(',
', $normaSmenaAdminsSumByLevel); $timetable[$keyTimetable]['normaSmenaAdminsSumByLevelList'] = $normaSmenaAdminsSumByLevelList; $reteId = $this->bonusService->getWagesBonusNormaSmena($normaSmenaAdminsSumByLevel, $adminsSalesSum, false); @@ -4442,8 +4512,7 @@ Group BY admin_id // Расчет оклада в зависимоти от выполненной общей норма смены магазина $wagesAddBonusNormaSmena = 0; - switch ($rateNormaSmena['value_type_add']) - { + switch ($rateNormaSmena['value_type_add']) { case 'multiplier': $rateNormaValue = $normalCostShift * $rateNormaSmena['value']; $wagesAddBonusNormaSmena = $normalCostShift - $rateNormaValue; @@ -4476,12 +4545,12 @@ Group BY admin_id * @return array * @throws \Exception */ - public function getTimetableDate($timetable ,$employeeId , $adminGuid, array $storeAdminsGuids, $dateFrom, $dateTo, $normalCostShift, bool $isAdministrator, $entityCityStoreEmployeeSelect = null): array + public function getTimetableDate($timetable, $employeeId, $adminGuid, array $storeAdminsGuids, $dateFrom, $dateTo, $normalCostShift, bool $isAdministrator, $entityCityStoreEmployeeSelect = null): array { $salesForAdmin = $this->getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator); $salesForStore = []; - if ($isAdministrator && $dateFrom >= '2023-09-01' ) { + if ($isAdministrator && $dateFrom >= '2023-09-01') { $salesForStore = $this->getSaluryStoreSum($entityCityStoreEmployeeSelect, $dateFrom, $dateTo, $isAdministrator); } @@ -4512,7 +4581,7 @@ Group BY admin_id if (!array_key_exists($rowDate, $avgCheckByDay)) { $avgCheckByDay[$rowDate] = 0; } - if($sale > 0 && $countByDate[$rowDate] > 0) { + if ($sale > 0 && $countByDate[$rowDate] > 0) { $avgCheckByDay[$rowDate] = round($sale / $countByDate[$rowDate], 2); } } @@ -4520,7 +4589,7 @@ Group BY admin_id $adminIds = array_keys($storeAdminsGuids); $admins = Admin::find() - ->select(['id','store_id','group_id','name_full']) + ->select(['id', 'store_id', 'group_id', 'name_full']) ->indexBy('id') ->andWhere(['id' => $adminIds]) ->asArray() @@ -4536,12 +4605,11 @@ Group BY admin_id $adminGroupIdRow = AdminGroupDynamic::getGroupByDate($adminId, $dateFrom, $dateTo); - if ( -1 === (int) $adminGroupIdRow ) { + if (-1 === (int)$adminGroupIdRow) { $adminGroupIdRow = Users::DAY_FLORIST_ID; } - $salesAdmins[$adminId] = [ 'id' => $adminId, 'group_id' => $adminGroupIdRow, @@ -4574,8 +4642,6 @@ Group BY admin_id } - - $daySale = 0; $timetable[$keyTimetable]['wagesInfo'] = ''; $wagesInfo = ''; @@ -4654,7 +4720,7 @@ Group BY admin_id $adminsSalesSum = 0; - if ($isAdministrator && $row['date'] >= '2023-09-01' ) { + if ($isAdministrator && $row['date'] >= '2023-09-01') { if (!empty($salesForStore) && array_key_exists($row['date'], $salesForStore)) { $adminsSalesSum = $salesForStore[$row['date']]; } @@ -4690,7 +4756,7 @@ Group BY admin_id } $adminNameColumn = ArrayHelper::getColumn($rateTimetableAdminsNames, 'name'); - $adminNameList = implode(',
' , $adminNameColumn); + $adminNameList = implode(',
', $adminNameColumn); $timetable[$keyTimetable]['typeSmena'] = $typeSmena . $wagesInfo; $timetable[$keyTimetable]['adminNameList'] = $adminNameList; @@ -4725,7 +4791,7 @@ Group BY admin_id $dateCheckRow = new DateTime($dateRow); $startDate = new DateTime($dateFromRow); - $endDate = new DateTime($dateToRow.' 23:59'); + $endDate = new DateTime($dateToRow . ' 23:59'); $isDateBetweenDates = DateHelper::isDateBetweenDates($dateCheckRow, $startDate, $endDate); if ($isDateBetweenDates) { @@ -4748,7 +4814,7 @@ Group BY admin_id $salaryStoreServicesPercentList, $winStoreIdDayChallenge, $anotherStore = false - ) : array + ): array { $timetableTemp = $timetable; @@ -4836,7 +4902,7 @@ Group BY admin_id $salaryStoreServicesPercent = $salaryStoreServicesPercentList[$row['date']]['summ']; } - $arrayProducts= Products1c::getProductsFromClass(["wrap", "potted", "related","services"]); + $arrayProducts = Products1c::getProductsFromClass(["wrap", "potted", "related", "services"]); $changeGroup = $this->changeGroup; $allowAddBonus = self::allowAddBonus($isAdministrator, $anotherStore, $changeGroup); @@ -4863,7 +4929,7 @@ Group BY admin_id $gameBonusAvgCheck = $this->bonusService->getGameBonusAvgCheck($avgCheck); // Бонус геймификации дневной челленж - $gameBonusDayChallengeArray = $this->bonusService->getGameBonusDayChallenge($row['store_id'], $winStoreIdDayChallenge , $row['date']); + $gameBonusDayChallengeArray = $this->bonusService->getGameBonusDayChallenge($row['store_id'], $winStoreIdDayChallenge, $row['date']); $gameBonusDayChallenge = 0; if ($allowAddBonus) { @@ -4901,39 +4967,39 @@ Group BY admin_id $salaryServicesPercent = 0; if (!empty($arrayProducts["services"]) && !empty($daySale)) { - $arrUsersSalaryServicesPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["services"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); + $arrUsersSalaryServicesPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["services"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); $arrUsersSalaryServices = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'bonus'); $arrUsersSalaryServicesCheck = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'check'); if (!empty($arrUsersSalaryServices)) { - $salaryServicesPercent = round(100 * $arrUsersSalaryServices[$adminGuid]/$daySale,1); + $salaryServicesPercent = round(100 * $arrUsersSalaryServices[$adminGuid] / $daySale, 1); } } $salaryWrapPercent = 0; if (!empty($arrayProducts["wrap"]) && !empty($daySale)) { - $arrUsersSalaryWrapPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["wrap"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); + $arrUsersSalaryWrapPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["wrap"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); $arrUsersSalaryWrap = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'bonus'); $arrUsersSalaryWrapCheck = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'check'); if (!empty($arrUsersSalaryWrap)) { - $salaryWrapPercent = round(100 * $arrUsersSalaryWrap[$adminGuid]/$daySale,1); + $salaryWrapPercent = round(100 * $arrUsersSalaryWrap[$adminGuid] / $daySale, 1); } } $salaryPottedPercent = 0; if (!empty($arrayProducts["potted"]) && !empty($daySale)) { - $arrUsersSalaryPottedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["potted"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); + $arrUsersSalaryPottedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["potted"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); $arrUsersSalaryPotted = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'bonus'); $arrUsersSalaryPottedCheck = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'check'); if (!empty($arrUsersSalaryPotted)) { - $salaryPottedPercent = round(100 * $arrUsersSalaryPotted[$adminGuid]/$daySale,1); + $salaryPottedPercent = round(100 * $arrUsersSalaryPotted[$adminGuid] / $daySale, 1); } } $salaryRelatedPercent = 0; if (!empty($arrayProducts["related"]) && !empty($daySale)) { - $arrUsersSalaryRelatedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["related"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); + $arrUsersSalaryRelatedPrepared = SalaryHelper::getSalaryBonusMulty($arrayProducts["related"], $adminGuidArr, $row['date'], $row['date'], $exportAdmin, $isAdministrator); $arrUsersSalaryRelated = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'bonus'); $arrUsersSalaryRelatedCheck = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'check'); if (!empty($arrUsersSalaryRelated)) { - $salaryRelatedPercent = round(100 * $arrUsersSalaryRelated[$adminGuid]/$daySale,1); + $salaryRelatedPercent = round(100 * $arrUsersSalaryRelated[$adminGuid] / $daySale, 1); } } @@ -5023,7 +5089,7 @@ Group BY admin_id ], ]; - if ('2023-08-01' <= date("Y-m-d H:i:s", strtotime($row['date']))){ + if ('2023-08-01' <= date("Y-m-d H:i:s", strtotime($row['date']))) { $floristAddValues = [ 'Бонус за выполнение персональной нормо смены' => [ 'value' => $gameBonusNormaSmenaReteLavel, @@ -5050,8 +5116,8 @@ Group BY admin_id ], ]; - if ('2022-12-01' <= date("Y-m-d H:i:s", strtotime($row['date']))){ - if (date("Y-m-d H:i:s", strtotime($row['date'])) < '2022-12-10'){ + if ('2022-12-01' <= date("Y-m-d H:i:s", strtotime($row['date']))) { + if (date("Y-m-d H:i:s", strtotime($row['date'])) < '2022-12-10') { $gameBonusCashSalaryStore = 0; $percentCheckWithCash = 0; } @@ -5064,12 +5130,12 @@ Group BY admin_id $administratorValues = array_merge($administratorValues, $administratorAddValues); - if ('2023-06-01' <= date("Y-m-d H:i:s", strtotime($row['date']))){ + if ('2023-06-01' <= date("Y-m-d H:i:s", strtotime($row['date']))) { $floristValues = array_merge($floristValues, $administratorAddValues); } } - if ('2023-06-01' <= date("Y-m-d H:i:s", strtotime($row['date']))){ + if ('2023-06-01' <= date("Y-m-d H:i:s", strtotime($row['date']))) { $floristBonusAddValues = [ 'Бонус за % продаж матрицы' => [ 'value' => $gameBonusMatrixSalaryShiftStore, @@ -5110,7 +5176,7 @@ Group BY admin_id $salaryStoreServicesPercentList, $winStoreIdDayChallenge, $anotherStore = false - ) : array + ): array { @@ -5118,7 +5184,7 @@ Group BY admin_id } - public function __setGameValuesAnotherStore($timetable, $adminGuid, $exportAdmin, $isAdministrator, $conversionArray, $bonusCardPercentList, $salesAvgCheckList, $salaryStoreServicesPercentList, $winStoreIdDayChallenge) : array + public function __setGameValuesAnotherStore($timetable, $adminGuid, $exportAdmin, $isAdministrator, $conversionArray, $bonusCardPercentList, $salesAvgCheckList, $salaryStoreServicesPercentList, $winStoreIdDayChallenge): array { $timetableTemp = $timetable; @@ -5176,7 +5242,7 @@ Group BY admin_id $salaryStoreServicesPercent = $salaryStoreServicesPercentList[$row['date']]['summ']; } - $arrayProducts= Products1c::getProductsFromClass(["wrap", "potted", "related","services"]); + $arrayProducts = Products1c::getProductsFromClass(["wrap", "potted", "related", "services"]); // Персональный бонус геймификации за выполнение норма смены $gameBonusNormaPerson = $this->bonusService->getGameBonusByRate($reteIdPerson, $daySale, $normaSmenaRate1Condition); @@ -5188,7 +5254,7 @@ Group BY admin_id $gameBonusAvgCheck = $this->bonusService->getGameBonusAvgCheck($avgCheck); // Бонус геймификации дневной челленж - $gameBonusDayChallengeArray = $this->bonusService->getGameBonusDayChallenge($row['store_id'], $winStoreIdDayChallenge , $row['date']); + $gameBonusDayChallengeArray = $this->bonusService->getGameBonusDayChallenge($row['store_id'], $winStoreIdDayChallenge, $row['date']); $gameBonusDayChallenge = ArrayHelper::getValue($gameBonusDayChallengeArray, 'bonus'); $gameBonusDayChallengeValue = ArrayHelper::getValue($gameBonusDayChallengeArray, 'value'); @@ -5214,7 +5280,7 @@ Group BY admin_id $arrUsersSalaryServices = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'bonus'); $arrUsersSalaryServicesCheck = ArrayHelper::getColumn($arrUsersSalaryServicesPrepared, 'check'); if (!empty($arrUsersSalaryServices)) { - $salaryServicesPercent = round(100 * $arrUsersSalaryServices[$adminGuid]/$daySale,1); + $salaryServicesPercent = round(100 * $arrUsersSalaryServices[$adminGuid] / $daySale, 1); } } $salaryWrapPercent = 0; @@ -5223,7 +5289,7 @@ Group BY admin_id $arrUsersSalaryWrap = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'bonus'); $arrUsersSalaryWrapCheck = ArrayHelper::getColumn($arrUsersSalaryWrapPrepared, 'check'); if (!empty($arrUsersSalaryWrap)) { - $salaryWrapPercent = round(100 * $arrUsersSalaryWrap[$adminGuid]/$daySale,1); + $salaryWrapPercent = round(100 * $arrUsersSalaryWrap[$adminGuid] / $daySale, 1); } } $salaryPottedPercent = 0; @@ -5232,7 +5298,7 @@ Group BY admin_id $arrUsersSalaryPotted = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'bonus'); $arrUsersSalaryPottedCheck = ArrayHelper::getColumn($arrUsersSalaryPottedPrepared, 'check'); if (!empty($arrUsersSalaryPotted)) { - $salaryPottedPercent = round(100 * $arrUsersSalaryPotted[$adminGuid]/$daySale,1); + $salaryPottedPercent = round(100 * $arrUsersSalaryPotted[$adminGuid] / $daySale, 1); } } $salaryRelatedPercent = 0; @@ -5241,7 +5307,7 @@ Group BY admin_id $arrUsersSalaryRelated = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'bonus'); $arrUsersSalaryRelatedCheck = ArrayHelper::getColumn($arrUsersSalaryRelatedPrepared, 'check'); if (!empty($arrUsersSalaryRelated)) { - $salaryRelatedPercent = round(100 * $arrUsersSalaryRelated[$adminGuid]/$daySale,1); + $salaryRelatedPercent = round(100 * $arrUsersSalaryRelated[$adminGuid] / $daySale, 1); } } @@ -5321,7 +5387,7 @@ Group BY admin_id ]; - if ('2022-12-01' <= date("Y-m-d H:i:s", strtotime($row['date']))){ + if ('2022-12-01' <= date("Y-m-d H:i:s", strtotime($row['date']))) { $administratorAddValues = [ 'Бонус за % чеков с оплатой наличными' => [ 'value' => $gameBonusPercenrCashInChecks, @@ -5352,7 +5418,7 @@ Group BY admin_id } - public function getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator) : array + public function getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator): array { $salesByAdminPrepared = $this->salesService->getSalesByAdmin($adminGuid, $dateFrom, $dateTo, $isAdministrator); @@ -5371,7 +5437,7 @@ Group BY admin_id } - public function getSaluryStoreSum($storeId1c, $dateFrom, $dateTo, $isAdministrator) : array + public function getSaluryStoreSum($storeId1c, $dateFrom, $dateTo, $isAdministrator): array { $salesByAdminPrepared = $this->salesService->getSalesByStore($storeId1c, $dateFrom, $dateTo, $isAdministrator); @@ -5381,52 +5447,52 @@ Group BY admin_id } - public function getSumForAdminByDate($adminGuid, $dateFrom, $dateTo, $isAdministrator) : array + public function getSumForAdminByDate($adminGuid, $dateFrom, $dateTo, $isAdministrator): array { return ArrayHelper::getValue($this->getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator), 'sumByDate'); } - public function getSumByAdmin($adminGuid, $dateFrom, $dateTo, $isAdministrator) : float + public function getSumByAdmin($adminGuid, $dateFrom, $dateTo, $isAdministrator): float { return ArrayHelper::getValue($this->getSalurySum($adminGuid, $dateFrom, $dateTo, $isAdministrator), 'sumByAdmin'); } - public function getAvgSumField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getAvgSumField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo): float { return round(DashboardSales::find() ->select(['summ']) - ->andWhere(['store_id'=> $employeeSelectStoreId]) - ->andWhere(['field_name'=> $fieldName]) + ->andWhere(['store_id' => $employeeSelectStoreId]) + ->andWhere(['field_name' => $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->average('summ'), 2); } - public function getSumField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getSumField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo): float { - $query = DashboardSales::find() + $query = DashboardSales::find() ->select(['summ' => new \yii\db\Expression("SUM(summ)")]) - ->andWhere(['store_id'=> $employeeSelectStoreId]) - ->andWhere(['field_name'=> $fieldName]) + ->andWhere(['store_id' => $employeeSelectStoreId]) + ->andWhere(['field_name' => $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]); - $resultQuery = $query->column(); + $resultQuery = $query->column(); - return ArrayHelper::getValue($resultQuery,array_key_first($resultQuery)) ?? 0; + return ArrayHelper::getValue($resultQuery, array_key_first($resultQuery)) ?? 0; } - public function getAvgSumCheck($employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getAvgSumCheck($employeeSelectStoreId, $dateFrom, $dateTo): float { return $this->getAvgSumField('sales_avg_check', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumListField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo): array { return DashboardSales::find() - ->andWhere(['store_id'=> $employeeSelectStoreId]) - ->andWhere(['field_name'=> $fieldName]) + ->andWhere(['store_id' => $employeeSelectStoreId]) + ->andWhere(['field_name' => $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->indexBy('date') @@ -5448,13 +5514,13 @@ Group BY admin_id return $groupId; } - public function getStoreIdDayChallenge($dateFrom, $dateTo) : array + public function getStoreIdDayChallenge($dateFrom, $dateTo): array { - $monthFrom = (int) date("m",strtotime($dateFrom)); - $monthTo = (int) date("m",strtotime($dateTo)); - $yearFrom = (int) date("Y",strtotime($dateFrom)); - $yearTo = (int) date("Y",strtotime($dateTo)); + $monthFrom = (int)date("m", strtotime($dateFrom)); + $monthTo = (int)date("m", strtotime($dateTo)); + $yearFrom = (int)date("Y", strtotime($dateFrom)); + $yearTo = (int)date("Y", strtotime($dateTo)); $months = range($monthFrom, $monthTo); $years = range($yearFrom, $yearTo); @@ -5463,7 +5529,9 @@ Group BY admin_id $storeIdsPrepared = ArrayHelper::getColumn($storesPlan, 'storeId.entity_id'); - $storeIds = array_filter($storeIdsPrepared, static function($var){return $var !== null;} ); + $storeIds = array_filter($storeIdsPrepared, static function ($var) { + return $var !== null; + }); $dayStartMonth = date('Y-m-01', strtotime($dateFrom)); $dayStopMonth = date('Y-m-t', strtotime($dateTo)); @@ -5497,10 +5565,10 @@ Group BY admin_id if (array_key_exists($rowStoreId, $newStores)) { $openDate = ArrayHelper::getValue($newStores[$rowStoreId], 'open_date'); $dateOpen = new DateTime($openDate); - $dateEndMonthOpen = date("Y-m-t",strtotime($openDate)); + $dateEndMonthOpen = date("Y-m-t", strtotime($openDate)); $dateEndMonth = new DateTime($dateEndMonthOpen); $interval = $dateOpen->diff($dateEndMonth); - $activeDayNewStore = (int) $interval->format('%a') + 1; + $activeDayNewStore = (int)$interval->format('%a') + 1; $countCalculateDaysRow = $activeDayNewStore; } } @@ -5514,7 +5582,7 @@ Group BY admin_id } $dashboardSales = DashboardSales::find() - ->andWhere(['field_name'=> 'sales_summ']) + ->andWhere(['field_name' => 'sales_summ']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->asArray() @@ -5523,7 +5591,7 @@ Group BY admin_id $avgCheckSummTrigger = 1200; $dashboardSalesAvgCheck = DashboardSales::find() - ->andWhere(['field_name'=> 'sales_avg_check']) + ->andWhere(['field_name' => 'sales_avg_check']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['>', 'summ', $avgCheckSummTrigger]) @@ -5544,19 +5612,19 @@ Group BY admin_id $dateRow = ArrayHelper::getValue($itemSale, 'date'); if (!array_key_exists($dateRow, $dashboardSalesAvgCheckArray)) { - $test =33; + $test = 33; continue; } $storeIdRow = ArrayHelper::getValue($itemSale, 'store_id'); $summRow = ArrayHelper::getValue($itemSale, 'summ'); - $monthRow = (int) date("m",strtotime($dateRow)); - $yearRow = (int) date("Y",strtotime($dateRow)); + $monthRow = (int)date("m", strtotime($dateRow)); + $yearRow = (int)date("Y", strtotime($dateRow)); $yearMonthKeyRow = $yearRow . '_' . $monthRow; - $keyArrayRow = $yearMonthKeyRow . '.' . $storeIdRow .'.plan_by_day'; + $keyArrayRow = $yearMonthKeyRow . '.' . $storeIdRow . '.plan_by_day'; $planByDayStoreRow = ArrayHelper::getValue($storesPlanByDay, $keyArrayRow); $dashboardSales[$key]['plan_by_day'] = $planByDayStoreRow; @@ -5591,13 +5659,13 @@ Group BY admin_id return $deltaPlanByDaySuccessWin; } - public function getStoreIdWeekChallenge($dateFrom, $dateTo) : array + public function getStoreIdWeekChallenge($dateFrom, $dateTo): array { - $monthFrom = (int) date("m",strtotime($dateFrom)); - $monthTo = (int) date("m",strtotime($dateTo)); - $yearFrom = (int) date("Y",strtotime($dateFrom)); - $yearTo = (int) date("Y",strtotime($dateTo)); + $monthFrom = (int)date("m", strtotime($dateFrom)); + $monthTo = (int)date("m", strtotime($dateTo)); + $yearFrom = (int)date("Y", strtotime($dateFrom)); + $yearTo = (int)date("Y", strtotime($dateTo)); $months = range($monthFrom, $monthTo); $years = range($yearFrom, $yearTo); @@ -5620,7 +5688,7 @@ Group BY admin_id } $dashboardSales = DashboardSales::find() - ->andWhere(['field_name'=> 'sales_summ']) + ->andWhere(['field_name' => 'sales_summ']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->asArray() @@ -5629,7 +5697,7 @@ Group BY admin_id $avgCheckSummTrigger = 1200; $dashboardSalesAvgCheck = DashboardSales::find() - ->andWhere(['field_name'=> 'sales_avg_check']) + ->andWhere(['field_name' => 'sales_avg_check']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['>', 'summ', $avgCheckSummTrigger]) @@ -5650,19 +5718,19 @@ Group BY admin_id $dateRow = ArrayHelper::getValue($itemSale, 'date'); if (!array_key_exists($dateRow, $dashboardSalesAvgCheckArray)) { - $test =33; + $test = 33; continue; } $storeIdRow = ArrayHelper::getValue($itemSale, 'store_id'); $summRow = ArrayHelper::getValue($itemSale, 'summ'); - $monthRow = (int) date("m",strtotime($dateRow)); - $yearRow = (int) date("Y",strtotime($dateRow)); + $monthRow = (int)date("m", strtotime($dateRow)); + $yearRow = (int)date("Y", strtotime($dateRow)); $yearMonthKeyRow = $yearRow . '_' . $monthRow; - $keyArrayRow = $yearMonthKeyRow . '.' . $storeIdRow .'.plan_by_day'; + $keyArrayRow = $yearMonthKeyRow . '.' . $storeIdRow . '.plan_by_day'; $planByDayStoreRow = ArrayHelper::getValue($storesPlanByDay, $keyArrayRow); $dashboardSales[$key]['plan_by_day'] = $planByDayStoreRow; @@ -5697,56 +5765,56 @@ Group BY admin_id return $deltaPlanByDaySuccessWin; } - public function getSumListAvgCheck($employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListAvgCheck($employeeSelectStoreId, $dateFrom, $dateTo): array { return $this->getSumListField('sales_avg_check', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumListConversion($employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListConversion($employeeSelectStoreId, $dateFrom, $dateTo): array { return $this->getSumListField('conversion_traffic', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumListNewBonusClientsPercent($employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListNewBonusClientsPercent($employeeSelectStoreId, $dateFrom, $dateTo): array { return $this->getSumListField('new_bonus_clients_percent', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumListConversionBonusClients($employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListConversionBonusClients($employeeSelectStoreId, $dateFrom, $dateTo): array { return $this->getSumListField('сonversion_bonus_clients', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumListStoreServicesPercent($employeeSelectStoreId, $dateFrom, $dateTo) : array + public function getSumListStoreServicesPercent($employeeSelectStoreId, $dateFrom, $dateTo): array { return $this->getSumListField('services_percent', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumChecksStore($employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getSumChecksStore($employeeSelectStoreId, $dateFrom, $dateTo): float { return $this->getSumField('checks_counter', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumIncomingTrafficStore($employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getSumIncomingTrafficStore($employeeSelectStoreId, $dateFrom, $dateTo): float { return $this->getSumField('incoming_traffic', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumClientsLtv($employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getSumClientsLtv($employeeSelectStoreId, $dateFrom, $dateTo): float { return $this->getSumField('clients_ltv', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getSumSalesSumm($employeeSelectStoreId, $dateFrom, $dateTo) : float + public function getSumSalesSumm($employeeSelectStoreId, $dateFrom, $dateTo): float { return $this->getSumField('sales_summ', $employeeSelectStoreId, $dateFrom, $dateTo); } - public function getGuidsByIds($ids, $exportAdmin) : array + public function getGuidsByIds($ids, $exportAdmin): array { $adminGuids = []; foreach ($ids as $id) { @@ -5760,10 +5828,10 @@ Group BY admin_id return $adminGuids; } - public function getValues(array $adminIdsInShift) : array + public function getValues(array $adminIdsInShift): array { $result = []; - array_walk_recursive($adminIdsInShift, function($v) use (&$result){ + array_walk_recursive($adminIdsInShift, function ($v) use (&$result) { $result[] = $v; }); @@ -5771,7 +5839,7 @@ Group BY admin_id } - public function getSumValues(array $values) : int + public function getSumValues(array $values): int { $sumRows = 0; foreach ($values as $item) { @@ -5782,7 +5850,7 @@ Group BY admin_id } - public function getSumGameBonus(array $timetable, $allPossibleSumGameBonusValuesFlorist) : array + public function getSumGameBonus(array $timetable, $allPossibleSumGameBonusValuesFlorist): array { $sumRows = 0; foreach ($timetable as $shift) { @@ -5791,7 +5859,7 @@ Group BY admin_id $sumForDays = $sumRows; - if (!empty($allPossibleSumGameBonusValuesFlorist) && (int) $allPossibleSumGameBonusValuesFlorist > 0) { + if (!empty($allPossibleSumGameBonusValuesFlorist) && (int)$allPossibleSumGameBonusValuesFlorist > 0) { $sumRows += $allPossibleSumGameBonusValuesFlorist; } @@ -5809,7 +5877,7 @@ Group BY admin_id ]; } - public function getSumBonus(array $bonusStore1, array $bonusStore2 ) : array + public function getSumBonus(array $bonusStore1, array $bonusStore2): array { $bonusStore1AdminSumGameBonusForDays = $bonusStore1['adminSumGameBonusForDays'] ?? 0; $bonusStore2AdminSumGameBonusForDays = $bonusStore2['adminSumGameBonusForDays'] ?? 0; @@ -5841,8 +5909,8 @@ Group BY admin_id public function getDeltaMonthToMonthClientsLtvPercent($employeeSelectStoreId, $dateFromBeginMonth, $dateToEndMonth) { - $dateFromBeginPreviousMonth = date("Y-m-01",strtotime($dateFromBeginMonth." -1 month")); - $dateToEndPreviousMonth = date("Y-m-t",strtotime($dateFromBeginPreviousMonth)); + $dateFromBeginPreviousMonth = date("Y-m-01", strtotime($dateFromBeginMonth . " -1 month")); + $dateToEndPreviousMonth = date("Y-m-t", strtotime($dateFromBeginPreviousMonth)); $sumClientsLtvCurrentMonth = $this->getSumClientsLtv($employeeSelectStoreId, $dateFromBeginMonth, $dateToEndMonth); $sumIncomingTrafficStoreCurrentMonth = $this->getSumIncomingTrafficStore($employeeSelectStoreId, $dateFromBeginMonth, $dateToEndMonth); @@ -5864,7 +5932,7 @@ Group BY admin_id $deltaPercent = 0; - if ( $sumClientsLtvPreviousMonthPercent > 0) { + if ($sumClientsLtvPreviousMonthPercent > 0) { $deltaPercent = round(round(100 * $sumClientsLtvCurrentMonthPercent / $sumClientsLtvPreviousMonthPercent, 1) - 100, 1); } @@ -5885,34 +5953,34 @@ Group BY admin_id $salesSummPastYearMonthFromDict = null; $salesSummPastYearMonthDict = [ - '2022-12' => [ + '2022-12' => [ 26 => 961015, // ул. Краснодонцев 1 27 => 1195200, // д. Кузнечиха ул. Бархатная 86Д 28 => 841351, // п. Революции 7А - 1 => 2521529.00, //01 Ванеева - 2 => 1918369.60, //05 Белинского ККМ - 3 => 1097327.26, //03 Гагарина 60 - 4 => 876268.20, //07 Аэродромная - 6 => 997197.93, //13 Горького - 7 => 1271296.00, //02 Плотникова - 8 => 991041.26, //04 Шайба новая - 9 => 1727580.00, //10 Народная - 10 => 1195303.00, //12 Гагарина 19 - 11 => 904932.00, //06 Коминтерна - 14 => 411538.80, //11 Гагарина 37Б - 13 => 1015329.73, //14 Печеры ККМ - 15 => 971241.96, //16 Гагарина 182 - 16 => 968547.89, //15 Ленина 76 новый - 19 => 1026177.12, //17 Коминтерная 248 ККМ - 20 => 691301.21, //18 Ленина 62 - 23 => 361494.00, //08 Веденяпина 4 с 14.11.2021 (Ванеева 11) - - ], + 1 => 2521529.00, //01 Ванеева + 2 => 1918369.60, //05 Белинского ККМ + 3 => 1097327.26, //03 Гагарина 60 + 4 => 876268.20, //07 Аэродромная + 6 => 997197.93, //13 Горького + 7 => 1271296.00, //02 Плотникова + 8 => 991041.26, //04 Шайба новая + 9 => 1727580.00, //10 Народная + 10 => 1195303.00, //12 Гагарина 19 + 11 => 904932.00, //06 Коминтерна + 14 => 411538.80, //11 Гагарина 37Б + 13 => 1015329.73, //14 Печеры ККМ + 15 => 971241.96, //16 Гагарина 182 + 16 => 968547.89, //15 Ленина 76 новый + 19 => 1026177.12, //17 Коминтерная 248 ККМ + 20 => 691301.21, //18 Ленина 62 + 23 => 361494.00, //08 Веденяпина 4 с 14.11.2021 (Ванеева 11) + + ], // Продажи за 02 месяц в 2022 году '2022-02' => [ - 8 => 1233571.00, //04 Шайба новая + 8 => 1233571.00, //04 Шайба новая ], '2023-03' => [ 26 => 933577, // ул. Краснодонцев 1 @@ -5980,7 +6048,7 @@ Group BY admin_id ], ]; - $yearMonthDateFromBeginMonth = date("Y-m",strtotime($dateFromBeginMonth)); + $yearMonthDateFromBeginMonth = date("Y-m", strtotime($dateFromBeginMonth)); $modifier = ' -1 year'; @@ -6000,10 +6068,10 @@ Group BY admin_id } } - $dateFromBeginPastYear = date("Y-m-d",strtotime($dateFromBeginMonth.$modifier)); - $dateToEndPastYear = date("Y-m-d",strtotime($dateTo.$modifier)); + $dateFromBeginPastYear = date("Y-m-d", strtotime($dateFromBeginMonth . $modifier)); + $dateToEndPastYear = date("Y-m-d", strtotime($dateTo . $modifier)); - $yearDateFromBeginPastYear = date("Y-m",strtotime($dateFromBeginPastYear)); + $yearDateFromBeginPastYear = date("Y-m", strtotime($dateFromBeginPastYear)); if (array_key_exists($yearDateFromBeginPastYear, $salesSummPastYearMonthDict)) { $salesSummPastYearMonthDictRow = $salesSummPastYearMonthDict[$yearDateFromBeginPastYear]; @@ -6037,15 +6105,15 @@ Group BY admin_id $foundKey = $entityCityStoreEmployeeSelect . '_' . $dateFrom; $aeroStore = 'dbd70103-2c7b-11e9-9b87-c85b76f0e893'; $customSum = [ - $aeroStore.'_2021-10-01' => 885795, - $aeroStore.'_2021-11-01' => 889483, + $aeroStore . '_2021-10-01' => 885795, + $aeroStore . '_2021-11-01' => 889483, ]; if (array_key_exists($foundKey, $customSum)) { return $customSum[$foundKey]; } - if (true === (bool) $writeOff) { + if (true === (bool)$writeOff) { $salesPrepared = $this->salesService->getSalesSum($dateFrom, $dateTo, false, true, $entityCityStoreEmployeeSelect); } else { $salesPrepared = $this->salesService->getSalesSum($dateFrom, $dateTo, false, false, $entityCityStoreEmployeeSelect); @@ -6053,17 +6121,17 @@ Group BY admin_id $sales = []; - foreach($salesPrepared as $row) { + foreach ($salesPrepared as $row) { if (!array_key_exists($row["store_id_1c"], $sales)) { $sales[$row["store_id_1c"]] = 0; } - if($row["operation"] == Sales::OPERATION_SALE) { - $sales[$row["store_id_1c"]] +=$row["summ"]; + if ($row["operation"] == Sales::OPERATION_SALE) { + $sales[$row["store_id_1c"]] += $row["summ"]; } - if($row["operation"] == Sales::OPERATION_RETURN) { - $sales[$row["store_id_1c"]] -=$row["summ"]; + if ($row["operation"] == Sales::OPERATION_RETURN) { + $sales[$row["store_id_1c"]] -= $row["summ"]; } } $salesByStore = 0; @@ -6082,7 +6150,7 @@ Group BY admin_id * @param $storeId * @return array */ - public function getCountStoreVisitors(string $dateFrom,string $dateTo, $storeId) : array + public function getCountStoreVisitors(string $dateFrom, string $dateTo, $storeId): array { $storeVisitorsService = new StoreVisitorsService(); $countStoreVisitorsDay = $storeVisitorsService->getStoreVisitors($dateFrom, $dateTo, $storeId, true); @@ -6107,19 +6175,19 @@ Group BY admin_id * @return array[] * @throws \Exception */ - public function getConversionShift(string $dateFrom, string $dateTo, $storeId) : array + public function getConversionShift(string $dateFrom, string $dateTo, $storeId): array { - $salesCount = $this->salesService->getSalesCount( $dateFrom, $dateTo, $storeId); - $countStoreVisitors = $this->getCountStoreVisitors( $dateFrom, $dateTo, $storeId); + $salesCount = $this->salesService->getSalesCount($dateFrom, $dateTo, $storeId); + $countStoreVisitors = $this->getCountStoreVisitors($dateFrom, $dateTo, $storeId); $datesShiftDay = array_keys($salesCount['salesCountDay']); $dayConversion = []; foreach ($datesShiftDay as $date) { $dayConversion[$date] = 0; - if (array_key_exists($date, $countStoreVisitors['countStoreVisitorsDay'])){ + if (array_key_exists($date, $countStoreVisitors['countStoreVisitorsDay'])) { $salesCountShiftDay = $salesCount['salesCountDay'][$date]; $visitorsCountShiftDay = $countStoreVisitors['countStoreVisitorsDay'][$date]; - if (0 < (int) $visitorsCountShiftDay) { + if (0 < (int)$visitorsCountShiftDay) { $dayConversion[$date] = round(($salesCountShiftDay / $visitorsCountShiftDay) * 100, 1); } } @@ -6129,11 +6197,11 @@ Group BY admin_id $nightConversion = []; foreach ($datesShiftNight as $date) { $nightConversion[$date] = 0; - if (array_key_exists($date, $countStoreVisitors['countStoreVisitorsNight'])){ + if (array_key_exists($date, $countStoreVisitors['countStoreVisitorsNight'])) { $salesCountShiftNight = $salesCount['salesCountNight'][$date]; $visitorsCountShiftNight = $countStoreVisitors['countStoreVisitorsNight'][$date]; - if (0 < (int) $visitorsCountShiftNight) { - $nightConversion[$date] = round(100 * $salesCountShiftNight/$visitorsCountShiftNight,1); + if (0 < (int)$visitorsCountShiftNight) { + $nightConversion[$date] = round(100 * $salesCountShiftNight / $visitorsCountShiftNight, 1); } } } @@ -6145,12 +6213,12 @@ Group BY admin_id } - public function checkError( array $storeAdminsPrepared, array $storeAdminsNames, $controller, $checkErrorName) + public function checkError(array $storeAdminsPrepared, array $storeAdminsNames, $controller, $checkErrorName) { if (!empty($storeAdminsPrepared['error'])) { $errorText = 'При проверке сотрудников по ' . $checkErrorName . ' на смене возникла ошибка:
'; foreach ($storeAdminsPrepared['error'] as $item) { - $errorText .= 'В ERP нет данных GUID из 1с о пользователе ' . $storeAdminsNames[$item] . ' id : ' . $item . '
'; + $errorText .= 'В ERP нет данных GUID из 1с о пользователе ' . $storeAdminsNames[$item] . ' id : ' . $item . '
'; } $errorText .= 'Связь с 1с нужна для того, что бы посчитать продажи смены.
Обратитесь в HR отдел'; @@ -6182,16 +6250,16 @@ Group BY admin_id $adminIdsInShift = []; $storeIdsInShift = []; $adminNamesInShift = []; - foreach ( $timetableTmp as $key => $item) { + foreach ($timetableTmp as $key => $item) { $resultTimetableInfo = $this->getTimetableAdminData($item['shift_id'], $item['store_id'], $item['date']); - $adminIds = ArrayHelper::getColumn($resultTimetableInfo , 'admin_id'); - $adminNames = ArrayHelper::getColumn($resultTimetableInfo , 'admin.name_full'); - $adminNamesList = implode(',
' , $adminNames); + $adminIds = ArrayHelper::getColumn($resultTimetableInfo, 'admin_id'); + $adminNames = ArrayHelper::getColumn($resultTimetableInfo, 'admin.name_full'); + $adminNamesList = implode(',
', $adminNames); $timetableInfo[$key] = $resultTimetableInfo; $timetable[$key]['count_admin_store_shift']['shift_id'][$item['shift_id']] = count($resultTimetableInfo); $timetable[$key]['admin_store'] = [ - 'adminIds' => $adminIds, - 'adminNames' => $adminNames, + 'adminIds' => $adminIds, + 'adminNames' => $adminNames, ]; $timetable[$key]['name_list_admin_store'] = $adminNamesList; $timetable[$key]['count_admin_store'] = count($resultTimetableInfo); @@ -6248,25 +6316,25 @@ Group BY admin_id ): array { - $dateCurrent = date("Y-m-d",time()); + $dateCurrent = date("Y-m-d", time()); - $yearCurrent = date("Y",strtotime($dateCurrent)); - $monthCurrent = date("n",strtotime($dateCurrent)); + $yearCurrent = date("Y", strtotime($dateCurrent)); + $monthCurrent = date("n", strtotime($dateCurrent)); - $yearDateFrom = date("Y",strtotime($dateFrom)); - $monthDateFrom = date("n",strtotime($dateFrom)); + $yearDateFrom = date("Y", strtotime($dateFrom)); + $monthDateFrom = date("n", strtotime($dateFrom)); - $dayCurrent = date("j",strtotime($dateCurrent)); + $dayCurrent = date("j", strtotime($dateCurrent)); $dateMonthBefore = date("Y-m-d", strtotime($dateFrom . " -1 months")); $dateToMonthBefore = date("Y-m-d", strtotime($dateTo . " -1 months")); $dateBeginMonthBefore = date("Y-m-01", strtotime($dateFrom . " -1 months")); $dateEndMonthBefore = date("Y-m-t", strtotime($dateFrom . " -1 months")); - $dayInPastMonth = date("j",strtotime($dateEndMonthBefore)); + $dayInPastMonth = date("j", strtotime($dateEndMonthBefore)); - $yearBeforeSelect = date("Y",strtotime($dateMonthBefore)); - $monthWithZeroBeforeSelect = date("m",strtotime($dateMonthBefore)); + $yearBeforeSelect = date("Y", strtotime($dateMonthBefore)); + $monthWithZeroBeforeSelect = date("m", strtotime($dateMonthBefore)); $storeIdsString = ArrayHelper::getValue($clusterAdmin, 'store_arr'); $clusterAdminId = ArrayHelper::getValue($clusterAdmin, 'id'); @@ -6277,7 +6345,7 @@ Group BY admin_id ]; $adminAdministrator = Admin::getAdmins('', $groupIds, 'ASC', $storeIds, '', Admin::NOT_IN_STORE_IDS); - $adminAdministratorIdsMap = ArrayHelper::map($adminAdministrator, 'store_id','id'); + $adminAdministratorIdsMap = ArrayHelper::map($adminAdministrator, 'store_id', 'id'); $adminAdministratorIds = ArrayHelper::getColumn($adminAdministrator, 'id'); $clusterStores = []; @@ -6349,14 +6417,12 @@ Group BY admin_id $clusterStores[$storeId] = []; - $salesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); - $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect,true); + $allSalesByStore = $this->getSalesSaleSum($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect, true); $salesByStoreInterval = $this->getSalesSaleSum($dateFrom, $dateTo, $entityCityStoreEmployeeSelect); $salesSummCurrentMonth = $this->getSalesSaleSum($dateFromBeginMonth, $dateToEndMonth, $entityCityStoreEmployeeSelect); - $amountWriteOff = WriteOffs::getWriteOffByStore($dateFromBeginMonth, $dateTo, $entityCityStoreEmployeeSelect); // списание @@ -6440,11 +6506,11 @@ Group BY admin_id $percentLossFromDict = true; } else { if (!empty($allSalesByStore)) { - $percentLossPrepared = 100 * $amountWriteOffByStore/$allSalesByStore; + $percentLossPrepared = 100 * $amountWriteOffByStore / $allSalesByStore; } else { - $percentLossPrepared = 100 * $amountWriteOffByStore/$salesByStore; + $percentLossPrepared = 100 * $amountWriteOffByStore / $salesByStore; } - $percentLoss = round($percentLossPrepared,1); + $percentLoss = round($percentLossPrepared, 1); } } @@ -6452,7 +6518,7 @@ Group BY admin_id $planPercent = 0; $planStoreMonthCalculatePercent = 0; if (!empty($salesByStore) && !empty($planMonthByStore)) { - $planPercent=round(100 * $salesByStore/$planMonthByStore,1); + $planPercent = round(100 * $salesByStore / $planMonthByStore, 1); } $saleByMonthCalculate = 0; @@ -6505,7 +6571,6 @@ Group BY admin_id ->asArray()->column(); - $adminPayrollIdsBeforeMonth = AdminPayroll::find() ->select(['id']) ->indexBy('id') @@ -6514,7 +6579,6 @@ Group BY admin_id ->asArray()->column(); - $payrollSumValuesCurrentMonthRow = AdminPayrollValues::getSumByAlias($allTotalPayrollAttributeId, $adminPayrollIdsCurrentMonth); $payrollSumValuesBeforeMonthRow = AdminPayrollValues::getSumByAlias($allTotalPayrollAttributeId, $adminPayrollIdsBeforeMonth); @@ -6530,15 +6594,15 @@ Group BY admin_id $percentFotCurrentMonth = 0; if (!empty($salesByStore)) { - $percentFotCurrentMonth = round(($payrollSumValuesCurrentMonthRow/$salesByStore) * 100, 1); + $percentFotCurrentMonth = round(($payrollSumValuesCurrentMonthRow / $salesByStore) * 100, 1); } $percentFotBeforeMonth = 0; if (!empty($salesSummBeforeMonth)) { - $percentFotBeforeMonth = round(($payrollSumValuesBeforeMonthRow/$salesSummBeforeMonth) * 100, 1); + $percentFotBeforeMonth = round(($payrollSumValuesBeforeMonthRow / $salesSummBeforeMonth) * 100, 1); } - if ($monthSelect == 10 && $yearSelect == 2022 ) { + if ($monthSelect == 10 && $yearSelect == 2022) { $oldFot2022_09 = [ 13 => 15.79, 1 => 10.88, @@ -6651,7 +6715,7 @@ Group BY admin_id $sumSalesByStoreInterval = $param['sumSalesByStoreInterval']; } - if ($monthSelect == 10 && $yearSelect == 2022 ) { + if ($monthSelect == 10 && $yearSelect == 2022) { $oldFotValuesAdmins2022_09 = [ 163 => 24.82, // 163 Оксана Кузнецова 164 => 14.84, // 164 Иван Карпушкин @@ -6659,7 +6723,7 @@ Group BY admin_id ]; if (array_key_exists($clusterAdminId, $oldFotValuesAdmins2022_09)) { - $percentFotBeforeMonth = $oldFotValuesAdmins2022_09[$clusterAdminId]; + $percentFotBeforeMonth = $oldFotValuesAdmins2022_09[$clusterAdminId]; } } @@ -6680,12 +6744,11 @@ Group BY admin_id } - $raznicaDoPlanaStore = $param['planMonthByStore'] - $param['salesByStore']; $showRaznicaDoPlanaPerson = false; - if (1 === (int) date('d', strtotime($dateFrom))) { + if (1 === (int)date('d', strtotime($dateFrom))) { $showRaznicaDoPlanaPerson = true; } @@ -6748,7 +6811,7 @@ Group BY admin_id $planPercentCluster = 0; // процент выполнения плана продаж if (!empty($param['salesByStore']) && !empty($param['planMonthByStore'])) { - $planPercentCluster=round(100 * $param['salesByStore']/$param['planMonthByStore'],1); + $planPercentCluster = round(100 * $param['salesByStore'] / $param['planMonthByStore'], 1); } $date = $yearSelect . '-' . $monthWithZeroSelect; @@ -6767,7 +6830,6 @@ Group BY admin_id $personVacationDay = ArrayHelper::getValue($personBonusesArray, 'vacation_day'); // Оплаченный отпуск - // Сумма окладной части устанавливается стандартной - 45 000 руб. $okladClusterAdmin = 45000; if ($dateFrom >= '2023-09-01') { @@ -6810,7 +6872,7 @@ Group BY admin_id $ratingPerson = ArrayHelper::getValue($ratingPersonValues, 'rating'); - if ($yearSelect . '-' . $monthWithZeroSelect == '2022-12' && $clusterAdminId == 164) { + if ($yearSelect . '-' . $monthWithZeroSelect == '2022-12' && $clusterAdminId == 164) { $administratorCountInRating = 7; } else { $administratorCountInRating = ArrayHelper::getValue($ratingPersonValues, 'administrators_count'); @@ -6847,7 +6909,7 @@ Group BY admin_id if (!empty($personBonuses)) { $personBonusesArrayInfo = [ - 'Персональная премия' => (int) $personBonuses, + 'Персональная премия' => (int)$personBonuses, ]; $arrayColumnWages = array_merge($arrayColumnWages, $personBonusesArrayInfo); } @@ -6878,7 +6940,7 @@ Group BY admin_id $percentDeMotivateYearToYear = $param['percentDeMotivateYearToYear']; - if( + if ( $allPossibleSumValuesClusterPrepared > 0 && ($percentDeMotivateYearToYear < 100) ) { @@ -6889,8 +6951,6 @@ Group BY admin_id } - - // Таблица итоговых сумм $sumValuesCluster = array( @@ -6957,10 +7017,10 @@ Group BY admin_id ]; if (!empty($resultArrayErrorText)) { - $resultArray = array_merge($resultArray,['errorText' => $resultArrayErrorText,]); + $resultArray = array_merge($resultArray, ['errorText' => $resultArrayErrorText,]); } - $resultArray = array_merge($resultArray,$param); + $resultArray = array_merge($resultArray, $param); return $resultArray; @@ -6977,7 +7037,7 @@ Group BY admin_id $yearSelectTo = date("Y", strtotime($dateTo)); $monthSelectTo = date("m", strtotime($dateTo)); - $yearMonthSelectTo = $yearSelectTo . '-' . $monthSelectTo; + $yearMonthSelectTo = $yearSelectTo . '-' . $monthSelectTo; $allowedByMonth = true; $allowedByBlockList = true; @@ -7018,7 +7078,7 @@ Group BY admin_id $yearSelectTo = date("Y", strtotime($dateTo)); $monthSelectTo = date("m", strtotime($dateTo)); - $yearMonthSelectTo = $yearSelectTo . '-' . $monthSelectTo; + $yearMonthSelectTo = $yearSelectTo . '-' . $monthSelectTo; $allowedByMonth = true; $allowedByBlockList = true; @@ -7032,7 +7092,8 @@ Group BY admin_id return ($allowedByMonth); } - public function getAllowedDemotivateStoreCalculate($employeeSelectStoreId, $dateFrom, $dateTo) : bool + + public function getAllowedDemotivateStoreCalculate($employeeSelectStoreId, $dateFrom, $dateTo): bool { $yearSelectFrom = date("Y", strtotime($dateFrom)); $monthSelectFrom = date("m", strtotime($dateFrom)); @@ -7061,7 +7122,7 @@ Group BY admin_id $percentLoss = 0; //заплатка на процент списания по Аэродромной - if ($storeId == 4 && $yearSelect == 2022 && $monthSelect == 11 ) { + if ($storeId == 4 && $yearSelect == 2022 && $monthSelect == 11) { $percentLoss = 7.4; } @@ -7176,7 +7237,7 @@ Group BY admin_id return $percentLoss; } - public function getCustomSumForLoss($storeId, $yearSelect, $monthSelect) : array + public function getCustomSumForLoss($storeId, $yearSelect, $monthSelect): array { $result = []; @@ -7647,7 +7708,7 @@ Group BY admin_id //заплатка на подсчет процента списания для лк кустового - $monthSelect = trim($monthSelect,'0'); + $monthSelect = trim($monthSelect, '0'); $yearMonthKey = $yearSelect . '_' . $monthSelect; if (!empty($storeId)) { if (array_key_exists($yearMonthKey, $configSalesAndWriteOff)) { @@ -7664,9 +7725,9 @@ Group BY admin_id } /** - * @return int - */ - public function getAdministratorSalaryShift($employeeId, $dateFrom, $salesByStore = null) : int + * @return int + */ + public function getAdministratorSalaryShift($employeeId, $dateFrom, $salesByStore = null): int { $administratorOklad = 0; @@ -7678,7 +7739,7 @@ Group BY admin_id $administratorOklad = $this->bonusService->getAdministratorOklad($salesByStore); } - return (int) $administratorOklad; + return (int)$administratorOklad; } public function getPremiumByFocusGroups($adminGuid, $arrUsersSalary, $dateFrom, $dateTo, $isAdministrator): array @@ -7718,9 +7779,9 @@ Group BY admin_id $userSalaryPottedPremium = round($userSalaryPotted * 0.05); $userSalaryWrapPremium = round($userSalaryWrap * 0.05); // 5% за личные продажи упаковки - $userSalarySalutPremium = round($userSalarySalut * 0.05); // 5% за личные продажи пиротехники + $userSalarySalutPremium = round($userSalarySalut * 0.05); // 5% за личные продажи пиротехники - $userSalaryOtherItemsPremium = round($userSalaryOtherItems * 0.01); // 1% за личные продажи не фокусной продукции (Другме товары) + $userSalaryOtherItemsPremium = round($userSalaryOtherItems * 0.01); // 1% за личные продажи не фокусной продукции (Другме товары) $userSalaryPremium = [ 'userSalaryServicesPremium' => $userSalaryServicesPremium, @@ -7758,7 +7819,8 @@ Group BY admin_id $isAdministrator, $showHolidayVersion = false, $notHolidayCalculate = true - ): array { + ): array + { $adminGuidDateArr = []; $adminGuidArrAll = []; if ($showHolidayVersion) { @@ -7770,7 +7832,7 @@ Group BY admin_id $adminGuidDateArr = SalaryHelper::getAdminGuidByStore($dateFrom, $dateTo, $employeeSelectStoreId); $isAdministrator = false; } - $dates = ArrayHelper::getValue($holidayDatesBetweenPrepared, $dataKey); + $dates = ArrayHelper::getValue($holidayDatesBetweenPrepared, $dataKey); } else { $dates = [ 0 => [