From: marina Date: Wed, 17 Jul 2024 08:27:48 +0000 (+0300) Subject: Правка того что не у всех нормально открывались смены X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=refs%2Fheads%2Ffix_shift_opening;p=erp24_rep%2Fyii-erp24%2F.git Правка того что не у всех нормально открывались смены --- diff --git a/erp24/commands/TimetableController.php b/erp24/commands/TimetableController.php index ed2f7fb6..e3ce4e3b 100644 --- a/erp24/commands/TimetableController.php +++ b/erp24/commands/TimetableController.php @@ -14,7 +14,8 @@ class TimetableController extends Controller $timetableFactModels = TimetableFactModel::find() ->with(['checkinStart']) ->andWhere(['!=', 'is_close', true]) - ->andWhere(['<=', new Expression('CONCAT(date_start, \' \', time_start)'), date('Y-m-d H:i:s', strtotime('-14 hours', time()))])->all(); + ->andWhere(['<=', new Expression('CONCAT(date_start, \' \', time_start)'), date('Y-m-d H:i:s', strtotime('-14 hours', time()))]) + ->all(); foreach ($timetableFactModels as $timetableFactModel) { /** @var $timetableFactModel TimetableFactModel */ diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php index 734563ad..5183cd10 100644 --- a/erp24/records/TimetableFactModel.php +++ b/erp24/records/TimetableFactModel.php @@ -105,16 +105,17 @@ class TimetableFactModel extends ActiveRecord //is_start моя пометка для выравнивания открытия/закрытия натыканных флористами смен /** + * @param $adminCheckin + * @param $is_start + * @return void * @throws \Exception */ public static function setValues($adminCheckin, $is_start = true) { - if ($model = self::find() - ->where(['admin_id' => $adminCheckin->admin_id, 'is_opening' => true]) - ->andWhere(['between', 'date_shift', date('Y-m-d', strtotime($adminCheckin->date . ' -1 day')), date('Y-m-d', strtotime($adminCheckin->date))]) - ->andWhere(['status' => array(AdminCheckin::TYPE_START, AdminCheckin::TYPE_APPEAR)]) - ->one()) { + $model = self::getOpening($adminCheckin->admin_id, $adminCheckin->date); + /** @var $model TimetableFactModel */ + if ($model) { $model->date_end = date("Y-m-d", strtotime($adminCheckin->time)); $model->time_end = date("H:i:s", strtotime($adminCheckin->time)); $model->work_time = min(abs(strtotime($model->date_end . $model->time_end) + 600 - strtotime($model->date_start . $model->time_start)) / 3600, self::WORK_HOURS_TIME); @@ -168,6 +169,20 @@ class TimetableFactModel extends ActiveRecord } } + /** + * Проверка на то есть ли открытый факт + * @param int $adminId + * @param $date + * @return array|ActiveRecord|null + */ + public static function getOpening(int $adminId, $date) { + return self::find() + ->where(['admin_id' => $adminId, 'is_opening' => true]) + ->andWhere(['date_shift' => $date]) +// ->andWhere(['status' => array(AdminCheckin::TYPE_START, AdminCheckin::TYPE_APPEAR)]) + ->orderBy('id desc') + ->one(); + } public function getAdmin() {