]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-103 Вычисление значений для недель по плану для отдельных строк
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 2 Aug 2024 06:18:12 +0000 (06:18 +0000)
committerMarina Zozirova <marina.zozirova@erp-flowers.ru>
Fri, 2 Aug 2024 06:18:12 +0000 (06:18 +0000)
erp24/actions/motivation/IndexAction.php
erp24/services/MotivationService.php
erp24/views/motivation/index.php

index 46cb17f2e71ddb16d969586d85fbaccbe63805f2..b60157ac6578765cb2edf84f37d88e805b580b6e 100644 (file)
@@ -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;
+    }
 }
index 51ab681c0663fb10e0aa9d03890ab87f295f1f82..06e071aa8c8fedcbb9658b000d963de733d1dc08 100644 (file)
@@ -68,6 +68,7 @@ class MotivationService
 
             if (!isset($result[$costsItem->order])) {
                 $result[$costsItem->order] = [
+                    'code' => $costsItem->code,
                     'name' => $costsItem->name,
                     'plan' => null,
                     'correction' => null,
index 806b028082446f1df0005d2b3e064f137b1ffd5c..a6bdb8b4566598a242170a5c86b14ed47d89f050 100644 (file)
@@ -343,5 +343,5 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
             <?php endif; ?>
         <?php endif; ?>
 
-       
+    
     </div>
\ No newline at end of file