use yii_app\records\AdminDesktop;
use yii_app\records\CityStore;
use yii_app\records\Shift;
+use yii_app\records\Timetable;
class StartShiftStepOneAction extends Action
{
if ($modelTypeId == AdminCheckin::TYPE_END) {
$adminStores = CityStore::getNames([$lastCheckin->store_id]);
$lastCheckinFact = TimetableFactModel::findOne(['checkin_start_id' => $lastCheckin->id]);
- $shiftArray = $lastCheckinFact ? ['id' => $lastCheckinFact->shift_id, 'name' => $lastCheckinFact->shift->name] : [];
+ if(!empty($lastCheckinFact)) {
+ $shiftArray = array('id' => $lastCheckinFact->shift_id, 'name' => $lastCheckinFact->shift->name);
+ } else {
+ $plan = Timetable::find()
+ ->andWhere(['store_id' => $lastCheckin->store_id])
+ ->andWhere(['date' => $lastCheckin->date])
+ ->one();
+ $shiftArray = array('id' => $plan->shift->id, 'name' => $plan->shift->name);
+ }
} else {
$adminStores = ArrayHelper::map($userModel->getStores(), 'id', 'name');
$shiftArray = ArrayHelper::map(Shift::find()->andWhere(['not in', 'id', [3, 4, 6, 7]])->all(), 'id', 'name');