From: Alexander Smirnov Date: Fri, 28 Jun 2024 14:37:40 +0000 (+0300) Subject: [ERP-70] Автоматическое закрытие смен через 14 часов после их открытия X-Git-Tag: 1.3~25^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=bcb5052e7b90a288a694012ac662f5cb2687163c;p=erp24_rep%2Fyii-erp24%2F.git [ERP-70] Автоматическое закрытие смен через 14 часов после их открытия --- diff --git a/erp24/commands/TimetableController.php b/erp24/commands/TimetableController.php new file mode 100644 index 00000000..5653f944 --- /dev/null +++ b/erp24/commands/TimetableController.php @@ -0,0 +1,53 @@ +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 diff --git a/erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php b/erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php new file mode 100755 index 00000000..090f9ffd --- /dev/null +++ b/erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php @@ -0,0 +1,27 @@ +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'); + } +} diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index f36cb792..709fed2d 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -27,6 +27,7 @@ use yii_app\records\Shift; * @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 тип смены @@ -66,6 +67,7 @@ class TimetableFactModel extends ActiveRecord 'date_end' => 'дата закрытия смены', 'is_opening' => 'смена открыта?', 'is_close' => 'смена закрыта?', + 'autoclosed' => 'если смена закрыта, то автоматически?', 'tabel' => 'табель', 'plan_id' => 'Табель, если смена поставлена', 'shift_id' => 'тип смены', @@ -95,7 +97,7 @@ class TimetableFactModel extends ActiveRecord // [['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'], ];