public function run()
{
$request = Yii::$app->request;
- $store_id = $request->get('store_id', 1);
+ $store_id = $request->get('store_id', 2);
$date = $request->get('date', '2024-08-05');
$records = [];
if (!$model->hasErrors()) {
$records = MotivationService::getRecordsByDateAndStore($date, $store_id);
+ $vacationSum = MotivationService::getVacationsSum($date, $store_id);
}
// Определяем начало недели и номер недели в месяце
$currentDate = new DateTime($model->date);
'startOfWeek' => $startOfWeek,
'endOfWeek' => $endOfWeek,
'weekNumberInMonth' => $weekNumberInMonth,
+ 'vacation'=> $vacationSum,
]);
}
}
$store_id = $motivation->store_id;
$date = $currentDate->format('Y-m-d');
$records = MotivationService::getRecordsByDateAndStore($date, $store_id);
-
+ $vacationSum = MotivationService::getVacationsSum($date, $store_id);
$totalSalary = 0;
foreach ($records as $record) {
}
}
- $results[$store_id] = $totalSalary;
+ $results[$store_id] = $totalSalary + $vacationSum;
}
// Определяем начало недели и номер недели в месяце
use yii_app\records\TimetableFactModel;
use DateTime;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Timetable;
+use yii_app\records\EmployeePayment;
+
+
class MotivationService
{
return $records;
}
+
+ public static function getVacationsSum($currentDate, $store_id)
+ {
+ // Преобразуем дату в объект DateTime
+ $dateTime = new DateTime($currentDate);
+
+ // Определяем номер недели в месяце и начало недели
+ $weekOfMonth = self::getWeekOfMonth($dateTime);
+ $startOfWeek = self::getStartOfWeek($dateTime, $weekOfMonth);
+
+ // Делаем запрос к таблице Timetable для получения записей с slot_type_id = 2
+ $records = Timetable::find()
+ ->where(['store_id' => $store_id])
+ ->andWhere(['between', 'date', $startOfWeek->format('Y-m-d'), $dateTime->format('Y-m-d')])
+ ->andWhere(['slot_type_id' => 2])
+ ->all();
+
+ // Получаем массив admin_id
+ $adminIds = ArrayHelper::getColumn($records, 'admin_id');
+
+ // Делаем запрос к таблице EmployeePayment для получения daily_payment
+ $payments = EmployeePayment::find()
+ ->where(['admin_id' => $adminIds])
+ ->all();
+
+ // Получаем массив стоимости каждого дня отпуска
+ $dailyPayments = ArrayHelper::getColumn($payments, 'daily_payment');
+
+ // Вычисляем сумму отпускных выплат
+ $vacationsSum = array_sum($dailyPayments);
+
+ return $vacationsSum;
+ }
private static function getWeekOfMonth($dateTime)
{
/** @var $startOfWeek string */
/** @var $endOfWeek string */
/** @var $weekNumberInMonth int */
+/** @var $vacation float */
$this->title = 'Записи';
?>
<p>Всего смен: <?= count($records) ?></p>
<p>ЗП за весь период: <?= Html::encode($totalSalary) ?></p>
+ <p>Отпускные: <?= Html::encode($vacation) ?></p>
<p>Период: с <?= Html::encode($startOfWeek) ?> по <?= Html::encode($endOfWeek) ?></p>
<p>Номер недели в месяце: <?= Html::encode($weekNumberInMonth) ?></p>
<?php endif; ?>