From: JoySystem_v Date: Wed, 7 Aug 2024 12:39:59 +0000 (+0300) Subject: Added compute action for previous mounth X-Git-Tag: 1.4~35^2~16 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=35add9e75a5c8886560b230d6290a2b706769a37;p=erp24_rep%2Fyii-erp24%2F.git Added compute action for previous mounth --- diff --git a/erp24/actions/motivation/SumPreviousMonthSalaryAction.php b/erp24/actions/motivation/SumPreviousMonthSalaryAction.php new file mode 100644 index 00000000..7225f69e --- /dev/null +++ b/erp24/actions/motivation/SumPreviousMonthSalaryAction.php @@ -0,0 +1,61 @@ +modify('first day of last month'); + $year = $previousMonthDate->format('Y'); + $mounth = $previousMonthDate->format('m'); + + // Определяем даты начала и конца предыдущего месяца + $startOfPreviousMonth = new DateTime("$year-$mounth-01"); + $endOfPreviousMonth = new DateTime($startOfPreviousMonth->format('Y-m-t')); + + // Найти все записи по предыдущему месяцу и году + $motivations = Motivation::find() + ->where(['year' => $year, 'month' => $mounth]) + ->all(); + + if (empty($motivations)) { + Yii::warning("Записи для текущего месяца и года таблицы мотивации не найдены."); + return $this->controller->redirect(['motivation/index']); + } + + foreach ($motivations as $motivation) { + $store_id = $motivation->store_id; + + $monthlyRecords = MotivationService::getTimetableFactRecordsByDateAndStore($startOfPreviousMonth->format('Y-m-d'), $endOfPreviousMonth->format('Y-m-d'), $store_id); + $monthlyVacationSum = MotivationService::getVacationsSum($startOfPreviousMonth->format('Y-m-d'), $endOfPreviousMonth->format('Y-m-d'), $store_id); + + $monthlyTotalSalary = 0; + foreach ($monthlyRecords as $record) { + $payment = EmployeePayment::findOne(['admin_id' => $record->admin_id]); + $dailyPayment = $payment ? $payment->daily_payment : null; + + // Если $record->salary_shift имеет значение, учитываем его и не добавляем dailyPayment + if (!empty($record->salary_shift)) { + $monthlyTotalSalary += $record->salary_shift; + } else { + $monthlyTotalSalary += $dailyPayment; + } + } + + $monthlyTotalSalary += $monthlyVacationSum; + //TODO Проверка записи + $idMotivation = MotivationService::saveOrUpdateMotivationValue($motivation->id, 6, 11, "float", $monthlyTotalSalary); + } + + return $this->controller->redirect(['motivation/index']); + } +} diff --git a/erp24/actions/motivation/SumSalaryAction.php b/erp24/actions/motivation/SumSalaryAction.php index e3b48ec2..60053002 100644 --- a/erp24/actions/motivation/SumSalaryAction.php +++ b/erp24/actions/motivation/SumSalaryAction.php @@ -33,7 +33,7 @@ class SumSalaryAction extends \yii\base\Action ->all(); if (empty($motivations)) { - Yii::warning("No motivation records found for the current month and year."); + Yii::warning("Записи для текущего месяца и года таблицы мотивации не найдены."); return $this->controller->redirect(['motivation/index']); } @@ -96,59 +96,6 @@ class SumSalaryAction extends \yii\base\Action } } - // Определяем даты начала и конца текущего месяца - $startOfMonth = new DateTime("$currentYear-$currentMonth-01"); - $endOfMonth = new DateTime($startOfMonth->format('Y-m-t')); - - // Записываем информацию в таблицу MotivationValue за текущий месяц - foreach ($motivations as $motivation) { - $store_id = $motivation->store_id; - - $monthlyRecords = MotivationService::getTimetableFactRecordsByDateAndStore($startOfMonth->format('Y-m-d'), $endOfMonth->format('Y-m-d'), $store_id); - $monthlyVacationSum = MotivationService::getVacationsSum($startOfMonth->format('Y-m-d'), $endOfMonth->format('Y-m-d'), $store_id); - - $monthlyTotalSalary = 0; - foreach ($monthlyRecords as $record) { - $payment = EmployeePayment::findOne(['admin_id' => $record->admin_id]); - $dailyPayment = $payment ? $payment->daily_payment : null; - - // Если $record->salary_shift имеет значение, учитываем его и не добавляем dailyPayment - if (!empty($record->salary_shift)) { - $monthlyTotalSalary += $record->salary_shift; - } else { - $monthlyTotalSalary += $dailyPayment; - } - } - - $monthlyTotalSalary += $monthlyVacationSum; - - // Проверка наличия записи в MotivationValue за текущий месяц - $motivationValue = MotivationValue::findOne([ - 'motivation_id' => $motivation->id, - 'motivation_group_id' => 6, // 6 для обозначения всего месяца - 'value_id' => 11 - ]); - - if ($motivationValue === null) { - // Если записи нет, создаем новую - $motivationValue = new MotivationValue(); - $motivationValue->motivation_id = $motivation->id; - $motivationValue->motivation_group_id = 6; - $motivationValue->value_id = 11; - $motivationValue->value_type = 'float'; - } - - // Обновляем значение - $motivationValue->value_float = $monthlyTotalSalary; - $motivationValue->value_int = null; - $motivationValue->value_string = null; - - // Сохраняем запись - if (!$motivationValue->save()) { - Yii::error("Не удалось записать данные для store_id: $store_id"); - } - } - return $this->controller->redirect(['motivation/index']); } } diff --git a/erp24/controllers/MotivationController.php b/erp24/controllers/MotivationController.php index 412b0905..e56fe240 100644 --- a/erp24/controllers/MotivationController.php +++ b/erp24/controllers/MotivationController.php @@ -18,6 +18,7 @@ class MotivationController extends Controller 'delete-value' => \yii_app\actions\motivation\DeleteValueAction::class, 'get-salary' => \yii_app\actions\motivation\GetSalaryAction::class, 'sum-salary' => \yii_app\actions\motivation\SumSalaryAction::class, + 'mounth-salary' => \yii_app\actions\motivation\SumPreviousMonthSalaryAction::class, ]; } diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 67128525..30b3b785 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -2,6 +2,7 @@ namespace yii_app\services; +use Yii; use PhpOffice\PhpSpreadsheet\IOFactory; use yii_app\records\Motivation; use yii_app\records\MotivationValue; @@ -428,14 +429,14 @@ class MotivationService $motivationValue->value_string = $value; break; default: - throw new \InvalidArgumentException("Invalid value type: $value_type"); + throw new \InvalidArgumentException("Неправильное значение типа: $value_type"); } // Сохранить запись и вернуть id или false if ($motivationValue->save()) { return $motivationValue->id; } else { - Yii::error("Failed to save MotivationValue: " . json_encode($motivationValue->errors)); + Yii::error("Не удалось сохранить значение: " . json_encode($motivationValue->errors)); return false; } } diff --git a/erp24/views/motivation/run-sum-salary.php b/erp24/views/motivation/run-sum-salary.php index 9ef37c43..373fd020 100644 --- a/erp24/views/motivation/run-sum-salary.php +++ b/erp24/views/motivation/run-sum-salary.php @@ -9,9 +9,16 @@ $this->title = 'Запуск экшена SumSalary';

title) ?>

-

Нажмите кнопку ниже, чтобы запустить экшн SumSalary и вычислить суммы зарплат.

+

Нажмите кнопку ниже, чтобы запустить экшн SumSalary и вычислить суммы зарплат за текущую неделю.

- 'btn btn-primary']) ?> + 'btn btn-primary']) ?> + +

Нажмите кнопку ниже, чтобы запустить экшн SumPreviousMonthSalary и вычислить суммы зарплат за предыдущий месяц.

+ + + 'btn btn-primary']) ?> + +