From: Alexander Smirnov Date: Tue, 25 Jun 2024 10:14:03 +0000 (+0300) Subject: Добавлен интерфейс добавления фактических смен X-Git-Tag: 1.3~45^2~3 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ac06e355dfc98fb54b78aa7c78a2c04309d2d96b;p=erp24_rep%2Fyii-erp24%2F.git Добавлен интерфейс добавления фактических смен --- diff --git a/erp24/actions/timetable/AddFactHandAction.php b/erp24/actions/timetable/AddFactHandAction.php new file mode 100644 index 00000000..0397e175 --- /dev/null +++ b/erp24/actions/timetable/AddFactHandAction.php @@ -0,0 +1,179 @@ +request->post('action'); + + $model = DynamicModel::validateData([ + 'admin_id' => 0, 'store_id' => 0, 'shift_id' => 0, 'plan_id' => null, + 'tabel' => null, 'admin_group_id' => null, 'timetable_fact_id' => null, 'shift_start' => null, 'shift_end' => null + ], + [ + [['admin_id', 'store_id', 'shift_id', 'shift_start', 'shift_end'], 'required'], + [['plan_id', 'tabel', 'admin_group_id', 'timetable_fact_id'], 'safe'] + ]); + + $allowAdd = false; + if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { + if ($model->validate()) { + $allowAdd = true; + if (in_array($action, ['createFact', 'createFactOpenShift', 'createFactCloseShift'])) { + + $checkInIds = []; + foreach (range(0,1) as $index) { + if ($index == 0 && $action == 'createFactCloseShift') { + continue; + } + if ($index == 1 && $action == 'createFactOpenShift') { + continue; + } + $checkIn = new AdminCheckin; + $checkIn->admin_id = $model->admin_id; + if (!empty($model->plan_id)) { + $checkIn->plan_id = $model->plan_id; + } + $checkIn->store_id = $model->store_id; + $checkIn->ball = 5; + $checkIn->comment = "Ручное добавление чекина"; + $checkIn->d_id = $model->admin_group_id; + $checkIn->date = date('Y-m-d', strtotime($model->shift_start)); + $checkIn->time = [$model->shift_start, $model->shift_end][$index]; + $checkIn->lat = null; + $checkIn->lon = null; + $checkIn->photo = 'images/next.png'; + $checkIn->device_id = AdminDevice::findOne(['admin_id' => $model->admin_id])->id ?? 0; + $checkIn->type_id = in_array($model->shift_id, [5, 8]) ? AdminCheckin::TYPE_APPEAR : + [AdminCheckin::TYPE_START, AdminCheckin::TYPE_END][$index]; + $checkIn->status = 0; + $checkIn->save(); + if ($checkIn->getErrors()) { + throw new \Exception(Json::encode($checkIn->getErrors())); + } + $checkInIds[$index] = $checkIn->id; + } + + if (in_array($action, ['createFact', 'createFactOpenShift'])) { + $timetableFactModel = new TimetableFactModel; + $timetableFactModel->admin_id = $model->admin_id; + $timetableFactModel->store_id = $model->store_id; + $timetableFactModel->admin_group_id = $model->admin_group_id; + $timetableFactModel->d_id = $model->admin_group_id; + $timetableFactModel->date_shift = date('Y-m-d', strtotime($model->shift_start)); + $timetableFactModel->date_start = $timetableFactModel->date_shift; + $timetableFactModel->date_end = date('Y-m-d', strtotime($model->shift_end)); + $timetableFactModel->is_opening = false; + $timetableFactModel->is_close = true; + if (!empty($model->tabel)) { + $timetableFactModel->tabel = $model->tabel; + } + $timetableFactModel->shift_id = $model->shift_id; + $timetableFactModel->admin_id_add = Yii::$app->user->id; + $timetableFactModel->time_start = date("H:i:s", strtotime($model->shift_start)); + $timetableFactModel->time_end = date("H:i:s", strtotime($model->shift_end)); + $timetableFactModel->work_time = min(abs(strtotime($timetableFactModel->date_end + . $timetableFactModel->time_end) + 600 - strtotime($timetableFactModel->date_start + . $timetableFactModel->time_start)) / 3600, TimetableFactModel::WORK_HOURS_TIME); + + $timetableFactModel->salary_shift = !empty($salary = EmployeePayment::findOne(['admin_id' => $model->admin_id])) ? $salary->daily_payment : null; + $timetableFactModel->price_hour = $timetableFactModel->salary_shift / ($timetableFactModel->d_id == AdminGroup::GROUP_ADMINISTRATORS ? 8 : 12); + $timetableFactModel->date_add = date('Y-m-d H:i:s'); + $timetableFactModel->status = AdminCheckin::TYPE_END; + $timetableFactModel->checkin_start_id = $checkInIds[0]; + if ($action == 'createFact') { + $timetableFactModel->checkin_end_id = $checkInIds[1]; + } + } + if ($action == 'createFactCloseShift') { + $timetableFactModel = TimetableFactModel::findOne($model->timetable_fact_id); + $timetableFactModel->checkin_end_id = $checkInIds[1]; + } + $timetableFactModel->save(); + if ($timetableFactModel->getErrors()) { + throw new \Exception(Json::encode($timetableFactModel->getErrors())); + } + + return $this->controller->redirect('/timetable/add-fact-hand'); + } + } else { + $adm = Admin::findOne($model->admin_id); + if ($adm) { + $model->admin_group_id = $adm->group_id; + } + } + } + + $adminArr = []; + foreach (Admin::find()->with('adminGroup')->orderBy(['id' => SORT_ASC])->all() as $admin) { + if ($admin->group_id > 0) { + $adminArr[] = ['id' => $admin->id, 'name' => $admin->name, 'groupName' => $admin->adminGroup->name ?? "Другие"]; + } + } + $admins = ArrayHelper::map($adminArr, 'id', 'name', 'groupName'); + $stores = ArrayHelper::map(CityStore::find()->all(), 'id', 'name'); + $shifts = ArrayHelper::map(Shift::find()->all(), 'id', 'name'); + $adminGroups = ArrayHelper::map(AdminGroup::find()->all(), 'id', 'name'); + foreach ($adminGroups as $key => $name) { + if (!in_array($key, AdminGroup::getGroupsForEmployeeOnCashbox())) { + unset($adminGroups[$key]); + } + } + + $timetables = null; + $checkIns = null; + $timetableFacts = null; + + if ($allowAdd) { + $timetables = Timetable::find()->where([ + 'or', + [ + 'and', + ['<=', 'datetime_start', date('Y-m-d H:i:s', strtotime("+6 hour", strtotime($model->shift_start)))], + ['>=', 'datetime_end', date('Y-m-d H:i:s', strtotime("+6 hour", strtotime($model->shift_start)))], + ], + [ + 'and', + ['<=', 'datetime_start', date('Y-m-d H:i:s', strtotime("-6 hour", strtotime($model->shift_end)))], + ['>=', 'datetime_end', date('Y-m-d H:i:s', strtotime("-6 hour", strtotime($model->shift_end)))], + ], + [ + 'and', + ['>=', 'datetime_start', date('Y-m-d H:i:s', strtotime("+6 hour", strtotime($model->shift_start)))], + ['<=', 'datetime_end', date('Y-m-d H:i:s', strtotime("-6 hour", strtotime($model->shift_end)))], + ], + ])->andWhere(['admin_id' => $model->admin_id])->all(); + + $checkIns = AdminCheckin::find()->where(['admin_id' => $model->admin_id]) + ->andWhere([ + 'and', + ['>=', 'time', date('Y-m-d H:i:s', strtotime("-6 hour", strtotime($model->shift_start)))], + ['<=', 'time', date('Y-m-d H:i:s', strtotime("+6 hour", strtotime($model->shift_end)))], + ])->all(); + + $timetableFacts = TimetableFactModel::find()->where(['admin_id' => $model->admin_id]) + ->andWhere(['>=', 'date_shift', date('Y-m-d', strtotime($model->shift_start))]) + ->andWhere(['<=', 'date_shift', date('Y-m-d', strtotime($model->shift_end))]) + ->all(); + } + + return $this->controller->render('add-fact-hand', compact('model', 'admins', 'stores', + 'shifts', 'allowAdd', 'timetables', 'checkIns', 'timetableFacts', 'adminGroups')); + } +} \ No newline at end of file diff --git a/erp24/controllers/TimetableController.php b/erp24/controllers/TimetableController.php index 51811916..491387c0 100755 --- a/erp24/controllers/TimetableController.php +++ b/erp24/controllers/TimetableController.php @@ -34,6 +34,7 @@ class TimetableController extends \yii\web\Controller 'checkins' => \yii_app\actions\timetable\CheckinsAction::class, 'fact-overview-item' => \yii_app\actions\timetable\FactOverviewItemAction::class, 'join-missing-shifts-with-checkins' => \yii_app\actions\timetable\JoinMissingShiftsWithCheckinsAction::class, + 'add-fact-hand' => \yii_app\actions\timetable\AddFactHandAction::class, ]; } diff --git a/erp24/views/timetable/add-fact-hand.php b/erp24/views/timetable/add-fact-hand.php new file mode 100644 index 00000000..8080aa53 --- /dev/null +++ b/erp24/views/timetable/add-fact-hand.php @@ -0,0 +1,157 @@ + + +
+ + false]) ?> + +
+
+ Сотрудник:
field($model, 'admin_id')->dropDownList($admins)->label(false) ?>
+ Магазин:
field($model, 'store_id')->dropDownList($stores)->label(false) ?>
+ Тип смены:
field($model, 'shift_id')->dropDownList($shifts)->label(false) ?>
+
+ plan_id:
field($model, 'plan_id')->textInput(['type' => 'number'])->label(false) ?>
+ tabel:
field($model, 'tabel')->textInput(['type' => 'number'])->label(false) ?>
+ admin_group_id:
field($model, 'admin_group_id')->dropDownList($adminGroups)->label(false) ?>
+
+ Начало смены:
field($model, 'shift_start')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d H:i:s', + 'todayBtn' => true + ], + ])->label(false) ?>
+ Конец смены:
field($model, 'shift_end')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d H:i:s', + 'todayBtn' => true + ], + ])->label(false) ?>
+
+ 'btn btn-secondary btn-sm', 'name' => 'action', 'value' => 'showShiftsAndCheckins'])?> + + 'btn btn-danger btn-sm', 'name' => 'action', 'value' => 'createFact'])?> + 'btn btn-danger btn-sm', 'name' => 'action', 'value' => 'createFactOpenShift'])?> + timetable_fact_id:
field($model, 'timetable_fact_id')->textInput(['type' => 'number'])->label(false) ?>
+ 'btn btn-danger btn-sm', 'name' => 'action', 'value' => 'createFactCloseShift'])?> + +
+
+ + + + + Смены-Факты (/timetable-fact): + + + + + + + + + + + + + + + + + + + + + + + + + +
timetable_fact_idМагазинДень сменыНачала сменыКонец сменыЧекин старт idЧекин конец id
id ?>store_id] ?? '' ?>date_shift ?>time_start ?>time_end ?>checkin_start_id ?>checkin_end_id ?>
+ Смены (/timetable/fact, /timetable/plan): + + + + + + + + + + + + + + + + + + + + + + + +
idПлан/Фактadmin_group_idМагазинНачала сменыКонец смены
id ?>tabel == 0 ? 'План' : 'Факт'?>admin_group_id ?>store_id] ?? '' ?>datetime_start ?>datetime_end ?>
+ Чекины: + + + + + + + + + + + + + + + + + + + + + + + +
idplan_idtype_idВремяМагазинФото
id ?>plan_id ?>type_id == 1 ? 'Старт' : ($checkIn->type_id == 2 ? 'Конец' : 'Появление') ?>time ?>store_id] ?? '' ?>photo, 100) ?>
+ + +