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
{
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],
'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;
{
\Yii::debug($this->datetime_start);
\Yii::debug($this->datetime_end);
-
if (empty($this->datetime_start) && empty($this->datetime_end)) {
return;
}
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
->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']);
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();