--- /dev/null
+<?php
+
+namespace yii_app\commands;
+
+use app\records\TimetableFactModel;
+use yii\console\Controller;
+use yii\helpers\Json;
+use yii_app\records\AdminCheckin;
+
+class TimetableController extends Controller
+{
+ public function actionAutocloseShifts() {
+ $timetableFactModels = TimetableFactModel::find()->with(['checkinStart'])->where(['status' => AdminCheckin::TYPE_START])
+ ->andWhere(['<=', 'date_start', date('Y-m-d H:i:s', strtotime('-14 hours', time()))])->all();
+
+ foreach ($timetableFactModels as $timetableFactModel) {
+ /** @var $timetableFactModel TimetableFactModel */
+ $checkIn = new AdminCheckin;
+ $checkIn->admin_id = $timetableFactModel->admin_id;
+ $checkIn->plan_id = $timetableFactModel->checkinStart->plan_id ?? 0;
+ $checkIn->store_id = $timetableFactModel->store_id;
+ $checkIn->ball = 5;
+ $checkIn->comment = "Закрыта автоматически";
+ $checkIn->d_id = $timetableFactModel->d_id;
+ $checkIn->date = date('Y-m-d');
+ $checkIn->time = date('Y-m-d H:i:s');
+ $checkIn->lat = 0;
+ $checkIn->lon = 0;
+ $checkIn->photo = 'images/avatar-empty.png';
+ $checkIn->device_id = 0;
+ $checkIn->type_id = AdminCheckin::TYPE_END;
+ $checkIn->status = 0;
+ $checkIn->save();
+ if ($checkIn->getErrors()) {
+ throw new \Exception(Json::encode($checkIn->getErrors()));
+ }
+ $timetableFactModel->checkin_end_id = $checkIn->id;
+
+ $timetableFactModel->date_end = date('Y-m-d', strtotime($checkIn->time));
+ $timetableFactModel->is_opening = false;
+ $timetableFactModel->is_close = true;
+ $timetableFactModel->time_end = date("H:i:s", strtotime($checkIn->time));
+ $timetableFactModel->work_time = 12;
+ $timetableFactModel->autoclosed = 1;
+ $timetableFactModel->comment = 'Закрыта автоматически';
+
+ $timetableFactModel->save();
+ if ($timetableFactModel->getErrors()) {
+ throw new \Exception(Json::encode($timetableFactModel->getErrors()));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240628_141321_alter_table_timetable_fact_add_column_autoclosed
+ */
+class m240628_141321_alter_table_timetable_fact_add_column_autoclosed extends Migration
+{
+ const TABLE_NAME = 'timetable_fact';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->addColumn(self::TABLE_NAME, 'autoclosed', $this->tinyInteger()->defaultValue(0)
+ ->notNull()->after('is_close')->comment('0 - ничего особенного, 1 - автоматически закрыта'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, 'autoclosed');
+ }
+}
* @property $date_end дата время закрытия смены
* @property bool $is_opening на открытие смены
* @property bool $is_close на закрытие смены
+ * @property bool $autoclosed 0 - ничего особенного, 1 - автоматически закрыта
* @property int $tabel табель
* @property int $plan_id ID табеля если смена поставлена
* @property int $shift_id тип смены
'date_end' => 'дата закрытия смены',
'is_opening' => 'смена открыта?',
'is_close' => 'смена закрыта?',
+ 'autoclosed' => 'если смена закрыта, то автоматически?',
'tabel' => 'табель',
'plan_id' => 'Табель, если смена поставлена',
'shift_id' => 'тип смены',
// [['work_time'], 'number', 'min' => 0, 'max' => 24],
[['comment'], 'string'],
[['comment'], 'default', 'value' => null],
- [['slot_type_id', 'date_add', 'date_end', 'time_end', 'salary_shift', 'price_hour', 'work_time'], 'safe'],
+ [['slot_type_id', 'date_add', 'date_end', 'time_end', 'salary_shift', 'price_hour', 'work_time', 'autoclosed'], 'safe'],
[['date_shift'], 'date', 'format' => 'yyyy-M-d'],
[['time_start', 'shift_id'], 'required'],
];