From: marina Date: Wed, 12 Jun 2024 20:18:26 +0000 (+0300) Subject: ERP-5 Доработать фактический план по сотрудникам X-Git-Tag: 1.2^2~4^2~9 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d4241591e23ed3bf6623c4bcac7f34dd7a684d93;p=erp24_rep%2Fyii-erp24%2F.git ERP-5 Доработать фактический план по сотрудникам --- diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index ca91c5b1..49b12f1a 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -60,6 +60,7 @@ class StartShiftStepTwoAction extends Action $model->admin_id = $userModel->id; $model->d_id = $userModel->group_id; $model->ball = 5; + $model->shift_id = $request->getBodyParam('shift_id'); if (empty($model->store_id)) { $model->store_id = (!empty($adminStoreId)) ? $adminStoreId : $device->store_id; } @@ -124,9 +125,9 @@ class StartShiftStepTwoAction extends Action $validate = $model->validate(); if ($validate) { $model->save(); - TimetableFactModel::setValues($model, $request->getBodyParam('shift_id')); $model->checkin_id = $model->checkinModel->id; $model->id = $model->checkinModel->id; + TimetableFactModel::setValues($model); if ($this->controller->request->getHeaders()->get('Accept') == 'application/json') { $this->controller->response->format = Response::FORMAT_JSON; diff --git a/erp24/controllers/TimetableFactController.php b/erp24/controllers/TimetableFactController.php new file mode 100644 index 00000000..820302c5 --- /dev/null +++ b/erp24/controllers/TimetableFactController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all TimetableFactModel models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => TimetableFactModel::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single TimetableFactModel model. + * @param int $id + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new TimetableFactModel model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new TimetableFactModel(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing TimetableFactModel model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing TimetableFactModel model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the TimetableFactModel model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id + * @return TimetableFactModel the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = TimetableFactModel::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); + } +} diff --git a/erp24/forms/timetable/StartForm.php b/erp24/forms/timetable/StartForm.php index 30067891..b0446f02 100755 --- a/erp24/forms/timetable/StartForm.php +++ b/erp24/forms/timetable/StartForm.php @@ -184,7 +184,7 @@ class StartForm extends Model $this->addError('date', 'Дата не совпадает с планом'); } }], - [['shift_id'], 'safe'], + [['shift_id'], 'required'], ]; } diff --git a/erp24/migrations/m240611_095133_change_timetable_fact_table.php b/erp24/migrations/m240611_095133_change_timetable_fact_table.php new file mode 100644 index 00000000..ff8de041 --- /dev/null +++ b/erp24/migrations/m240611_095133_change_timetable_fact_table.php @@ -0,0 +1,41 @@ +dropForeignKey('fk_timetable_fact_to_store', 'timetable_fact'); + + $this->alterColumn('timetable_fact', 'work_time', $this->integer()->comment('рабочее время')); + + $this->addColumn('timetable_fact', 'checkin_start_id', $this->integer()->comment('ID Отметка о начале работы')); + $this->addColumn('timetable_fact', 'checkin_end_id', $this->integer()->comment('ID Отметки об окончании работы')); + + $this->addForeignKey('fk_timetable_fact_to_admin_checkin_start', 'timetable_fact', 'checkin_start_id', 'admin_checkin', 'id'); + $this->addForeignKey('fk_timetable_fact_to_admin_checkin_end', 'timetable_fact', 'checkin_end_id', 'admin_checkin', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->addForeignKey('fk_timetable_fact_to_store', 'timetable_fact', 'store_id', 'city_store', 'id'); + + $this->alterColumn('timetable_fact', 'work_time', $this->float()->comment('рабочее время')); + + $this->dropColumn('timetable_fact', 'checkin_start_id'); + $this->dropColumn('timetable_fact', 'checkin_end_id'); + + $this->dropForeignKey('fk_timetable_fact_to_admin_checkin_start', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_admin_checkin_end', 'timetable_fact'); + } +} diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 7d9b44fe..457d7e72 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace app\records; +use Throwable; use yii\db\ActiveRecord; +use yii_app\records\AdminCheckin; use yii_app\records\TimetablePlan; use yii_app\records\Timetable; use yii_app\records\Admin; @@ -31,13 +33,15 @@ use yii_app\records\Shift; * @property int $admin_id_add ID поставившего смену * @property $time_start время начала работы по графику * @property $time_end время окончания работы по графику - * @property float $work_time время окончания работы по графику + * @property int $work_time время окончания работы по графику * @property float $price_hour часовая ставка * @property float $salary_shift оплата за смену * @property float $slot_type_id тип занятности * @property string $comment комментарий * @property $date_add дата постановки смены * @property int $status статус смены + * @property int $checkin_start_id ID Отметка о начале работы + * @property int $checkin_end_id ID Отметки об окончании работы */ class TimetableFactModel extends ActiveRecord { @@ -52,84 +56,99 @@ class TimetableFactModel extends ActiveRecord public function rules() { return [ -// [['is_opening, is_close'], 'boolean'], -// [['is_opening, is_close'], 'default', 'value' => null], [['d_id', 'admin_group_id'], 'exist', 'targetClass' => AdminGroup::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], + [['checkin_start_id', 'checkin_end_id'], 'exist', 'targetClass' => AdminCheckin::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], [['admin_id', 'admin_id_add'], 'exist', 'targetClass' => Admin::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], [['store_id'], 'exist', 'targetClass' => CityStore::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], [['time_start', 'time_end'], 'date', 'format' => 'HH:mm:ss'], [['work_time'], 'number', 'min' => 0, 'max' => 24], [['comment'], 'string'], [['comment'], 'default', 'value' => null], - [['slot_type_id', 'shift_id', 'date_add', 'time_end', 'salary_shift', 'price_hour'], 'safe'], + [['slot_type_id', 'date_add', 'date_end', 'time_end', 'salary_shift', 'price_hour'], 'safe'], [['date_shift'], 'date', 'format' => 'yyyy-M-d'], -// [['salary_shift'], 'in', 'range' => \yii_app\records\Timetable::getSalariesDay(), 'skipOnEmpty' => true], - [['time_start'], 'required'], -// [['price_hour'], 'number', 'numberPattern' => '/^\d+(\.\d{1,2})?$/'], -// [['date_add'], 'datetime', 'format' => "yyyy-MM-dd H:m:s"], + [['time_start', 'shift_id'], 'required'], ]; } - public static function setValues($adminCheckin, $shift_id) + public static function setValues($adminCheckin) { - if ($model = self::findOne(['admin_id' => $adminCheckin->admin_id, 'date_shift' => date('Y-m-d', strtotime($adminCheckin->date)), 'is_opening' => true]) ?? - self::findOne(['admin_id' => $adminCheckin->admin_id, 'date_shift' => date('Y-m-d', strtotime($adminCheckin->date . ' -1 day')), 'is_opening' => true])) { - - $model->date_start = date("Y-m-d", strtotime($adminCheckin->time)); - $model->time_end = date("H:i:s", strtotime($adminCheckin->time)); - $model->is_close = true; - $model->work_time = min((strtotime($model->time_end) - strtotime($model->time_start)) / 3600, self::WORK_HOURS_TIME); - $model->status = $adminCheckin->type_id; + if ($model = self::find() + ->where(['admin_id' => $adminCheckin->admin_id, 'is_opening' => true]) + ->andWhere(['between', 'date_shift', date('Y-m-d', strtotime($adminCheckin->date . ' -1 day')), date('Y-m-d', strtotime($adminCheckin->date))]) + ->andWhere(['status' => AdminCheckin::TYPE_START]) + ->one()) { + + $model->date_end = date("Y-m-d", strtotime($adminCheckin->time)); + $model->time_end = date("H:i:s", strtotime($adminCheckin->time)); + $model->is_close = true; + $model->is_opening = false; + $model->work_time = min((strtotime($model->time_end) - strtotime($model->time_start)) / 3600, self::WORK_HOURS_TIME); + $model->status = AdminCheckin::TYPE_END; + $model->checkin_end_id = $adminCheckin->id; + + } else { + $model = new TimetableFactModel(); + $model->date_end = null; + $model->date_start = date("Y-m-d", strtotime($adminCheckin->time)); + $model->time_start = date("H:i:s", strtotime($adminCheckin->time)); + $model->is_opening = true; + $model->status = AdminCheckin::TYPE_START; + $model->checkin_start_id = $adminCheckin->id; + + $timetable = Timetable::findOne(['date' => $adminCheckin->date]); + + if (!empty($timetable)) { + $model->tabel = $timetable->id; + $model->plan_id = $timetable->plan_id; + $model->admin_id_add = $timetable->admin_id_add; + $model->comment = $timetable->comment; + $model->date_add = $timetable->date_add; } else { - $model = new TimetableFactModel(); - $model->date_end = null; - $model->date_start = date("Y-m-d", strtotime($adminCheckin->time)); - $model->time_start = date("H:i:s", strtotime($adminCheckin->time)); - $model->is_opening = true; - $model->status = $adminCheckin->type_id; - - $timetable = Timetable::findOne(['date' => $adminCheckin->date]); - - if (!empty($timetable)) { - $model->tabel = $timetable->id; - $model->plan_id = $timetable->plan_id; - $model->admin_id_add = $timetable->admin_id_add; - $model->comment = $timetable->comment; - $model->date_add = $timetable->date_add; - - } else { - $model->tabel = 1; - $model->plan_id = null; - $model->admin_id_add = null; - $model->comment = null; - $model->date_add = null; - } - - $model->admin_id = $adminCheckin->admin_id; - $model->admin_group_id = Admin::findOne(['id' => $adminCheckin->admin_id])->group_id; - $model->d_id = $adminCheckin->d_id; - $model->store_id = $adminCheckin->store_id; - $model->date_shift = $adminCheckin->date; - $model->shift_id = $shift_id; - $model->salary_shift = !empty($salary = EmployeePayment::findOne(['admin_id' => $adminCheckin->admin_id])) ? $salary->daily_payment : null; - $model->price_hour = $model->salary_shift / ($model->d_id == AdminGroup::GROUP_ADMINISTRATORS ? 8 : 12); + $model->tabel = 1; + $model->plan_id = null; + $model->admin_id_add = null; + $model->comment = null; + $model->date_add = null; } - if ($model->validate()) { - $model->save(); - } else { - var_dump($model->getErrors()); - die(); - } + $model->admin_id = $adminCheckin->admin_id; + $model->admin_group_id = Admin::findOne(['id' => $adminCheckin->admin_id])->group_id; + $model->d_id = $adminCheckin->d_id; + $model->store_id = $adminCheckin->store_id; + $model->date_shift = $adminCheckin->date; + $model->shift_id = $adminCheckin->shift_id; + $model->salary_shift = !empty($salary = EmployeePayment::findOne(['admin_id' => $adminCheckin->admin_id])) ? $salary->daily_payment : null; + $model->price_hour = $model->salary_shift / ($model->d_id == AdminGroup::GROUP_ADMINISTRATORS ? 8 : 12); } -// } + + if($model->validate()) { + $model->save(); + } else { + var_dump($model->getErrors());die(); + } + } + public function getAdmin() { return $this->hasOne(Admin::class, ['id' => 'admin_id']); } + public function getCheckinStart() +{ + return $this->hasOne(AdminCheckin::class, ['id' => 'checkin_start_id']); +} + + public function getCheckinEnd() + { + return $this->hasOne(AdminCheckin::class, ['id' => 'checkin_end_id']); + } + public function getShift() + { + return $this->hasOne(Shift::class, ['id' => 'shift_id']); + } + public function getAdminAdd() { return $this->hasOne(Admin::class, ['id' => 'admin_id_add']); diff --git a/erp24/views/timetable-fact/index.php b/erp24/views/timetable-fact/index.php new file mode 100644 index 00000000..26121733 --- /dev/null +++ b/erp24/views/timetable-fact/index.php @@ -0,0 +1,93 @@ +title = Yii::t('app', 'Фактический табель сотрудников (Новый!)'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'attribute' => 'admin_id', + 'label' => 'Пользователь', + 'value' => function ($data) { + return $data->admin->name; + } + ], + [ + 'attribute' => 'store_id', + 'label' => 'Магазин, Должность', + 'format' => 'raw', + 'value' => function ($data) { + return $data->store->name . "
" . $data->adminGroup->name; + } + ], + [ + 'label' => 'Тип смены', + 'attribute' => 'shift_id', + 'format' => 'raw', + 'value' => function ($model) { + return $model->shift->name; + }, + ], + [ + 'label' => 'Отработанное время', + 'attribute' => 'work_time', + ], + [ + 'label' => 'Дата смены', + 'attribute' => 'date_shift', + 'format' => ['date', 'php:d.m.Y'], + ], + [ + 'label' => 'Начало', + 'attribute' => 'date_start', + 'format' => 'raw', + 'value' => function ($model) { + return Yii::$app->formatter->asDatetime($model->date_start, 'php:d.m.Y') . "
" . + Yii::$app->formatter->asDatetime($model->time_start, 'php:H:i:s'); + }, + ], + [ + 'label' => 'Конец', + 'attribute' => 'date_end', + 'format' => 'raw', + 'value' => function ($model) { + return !empty($model->date_end) ? Yii::$app->formatter->asDatetime($model->date_end, 'php:d.m.Y') . "
" . + Yii::$app->formatter->asDatetime($model->time_end, 'php:H:i:s') : 'Работает'; + }, + ], + [ + 'label' => 'Отметка о начале', + 'format' => 'raw', + 'value' => function ($model) { + return !empty($model->checkinStart->photo) ? Html::img($model->checkinStart->photo, ['alt="selfie" height="100px"']) : ''; + }, + ], + [ + 'label' => 'Отметка о конце', + 'format' => 'raw', + 'value' => function ($model) { + return !empty($model->checkinEnd->photo) ? Html::img($model->checkinEnd->photo, ['alt="selfie" height="100px"']) : ''; + }, + ], + ], + ]); ?> + + +
diff --git a/erp24/views/timetable/start_shift_step_two.php b/erp24/views/timetable/start_shift_step_two.php index be03be53..f0530acb 100644 --- a/erp24/views/timetable/start_shift_step_two.php +++ b/erp24/views/timetable/start_shift_step_two.php @@ -14,6 +14,7 @@ use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii_app\forms\timetable\StartForm; use yii_app\records\AdminCheckin; +use yii_app\records\Shift; use yii_app\records\TimetablePlan; \yii_app\assets\timetable\StartAsset::register($this); @@ -79,6 +80,7 @@ if ($userModel->adminGroup->isRoaming()) { + isStart()) { ?> @@ -175,10 +177,17 @@ if ($userModel->adminGroup->isRoaming()) {
adminGroup->name?>
Магазин
+
+
Тип смены
+ +
+
@@ -192,6 +201,11 @@ if ($userModel->adminGroup->isRoaming()) { >
+
+
shift_id)->name ?>
+