Commit 45620bb6ef1d1fabd8bc1b0820dbef2e9a78b039
Exists in
master
Merge branch 'master' into 'develop'
Master(efernandez) See merge request !45
Showing
2 changed files
Show diff stats
spec/controllerSpec.js
1 | describe('Controladores módulo crear hoja de ruta', function() { | 1 | describe('Controladores módulo crear hoja de ruta', function() { |
2 | 2 | ||
3 | var $controller; | 3 | var $controller; |
4 | 4 | ||
5 | beforeEach(function() { | 5 | beforeEach(function() { |
6 | 6 | ||
7 | module('focaCrearHojaRuta'); | 7 | module('focaCrearHojaRuta'); |
8 | inject(function(_$controller_) { | 8 | inject(function(_$controller_) { |
9 | $controller = _$controller_; | 9 | $controller = _$controller_; |
10 | }); | 10 | }); |
11 | }); | 11 | }); |
12 | 12 | ||
13 | describe('controlador focaModalDatosHojaRutaCtrl', function() { | 13 | describe('controlador focaModalDatosHojaRutaCtrl', function() { |
14 | 14 | ||
15 | it('Existe el controlador focaModalDatosHojaRutaCtrl', function() { | 15 | it('Existe el controlador focaModalDatosHojaRutaCtrl', function() { |
16 | 16 | ||
17 | //act | 17 | //act |
18 | var controlador = $controller('focaModalDatosHojaRutaCtrl', { | 18 | var controlador = $controller('focaModalDatosHojaRutaCtrl', { |
19 | $filter: {}, | 19 | $filter: {}, |
20 | $scope: {}, | 20 | $scope: {}, |
21 | $uibModalInstance: {}, | 21 | $uibModalInstance: {}, |
22 | focaModalService: {}, | 22 | focaModalService: {}, |
23 | parametrosDatos: {} | 23 | parametrosDatos: {} |
24 | }); | 24 | }); |
25 | 25 | ||
26 | //assert | 26 | //assert |
27 | expect(typeof controlador).toEqual('object'); | 27 | expect(typeof controlador).toEqual('object'); |
28 | }); | 28 | }); |
29 | 29 | ||
30 | it('función $scope.aceptar muestra alerta cuando el formulario es inválido', function() { | 30 | it('función $scope.aceptar muestra alerta cuando el formulario es inválido', function() { |
31 | 31 | ||
32 | //arrange | 32 | //arrange |
33 | var scope = {}; | 33 | var scope = {}; |
34 | var focaModalService = { | 34 | var focaModalService = { |
35 | alert: function() { } | 35 | alert: function() { } |
36 | }; | 36 | }; |
37 | 37 | ||
38 | $controller('focaModalDatosHojaRutaCtrl', { | 38 | $controller('focaModalDatosHojaRutaCtrl', { |
39 | $filter: {}, | 39 | $filter: {}, |
40 | $scope: scope, | 40 | $scope: scope, |
41 | $uibModalInstance: {}, | 41 | $uibModalInstance: {}, |
42 | focaModalService: focaModalService, | 42 | focaModalService: focaModalService, |
43 | parametrosDatos: {} | 43 | parametrosDatos: {} |
44 | }); | 44 | }); |
45 | 45 | ||
46 | //act | 46 | //act |
47 | scope.formDatosHojaRuta = { | 47 | scope.formDatosHojaRuta = { |
48 | $valid: false | 48 | $valid: false |
49 | }; | 49 | }; |
50 | spyOn(focaModalService, 'alert'); | 50 | spyOn(focaModalService, 'alert'); |
51 | scope.aceptar(13); | 51 | scope.aceptar(13); |
52 | 52 | ||
53 | //assert | 53 | //assert |
54 | expect(focaModalService.alert).toHaveBeenCalledWith('Formulario inválido'); | 54 | expect(focaModalService.alert).toHaveBeenCalledWith('Formulario inválido'); |
55 | }); | 55 | }); |
56 | 56 | ||
57 | it('función $scope.aceptar llama a uibModalInstance.close', function() { | 57 | it('función $scope.aceptar llama a uibModalInstance.close', function() { |
58 | 58 | ||
59 | //arrange | 59 | //arrange |
60 | var scope = {}; | 60 | var scope = {}; |
61 | var uibModalInstance = { | 61 | var uibModalInstance = { |
62 | close: function() { } | 62 | close: function() { } |
63 | }; | 63 | }; |
64 | 64 | ||
65 | $controller('focaModalDatosHojaRutaCtrl', { | 65 | $controller('focaModalDatosHojaRutaCtrl', { |
66 | $filter: {}, | 66 | $filter: {}, |
67 | $scope: scope, | 67 | $scope: scope, |
68 | $uibModalInstance: uibModalInstance, | 68 | $uibModalInstance: uibModalInstance, |
69 | focaModalService: {}, | 69 | focaModalService: {}, |
70 | parametrosDatos: {} | 70 | parametrosDatos: {} |
71 | }); | 71 | }); |
72 | 72 | ||
73 | //act | 73 | //act |
74 | scope.formDatosHojaRuta = { | 74 | scope.formDatosHojaRuta = { |
75 | $valid: true | 75 | $valid: true |
76 | }; | 76 | }; |
77 | spyOn(uibModalInstance, 'close'); | 77 | spyOn(uibModalInstance, 'close'); |
78 | scope.aceptar(13); | 78 | scope.aceptar(13); |
79 | 79 | ||
80 | //assert | 80 | //assert |
81 | expect(uibModalInstance.close).toHaveBeenCalled(); | 81 | expect(uibModalInstance.close).toHaveBeenCalled(); |
82 | }); | 82 | }); |
83 | 83 | ||
84 | it('función $scope.next suma uno a focused', function() { | 84 | it('función $scope.next suma uno a focused', function() { |
85 | 85 | ||
86 | //arrange | 86 | //arrange |
87 | var scope = {}; | 87 | var scope = {}; |
88 | 88 | ||
89 | $controller('focaModalDatosHojaRutaCtrl', { | 89 | $controller('focaModalDatosHojaRutaCtrl', { |
90 | $filter: {}, | 90 | $filter: {}, |
91 | $scope: scope, | 91 | $scope: scope, |
92 | $uibModalInstance: {}, | 92 | $uibModalInstance: {}, |
93 | focaModalService: {}, | 93 | focaModalService: {}, |
94 | parametrosDatos: {} | 94 | parametrosDatos: {} |
95 | }); | 95 | }); |
96 | scope.focused = 1; | 96 | scope.focused = 1; |
97 | 97 | ||
98 | //act | 98 | //act |
99 | var esperado = scope.focused + 1; | 99 | var esperado = scope.focused + 1; |
100 | scope.next(13); | 100 | scope.next(13); |
101 | 101 | ||
102 | //assert | 102 | //assert |
103 | expect(scope.focused).toEqual(esperado); | 103 | expect(scope.focused).toEqual(esperado); |
104 | }); | 104 | }); |
105 | 105 | ||
106 | it('función $scope.cancel llama a dismiss', function() { | 106 | it('función $scope.cancel llama a dismiss', function() { |
107 | 107 | ||
108 | //arrange | 108 | //arrange |
109 | var scope = {}; | 109 | var scope = {}; |
110 | var uibModalInstance = { | 110 | var uibModalInstance = { |
111 | dismiss: function() { } | 111 | dismiss: function() { } |
112 | }; | 112 | }; |
113 | 113 | ||
114 | $controller('focaModalDatosHojaRutaCtrl', { | 114 | $controller('focaModalDatosHojaRutaCtrl', { |
115 | $filter: {}, | 115 | $filter: {}, |
116 | $scope: scope, | 116 | $scope: scope, |
117 | $uibModalInstance: uibModalInstance, | 117 | $uibModalInstance: uibModalInstance, |
118 | focaModalService: {}, | 118 | focaModalService: {}, |
119 | parametrosDatos: {} | 119 | parametrosDatos: {} |
120 | }); | 120 | }); |
121 | 121 | ||
122 | //act | 122 | //act |
123 | spyOn(uibModalInstance, 'dismiss'); | 123 | spyOn(uibModalInstance, 'dismiss'); |
124 | scope.cancel(); | 124 | scope.cancel(); |
125 | 125 | ||
126 | //assert | 126 | //assert |
127 | expect(uibModalInstance.dismiss).toHaveBeenCalledWith('cancel'); | 127 | expect(uibModalInstance.dismiss).toHaveBeenCalledWith('cancel'); |
128 | }); | 128 | }); |
129 | }); | 129 | }); |
130 | 130 | ||
131 | describe('controlador hojaRutaCtrl', function() { | 131 | describe('controlador hojaRutaCtrl', function() { |
132 | 132 | ||
133 | var $filter = function() { | 133 | var $filter = function() { |
134 | return function() { }; | 134 | return function() { }; |
135 | }; | 135 | }; |
136 | 136 | ||
137 | var $timeout = function() { }; | 137 | var $timeout = function() { }; |
138 | 138 | ||
139 | it('existe el controlador hojaRutaCtrl', function() { | 139 | it('existe el controlador hojaRutaCtrl', function() { |
140 | 140 | ||
141 | //act | 141 | //act |
142 | var controlador = $controller('hojaRutaCtrl', { | 142 | var controlador = $controller('hojaRutaCtrl', { |
143 | $scope: { | 143 | $scope: { |
144 | $broadcast: function() { }, | 144 | $broadcast: function() { }, |
145 | $watch: function() {} | 145 | $watch: function() {} |
146 | }, | 146 | }, |
147 | $uibModal: {}, | 147 | $uibModal: {}, |
148 | $location: {}, | 148 | $location: {}, |
149 | $filter: $filter, | 149 | $filter: $filter, |
150 | $timeout: $timeout, | 150 | $timeout: $timeout, |
151 | focaCrearHojaRutaService: { | 151 | focaCrearHojaRutaService: { |
152 | getBotonera: function() { }, | 152 | getBotonera: function() { }, |
153 | getNumeroHojaRuta: function() { | 153 | getNumeroHojaRuta: function() { |
154 | return { | 154 | return { |
155 | then: function() { } | 155 | then: function() { } |
156 | }; | 156 | }; |
157 | }, | ||
158 | getParametros: function () { | ||
159 | return { | ||
160 | then: function() { } | ||
161 | }; | ||
157 | } | 162 | } |
158 | }, | 163 | }, |
159 | focaModalService: {}, | 164 | focaModalService: {}, |
160 | focaBotoneraLateralService: {}, | 165 | focaBotoneraLateralService: {}, |
161 | focaLoginService: {}, | 166 | focaLoginService: {}, |
162 | $localStorage: function() {} | 167 | $localStorage: function() {} |
163 | }); | 168 | }); |
164 | 169 | ||
165 | //assert | 170 | //assert |
166 | expect(typeof controlador).toEqual('object'); | 171 | expect(typeof controlador).toEqual('object'); |
167 | }); | 172 | }); |
168 | 173 | ||
169 | it('guardar hoja ruta valida que tenga al menos un remito', function() { | 174 | it('guardar hoja ruta valida que tenga al menos un remito', function() { |
170 | 175 | ||
171 | //arrange | 176 | //arrange |
172 | var scope = { | 177 | var scope = { |
173 | $broadcast: function() { }, | 178 | $broadcast: function() { }, |
174 | $watch: function() {} | 179 | $watch: function() {} |
175 | }; | 180 | }; |
176 | var focaModalService = { | 181 | var focaModalService = { |
177 | alert: function() { } | 182 | alert: function() { } |
178 | }; | 183 | }; |
179 | 184 | ||
180 | $controller('hojaRutaCtrl', { | 185 | $controller('hojaRutaCtrl', { |
181 | $scope: scope, | 186 | $scope: scope, |
182 | $uibModal: {}, | 187 | $uibModal: {}, |
183 | $location: {}, | 188 | $location: {}, |
184 | $filter: $filter, | 189 | $filter: $filter, |
185 | $timeout: $timeout, | 190 | $timeout: $timeout, |
186 | focaCrearHojaRutaService: { | 191 | focaCrearHojaRutaService: { |
187 | getBotonera: function() { }, | 192 | getBotonera: function() { }, |
188 | getNumeroHojaRuta: function() { | 193 | getNumeroHojaRuta: function() { |
189 | return { | 194 | return { |
190 | then: function() { } | 195 | then: function() { } |
191 | }; | 196 | }; |
197 | }, | ||
198 | getParametros: function () { | ||
199 | return { | ||
200 | then: function() { } | ||
201 | }; | ||
192 | } | 202 | } |
193 | }, | 203 | }, |
194 | focaModalService: focaModalService, | 204 | focaModalService: focaModalService, |
195 | focaBotoneraLateralService: {}, | 205 | focaBotoneraLateralService: {}, |
196 | focaLoginService: {}, | 206 | focaLoginService: {}, |
197 | $localStorage: function() {} | 207 | $localStorage: function() {} |
198 | }); | 208 | }); |
199 | scope.remitosTabla = []; | 209 | scope.remitosTabla = []; |
200 | 210 | ||
201 | //act | 211 | //act |
202 | spyOn(focaModalService, 'alert'); | 212 | spyOn(focaModalService, 'alert'); |
203 | 213 | ||
204 | scope.crearHojaRuta(); | 214 | scope.crearHojaRuta(); |
205 | 215 | ||
206 | //assert | 216 | //assert |
207 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Remitos'); | 217 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Remitos'); |
208 | }); | 218 | }); |
209 | 219 | ||
210 | it('guardar hoja ruta valida que tenga chofer', function() { | 220 | it('guardar hoja ruta valida que tenga chofer', function() { |
211 | 221 | ||
212 | //arrange | 222 | //arrange |
213 | var scope = { | 223 | var scope = { |
214 | $broadcast: function() { }, | 224 | $broadcast: function() { }, |
215 | $watch: function() {} | 225 | $watch: function() {} |
216 | }; | 226 | }; |
217 | var focaModalService = { | 227 | var focaModalService = { |
218 | alert: function() { } | 228 | alert: function() { } |
219 | }; | 229 | }; |
220 | 230 | ||
221 | $controller('hojaRutaCtrl', { | 231 | $controller('hojaRutaCtrl', { |
222 | $scope: scope, | 232 | $scope: scope, |
223 | $uibModal: {}, | 233 | $uibModal: {}, |
224 | $location: {}, | 234 | $location: {}, |
225 | $filter: $filter, | 235 | $filter: $filter, |
226 | $timeout: $timeout, | 236 | $timeout: $timeout, |
227 | focaCrearHojaRutaService: { | 237 | focaCrearHojaRutaService: { |
228 | getBotonera: function() { }, | 238 | getBotonera: function() { }, |
229 | getNumeroHojaRuta: function() { | 239 | getNumeroHojaRuta: function() { |
230 | return { | 240 | return { |
231 | then: function() { } | 241 | then: function() { } |
232 | }; | 242 | }; |
243 | }, | ||
244 | getParametros: function () { | ||
245 | return { | ||
246 | then: function() { } | ||
247 | }; | ||
233 | } | 248 | } |
234 | }, | 249 | }, |
235 | focaModalService: focaModalService, | 250 | focaModalService: focaModalService, |
236 | focaBotoneraLateralService: {}, | 251 | focaBotoneraLateralService: {}, |
237 | focaLoginService: {}, | 252 | focaLoginService: {}, |
238 | $localStorage: function() {} | 253 | $localStorage: function() {} |
239 | }); | 254 | }); |
240 | 255 | ||
241 | scope.hojaRuta = { | 256 | scope.hojaRuta = { |
242 | chofer: { }, | 257 | chofer: { }, |
243 | remitosTabla: [1] | 258 | remitosTabla: [1] |
244 | }; | 259 | }; |
245 | 260 | ||
246 | //act | 261 | //act |
247 | spyOn(focaModalService, 'alert'); | 262 | spyOn(focaModalService, 'alert'); |
248 | 263 | ||
249 | scope.crearHojaRuta(); | 264 | scope.crearHojaRuta(); |
250 | 265 | ||
251 | //assert | 266 | //assert |
252 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Chofer'); | 267 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Chofer'); |
253 | }); | 268 | }); |
254 | 269 | ||
255 | it('guardar hoja ruta valida que tenga vehiculo', function() { | 270 | it('guardar hoja ruta valida que tenga vehiculo', function() { |
256 | 271 | ||
257 | //arrange | 272 | //arrange |
258 | var scope = { | 273 | var scope = { |
259 | $broadcast: function() { }, | 274 | $broadcast: function() { }, |
260 | $watch: function() {} | 275 | $watch: function() {} |
261 | }; | 276 | }; |
262 | var focaModalService = { | 277 | var focaModalService = { |
263 | alert: function() { } | 278 | alert: function() { } |
264 | }; | 279 | }; |
265 | 280 | ||
266 | $controller('hojaRutaCtrl', { | 281 | $controller('hojaRutaCtrl', { |
267 | $scope: scope, | 282 | $scope: scope, |
268 | $uibModal: {}, | 283 | $uibModal: {}, |
269 | $location: {}, | 284 | $location: {}, |
270 | $filter: $filter, | 285 | $filter: $filter, |
271 | $timeout: $timeout, | 286 | $timeout: $timeout, |
272 | focaCrearHojaRutaService: { | 287 | focaCrearHojaRutaService: { |
273 | getBotonera: function() { }, | 288 | getBotonera: function() { }, |
274 | getNumeroHojaRuta: function() { | 289 | getNumeroHojaRuta: function() { |
275 | return { | 290 | return { |
276 | then: function() { } | 291 | then: function() { } |
277 | }; | 292 | }; |
293 | }, | ||
294 | getParametros: function () { | ||
295 | return { | ||
296 | then: function() { } | ||
297 | }; | ||
278 | } | 298 | } |
279 | }, | 299 | }, |
280 | focaModalService: focaModalService, | 300 | focaModalService: focaModalService, |
281 | focaBotoneraLateralService: {}, | 301 | focaBotoneraLateralService: {}, |
282 | focaLoginService: {}, | 302 | focaLoginService: {}, |
283 | $localStorage: function() {} | 303 | $localStorage: function() {} |
284 | }); | 304 | }); |
285 | scope.hojaRuta = { | 305 | scope.hojaRuta = { |
286 | chofer: { id: true }, | 306 | chofer: { id: true }, |
287 | vehiculo: { }, | 307 | vehiculo: { }, |
288 | remitosTabla: [1] | 308 | remitosTabla: [1] |
289 | }; | 309 | }; |
290 | 310 | ||
291 | //act | 311 | //act |
292 | spyOn(focaModalService, 'alert'); | 312 | spyOn(focaModalService, 'alert'); |
293 | 313 | ||
294 | scope.crearHojaRuta(); | 314 | scope.crearHojaRuta(); |
295 | 315 | ||
296 | //assert | 316 | //assert |
297 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vehiculo'); | 317 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vehiculo'); |
298 | }); | 318 | }); |
299 | 319 | ||
300 | it('guardar hoja ruta valida que tenga transportista', function() { | 320 | it('guardar hoja ruta valida que tenga transportista', function() { |
301 | 321 | ||
302 | //arrange | 322 | //arrange |
303 | var scope = { | 323 | var scope = { |
304 | $broadcast: function() { }, | 324 | $broadcast: function() { }, |
305 | $watch: function() {} | 325 | $watch: function() {} |
306 | }; | 326 | }; |
307 | var focaModalService = { | 327 | var focaModalService = { |
308 | alert: function() { } | 328 | alert: function() { } |
309 | }; | 329 | }; |
310 | 330 | ||
311 | $controller('hojaRutaCtrl', { | 331 | $controller('hojaRutaCtrl', { |
312 | $scope: scope, | 332 | $scope: scope, |
313 | $uibModal: {}, | 333 | $uibModal: {}, |
314 | $location: {}, | 334 | $location: {}, |
315 | $filter: $filter, | 335 | $filter: $filter, |
316 | $timeout: $timeout, | 336 | $timeout: $timeout, |
317 | focaCrearHojaRutaService: { | 337 | focaCrearHojaRutaService: { |
318 | getBotonera: function() { }, | 338 | getBotonera: function() { }, |
319 | getNumeroHojaRuta: function() { | 339 | getNumeroHojaRuta: function() { |
320 | return { | 340 | return { |
321 | then: function() { } | 341 | then: function() { } |
322 | }; | 342 | }; |
343 | }, | ||
344 | getParametros: function () { | ||
345 | return { | ||
346 | then: function() { } | ||
347 | }; | ||
323 | } | 348 | } |
324 | }, | 349 | }, |
325 | focaModalService: focaModalService, | 350 | focaModalService: focaModalService, |
326 | focaBotoneraLateralService: {}, | 351 | focaBotoneraLateralService: {}, |
327 | focaLoginService: {}, | 352 | focaLoginService: {}, |
328 | $localStorage: function() {} | 353 | $localStorage: function() {} |
329 | }); | 354 | }); |
330 | scope.hojaRuta = { | 355 | scope.hojaRuta = { |
331 | chofer: { id: true }, | 356 | chofer: { id: true }, |
332 | vehiculo: { id: true }, | 357 | vehiculo: { id: true }, |
333 | transportista: { }, | 358 | transportista: { }, |
334 | remitosTabla: [1] | 359 | remitosTabla: [1] |
335 | }; | 360 | }; |
336 | 361 | ||
337 | //act | 362 | //act |
338 | spyOn(focaModalService, 'alert'); | 363 | spyOn(focaModalService, 'alert'); |
339 | 364 | ||
340 | scope.crearHojaRuta(); | 365 | scope.crearHojaRuta(); |
341 | 366 | ||
342 | //assert | 367 | //assert |
343 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Transportista'); | 368 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Transportista'); |
344 | }); | 369 | }); |
345 | 370 | ||
346 | it('guardar hoja ruta valida que tenga tarifario', function() { | 371 | it('guardar hoja ruta valida que tenga tarifario', function() { |
347 | 372 | ||
348 | //arrange | 373 | //arrange |
349 | var scope = { | 374 | var scope = { |
350 | $broadcast: function() { }, | 375 | $broadcast: function() { }, |
351 | $watch: function() {} | 376 | $watch: function() {} |
352 | }; | 377 | }; |
353 | var focaModalService = { | 378 | var focaModalService = { |
354 | alert: function() { } | 379 | alert: function() { } |
355 | }; | 380 | }; |
356 | 381 | ||
357 | $controller('hojaRutaCtrl', { | 382 | $controller('hojaRutaCtrl', { |
358 | $scope: scope, | 383 | $scope: scope, |
359 | $uibModal: {}, | 384 | $uibModal: {}, |
360 | $location: {}, | 385 | $location: {}, |
361 | $filter: $filter, | 386 | $filter: $filter, |
362 | $timeout: $timeout, | 387 | $timeout: $timeout, |
363 | focaCrearHojaRutaService: { | 388 | focaCrearHojaRutaService: { |
364 | getBotonera: function() { }, | 389 | getBotonera: function() { }, |
365 | getNumeroHojaRuta: function() { | 390 | getNumeroHojaRuta: function() { |
366 | return { | 391 | return { |
367 | then: function() { } | 392 | then: function() { } |
368 | }; | 393 | }; |
394 | }, | ||
395 | getParametros: function () { | ||
396 | return { | ||
397 | then: function() { } | ||
398 | }; | ||
369 | } | 399 | } |
370 | }, | 400 | }, |
371 | focaModalService: focaModalService, | 401 | focaModalService: focaModalService, |
372 | focaBotoneraLateralService: {}, | 402 | focaBotoneraLateralService: {}, |
373 | focaLoginService: {}, | 403 | focaLoginService: {}, |
374 | $localStorage: function() {} | 404 | $localStorage: function() {} |
375 | }); | 405 | }); |
376 | scope.hojaRuta = { | 406 | scope.hojaRuta = { |
377 | chofer: { id: true }, | 407 | chofer: { id: true }, |
378 | vehiculo: { id: true }, | 408 | vehiculo: { id: true }, |
379 | transportista: { COD: true }, | 409 | transportista: { COD: true }, |
380 | tarifario: { }, | ||
381 | remitosTabla: [1] | 410 | remitosTabla: [1] |
382 | }; | 411 | }; |
383 | 412 | ||
384 | //act | 413 | //act |
385 | spyOn(focaModalService, 'alert'); | 414 | spyOn(focaModalService, 'alert'); |
386 | 415 | ||
387 | scope.crearHojaRuta(); | 416 | scope.crearHojaRuta(); |
388 | 417 | ||
389 | //assert | 418 | //assert |
390 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Tarifario'); | 419 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Tarifario'); |
391 | }); | 420 | }); |
392 | 421 | ||
393 | it('guardar hoja ruta valida que tenga datosExtra', function() { | 422 | it('guardar hoja ruta valida que tenga datosExtra', function() { |
394 | 423 | ||
395 | //arrange | 424 | //arrange |
396 | var scope = { | 425 | var scope = { |
397 | $broadcast: function() { }, | 426 | $broadcast: function() { }, |
398 | $watch: function() {} | 427 | $watch: function() {} |
399 | }; | 428 | }; |
400 | var focaModalService = { | 429 | var focaModalService = { |
401 | alert: function() { } | 430 | alert: function() { } |
402 | }; | 431 | }; |
403 | 432 | ||
404 | $controller('hojaRutaCtrl', { | 433 | $controller('hojaRutaCtrl', { |
405 | $scope: scope, | 434 | $scope: scope, |
406 | $uibModal: {}, | 435 | $uibModal: {}, |
407 | $location: {}, | 436 | $location: {}, |
408 | $filter: $filter, | 437 | $filter: $filter, |
409 | $timeout: $timeout, | 438 | $timeout: $timeout, |
410 | focaCrearHojaRutaService: { | 439 | focaCrearHojaRutaService: { |
411 | getBotonera: function() { }, | 440 | getBotonera: function() { }, |
412 | getNumeroHojaRuta: function() { | 441 | getNumeroHojaRuta: function() { |
413 | return { | 442 | return { |
414 | then: function() { } | 443 | then: function() { } |
415 | }; | 444 | }; |
445 | }, | ||
446 | getParametros: function () { | ||
447 | return { | ||
448 | then: function() { } | ||
449 | }; | ||
416 | } | 450 | } |
417 | }, | 451 | }, |
418 | focaModalService: focaModalService, | 452 | focaModalService: focaModalService, |
419 | focaBotoneraLateralService: {}, | 453 | focaBotoneraLateralService: {}, |
420 | focaLoginService: {}, | 454 | focaLoginService: {}, |
421 | $localStorage: function() {} | 455 | $localStorage: function() {} |
422 | }); | 456 | }); |
423 | scope.hojaRuta = { | 457 | scope.hojaRuta = { |
424 | chofer: { id: true }, | 458 | chofer: { id: true }, |
425 | vehiculo: { id: true }, | 459 | vehiculo: { id: true }, |
426 | transportista: { COD: true }, | 460 | transportista: { COD: true }, |
427 | tarifario: { costo: true }, | 461 | tarifario: { costo: true }, |
428 | remitosTabla: [1] | 462 | remitosTabla: [1] |
429 | }; | 463 | }; |
430 | 464 | ||
431 | //act | 465 | //act |
432 | spyOn(focaModalService, 'alert'); | 466 | spyOn(focaModalService, 'alert'); |
433 | 467 | ||
434 | scope.crearHojaRuta(); | 468 | scope.crearHojaRuta(); |
435 | 469 | ||
436 | //assert | 470 | //assert |
437 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Datos extra'); | 471 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Datos extra'); |
438 | }); | 472 | }); |
439 | 473 | ||
440 | it('guardar hoja ruta llama focaCrearHojaRutaService.crearHojaRuta', function() { | 474 | it('guardar hoja ruta llama focaCrearHojaRutaService.crearHojaRuta', function() { |
441 | 475 | ||
442 | //arrange | 476 | //arrange |
443 | var scope = { | 477 | var scope = { |
444 | $broadcast: function() { }, | 478 | $broadcast: function() { }, |
445 | $watch: function() {} | 479 | $watch: function() {} |
446 | }; | 480 | }; |
447 | var focaCrearHojaRutaService = { | 481 | var focaCrearHojaRutaService = { |
448 | getBotonera: function() { }, | 482 | getBotonera: function() { }, |
449 | getNumeroHojaRuta: function() { | 483 | getNumeroHojaRuta: function() { |
450 | return { | 484 | return { |
451 | then: function() { } | 485 | then: function() { } |
452 | }; | 486 | }; |
453 | }, | 487 | }, |
454 | crearHojaRuta: function() { } | 488 | crearHojaRuta: function() { }, |
489 | getParametros: function () { | ||
490 | return { | ||
491 | then: function() { } | ||
492 | }; | ||
493 | } | ||
455 | }; | 494 | }; |
456 | 495 | ||
457 | $controller('hojaRutaCtrl', { | 496 | $controller('hojaRutaCtrl', { |
458 | $scope: scope, | 497 | $scope: scope, |
459 | $uibModal: {}, | 498 | $uibModal: {}, |
460 | $location: {}, | 499 | $location: {}, |
461 | $filter: $filter, | 500 | $filter: $filter, |
462 | $timeout: $timeout, | 501 | $timeout: $timeout, |
463 | focaCrearHojaRutaService: focaCrearHojaRutaService, | 502 | focaCrearHojaRutaService: focaCrearHojaRutaService, |
464 | focaModalService: {}, | 503 | focaModalService: {}, |
465 | focaBotoneraLateralService: {}, | 504 | focaBotoneraLateralService: {}, |
466 | focaLoginService: {}, | 505 | focaLoginService: {}, |
467 | $localStorage: function() {} | 506 | $localStorage: function() {} |
468 | }); | 507 | }); |
469 | scope.hojaRuta = { | 508 | scope.hojaRuta = { |
470 | chofer: { id: true }, | 509 | chofer: { id: true }, |
471 | vehiculo: { id: true }, | 510 | vehiculo: { id: true }, |
472 | transportista: { COD: true }, | 511 | transportista: { COD: true }, |
473 | tarifario: { costo: true }, | 512 | tarifario: { costo: true }, |
474 | datosExtra: { }, | 513 | datosExtra: { }, |
475 | fechaReparto: new Date(), | 514 | fechaReparto: new Date(), |
476 | remitosTabla: [1] | 515 | remitosTabla: [1] |
477 | }; | 516 | }; |
478 | 517 | ||
479 | var respuesta = { then: function() { } }; | 518 | var respuesta = { then: function() { } }; |
480 | 519 | ||
481 | //act | 520 | //act |
482 | spyOn(focaCrearHojaRutaService, 'crearHojaRuta').and.returnValue(respuesta); | 521 | spyOn(focaCrearHojaRutaService, 'crearHojaRuta').and.returnValue(respuesta); |
483 | 522 | ||
484 | scope.crearHojaRuta(); | 523 | scope.crearHojaRuta(); |
485 | 524 | ||
486 | //assert | 525 | //assert |
487 | expect(focaCrearHojaRutaService.crearHojaRuta).toHaveBeenCalled(); | 526 | expect(focaCrearHojaRutaService.crearHojaRuta).toHaveBeenCalled(); |
488 | }); | 527 | }); |
489 | 528 | ||
490 | it('seleccionarTransportista levanta modal y setea datos', function(done) { | 529 | it('seleccionarTransportista levanta modal y setea datos', function(done) { |
491 | 530 | ||
492 | //arrange | 531 | //arrange |
493 | var scope = { | 532 | var scope = { |
494 | $broadcast: function() { }, | 533 | $broadcast: function() { }, |
495 | $watch: function() {} | 534 | $watch: function() {} |
496 | }; | 535 | }; |
497 | var focaModalService = { | 536 | var focaModalService = { |
498 | modal: function() { } | 537 | modal: function() { } |
499 | }; | 538 | }; |
500 | 539 | ||
501 | $controller('hojaRutaCtrl', { | 540 | $controller('hojaRutaCtrl', { |
502 | $scope: scope, | 541 | $scope: scope, |
503 | $uibModal: {}, | 542 | $uibModal: {}, |
504 | $location: {}, | 543 | $location: {}, |
505 | $filter: $filter, | 544 | $filter: $filter, |
506 | $timeout: $timeout, | 545 | $timeout: $timeout, |
507 | focaCrearHojaRutaService: { | 546 | focaCrearHojaRutaService: { |
508 | getBotonera: function() { }, | 547 | getBotonera: function() { }, |
509 | getNumeroHojaRuta: function() { | 548 | getNumeroHojaRuta: function() { |
510 | return { | 549 | return { |
511 | then: function() { } | 550 | then: function() { } |
512 | }; | 551 | }; |
552 | }, | ||
553 | getParametros: function () { | ||
554 | return { | ||
555 | then: function() { } | ||
556 | }; | ||
513 | } | 557 | } |
514 | }, | 558 | }, |
515 | focaModalService: focaModalService, | 559 | focaModalService: focaModalService, |
516 | focaBotoneraLateralService: {}, | 560 | focaBotoneraLateralService: {}, |
517 | focaLoginService: {}, | 561 | focaLoginService: {}, |
518 | $localStorage: function() {} | 562 | $localStorage: function() {} |
519 | }); | 563 | }); |
520 | 564 | ||
521 | var respuesta = 1; | 565 | var respuesta = 1; |
522 | var promesa = Promise.resolve(respuesta); | 566 | var promesa = Promise.resolve(respuesta); |
523 | 567 | ||
524 | //act | 568 | //act |
525 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 569 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
526 | spyOn(scope, '$broadcast'); | 570 | spyOn(scope, '$broadcast'); |
527 | 571 | ||
528 | scope.seleccionarTransportista(); | 572 | scope.seleccionarTransportista(); |
529 | 573 | ||
530 | //assert | 574 | //assert |
531 | promesa.then(function() { | 575 | promesa.then(function() { |
532 | expect(focaModalService.modal).toHaveBeenCalled(); | 576 | expect(focaModalService.modal).toHaveBeenCalled(); |
533 | expect(scope.$broadcast).toHaveBeenCalled(); | 577 | expect(scope.$broadcast).toHaveBeenCalled(); |
534 | expect(scope.hojaRuta.transportista).toEqual(respuesta); | 578 | expect(scope.hojaRuta.transportista).toEqual(respuesta); |
535 | done(); | 579 | done(); |
536 | }); | 580 | }); |
537 | 581 | ||
538 | }); | 582 | }); |
539 | 583 | ||
540 | it('seleccionarChofer levanta modal y setea datos', function(done) { | 584 | it('seleccionarChofer levanta modal y setea datos', function(done) { |
541 | 585 | ||
542 | //arrange | 586 | //arrange |
543 | var scope = { | 587 | var scope = { |
544 | $broadcast: function() { }, | 588 | $broadcast: function() { }, |
545 | $watch: function() {} | 589 | $watch: function() {} |
546 | }; | 590 | }; |
547 | var focaModalService = { | 591 | var focaModalService = { |
548 | modal: function() { } | 592 | modal: function() { } |
549 | }; | 593 | }; |
550 | 594 | ||
551 | $controller('hojaRutaCtrl', { | 595 | $controller('hojaRutaCtrl', { |
552 | $scope: scope, | 596 | $scope: scope, |
553 | $uibModal: {}, | 597 | $uibModal: {}, |
554 | $location: {}, | 598 | $location: {}, |
555 | $filter: $filter, | 599 | $filter: $filter, |
556 | $timeout: $timeout, | 600 | $timeout: $timeout, |
557 | focaCrearHojaRutaService: { | 601 | focaCrearHojaRutaService: { |
558 | getBotonera: function() { }, | 602 | getBotonera: function() { }, |
559 | getNumeroHojaRuta: function() { | 603 | getNumeroHojaRuta: function() { |
560 | return { | 604 | return { |
561 | then: function() { } | 605 | then: function() { } |
562 | }; | 606 | }; |
607 | }, | ||
608 | getParametros: function () { | ||
609 | return { | ||
610 | then: function() { } | ||
611 | }; | ||
563 | } | 612 | } |
564 | }, | 613 | }, |
565 | focaModalService: focaModalService, | 614 | focaModalService: focaModalService, |
566 | focaBotoneraLateralService: {}, | 615 | focaBotoneraLateralService: {}, |
567 | focaLoginService: {}, | 616 | focaLoginService: {}, |
568 | $localStorage: function() {} | 617 | $localStorage: function() {} |
569 | }); | 618 | }); |
570 | 619 | ||
571 | var respuesta = 1; | 620 | var respuesta = 1; |
572 | var promesa = Promise.resolve(respuesta); | 621 | var promesa = Promise.resolve(respuesta); |
573 | 622 | ||
574 | //act | 623 | //act |
575 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 624 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
576 | spyOn(scope, '$broadcast'); | 625 | spyOn(scope, '$broadcast'); |
577 | 626 | ||
578 | scope.seleccionarChofer(); | 627 | scope.seleccionarChofer(); |
579 | 628 | ||
580 | //assert | 629 | //assert |
581 | promesa.then(function() { | 630 | promesa.then(function() { |
582 | expect(focaModalService.modal).toHaveBeenCalled(); | 631 | expect(focaModalService.modal).toHaveBeenCalled(); |
583 | expect(scope.$broadcast).toHaveBeenCalled(); | 632 | expect(scope.$broadcast).toHaveBeenCalled(); |
584 | expect(scope.hojaRuta.chofer).toEqual(respuesta); | 633 | expect(scope.hojaRuta.chofer).toEqual(respuesta); |
585 | done(); | 634 | done(); |
586 | }); | 635 | }); |
587 | 636 | ||
588 | }); | 637 | }); |
589 | 638 | ||
590 | it('seleccionarTarifario levanta prompt', function(done) { | 639 | it('seleccionarTarifario levanta prompt', function(done) { |
591 | 640 | ||
592 | //arrange | 641 | //arrange |
593 | var scope = { | 642 | var scope = { |
594 | $broadcast: function() { }, | 643 | $broadcast: function() { }, |
595 | $watch: function() {} | 644 | $watch: function() {} |
596 | }; | 645 | }; |
597 | var focaModalService = { | 646 | var focaModalService = { |
598 | prompt: function() { } | 647 | prompt: function() { } |
599 | }; | 648 | }; |
600 | 649 | ||
601 | $controller('hojaRutaCtrl', { | 650 | $controller('hojaRutaCtrl', { |
602 | $scope: scope, | 651 | $scope: scope, |
603 | $uibModal: {}, | 652 | $uibModal: {}, |
604 | $location: {}, | 653 | $location: {}, |
605 | $filter: $filter, | 654 | $filter: $filter, |
606 | $timeout: $timeout, | 655 | $timeout: $timeout, |
607 | focaCrearHojaRutaService: { | 656 | focaCrearHojaRutaService: { |
608 | getBotonera: function() { }, | 657 | getBotonera: function() { }, |
609 | getNumeroHojaRuta: function() { | 658 | getNumeroHojaRuta: function() { |
610 | return { | 659 | return { |
611 | then: function() { } | 660 | then: function() { } |
612 | }; | 661 | }; |
662 | }, | ||
663 | getParametros: function () { | ||
664 | return { | ||
665 | then: function() { } | ||
666 | }; | ||
613 | } | 667 | } |
614 | }, | 668 | }, |
615 | focaModalService: focaModalService, | 669 | focaModalService: focaModalService, |
616 | focaBotoneraLateralService: {}, | 670 | focaBotoneraLateralService: {}, |
617 | focaLoginService: {}, | 671 | focaLoginService: {}, |
618 | $localStorage: function() {} | 672 | $localStorage: function() {} |
619 | }); | 673 | }); |
620 | 674 | ||
621 | var respuesta = 1; | 675 | var respuesta = 1; |
622 | var promesa = Promise.resolve(respuesta); | 676 | var promesa = Promise.resolve(respuesta); |
623 | 677 | ||
624 | //act | 678 | //act |
625 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); | 679 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); |
626 | spyOn(scope, '$broadcast'); | 680 | spyOn(scope, '$broadcast'); |
627 | 681 | ||
628 | scope.seleccionarTarifario(); | 682 | scope.seleccionarTarifario(); |
629 | 683 | ||
630 | //assert | 684 | //assert |
631 | promesa.then(function() { | 685 | promesa.then(function() { |
632 | expect(focaModalService.prompt).toHaveBeenCalled(); | 686 | expect(focaModalService.prompt).toHaveBeenCalled(); |
633 | expect(scope.$broadcast).toHaveBeenCalled(); | 687 | expect(scope.$broadcast).toHaveBeenCalled(); |
634 | expect(scope.hojaRuta.tarifario.costo).toEqual(respuesta); | 688 | expect(scope.hojaRuta.tarifario).toEqual(respuesta); |
635 | done(); | 689 | done(); |
636 | }); | 690 | }); |
637 | 691 | ||
638 | }); | 692 | }); |
639 | 693 | ||
640 | it('seleccionarRemitos levanta modal y setea datos', function(done) { | 694 | it('seleccionarRemitos levanta modal y setea datos', function(done) { |
641 | 695 | ||
642 | //arrange | 696 | //arrange |
643 | var scope = { | 697 | var scope = { |
644 | $broadcast: function() { }, | 698 | $broadcast: function() { }, |
645 | $watch: function() {} | 699 | $watch: function() {} |
646 | }; | 700 | }; |
647 | var uibModal = { | 701 | var uibModal = { |
648 | open: function() { } | 702 | open: function() { } |
649 | }; | 703 | }; |
650 | 704 | ||
651 | $controller('hojaRutaCtrl', { | 705 | $controller('hojaRutaCtrl', { |
652 | $scope: scope, | 706 | $scope: scope, |
653 | $uibModal: uibModal, | 707 | $uibModal: uibModal, |
654 | $location: {}, | 708 | $location: {}, |
655 | $filter: $filter, | 709 | $filter: $filter, |
656 | $timeout: $timeout, | 710 | $timeout: $timeout, |
657 | focaCrearHojaRutaService: { | 711 | focaCrearHojaRutaService: { |
658 | getBotonera: function() { }, | 712 | getBotonera: function() { }, |
659 | getNumeroHojaRuta: function() { | 713 | getNumeroHojaRuta: function() { |
660 | return { | 714 | return { |
661 | then: function() { } | 715 | then: function() { } |
662 | }; | 716 | }; |
717 | }, | ||
718 | getParametros: function () { | ||
719 | return { | ||
720 | then: function() { } | ||
721 | }; | ||
663 | } | 722 | } |
664 | }, | 723 | }, |
665 | focaModalService: { | 724 | focaModalService: { |
666 | alert: function() {} | 725 | alert: function() {} |
667 | }, | 726 | }, |
668 | focaBotoneraLateralService: {}, | 727 | focaBotoneraLateralService: {}, |
669 | focaLoginService: {}, | 728 | focaLoginService: {}, |
670 | $localStorage: function() {} | 729 | $localStorage: function() {} |
671 | }); | 730 | }); |
672 | scope.eligioPreConfirmado = false; | 731 | scope.eligioPreConfirmado = false; |
673 | scope.hojaRuta = { | 732 | scope.hojaRuta = { |
674 | vehiculo: { | 733 | vehiculo: { |
675 | id: true | 734 | id: true |
676 | }, | 735 | }, |
677 | fechaReparto: true | 736 | fechaReparto: true |
678 | }; | 737 | }; |
679 | 738 | ||
680 | var respuesta = 1; | 739 | var respuesta = 1; |
681 | var promesa = { result: Promise.resolve(respuesta) }; | 740 | var promesa = { result: Promise.resolve(respuesta) }; |
682 | 741 | ||
683 | //act | 742 | //act |
684 | spyOn(uibModal, 'open').and.returnValue(promesa); | 743 | spyOn(uibModal, 'open').and.returnValue(promesa); |
685 | 744 | ||
686 | scope.seleccionarRemitos(); | 745 | scope.seleccionarRemitos(); |
687 | 746 | ||
688 | //assert | 747 | //assert |
689 | promesa.result.then(function() { | 748 | promesa.result.then(function() { |
690 | expect(uibModal.open).toHaveBeenCalled(); | 749 | expect(uibModal.open).toHaveBeenCalled(); |
691 | done(); | 750 | done(); |
692 | }); | 751 | }); |
693 | 752 | ||
694 | }); | 753 | }); |
695 | 754 | ||
696 | it('seleccionarVehiculosPrecargados levanta modal y setea datos', function(done) { | 755 | it('seleccionarVehiculosPrecargados levanta modal y setea datos', function(done) { |
697 | 756 | ||
698 | //arrange | 757 | //arrange |
699 | var scope = { | 758 | var scope = { |
700 | $broadcast: function() { }, | 759 | $broadcast: function() { }, |
701 | $watch: function() {} | 760 | $watch: function() {} |
702 | }; | 761 | }; |
703 | var focaModalService = { | 762 | var focaModalService = { |
704 | modal: function() { }, | 763 | modal: function() { }, |
705 | alert: function() { } | 764 | alert: function() { } |
706 | }; | 765 | }; |
707 | var focaCrearHojaRutaService = { | 766 | var focaCrearHojaRutaService = { |
708 | getBotonera: function() { }, | 767 | getBotonera: function() { }, |
709 | getNumeroHojaRuta: function() { | 768 | getNumeroHojaRuta: function() { |
710 | return { | 769 | return { |
711 | then: function() { } | 770 | then: function() { } |
712 | }; | 771 | }; |
713 | }, | 772 | }, |
714 | getRemitosByIdVehiculo: function() { | 773 | getRemitosByIdVehiculo: function() { |
715 | return { | 774 | return { |
716 | then: function() { } | 775 | then: function() { } |
717 | }; | 776 | }; |
777 | }, | ||
778 | getParametros: function () { | ||
779 | return { | ||
780 | then: function() { } | ||
781 | }; | ||
718 | } | 782 | } |
719 | }; | 783 | }; |
720 | 784 | ||
721 | $controller('hojaRutaCtrl', { | 785 | $controller('hojaRutaCtrl', { |
722 | $scope: scope, | 786 | $scope: scope, |
723 | $uibModal: {}, | 787 | $uibModal: {}, |
724 | $location: {}, | 788 | $location: {}, |
725 | $filter: $filter, | 789 | $filter: $filter, |
726 | $timeout: $timeout, | 790 | $timeout: $timeout, |
727 | focaCrearHojaRutaService: focaCrearHojaRutaService, | 791 | focaCrearHojaRutaService: focaCrearHojaRutaService, |
728 | focaModalService: focaModalService, | 792 | focaModalService: focaModalService, |
729 | focaBotoneraLateralService: {}, | 793 | focaBotoneraLateralService: {}, |
730 | focaLoginService: {}, | 794 | focaLoginService: {}, |
731 | $localStorage: function() {} | 795 | $localStorage: function() {} |
732 | }); | 796 | }); |
733 | scope.eligioPreConfirmado = false; | 797 | scope.eligioPreConfirmado = false; |
734 | scope.hojaRuta = { | 798 | scope.hojaRuta = { |
735 | fechaReparto: new Date() | 799 | fechaReparto: new Date() |
736 | }; | 800 | }; |
737 | 801 | ||
738 | var respuesta = { transportista: { } }; | 802 | var respuesta = { transportista: { } }; |
739 | var promesa = Promise.resolve(respuesta); | 803 | var promesa = Promise.resolve(respuesta); |
740 | 804 | ||
741 | //act | 805 | //act |
742 | spyOn(focaModalService, 'modal') | 806 | spyOn(focaModalService, 'modal') |
743 | .and.returnValue(promesa); | 807 | .and.returnValue(promesa); |
744 | spyOn(focaCrearHojaRutaService, 'getRemitosByIdVehiculo') | 808 | spyOn(focaCrearHojaRutaService, 'getRemitosByIdVehiculo') |
745 | .and.returnValue( { then: function() { } } ); | 809 | .and.returnValue( { then: function() { } } ); |
746 | spyOn(scope, '$broadcast'); | 810 | spyOn(scope, '$broadcast'); |
747 | 811 | ||
748 | scope.seleccionarVehiculosPrecargados(); | 812 | scope.seleccionarVehiculosPrecargados(); |
749 | 813 | ||
750 | //assert | 814 | //assert |
751 | promesa.then(function() { | 815 | promesa.then(function() { |
752 | expect(focaModalService.modal).toHaveBeenCalled(); | 816 | expect(focaModalService.modal).toHaveBeenCalled(); |
753 | expect(focaCrearHojaRutaService.getRemitosByIdVehiculo).toHaveBeenCalled(); | 817 | expect(focaCrearHojaRutaService.getRemitosByIdVehiculo).toHaveBeenCalled(); |
754 | expect(scope.$broadcast).toHaveBeenCalled(); | 818 | expect(scope.$broadcast).toHaveBeenCalled(); |
755 | done(); | 819 | done(); |
756 | }); | 820 | }); |
757 | 821 | ||
758 | }); | 822 | }); |
759 | 823 | ||
760 | it('cargarCisterna levanta modal y devuelve promesa', function(done) { | 824 | it('cargarCisterna levanta modal y devuelve promesa', function(done) { |
761 | 825 | ||
762 | //arrange | 826 | //arrange |
763 | var scope = { | 827 | var scope = { |
764 | $broadcast: function() { }, | 828 | $broadcast: function() { }, |
765 | $watch: function() {} | 829 | $watch: function() {} |
766 | }; | 830 | }; |
767 | var uibModal = { | 831 | var uibModal = { |
768 | open: function() { } | 832 | open: function() { } |
769 | }; | 833 | }; |
770 | 834 | ||
771 | $controller('hojaRutaCtrl', { | 835 | $controller('hojaRutaCtrl', { |
772 | $scope: scope, | 836 | $scope: scope, |
773 | $uibModal: uibModal, | 837 | $uibModal: uibModal, |
774 | $location: {}, | 838 | $location: {}, |
775 | $filter: $filter, | 839 | $filter: $filter, |
776 | $timeout: $timeout, | 840 | $timeout: $timeout, |
777 | focaCrearHojaRutaService: { | 841 | focaCrearHojaRutaService: { |
778 | getBotonera: function() { }, | 842 | getBotonera: function() { }, |
779 | getNumeroHojaRuta: function() { | 843 | getNumeroHojaRuta: function() { |
780 | return { | 844 | return { |
781 | then: function() { } | 845 | then: function() { } |
782 | }; | 846 | }; |
847 | }, | ||
848 | getParametros: function () { | ||
849 | return { | ||
850 | then: function() { } | ||
851 | }; | ||
783 | } | 852 | } |
784 | }, | 853 | }, |
785 | focaModalService: { | 854 | focaModalService: { |
786 | alert: function() {} | 855 | alert: function() {} |
787 | }, | 856 | }, |
788 | focaBotoneraLateralService: {}, | 857 | focaBotoneraLateralService: {}, |
789 | focaLoginService: {}, | 858 | focaLoginService: {}, |
790 | $localStorage: function() {} | 859 | $localStorage: function() {} |
791 | }); | 860 | }); |
792 | scope.eligioPreConfirmado = false; | 861 | scope.eligioPreConfirmado = false; |
793 | scope.hojaRuta = { | 862 | scope.hojaRuta = { |
794 | vehiculo: { | 863 | vehiculo: { |
795 | id: true | 864 | id: true |
796 | }, | 865 | }, |
797 | fechaReparto: true | 866 | fechaReparto: true |
798 | }; | 867 | }; |
799 | 868 | ||
800 | var respuesta = 1; | 869 | var respuesta = 1; |
801 | var promesa = { result: Promise.resolve(respuesta) }; | 870 | var promesa = { result: Promise.resolve(respuesta) }; |
802 | 871 | ||
803 | //act | 872 | //act |
804 | spyOn(uibModal, 'open').and.returnValue(promesa); | 873 | spyOn(uibModal, 'open').and.returnValue(promesa); |
805 | 874 | ||
806 | var resultado = scope.cargarCisterna(); | 875 | var resultado = scope.cargarCisterna(); |
807 | 876 | ||
808 | //assert | 877 | //assert |
809 | promesa.result.then(function() { | 878 | promesa.result.then(function() { |
810 | expect(uibModal.open).toHaveBeenCalled(); | 879 | expect(uibModal.open).toHaveBeenCalled(); |
811 | expect(typeof resultado).toEqual('object'); | 880 | expect(typeof resultado).toEqual('object'); |
812 | done(); | 881 | done(); |
813 | }); | 882 | }); |
814 | 883 | ||
815 | }); | 884 | }); |
816 | 885 | ||
817 | it('seleccionarFechaEntrega levanta modal', function(done) { | 886 | it('seleccionarFechaEntrega levanta modal', function(done) { |
818 | 887 | ||
819 | //arrange | 888 | //arrange |
820 | var scope = { | 889 | var scope = { |
821 | $broadcast: function() { }, | 890 | $broadcast: function() { }, |
822 | $watch: function() {} | 891 | $watch: function() {} |
823 | }; | 892 | }; |
824 | var focaModalService = { | 893 | var focaModalService = { |
825 | modalFecha: function() { } | 894 | modalFecha: function() { }, |
895 | confirm: function() { | ||
896 | return Promise.resolve({}); | ||
897 | } | ||
826 | }; | 898 | }; |
827 | 899 | ||
828 | $controller('hojaRutaCtrl', { | 900 | $controller('hojaRutaCtrl', { |
829 | $scope: scope, | 901 | $scope: scope, |
830 | $uibModal: {}, | 902 | $uibModal: {}, |
831 | $location: {}, | 903 | $location: {}, |
832 | $filter: $filter, | 904 | $filter: $filter, |
833 | $timeout: $timeout, | 905 | $timeout: $timeout, |
834 | focaCrearHojaRutaService: { | 906 | focaCrearHojaRutaService: { |
835 | getBotonera: function() { }, | 907 | getBotonera: function() { }, |
836 | getNumeroHojaRuta: function() { | 908 | getNumeroHojaRuta: function() { |
837 | return { | 909 | return { |
838 | then: function() { } | 910 | then: function() { } |
839 | }; | 911 | }; |
912 | }, | ||
913 | getParametros: function () { | ||
914 | return { | ||
915 | then: function() { } | ||
916 | }; | ||
840 | } | 917 | } |
841 | }, | 918 | }, |
842 | focaModalService: focaModalService, | 919 | focaModalService: focaModalService, |
843 | focaBotoneraLateralService: {}, | 920 | focaBotoneraLateralService: {}, |
844 | focaLoginService: {}, | 921 | focaLoginService: {}, |
845 | $localStorage: function() {} | 922 | $localStorage: function() {} |
846 | }); | 923 | }); |
847 | 924 | ||
848 | var respuesta = new Date(); | 925 | var respuesta = new Date(); |
849 | var promesa = Promise.resolve(respuesta); | 926 | var promesa = Promise.resolve(respuesta); |
850 | 927 | ||
851 | //act | 928 | //act |
852 | spyOn(focaModalService, 'modalFecha').and.returnValue(promesa); | 929 | spyOn(focaModalService, 'modalFecha').and.returnValue(promesa); |
853 | spyOn(scope, '$broadcast'); | 930 | spyOn(scope, '$broadcast'); |
854 | 931 | ||
855 | scope.seleccionarFechaEntrega(); | 932 | scope.seleccionarFechaEntrega(); |
856 | 933 | ||
857 | //assert | 934 | //assert |
858 | promesa.then(function() { | 935 | promesa.then(function() { |
859 | expect(focaModalService.modalFecha).toHaveBeenCalled(); | 936 | setTimeout(function() { |
860 | expect(scope.$broadcast).toHaveBeenCalled(); | 937 | |
861 | done(); | 938 | expect(focaModalService.modalFecha).toHaveBeenCalled(); |
939 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
940 | done(); | ||
941 | }); | ||
862 | }); | 942 | }); |
863 | 943 | ||
864 | }); | 944 | }); |
865 | 945 | ||
866 | }); | 946 | }); |
867 | 947 | ||
868 | }); | 948 | }); |
src/js/controller.js
1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', | 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'focaCrearHojaRutaService', | 8 | 'focaCrearHojaRutaService', |
9 | 'focaModalService', | 9 | 'focaModalService', |
10 | 'focaBotoneraLateralService', | 10 | 'focaBotoneraLateralService', |
11 | 'focaLoginService', | 11 | 'focaLoginService', |
12 | '$localStorage', | 12 | '$localStorage', |
13 | function($scope, $uibModal, $location, $filter, $timeout, | 13 | function($scope, $uibModal, $location, $filter, $timeout, |
14 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, | 14 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, |
15 | focaLoginSrv, $localStorage) | 15 | focaLoginSrv, $localStorage) |
16 | { | 16 | { |
17 | config(); | 17 | config(); |
18 | 18 | ||
19 | function config() { | 19 | function config() { |
20 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); | 20 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); |
21 | $scope.datepickerAbierto = false; | 21 | $scope.datepickerAbierto = false; |
22 | $scope.show = false; | 22 | $scope.show = false; |
23 | $scope.cargando = true; | 23 | $scope.cargando = true; |
24 | $scope.now = new Date(); | 24 | $scope.now = new Date(); |
25 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 25 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
26 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 26 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
27 | 27 | ||
28 | //SETEO BOTONERA LATERAL | 28 | //SETEO BOTONERA LATERAL |
29 | $timeout(function() { | 29 | $timeout(function() { |
30 | focaBotoneraLateralService.showSalir(false); | 30 | focaBotoneraLateralService.showSalir(false); |
31 | focaBotoneraLateralService.showPausar(true); | 31 | focaBotoneraLateralService.showPausar(true); |
32 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); | 32 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); |
33 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 33 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
34 | }); | 34 | }); |
35 | 35 | ||
36 | focaCrearHojaRutaService.getParametros().then(function(res) { | 36 | focaCrearHojaRutaService.getParametros().then(function(res) { |
37 | 37 | ||
38 | var parametros = JSON.parse(res.data[0].jsonText); | 38 | var parametros = JSON.parse(res.data[0].jsonText); |
39 | 39 | ||
40 | if ($localStorage.hojaRuta) { | 40 | if ($localStorage.hojaRuta) { |
41 | $timeout(function() {getLSHojaRuta();}); | 41 | $timeout(function() {getLSHojaRuta();}); |
42 | } else { | 42 | } else { |
43 | 43 | ||
44 | for(var property in parametros) { | 44 | for(var property in parametros) { |
45 | $scope.hojaRuta[property] = parametros[property]; | 45 | $scope.hojaRuta[property] = parametros[property]; |
46 | $scope.inicial[property] = parametros[property]; | ||
46 | } | 47 | } |
47 | 48 | ||
48 | setearHojaRuta($scope.hojaRuta); | 49 | setearHojaRuta($scope.hojaRuta); |
49 | } | 50 | } |
50 | }); | 51 | }); |
51 | init(); | 52 | init(); |
52 | } | 53 | } |
53 | 54 | ||
54 | function init() { | 55 | function init() { |
55 | $scope.$broadcast('cleanCabecera'); | 56 | $scope.$broadcast('cleanCabecera'); |
56 | 57 | ||
57 | $scope.hojaRuta = { | 58 | $scope.hojaRuta = { |
58 | fecha: new Date(), | 59 | fecha: new Date(), |
59 | litros: 0, | 60 | litros: 0, |
60 | chofer: {}, | 61 | chofer: {}, |
61 | vehiculo: { | 62 | vehiculo: { |
62 | capacidad: 0 | 63 | capacidad: 0 |
63 | }, | 64 | }, |
64 | transportista: {}, | 65 | transportista: {}, |
65 | remitosTabla: [] | 66 | remitosTabla: [] |
66 | }; | 67 | }; |
67 | $scope.idLista = undefined; | 68 | $scope.idLista = undefined; |
68 | 69 | ||
69 | focaCrearHojaRutaService.getNumeroHojaRuta().then( | 70 | focaCrearHojaRutaService.getNumeroHojaRuta().then( |
70 | function(res) { | 71 | function(res) { |
71 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); | 72 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); |
72 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); | 73 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); |
73 | }, | 74 | }, |
74 | function(err) { | 75 | function(err) { |
75 | focaModalService.alert('La terminal no esta configurada correctamente'); | 76 | focaModalService.alert('La terminal no esta configurada correctamente'); |
76 | console.info(err); | 77 | console.info(err); |
77 | } | 78 | } |
78 | ); | 79 | ); |
79 | setearFecha(new Date()); | 80 | setearFecha(new Date()); |
80 | $scope.inicial = angular.copy($scope.hojaRuta); | 81 | $scope.inicial = angular.copy($scope.hojaRuta); |
81 | } | 82 | } |
82 | 83 | ||
83 | $scope.$watch('hojaRuta', function(newValue) { | 84 | $scope.$watch('hojaRuta', function(newValue) { |
84 | 85 | ||
85 | // Seteo checked en remitos | 86 | // Seteo checked en remitos |
86 | if ($scope.hojaRuta.remitosTabla.length) { | 87 | if ($scope.hojaRuta.remitosTabla.length) { |
87 | 88 | ||
88 | $filter('filter')($scope.botonera, { | 89 | $filter('filter')($scope.botonera, { |
89 | label: 'Remitos', | 90 | label: 'Remitos', |
90 | })[0].checked = true; | 91 | })[0].checked = true; |
91 | } else { | 92 | } else { |
92 | $filter('filter')($scope.botonera, { | 93 | $filter('filter')($scope.botonera, { |
93 | label: 'Remitos', | 94 | label: 'Remitos', |
94 | })[0].checked = false; | 95 | })[0].checked = false; |
95 | } | 96 | } |
96 | 97 | ||
97 | focaBotoneraLateralService.setPausarData({ | 98 | focaBotoneraLateralService.setPausarData({ |
98 | label: 'hojaRuta', | 99 | label: 'hojaRuta', |
99 | val: newValue | 100 | val: newValue |
100 | }); | 101 | }); |
101 | }, true); | 102 | }, true); |
102 | 103 | ||
103 | $scope.crearHojaRuta = function() { | 104 | $scope.crearHojaRuta = function() { |
104 | if (!$scope.hojaRuta.remitosTabla.length) { | 105 | if (!$scope.hojaRuta.remitosTabla.length) { |
105 | focaModalService.alert('Ingrese Remitos'); | 106 | focaModalService.alert('Ingrese Remitos'); |
106 | return; | 107 | return; |
107 | } | 108 | } |
108 | if (!$scope.hojaRuta.chofer.id) { | 109 | if (!$scope.hojaRuta.chofer.id) { |
109 | focaModalService.alert('Ingrese Chofer'); | 110 | focaModalService.alert('Ingrese Chofer'); |
110 | return; | 111 | return; |
111 | } | 112 | } |
112 | if (!$scope.hojaRuta.vehiculo.id) { | 113 | if (!$scope.hojaRuta.vehiculo.id) { |
113 | focaModalService.alert('Ingrese Vehiculo'); | 114 | focaModalService.alert('Ingrese Vehiculo'); |
114 | return; | 115 | return; |
115 | } | 116 | } |
116 | if (!$scope.hojaRuta.transportista.COD) { | 117 | if (!$scope.hojaRuta.transportista.COD) { |
117 | focaModalService.alert('Ingrese Transportista'); | 118 | focaModalService.alert('Ingrese Transportista'); |
118 | return; | 119 | return; |
119 | } | 120 | } |
120 | if (!$scope.hojaRuta.tarifario) { | 121 | if (!$scope.hojaRuta.tarifario) { |
121 | focaModalService.alert('Ingrese Tarifario'); | 122 | focaModalService.alert('Ingrese Tarifario'); |
122 | return; | 123 | return; |
123 | } | 124 | } |
124 | if (!$scope.hojaRuta.datosExtra) { | 125 | if (!$scope.hojaRuta.datosExtra) { |
125 | focaModalService.alert('Ingrese Datos extra'); | 126 | focaModalService.alert('Ingrese Datos extra'); |
126 | return; | 127 | return; |
127 | } | 128 | } |
128 | var date = new Date(); | 129 | var date = new Date(); |
129 | var save = { | 130 | var save = { |
130 | hojaRuta: { | 131 | hojaRuta: { |
131 | id: 0, | 132 | id: 0, |
132 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) | 133 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) |
133 | .replace('T', ' '), | 134 | .replace('T', ' '), |
134 | idTransportista: $scope.hojaRuta.transportista.COD, | 135 | idTransportista: $scope.hojaRuta.transportista.COD, |
135 | idChofer: $scope.hojaRuta.chofer.id, | 136 | idChofer: $scope.hojaRuta.chofer.id, |
136 | idVehiculo: $scope.hojaRuta.vehiculo.id, | 137 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
137 | tarifaFlete: $scope.hojaRuta.tarifario, | 138 | tarifaFlete: $scope.hojaRuta.tarifario, |
138 | fechaReparto: | 139 | fechaReparto: |
139 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), | 140 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), |
140 | estado: 0 | 141 | estado: 0 |
141 | }, | 142 | }, |
142 | remitos: $scope.hojaRuta.remitosTabla | 143 | remitos: $scope.hojaRuta.remitosTabla |
143 | }; | 144 | }; |
144 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); | 145 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); |
145 | focaCrearHojaRutaService.crearHojaRuta(save).then( | 146 | focaCrearHojaRutaService.crearHojaRuta(save).then( |
146 | function(data) { | 147 | function(data) { |
147 | focaModalService.alert( | 148 | focaModalService.alert( |
148 | 'Hoja ruta creada Nº: ' + | 149 | 'Hoja ruta creada Nº: ' + |
149 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + | 150 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + |
150 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) | 151 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) |
151 | ); | 152 | ); |
152 | 153 | ||
153 | config(); | 154 | config(); |
154 | }, | 155 | }, |
155 | function(error) { | 156 | function(error) { |
156 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); | 157 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); |
157 | console.info(error); | 158 | console.info(error); |
158 | } | 159 | } |
159 | ); | 160 | ); |
160 | }; | 161 | }; |
161 | 162 | ||
162 | $scope.seleccionarTransportista = function() { | 163 | $scope.seleccionarTransportista = function() { |
163 | if (eligioPreConfirmado()) return; | 164 | if (eligioPreConfirmado()) return; |
164 | var parametrosModal = { | 165 | var parametrosModal = { |
165 | titulo: 'Búsqueda de transportista', | 166 | titulo: 'Búsqueda de transportista', |
166 | query: '/transportista', | 167 | query: '/transportista', |
167 | columnas: [ | 168 | columnas: [ |
168 | { | 169 | { |
169 | nombre: 'Código', | 170 | nombre: 'Código', |
170 | propiedad: 'COD' | 171 | propiedad: 'COD' |
171 | }, | 172 | }, |
172 | { | 173 | { |
173 | nombre: 'Nombre', | 174 | nombre: 'Nombre', |
174 | propiedad: 'NOM' | 175 | propiedad: 'NOM' |
175 | }, | 176 | }, |
176 | { | 177 | { |
177 | nombre: 'CUIT', | 178 | nombre: 'CUIT', |
178 | propiedad: 'CUIT' | 179 | propiedad: 'CUIT' |
179 | } | 180 | } |
180 | ] | 181 | ] |
181 | }; | 182 | }; |
182 | focaModalService.modal(parametrosModal).then( | 183 | focaModalService.modal(parametrosModal).then( |
183 | function(proveedor) { | 184 | function(proveedor) { |
184 | $scope.hojaRuta.transportista = proveedor; | 185 | $scope.hojaRuta.transportista = proveedor; |
185 | $scope.$broadcast('addCabecera', { | 186 | $scope.$broadcast('addCabecera', { |
186 | label: 'Transportista:', | 187 | label: 'Transportista:', |
187 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 188 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
188 | proveedor.NOM | 189 | proveedor.NOM |
189 | }); | 190 | }); |
190 | 191 | ||
191 | $filter('filter')($scope.botonera, { | 192 | $filter('filter')($scope.botonera, { |
192 | label: 'Transportista', | 193 | label: 'Transportista', |
193 | })[0].checked = true; | 194 | })[0].checked = true; |
194 | }, function() { | 195 | }, function() { |
195 | 196 | ||
196 | } | 197 | } |
197 | ); | 198 | ); |
198 | }; | 199 | }; |
199 | 200 | ||
200 | $scope.seleccionarChofer = function() { | 201 | $scope.seleccionarChofer = function() { |
201 | var parametrosModal = { | 202 | var parametrosModal = { |
202 | titulo: 'Búsqueda de Chofer', | 203 | titulo: 'Búsqueda de Chofer', |
203 | query: '/chofer', | 204 | query: '/chofer', |
204 | columnas: [ | 205 | columnas: [ |
205 | { | 206 | { |
206 | propiedad: 'id', | 207 | propiedad: 'id', |
207 | nombre: 'Código', | 208 | nombre: 'Código', |
208 | filtro: { | 209 | filtro: { |
209 | nombre: 'rellenarDigitos', | 210 | nombre: 'rellenarDigitos', |
210 | parametro: 3 | 211 | parametro: 3 |
211 | } | 212 | } |
212 | }, | 213 | }, |
213 | { | 214 | { |
214 | propiedad: 'nombre', | 215 | propiedad: 'nombre', |
215 | nombre: 'Nombre' | 216 | nombre: 'Nombre' |
216 | }, | 217 | }, |
217 | { | 218 | { |
218 | propiedad: 'dni', | 219 | propiedad: 'dni', |
219 | nombre: 'DNI' | 220 | nombre: 'DNI' |
220 | }, | 221 | }, |
221 | { | 222 | { |
222 | propiedad: 'telefono', | 223 | propiedad: 'telefono', |
223 | nombre: 'Teléfono' | 224 | nombre: 'Teléfono' |
224 | } | 225 | } |
225 | ] | 226 | ] |
226 | }; | 227 | }; |
227 | focaModalService.modal(parametrosModal).then( | 228 | focaModalService.modal(parametrosModal).then( |
228 | function(chofer) { | 229 | function(chofer) { |
229 | $scope.hojaRuta.chofer = chofer; | 230 | $scope.hojaRuta.chofer = chofer; |
230 | $scope.$broadcast('addCabecera', { | 231 | $scope.$broadcast('addCabecera', { |
231 | label: 'Chofer:', | 232 | label: 'Chofer:', |
232 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre | 233 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre |
233 | }); | 234 | }); |
234 | 235 | ||
235 | $filter('filter')($scope.botonera, { | 236 | $filter('filter')($scope.botonera, { |
236 | label: 'Chofer', | 237 | label: 'Chofer', |
237 | })[0].checked = true; | 238 | })[0].checked = true; |
238 | }, function() { | 239 | }, function() { |
239 | // funcion ejecutada cuando se cancela el modal | 240 | // funcion ejecutada cuando se cancela el modal |
240 | } | 241 | } |
241 | ); | 242 | ); |
242 | }; | 243 | }; |
243 | 244 | ||
244 | $scope.seleccionarVehiculo = function() { | 245 | $scope.seleccionarVehiculo = function() { |
245 | if (!eligioFecha() || eligioPreConfirmado()) return; | 246 | if (!eligioFecha() || eligioPreConfirmado()) return; |
246 | modalVehiculos(); | 247 | modalVehiculos(); |
247 | }; | 248 | }; |
248 | 249 | ||
249 | $scope.seleccionarTarifario = function() { | 250 | $scope.seleccionarTarifario = function() { |
250 | focaModalService | 251 | focaModalService |
251 | .prompt({ | 252 | .prompt({ |
252 | titulo: 'Tarifa flete', | 253 | titulo: 'Tarifa flete', |
253 | value: $scope.hojaRuta.tarifario | 254 | value: $scope.hojaRuta.tarifario |
254 | }) | 255 | }) |
255 | .then(function(costo) { | 256 | .then(function(costo) { |
256 | if (isNaN(costo)) { | 257 | if (isNaN(costo)) { |
257 | focaModalService | 258 | focaModalService |
258 | .alert('Ingrese un valor válido') | 259 | .alert('Ingrese un valor válido') |
259 | .then(function() { | 260 | .then(function() { |
260 | $scope.seleccionarTarifario(); | 261 | $scope.seleccionarTarifario(); |
261 | }); | 262 | }); |
262 | 263 | ||
263 | return; | 264 | return; |
264 | } | 265 | } |
265 | 266 | ||
266 | $scope.hojaRuta.tarifario = costo; | 267 | $scope.hojaRuta.tarifario = costo; |
267 | $scope.$broadcast('addCabecera', { | 268 | $scope.$broadcast('addCabecera', { |
268 | label: 'Tarifario:', | 269 | label: 'Tarifario:', |
269 | valor: costo | 270 | valor: costo |
270 | }); | 271 | }); |
271 | 272 | ||
272 | $filter('filter')($scope.botonera, { | 273 | $filter('filter')($scope.botonera, { |
273 | label: 'Tarifario', | 274 | label: 'Tarifario', |
274 | })[0].checked = true; | 275 | })[0].checked = true; |
275 | }); | 276 | }); |
276 | }; | 277 | }; |
277 | 278 | ||
278 | $scope.seleccionarRemitos = function() { | 279 | $scope.seleccionarRemitos = function() { |
279 | if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; | 280 | if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; |
280 | var modalInstance = $uibModal.open( | 281 | var modalInstance = $uibModal.open( |
281 | { | 282 | { |
282 | ariaLabelledBy: 'Busqueda de Remito', | 283 | ariaLabelledBy: 'Busqueda de Remito', |
283 | templateUrl: 'foca-modal-remito.html', | 284 | templateUrl: 'foca-modal-remito.html', |
284 | controller: 'focaModalRemitoController', | 285 | controller: 'focaModalRemitoController', |
285 | size: 'lg', | 286 | size: 'lg', |
286 | resolve: {usadoPor: function() {return 'hojaRuta';}} | 287 | resolve: {usadoPor: function() {return 'hojaRuta';}} |
287 | } | 288 | } |
288 | ); | 289 | ); |
289 | modalInstance.result.then( | 290 | modalInstance.result.then( |
290 | function(remito) { | 291 | function(remito) { |
291 | // TODO: borrar cuando no se use definitivamente | 292 | // TODO: borrar cuando no se use definitivamente |
292 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { | 293 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { |
293 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { | 294 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { |
294 | // focaModalService.alert('Remito ya incluido'); | 295 | // focaModalService.alert('Remito ya incluido'); |
295 | // return; | 296 | // return; |
296 | // } | 297 | // } |
297 | // } | 298 | // } |
298 | 299 | ||
299 | // var litros = 0; | 300 | // var litros = 0; |
300 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 301 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
301 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 302 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
302 | // } | 303 | // } |
303 | 304 | ||
304 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 305 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
305 | // focaModalService.alert( | 306 | // focaModalService.alert( |
306 | // 'Debe ingresar toda la información para el transporte' | 307 | // 'Debe ingresar toda la información para el transporte' |
307 | // ); | 308 | // ); |
308 | // return; | 309 | // return; |
309 | // } | 310 | // } |
310 | 311 | ||
311 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 312 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
312 | // { | 313 | // { |
313 | // var litrostotales = litros; | 314 | // var litrostotales = litros; |
314 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 315 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
315 | // focaModalService.alert( | 316 | // focaModalService.alert( |
316 | // 'La carga excede la capacidad disponible del vehiculo. ' + | 317 | // 'La carga excede la capacidad disponible del vehiculo. ' + |
317 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 318 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
318 | // ); | 319 | // ); |
319 | // } | 320 | // } |
320 | 321 | ||
321 | // remito.litros = litros; | 322 | // remito.litros = litros; |
322 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 323 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
323 | $scope.cargarCisterna(remito.id).then(function() { | 324 | $scope.cargarCisterna(remito.id).then(function() { |
324 | $scope.hojaRuta.remitosTabla.push(remito); | 325 | $scope.hojaRuta.remitosTabla.push(remito); |
325 | }, function(error) { | 326 | }, function(error) { |
326 | 327 | ||
327 | if (error && error !== 'backdrop click') { | 328 | if (error && error !== 'backdrop click') { |
328 | 329 | ||
329 | focaModalService | 330 | focaModalService |
330 | .alert(error || 'Ha ocurrido un error') | 331 | .alert(error || 'Ha ocurrido un error') |
331 | .then(function() { | 332 | .then(function() { |
332 | $scope.seleccionarRemitos(); | 333 | $scope.seleccionarRemitos(); |
333 | }); | 334 | }); |
334 | 335 | ||
335 | } else { | 336 | } else { |
336 | 337 | ||
337 | $scope.seleccionarRemitos(); | 338 | $scope.seleccionarRemitos(); |
338 | 339 | ||
339 | } | 340 | } |
340 | }); | 341 | }); |
341 | }, function() { | 342 | }, function() { |
342 | // funcion ejecutada cuando se cancela el modal | 343 | // funcion ejecutada cuando se cancela el modal |
343 | } | 344 | } |
344 | ); | 345 | ); |
345 | }; | 346 | }; |
346 | 347 | ||
347 | $scope.seleccionarVehiculosPrecargados = function() { | 348 | $scope.seleccionarVehiculosPrecargados = function() { |
348 | if (!eligioFecha()) return; | 349 | if (!eligioFecha()) return; |
349 | modalVehiculos(true); | 350 | modalVehiculos(true); |
350 | }; | 351 | }; |
351 | 352 | ||
352 | $scope.cargarCisterna = function(idRemito) { | 353 | $scope.cargarCisterna = function(idRemito) { |
353 | if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; | 354 | if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; |
354 | var modalInstance = $uibModal.open( | 355 | var modalInstance = $uibModal.open( |
355 | { | 356 | { |
356 | ariaLabelledBy: 'Busqueda de Vehiculo', | 357 | ariaLabelledBy: 'Busqueda de Vehiculo', |
357 | templateUrl: 'foca-detalle-vehiculo.html', | 358 | templateUrl: 'foca-detalle-vehiculo.html', |
358 | controller: 'focaDetalleVehiculo', | 359 | controller: 'focaDetalleVehiculo', |
359 | size: 'lg', | 360 | size: 'lg', |
360 | resolve: { | 361 | resolve: { |
361 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, | 362 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
362 | idRemito: function() {return idRemito;}, | 363 | idRemito: function() {return idRemito;}, |
363 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} | 364 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} |
364 | } | 365 | } |
365 | } | 366 | } |
366 | ); | 367 | ); |
367 | return modalInstance.result; | 368 | return modalInstance.result; |
368 | }; | 369 | }; |
369 | 370 | ||
370 | $scope.seleccionarFechaEntrega = function() { | 371 | $scope.seleccionarFechaEntrega = function() { |
371 | var confirmacion = false; | 372 | var confirmacion = false; |
372 | var hasVehiculoId = $scope.hojaRuta.vehiculo.id !== undefined; | 373 | var hasVehiculoId = $scope.hojaRuta.vehiculo.id !== undefined; |
373 | var hasTarifario = $scope.hojaRuta.tarifario.costo !== null; | 374 | var hasTarifario = $scope.hojaRuta.tarifario !== null; |
374 | var hasTransportista = Object.keys($scope.hojaRuta.transportista).length > 0; | 375 | var hasTransportista = Object.keys($scope.hojaRuta.transportista).length > 0; |
375 | var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0; | 376 | var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0; |
376 | var hasDatosExtra = $scope.hojaRuta.datosExtra !== undefined; | 377 | var hasDatosExtra = $scope.hojaRuta.datosExtra !== undefined; |
377 | 378 | ||
378 | if (hasVehiculoId || hasTarifario || hasTransportista || | 379 | if (hasVehiculoId || hasTarifario || hasTransportista || |
379 | hasChofer || hasDatosExtra) { | 380 | hasChofer || hasDatosExtra) { |
380 | confirmacion = true; | 381 | confirmacion = true; |
381 | if (confirmacion) { | 382 | if (confirmacion) { |
382 | focaModalService | 383 | focaModalService |
383 | .confirm('Si cambia la fecha se perderán los datos actuales') | 384 | .confirm('Si cambia la fecha se perderán los datos actuales') |
384 | .then(function(data) { | 385 | .then(function(data) { |
385 | if(data) { | 386 | if(data) { |
386 | $scope.hojaRuta.vehiculo.id = undefined; | 387 | $scope.hojaRuta.vehiculo.id = undefined; |
387 | $scope.hojaRuta.tarifario.costo = null; | 388 | $scope.hojaRuta.tarifario = null; |
388 | $scope.hojaRuta.transportista = {}; | 389 | $scope.hojaRuta.transportista = {}; |
389 | $scope.hojaRuta.chofer = {}; | 390 | $scope.hojaRuta.chofer = {}; |
390 | $scope.hojaRuta.datosExtra = undefined; | 391 | $scope.hojaRuta.datosExtra = undefined; |
391 | elegirFecha(); | 392 | elegirFecha(); |
392 | } | 393 | } |
393 | }, function() { | 394 | }, function() { |
394 | return ; | 395 | return ; |
395 | }); | 396 | }); |
396 | } | 397 | } |
397 | } else { | 398 | } else { |
398 | elegirFecha(); | 399 | elegirFecha(); |
399 | } | 400 | } |
400 | } | 401 | }; |
401 | 402 | ||
402 | function setearFecha(fecha) { | 403 | function setearFecha(fecha) { |
403 | $timeout(function() { | 404 | $timeout(function() { |
404 | $scope.$broadcast('addCabecera', { | 405 | $scope.$broadcast('addCabecera', { |
405 | label: 'Fecha de entrega: ', | 406 | label: 'Fecha de entrega: ', |
406 | valor: fecha.toLocaleDateString() | 407 | valor: fecha.toLocaleDateString() |
407 | }); | 408 | }); |
408 | $scope.hojaRuta.fechaReparto = fecha; | 409 | $scope.hojaRuta.fechaReparto = fecha; |
410 | $scope.inicial.fechaReparto = fecha; | ||
409 | }); | 411 | }); |
410 | } | 412 | } |
411 | 413 | ||
412 | $scope.seleccionarDatosExtra = function() { | 414 | $scope.seleccionarDatosExtra = function() { |
413 | var datosHojaRuta = $scope.hojaRuta.datosExtra; | 415 | var datosHojaRuta = $scope.hojaRuta.datosExtra; |
414 | var modalInstance = $uibModal.open( | 416 | var modalInstance = $uibModal.open( |
415 | { | 417 | { |
416 | templateUrl: 'foca-modal-datos-hoja-ruta.html', | 418 | templateUrl: 'foca-modal-datos-hoja-ruta.html', |
417 | controller: 'focaModalDatosHojaRutaCtrl', | 419 | controller: 'focaModalDatosHojaRutaCtrl', |
418 | size: 'lg', | 420 | size: 'lg', |
419 | resolve: { | 421 | resolve: { |
420 | parametrosDatos: function() { | 422 | parametrosDatos: function() { |
421 | return { | 423 | return { |
422 | datosHojaRuta: datosHojaRuta | 424 | datosHojaRuta: datosHojaRuta |
423 | }; | 425 | }; |
424 | } | 426 | } |
425 | } | 427 | } |
426 | } | 428 | } |
427 | ); | 429 | ); |
428 | return modalInstance.result.then(function(datosExtra) { | 430 | return modalInstance.result.then(function(datosExtra) { |
429 | 431 | ||
430 | $filter('filter')($scope.botonera, { | 432 | $filter('filter')($scope.botonera, { |
431 | label: 'Datos extra', | 433 | label: 'Datos extra', |
432 | })[0].checked = true; | 434 | })[0].checked = true; |
433 | 435 | ||
434 | $scope.hojaRuta.datosExtra = datosExtra; | 436 | $scope.hojaRuta.datosExtra = datosExtra; |
435 | }, function() { | 437 | }, function() { |
436 | //se ejecuta cuando se cancela el modal | 438 | //se ejecuta cuando se cancela el modal |
437 | }); | 439 | }); |
438 | }; | 440 | }; |
439 | 441 | ||
440 | $scope.desasociarRemito = function(key, idRemito) { | 442 | $scope.desasociarRemito = function(key, idRemito) { |
441 | var idsRemito = [idRemito]; | 443 | var idsRemito = [idRemito]; |
442 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + | 444 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + |
443 | ' vehículo?').then(function() { | 445 | ' vehículo?').then(function() { |
444 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, | 446 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
445 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) | 447 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) |
446 | .then(function() { | 448 | .then(function() { |
447 | $scope.hojaRuta.remitosTabla.splice(key, 1); | 449 | $scope.hojaRuta.remitosTabla.splice(key, 1); |
448 | focaModalService.alert('Remito desasociado con éxito'); | 450 | focaModalService.alert('Remito desasociado con éxito'); |
449 | }); | 451 | }); |
450 | }); | 452 | }); |
451 | }; | 453 | }; |
452 | 454 | ||
453 | $scope.verProductosRemito = function(idRemito) { | 455 | $scope.verProductosRemito = function(idRemito) { |
454 | var parametrosModal = { | 456 | var parametrosModal = { |
455 | titulo: 'Articulos remito', | 457 | titulo: 'Articulos remito', |
456 | query: '/articulos/remito/' + idRemito, | 458 | query: '/articulos/remito/' + idRemito, |
457 | soloMostrar: true, | 459 | soloMostrar: true, |
458 | columnas: [ | 460 | columnas: [ |
459 | { | 461 | { |
460 | nombre: 'Código', | 462 | nombre: 'Código', |
461 | propiedad: 'codigo' | 463 | propiedad: 'codigo' |
462 | }, | 464 | }, |
463 | { | 465 | { |
464 | nombre: 'Descripción', | 466 | nombre: 'Descripción', |
465 | propiedad: 'descripcion' | 467 | propiedad: 'descripcion' |
466 | }, | 468 | }, |
467 | { | 469 | { |
468 | nombre: 'Cantidad', | 470 | nombre: 'Cantidad', |
469 | propiedad: 'cantidad' | 471 | propiedad: 'cantidad' |
470 | } | 472 | } |
471 | ] | 473 | ] |
472 | }; | 474 | }; |
473 | focaModalService.modal(parametrosModal).then(); | 475 | focaModalService.modal(parametrosModal).then(); |
474 | }; | 476 | }; |
475 | 477 | ||
476 | function elegirFecha() { | 478 | function elegirFecha() { |
477 | var fechaEntrega = { | 479 | var fechaEntrega = { |
478 | titulo: 'Fecha de entrega', | 480 | titulo: 'Fecha de entrega', |
479 | minDate: new Date() | 481 | minDate: new Date() |
480 | }; | 482 | }; |
481 | focaModalService.modalFecha(fechaEntrega).then(function(fecha) { | 483 | focaModalService.modalFecha(fechaEntrega).then(function(fecha) { |
482 | 484 | ||
485 | $scope.hojaRuta.fechaReparto = fecha; | ||
486 | |||
483 | $scope.$broadcast('addCabecera', { | 487 | $scope.$broadcast('addCabecera', { |
484 | label: 'Fecha de entrega: ', | 488 | label: 'Fecha de entrega: ', |
485 | valor: fecha.toLocaleDateString() | 489 | valor: fecha.toLocaleDateString() |
486 | }); | 490 | }); |
487 | 491 | ||
488 | $filter('filter')($scope.botonera, { | 492 | $filter('filter')($scope.botonera, { |
489 | label: 'Fecha Entrega', | 493 | label: 'Fecha Entrega', |
490 | })[0].checked = true; | 494 | })[0].checked = true; |
491 | |||
492 | $scope.hojaRuta.fechaReparto = fecha; | ||
493 | }); | 495 | }); |
494 | } | 496 | } |
495 | 497 | ||
496 | function eligioPreConfirmado() { | 498 | function eligioPreConfirmado() { |
497 | if ($scope.eligioPreConfirmado) { | 499 | if ($scope.eligioPreConfirmado) { |
498 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); | 500 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); |
499 | return true; | 501 | return true; |
500 | } | 502 | } |
501 | return false; | 503 | return false; |
502 | } | 504 | } |
503 | 505 | ||
504 | function eligioFecha() { | 506 | function eligioFecha() { |
505 | if (!$scope.hojaRuta.fechaReparto) { | 507 | if (!$scope.hojaRuta.fechaReparto) { |
506 | focaModalService.alert('Primero seleccione fecha de reparto'); | 508 | focaModalService.alert('Primero seleccione fecha de reparto'); |
507 | return false; | 509 | return false; |
508 | } | 510 | } |
509 | return true; | 511 | return true; |
510 | } | 512 | } |
511 | 513 | ||
512 | function eligioVehiculo() { | 514 | function eligioVehiculo() { |
513 | if (!$scope.hojaRuta.vehiculo.id) { | 515 | if (!$scope.hojaRuta.vehiculo.id) { |
514 | focaModalService.alert('Primero seleccione vehiculo'); | 516 | focaModalService.alert('Primero seleccione vehiculo'); |
515 | return false; | 517 | return false; |
516 | } | 518 | } |
517 | return true; | 519 | return true; |
518 | } | 520 | } |
519 | 521 | ||
520 | function modalVehiculos(preCargados) { | 522 | function modalVehiculos(preCargados) { |
521 | var parametrosModal = {}; | 523 | var parametrosModal = {}; |
522 | if (preCargados) { | 524 | if (preCargados) { |
523 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + | 525 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
524 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); | 526 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); |
525 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; | 527 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; |
526 | } else { | 528 | } else { |
527 | parametrosModal.query = '/vehiculo'; | 529 | parametrosModal.query = '/vehiculo'; |
528 | parametrosModal.titulo = 'Búsqueda de vehículos'; | 530 | parametrosModal.titulo = 'Búsqueda de vehículos'; |
529 | } | 531 | } |
530 | parametrosModal.columnas = [ | 532 | parametrosModal.columnas = [ |
531 | { | 533 | { |
532 | propiedad: 'codigo', | 534 | propiedad: 'codigo', |
533 | nombre: 'Código' | 535 | nombre: 'Código' |
534 | }, | 536 | }, |
535 | { | 537 | { |
536 | propiedad: 'tractor', | 538 | propiedad: 'tractor', |
537 | nombre: 'tractor' | 539 | nombre: 'tractor' |
538 | }, | 540 | }, |
539 | { | 541 | { |
540 | propiedad: 'semi', | 542 | propiedad: 'semi', |
541 | nombre: 'Semi' | 543 | nombre: 'Semi' |
542 | } | 544 | } |
543 | ]; | 545 | ]; |
544 | focaModalService.modal(parametrosModal).then(function(vehiculo) { | 546 | focaModalService.modal(parametrosModal).then(function(vehiculo) { |
545 | if (!preCargados && vehiculoEnUso(vehiculo)) return; | 547 | if (!preCargados && vehiculoEnUso(vehiculo)) return; |
546 | $scope.hojaRuta.vehiculo = vehiculo; | 548 | $scope.hojaRuta.vehiculo = vehiculo; |
547 | $scope.hojaRuta.transportista = vehiculo.transportista; | 549 | $scope.hojaRuta.transportista = vehiculo.transportista; |
548 | if (preCargados) { | 550 | if (preCargados) { |
549 | $scope.eligioPreConfirmado = true; | 551 | $scope.eligioPreConfirmado = true; |
550 | $scope.hojaRuta.vehiculo = vehiculo; | 552 | $scope.hojaRuta.vehiculo = vehiculo; |
551 | $scope.$broadcast('addCabecera', { | 553 | $scope.$broadcast('addCabecera', { |
552 | label: 'Transportista:', | 554 | label: 'Transportista:', |
553 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + | 555 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + |
554 | ' - ' + vehiculo.transportista.NOM | 556 | ' - ' + vehiculo.transportista.NOM |
555 | }); | 557 | }); |
556 | focaCrearHojaRutaService | 558 | focaCrearHojaRutaService |
557 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) | 559 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) |
558 | .then(function(res) { | 560 | .then(function(res) { |
559 | 561 | ||
560 | $filter('filter')($scope.botonera, { | 562 | $filter('filter')($scope.botonera, { |
561 | label: 'Vehiculos precargados', | 563 | label: 'Vehiculos precargados', |
562 | })[0].checked = true; | 564 | })[0].checked = true; |
563 | 565 | ||
564 | $scope.hojaRuta.remitosTabla = res.data; | 566 | $scope.hojaRuta.remitosTabla = res.data; |
565 | }); | 567 | }); |
566 | } else { | 568 | } else { |
567 | focaCrearHojaRutaService | 569 | focaCrearHojaRutaService |
568 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) | 570 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) |
569 | .then(function(res) { | 571 | .then(function(res) { |
570 | 572 | ||
571 | $filter('filter')($scope.botonera, { | 573 | $filter('filter')($scope.botonera, { |
572 | label: 'Vehiculo', | 574 | label: 'Vehiculo', |
573 | })[0].checked = true; | 575 | })[0].checked = true; |
574 | 576 | ||
575 | $scope.hojaRuta.remitosTabla = res.data; | 577 | $scope.hojaRuta.remitosTabla = res.data; |
576 | }); | 578 | }); |
577 | } | 579 | } |
578 | $scope.$broadcast('addCabecera', { | 580 | $scope.$broadcast('addCabecera', { |
579 | label: 'Tractor:', | 581 | label: 'Tractor:', |
580 | valor: vehiculo.tractor | 582 | valor: vehiculo.tractor |
581 | }); | 583 | }); |
582 | $scope.$broadcast('addCabecera', { | 584 | $scope.$broadcast('addCabecera', { |
583 | label: 'Semi:', | 585 | label: 'Semi:', |
584 | valor: vehiculo.semi | 586 | valor: vehiculo.semi |
585 | }); | 587 | }); |
586 | $scope.$broadcast('addCabecera', { | 588 | $scope.$broadcast('addCabecera', { |
587 | label: 'Capacidad:', | 589 | label: 'Capacidad:', |
588 | valor: vehiculo.capacidad | 590 | valor: vehiculo.capacidad |
589 | }); | 591 | }); |
590 | 592 | ||
591 | }); | 593 | }); |
592 | } | 594 | } |
593 | 595 | ||
594 | function vehiculoEnUso(vehiculo) { | 596 | function vehiculoEnUso(vehiculo) { |
595 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; | 597 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; |
596 | for (var i = 0; i < vehiculo.cisternas.length; i++) { | 598 | for (var i = 0; i < vehiculo.cisternas.length; i++) { |
597 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 599 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
598 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 600 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
599 | if (cisternaCarga.fechaReparto.substring(0, 10) === | 601 | if (cisternaCarga.fechaReparto.substring(0, 10) === |
600 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && | 602 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && |
601 | cisternaCarga.idUsuarioProceso && | 603 | cisternaCarga.idUsuarioProceso && |
602 | cisternaCarga.idUsuarioProceso !== idUsuario) | 604 | cisternaCarga.idUsuarioProceso !== idUsuario) |
603 | { | 605 | { |
604 | focaModalService.alert('El vehículo está siendo usado por otro' + | 606 | focaModalService.alert('El vehículo está siendo usado por otro' + |
605 | ' usuario'); | 607 | ' usuario'); |
606 | return true; | 608 | return true; |
607 | } | 609 | } |
608 | } | 610 | } |
609 | } | 611 | } |
610 | return false; | 612 | return false; |
611 | } | 613 | } |
612 | 614 | ||
613 | function salir() { | 615 | function salir() { |
614 | var confirmacion = false; | 616 | var confirmacion = false; |
615 | 617 | ||
616 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { | 618 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { |
617 | confirmacion = true; | 619 | confirmacion = true; |
618 | } | 620 | } |
619 | 621 | ||
620 | if (confirmacion) { | 622 | if (confirmacion) { |
621 | focaModalService.confirm( | 623 | focaModalService.confirm( |
622 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 624 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
623 | ).then(function(data) { | 625 | ).then(function(data) { |
624 | if (data) { | 626 | if (data) { |
625 | $location.path('/'); | 627 | $location.path('/'); |
626 | } | 628 | } |
627 | }); | 629 | }); |
628 | } else { | 630 | } else { |
629 | $location.path('/'); | 631 | $location.path('/'); |
630 | } | 632 | } |
631 | } | 633 | } |
632 | 634 | ||
633 | function setearHojaRuta(hojaRuta) { | 635 | function setearHojaRuta(hojaRuta) { |
634 | $scope.$broadcast('cleanCabecera'); | 636 | $scope.$broadcast('cleanCabecera'); |
635 | 637 | ||
636 | var cabeceras = []; | 638 | var cabeceras = []; |
637 | if (hojaRuta.fechaReparto) { | 639 | if (hojaRuta.fechaReparto) { |
638 | cabeceras.push({ | 640 | cabeceras.push({ |
639 | label: 'Fecha de entrega:', | 641 | label: 'Fecha de entrega:', |
640 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') | 642 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') |
641 | }); | 643 | }); |
642 | 644 | ||
643 | $filter('filter')( $scope.botonera, { | 645 | $filter('filter')( $scope.botonera, { |
644 | label: 'Fecha Entrega' | 646 | label: 'Fecha Entrega' |
645 | })[0].checked = true; | 647 | })[0].checked = true; |
646 | } | 648 | } |
647 | if (hojaRuta.transportista.COD) { | 649 | if (hojaRuta.transportista.COD) { |
648 | cabeceras.push({ | 650 | cabeceras.push({ |
649 | label: 'Transportista:', | 651 | label: 'Transportista:', |
650 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + | 652 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + |
651 | hojaRuta.transportista.NOM | 653 | hojaRuta.transportista.NOM |
652 | }); | 654 | }); |
653 | 655 | ||
654 | $filter('filter')( $scope.botonera, { | 656 | $filter('filter')( $scope.botonera, { |
655 | label: 'Transportista' | 657 | label: 'Transportista' |
656 | })[0].checked = true; | 658 | })[0].checked = true; |
657 | } | 659 | } |
658 | if (hojaRuta.chofer.id) { | 660 | if (hojaRuta.chofer.id) { |
659 | cabeceras.push({ | 661 | cabeceras.push({ |
660 | label: 'Chofer:', | 662 | label: 'Chofer:', |
661 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + | 663 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + |
662 | ' - ' + hojaRuta.chofer.nombre | 664 | ' - ' + hojaRuta.chofer.nombre |
663 | }); | 665 | }); |
664 | 666 | ||
665 | $filter('filter')( $scope.botonera, { | 667 | $filter('filter')( $scope.botonera, { |
666 | label: 'Chofer' | 668 | label: 'Chofer' |
667 | })[0].checked = true; | 669 | })[0].checked = true; |
668 | } | 670 | } |
669 | if (hojaRuta.vehiculo.id) { | 671 | if (hojaRuta.vehiculo.id) { |
670 | cabeceras.push({ | 672 | cabeceras.push({ |
671 | label: 'Tractor:', | 673 | label: 'Tractor:', |
672 | valor: hojaRuta.vehiculo.tractor | 674 | valor: hojaRuta.vehiculo.tractor |
673 | }); | 675 | }); |
674 | cabeceras.push({ | 676 | cabeceras.push({ |
675 | label: 'Semi:', | 677 | label: 'Semi:', |
676 | valor: hojaRuta.vehiculo.semi | 678 | valor: hojaRuta.vehiculo.semi |
677 | }); | 679 | }); |
678 | cabeceras.push({ | 680 | cabeceras.push({ |
679 | label: 'Capacidad:', | 681 | label: 'Capacidad:', |
680 | valor: hojaRuta.vehiculo.capacidad | 682 | valor: hojaRuta.vehiculo.capacidad |
681 | }); | 683 | }); |
682 | 684 | ||
683 | $filter('filter')( $scope.botonera, { | 685 | $filter('filter')( $scope.botonera, { |
684 | label: 'Vehiculo' | 686 | label: 'Vehiculo' |
685 | })[0].checked = true; | 687 | })[0].checked = true; |
686 | } | 688 | } |
687 | if (hojaRuta.tarifario) { | 689 | if (hojaRuta.tarifario) { |
688 | cabeceras.push({ | 690 | cabeceras.push({ |
689 | label: 'Tarifario:', | 691 | label: 'Tarifario:', |
690 | valor: hojaRuta.tarifario | 692 | valor: hojaRuta.tarifario |
691 | }); | 693 | }); |
692 | 694 | ||
693 | $filter('filter')( $scope.botonera, { | 695 | $filter('filter')( $scope.botonera, { |
694 | label: 'Tarifario' | 696 | label: 'Tarifario' |
695 | })[0].checked = true; | 697 | })[0].checked = true; |
696 | } | 698 | } |
697 | 699 | ||
698 | addArrayCabecera(cabeceras); | 700 | addArrayCabecera(cabeceras); |
699 | $scope.hojaRuta = hojaRuta; | 701 | $scope.hojaRuta = hojaRuta; |
700 | } | 702 | } |
701 | 703 | ||
702 | function getLSHojaRuta() { | 704 | function getLSHojaRuta() { |
703 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | 705 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); |
704 | if (hojaRuta) { | 706 | if (hojaRuta) { |
705 | setearHojaRuta(hojaRuta); | 707 | setearHojaRuta(hojaRuta); |
706 | delete $localStorage.hojaRuta; | 708 | delete $localStorage.hojaRuta; |
707 | } | 709 | } |
708 | } | 710 | } |
709 | function addArrayCabecera(array) { | 711 | function addArrayCabecera(array) { |
710 | for(var i = 0; i < array.length; i++) { | 712 | for(var i = 0; i < array.length; i++) { |
711 | $scope.$broadcast('addCabecera', { | 713 | $scope.$broadcast('addCabecera', { |
712 | label: array[i].label, | 714 | label: array[i].label, |
713 | valor: array[i].valor | 715 | valor: array[i].valor |
714 | }); | 716 | }); |
715 | } | 717 | } |
716 | } | 718 | } |
717 | } | 719 | } |