class IndexAction extends Action
{
- public function run() {
+ public function run()
+ {
// Получаем текущего пользователя
$currentUser = Yii::$app->user->identity;
]);
-
+
$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);
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);
$showTable = true;
$motivationService = new MotivationService();
-
+
// получаем данные из таблицы
$motivationDataTableSort = $motivationService->getMotivationDataTableSort($model->store_id, $model->year, $model->month + 1);
// Определяем, сколько дней в последней неделе
$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;
+ }
+ }
+ }
// Подготавливаем данные для 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;
+ }
}