Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

Please ensure your account's recovery settings are up to date.

Commit 3ce0043c authored 1 week ago by Guillermo Agudelo

Lista de turnos siguientes en pantalla Turnos

parent 1fc49d3a master

No related merge requests found

Showing 11 changed files  with 185 additions and 11 deletions

  app/Employee.php
... ... @@ -3,6 +3,7 @@
3 3 namespace App;
4 4
5 5 use App\Support\LarafireModel;
6 + use TurnState;
6 7
7 8 class Employee extends LarafireModel
8 9 {
... ... @@ -22,4 +23,34 @@ class Employee extends LarafireModel
22 23
23 24 return $services;
24 25 }
26 +
27 + public function getMyNextTurnsList()
28 + {
29 + $servicesEmployees = ServiceEmployee::whereGetInstances('idEmployee','=',$this->id());
30 + $servicesIds = $servicesEmployees->map(fn($servEmp) => $servEmp->field('idService'))->all();
31 + $services = Service::whereIdIn($servicesIds);
32 +
33 + $queues = Queue::createdToday()
34 + ->where('idService', 'in', $servicesIds)
35 + ->orderBy('createAt')
36 + ->documents()->rows();
37 + $queues = Queue::rowsToInstances($queues);
38 + $queues = $queues->filter(fn($q) => $q->field('state') == TurnState::ACTIVO ||
39 + $q->field('state') == TurnState::AGENDADO);
40 +
41 + $usersIds = $queues->map(fn($queue) => $queue->field('uid'))->all();
42 +
43 + $users = User::whereIdIn($usersIds);
44 +
45 + $results = $queues->map(fn($queue) => [
46 + 'id' => $queue->id(),
47 + 'order' => $queue->field('order'),
48 + 'clientName' => $users->first(fn($u) => $u->field('id') == $queue->field('uid'))-
>field('displayName'),
49 + 'serviceName' => $services->first(fn($s) => $s->field('id') == $queue->field('idService'))-
>field('name'),
50 + 'isPriority' => $queue->field('isPriority'),
51 + 'date' => $queue->field('date'),
52 + ]);
53 +
54 + return $results;
55 + }
25 56 }

  app/Http/Controllers/API/EmployeeController.php 0 → 100644
1 + <?php
2 +
3 + namespace App\Http\Controllers\API;
4 +
5 + use App\Employee;

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 1/6
29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

6 + use App\Http\Controllers\Controller;
7 + use Illuminate\Http\Request;
8 +
9 + class EmployeeController extends Controller
10 +{
11 + public function nextTurns()
12 + {
13 + $employee = Employee::find(\State::get('employee.id'));
14 + $nextTurns = $employee->getMyNextTurnsList();
15 +
16 + return response()->json(['status' => 'success', 'data' => compact('nextTurns')]);
17 + }
18 +}

  app/Http/Controllers/API/TurnController.php

... ... @@ -15,9 +15,11 @@ use TurnState;


15 15
16 16 class TurnController extends Controller
17 17 {
18 - public function create()
18 + public function create(Request $request)
19 19 {
20 - $queue = Queue::getNextToBeAttended(\State::get('employee.id'));
20 + $turnId = $request->get('turn-id');
21 +
22 + $queue = $turnId ? Queue::find($turnId) : Queue::getNextToBeAttended(\State::get('employee.id'));
21 23
22 24 $client = Client::first('uid', '=', $queue->field('uid'));
23 25
... ...

  app/Http/Controllers/TurnController.php
... ... @@ -3,6 +3,7 @@
3 3 namespace App\Http\Controllers;
4 4
5 5 use App\Client;
6 + use App\Employee;
6 7 use App\Queue;
7 8 use App\Service;
8 9 use App\Turn;
... ... @@ -27,12 +28,16 @@ class TurnController extends Controller
27 28 $service = Service::find($queue->field('idService'));
28 29 }
29 30
31 + $employee = Employee::find(\State::get('employee.id'));
32 + $nextTurns = $employee->getMyNextTurnsList()->toArray();
33 +
30 34 return view('turns.index', compact(
31 35 'unfinishedTurn',
32 36 'queue',
33 37 'client',
34 38 'userClient',
35 - 'service'
39 + 'service',
40 + 'nextTurns'
36 41 ));
37 42 }
38 43 }

  app/Support/Globals.php
... ... @@ -16,6 +16,8 @@ if (!function_exists('feedback')) {
16 16
17 17 abstract class TurnState
18 18 {
19 + const ACTIVO = 'Activo';
20 + const AGENDADO = 'Agendado';
19 21 const ESPERANDO = 'Esperando';
20 22 const ATENDIENDO = 'Atendiendo';
21 23 const TERMINADO = 'Terminado';
... ...

  app/Support/LarafireModel.php

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 2/6
29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

... ... @@ -6,6 +6,7 @@ use Google\Cloud\Firestore\CollectionReference;


6 6 use Google\Cloud\Firestore\DocumentSnapshot;
7 7 use Google\Cloud\Firestore\Query;
8 8 use Illuminate\Database\Eloquent\ModelNotFoundException;
9 + use InvalidArgumentException;
9 10 use JsonSerializable;
10 11
11 12 class LarafireModel implements JsonSerializable
... ... @@ -175,7 +176,11 @@ class LarafireModel implements JsonSerializable
175 176 {
176 177 $this->checkFirebaseObjectSet();
177 178 if ($field == 'id') return $this->firebaseObject->id();
178 - return $this->firebaseObject->get($field);
179 + try {
180 + return $this->firebaseObject->get($field);
181 + } catch (\Exception $ex) {
182 + if ($ex instanceof InvalidArgumentException) return null;
183 + }
179 184 }
180 185
181 186 public function id()
... ...

  app/Support/LarafireUserModel.php
... ... @@ -64,6 +64,16 @@ class LarafireUserModel implements JsonSerializable
64 64 return $instance;
65 65 }
66 66
67 + public static function whereIdIn(array $ids)
68 + {
69 + $instance = self::getNewInstance();
70 +
71 + return collect(collect($ids)->map(fn($id) => $instance->find($id)));
72 + // return collect(array_map(function($id) use ($instance) {
73 + // return $instance->find($id);
74 + // }, $ids));
75 + }
76 +
67 77 public static function first($field, $operation, $value)
68 78 {
69 79 $instance = self::getNewInstance();
... ... @@ -117,7 +127,11 @@ class LarafireUserModel implements JsonSerializable
117 127 {
118 128 $this->checkFirebaseObjectSet();
119 129 if ($field == 'id') $field = 'uid';
120 - return $this->firebaseObject->$field;
130 + try {
131 + return $this->firebaseObject->$field;
132 + } catch (\Exception $ex) {
133 + if (\Str::startsWith($ex->getMessage(), 'Undefined property')) return null;
134 + }
121 135 }
122 136
123 137 public function id()
... ...

  app/Turn.php

... ... @@ -13,7 +13,8 @@ class Turn extends LarafireModel


13 13 public static function isThereTurnWaiting()
14 14 {
15 15 $instance = new Turn;
16 - $records = $instance->createdToday()->where('state', '=', 'Esperando')->documents()->rows();
16 + $records = $instance->createdToday()->where('state', '=', TurnState::ESPERANDO)
17 + ->documents()->rows();
17 18 return count($records) > 0;
18 19 }
19 20
... ... @@ -24,4 +25,6 @@ class Turn extends LarafireModel
24 25 ->documents()->rows();
25 26 return count($turns) > 0 ? Turn::rowsToInstances($turns)[0] : null;
26 27 }
28 +
29 +

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 3/6
29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

27 30 }

  notas.txt
... ... @@ -10,6 +10,8 @@
10 10 ui
11 11 . arreglar posicion icono usuario cuando responsive
12 12 . cambiar datos navbar arriba cuando mobile
13 + . centrar el agendar? en pantalla cola cuando responsive
14 + . mostrar nombre usuario y tramite al terminar de generar un turno
13 15
14 16 largo
15 17 . que cuando recupere un turno pendiente en estado 'atendiendo' en pantalla turno, muestre el tiempo
transcurrido desde que empezo el turno en el timer
... ...

  resources/views/turns/index.blade.php
... ... @@ -46,8 +46,67 @@
46 46 </div>
47 47 </div>
48 48 </div>
49 - </div>
50 49
50 + <div class="row w-75 mx-auto" v-show="status == 'idling'">
51 + <div class="col mb-3">
52 + <h3>Turnos ordenados</h3>
53 + <table class="table">
54 + <thead>
55 + <th class="text-center">#Turno</th>
56 + <th class="text-center">Nombre</th>
57 + <th class="text-center">Trámite</th>
58 + <th class="text-center">Prioritario</th>
59 + <th class="text-center">Acciones</th>
60 + </thead>
61 + <tbody>
62 + <tr v-for="turn in orderedTurns">
63 + <td class="text-center">@{{turn.order}}</td>
64 + <td class="text-center">@{{turn.clientName}}</td>
65 + <td class="text-center">@{{turn.serviceName}}</td>
66 + <td class="text-center">@{{turn.isPriority ? 'Si' : '-'}}</td>
67 + <td class="text-center">
68 + <a href="#"
69 + title="Atender de inmediato"
70 + @click.prevent="callNextTurn(turn.id)">
71 + <i class="fa fa-bullseye"></i>
72 + </a>
73 + </td>
74 + </tr>
75 + </tbody>
76 + </table>
77 + </div>
78 + </div>
79 +
80 + <div class="row w-75 mx-auto" v-show="status == 'idling'">
81 + <div class="col">
82 + <h3>Turnos agendados</h3>
83 + <table class="table">
84 + <thead>
85 + <th class="text-center">Hora</th>
86 + <th class="text-center">Nombre</th>
87 + <th class="text-center">Trámite</th>
88 + <th class="text-center">Acciones</th>
89 + </thead>
90 + <tbody>
91 + <tr v-for="turn in scheduledTurns">
92 + <td class="text-center">03:30</td>
93 + <td class="text-center">@{{turn.clientName}}</td>
94 + <td class="text-center">@{{turn.serviceName}}</td>
95 + <td class="text-center">
96 + <a href="#"
97 + title="Atender de inmediato"
98 + @click.prevent="callNextTurn(turn.id)">
99 + <i class="fa fa-bullseye"></i>
100 + </a>

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 4/6
29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

101 + </td>
102 + </tr>
103 + </tbody>
104 + </table>
105 + </div>
106 + </div>
107 +
108 + </div>
109 + <!-- TODO: Actualzar lista de turnos cuando turnos cambia estado!! -->
51 110 @push('js')
52 111 <script src="{{ asset('js/easytimer.min.js') }}"></script>
53 112 <script>
... ... @@ -62,12 +121,17 @@
62 121 turn: null,
63 122 userClient: null,
64 123 service: null,
124 + scheduledTurns: [],
125 + orderedTurns: []
65 126 }
66 127 },
67 128 methods: {
68 - callNextTurn() {
129 + callNextTurn(turnId) {
69 130 Progress.start()
70 - axios.get(@json(route('api.turns.create')))
131 + const url = turnId ? @json(route('api.turns.create'))+'?turn-id='+turnId
132 + : @json(route('api.turns.create'));
133 +
134 + axios.get(url)
71 135 .then((res) => {
72 136 if (res.data.status == 'success') {
73 137 this.client = res.data.data.client
... ... @@ -112,6 +176,7 @@
112 176 this.stopTimer()
113 177 this.resetAppData()
114 178 Feedback('success', 'Se terminó el turno exitosamente')
179 + this.fetchNextTurns()
115 180 }
116 181 }).catch(err => {
117 182 bootbox.alert("<p>Ocurrió un error al llamar al siguiente turno.</p>"
... ... @@ -128,6 +193,7 @@
128 193 this.status = 'idling'
129 194 this.resetAppData()
130 195 Feedback('success', 'Se canceló el turno exitosamente')
196 + this.fetchNextTurns()
131 197 }
132 198 }).catch(err => {
133 199 bootbox.alert("<p>Ocurrió un error al llamar al siguiente turno.</p>"
... ... @@ -150,6 +216,24 @@
150 216 stopTimer() {
151 217 this.timer.stop()
152 218 },
219 + fetchNextTurns() {
220 + Progress.start()
221 + axios.get('/api/employees/next-turns')
222 + .then((res) => {
223 + if (res.data.status == 'success') {
224 + const nextTurns = Object.values(res.data.data.nextTurns)
225 + this.scheduledTurns = nextTurns.filter(turn => turn.date)
226 + this.orderedTurns = nextTurns.filter(turn => !turn.date)
227 + console.log(this.scheduledTurns, this.orderedTurns)
228 + }
229 + })
230 + .catch((err) => {
231 + let msg = "<p>Ocurrió un error al buscar los siguientes turnos.</p>"
232 + msg += err.response.data.message.toUpperCase()
233 + bootbox.alert(msg)
234 + console.log(err.response)
235 + }).then(() => Progress.done())
236 + }
153 237 },
154 238 mounted() {
155 239 const unfinishedTurn = @json($unfinishedTurn);
... ... @@ -160,8 +244,9 @@
160 244 this.userClient = @json($userClient);

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 5/6
29/6/2020 Lista de turnos siguientes en pantalla Turnos (3ce0043c) · Commits · Guillermo Agudelo / transito-frontend · GitLab

161 245 this.service = @json($service);


162 246 this.status = this.turn.state == 'Esperando' ? 'waiting' : 'attending'
163 - // if (this.status == 'attending') this.startTimer()
164 247 }
248 +
249 + this.fetchNextTurns()
165 250 }
166 251 })
167 252 </script>
... ...

  routes/web.php
... ... @@ -80,9 +80,16 @@ Route::group([
80 80
81 81 Route::group([
82 82 'prefix' => 'pending-turns',
83 - 'as' => 'prending-turns.'
83 + 'as' => 'pending-turns.'
84 84 ], function() {
85 85 Route::get('all-from-today','PendingTurnController@allFromToday')->name('all-from-today');
86 86 });
87 +
88 + Route::group([
89 + 'prefix' => 'employees',
90 + 'as' => 'employees.'
91 + ], function() {
92 + Route::get('next-turns','EmployeeController@nextTurns')->name('next-turns');
93 + });
87 94 });
88 95

Write a comment or drag your files here…

Markdown and quick actions are supported

https://gitlab.com/guille.agudelo/transito-frontend/-/commit/3ce0043c4ef085363fa4e4da51621c87625d06a7 6/6

You might also like