$end = end($facts);
+ if ($start->id > $end->id) {
+ $temp = $start;
+ $start = $end;
+ $end = $temp;
+ }
+
+ $start->setAttribute('date_end', $end->date_start);
+ $start->setAttribute('time_end', $end->time_start);
+ $start->setAttribute('checkin_end_id', $end->checkin_start_id);
+ $start->setAttribute('work_time', min(abs(strtotime($end->date_start . $end->time_start) + 600 - strtotime($start->date_start . $start->time_start)) / 3600, TimetableFactModel::WORK_HOURS_TIME));
+ $start->setAttribute('autoclosed', 0);
+ $start->save();
+ $end->delete();
+ }
+ }
+ } else if ($action == 'withoutPlan') {
+ $facts = TimetableFactModel::find()
+ ->andWhere(['is_opening' => false])
+ ->andWhere(['checkin_end_id' => null])
+ ->all();
+
+ foreach ($facts as $fact) {
+ $start = $fact;
+ $end = TimetableFactModel::find()
+ ->andWhere(['admin_id' => $fact->admin_id])
+ ->andWhere(['store_id' => $fact->store_id])
+ ->andWhere(['!=', 'id', $fact->id])
+ ->andWhere(['date_shift' => $fact->date_shift])
+ ->andWhere(['shift_id' => $fact->shift_id])
+ ->one();
+
+ if ($end && $start) {
if ($start->id > $end->id) {
$temp = $start;
$start = $end;
<?php ActiveForm::begin() ?>
<?= Html::submitButton('Объединить', ['class' => 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?>
+ <?= Html::submitButton('Объединить смены без плана', ['class' => 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'withoutPlan']) ?>
+
<?php ActiveForm::end() ?>
<pre>