Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
79.82% |
87 / 109 |
|
61.54% |
8 / 13 |
CRAP | |
0.00% |
0 / 1 |
ProcessStatusArchived | |
79.82% |
87 / 109 |
|
61.54% |
8 / 13 |
32.99 | |
0.00% |
0 / 1 |
getEntityMapping | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
1 | |||
addConditionArchiveId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionScopeId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionScopeIds | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
addConditionTime | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionTimes | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
addConditionIsMissed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionWithAppointment | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addJoinStatisticFailed | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
addValuesNewArchive | |
76.92% |
20 / 26 |
|
0.00% |
0 / 1 |
10.00 | |||
postProcess | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
getArchivedServices | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
3.33 | |||
addConditionOlderThanDate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb\Query; |
4 | |
5 | /** |
6 | * |
7 | * @SuppressWarnings(TooManyPublicMethods) |
8 | * @SuppressWarnings(Complexity) |
9 | */ |
10 | class ProcessStatusArchived extends Base implements MappingInterface |
11 | { |
12 | /** |
13 | * |
14 | * @var String TABLE mysql table reference |
15 | */ |
16 | const TABLE = 'buergerarchiv'; |
17 | const STATISTIC_TABLE = 'statistik'; |
18 | const ALIAS = 'process'; |
19 | |
20 | const QUERY_INSERT_IN_STATISTIC = ' |
21 | INSERT INTO ' . self::STATISTIC_TABLE . ' SET |
22 | lastbuergerarchivid = :archiveId, |
23 | termin = :withAppointment, |
24 | datum = :date, |
25 | anliegenid = :requestId, |
26 | info_dl_id = :providerId, |
27 | standortid = :scopeId, |
28 | clusterid = :clusterId, |
29 | behoerdenid = :departmentId, |
30 | organisationsid = :organisationId, |
31 | kundenid = :ownerId, |
32 | bearbeitungszeit = :processingTime |
33 | '; |
34 | |
35 | public function getEntityMapping() |
36 | { |
37 | return [ |
38 | 'archiveId' => 'process.BuergerarchivID', |
39 | 'status' => self::expression('"archived"'), |
40 | 'appointments__0__date' => self::expression( |
41 | 'CONCAT(`process`.`Datum`, " ", `process`.`Timestamp`)' |
42 | ), |
43 | 'scope__id' => 'process.StandortID', |
44 | '__clientsCount' => 'process.AnzahlPersonen', |
45 | 'waitingTime' => 'process.wartezeit', |
46 | 'wayTime' => 'process.wegezeit', |
47 | 'processingTime' => 'process.bearbeitungszeit', |
48 | 'name' => 'process.name', |
49 | 'services' => 'process.dienstleistungen', |
50 | 'queue__arrivalTime' => self::expression( |
51 | 'CONCAT(`process`.`Datum`, " 00:00:00")' |
52 | ), |
53 | 'queue__callTime' => self::expression( |
54 | 'CONCAT(`process`.`Datum`, " ", SEC_TO_TIME(`wartezeit`))' |
55 | ), |
56 | 'queue__withAppointment' => 'process.mitTermin', |
57 | 'withAppointment' => 'process.mitTermin', |
58 | 'queue__status' => self::expression( |
59 | 'IF(`process`.`nicht_erschienen`, |
60 | "missed", |
61 | "finished" |
62 | )' |
63 | ), |
64 | ]; |
65 | } |
66 | |
67 | public function addConditionArchiveId($archiveId) |
68 | { |
69 | $this->query->where('process.BuergerarchivID', '=', $archiveId); |
70 | return $this; |
71 | } |
72 | |
73 | public function addConditionScopeId($scopeId) |
74 | { |
75 | $this->query->where('process.StandortID', '=', $scopeId); |
76 | return $this; |
77 | } |
78 | |
79 | public function addConditionScopeIds($scopeIds) |
80 | { |
81 | $this->query->where(function (\Solution10\SQL\ConditionBuilder $condition) use ($scopeIds) { |
82 | foreach ($scopeIds as $scopeId) { |
83 | $condition |
84 | ->orWith('process.StandortID', '=', $scopeId); |
85 | } |
86 | }); |
87 | return $this; |
88 | } |
89 | |
90 | |
91 | public function addConditionTime(\DateTimeInterface $now) |
92 | { |
93 | $this->query->where('process.Datum', '=', $now->format('Y-m-d')); |
94 | return $this; |
95 | } |
96 | |
97 | public function addConditionTimes(array $dateTimes) |
98 | { |
99 | $this->query->where(function (\Solution10\SQL\ConditionBuilder $condition) use ($dateTimes) { |
100 | foreach ($dateTimes as $dateTime) { |
101 | $condition |
102 | ->orWith('process.Datum', '=', $dateTime->format('Y-m-d')); |
103 | } |
104 | }); |
105 | return $this; |
106 | } |
107 | |
108 | public function addConditionIsMissed($missed) |
109 | { |
110 | $this->query->where('process.nicht_erschienen', '=', $missed); |
111 | return $this; |
112 | } |
113 | |
114 | public function addConditionWithAppointment($withAppointment) |
115 | { |
116 | $this->query->where('process.mitTermin', '=', $withAppointment); |
117 | return $this; |
118 | } |
119 | |
120 | public function addJoinStatisticFailed($dateTime, \BO\Zmsentities\Scope $scope) |
121 | { |
122 | //use existing index with StandortID and Datum |
123 | $this->leftJoin( |
124 | new Alias(self::STATISTIC_TABLE, 'statistic'), |
125 | self::expression(' |
126 | statistic.StandortID = process.StandortID |
127 | AND statistic.Datum = process.Datum |
128 | AND `statistic`.`lastbuergerarchivid` = `process`.`BuergerarchivID` |
129 | ') |
130 | ); |
131 | $this->query->where(function (\Solution10\SQL\ConditionBuilder $query) use ($dateTime, $scope) { |
132 | $query->andWith( |
133 | self::expression('statistic.lastbuergerarchivid IS NULL AND process.Datum'), |
134 | '>', |
135 | $dateTime->format('Y-m-d') |
136 | ); |
137 | $query->andWith('process.nicht_erschienen', '=', 0); |
138 | $query->andWith('process.StandortID', '=', $scope->id); |
139 | }); |
140 | return $this; |
141 | } |
142 | public function addValuesNewArchive(\BO\Zmsentities\Process $process, \DateTimeInterface $now) |
143 | { |
144 | $processingTimeStr = $process->getProcessingTime(); |
145 | $bearbeitungszeit = null; |
146 | |
147 | if (!empty($processingTimeStr)) { |
148 | list($hours, $minutes, $seconds) = explode(':', $processingTimeStr); |
149 | $totalMinutes = (double) ($hours * 60 + $minutes + $seconds / 60); |
150 | $bearbeitungszeit = $totalMinutes; |
151 | } |
152 | |
153 | $waitingTimeStr = $process->getWaitingTime(); |
154 | $warteZeit = null; |
155 | |
156 | if (!empty($waitingTimeStr)) { |
157 | list($hours, $minutes, $seconds) = explode(':', $waitingTimeStr); |
158 | $totalMinutes = (double) ($hours * 60 + $minutes + $seconds / 60); |
159 | $warteZeit = $totalMinutes; |
160 | } |
161 | |
162 | $this->addValues([ |
163 | 'StandortID' => $process->scope['id'], |
164 | 'name' => $process->getFirstClient()['familyName'], |
165 | 'dienstleistungen' => $this->getArchivedServices($process), |
166 | 'Datum' => $process->getFirstAppointment()->toDateTime()->format('Y-m-d'), |
167 | 'mitTermin' => ($process->toQueue($now)->withAppointment) ? 1 : 0, |
168 | 'nicht_erschienen' => ('missed' == $process->queue['status']) ? 1 : 0, |
169 | 'Timestamp' => $process->getArrivalTime()->format('H:i:s'), |
170 | 'wartezeit' => ($process->getWaitedSeconds() > 0) ? $process->getWaitedMinutes() : 0, |
171 | 'wegezeit' => ($process->getWaySeconds() > 0) ? $process->getWayMinutes() : 0, |
172 | 'bearbeitungszeit' => ($bearbeitungszeit > 0) ? $bearbeitungszeit : 0, |
173 | 'wartezeit' => ($warteZeit > 0) ? $warteZeit : 0, |
174 | 'AnzahlPersonen' => $process->getClients()->count() |
175 | ]); |
176 | } |
177 | |
178 | public function postProcess($data) |
179 | { |
180 | $data[$this->getPrefixed("appointments__0__date")] = |
181 | strtotime($data[$this->getPrefixed("appointments__0__date")]); |
182 | $data[$this->getPrefixed("queue__callTime")] = |
183 | strtotime($data[$this->getPrefixed("queue__callTime")]); |
184 | $data[$this->getPrefixed("queue__arrivalTime")] = |
185 | strtotime($data[$this->getPrefixed("queue__arrivalTime")]); |
186 | if (isset($data[$this->getPrefixed('__clientsCount')])) { |
187 | $clientsCount = $data[$this->getPrefixed('__clientsCount')]; |
188 | unset($data[$this->getPrefixed('__clientsCount')]); |
189 | while ($clientsCount-- > 0) { |
190 | $data[$this->getPrefixed('clients__' . $clientsCount . '__familyName')] = 'Unknown'; |
191 | } |
192 | } |
193 | return $data; |
194 | } |
195 | |
196 | private function getArchivedServices(\BO\Zmsentities\Process $process) |
197 | { |
198 | if ($process->getRequests()->count() === 0) { |
199 | return ''; |
200 | } |
201 | |
202 | $services = $process->getRequests()->getFirst()->name; |
203 | |
204 | if ($process->getRequests()->count() > 1) { |
205 | $services .= ' +' . ($process->getRequests()->count() - 1); |
206 | } |
207 | |
208 | return $services; |
209 | } |
210 | |
211 | public function addConditionOlderThanDate(\DateTimeInterface $dateTime) |
212 | { |
213 | // Assuming 'Datum' is the column name that holds the date of the record |
214 | // and you want to select records older than the specified $dateTime |
215 | $this->query->where('Datum', '<', $dateTime->format('Y-m-d')); |
216 | return $this; |
217 | } |
218 | } |