From ff7831c75ebfc79b713763ea7c684dd84f0e594e Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 7 Jun 2024 10:01:46 +0300 Subject: [PATCH] =?utf8?q?ERP-5=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?utf8?q?=D1=82=D0=B0=D1=82=D1=8C=20=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?utf8?q?=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=BF=D0=BB=D0=B0=D0=BD=20?= =?utf8?q?=D0=BF=D0=BE=20=D1=81=D0=BE=D1=82=D1=80=D1=83=D0=B4=D0=BD=D0=B8?= =?utf8?q?=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../timetable/StartShiftStepOneAction.php | 6 +- .../timetable/StartShiftStepTwoAction.php | 6 +- erp24/forms/timetable/StartForm.php | 2 + ...0603_082541_create_new_fact_plan_table.php | 6 +- erp24/records/TimetableFactModel.php | 105 ++++++++++++------ .../views/timetable/start_shift_step_one.php | 9 ++ 6 files changed, 88 insertions(+), 46 deletions(-) diff --git a/erp24/actions/timetable/StartShiftStepOneAction.php b/erp24/actions/timetable/StartShiftStepOneAction.php index 8a743b52..26ed5bee 100755 --- a/erp24/actions/timetable/StartShiftStepOneAction.php +++ b/erp24/actions/timetable/StartShiftStepOneAction.php @@ -1,5 +1,5 @@ getStores(), 'id', 'name'); } + $shiftArray = ArrayHelper::map(Shift::find()->all(), 'id', 'name'); + return $this->controller->render('/timetable/start_shift_step_one.php', [ 'userModel' => $userModel, 'adminStores' => $adminStores, 'device' => $device, 'dayCheckins' => $dayCheckins, 'lastCheckin' => $lastCheckin, + 'shiftArray' => $shiftArray, ]); } } \ No newline at end of file diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index 9716da08..ca91c5b1 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -109,9 +109,6 @@ class StartShiftStepTwoAction extends Action } } - $timetableFact = new TimetableFactModel(); - $timetableFact->setValues($model, $planSlots, $lastCheckin); - if (!$model->date) { \Yii::warning('Не указана дата явки. Скорее всего отсутствуент связанный план. admin_id:' . $model->admin_id . ', plan_id:' . $model->plan_id . ', store_id:' . $model->store_id); $model->date = date('Y-m-d'); @@ -125,10 +122,9 @@ class StartShiftStepTwoAction extends Action $model->load($this->controller->request->post()); $model->photo = UploadedFile::getInstance($model, 'photo'); $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; diff --git a/erp24/forms/timetable/StartForm.php b/erp24/forms/timetable/StartForm.php index ec4a06f9..30067891 100755 --- a/erp24/forms/timetable/StartForm.php +++ b/erp24/forms/timetable/StartForm.php @@ -49,6 +49,7 @@ class StartForm extends Model public $checkinModel; /** @var TimetablePlan */ private $planSlotModel; + public $shift_id; public function isStart() { @@ -183,6 +184,7 @@ class StartForm extends Model $this->addError('date', 'Дата не совпадает с планом'); } }], + [['shift_id'], 'safe'], ]; } diff --git a/erp24/migrations/m240603_082541_create_new_fact_plan_table.php b/erp24/migrations/m240603_082541_create_new_fact_plan_table.php index 0437c271..e9cabca4 100644 --- a/erp24/migrations/m240603_082541_create_new_fact_plan_table.php +++ b/erp24/migrations/m240603_082541_create_new_fact_plan_table.php @@ -12,7 +12,7 @@ class m240603_082541_create_new_fact_plan_table extends Migration */ public function safeUp() { - $this->createTable('{{%timetable_fact}}', [ + $this->createTable('{{%erp24.timetable_fact}}', [ 'id' => $this->primaryKey(), 'admin_id' => $this->integer()->comment('ID сотрудника'), 'store_id' => $this->integer()->comment('ID магазина'), @@ -27,7 +27,7 @@ class m240603_082541_create_new_fact_plan_table extends Migration 'plan_id' => $this->integer()->comment('ID табеля если смена поставлена'), 'shift_id' => $this->integer()->comment('тип смены'), 'admin_id_add' => $this->integer()->comment('ID поставившего смену'), - 'time_start' => $this->integer()->comment('время начала работы по графику'), + 'time_start' => $this->time()->comment('время начала работы по графику'), 'time_end' => $this->time()->comment('время окончания работы по графику'), 'work_time' => $this->float()->comment('рабочее время'), 'price_hour' => $this->float()->comment('часовая ставка'), @@ -58,6 +58,6 @@ class m240603_082541_create_new_fact_plan_table extends Migration $this->dropForeignKey('fk_timetable_fact_to_plan', 'timetable_fact'); $this->dropForeignKey('fk_timetable_fact_to_admin_as_admin_id_add', 'timetable_fact'); - $this->dropTable('{{%timetable_fact}}'); + $this->dropTable('{{%erp24.timetable_fact}}'); } } diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 582d2e14..47a19aba 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -5,10 +5,12 @@ declare(strict_types=1); namespace app\records; use yii\db\ActiveRecord; -use yii_app\api3\modules\v1\models\timetable\Timetable; +use yii_app\records\TimetablePlan; +use yii_app\records\Timetable; use yii_app\records\Admin; use yii_app\records\AdminGroup; use yii_app\records\CityStore; +use yii_app\records\EmployeePayment; use yii_app\records\Shift; /** @@ -21,13 +23,13 @@ use yii_app\records\Shift; * @property $date_shift дата смены * @property $date_start дата время открытия смены * @property $date_end дата время закрытия смены - * @property bool $is_active на открытие смены + * @property bool $is_opening на открытие смены * @property bool $is_close на закрытие смены * @property int $tabel табель * @property int $plan_id ID табеля если смена поставлена * @property int $shift_id тип смены * @property int $admin_id_add ID поставившего смену - * @property $time_start время начала работы по графику + * @property $time_start время начала работы по графику * @property $time_end время окончания работы по графику * @property float $work_time время окончания работы по графику * @property float $price_hour часовая ставка @@ -39,6 +41,9 @@ use yii_app\records\Shift; */ class TimetableFactModel extends ActiveRecord { + + public const WORK_HOURS_TIME = 12; + public static function tableName() { return 'timetable_fact'; @@ -47,52 +52,78 @@ class TimetableFactModel extends ActiveRecord public function rules() { return [ - [[]], - [['is_opening, is_close'], 'boolean'], - [['is_opening, is_close'], 'default', 'value' => null], +// [['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], [['admin_id', 'admin_id_add'], 'exist', 'targetClass' => Admin::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], [['store_id'], 'exist', 'targetClass' => CityStore::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], - [['shift_id'], 'in', 'range' => array_keys(Shift::all()), 'skipOnEmpty' => false], [['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', 'in', 'range' => array_keys(Timetable::slotTypeName())], + [['slot_type_id', 'shift_id', 'date_add', 'time_end', 'salary_shift'], 'safe'], [['date_shift'], 'date', 'format' => 'yyyy-M-d'], - [['salary_shift'], 'in', 'range' => \yii_app\records\Timetable::getSalariesDay(), 'skipOnEmpty' => true], - [['datetime_start', 'datetime_end'], 'required'], - [['tabel', 'plan_id', 'status'], 'safe', 'skipOnEmpty' => false,], - ['price_hour', 'float'], - [['date_add'], 'datetime', 'format' => "yyyy-MM-dd H:m:s"], +// [['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"], ]; } - public function setValues($adminCheckin, $timetable, $lastCheckin) + public static function setValues($adminCheckin, $shift_id) { - $this->admin_id = $adminCheckin->admin_id; - $this->admin_group_id = $adminCheckin->admin->shift; - $this->d_id = $adminCheckin->d_id; - $this->store_id = $adminCheckin->store_id; - $this->date_shift = $adminCheckin->date; - $this->shift_id = $timetable->shift_id; - $this->comment = $timetable->comment; - $this->work_time = $timetable->work_time < 12 ? $timetable->work_time : 12; - $this->salary_shift = $timetable->salary_shift; - $this->admin_id_add = $timetable->admin_id_add; - $this->tabel = $timetable->tabel; - $this->slot_type_id = $timetable->slot_type_id; - $this->plan_id = $adminCheckin->plan_id; - $this->time_start = $timetable->time_start; - $this->time_end = $timetable->time_end; - $this->date_end = $timetable->datetime_end; - if (empty($lastCheckin)) { - $is_active = true; - } else { - $is_close = true; + 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; + + } 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 = EmployeePayment::findOne(['admin_id' => $adminCheckin->admin_id])->daily_payment; + $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(); + } } - $this->save(); - } +// } public function getAdmin() { @@ -111,7 +142,7 @@ class TimetableFactModel extends ActiveRecord public function getPlan() { - return $this->hasOne(TimetablePlan::class, ['id' => 'plan_id']); + return $this->hasOne(Timetable::class, ['id' => 'plan_id']); } public function getD() diff --git a/erp24/views/timetable/start_shift_step_one.php b/erp24/views/timetable/start_shift_step_one.php index 8efda329..598e345a 100644 --- a/erp24/views/timetable/start_shift_step_one.php +++ b/erp24/views/timetable/start_shift_step_one.php @@ -8,6 +8,7 @@ * @var AdminCheckin $lastCheckin * @var TimetablePlan[] $planSlots * @var array $adminStores + * @var array $shiftArray */ use yii\helpers\ArrayHelper; @@ -115,6 +116,14 @@ use yii_app\forms\timetable\StartForm; ?> + +
+
Тип смены
+ "form-select", + 'aria-label' => "Пример выбора по умолчанию", + ]) ?> +
'btn btn-bd-primary ps-3 pe-3 mt-2']); ?> -- 2.39.5