$motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one();
foreach ($items as $code) {
+ if ($code == 34) { // Количество сотрудников считается в другой задаче
+ continue;
+ }
if ($motivation) {
$motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id,
'motivation_group_id' => $motivationValueGroupForecast->id, 'value_id' => $code])->one();
}
}
+ public static function calculatePersonalCount($store_id, $year, $month) {
+ $monthStart = date("Y-m-d 00:00:00", strtotime($year . '-' . $month . '-1'));
+ $monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1'));
+
+ $motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one();
+ if ($motivation) {
+ $timetableFactModels = TimetableFactModel::find()->select(['DISTINCT(admin_id) as admin_id'])->where(['store_id' => $store_id])
+ ->andWhere(['between', 'date_shift', $monthStart, $monthEnd])->all();
+ $adminIds = ArrayHelper::getColumn($timetableFactModels, 'admin_id');
+
+ $result = 0;
+ foreach ($adminIds as $admin_id) {
+ $timetableFactModel = TimetableFactModel::find()->select(['COUNT(*) as total', 'admin_group_id'])->where(['store_id' => $store_id, 'admin_id' => $admin_id])
+ ->andWhere(['between', 'date_shift', $monthStart, $monthEnd])->groupBy(['admin_group_id'])->asArray()->one();
+
+ $norma = 15;
+ if ($timetableFactModel['admin_group_id'] != 45) {
+ $timetablePlan = Timetable::find()->select(['COUNT(*) as total'])->where(['store_id' => $store_id, 'admin_id' => $admin_id, 'tabel' => 0])
+ ->andWhere(['between', 'date', $monthStart, $monthEnd])->asArray()->one();
+ $norma = $timetablePlan['total'];
+ }
+ $result += $norma == 0 ? 0 : $timetableFactModel['total'] / $norma;
+ }
+ self::saveOrUpdateMotivationValue($motivation->id, 'fact', 34, 'float', $result);
+ }
+ }
+
/**
* Получение записей по фактическому количеству смен в магазине за указанный период.
*