From 6e823152a41319c0c0123b0fb29036719b94d09a Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Sep 2024 14:12:47 +0300 Subject: [PATCH] =?utf8?q?ERP-175=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=B8=D1=82=D1=8C=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?utf8?q?=D0=B2=D0=BE=D1=80=D0=BA-=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/timetable/PlanController.php | 16 ++-- .../modules/v1/models/timetable/Timetable.php | 24 ++---- erp24/records/TimetableFactModel.php | 74 +++++++++++++++++-- 3 files changed, 81 insertions(+), 33 deletions(-) diff --git a/erp24/api3/modules/v1/controllers/timetable/PlanController.php b/erp24/api3/modules/v1/controllers/timetable/PlanController.php index 9501da65..51e920a4 100644 --- a/erp24/api3/modules/v1/controllers/timetable/PlanController.php +++ b/erp24/api3/modules/v1/controllers/timetable/PlanController.php @@ -5,9 +5,12 @@ namespace yii_app\api3\modules\v1\controllers\timetable; use Yii; use yii\base\DynamicModel; use yii\db\Expression; +use yii\helpers\Json; use yii_app\api3\core\exceptions\ErrorException; use yii_app\api3\core\services\TimetableService; use yii_app\api3\core\traits\ServiceTrait; +use yii_app\api3\modules\v1\models\timetable\Timetable; +use yii_app\records\TimetableFactModel; /** * @property TimetableService $timetableService @@ -16,13 +19,14 @@ class PlanController extends \yii_app\api3\controllers\ActiveController { use ServiceTrait; - public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class; +// public $modelClass = \yii_app\api3\modules\v1\models\timetable\Timetable::class; + public $modelClass = TimetableFactModel::class; + public function actions() { $actions = parent::actions(); - // $actions['index']['sort'] = ['defaultOrder' => ['date' => SORT_ASC]]; $actions['index']['pagination'] = [ 'defaultPageSize' => 50, 'pageSizeLimit' => [1, 50], @@ -33,14 +37,6 @@ class PlanController extends \yii_app\api3\controllers\ActiveController 'searchModel' => $this->modelClass ]; - /*$actions['index']['prepareSearchQuery'] = function($query, $requestParams) { - if(isset($requestParams['filter']['checks'])) { - $query = $query->select(new Expression('*, (SELECT COUNT(*) FROM admin_checkin WHERE plan_id = {{timetable}}.plan_id) checks')); - } - - return $query; - };*/ - unset($actions['delete']); return $actions; diff --git a/erp24/api3/modules/v1/models/timetable/Timetable.php b/erp24/api3/modules/v1/models/timetable/Timetable.php index 240e0491..e380916d 100644 --- a/erp24/api3/modules/v1/models/timetable/Timetable.php +++ b/erp24/api3/modules/v1/models/timetable/Timetable.php @@ -43,7 +43,6 @@ class Timetable extends \yii_app\records\TimetableV3 { \Yii::debug($this->datetime_start); \Yii::debug($this->datetime_end); - if (empty($this->datetime_start) && empty($this->datetime_end)) { return; } @@ -186,27 +185,16 @@ class Timetable extends \yii_app\records\TimetableV3 public function getCheckIns() { - if (!empty($this->plan_id)) { - return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']); - } else { - 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')]); + 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'))]); -// return $this->hasOne(AdminCheckin::class, ['admin_id' => 'id']) -// ->andWhere(['>=', 'date', date('Y-m-d 00:00:00')]) -// ->andWhere(['<=', 'date', date('Y-m-d 23:59:59')]); - } } public function getCheckInCount() { - if (!empty($this->plan_id)) { - return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count(); - } else { - 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(); - } + 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(); + } } \ No newline at end of file diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 0b5a646d..fb95f1d5 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -191,6 +191,68 @@ 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_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']) + ->andWhere(['BETWEEN', 'time', + date('Y-m-d H:i:s', strtotime($this->date_start . ' ' . $this->time_start)), + date('Y-m-d H:i:s', strtotime($this->date_end . ' ' . $this->time_end))]); + } + + public function getCheckInCount() + { + return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id']) + ->andWhere(['BETWEEN', 'time', + date('Y-m-d H:i:s', strtotime($this->date_start . ' ' . $this->time_start)), + date('Y-m-d H:i:s', strtotime($this->date_end . ' ' . $this->time_end))]) + ->count(); + } + public function getAdmin() { return $this->hasOne(Admin::class, ['id' => 'admin_id']); @@ -236,15 +298,17 @@ class TimetableFactModel extends ActiveRecord return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']); } - public function isWorkSlot() { + public function isWorkSlot() + { return true; } - public static function getClosedShiftData($admin_id, $date_start, $date_end) { + public static function getClosedShiftData($admin_id, $date_start, $date_end) + { $timetableFactModels = TimetableFactModel::find()->where([ - 'admin_id' => $admin_id, - 'status' => AdminCheckin::TYPE_END, - ]) + 'admin_id' => $admin_id, + 'status' => AdminCheckin::TYPE_END, + ]) ->andWhere(['>=', 'date_start', date('Y-m-d', strtotime($date_start))]) ->andWhere(['<=', 'date_end', date('Y-m-d', strtotime($date_end))]) ->all(); -- 2.39.5