From: Vladimir Fomichev Date: Fri, 2 Aug 2024 06:18:12 +0000 (+0000) Subject: ERP-103 Вычисление значений для недель по плану для отдельных строк X-Git-Tag: 1.4~50^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8eeb8c9dcd50d441783f09f7f8bbfdd66acf2582;p=erp24_rep%2Fyii-erp24%2F.git ERP-103 Вычисление значений для недель по плану для отдельных строк --- diff --git a/erp24/actions/motivation/IndexAction.php b/erp24/actions/motivation/IndexAction.php index 46cb17f2..b60157ac 100644 --- a/erp24/actions/motivation/IndexAction.php +++ b/erp24/actions/motivation/IndexAction.php @@ -17,7 +17,8 @@ use yii_app\services\MotivationService; class IndexAction extends Action { - public function run() { + public function run() + { // Получаем текущего пользователя $currentUser = Yii::$app->user->identity; @@ -49,12 +50,12 @@ class IndexAction extends Action ]); - + $motivations = Motivation::find()->all(); $possibleStoreIds = ArrayHelper::getColumn($motivations, 'store_id'); $stores = ArrayHelper::map(CityStore::find()->all(), 'id', 'name'); - $stores = array_filter($stores, function ($k, $v) use($possibleStoreIds) { + $stores = array_filter($stores, function ($k, $v) use ($possibleStoreIds) { return in_array($v, $possibleStoreIds); }, ARRAY_FILTER_USE_BOTH); @@ -63,7 +64,7 @@ class IndexAction extends Action return in_array($k, $possibleYears); }); $possibleMonth = ArrayHelper::getColumn($motivations, 'month'); - $months = array_filter(['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], function ($k, $v) use ($possibleMonth) { + $months = array_filter(['Январь', ' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], function ($k, $v) use ($possibleMonth) { return in_array($v + 1, $possibleMonth); }, ARRAY_FILTER_USE_BOTH); @@ -97,7 +98,7 @@ class IndexAction extends Action $showTable = true; $motivationService = new MotivationService(); - + // получаем данные из таблицы $motivationDataTableSort = $motivationService->getMotivationDataTableSort($model->store_id, $model->year, $model->month + 1); @@ -107,6 +108,47 @@ class IndexAction extends Action // Определяем, сколько дней в последней неделе $daysInLastWeek = $daysInMonth - 28; + // Список названий строк, для которых нужно выполнить расчет + $calculateFor = [ + + '12', //'Аренда' + '13', //'Коммунальные услуги' + '14', //'Охрана' + '16', //'Доставка до клиента курьер' + '17', //'Доставка до клиента такси' + '22', //'Техническое обслуживание кассовых аппаратов' + '23', //'Интернет' + '27', // 'Бухгалтерские услуги: постановка и ведение БУ и НУ' + '28', //'Юридические услуги' + '29', //'Кадровое администрирование, охрана труда' + '30', //'Услуги по подбору персонала' + '31', //'Администрирование ИТ инфраструктуры (подключения к базам данных, ПО, почта, интернет)' + '32', //'Лицензия на ПО: ERP система' + '33' //'Продвижение и продажа товара через сайт' + + ]; + + + + // Проходим по всем данным и выполняем расчеты для каждой недели + foreach ($motivationDataTableSort as &$row) { + if (!key_exists('code', $row)){ + continue; + } + if (in_array($row['code'], $calculateFor)) { + $row['week1'] = $this->calculateWeekValue($row['plan'], $daysInMonth, 7); + $row['week2'] = $this->calculateWeekValue($row['plan'], $daysInMonth, 7); + $row['week3'] = $this->calculateWeekValue($row['plan'], $daysInMonth, 7); + $row['week4'] = $this->calculateWeekValue($row['plan'], $daysInMonth, 7); + + // Для 5-й недели используем оставшиеся дни + if ($daysInLastWeek > 0) { + $row['week5'] = $this->calculateWeekValue($row['plan'], $daysInMonth, $daysInLastWeek); + } else { + $row['week5'] = null; + } + } + } @@ -123,12 +165,28 @@ class IndexAction extends Action // Подготавливаем данные для Select2 виджета $yearsForSelect = array_combine($years, $years); - - + + return $this->controller->render( 'index', compact('model', 'stores', 'yearsForSelect', 'months', 'motivationDataTableSort', 'showTable', 'daysInMonth', 'daysInLastWeek', 'week5Header') ); } + + // Функция для расчета значения недели + private function calculateWeekValue($plan, $daysInMonth, $daysInWeek) + { + // Проверяем, является ли план пустым или нулевым + if (empty($plan) || $plan === null) { + return null; + } + + // Проверяем, чтобы избежать деления на ноль + if ($daysInMonth == 0) { + return null; + } + + return ($plan / $daysInMonth) * $daysInWeek; + } } diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 51ab681c..06e071aa 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -68,6 +68,7 @@ class MotivationService if (!isset($result[$costsItem->order])) { $result[$costsItem->order] = [ + 'code' => $costsItem->code, 'name' => $costsItem->name, 'plan' => null, 'correction' => null, diff --git a/erp24/views/motivation/index.php b/erp24/views/motivation/index.php index 806b0280..a6bdb8b4 100644 --- a/erp24/views/motivation/index.php +++ b/erp24/views/motivation/index.php @@ -343,5 +343,5 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P - + \ No newline at end of file