123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- require 'tmc/yiiInit.php';
- use app\models\entity\Accounts;
- use app\models\entity\Jobtypes;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\Tasks;
- use app\models\entity\Tasktypes;
- const DATE_FORMAT = 'Y-m-d H:i:s';
- try {
- $date = new DateTime($_GET['date']);
- } catch (Exception $e) {
- $date = new DateTime();
- }
- $shift = (int)$_GET['shift'];
- $company = (int)$_GET['company'];
- $positionIds = (array)$_GET['positions'];
- $positions = [];
- foreach ($positionIds as $positionId) {
- $positions[] = Jobtypes::findOne($positionId)->name;
- }
- $twelveHour = new DateInterval('PT12H');
- $threeHour = new DateInterval('PT3H');
- $date->add($threeHour);
- if ($shift) {
- $date->add($twelveHour);
- }
- $startShift = clone $date;
- $date->add($twelveHour);
- $endShift = clone $date;
- $endShift->add($oneHour);
- $projects = ProjectsLocotech::find()
- ->where(['company' => $company])
- ->andWhere(['between', 'created', $startShift->format(DATE_FORMAT), $endShift->format(DATE_FORMAT)])
- ->all()
- ;
- $tasksByLocoId = [];
- $lettersByLocoId = [];
- $counts = [];
- $statuses = [];
- foreach ($projects as $project) {
- $locoId = $project->loco_type . '-' . $project->loco_number;
-
- $tasks = Tasks::find()
- ->where(['input_id' => $project->id])
-
- ->andWhere(['not', ['assignees_arr' => null]])
-
- ->andWhere(['between', 'created', $startShift->format(DATE_FORMAT), $endShift->format(DATE_FORMAT)])
- ->all()
- ;
-
- foreach ($tasks as $key => $task) {
-
- if ($user = $task->getAccounts()->one()) {
- $positionFound = false;
- foreach ($user->getPositionIds() as $positionId) {
- if (in_array($positionId, $positionIds)) $positionFound = true;
- }
- }
- if ($positionFound) {
- $taskType = Tasktypes::findOne($task->type);
- $letter = $taskType->letter ? $taskType->letter : '?';
- $tasksByLocoId[$locoId][$user->name][$letter][] = $task;
-
- if (!in_array($letter, $lettersByLocoId[$locoId])) {
- $lettersByLocoId[$locoId][] = $letter;
- }
- if (isset($counts[$locoId][$user->name][$letter])) {
- $counts[$locoId][$user->name][$letter]++;
- } else {
- $counts[$locoId][$user->name][$letter] = 1;
- }
- $statuses[$locoId][$user->name][$letter][] = $task->status;
- }
- }
- }
- $dataForTable = [];
- foreach ($tasksByLocoId as $locoId => $tasksByUser) {
- foreach ($tasksByUser as $userName => $tasksByLetter) {
- foreach ($lettersByLocoId[$locoId] as $letter) {
- if (isset($tasksByLocoId[$locoId][$userName][$letter])) {
-
- $taskCount = $counts[$locoId][$userName][$letter];
- $taskFinishedCount = 0;
- foreach ($tasksByLocoId[$locoId][$userName][$letter] as $task) {
- if ($task->status == 5) $taskFinishedCount++;
- }
-
- $dataForTable[$locoId][$userName][$letter] = round($taskFinishedCount / $taskCount * 100) . '%';
- } else {
- $dataForTable[$locoId][$userName][$letter] = '0%';
- }
- }
- }
- }
- ?>
- <div class="for-print">
- <h3>Дата: <?= $date->format('d.m.Y') ?>. Смена: <?= $shift ? 'ночная' : 'дневная' ?></h3>
- <h4>Должности: <?= implode(', ', $positions)?></h4>
- <?php foreach ($lettersByLocoId as $locoId => $letters):
- sort($letters);
- //Не выводим пустые таблицы
- if (!isset($dataForTable[$locoId])) continue;
- list($locoSeries, $locoNumber) = explode('-', $locoId)
- ?>
- <table class="table text-center" border="2">
- <thead>
- <tr>
- <td colspan="<?= count($letters) + 1?>">
- <h3>Локомотив серии <?= $locoSeries ?> с номером <?= $locoNumber ?></h3>
- </td>
- </tr>
- </thead>
- <tr>
- <th>Сотрудник</th>
- <?php foreach ($letters as $letter): ?>
- <th><?= $letter ?></th>
- <?php endforeach; ?>
- </tr>
- <?php ksort($dataForTable[$locoId]); ?>
- <?php foreach ($dataForTable[$locoId] as $userName => $statistics): ?>
- <tr>
- <td><?= $userName ?></td>
- <?foreach ($letters as $letter): ?>
- <td><?= $statistics[$letter] ?></td>
- <?php endforeach; ?>
- </tr>
- <?php endforeach; ?>
- </table>
- <?php endforeach; ?>
- </div>
- <style type="text/css">
- :root {
- --border-style: 2px solid
- }
-
- margin-top: 60px;
- }
- .table td {
- padding: 0;
- border: var(--border-style);
- }
- .table th {
- border: var(--border-style);
- }
- h3, h4 {
- text-align: center;
- }
- </style>
|