]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-5 Доработать фактический план по сотрудникам
authormarina <m.zozirova@gmail.com>
Wed, 5 Jun 2024 05:08:49 +0000 (08:08 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 5 Jun 2024 05:08:49 +0000 (08:08 +0300)
erp24/actions/timetable/StartShiftStepTwoAction.php
erp24/migrations/m240603_082541_create_new_fact_plan_table.php [new file with mode: 0644]
erp24/records/TimetableFactModel.php [new file with mode: 0644]

index 83090d75d6750005f88ad699874e030e293b24ab..0a7d91eba4b63986919202ec206d596aaab7062a 100755 (executable)
@@ -3,6 +3,7 @@ declare(strict_types = 1);
 
 namespace yii_app\actions\timetable;
 
+use app\records\TimetableFactModel;
 use Yii;
 use yii\base\Action;
 use yii\helpers\ArrayHelper;
@@ -77,11 +78,7 @@ class StartShiftStepTwoAction extends Action
 
         /** @var TimetablePlan[] $planSlots */
         $planSlots = TimetablePlan::find()
-            ->andWhere(
-                ($device->isFixedStore() && !$userModel->adminGroup->isRoaming()) ?
-                    ['store_id' => $model->store_id] :
-                    ['admin_id' => $model->admin_id]
-            )
+            ->andFilterWhere(['store_id' => $model->store_id])
             ->andWhere(['OR',
                 ['BETWEEN', 'datetime_start', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))],
                 ['BETWEEN', 'datetime_end', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')],
@@ -112,6 +109,9 @@ class StartShiftStepTwoAction extends Action
             }
         }
 
+        $timetableFact = new TimetableFactModel();
+        $timetableFact->setValues($model, $planSlots);
+
         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');
diff --git a/erp24/migrations/m240603_082541_create_new_fact_plan_table.php b/erp24/migrations/m240603_082541_create_new_fact_plan_table.php
new file mode 100644 (file)
index 0000000..0437c27
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%new_fact_plan}}`.
+ */
+class m240603_082541_create_new_fact_plan_table extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable('{{%timetable_fact}}', [
+            'id' => $this->primaryKey(),
+            'admin_id' => $this->integer()->comment('ID сотрудника'),
+            'store_id' => $this->integer()->comment('ID магазина'),
+            'admin_group_id' => $this->integer()->comment('ID должности'),
+            'd_id' => $this->integer()->comment('в какой должности работал на смене'),
+            'date_shift' => $this->date()->comment('дата смены'),
+            'date_start' => $this->date()->comment('дата время открытия смены'),
+            'date_end' => $this->date()->comment('дата время закрытия смены'),
+            'is_opening' => $this->boolean()->comment('на открытие смены'),
+            'is_close' => $this->boolean()->comment('на закрытие смены'),
+            'tabel' => $this->integer()->comment('табель'),
+            'plan_id' => $this->integer()->comment('ID табеля если смена поставлена'),
+            'shift_id' => $this->integer()->comment('тип смены'),
+            'admin_id_add' => $this->integer()->comment('ID поставившего смену'),
+            'time_start' => $this->integer()->comment('время начала работы по графику'),
+            'time_end' => $this->time()->comment('время окончания работы по графику'),
+            'work_time' => $this->float()->comment('рабочее время'),
+            'price_hour' => $this->float()->comment('часовая ставка'),
+            'salary_shift' => $this->integer()->comment('оплата за смену'),
+            'slot_type_id' => $this->integer()->comment('тип занятности'),
+            'comment' => $this->text()->comment('комментарий'),
+            'date_add' => $this->timestamp()->comment('дата постановки смены'),
+            'status' => $this->integer()->comment('статус смены'),
+        ]);
+
+        $this->addForeignKey('fk_timetable_fact_to_admin', 'timetable_fact', 'admin_id', 'admin', 'id');
+        $this->addForeignKey('fk_timetable_fact_to_store', 'timetable_fact', 'store_id', 'store', 'id');
+        $this->addForeignKey('fk_timetable_fact_to_admin_group', 'timetable_fact', 'admin_group_id', 'admin_group', 'id');
+        $this->addForeignKey('fk_timetable_fact_to_admin_group_as_d', 'timetable_fact', 'd_id', 'admin_group', 'id');
+        $this->addForeignKey('fk_timetable_fact_to_plan', 'timetable_fact', 'plan_id', 'timetable', 'id');
+        $this->addForeignKey('fk_timetable_fact_to_admin_as_admin_id_add', 'timetable_fact', 'admin_id_add', 'admin', 'id');
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropForeignKey('fk_timetable_fact_to_admin', 'timetable_fact');
+        $this->dropForeignKey('fk_timetable_fact_to_store', 'timetable_fact');
+        $this->dropForeignKey('fk_timetable_fact_to_admin_group', 'timetable_fact');
+        $this->dropForeignKey('fk_timetable_fact_to_admin_group_as_d', 'timetable_fact');
+        $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}}');
+    }
+}
diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php
new file mode 100644 (file)
index 0000000..f58a603
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+
+declare(strict_types=1);
+
+namespace app\records;
+
+use yii\db\ActiveRecord;
+use yii_app\api3\modules\v1\models\timetable\Timetable;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
+use yii_app\records\CityStore;
+use yii_app\records\Shift;
+
+/**
+ * Class TimetableFactModel
+ * @property int $id
+ * @property int $admin_id ID сотрудника
+ * @property int $store_id ID магазина
+ * @property int $admin_group_id ID должности
+ * @property int $d_id в какой должности работал на смене
+ * @property $date_shift дата смены
+ * @property $date_start дата время открытия смены
+ * @property $date_end дата время закрытия смены
+ * @property bool $is_active на открытие смены
+ * @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_end время окончания работы по графику
+ * @property float $work_time время окончания работы по графику
+ * @property float $price_hour часовая ставка
+ * @property float $salary_shift оплата за смену
+ * @property float $slot_type_id тип занятности
+ * @property string $comment комментарий
+ * @property  $date_add дата постановки смены
+ * @property int $status статус смены
+ */
+class TimetableFactModel extends ActiveRecord
+{
+    public static function tableName()
+    {
+        return '{{%timetable_fact}}';
+    }
+
+    public function rules()
+    {
+        return [
+            [[]],
+            [['is_opening, is_close'], 'boolean'],
+            [['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())],
+            [['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"],
+        ];
+    }
+
+    public function setValues($adminCheckin, $timetable)
+    {
+        $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;
+        $this->save();
+    }
+
+    public function getAdmin()
+    {
+        return $this->hasOne(Admin::class, ['id' => 'admin_id']);
+    }
+
+    public function getAdminAdd()
+    {
+        return $this->hasOne(Admin::class, ['id' => 'admin_id_add']);
+    }
+
+    public function getStore()
+    {
+        return $this->hasOne(CityStore::class, ['id' => 'store_id']);
+    }
+
+    public function getPlan()
+    {
+        return $this->hasOne(TimetablePlan::class, ['id' => 'plan_id']);
+    }
+
+    public function getD()
+    {
+        return $this->hasOne(AdminGroup::class, ['id' => 'd_id']);
+    }
+
+    public function getAdminGroup()
+    {
+        return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']);
+    }
+}
\ No newline at end of file