$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 */
//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);
}
}
+ /**
+ * Проверка на то есть ли открытый факт
+ * @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()
{