namespace yii_app\actions\timetable;
+use app\records\TimetableFactModel;
use Yii;
use yii\base\Action;
+use yii\data\ActiveDataProvider;
use yii\web\Response;
use yii_app\records\Admin;
use yii_app\records\Timetable;
$slot->time_end = $slot->shift ? $slot->shift->end_time : null;
}
$fact = TimetableFact::find()->andWhere(['plan_id' => $slot->id])->one();
+ $dataProvider = new ActiveDataProvider(['query' => TimetableFactModel::find()->where(['admin_id' => $row['admin_id'], 'store_id' => $row['store_id'], 'date_shift' => $row['date']])]);
return $this->controller->renderPartial('/timetable/tabel_edit.php', [
'slot' => $slot,
'fact' => $fact,
+ 'dataProvider' => $dataProvider,
'success' => $success ?? false,
]);
}
namespace yii_app\actions\timetable;
+use app\records\TimetableFactModel;
use yii\base\Action;
use yii\helpers\ArrayHelper;
use yii_app\forms\timetable\TabelSearchForm;
'tabelForm' => $tabelForm,
'timetablePlan' => [],
'timetableFact' => [],
+ 'timetableFactModel' => [],
]);
}
/** @var TimetableFact[] $timetablePlan */
$timetableFact = array_filter(ArrayHelper::getColumn($timetablePlan, 'fact'));
+ $timetableFactModel = $tabelForm->search(Timetable::TABLE_FACT_NEW)->all();
+
return $this->controller->render('/timetable/plan.php', [
'tabelForm' => $tabelForm,
'timetablePlan' => $timetablePlan,
'timetableFact' => $timetableFact,
+ 'timetableFactModel' => $timetableFactModel,
]);
}
namespace yii_app\forms\timetable;
+use app\records\TimetableFactModel;
use yii\base\Model;
use yii\db\ActiveQuery;
use yii\db\Expression;
$classes = [
Timetable::TABLE_PLAN => TimetablePlan::class,
Timetable::TABLE_FACT => TimetableFact::class,
+ Timetable::TABLE_FACT_NEW => TimetableFactModel::class,
];
if (!isset($classes[$tabel])) {
throw new \Exception('Unknown type');
}
- /** @var TimetablePlan | TimetableFact $class */
+ /** @var TimetablePlan | TimetableFact | TimetableFactModel $class */
$class = $classes[$tabel];
- return $class::find()
- ->andWhere([
- 'admin_group_id' => array_keys(AdminGroup::groupsWithShift()),
- 'store_id' => array_keys(self::stores()),
- ])
- ->andFilterWhere([
- 'admin_group_id' => $this->adminGroupId,
- 'store_id' => $this->storeId,
- 'status' => $this->status,
- ])
- ->andFilterWhere(['>=', 'date', $this->start])
- ->andFilterWhere(['<=', 'date', $this->end])
- ;
+ if (in_array($tabel, [Timetable::TABLE_PLAN, Timetable::TABLE_FACT])) {
+ return $class::find()
+ ->andWhere([
+ 'admin_group_id' => array_keys(AdminGroup::groupsWithShift()),
+ 'store_id' => array_keys(self::stores()),
+ ])
+ ->andFilterWhere([
+ 'admin_group_id' => $this->adminGroupId,
+ 'store_id' => $this->storeId,
+ 'status' => $this->status,
+ ])
+ ->andFilterWhere(['>=', 'date', $this->start])
+ ->andFilterWhere(['<=', 'date', $this->end]);
+ } else {
+ return $class::find()
+ ->andWhere(['store_id' => array_keys(self::stores())])
+ ->andFilterWhere(['>=', 'date_shift', $this->start])
+ ->andFilterWhere(['<=', 'date_shift', $this->end]);
+ }
}
public function holidays()
const TABLE_PLAN = 0;
const TABLE_FACT = 1;
+ const TABLE_FACT_NEW = 2;
const TIMESLOT_WORK = 1;
const TIMESLOT_VACATION = 2;
return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']);
}
+ public function isWorkSlot() {
+ return true;
+ }
+
public static function getClosedShiftData($admin_id, $date_start, $date_end) {
$timetableFactModels = TimetableFactModel::find()->where([
'admin_id' => $admin_id,
* @var TabelSearchForm $tabelForm
* @var Timetable[] $timetablePlan
* @var Timetable[] $timetableFact
+ * @var TimetableFactModel[] $timetableFactModel
* @var array $userSummaryPlan
* @var array $userSummaryFact
*/
+use app\records\TimetableFactModel;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$getUserSummary = function (array $timetable) {
$userSummary = [];
- /** @var TimetablePlan[] $timetable */
+ /** @var TimetablePlan[] | TimetableFactModel $timetable */
foreach ($timetable as $slot) {
$userSummary[$slot->admin_id] ??= [
'time' => 0,
};
$userSummaryPlan = $getUserSummary($timetablePlan);
$userSummaryFact = $getUserSummary($timetableFact);
+$userSummaryFactModel = $getUserSummary($timetableFactModel);
$allShifts = \yii_app\records\Shift::all();
$adminGroups = AdminGroup::groupsWithShift();
$regroupedTimetablePlan = ArrayHelper::index($timetablePlan, 'date', ['admin_id']);
/** @var Timetable[][] $regroupedTimetableFact */
$regroupedTimetableFact = ArrayHelper::index($timetableFact, 'date', ['admin_id']);
+/** @var TimetableFactModel[][] $regroupedTimetableFactModel */
+$regroupedTimetableFactModel = [];
+foreach($timetableFactModel as $ttfm) {
+ $regroupedTimetableFactModel[$ttfm->admin_id][$ttfm->date_shift][] = $ttfm;
+}
$rowNumber = 0;
?>
<?php
$recordPlan = $regroupedTimetablePlan[$idu][$date->format('Y-m-d')] ?? null;
$recordFact = $regroupedTimetableFact[$idu][$date->format('Y-m-d')] ?? null;
+ $recordFactModels = $regroupedTimetableFactModel[$idu][$date->format('Y-m-d')] ?? null;
$attributes = [
'class' => ['day' . $date->format('N')],
'data-user-id' => $user->id,
<?= $slotTypeLetters[$recordPlan->slot_type_id]?? '#'; ?>
<?php if ($recordPlan->isWorkSlot()) { ?><span class="color-success">+<?= $recordPlan->work_time; ?></span>
<?php } ?>
- <?php if ($recordFact && $recordPlan->isWorkSlot()) { ?>
- <div class="hours">Ф+<?= $recordFact->work_time ?></div>
+ <?php if ($recordFactModels && $recordPlan->isWorkSlot()) { ?>
+ <?php $rfm_work_time = 0; foreach ($recordFactModels as $rfm) { $rfm_work_time += $rfm->work_time ?? 0; } ?>
+ <div class="hours" <?= count($recordFactModels) > 1 ? 'style="background: yellow"' : '' ?>>Ф+<?= $rfm_work_time ?></div>
<?php } ?>
<?php } ?>
</div>
/**
* @var \yii_app\records\Timetable $slot
* @var \yii_app\records\TimetableFact $fact
+ * @var \yii\data\ActiveDataProvider $dataProvider
* @var bool $success
*/
+use yii\grid\ActionColumn;
+use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii_app\records\AdminGroup;
use yii_app\records\Timetable;
<?php
} ?>
<?php $form::end() ?>
+
+<h3 class="m-2">Факты смены:</h3>
+
+<div class="table-responsive">
+<?= \yii\grid\GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+ [
+ 'attribute' => 'admin_id',
+ 'label' => 'Пользователь',
+ 'value' => function ($data) {
+ return $data->admin->name;
+ }
+ ],
+ [
+ 'attribute' => 'store_id',
+ 'label' => 'Магазин, Должность',
+ 'format' => 'raw',
+ 'value' => function ($data) {
+ return $data->store->name . "<br>" . $data->adminGroup->name;
+ }
+ ],
+ [
+ 'label' => 'Тип смены',
+ 'attribute' => 'shift_id',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ return $model->shift_id ? $model->shift->name : null;
+ },
+ ],
+ [
+ 'attribute' => 'work_time',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ return $model->work_time;
+ },
+ ],
+ [
+ 'label' => 'Дата смены',
+ 'attribute' => 'date_shift',
+ 'format' => ['date', 'php:d.m.Y'],
+ ],
+ [
+ 'label' => 'Начало',
+ 'attribute' => 'date_start',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ return Yii::$app->formatter->asDatetime($model->date_start, 'php:d.m.Y') . "<br>" .
+ Yii::$app->formatter->asDatetime($model->time_start, 'php:H:i:s');
+ },
+ ],
+ [
+ 'label' => 'Конец',
+ 'attribute' => 'date_end',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ return !empty($model->date_end) ? Yii::$app->formatter->asDatetime($model->date_end, 'php:d.m.Y') . "<br>" .
+ Yii::$app->formatter->asDatetime($model->time_end, 'php:H:i:s') : 'Работает';
+ },
+ ],
+ [
+ 'label' => 'Отметка о начале',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ if (!empty($model->checkin_start_id)) {
+ return !empty($photo = $model->checkinStart->photo) ? Html::img("/$photo", ['alt' => 'selfie', 'style' => 'min-width: 200px']) : null;
+ };
+ return '';
+ },
+ ],
+ [
+ 'label' => 'Отметка о конце',
+ 'format' => 'raw',
+ 'value' => function ($model) {
+ if (!empty($model->checkin_end_id)) {
+ return !empty($photo = $model->checkinEnd->photo) ? Html::img("/$photo", ['alt' => 'selfie', 'style' => 'min-width: 200px']) : null;
+ };
+ return '';
+ },
+ ],
+ ],
+]); ?>
+</div>
\ No newline at end of file