123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- use app\models\entity\Accounts;
- use app\models\entity\Log;
- use app\models\entity\Stack;
- use app\models\entity\Storage;
- use app\models\entity\Tmc;
- use app\models\entity\TmcStatus;
- use app\models\entity\Warehouse;
- use yii\db\Query;
- /** Created by Anton on 14.02.2020. */
- function addTmc(array $devices, $tmc)
- {
- if (!isset($devices['total'])) {//Инициализация переменных в массиве
- $devices['total'] = 0;
- $devices['issued'] = 0;
- $devices['inCharge'] = 0;
- }
- $devices['total']++;
- switch ($tmc['status']) {
- case 1:
- $devices['issued']++;
- break;
- case 2: case 6:
- $devices['inCharge']++;
- break;
- }
- $devices['list'][] = $tmc;
- return $devices;
- }
- function getColorByStatus(int $status)
- {
- $color = 'loco_';
- switch ($status) {
- case 1:
- $color .= 'red';
- break;
- case 3:
- $color .= 'blue';
- break;
- default:
- $color .= 'grey';
- break;
- }
- return $color;
- }
- function getTmcs()
- {
- $query = new Query();
- $query->select('t.id, t.title, t.tmc_type, t.status, t.employee, ta.name, ts.title as storage')
- ->from(Tmc::tableName() . ' t')
- ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = t.employee')
- ->leftJoin(Storage::tableName() . ' ts', 'ts.id = t.storage')
- ;
- return $query->all();
- }
- function getTmcsByStatus(int $status)
- {
- $query = new Query();
- $query->select('t.id, t.title, t.tmc_type, t.status, t.employee, ta.name, ts.title as storage')
- ->from(Tmc::tableName() . ' t')
- ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = t.employee')
- ->leftJoin(Storage::tableName() . ' ts', 'ts.id = t.storage')
- ->where(['t.status' => $status])
- ;
- return $query->all();
- }
- function sortTmc($tmcs)
- {
- $cameras = [];
- $phones = [];
- $oilMeters = [];
- foreach ($tmcs as $tmc) {
- switch ($tmc['tmc_type']) {
- case 1:
- $cameras = addTmc($cameras, $tmc);
- break;
- case 2:
- $oilMeters = addTmc($oilMeters, $tmc);
- break;
- case 3:
- $phones = addTmc($phones, $tmc);
- break;
- }
- }
- return [$cameras, $phones, $oilMeters];
- }
- function getDataStorages()
- {
- $query = new Query();
- $query->select('ts.title as storage, ts.warehouse, tw.title as w_title, ts.stack, tstack.title as s_title,
- ts.tmc, t.title as name, tstat.title as status, tstat.id as id_status, td.issue_date, ta.name AS user')
- ->from(Storage::tableName() . ' ts')
- ->leftJoin(Tmc::tableName() . ' t', 'ts.tmc = t.id')
- ->leftJoin(Log::tableName() . ' td', 'td.tmc = ts.tmc')
- ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = td.employee')
- ->leftJoin(TmcStatus::tableName() . ' tstat', 't.status = tstat.id')
- ->leftJoin(Warehouse::tableName() . ' tw', 'tw.id = ts.warehouse')
- ->leftJoin(Stack::tableName() . ' tstack', 'tstack.id = ts.stack')
- ->groupBy('ts.id')//todo: надо ли?
- ;
- return $query->all();
- }
- function getDevicesFromRows(array $rows)
- {
- /*
- * [warehouseId => [
- * 'title' => string,
- * 'stacks' => [
- * stackId => [
- * 'title' => string,
- * 'tmcs' => [
- * key => value,
- * ...
- * ]
- * ],
- * ...
- * ],
- * ...
- * ]
- * */
- $devices = [];
- foreach ($rows as $row) {
- $devices[$row['warehouse']]['title'] = $row['w_title'];
- $devices[$row['warehouse']]['stacks'][$row['s_title']]['title'] = $row['s_title'];
- $devices[$row['warehouse']]['stacks'][$row['s_title']]['tmcs'][] = $row;
- }
- return $devices;
- }
- function sortDevicesAlph(array $devices)
- {
- //Сортируем в алфавитном порядке по title стеллажа
- foreach ($devices as $key => $device) {
- ksort($device['stacks']);
- $devices[$key] = $device;
- }
- return $devices;
- }
|