From: marina Date: Thu, 4 Jul 2024 05:38:54 +0000 (+0300) Subject: ERP-65 X-Git-Tag: 1.3~23^2~8 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c1d09f35ca9001a6668c14b436fae4dc311f8981;p=erp24_rep%2Fyii-erp24%2F.git ERP-65 Перенести в новый фактический табель все смены сотрудников, которые были до 13.06 --- diff --git a/erp24/controllers/TimetableFactController.php b/erp24/controllers/TimetableFactController.php index 40781e51..a24d7cef 100644 --- a/erp24/controllers/TimetableFactController.php +++ b/erp24/controllers/TimetableFactController.php @@ -4,9 +4,13 @@ namespace app\controllers; use app\records\TimetableFactModel; use yii\data\ActiveDataProvider; +use yii\db\Query; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use yii_app\records\Admin; +use yii_app\records\AdminCheckin; +use yii_app\records\Timetable; /** * TimetableFactController implements the CRUD actions for TimetableFactModel model. @@ -142,4 +146,103 @@ class TimetableFactController extends Controller throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } + + public function actionAddOldShifts() + { + + $action = \Yii::$app->request->post('action'); + + $query = Timetable::find() + ->andWhere(['>=', 'date', '2024-06-01']) + ->andWhere(['<', 'date', date('Y-m-d')]) + ->andWhere(['is not', 'plan_id', null]) + ->andWhere(['not in', 'id', (new Query())->select('plan_id')->from('timetable_fact')]); + + + if ($action == 'applyPlus') { + + $timetables = Timetable::find() + ->andWhere(['>=', 'date', '2024-06-01']) + ->andWhere(['<', 'date', date('Y-m-d')]) + ->andWhere(['is not', 'plan_id', null]) + ->all(); + + foreach ($timetables as $timetable) { + $newFact = TimetableFactModel::find() + ->andWhere(['date_shift' => $timetable->date]) + ->andWhere(['admin_id' => $timetable->admin_id]) + ->andWhere(['store_id' => $timetable->store_id]) + ->one(); + + if ($newFact) { + var_dump($newFact);die(); + $newFact->plan_id = $timetable->id; + $newFact->tabel = $timetable->tabel; + $newFact->save(); + } else { + $adminCheckinStart = AdminCheckin::find() + ->where(['plan_id' => $timetable->id]) + ->orderBy('id asc') + ->one(); + + $adminCheckinEnd = AdminCheckin::find() + ->where(['plan_id' => $timetable->id]) + ->orderBy('id desc') + ->one(); + + if ($adminCheckinStart) { + $adminCheckinStart->shift_id = $timetable->shift_id; + var_dump($timetable->shift_id); + var_dump($adminCheckinStart->shift_id); + TimetableFactModel::setValues($adminCheckinStart); + + if ($adminCheckinEnd && $adminCheckinStart->id != $adminCheckinEnd->id) { + $adminCheckinEnd->shift_id = $timetable->shift_id; + var_dump($timetable->shift_id); + var_dump($adminCheckinStart->shift_id); + die(); + TimetableFactModel::setValues($adminCheckinEnd); + } + } + } + + if ($timetable && empty($adminCheckinStart) && empty($adminCheckinEnd)) { + $newCheckin = new AdminCheckin(); + $newCheckin->admin_id = $timetable->admin_id; + $newCheckin->type_id = $timetable->shift_id == 5 || $timetable->shift_id = 8 ? AdminCheckin::TYPE_APPEAR : AdminCheckin::TYPE_START; + $newCheckin->date = $timetable->date; + $newCheckin->shift_id = $timetable->shift_id; + $newCheckin->time = $timetable->datetime_start; + $newCheckin->store_id = $timetable->store_id; + $newCheckin->ball = 5; + $newCheckin->comment = ''; + $newCheckin->photo = 'images/avatar-empty.png'; + $newCheckin->d_id = $timetable->d_id; + $newCheckin->plan_id = $timetable->plan_id; + $newCheckin->device_id = ''; + $newCheckin->lat = ''; + $newCheckin->lon = ''; + $newCheckin->validate(); + TimetableFactModel::setValues($newCheckin); + + $newCheckin->time = $timetable->datetime_end; + $newCheckin->type_id = $timetable->shift_id == 5 || $timetable->shift_id = 8 ? AdminCheckin::TYPE_APPEAR : AdminCheckin::TYPE_END; + $newCheckin->validate(); + TimetableFactModel::setValues($newCheckin); + } + } + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 20 + ] + ]); + + return $this->render('add-old-shifts', [ + 'dataProvider' => $dataProvider, + 'action' => $action, + ]); + } } diff --git a/erp24/records/AdminCheckin.php b/erp24/records/AdminCheckin.php index 1d7b0178..4482b6a7 100755 --- a/erp24/records/AdminCheckin.php +++ b/erp24/records/AdminCheckin.php @@ -31,6 +31,7 @@ use yii_app\forms\timetable\StartForm; */ class AdminCheckin extends ActiveRecord { + public $shift_id; public $cnt; public $adminGuid; const TYPE_START = 1; diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 48d33042..85489137 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -126,21 +126,25 @@ class TimetableFactModel extends ActiveRecord $model->status = AdminCheckin::TYPE_START; $model->checkin_start_id = $adminCheckin->id; - $timetable = Timetable::findOne(['date' => $adminCheckin->date]); + $timetable = Timetable::findOne(['date' => $adminCheckin->date, 'admin_id' => $adminCheckin->admin_id]); if (!empty($timetable)) { - $model->tabel = $timetable->id; + $model->tabel = 1; $model->plan_id = $timetable->plan_id; $model->admin_id_add = $timetable->admin_id_add; $model->comment = $timetable->comment; $model->date_add = $timetable->date_add; + $model->salary_shift = $timetable->salary_shift; + $model->price_hour = $model->salary_shift / ($model->d_id == AdminGroup::GROUP_ADMINISTRATORS ? 8 : 12); } else { - $model->tabel = 1; + $model->tabel = 0; $model->plan_id = null; $model->admin_id_add = null; $model->comment = null; $model->date_add = null; + $model->salary_shift = null; + $model->price_hour = null; } $model->admin_id = $adminCheckin->admin_id; @@ -149,8 +153,6 @@ class TimetableFactModel extends ActiveRecord $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()) { diff --git a/erp24/views/timetable-fact/add-old-shifts.php b/erp24/views/timetable-fact/add-old-shifts.php new file mode 100644 index 00000000..6f306ceb --- /dev/null +++ b/erp24/views/timetable-fact/add-old-shifts.php @@ -0,0 +1,47 @@ + + + 'yii\grid\SerialColumn'], + [ + 'attribute' => 'admin_id', + 'value' => function($data) { + return $data->admin->name; +} + ], + [ + 'attribute' => 'store_id', + + 'value' => function($data) { + return $data->store->name; + } + ], + 'datetime_start:datetime', + 'datetime_end:datetime', +// 'attribute' => 'time_start:datetime', +) +?> + + +
+ + + + 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?> + + +
+         $dataProvider,
+            'columns' => $columns,
+        ]);; ?>
+        
+