From: Marina Zozirova Date: Wed, 18 Sep 2024 09:34:26 +0000 (+0000) Subject: Bug zozirova erp 175 fixes for tg bot X-Git-Tag: 1.5~19^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=a137737b6a2cd58283c3b4f1cad2c7922768fd0f;p=erp24_rep%2Fyii-erp24%2F.git Bug zozirova erp 175 fixes for tg bot --- diff --git a/erp24/api3/core/services/TimetableService.php b/erp24/api3/core/services/TimetableService.php index 59e859f3..a4a04520 100644 --- a/erp24/api3/core/services/TimetableService.php +++ b/erp24/api3/core/services/TimetableService.php @@ -131,37 +131,17 @@ class TimetableService { /** @var $data Fact */ - if ($data->plan_id) { - $timetable = Timetable::findOne(['plan_id' => $data->plan_id, 'tabel' => 1]); - if (!$timetable) { - throw new NotFoundHttpException("Факт не найден"); - } - } + $fact = TimetableFactModel::getLast($data->admin_id, date('Y-m-d')); $currentDate = date('Y-m-d H:i:s'); - $admin_id = $data->plan_id ? $timetable->admin_id : $data->admin_id; + $admin_id = $data->admin_id; - //убрать после согласования оплаты подработчиков - if (Admin::findOne($admin_id)->group_id === AdminGroup::GROUP_WORKERS && !$data->plan_id) { - throw new \InvalidArgumentException('Подработчики не могут открыть смены без плана!'); - } - - $checkInFirst = $data->plan_id ? - AdminCheckin::find()->where(['plan_id' => $timetable->plan_id])->orderBy(['time' => SORT_ASC])->one() : - AdminCheckin::find()->where(['admin_id' => $admin_id])->orderBy(['id' => SORT_DESC])->one(); + $checkInFirst = AdminCheckin::findOne($fact->checkin_start_id); if ($checkInFirst && (strtotime($checkInFirst->time) + 60 * 60 > strtotime($currentDate))) { throw new InvalidArgumentException("Между началом и концом смены должно пройти минимум один час"); } - if ($data->plan_id) { - $timetable->datetime_end = $currentDate; - $timetable->save(); - if ($timetable->getErrors()) { - throw new \Exception(Json::encode($timetable->getErrors())); - } - } - $imagePath = $data->uploadImage($admin_id); if (!$imagePath) { throw new InvalidArgumentException("Не удалось загрузить картинку"); @@ -169,28 +149,10 @@ class TimetableService $checkIn = new AdminCheckin(); - if ($data->plan_id) { - $checkIn->plan_id = $timetable->plan_id; - $checkIn->store_id = $timetable->store_id; - $checkIn->d_id = $timetable->admin->group_id; - $checkIn->date = $timetable->date; - } else { - - //остается буквально на день чтобы не посыпались ошибки из-за открытых смен до выката функционала - $plan = Timetable::find() - ->andWhere(['admin_id' => $admin_id]) - ->andWhere(['between', 'date', date('Y-m-d', strtotime('-1 day')), date('Y-m-d')]) - ->andWhere(['tabel' => 1]) - ->orderBy('id desc') - ->one(); - $checkIn->shift_id = !empty($plan) ? $plan->shift_id : null; - - $checkIn->plan_id = null; - $checkIn->store_id = $checkInFirst->store_id; - $checkIn->d_id = $checkInFirst->d_id; - $checkIn->date = $checkInFirst->date; - } - + $checkIn->plan_id = $fact->plan_id; + $checkIn->store_id = $fact->store_id; + $checkIn->d_id = $fact->admin->group_id; + $checkIn->date = $fact->date_shift; $checkIn->ball = 5; $checkIn->comment = ""; $checkIn->admin_id = $admin_id; diff --git a/erp24/api3/modules/v1/controllers/timetable/FactController.php b/erp24/api3/modules/v1/controllers/timetable/FactController.php index 6585682a..93de0f5a 100644 --- a/erp24/api3/modules/v1/controllers/timetable/FactController.php +++ b/erp24/api3/modules/v1/controllers/timetable/FactController.php @@ -7,6 +7,7 @@ use yii_app\api3\controllers\ActiveController; use yii_app\api3\core\services\TimetableService; use yii_app\api3\core\traits\ServiceTrait; use yii_app\api3\modules\v1\requests\timetable\Fact; +use yii_app\records\TimetableFactModel; /** * @property TimetableService $timetableService @@ -15,7 +16,7 @@ class FactController extends ActiveController { use ServiceTrait; - public $modelClass = \yii_app\api3\modules\v1\requests\timetable\Fact::class; + public $modelClass = TimetableFactModel::class; public function actions() { diff --git a/erp24/api3/modules/v1/controllers/timetable/PlanController.php b/erp24/api3/modules/v1/controllers/timetable/PlanController.php index 617d8c31..4508a23d 100644 --- a/erp24/api3/modules/v1/controllers/timetable/PlanController.php +++ b/erp24/api3/modules/v1/controllers/timetable/PlanController.php @@ -19,8 +19,8 @@ class PlanController extends \yii_app\api3\controllers\ActiveController { use ServiceTrait; - public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class; -// public $modelClass = TimetableFactModel::class; + + public $modelClass = Timetable::class; public function actions() @@ -34,7 +34,7 @@ class PlanController extends \yii_app\api3\controllers\ActiveController $actions['index']['dataFilter'] = [ 'class' => \yii\data\ActiveDataFilter::class, - 'searchModel' => $this->modelClass + 'searchModel' => $this->modelClass, ]; unset($actions['delete']); diff --git a/erp24/api3/modules/v1/models/timetable/Timetable.php b/erp24/api3/modules/v1/models/timetable/Timetable.php index e380916d..c9681b24 100644 --- a/erp24/api3/modules/v1/models/timetable/Timetable.php +++ b/erp24/api3/modules/v1/models/timetable/Timetable.php @@ -182,19 +182,11 @@ class Timetable extends \yii_app\records\TimetableV3 { return $this->hasOne(CityStore::class, ['id' => 'store_id']); } - - public function getCheckIns() - { - return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id']) - ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s', strtotime('+6 hour'))]); - + public function getCheckIns() { + return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']); } - public function getCheckInCount() - { - return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id']) - ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))]) - ->andWhere(['BETWEEN', 'time', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')])->count(); - + public function getCheckInCount() { + return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count(); } } \ No newline at end of file diff --git a/erp24/records/AdminCheckin.php b/erp24/records/AdminCheckin.php index 91f32ea7..329b2e83 100755 --- a/erp24/records/AdminCheckin.php +++ b/erp24/records/AdminCheckin.php @@ -87,9 +87,9 @@ class AdminCheckin extends ActiveRecord public function rules() { return [ - [['admin_id', 'device_id', 'replaced_admin_id', 'plan_id', 'store_id', 'type_id', 'd_id', 'ball', 'status'], 'integer'], + [['admin_id', 'device_id', 'replaced_admin_id', 'store_id', 'type_id', 'd_id', 'ball', 'status'], 'integer'], [['lat', 'lon'], 'double'], - [['shift_id'], 'safe'], + [['shift_id', 'plan_id'], 'safe'], [['comment', 'photo'], 'string'], [['date'], 'date', 'format' => 'yyyy-M-d'], // [['time'], 'date', 'format' => 'yyyy-M-d HH:mm:ss'], diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 0fc5a007..6c0c56bd 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -191,6 +191,51 @@ class TimetableFactModel extends ActiveRecord ->one(); } + public function fields() + { + $fields = [ + 'id', + 'admin_id', + 'store_id', + 'shift_id', + 'salary_shift', + // 'price' => fn($x) => $x->shift_id == 2 ? 140 : 125, + 'tabel', + 'date' => fn($x) => $x->date_shift, + 'date_start' => fn($x) => $x->date_start . ' ' .$x->time_start, + 'date_end' => fn($x) => !empty($x->date_end) ? $x->date_end . ' ' .$x->time_end : null, + 'time_start', + 'time_end', + 'work_time', + 'status', + 'checkInCount', + 'can_open' => fn($x) => $this->is_opening === false && $this->is_close === true, + ]; + + return $fields; + } + + public function extraFields() + { + return [ + 'admin' => fn($x) => [ + 'id' => $x->admin->id, + 'name' => $x->admin->name, + 'guid' => $x->admin->guid, + 'group' => [ + 'id' => $x->admin->group_id, + 'name' => $x->admin->group_name, + ], + ], + 'store' => fn($x) => [ + 'id' => $x->store->id, + 'name' => $x->store->name, + 'name_full' => $x->store->name_full, + ], + 'checkIns' + ]; + } + public function getCheckIns() { return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])