$query = Timetable::find()
->alias('t')
->leftJoin('timetable_fact tf', 'tf.plan_id = t.plan_id')
- ->andWhere(['>=', 'date', '2024-06-01'])
- ->andWhere(['<', 'date', date('Y-m-d')])
- ->andWhere(['is not', 't.plan_id', null])
+ ->andWhere(['>=', 't.date', '2024-06-01'])
+ ->andWhere(['<', 't.date', date('Y-m-d')])
->select([
't.*',
- new \yii\db\Expression('CASE WHEN tf.plan_id IS NOT NULL THEN true ELSE false END AS is_exist')
+ new \yii\db\Expression('(SELECT ARRAY(SELECT ac.id FROM admin_checkin ac WHERE ac.plan_id = t.id)) AS admin_checkin_ids'),
]);
if ($action == 'applyPlus') {
- $timetables = Timetable::find()
- ->andWhere(['>=', 'date', '2024-06-01'])
- ->andWhere(['<', 'date', date('Y-m-d')])
- ->andWhere(['is not', 'plan_id', null])
- ->all();
+ $timetables = $query->all();
foreach ($timetables as $timetable) {
$newFact = TimetableFactModel::find()
$newFact->save();
} else {
$adminCheckinStart = AdminCheckin::find()
- ->where(['plan_id' => $timetable->plan_id])
+ ->where(['plan_id' => $timetable->id])
->orderBy('id asc')
->one();
$adminCheckinEnd = AdminCheckin::find()
- ->where(['plan_id' => $timetable->plan_id])
+ ->where(['plan_id' => $timetable->id])
->orderBy('id desc')
->one();
],
'datetime_start:datetime',
'datetime_end:datetime',
- [
- 'label' => 'Есть ли в новом факте?',
- 'attribute' => 'isNewRecord',
- 'value' => function ($data) {
- return $data->is_exist ? 'Да' : 'Нет';
- }
- ]
)
?>
<div class="bonusAdd m-5">
+ <?= Html::label('Данные для сверки. Все !рабочие! смены с 1.06.2024 по текущую дату, без фильтрации'); ?>
<?php ActiveForm::begin() ?>
<?= Html::submitButton('Перенести', ['class' => 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?>