Commit a75d80f78f3e690d47a8218b3663eb68570dbc4d

Authored by Marcelo Puebla
1 parent 12d6f6d4c0
Exists in master

Cambio para que al seleccionar cliente automaticamente me agregue el cobrador que corresponde.

Showing 2 changed files with 54 additions and 203 deletions   Show diff stats
spec/controllerSpec.js
1 describe('controladores módulo crear cobranza', function() { 1 describe('controladores módulo crear cobranza', function() {
2 2
3 var $controller; 3 var $controller;
4 4
5 beforeEach(function() { 5 beforeEach(function() {
6 6
7 module('focaCrearCobranza'); 7 module('focaCrearCobranza');
8 8
9 inject(function(_$controller_) { 9 inject(function(_$controller_) {
10 10
11 $controller = _$controller_; 11 $controller = _$controller_;
12 }); 12 });
13 }); 13 });
14 14
15 describe('Controlador cobranzaController', function() { 15 describe('Controlador cobranzaController', function() {
16 16
17 var $filter = function() { 17 var $filter = function() {
18 return function() { }; 18 return function() { };
19 }; 19 };
20 20
21 var $timeout = function() { }; 21 var $timeout = function() { };
22 22
23 it('existe el controlador cobranzaController', function() { 23 it('existe el controlador cobranzaController', function() {
24 24
25 //act 25 //act
26 var controlador = $controller('cobranzaController', { 26 var controlador = $controller('cobranzaController', {
27 $scope: { 27 $scope: {
28 $broadcast: function() { }, 28 $broadcast: function() { },
29 $watch: function() { } 29 $watch: function() { }
30 }, 30 },
31 $timeout: $timeout, 31 $timeout: $timeout,
32 $uibModal: {}, 32 $uibModal: {},
33 $location: {}, 33 $location: {},
34 focaCrearCobranzaService: { 34 focaCrearCobranzaService: {
35 getCotizacionByIdMoneda: function() { 35 getCotizacionByIdMoneda: function() {
36 return { 36 return {
37 then: function() { } 37 then: function() { }
38 }; 38 };
39 }, 39 },
40 getBotonera: function() { }, 40 getBotonera: function() { },
41 getNumeroRecibo: function() { 41 getNumeroRecibo: function() {
42 return { 42 return {
43 then: function() { } 43 then: function() { }
44 }; 44 };
45 } 45 }
46 }, 46 },
47 focaModalService: {}, 47 focaModalService: {},
48 $filter: $filter, 48 $filter: $filter,
49 focaSeguimientoService: {}, 49 focaSeguimientoService: {},
50 focaBotoneraLateralService: {}, 50 focaBotoneraLateralService: {},
51 APP: {}, 51 APP: {},
52 focaLoginService: {}, 52 focaLoginService: {},
53 $localStorage: true 53 $localStorage: true
54 }); 54 });
55 55
56 //assert 56 //assert
57 expect(typeof controlador).toEqual('object'); 57 expect(typeof controlador).toEqual('object');
58 }); 58 });
59 59
60 it('function crearCobranza muestra alerta cuando no hay cliente', function() { 60 it('function crearCobranza muestra alerta cuando no hay cliente', function() {
61 61
62 //arrange 62 //arrange
63 var scope = { 63 var scope = {
64 $broadcast: function() { }, 64 $broadcast: function() { },
65 $watch: function() { } 65 $watch: function() { }
66 }; 66 };
67 var focaModalService = { 67 var focaModalService = {
68 alert: function() { } 68 alert: function() { }
69 }; 69 };
70 70
71 $controller('cobranzaController', { 71 $controller('cobranzaController', {
72 $scope: scope, 72 $scope: scope,
73 $timeout: $timeout, 73 $timeout: $timeout,
74 $uibModal: {}, 74 $uibModal: {},
75 $location: {}, 75 $location: {},
76 focaCrearCobranzaService: { 76 focaCrearCobranzaService: {
77 getCotizacionByIdMoneda: function() { 77 getCotizacionByIdMoneda: function() {
78 return { 78 return {
79 then: function() { } 79 then: function() { }
80 }; 80 };
81 }, 81 },
82 getBotonera: function() { }, 82 getBotonera: function() { },
83 getNumeroRecibo: function() { 83 getNumeroRecibo: function() {
84 return { 84 return {
85 then: function() { } 85 then: function() { }
86 }; 86 };
87 } 87 }
88 }, 88 },
89 focaModalService: focaModalService, 89 focaModalService: focaModalService,
90 $filter: $filter, 90 $filter: $filter,
91 focaSeguimientoService: {}, 91 focaSeguimientoService: {},
92 focaBotoneraLateralService: {}, 92 focaBotoneraLateralService: {},
93 APP: {}, 93 APP: {},
94 focaLoginService: {}, 94 focaLoginService: {},
95 $localStorage: true 95 $localStorage: true
96 }); 96 });
97 97
98 //act 98 //act
99 spyOn(focaModalService, 'alert'); 99 spyOn(focaModalService, 'alert');
100 scope.crearCobranza(); 100 scope.crearCobranza();
101 101
102 //assert 102 //assert
103 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); 103 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente');
104 }); 104 });
105 105
106 it('function crearCobranza muestra alerta cuando no hay cobrador', function() { 106 it('function crearCobranza muestra alerta cuando no hay cobrador', function() {
107 107
108 //arrange 108 //arrange
109 var scope = { 109 var scope = {
110 $broadcast: function() { }, 110 $broadcast: function() { },
111 $watch: function() { } 111 $watch: function() { }
112 }; 112 };
113 var focaModalService = { 113 var focaModalService = {
114 alert: function() { } 114 alert: function() { }
115 }; 115 };
116 116
117 $controller('cobranzaController', { 117 $controller('cobranzaController', {
118 $scope: scope, 118 $scope: scope,
119 $timeout: $timeout, 119 $timeout: $timeout,
120 $uibModal: {}, 120 $uibModal: {},
121 $location: {}, 121 $location: {},
122 focaCrearCobranzaService: { 122 focaCrearCobranzaService: {
123 getCotizacionByIdMoneda: function() { 123 getCotizacionByIdMoneda: function() {
124 return { 124 return {
125 then: function() { } 125 then: function() { }
126 }; 126 };
127 }, 127 },
128 getBotonera: function() { }, 128 getBotonera: function() { },
129 getNumeroRecibo: function() { 129 getNumeroRecibo: function() {
130 return { 130 return {
131 then: function() { } 131 then: function() { }
132 }; 132 };
133 } 133 }
134 }, 134 },
135 focaModalService: focaModalService, 135 focaModalService: focaModalService,
136 $filter: $filter, 136 $filter: $filter,
137 focaSeguimientoService: {}, 137 focaSeguimientoService: {},
138 focaBotoneraLateralService: {}, 138 focaBotoneraLateralService: {},
139 APP: {}, 139 APP: {},
140 focaLoginService: {}, 140 focaLoginService: {},
141 $localStorage: true 141 $localStorage: true
142 }); 142 });
143 scope.cobranza = { 143 scope.cobranza = {
144 cliente: { 144 cliente: {
145 COD: true 145 COD: true
146 }, 146 },
147 cobrador: {} 147 cobrador: {}
148 }; 148 };
149 149
150 //act 150 //act
151 spyOn(focaModalService, 'alert'); 151 spyOn(focaModalService, 'alert');
152 scope.crearCobranza(); 152 scope.crearCobranza();
153 153
154 //assert 154 //assert
155 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador'); 155 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cobrador');
156 }); 156 });
157 157
158 it('function crearCobranza muestra alerta cuando no hay facturas', function() { 158 it('function crearCobranza muestra alerta cuando no hay facturas', function() {
159 159
160 //arrange 160 //arrange
161 var scope = { 161 var scope = {
162 $broadcast: function() { }, 162 $broadcast: function() { },
163 $watch: function() { } 163 $watch: function() { }
164 }; 164 };
165 var focaModalService = { 165 var focaModalService = {
166 alert: function() { } 166 alert: function() { }
167 }; 167 };
168 168
169 $controller('cobranzaController', { 169 $controller('cobranzaController', {
170 $scope: scope, 170 $scope: scope,
171 $timeout: $timeout, 171 $timeout: $timeout,
172 $uibModal: {}, 172 $uibModal: {},
173 $location: {}, 173 $location: {},
174 focaCrearCobranzaService: { 174 focaCrearCobranzaService: {
175 getCotizacionByIdMoneda: function() { 175 getCotizacionByIdMoneda: function() {
176 return { 176 return {
177 then: function() { } 177 then: function() { }
178 }; 178 };
179 }, 179 },
180 getBotonera: function() { }, 180 getBotonera: function() { },
181 getNumeroRecibo: function() { 181 getNumeroRecibo: function() {
182 return { 182 return {
183 then: function() { } 183 then: function() { }
184 }; 184 };
185 } 185 }
186 }, 186 },
187 focaModalService: focaModalService, 187 focaModalService: focaModalService,
188 $filter: $filter, 188 $filter: $filter,
189 focaSeguimientoService: {}, 189 focaSeguimientoService: {},
190 focaBotoneraLateralService: {}, 190 focaBotoneraLateralService: {},
191 APP: {}, 191 APP: {},
192 focaLoginService: {}, 192 focaLoginService: {},
193 $localStorage: true 193 $localStorage: true
194 }); 194 });
195 scope.cobranza = { 195 scope.cobranza = {
196 cliente: { 196 cliente: {
197 COD: true 197 COD: true
198 }, 198 },
199 cobrador: { 199 cobrador: {
200 NUM: true 200 NUM: true
201 }, 201 },
202 facturas: [] 202 facturas: []
203 }; 203 };
204 204
205 //act 205 //act
206 spyOn(focaModalService, 'alert'); 206 spyOn(focaModalService, 'alert');
207 scope.crearCobranza(); 207 scope.crearCobranza();
208 208
209 //assert 209 //assert
210 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura'); 210 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese al menos una factura');
211 }); 211 });
212 212
213 it('crearCobranza muestra alerta cuando la diferencia no es 0', function() { 213 it('crearCobranza muestra alerta cuando la diferencia no es 0', function() {
214 214
215 //arrange 215 //arrange
216 var scope = { 216 var scope = {
217 $broadcast: function() { }, 217 $broadcast: function() { },
218 $watch: function() { } 218 $watch: function() { }
219 }; 219 };
220 var focaModalService = { 220 var focaModalService = {
221 alert: function() { } 221 alert: function() { }
222 }; 222 };
223 223
224 $controller('cobranzaController', { 224 $controller('cobranzaController', {
225 $scope: scope, 225 $scope: scope,
226 $timeout: $timeout, 226 $timeout: $timeout,
227 $uibModal: {}, 227 $uibModal: {},
228 $location: {}, 228 $location: {},
229 focaCrearCobranzaService: { 229 focaCrearCobranzaService: {
230 getCotizacionByIdMoneda: function() { 230 getCotizacionByIdMoneda: function() {
231 return { 231 return {
232 then: function() { } 232 then: function() { }
233 }; 233 };
234 }, 234 },
235 getBotonera: function() { }, 235 getBotonera: function() { },
236 getNumeroRecibo: function() { 236 getNumeroRecibo: function() {
237 return { 237 return {
238 then: function() { } 238 then: function() { }
239 }; 239 };
240 } 240 }
241 }, 241 },
242 focaModalService: focaModalService, 242 focaModalService: focaModalService,
243 $filter: $filter, 243 $filter: $filter,
244 focaSeguimientoService: {}, 244 focaSeguimientoService: {},
245 focaBotoneraLateralService: {}, 245 focaBotoneraLateralService: {},
246 APP: {}, 246 APP: {},
247 focaLoginService: {}, 247 focaLoginService: {},
248 $localStorage: true 248 $localStorage: true
249 }); 249 });
250 scope.cobranza = { 250 scope.cobranza = {
251 cliente: { 251 cliente: {
252 COD: true 252 COD: true
253 }, 253 },
254 cobrador: { 254 cobrador: {
255 NUM: true 255 NUM: true
256 }, 256 },
257 moneda: { 257 moneda: {
258 SIMBOLO: '' 258 SIMBOLO: ''
259 }, 259 },
260 facturas: [1] 260 facturas: [1]
261 }; 261 };
262 scope.facturaTabla = [1]; 262 scope.facturaTabla = [1];
263 263
264 //act 264 //act
265 spyOn(focaModalService, 'alert'); 265 spyOn(focaModalService, 'alert');
266 spyOn(scope, 'getTotalCobrado').and.returnValue(1); 266 spyOn(scope, 'getTotalCobrado').and.returnValue(1);
267 spyOn(scope, 'getTotalDeuda').and.returnValue(1); 267 spyOn(scope, 'getTotalDeuda').and.returnValue(1);
268 scope.crearCobranza(); 268 scope.crearCobranza();
269 269
270 //assert 270 //assert
271 expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00'); 271 expect(focaModalService.alert).toHaveBeenCalledWith('La diferencia debe ser 0,00');
272 }); 272 });
273 273
274 it('crearCobranza llama a startGuardar y guardarCobranza', function() { 274 it('crearCobranza llama a startGuardar y guardarCobranza', function() {
275 275
276 //arrange 276 //arrange
277 var scope = { 277 var scope = {
278 $broadcast: function() { }, 278 $broadcast: function() { },
279 $watch: function() { } 279 $watch: function() { }
280 }; 280 };
281 var focaBotoneraLateralService = { 281 var focaBotoneraLateralService = {
282 startGuardar: function() { } 282 startGuardar: function() { }
283 }; 283 };
284 var focaCrearCobranzaService = { 284 var focaCrearCobranzaService = {
285 guardarCobranza: function() { }, 285 guardarCobranza: function() { },
286 getCotizacionByIdMoneda: function() { 286 getCotizacionByIdMoneda: function() {
287 return { 287 return {
288 then: function() { } 288 then: function() { }
289 }; 289 };
290 }, 290 },
291 getBotonera: function() { }, 291 getBotonera: function() { },
292 getNumeroRecibo: function() { 292 getNumeroRecibo: function() {
293 return { 293 return {
294 then: function() { } 294 then: function() { }
295 }; 295 };
296 } 296 }
297 }; 297 };
298 298
299 $controller('cobranzaController', { 299 $controller('cobranzaController', {
300 $scope: scope, 300 $scope: scope,
301 $timeout: $timeout, 301 $timeout: $timeout,
302 $uibModal: {}, 302 $uibModal: {},
303 $location: {}, 303 $location: {},
304 focaCrearCobranzaService: focaCrearCobranzaService, 304 focaCrearCobranzaService: focaCrearCobranzaService,
305 focaModalService: { 305 focaModalService: {
306 alert: function() {} 306 alert: function() {}
307 }, 307 },
308 $filter: $filter, 308 $filter: $filter,
309 focaSeguimientoService: {}, 309 focaSeguimientoService: {},
310 focaBotoneraLateralService: focaBotoneraLateralService, 310 focaBotoneraLateralService: focaBotoneraLateralService,
311 APP: {}, 311 APP: {},
312 focaLoginService: {}, 312 focaLoginService: {},
313 $localStorage: true 313 $localStorage: true
314 }); 314 });
315 scope.cobranza = { 315 scope.cobranza = {
316 cliente: { 316 cliente: {
317 COD: true 317 COD: true
318 }, 318 },
319 cobrador: { 319 cobrador: {
320 NUM: true 320 NUM: true
321 }, 321 },
322 moneda: { 322 moneda: {
323 cotizacion: {} 323 cotizacion: {}
324 }, 324 },
325 facturas: [1], 325 facturas: [1],
326 cobros: [{ 326 cobros: [{
327 FEC: new Date(), 327 FEC: new Date(),
328 fechaPresentacion: new Date(), 328 fechaPresentacion: new Date(),
329 fechaEmision: new Date(), 329 fechaEmision: new Date(),
330 tipo: true, 330 tipo: true,
331 banco: { 331 banco: {
332 ID: true 332 ID: true
333 }, 333 },
334 localidad: { 334 localidad: {
335 ID: true, 335 ID: true,
336 NOMBRE: true 336 NOMBRE: true
337 }, 337 },
338 provincia: { 338 provincia: {
339 ID: true 339 ID: true
340 } 340 }
341 }], 341 }],
342 FEC: new Date() 342 FEC: new Date()
343 }; 343 };
344 344
345 //act 345 //act
346 spyOn(focaBotoneraLateralService, 'startGuardar'); 346 spyOn(focaBotoneraLateralService, 'startGuardar');
347 spyOn(focaCrearCobranzaService, 'guardarCobranza') 347 spyOn(focaCrearCobranzaService, 'guardarCobranza')
348 .and.returnValue({ then: function() { } }); 348 .and.returnValue({ then: function() { } });
349 spyOn(scope, 'getTotalCobrado').and.returnValue(0); 349 spyOn(scope, 'getTotalCobrado').and.returnValue(0);
350 spyOn(scope, 'getTotalDeuda').and.returnValue(0); 350 spyOn(scope, 'getTotalDeuda').and.returnValue(0);
351 scope.crearCobranza(); 351 scope.crearCobranza();
352 352
353 //assert 353 //assert
354 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); 354 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled();
355 expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled(); 355 expect(focaCrearCobranzaService.guardarCobranza).toHaveBeenCalled();
356 }); 356 });
357 357
358 it('seleccionarCobros seatea cobroDeuda en false', function() { 358 it('seleccionarCobros seatea cobroDeuda en false', function() {
359 359
360 //arrange 360 //arrange
361 var scope = { 361 var scope = {
362 $broadcast: function() { }, 362 $broadcast: function() { },
363 $watch: function() { } 363 $watch: function() { }
364 }; 364 };
365 365
366 $controller('cobranzaController', { 366 $controller('cobranzaController', {
367 $scope: scope, 367 $scope: scope,
368 $timeout: $timeout, 368 $timeout: $timeout,
369 $uibModal: {}, 369 $uibModal: {},
370 $location: {}, 370 $location: {},
371 focaCrearCobranzaService: { 371 focaCrearCobranzaService: {
372 getCotizacionByIdMoneda: function() { 372 getCotizacionByIdMoneda: function() {
373 return { 373 return {
374 then: function() { } 374 then: function() { }
375 }; 375 };
376 }, 376 },
377 getBotonera: function() { }, 377 getBotonera: function() { },
378 getNumeroRecibo: function() { 378 getNumeroRecibo: function() {
379 return { 379 return {
380 then: function() { } 380 then: function() { }
381 }; 381 };
382 } 382 }
383 }, 383 },
384 focaModalService: {}, 384 focaModalService: {},
385 $filter: $filter, 385 $filter: $filter,
386 focaSeguimientoService: {}, 386 focaSeguimientoService: {},
387 focaBotoneraLateralService: {}, 387 focaBotoneraLateralService: {},
388 APP: {}, 388 APP: {},
389 focaLoginService: {}, 389 focaLoginService: {},
390 $localStorage: true 390 $localStorage: true
391 }); 391 });
392 392
393 //act 393 //act
394 scope.seleccionarCobros(); 394 scope.seleccionarCobros();
395 395
396 //assert 396 //assert
397 expect(scope.cobroDeuda).toEqual(false); 397 expect(scope.cobroDeuda).toEqual(false);
398 }); 398 });
399 399
400 it('seleccionarComprobantes seatea cobroDeuda en true', function() { 400 it('seleccionarComprobantes seatea cobroDeuda en true', function() {
401 401
402 //arrange 402 //arrange
403 var scope = { 403 var scope = {
404 $broadcast: function() { }, 404 $broadcast: function() { },
405 $watch: function() { } 405 $watch: function() { }
406 }; 406 };
407 407
408 $controller('cobranzaController', { 408 $controller('cobranzaController', {
409 $scope: scope, 409 $scope: scope,
410 $timeout: $timeout, 410 $timeout: $timeout,
411 $uibModal: {}, 411 $uibModal: {},
412 $location: {}, 412 $location: {},
413 focaCrearCobranzaService: { 413 focaCrearCobranzaService: {
414 getCotizacionByIdMoneda: function() { 414 getCotizacionByIdMoneda: function() {
415 return { 415 return {
416 then: function() { } 416 then: function() { }
417 }; 417 };
418 }, 418 },
419 getBotonera: function() { }, 419 getBotonera: function() { },
420 getNumeroRecibo: function() { 420 getNumeroRecibo: function() {
421 return { 421 return {
422 then: function() { } 422 then: function() { }
423 }; 423 };
424 } 424 }
425 }, 425 },
426 focaModalService: {}, 426 focaModalService: {},
427 $filter: $filter, 427 $filter: $filter,
428 focaSeguimientoService: {}, 428 focaSeguimientoService: {},
429 focaBotoneraLateralService: {}, 429 focaBotoneraLateralService: {},
430 APP: {}, 430 APP: {},
431 focaLoginService: {}, 431 focaLoginService: {},
432 $localStorage: true 432 $localStorage: true
433 }); 433 });
434 434
435 //act 435 //act
436 scope.seleccionarComprobantes(); 436 scope.seleccionarComprobantes();
437 437
438 //assert 438 //assert
439 expect(scope.cobroDeuda).toEqual(true); 439 expect(scope.cobroDeuda).toEqual(true);
440 }); 440 });
441 441
442 it('seleccionarCobranza levanta modal y setea datos', function(done) {
443
444 //arrange
445 var scope = {
446 $broadcast: function() { },
447 $watch: function() { }
448 };
449 var uibModal = {
450 open: function() { }
451 };
452
453 $controller('cobranzaController', {
454 $scope: scope,
455 $timeout: $timeout,
456 $uibModal: uibModal,
457 $location: {},
458 focaCrearCobranzaService: {
459 getCotizacionByIdMoneda: function() {
460 return {
461 then: function() { }
462 };
463 },
464 getBotonera: function() { },
465 getNumeroRecibo: function() {
466 return {
467 then: function() { }
468 };
469 }
470 },
471 focaModalService: {},
472 $filter: $filter,
473 focaSeguimientoService: {},
474 focaBotoneraLateralService: {},
475 APP: {},
476 focaLoginService: {},
477 $localStorage: true
478 });
479 var respuesta = {
480 facturas: 1,
481 cobros: 2,
482 cliente: { },
483 moneda: {
484 cotizaciones: []
485 }
486 };
487 var promesa = { result: Promise.resolve(respuesta) };
488
489 //act
490 spyOn(uibModal, 'open').and.returnValue(promesa);
491 spyOn(scope, '$broadcast');
492 scope.seleccionarCobranza();
493
494 //assert
495 promesa.result.then(function() {
496 expect(uibModal.open).toHaveBeenCalled();
497 expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera');
498 expect(scope.cobranza.facturas).toEqual(respuesta.facturas);
499 expect(scope.cobranza.cobros).toEqual(respuesta.cobros);
500 done();
501 });
502 });
503
504 it('seleccionarCliente levanta modal y setea datos', function(done) { 442 it('seleccionarCliente levanta modal y setea datos', function(done) {
505 443
506 //arrange 444 //arrange
507 var scope = { 445 var scope = {
508 $broadcast: function() { }, 446 $broadcast: function() { },
509 $watch: function() { } 447 $watch: function() { }
510 }; 448 };
511 var uibModal = { 449 var uibModal = {
512 open: function() { } 450 open: function() { }
513 }; 451 };
514 452
515 $controller('cobranzaController', { 453 $controller('cobranzaController', {
516 $scope: scope, 454 $scope: scope,
517 $timeout: $timeout, 455 $timeout: $timeout,
518 $uibModal: uibModal, 456 $uibModal: uibModal,
519 $location: {}, 457 $location: {},
520 focaCrearCobranzaService: { 458 focaCrearCobranzaService: {
521 getCotizacionByIdMoneda: function() { 459 getCotizacionByIdMoneda: function() {
522 return { 460 return {
523 then: function() { } 461 then: function() { }
524 }; 462 };
525 }, 463 },
526 getBotonera: function() { }, 464 getBotonera: function() { },
527 getNumeroRecibo: function() { 465 getNumeroRecibo: function() {
528 return { 466 return {
529 then: function() { } 467 then: function() { }
530 }; 468 };
531 }, 469 },
532 getCobradorById: function() { 470 getCobradorById: function() {
533 return { 471 return {
534 then: function() { } 472 then: function() { }
535 }; 473 };
536 } 474 }
537 }, 475 },
538 focaModalService: { 476 focaModalService: {
539 modal: function() { 477 modal: function() {
540 return { 478 return {
541 then: function() {} 479 then: function() {}
542 }; 480 };
543 } 481 }
544 }, 482 },
545 $filter: $filter, 483 $filter: $filter,
546 focaSeguimientoService: {}, 484 focaSeguimientoService: {},
547 focaBotoneraLateralService: {}, 485 focaBotoneraLateralService: {},
548 APP: 'cobranza', 486 APP: 'cobranza',
549 focaLoginService: { 487 focaLoginService: {
550 getLoginData: function() { 488 getLoginData: function() {
551 return { 489 return {
552 vendedorCobrador: true 490 vendedorCobrador: true
553 }; 491 };
554 } 492 }
555 }, 493 },
556 $localStorage: true 494 $localStorage: true
557 }); 495 });
558 scope.cobranza = { 496 scope.cobranza = {
559 cobrador: {} 497 cobrador: {}
560 }; 498 };
561 var respuesta = { facturas: 1, cobros: 2, cliente: { } }; 499 var respuesta = { facturas: 1, cobros: 2, cliente: { } };
562 var promesa = { result: Promise.resolve(respuesta) }; 500 var promesa = { result: Promise.resolve(respuesta) };
563 501
564 //act 502 //act
565 spyOn(uibModal, 'open').and.returnValue(promesa); 503 spyOn(uibModal, 'open').and.returnValue(promesa);
566 spyOn(scope, '$broadcast'); 504 spyOn(scope, '$broadcast');
567 scope.seleccionarCliente(); 505 scope.seleccionarCliente();
568 506
569 //assert 507 //assert
570 promesa.result.then(function() { 508 promesa.result.then(function() {
571 expect(uibModal.open).toHaveBeenCalled(); 509 expect(uibModal.open).toHaveBeenCalled();
572 expect(scope.$broadcast).toHaveBeenCalled(); 510 expect(scope.$broadcast).toHaveBeenCalled();
573 done(); 511 done();
574 }); 512 });
575 }); 513 });
576 514
577 it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() { 515 it('seleccionarFactura muestra alerta cuando no se seteo cliente', function() {
578 516
579 //arrange 517 //arrange
580 var scope = { 518 var scope = {
581 $broadcast: function() { }, 519 $broadcast: function() { },
582 $watch: function() { } 520 $watch: function() { }
583 }; 521 };
584 var focaModalService = { 522 var focaModalService = {
585 alert: function() { } 523 alert: function() { }
586 }; 524 };
587 525
588 $controller('cobranzaController', { 526 $controller('cobranzaController', {
589 $scope: scope, 527 $scope: scope,
590 $timeout: $timeout, 528 $timeout: $timeout,
591 $uibModal: { 529 $uibModal: {
592 open: function() { 530 open: function() {
593 return { 531 return {
594 result: { 532 result: {
595 then: function() { } 533 then: function() { }
596 } 534 }
597 }; 535 };
598 } 536 }
599 }, 537 },
600 $location: {}, 538 $location: {},
601 focaCrearCobranzaService: { 539 focaCrearCobranzaService: {
602 getCotizacionByIdMoneda: function() { 540 getCotizacionByIdMoneda: function() {
603 return { 541 return {
604 then: function() { } 542 then: function() { }
605 }; 543 };
606 }, 544 },
607 getBotonera: function() { }, 545 getBotonera: function() { },
608 getNumeroRecibo: function() { 546 getNumeroRecibo: function() {
609 return { 547 return {
610 then: function() { } 548 then: function() { }
611 }; 549 };
612 } 550 }
613 }, 551 },
614 focaModalService: focaModalService, 552 focaModalService: focaModalService,
615 $filter: $filter, 553 $filter: $filter,
616 focaSeguimientoService: {}, 554 focaSeguimientoService: {},
617 focaBotoneraLateralService: {}, 555 focaBotoneraLateralService: {},
618 APP: {}, 556 APP: {},
619 focaLoginService: {}, 557 focaLoginService: {},
620 $localStorage: true 558 $localStorage: true
621 }); 559 });
622 560
623 //act 561 //act
624 spyOn(focaModalService, 'alert'); 562 spyOn(focaModalService, 'alert');
625 scope.seleccionarFactura(); 563 scope.seleccionarFactura();
626 564
627 //assert 565 //assert
628 expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente'); 566 expect(focaModalService.alert).toHaveBeenCalledWith('Seleccione primero un cliente');
629 }); 567 });
630 568
631 it('seleccionarFactura levanta modal', function() { 569 it('seleccionarFactura levanta modal', function() {
632 570
633 //arrange 571 //arrange
634 var scope = { 572 var scope = {
635 $broadcast: function() { }, 573 $broadcast: function() { },
636 $watch: function() { } 574 $watch: function() { }
637 }; 575 };
638 var uibModal = { 576 var uibModal = {
639 open: function() { } 577 open: function() { }
640 }; 578 };
641 579
642 $controller('cobranzaController', { 580 $controller('cobranzaController', {
643 $scope: scope, 581 $scope: scope,
644 $timeout: $timeout, 582 $timeout: $timeout,
645 $uibModal: uibModal, 583 $uibModal: uibModal,
646 $location: {}, 584 $location: {},
647 focaCrearCobranzaService: { 585 focaCrearCobranzaService: {
648 getCotizacionByIdMoneda: function() { 586 getCotizacionByIdMoneda: function() {
649 return { 587 return {
650 then: function() { } 588 then: function() { }
651 }; 589 };
652 }, 590 },
653 getBotonera: function() { }, 591 getBotonera: function() { },
654 getNumeroRecibo: function() { 592 getNumeroRecibo: function() {
655 return { 593 return {
656 then: function() { } 594 then: function() { }
657 }; 595 };
658 } 596 }
659 }, 597 },
660 focaModalService: { 598 focaModalService: {
661 alert: function() {} 599 alert: function() {}
662 }, 600 },
663 $filter: $filter, 601 $filter: $filter,
664 focaSeguimientoService: {}, 602 focaSeguimientoService: {},
665 focaBotoneraLateralService: {}, 603 focaBotoneraLateralService: {},
666 APP: {}, 604 APP: {},
667 focaLoginService: {}, 605 focaLoginService: {},
668 $localStorage: true 606 $localStorage: true
669 }); 607 });
670 scope.cobranza = { 608 scope.cobranza = {
671 cliente: { 609 cliente: {
672 COD: true 610 COD: true
673 } 611 }
674 }; 612 };
675 613
676 var respuesta = { result: { then: function() { } } }; 614 var respuesta = { result: { then: function() { } } };
677 615
678 //act 616 //act
679 spyOn(uibModal, 'open').and.returnValue(respuesta); 617 spyOn(uibModal, 'open').and.returnValue(respuesta);
680 scope.seleccionarFactura(); 618 scope.seleccionarFactura();
681 619
682 //assert 620 //assert
683 expect(uibModal.open).toHaveBeenCalled(); 621 expect(uibModal.open).toHaveBeenCalled();
684 }); 622 });
685 623
686 it('seleccionarCheque levanta modal', function() { 624 it('seleccionarCheque levanta modal', function() {
687 625
688 //arrange 626 //arrange
689 var scope = { 627 var scope = {
690 $broadcast: function() { }, 628 $broadcast: function() { },
691 $watch: function() { } 629 $watch: function() { }
692 }; 630 };
693 var uibModal = { 631 var uibModal = {
694 open: function() { } 632 open: function() { }
695 }; 633 };
696 634
697 $controller('cobranzaController', { 635 $controller('cobranzaController', {
698 $scope: scope, 636 $scope: scope,
699 $timeout: $timeout, 637 $timeout: $timeout,
700 $uibModal: uibModal, 638 $uibModal: uibModal,
701 $location: {}, 639 $location: {},
702 focaCrearCobranzaService: { 640 focaCrearCobranzaService: {
703 getCotizacionByIdMoneda: function() { 641 getCotizacionByIdMoneda: function() {
704 return { 642 return {
705 then: function() { } 643 then: function() { }
706 }; 644 };
707 }, 645 },
708 getBotonera: function() { }, 646 getBotonera: function() { },
709 getNumeroRecibo: function() { 647 getNumeroRecibo: function() {
710 return { 648 return {
711 then: function() { } 649 then: function() { }
712 }; 650 };
713 } 651 }
714 }, 652 },
715 focaModalService: {}, 653 focaModalService: {},
716 $filter: $filter, 654 $filter: $filter,
717 focaSeguimientoService: {}, 655 focaSeguimientoService: {},
718 focaBotoneraLateralService: {}, 656 focaBotoneraLateralService: {},
719 APP: {}, 657 APP: {},
720 focaLoginService: {}, 658 focaLoginService: {},
721 $localStorage: true 659 $localStorage: true
722 }); 660 });
723 scope.cobranza = { 661 scope.cobranza = {
724 cliente: { }, 662 cliente: { },
725 facturas: [], 663 facturas: [],
726 cobros: [] 664 cobros: []
727 }; 665 };
728 666
729 var respuesta = { result: { then: function() { } } }; 667 var respuesta = { result: { then: function() { } } };
730 668
731 //act 669 //act
732 spyOn(uibModal, 'open').and.returnValue(respuesta); 670 spyOn(uibModal, 'open').and.returnValue(respuesta);
733 scope.seleccionarCheque(); 671 scope.seleccionarCheque();
734 672
735 //assert 673 //assert
736 expect(uibModal.open).toHaveBeenCalled(); 674 expect(uibModal.open).toHaveBeenCalled();
737 }); 675 });
738 676
739 it('seleccionarEfectivo levanta modal', function() { 677 it('seleccionarEfectivo levanta modal', function() {
740 678
741 //arrange 679 //arrange
742 var scope = { 680 var scope = {
743 $broadcast: function() { }, 681 $broadcast: function() { },
744 $watch: function() { } 682 $watch: function() { }
745 }; 683 };
746 var uibModal = { 684 var uibModal = {
747 open: function() { } 685 open: function() { }
748 }; 686 };
749 687
750 $controller('cobranzaController', { 688 $controller('cobranzaController', {
751 $scope: scope, 689 $scope: scope,
752 $timeout: $timeout, 690 $timeout: $timeout,
753 $uibModal: uibModal, 691 $uibModal: uibModal,
754 $location: {}, 692 $location: {},
755 focaCrearCobranzaService: { 693 focaCrearCobranzaService: {
756 getCotizacionByIdMoneda: function() { 694 getCotizacionByIdMoneda: function() {
757 return { 695 return {
758 then: function() { } 696 then: function() { }
759 }; 697 };
760 }, 698 },
761 getBotonera: function() { }, 699 getBotonera: function() { },
762 getNumeroRecibo: function() { 700 getNumeroRecibo: function() {
763 return { 701 return {
764 then: function() { } 702 then: function() { }
765 }; 703 };
766 } 704 }
767 }, 705 },
768 focaModalService: {}, 706 focaModalService: {},
769 $filter: $filter, 707 $filter: $filter,
770 focaSeguimientoService: {}, 708 focaSeguimientoService: {},
771 focaBotoneraLateralService: {}, 709 focaBotoneraLateralService: {},
772 APP: {}, 710 APP: {},
773 focaLoginService: {}, 711 focaLoginService: {},
774 $localStorage: true 712 $localStorage: true
775 }); 713 });
776 scope.cobranza = { 714 scope.cobranza = {
777 cliente: { }, 715 cliente: { },
778 cobros: [] 716 cobros: []
779 }; 717 };
780 718
781 var respuesta = { result: { then: function() { } } }; 719 var respuesta = { result: { then: function() { } } };
782 720
783 //act 721 //act
784 spyOn(uibModal, 'open').and.returnValue(respuesta); 722 spyOn(uibModal, 'open').and.returnValue(respuesta);
785 scope.seleccionarEfectivo(); 723 scope.seleccionarEfectivo();
786 724
787 //assert 725 //assert
788 expect(uibModal.open).toHaveBeenCalled(); 726 expect(uibModal.open).toHaveBeenCalled();
789 }); 727 });
790 728
791 it('seleccionarDetalles levanta modal', function() { 729 it('seleccionarDetalles levanta modal', function() {
792 730
793 //arrange 731 //arrange
794 var scope = { 732 var scope = {
795 $broadcast: function() { }, 733 $broadcast: function() { },
796 $watch: function() { } 734 $watch: function() { }
797 }; 735 };
798 var uibModal = { 736 var uibModal = {
799 open: function() { } 737 open: function() { }
800 }; 738 };
801 739
802 $controller('cobranzaController', { 740 $controller('cobranzaController', {
803 $scope: scope, 741 $scope: scope,
804 $timeout: $timeout, 742 $timeout: $timeout,
805 $uibModal: uibModal, 743 $uibModal: uibModal,
806 $location: {}, 744 $location: {},
807 focaCrearCobranzaService: { 745 focaCrearCobranzaService: {
808 getCotizacionByIdMoneda: function() { 746 getCotizacionByIdMoneda: function() {
809 return { 747 return {
810 then: function() { } 748 then: function() { }
811 }; 749 };
812 }, 750 },
813 getBotonera: function() { }, 751 getBotonera: function() { },
814 getNumeroRecibo: function() { 752 getNumeroRecibo: function() {
815 return { 753 return {
816 then: function() { } 754 then: function() { }
817 }; 755 };
818 } 756 }
819 }, 757 },
820 focaModalService: {}, 758 focaModalService: {},
821 $filter: $filter, 759 $filter: $filter,
822 focaSeguimientoService: {}, 760 focaSeguimientoService: {},
823 focaBotoneraLateralService: {}, 761 focaBotoneraLateralService: {},
824 APP: {}, 762 APP: {},
825 focaLoginService: {}, 763 focaLoginService: {},
826 $localStorage: true 764 $localStorage: true
827 }); 765 });
828 scope.cobranza = { 766 scope.cobranza = {
829 cliente: { }, 767 cliente: { },
830 facturas: [], 768 facturas: [],
831 cobros: [] 769 cobros: []
832 }; 770 };
833 771
834 var respuesta = { result: { then: function() { } } }; 772 var respuesta = { result: { then: function() { } } };
835 773
836 //act 774 //act
837 spyOn(uibModal, 'open').and.returnValue(respuesta); 775 spyOn(uibModal, 'open').and.returnValue(respuesta);
838 scope.seleccionarDetalles(); 776 scope.seleccionarDetalles();
839 777
840 //assert 778 //assert
841 expect(uibModal.open).toHaveBeenCalled(); 779 expect(uibModal.open).toHaveBeenCalled();
842 }); 780 });
843 781
844 it('seleccionarMoneda levanta modal', function(done) { 782 it('seleccionarMoneda levanta modal', function(done) {
845 783
846 //arrange 784 //arrange
847 var scope = { 785 var scope = {
848 $broadcast: function() { }, 786 $broadcast: function() { },
849 $watch: function() { } 787 $watch: function() { }
850 }; 788 };
851 var focaModalService = { 789 var focaModalService = {
852 modal: function() { } 790 modal: function() { }
853 }; 791 };
854 792
855 $controller('cobranzaController', { 793 $controller('cobranzaController', {
856 $scope: scope, 794 $scope: scope,
857 $timeout: $timeout, 795 $timeout: $timeout,
858 $uibModal: {}, 796 $uibModal: {},
859 $location: {}, 797 $location: {},
860 focaCrearCobranzaService: { 798 focaCrearCobranzaService: {
861 getCotizacionByIdMoneda: function() { 799 getCotizacionByIdMoneda: function() {
862 return { 800 return {
863 then: function() { } 801 then: function() { }
864 }; 802 };
865 }, 803 },
866 getBotonera: function() { }, 804 getBotonera: function() { },
867 getNumeroRecibo: function() { 805 getNumeroRecibo: function() {
868 return { 806 return {
869 then: function() { } 807 then: function() { }
870 }; 808 };
871 } 809 }
872 }, 810 },
873 focaModalService: focaModalService, 811 focaModalService: focaModalService,
874 $filter: $filter, 812 $filter: $filter,
875 focaSeguimientoService: {}, 813 focaSeguimientoService: {},
876 focaBotoneraLateralService: {}, 814 focaBotoneraLateralService: {},
877 APP: {}, 815 APP: {},
878 focaLoginService: {}, 816 focaLoginService: {},
879 $localStorage: true 817 $localStorage: true
880 }); 818 });
881 819
882 var respuesta = 1; 820 var respuesta = 1;
883 var promesa = Promise.resolve(respuesta); 821 var promesa = Promise.resolve(respuesta);
884 822
885 //act 823 //act
886 spyOn(focaModalService, 'modal').and.returnValue(promesa); 824 spyOn(focaModalService, 'modal').and.returnValue(promesa);
887 spyOn(scope, 'seleccionarCotizacion'); 825 spyOn(scope, 'seleccionarCotizacion');
888 scope.seleccionarMoneda(); 826 scope.seleccionarMoneda();
889 827
890 //assert 828 //assert
891 expect(focaModalService.modal).toHaveBeenCalled(); 829 expect(focaModalService.modal).toHaveBeenCalled();
892 promesa.then(function() { 830 promesa.then(function() {
893 expect(scope.seleccionarCotizacion).toHaveBeenCalled(); 831 expect(scope.seleccionarCotizacion).toHaveBeenCalled();
894 done(); 832 done();
895 }); 833 });
896 }); 834 });
897 835
898 it('seleccionarCotizacion levanta modal', function(done) { 836 it('seleccionarCotizacion levanta modal', function(done) {
899 837
900 //arrange 838 //arrange
901 var scope = { 839 var scope = {
902 $broadcast: function() { }, 840 $broadcast: function() { },
903 $watch: function() { } 841 $watch: function() { }
904 }; 842 };
905 var uibModal = { 843 var uibModal = {
906 open: function() { } 844 open: function() { }
907 }; 845 };
908 846
909 $controller('cobranzaController', { 847 $controller('cobranzaController', {
910 $scope: scope, 848 $scope: scope,
911 $timeout: $timeout, 849 $timeout: $timeout,
912 $uibModal: uibModal, 850 $uibModal: uibModal,
913 $location: {}, 851 $location: {},
914 focaCrearCobranzaService: { 852 focaCrearCobranzaService: {
915 getCotizacionByIdMoneda: function() { 853 getCotizacionByIdMoneda: function() {
916 return { 854 return {
917 then: function() { } 855 then: function() { }
918 }; 856 };
919 }, 857 },
920 getBotonera: function() { }, 858 getBotonera: function() { },
921 getNumeroRecibo: function() { 859 getNumeroRecibo: function() {
922 return { 860 return {
923 then: function() { } 861 then: function() { }
924 }; 862 };
925 } 863 }
926 }, 864 },
927 focaModalService: {}, 865 focaModalService: {},
928 $filter: $filter, 866 $filter: $filter,
929 focaSeguimientoService: {}, 867 focaSeguimientoService: {},
930 focaBotoneraLateralService: {}, 868 focaBotoneraLateralService: {},
931 APP: {}, 869 APP: {},
932 focaLoginService: {}, 870 focaLoginService: {},
933 $localStorage: true 871 $localStorage: true
934 }); 872 });
935 873
936 var respuesta = 1; 874 var respuesta = 1;
937 var promesa = { result: Promise.resolve(respuesta) }; 875 var promesa = { result: Promise.resolve(respuesta) };
938 876
939 //act 877 //act
940 spyOn(uibModal, 'open').and.returnValue(promesa); 878 spyOn(uibModal, 'open').and.returnValue(promesa);
941 spyOn(scope, '$broadcast'); 879 spyOn(scope, '$broadcast');
942 scope.seleccionarCotizacion({ }); 880 scope.seleccionarCotizacion({ });
943 881
944 //assert 882 //assert
945 promesa.result.then(function() { 883 promesa.result.then(function() {
946 expect(uibModal.open).toHaveBeenCalled(); 884 expect(uibModal.open).toHaveBeenCalled();
947 expect(scope.$broadcast).toHaveBeenCalled(); 885 expect(scope.$broadcast).toHaveBeenCalled();
948 scope.cobranza.cotizacion = respuesta; 886 scope.cobranza.cotizacion = respuesta;
949 done(); 887 done();
950 }); 888 });
951 }); 889 });
952 890
953 it('seleccionarCobrador levanta modal', function(done) {
954
955 //arrange
956 var scope = {
957 $broadcast: function() { },
958 $watch: function() { }
959 };
960 var focaModalService = {
961 modal: function() { }
962 };
963
964 $controller('cobranzaController', {
965 $scope: scope,
966 $timeout: $timeout,
967 $uibModal: {},
968 $location: {},
969 focaCrearCobranzaService: {
970 getCotizacionByIdMoneda: function() {
971 return {
972 then: function() { }
973 };
974 },
975 getBotonera: function() { },
976 getNumeroRecibo: function() {
977 return {
978 then: function() { }
979 };
980 }
981 },
982 focaModalService: focaModalService,
983 $filter: $filter,
984 focaSeguimientoService: {},
985 focaBotoneraLateralService: {},
986 APP: {},
987 focaLoginService: {},
988 $localStorage: true
989 });
990
991 var respuesta = 1;
992 var promesa = Promise.resolve(respuesta);
993
994 //act
995 spyOn(focaModalService, 'modal').and.returnValue(promesa);
996 spyOn(scope, '$broadcast');
997 scope.seleccionarCobrador({ });
998
999 //assert
1000 promesa.then(function() {
1001 expect(focaModalService.modal).toHaveBeenCalled();
1002 expect(scope.$broadcast).toHaveBeenCalled();
1003 scope.cobranza.cobrador = respuesta;
1004 done();
1005 });
1006 });
1007
1008 it('getTotalDeuda devuelve correcto', function() { 891 it('getTotalDeuda devuelve correcto', function() {
1009 892
1010 //arrange 893 //arrange
1011 var scope = { 894 var scope = {
1012 $broadcast: function() { }, 895 $broadcast: function() { },
1013 $watch: function() { } 896 $watch: function() { }
1014 }; 897 };
1015 898
1016 $controller('cobranzaController', { 899 $controller('cobranzaController', {
1017 $scope: scope, 900 $scope: scope,
1018 $timeout: $timeout, 901 $timeout: $timeout,
1019 $uibModal: {}, 902 $uibModal: {},
1020 $location: {}, 903 $location: {},
1021 focaCrearCobranzaService: { 904 focaCrearCobranzaService: {
1022 getCotizacionByIdMoneda: function() { 905 getCotizacionByIdMoneda: function() {
1023 return { 906 return {
1024 then: function() { } 907 then: function() { }
1025 }; 908 };
1026 }, 909 },
1027 getBotonera: function() { }, 910 getBotonera: function() { },
1028 getNumeroRecibo: function() { 911 getNumeroRecibo: function() {
1029 return { 912 return {
1030 then: function() { } 913 then: function() { }
1031 }; 914 };
1032 } 915 }
1033 }, 916 },
1034 focaModalService: {}, 917 focaModalService: {},
1035 $filter: $filter, 918 $filter: $filter,
1036 focaSeguimientoService: {}, 919 focaSeguimientoService: {},
1037 focaBotoneraLateralService: {}, 920 focaBotoneraLateralService: {},
1038 APP: {}, 921 APP: {},
1039 focaLoginService: {}, 922 focaLoginService: {},
1040 $localStorage: true 923 $localStorage: true
1041 }); 924 });
1042 scope.cobranza = { 925 scope.cobranza = {
1043 facturas: [{ IPA: 1 }] 926 facturas: [{ IPA: 1 }]
1044 }; 927 };
1045 928
1046 //act 929 //act
1047 var esperado = 1; 930 var esperado = 1;
1048 var resultado = scope.getTotalDeuda(); 931 var resultado = scope.getTotalDeuda();
1049 932
1050 //assert 933 //assert
1051 expect(resultado).toEqual(esperado); 934 expect(resultado).toEqual(esperado);
1052 }); 935 });
1053 936
1054 it('getTotalCobrado devuelve correcto', function() { 937 it('getTotalCobrado devuelve correcto', function() {
1055 938
1056 //arrange 939 //arrange
1057 var scope = { 940 var scope = {
1058 $broadcast: function() { }, 941 $broadcast: function() { },
1059 $watch: function() { } 942 $watch: function() { }
1060 }; 943 };
1061 944
1062 $controller('cobranzaController', { 945 $controller('cobranzaController', {
1063 $scope: scope, 946 $scope: scope,
1064 $timeout: $timeout, 947 $timeout: $timeout,
1065 $uibModal: {}, 948 $uibModal: {},
1066 $location: {}, 949 $location: {},
1067 focaCrearCobranzaService: { 950 focaCrearCobranzaService: {
1068 getCotizacionByIdMoneda: function() { 951 getCotizacionByIdMoneda: function() {
1069 return { 952 return {
1070 then: function() { } 953 then: function() { }
1071 }; 954 };
1072 }, 955 },
1073 getBotonera: function() { }, 956 getBotonera: function() { },
1074 getNumeroRecibo: function() { 957 getNumeroRecibo: function() {
1075 return { 958 return {
1076 then: function() { } 959 then: function() { }
1077 }; 960 };
1078 } 961 }
1079 }, 962 },
1080 focaModalService: {}, 963 focaModalService: {},
1081 $filter: $filter, 964 $filter: $filter,
1082 focaSeguimientoService: {}, 965 focaSeguimientoService: {},
1083 focaBotoneraLateralService: {}, 966 focaBotoneraLateralService: {},
1084 APP: {}, 967 APP: {},
1085 focaLoginService: {}, 968 focaLoginService: {},
1086 $localStorage: true 969 $localStorage: true
1087 }); 970 });
1088 scope.cobranza = { 971 scope.cobranza = {
1089 cobros: [{ IMP: 1 }] 972 cobros: [{ IMP: 1 }]
1090 }; 973 };
1091 974
1092 //act 975 //act
1093 var esperado = 1; 976 var esperado = 1;
1094 var resultado = scope.getTotalCobrado(); 977 var resultado = scope.getTotalCobrado();
1095 978
1096 //assert 979 //assert
1097 expect(resultado).toEqual(esperado); 980 expect(resultado).toEqual(esperado);
1098 }); 981 });
1099 982
1100 it('getSubTotal devuelve correcto', function() { 983 it('getSubTotal devuelve correcto', function() {
1101 984
1102 //arrange 985 //arrange
1103 var scope = { 986 var scope = {
1104 $broadcast: function() { }, 987 $broadcast: function() { },
1105 $watch: function() { } 988 $watch: function() { }
1106 }; 989 };
1107 990
1108 $controller('cobranzaController', { 991 $controller('cobranzaController', {
1109 $scope: scope, 992 $scope: scope,
1110 $timeout: $timeout, 993 $timeout: $timeout,
1111 $uibModal: {}, 994 $uibModal: {},
1112 $location: {}, 995 $location: {},
1113 focaCrearCobranzaService: { 996 focaCrearCobranzaService: {
1114 getCotizacionByIdMoneda: function() { 997 getCotizacionByIdMoneda: function() {
1115 return { 998 return {
1116 then: function() { } 999 then: function() { }
1117 }; 1000 };
1118 }, 1001 },
1119 getBotonera: function() { }, 1002 getBotonera: function() { },
1120 getNumeroRecibo: function() { 1003 getNumeroRecibo: function() {
1121 return { 1004 return {
1122 then: function() { } 1005 then: function() { }
1123 }; 1006 };
1124 } 1007 }
1125 }, 1008 },
1126 focaModalService: {}, 1009 focaModalService: {},
1127 $filter: $filter, 1010 $filter: $filter,
1128 focaSeguimientoService: {}, 1011 focaSeguimientoService: {},
1129 focaBotoneraLateralService: {}, 1012 focaBotoneraLateralService: {},
1130 APP: {}, 1013 APP: {},
1131 focaLoginService: {}, 1014 focaLoginService: {},
1132 $localStorage: true 1015 $localStorage: true
1133 }); 1016 });
1134 scope.articuloACargar = { 1017 scope.articuloACargar = {
1135 precio: 2, 1018 precio: 2,
1136 cantidad: 5 1019 cantidad: 5
1137 }; 1020 };
1138 1021
1139 //act 1022 //act
1140 var esperado = 10; 1023 var esperado = 10;
1141 var resultado = scope.getSubTotal(); 1024 var resultado = scope.getSubTotal();
1142 1025
1143 //assert 1026 //assert
1144 expect(resultado).toEqual(esperado); 1027 expect(resultado).toEqual(esperado);
1145 }); 1028 });
1146 1029
1147 it('salir lleva a la ruta correcta', function() { 1030 it('salir lleva a la ruta correcta', function() {
1148 1031
1149 inject(function($location) { 1032 inject(function($location) {
1150 1033
1151 //arrange 1034 //arrange
1152 var scope = { 1035 var scope = {
1153 $broadcast: function() { }, 1036 $broadcast: function() { },
1154 $watch: function() { } 1037 $watch: function() { }
1155 }; 1038 };
1156 1039
1157 $controller('cobranzaController', { 1040 $controller('cobranzaController', {
1158 $scope: scope, 1041 $scope: scope,
1159 $timeout: $timeout, 1042 $timeout: $timeout,
1160 $uibModal: {}, 1043 $uibModal: {},
1161 $location: $location, 1044 $location: $location,
1162 focaCrearCobranzaService: { 1045 focaCrearCobranzaService: {
1163 getCotizacionByIdMoneda: function() { 1046 getCotizacionByIdMoneda: function() {
1164 return { 1047 return {
1165 then: function() { } 1048 then: function() { }
1166 }; 1049 };
1167 }, 1050 },
1168 getBotonera: function() { }, 1051 getBotonera: function() { },
1169 getNumeroRecibo: function() { 1052 getNumeroRecibo: function() {
1170 return { 1053 return {
1171 then: function() { } 1054 then: function() { }
1172 }; 1055 };
1173 } 1056 }
1174 }, 1057 },
1175 focaModalService: {}, 1058 focaModalService: {},
1176 $filter: $filter, 1059 $filter: $filter,
1177 focaSeguimientoService: {}, 1060 focaSeguimientoService: {},
1178 focaBotoneraLateralService: {}, 1061 focaBotoneraLateralService: {},
1179 APP: {}, 1062 APP: {},
1180 focaLoginService: {}, 1063 focaLoginService: {},
1181 $localStorage: true 1064 $localStorage: true
1182 }); 1065 });
1183 1066
1184 //act 1067 //act
1185 scope.salir(); 1068 scope.salir();
1186 1069
1187 //assert 1070 //assert
1188 expect($location.url()).toEqual('/'); 1071 expect($location.url()).toEqual('/');
1189 }); 1072 });
1190 }); 1073 });
1191 1074
1192 it('parsearATexto parsea correctamente', function() { 1075 it('parsearATexto parsea correctamente', function() {
1193 1076
1194 //arrange 1077 //arrange
1195 var scope = { 1078 var scope = {
1196 $broadcast: function() { }, 1079 $broadcast: function() { },
1197 $watch: function() { } 1080 $watch: function() { }
1198 }; 1081 };
1199 1082
1200 $controller('cobranzaController', { 1083 $controller('cobranzaController', {
1201 $scope: scope, 1084 $scope: scope,
1202 $timeout: $timeout, 1085 $timeout: $timeout,
1203 $uibModal: {}, 1086 $uibModal: {},
1204 $location: {}, 1087 $location: {},
1205 focaCrearCobranzaService: { 1088 focaCrearCobranzaService: {
1206 getCotizacionByIdMoneda: function() { 1089 getCotizacionByIdMoneda: function() {
1207 return { 1090 return {
1208 then: function() { } 1091 then: function() { }
1209 }; 1092 };
1210 }, 1093 },
1211 getBotonera: function() { }, 1094 getBotonera: function() { },
1212 getNumeroRecibo: function() { 1095 getNumeroRecibo: function() {
1213 return { 1096 return {
1214 then: function() { } 1097 then: function() { }
1215 }; 1098 };
1216 } 1099 }
1217 }, 1100 },
1218 focaModalService: {}, 1101 focaModalService: {},
1219 $filter: $filter, 1102 $filter: $filter,
1220 focaSeguimientoService: {}, 1103 focaSeguimientoService: {},
1221 focaBotoneraLateralService: {}, 1104 focaBotoneraLateralService: {},
1222 APP: {}, 1105 APP: {},
1223 focaLoginService: {}, 1106 focaLoginService: {},
1224 $localStorage: true 1107 $localStorage: true
1225 }); 1108 });
1226 1109
1227 var parametro = { 1110 var parametro = {
1228 cantidad: '1', 1111 cantidad: '1',
1229 precio: '2' 1112 precio: '2'
1230 }; 1113 };
1231 1114
1232 //act 1115 //act
1233 scope.parsearATexto(parametro); 1116 scope.parsearATexto(parametro);
1234 1117
1235 //assert 1118 //assert
1236 expect(typeof parametro.cantidad).toEqual('number'); 1119 expect(typeof parametro.cantidad).toEqual('number');
1237 expect(typeof parametro.precio).toEqual('number'); 1120 expect(typeof parametro.precio).toEqual('number');
1238 }); 1121 });
1239 1122
1240 }); 1123 });
1241 }); 1124 });
1242 1125
src/js/controller.js
1 angular.module('focaCrearCobranza') .controller('cobranzaController', 1 angular.module('focaCrearCobranza') .controller('cobranzaController',
2 [ 2 [
3 '$scope', '$timeout', '$uibModal', '$location', 3 '$scope', '$timeout', '$uibModal', '$location',
4 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', 4 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService',
5 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', 5 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage',
6 function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, 6 function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService,
7 focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, 7 focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService,
8 APP, loginService, $localStorage) 8 APP, loginService, $localStorage)
9 { 9 {
10 config(); 10 config();
11 11
12 function config() { 12 function config() {
13 $scope.datepickerAbierto = false; 13 $scope.datepickerAbierto = false;
14 $scope.cobroDeuda = true; 14 $scope.cobroDeuda = true;
15 $scope.show = false; 15 $scope.show = false;
16 $scope.cargando = true; 16 $scope.cargando = true;
17 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 17 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
18 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 18 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
19 $scope.botonera = focaCrearCobranzaService.getBotonera(); 19 $scope.botonera = focaCrearCobranzaService.getBotonera();
20 $scope.dateOptions = { 20 $scope.dateOptions = {
21 maxDate: new Date(), 21 maxDate: new Date(),
22 minDate: new Date(2010, 0, 1) 22 minDate: new Date(2010, 0, 1)
23 }; 23 };
24 24
25 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 25 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
26 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { 26 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) {
27 var moneda = res.data[0]; 27 var moneda = res.data[0];
28 moneda.cotizacion = moneda.cotizaciones[0]; 28 moneda.cotizacion = moneda.cotizaciones[0];
29 $scope.cobranza.moneda = $scope.inicial.moneda = moneda; 29 $scope.cobranza.moneda = $scope.inicial.moneda = moneda;
30 $filter('filter')( $scope.botonera, { 30 $filter('filter')( $scope.botonera, {
31 label: 'Moneda' 31 label: 'Moneda'
32 })[0].checked = true; 32 })[0].checked = true;
33 $timeout(function() { getLSCobranza();} ); 33 $timeout(function() { getLSCobranza();} );
34 }); 34 });
35 35
36 $timeout(function() { 36 $timeout(function() {
37 focaBotoneraLateralService.showSalir(false); 37 focaBotoneraLateralService.showSalir(false);
38 focaBotoneraLateralService.showPausar(true); 38 focaBotoneraLateralService.showPausar(true);
39 focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); 39 focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza);
40 focaBotoneraLateralService.addCustomButton('Salir', salir); 40 focaBotoneraLateralService.addCustomButton('Salir', salir);
41 }); 41 });
42 42
43 if (APP === 'cobranza') { 43 if (APP === 'cobranza') {
44 $scope.idCobrador = loginService.getLoginData().vendedorCobrador; 44 $scope.idCobrador = loginService.getLoginData().vendedorCobrador;
45 } 45 }
46 46
47 init(); 47 init();
48 } 48 }
49 49
50 function init() { 50 function init() {
51 $scope.$broadcast('cleanCabecera'); 51 $scope.$broadcast('cleanCabecera');
52 $scope.cobranza = { 52 $scope.cobranza = {
53 FEC: new Date(), 53 FEC: new Date(),
54 moneda: {}, 54 moneda: {},
55 facturas: [], 55 facturas: [],
56 cobros: [], 56 cobros: [],
57 cliente: {}, 57 cliente: {},
58 cobrador: {} 58 cobrador: {}
59 }; 59 };
60 60
61 if (APP === 'cobranza') { 61 if (APP === 'cobranza') {
62 focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( 62 focaCrearCobranzaService.getCobradorById($scope.idCobrador).then(
63 function(res) { 63 function(res) {
64 var cobrador = res.data; 64 var cobrador = res.data;
65 65
66 $scope.$broadcast('addCabecera', { 66 $scope.$broadcast('addCabecera', {
67 label: 'Cobrador:', 67 label: 'Cobrador:',
68 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + 68 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' +
69 cobrador.NOM 69 cobrador.NOM
70 }); 70 });
71 71
72 $scope.cobranza.cobrador = cobrador; 72 $scope.cobranza.cobrador = cobrador;
73 $scope.inicial.cobrador = $scope.cobranza.cobrador; 73 $scope.inicial.cobrador = $scope.cobranza.cobrador;
74 } 74 }
75 ); 75 );
76 } 76 }
77 77
78 $scope.inicial = angular.copy($scope.cobranza); 78 $scope.inicial = angular.copy($scope.cobranza);
79 79
80 focaCrearCobranzaService.getNumeroRecibo().then( 80 focaCrearCobranzaService.getNumeroRecibo().then(
81 function(res) { 81 function(res) {
82 $scope.puntoVenta = $filter('rellenarDigitos')( 82 $scope.puntoVenta = $filter('rellenarDigitos')(
83 res.data.sucursal, 4 83 res.data.sucursal, 4
84 ); 84 );
85 85
86 $scope.comprobante = $filter('rellenarDigitos')( 86 $scope.comprobante = $filter('rellenarDigitos')(
87 res.data.numeroRecibo, 8 87 res.data.numeroRecibo, 8
88 ); 88 );
89 }, 89 },
90 function(err) { 90 function(err) {
91 focaModalService.alert( 91 focaModalService.alert(
92 'La terminal no esta configurada correctamente' 92 'La terminal no esta configurada correctamente'
93 ); 93 );
94 console.info(err); 94 console.info(err);
95 } 95 }
96 ); 96 );
97 } 97 }
98 98
99 $scope.$watch('cobranza', function(newValue) { 99 $scope.$watch('cobranza', function(newValue) {
100 focaBotoneraLateralService.setPausarData({ 100 focaBotoneraLateralService.setPausarData({
101 label: 'cobranza', 101 label: 'cobranza',
102 val: newValue 102 val: newValue
103 }); 103 });
104 }, true); 104 }, true);
105 105
106 $scope.crearCobranza = function() { 106 $scope.crearCobranza = function() {
107 if (!$scope.cobranza.cliente.COD) { 107 if (!$scope.cobranza.cliente.COD) {
108 focaModalService.alert('Ingrese Cliente'); 108 focaModalService.alert('Ingrese Cliente');
109 return; 109 return;
110 } 110 }
111 if (!$scope.cobranza.cobrador.NUM) { 111 if (!$scope.cobranza.cobrador.NUM) {
112 focaModalService.alert('Ingrese Cobrador'); 112 focaModalService.alert('Ingrese Cobrador');
113 return; 113 return;
114 } 114 }
115 if ($scope.cobranza.facturas.length < 1) { 115 if ($scope.cobranza.facturas.length < 1) {
116 focaModalService.alert('Ingrese al menos una factura'); 116 focaModalService.alert('Ingrese al menos una factura');
117 return; 117 return;
118 } 118 }
119 if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { 119 if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) {
120 focaModalService.alert('La diferencia debe ser ' + 120 focaModalService.alert('La diferencia debe ser ' +
121 $scope.cobranza.moneda.SIMBOLO + '0,00'); 121 $scope.cobranza.moneda.SIMBOLO + '0,00');
122 return; 122 return;
123 } 123 }
124 var cobranza = {}; 124 var cobranza = {};
125 var cheques = []; 125 var cheques = [];
126 var cuerpos = []; 126 var cuerpos = [];
127 var imgs = []; 127 var imgs = [];
128 var observacion; 128 var observacion;
129 //TODO: habilitar edición 129 //TODO: habilitar edición
130 $scope.editando = false; 130 $scope.editando = false;
131 focaBotoneraLateralService.startGuardar(); 131 focaBotoneraLateralService.startGuardar();
132 $scope.saveLoading = true; 132 $scope.saveLoading = true;
133 for(var i = 0; i < $scope.cobranza.facturas.length; i++) { 133 for(var i = 0; i < $scope.cobranza.facturas.length; i++) {
134 var cuerpoFactura = { 134 var cuerpoFactura = {
135 CYV: 'V', 135 CYV: 'V',
136 TIP: 'C', 136 TIP: 'C',
137 TCO: 'RC', 137 TCO: 'RC',
138 PVE: $scope.puntoVenta, 138 PVE: $scope.puntoVenta,
139 NCO: $scope.comprobante, 139 NCO: $scope.comprobante,
140 LOP: 'L', 140 LOP: 'L',
141 TIL: $scope.cobranza.facturas[i].TCO, 141 TIL: $scope.cobranza.facturas[i].TCO,
142 COM: $scope.cobranza.facturas[i].numeroFactura + '-' + 142 COM: $scope.cobranza.facturas[i].numeroFactura + '-' +
143 $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU), 143 $filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU),
144 FEC: new Date($scope.cobranza.FEC) 144 FEC: new Date($scope.cobranza.FEC)
145 .toISOString().slice(0, 19).replace('T', ' '), 145 .toISOString().slice(0, 19).replace('T', ' '),
146 IMP: Math.abs($scope.cobranza.facturas[i].IMP || 146 IMP: Math.abs($scope.cobranza.facturas[i].IMP ||
147 $scope.cobranza.facturas[i].IPA), 147 $scope.cobranza.facturas[i].IPA),
148 RES: 0,//caja de tesorería 148 RES: 0,//caja de tesorería
149 SUBM: 0, 149 SUBM: 0,
150 NCU: $scope.cobranza.facturas[i].NCU 150 NCU: $scope.cobranza.facturas[i].NCU
151 }; 151 };
152 cuerpos.push(cuerpoFactura); 152 cuerpos.push(cuerpoFactura);
153 } 153 }
154 for (var j = 0; j < $scope.cobranza.cobros.length; j++) { 154 for (var j = 0; j < $scope.cobranza.cobros.length; j++) {
155 var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo'; 155 var efectivo = $scope.cobranza.cobros[j].tipo === 'Efectivo';
156 var cuerpoCobros = { 156 var cuerpoCobros = {
157 CYV: 'V', 157 CYV: 'V',
158 TIP: 'C', 158 TIP: 'C',
159 TCO: 'RC', 159 TCO: 'RC',
160 PVE: $scope.puntoVenta, 160 PVE: $scope.puntoVenta,
161 NCO: $scope.comprobante, 161 NCO: $scope.comprobante,
162 LOP: 'P', 162 LOP: 'P',
163 TIL: $scope.cobranza.cobros[j].TIL, 163 TIL: $scope.cobranza.cobros[j].TIL,
164 COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM, 164 COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM,
165 FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? 165 FEC: !$scope.cobranza.cobros[j].fechaPresentacion ?
166 new Date($scope.cobranza.cobros[j].FEC) 166 new Date($scope.cobranza.cobros[j].FEC)
167 .toISOString().slice(0, 19).replace('T', ' ') : 167 .toISOString().slice(0, 19).replace('T', ' ') :
168 new Date($scope.cobranza.cobros[j].fechaPresentacion) 168 new Date($scope.cobranza.cobros[j].fechaPresentacion)
169 .toISOString().slice(0, 19).replace('T', ' '), 169 .toISOString().slice(0, 19).replace('T', ' '),
170 IMP: Math.abs($scope.cobranza.cobros[j].IMP), 170 IMP: Math.abs($scope.cobranza.cobros[j].IMP),
171 RES: 0,//caja de tesorería 171 RES: 0,//caja de tesorería
172 SUBM: 0 172 SUBM: 0
173 }; 173 };
174 cuerpos.push(cuerpoCobros); 174 cuerpos.push(cuerpoCobros);
175 175
176 if ($scope.cobranza.cobros[j].observacion) 176 if ($scope.cobranza.cobros[j].observacion)
177 observacion = $scope.cobranza.cobros[j].observacion; 177 observacion = $scope.cobranza.cobros[j].observacion;
178 178
179 if ($scope.cobranza.cobros[j].banco) { 179 if ($scope.cobranza.cobros[j].banco) {
180 var cheque = { 180 var cheque = {
181 BCO: $scope.cobranza.cobros[j].banco.ID, 181 BCO: $scope.cobranza.cobros[j].banco.ID,
182 NUM: $scope.comprobante, 182 NUM: $scope.comprobante,
183 FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion) 183 FEP: new Date($scope.cobranza.cobros[j].fechaPresentacion)
184 .toISOString().slice(0, 19).replace('T', ' '), 184 .toISOString().slice(0, 19).replace('T', ' '),
185 FEE: new Date($scope.cobranza.cobros[j].fechaEmision) 185 FEE: new Date($scope.cobranza.cobros[j].fechaEmision)
186 .toISOString().slice(0, 19).replace('T', ' '), 186 .toISOString().slice(0, 19).replace('T', ' '),
187 LUG: $scope.cobranza.cobros[j].localidad.NOMBRE, 187 LUG: $scope.cobranza.cobros[j].localidad.NOMBRE,
188 IMP: $scope.cobranza.cobros[j].importe, 188 IMP: $scope.cobranza.cobros[j].importe,
189 LIB: $scope.cobranza.cobros[j].librador, 189 LIB: $scope.cobranza.cobros[j].librador,
190 EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera 190 EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera
191 PCI: $scope.cobranza.cobros[j].provincia.ID, 191 PCI: $scope.cobranza.cobros[j].provincia.ID,
192 LPLA: 0, 192 LPLA: 0,
193 PLA: 0, 193 PLA: 0,
194 VEN: $scope.cobranza.cobrador.id,//Id vendedor 194 VEN: $scope.cobranza.cobrador.id,//Id vendedor
195 CCLIE: $scope.cobranza.cliente.COD,//Id cliente 195 CCLIE: $scope.cobranza.cliente.COD,//Id cliente
196 REN: 0, 196 REN: 0,
197 PVEC: $scope.puntoVenta, 197 PVEC: $scope.puntoVenta,
198 NCOC: $scope.comprobante, 198 NCOC: $scope.comprobante,
199 OBSE: $scope.cobranza.cobros[j].observaciones, 199 OBSE: $scope.cobranza.cobros[j].observaciones,
200 LUV: 0, 200 LUV: 0,
201 ORI: 've', 201 ORI: 've',
202 FER: '', 202 FER: '',
203 BIMP: 0, 203 BIMP: 0,
204 COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, 204 COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante,
205 VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso 205 VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso
206 VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso 206 VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso
207 REC_CAJ: 'D', 207 REC_CAJ: 'D',
208 TIPO_C: 0,//?? 208 TIPO_C: 0,//??
209 SALDO_CAJ: 'S', 209 SALDO_CAJ: 'S',
210 FECHA_INGRESO: new Date($scope.cobranza.FEC) 210 FECHA_INGRESO: new Date($scope.cobranza.FEC)
211 .toISOString().slice(0, 19).replace('T', ' '), 211 .toISOString().slice(0, 19).replace('T', ' '),
212 Vendedor_valor: 0, 212 Vendedor_valor: 0,
213 FAMILIA: 0, 213 FAMILIA: 0,
214 CUIT_LIB: '', 214 CUIT_LIB: '',
215 COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar 215 COD_LUG: $scope.cobranza.cobros[j].localidad.ID,//código lugar
216 SEN: '', 216 SEN: '',
217 NRC: 0, 217 NRC: 0,
218 COD_LARGO: '', 218 COD_LARGO: '',
219 VN: 0, 219 VN: 0,
220 ID_LECTOR: 0, 220 ID_LECTOR: 0,
221 NATHB: '' 221 NATHB: ''
222 }; 222 };
223 cheques.push(cheque); 223 cheques.push(cheque);
224 } 224 }
225 if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; 225 if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs;
226 226
227 } 227 }
228 228
229 cobranza = { 229 cobranza = {
230 recibo: { 230 recibo: {
231 CYV: 'V', 231 CYV: 'V',
232 TIP: 'C', 232 TIP: 'C',
233 TCO: 'RC', 233 TCO: 'RC',
234 PVE: $scope.puntoVenta, //Sucursar, punto de venta 234 PVE: $scope.puntoVenta, //Sucursar, punto de venta
235 NCO: $scope.comprobante, //Numero de comprobante 235 NCO: $scope.comprobante, //Numero de comprobante
236 FEC: new Date($scope.cobranza.FEC) 236 FEC: new Date($scope.cobranza.FEC)
237 .toISOString().slice(0, 19).replace('T', ' '), 237 .toISOString().slice(0, 19).replace('T', ' '),
238 CLI: $scope.cobranza.cliente.COD, 238 CLI: $scope.cobranza.cliente.COD,
239 ATO: 0, //número de asiento 239 ATO: 0, //número de asiento
240 CFE: $scope.cobranza.cobrador.NOM, 240 CFE: $scope.cobranza.cobrador.NOM,
241 PLA: '',//Numero de planilla, sin uso 241 PLA: '',//Numero de planilla, sin uso
242 ID_MONEDA: $scope.cobranza.moneda.ID, 242 ID_MONEDA: $scope.cobranza.moneda.ID,
243 COTIZACION: $scope.cobranza.moneda.cotizacion.VENDEDOR, 243 COTIZACION: $scope.cobranza.moneda.cotizacion.VENDEDOR,
244 idCobrador: $scope.cobranza.cobrador.id 244 idCobrador: $scope.cobranza.cobrador.id
245 }, 245 },
246 cuerpo: cuerpos, 246 cuerpo: cuerpos,
247 cheques: cheques, 247 cheques: cheques,
248 acobypag: { 248 acobypag: {
249 CYV: 'V', 249 CYV: 'V',
250 COD: $scope.cobranza.cliente.COD, 250 COD: $scope.cobranza.cliente.COD,
251 FEP: new Date($scope.cobranza.FEC) 251 FEP: new Date($scope.cobranza.FEC)
252 .toISOString().slice(0, 19).replace('T', ' '), 252 .toISOString().slice(0, 19).replace('T', ' '),
253 TIP: 'C', 253 TIP: 'C',
254 TCO: 'RC', 254 TCO: 'RC',
255 SUC: $scope.puntoVenta, 255 SUC: $scope.puntoVenta,
256 NCO: $scope.comprobante, 256 NCO: $scope.comprobante,
257 IPA: $scope.getTotalCobrado(), 257 IPA: $scope.getTotalCobrado(),
258 SAL: '',//?? 258 SAL: '',//??
259 TCA: 1, 259 TCA: 1,
260 ZONA: 1, 260 ZONA: 1,
261 FPA: 2,//Forma de pago 261 FPA: 2,//Forma de pago
262 REC: 0, 262 REC: 0,
263 REP: 0, 263 REP: 0,
264 FER: null, 264 FER: null,
265 REM: 0, 265 REM: 0,
266 FRE: null,//?? 266 FRE: null,//??
267 PRO: 'N', 267 PRO: 'N',
268 FEV: new Date($scope.cobranza.FEC) 268 FEV: new Date($scope.cobranza.FEC)
269 .toISOString().slice(0, 19).replace('T', ' ') 269 .toISOString().slice(0, 19).replace('T', ' ')
270 }, 270 },
271 datosCobrador: { 271 datosCobrador: {
272 COD: $scope.cobranza.cobrador.NUM, 272 COD: $scope.cobranza.cobrador.NUM,
273 PVE: $scope.puntoVenta, 273 PVE: $scope.puntoVenta,
274 NUM: $scope.comprobante, 274 NUM: $scope.comprobante,
275 EST: 'C', 275 EST: 'C',
276 OBS: 'RC: ' + $scope.comprobante + '-' + 276 OBS: 'RC: ' + $scope.comprobante + '-' +
277 new Date($scope.cobranza.FEC).toLocaleDateString(), 277 new Date($scope.cobranza.FEC).toLocaleDateString(),
278 DAT1: 'C', 278 DAT1: 'C',
279 CLI: $scope.cobranza.cliente.COD 279 CLI: $scope.cobranza.cliente.COD
280 }, 280 },
281 cliente: $scope.cobranza.cliente, 281 cliente: $scope.cobranza.cliente,
282 imgs: imgs, 282 imgs: imgs,
283 observacion: observacion, 283 observacion: observacion,
284 facturasACobrar: $scope.cobranza.facturas 284 facturasACobrar: $scope.cobranza.facturas
285 }; 285 };
286 //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS 286 //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS
287 var cobranzaMail = angular.copy(cobranza); 287 var cobranzaMail = angular.copy(cobranza);
288 288
289 cobranza.cuerpo = cobranza.cuerpo.map(function(c) { 289 cobranza.cuerpo = cobranza.cuerpo.map(function(c) {
290 if (c.NCU) delete c.NCU; 290 if (c.NCU) delete c.NCU;
291 return c; 291 return c;
292 }); 292 });
293 focaCrearCobranzaService 293 focaCrearCobranzaService
294 .guardarCobranza(cobranza) 294 .guardarCobranza(cobranza)
295 .then( 295 .then(
296 function(result) { 296 function(result) {
297 focaBotoneraLateralService.endGuardar(true); 297 focaBotoneraLateralService.endGuardar(true);
298 $scope.saveLoading = false; 298 $scope.saveLoading = false;
299 299
300 enviarMail(cobranzaMail); 300 enviarMail(cobranzaMail);
301 301
302 focaSeguimientoService.guardarPosicion( 302 focaSeguimientoService.guardarPosicion(
303 'Cobranza', 303 'Cobranza',
304 result.data, 304 result.data,
305 '' 305 ''
306 ); 306 );
307 307
308 config(); 308 config();
309 }, function(error) { 309 }, function(error) {
310 focaModalService.alert('Hubo un problema al cargar la cobranza'); 310 focaModalService.alert('Hubo un problema al cargar la cobranza');
311 focaBotoneraLateralService.endGuardar(); 311 focaBotoneraLateralService.endGuardar();
312 $scope.saveLoading = false; 312 $scope.saveLoading = false;
313 console.info(error); 313 console.info(error);
314 } 314 }
315 ); 315 );
316 }; 316 };
317 317
318 $scope.seleccionarCobros = function() { 318 $scope.seleccionarCobros = function() {
319 $scope.cobroDeuda = false; 319 $scope.cobroDeuda = false;
320 }; 320 };
321 321
322 $scope.seleccionarComprobantes = function() { 322 $scope.seleccionarComprobantes = function() {
323 $scope.cobroDeuda = true; 323 $scope.cobroDeuda = true;
324 }; 324 };
325 325
326 $scope.seleccionarCobranza = function() { 326 $scope.seleccionarCobranza = function() {
327 var modalInstance = $uibModal.open( 327 var modalInstance = $uibModal.open(
328 { 328 {
329 ariaLabelledBy: 'Busqueda de Cobranzas', 329 ariaLabelledBy: 'Busqueda de Cobranzas',
330 templateUrl: 'foca-modal-cobranza.html', 330 templateUrl: 'foca-modal-cobranza.html',
331 controller: 'focaModalCobranzaController', 331 controller: 'focaModalCobranzaController',
332 size: 'lg' 332 size: 'lg'
333 } 333 }
334 ); 334 );
335 modalInstance.result.then(function(cobranza) { 335 modalInstance.result.then(function(cobranza) {
336 cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0]; 336 cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0];
337 setearCobranza(cobranza); 337 setearCobranza(cobranza);
338 }); 338 });
339 }; 339 };
340 340
341 $scope.seleccionarResumenDeCuenta = function() { 341 $scope.seleccionarResumenDeCuenta = function() {
342 if (!$scope.cobranza.cliente.COD) { 342 if (!$scope.cobranza.cliente.COD) {
343 focaModalService.alert('Seleccione primero un cliente'); 343 focaModalService.alert('Seleccione primero un cliente');
344 return; 344 return;
345 } 345 }
346 var modalInstance = $uibModal.open( 346 var modalInstance = $uibModal.open(
347 { 347 {
348 ariaLabelledBy: 'Resumen de cuentas', 348 ariaLabelledBy: 'Resumen de cuentas',
349 templateUrl: 'modal-resumen-cuenta.html', 349 templateUrl: 'modal-resumen-cuenta.html',
350 controller: 'focaModalResumenCuentaController', 350 controller: 'focaModalResumenCuentaController',
351 resolve: { 351 resolve: {
352 cliente: function() { return $scope.cobranza.cliente; }, 352 cliente: function() { return $scope.cobranza.cliente; },
353 idMoneda: function() { return $scope.cobranza.moneda.ID; } 353 idMoneda: function() { return $scope.cobranza.moneda.ID; }
354 }, 354 },
355 size: 'lg' 355 size: 'lg'
356 } 356 }
357 ); 357 );
358 modalInstance.result.then( 358 modalInstance.result.then(
359 function(cliente) { 359 function(cliente) {
360 $scope.abrirModalDomicilios(cliente); 360 $scope.abrirModalDomicilios(cliente);
361 $scope.cliente = cliente; 361 $scope.cliente = cliente;
362 }, function() {} 362 }, function() {}
363 ); 363 );
364 }; 364 };
365 365
366 $scope.seleccionarCliente = function() { 366 $scope.seleccionarCliente = function() {
367 if ($scope.cobranza.id === undefined) { 367 if ($scope.cobranza.id === undefined) {
368 $scope.seleccionarCobrador(function() { 368 var modalInstance = $uibModal.open(
369 var modalInstance = $uibModal.open( 369 {
370 { 370 ariaLabelledBy: 'Busqueda de Cliente',
371 ariaLabelledBy: 'Busqueda de Cliente', 371 templateUrl: 'foca-busqueda-cliente-modal.html',
372 templateUrl: 'foca-busqueda-cliente-modal.html', 372 controller: 'focaBusquedaClienteModalController',
373 controller: 'focaBusquedaClienteModalController', 373 resolve: {
374 resolve: { 374 vendedor: function() { return null; },
375 vendedor: function() { return null; }, 375 cobrador: function() { return null; }
376 cobrador: function() { return $scope.cobranza.cobrador; } 376 },
377 }, 377 size: 'lg'
378 size: 'lg' 378 }
379 } 379 );
380 ); 380 modalInstance.result.then(
381 modalInstance.result.then( 381 function(cliente) {
382 function(cliente) { 382 //ELIMINO CLIENTE
383 383 $scope.$broadcast('removeCabecera', 'Cliente:');
384 var clienteMayus = { 384 $scope.cobranza.cliente = {};
385 COD: cliente.cod, 385
386 NOM: cliente.nom, 386 var clienteMayus = {
387 CUIT: cliente.cuit, 387 COD: cliente.cod,
388 MAIL: cliente.mail, 388 NOM: cliente.nom,
389 DOM: cliente.DOM, 389 CUIT: cliente.cuit,
390 LOC: cliente.LOC, 390 MAIL: cliente.mail,
391 PCI: cliente.PCI 391 DOM: cliente.DOM,
392 }; 392 LOC: cliente.LOC,
393 console.log(clienteMayus); 393 PCI: cliente.PCI,
394 $scope.$broadcast('addCabecera', { 394 idCobrador: cliente.idCobrador,
395 label: 'Cliente:', 395 cobrador: cliente.cobrador
396 valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + 396 };
397 clienteMayus.NOM 397 $scope.$broadcast('addCabecera', {
398 }); 398 label: 'Cobrador:',
399 399 valor: $filter('rellenarDigitos')(clienteMayus.cobrador.NUM, 3) +
400 $filter('filter')($scope.botonera, 400 ' - ' + clienteMayus.cobrador.NOM
401 { label: 'Cliente'})[0].checked = true; 401 });
402 402 $scope.cobranza.cobrador = clienteMayus.cobrador;
403 $scope.cobranza.cliente = clienteMayus;
404 $scope.cobranza.facturas = [];
405 }, function() {
406 if (APP !== 'cobranza') $scope.seleccionarCliente();
407 }
408 );
409 });
410 } else {
411 focaModalService.alert('Esta cobranza no se puede editar');
412 return;
413 }
414 };
415 403
416 $scope.seleccionarCobrador = function(callback) { 404 $scope.$broadcast('addCabecera', {
405 label: 'Cliente:',
406 valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' +
407 clienteMayus.NOM
408 });
417 409
418 if (APP === 'cobranza') { 410 $filter('filter')($scope.botonera,
419 callback(); 411 { label: 'Cliente'})[0].checked = true;
420 return;
421 }
422 412
423 var parametrosModal = { 413 $scope.cobranza.cliente = clienteMayus;
424 query: '/cobrador', 414 $scope.cobranza.facturas = [];
425 columnas: [ 415 focaCrearCobranzaService
426 { 416 .getCobradorById($scope.cobranza.cliente.idCobrador);
427 propiedad: 'NUM', 417 }, function() {
428 nombre: 'Codigo',
429 filtro: {
430 nombre: 'rellenarDigitos',
431 parametro: 3
432 }
433 },
434 {
435 propiedad: 'NOM',
436 nombre: 'Nombre'
437 } 418 }
438 ], 419 );
439 titulo:'Búsqueda de cobradores' 420 } else {
440 }; 421 focaModalService.alert('Esta cobranza no se puede editar');
441 focaModalService.modal(parametrosModal).then( 422 return;
442 function(cobrador) { 423 }
443 $scope.$broadcast('addCabecera', {
444 label: 'Cobrador:',
445 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' +
446 cobrador.NOM
447 });
448 $scope.cobranza.cobrador = cobrador;
449
450 //ELIMINO CLIENTE
451 $scope.$broadcast('removeCabecera', 'Cliente:');
452 $scope.cobranza.cliente = {};
453
454 callback();
455 }, function() {}
456 );
457 }; 424 };
458 425
459 $scope.seleccionarFactura = function() { 426 $scope.seleccionarFactura = function() {
460 if ($scope.cobranza.id === undefined) { 427 if ($scope.cobranza.id === undefined) {
461 if (!$scope.cobranza.cliente.COD) { 428 if (!$scope.cobranza.cliente.COD) {
462 focaModalService.alert('Seleccione primero un cliente'); 429 focaModalService.alert('Seleccione primero un cliente');
463 return; 430 return;
464 } 431 }
465 var modalInstance = $uibModal.open( 432 var modalInstance = $uibModal.open(
466 { 433 {
467 ariaLabelledBy: 'Busqueda de Facturas', 434 ariaLabelledBy: 'Busqueda de Facturas',
468 templateUrl: 'foca-modal-factura.html', 435 templateUrl: 'foca-modal-factura.html',
469 controller: 'focaModalFacturaController', 436 controller: 'focaModalFacturaController',
470 size: 'lg', 437 size: 'lg',
471 resolve: { 438 resolve: {
472 parametrosFactura: function() { 439 parametrosFactura: function() {
473 return { 440 return {
474 cliente: $scope.cobranza.cliente, 441 cliente: $scope.cobranza.cliente,
475 simbolo: $scope.cobranza.moneda.SIMBOLO, 442 simbolo: $scope.cobranza.moneda.SIMBOLO,
476 cotizacion: $scope.cobranza.moneda, 443 cotizacion: $scope.cobranza.moneda,
477 moneda: $scope.cobranza.moneda.ID 444 moneda: $scope.cobranza.moneda.ID
478 }; 445 };
479 } 446 }
480 } 447 }
481 } 448 }
482 ); 449 );
483 modalInstance.result.then( 450 modalInstance.result.then(
484 function(facturas) { 451 function(facturas) {
485 var facturasResult = []; 452 var facturasResult = [];
486 //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS 453 //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS
487 facturas.forEach(function(factura) { 454 facturas.forEach(function(factura) {
488 var existe = $scope.cobranza.facturas.filter(function(e) { 455 var existe = $scope.cobranza.facturas.filter(function(e) {
489 return angular.equals(factura, e); 456 return angular.equals(factura, e);
490 }); 457 });
491 458
492 if (!existe.length) facturasResult.push(factura); 459 if (!existe.length) facturasResult.push(factura);
493 }); 460 });
494 461
495 $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); 462 $scope.cobranza.facturas =
463 $scope.cobranza.facturas.concat(facturasResult);
496 }, function() { } 464 }, function() { }
497 ); 465 );
498 } else { 466 } else {
499 focaModalService.alert('Esta cobranza no se puede editar'); 467 focaModalService.alert('Esta cobranza no se puede editar');
500 return; 468 return;
501 } 469 }
502 470
503 }; 471 };
504 472
505 $scope.seleccionarCheque = function(cheque) { 473 $scope.seleccionarCheque = function(cheque) {
506 if ($scope.cobranza.id === undefined) { 474 if ($scope.cobranza.id === undefined) {
507 var parametros; 475 var parametros;
508 476
509 if (!cheque) { 477 if (!cheque) {
510 parametros = { 478 parametros = {
511 importe: getSugerido(), 479 importe: getSugerido(),
512 esNuevo : true 480 esNuevo : true
513 }; 481 };
514 } else { 482 } else {
515 parametros = cheque; 483 parametros = cheque;
516 parametros.importe = cheque.IMP; 484 parametros.importe = cheque.IMP;
517 } 485 }
518 486
519 var modalInstance = $uibModal.open( 487 var modalInstance = $uibModal.open(
520 { 488 {
521 ariaLabelledBy: 'Carga de cheques', 489 ariaLabelledBy: 'Carga de cheques',
522 templateUrl: 'modal-cheque.html', 490 templateUrl: 'modal-cheque.html',
523 controller: 'focaModalChequeController', 491 controller: 'focaModalChequeController',
524 size: 'lg', 492 size: 'lg',
525 resolve: { 493 resolve: {
526 cheque: function() { 494 cheque: function() {
527 return parametros; 495 return parametros;
528 } 496 }
529 } 497 }
530 } 498 }
531 ); 499 );
532 modalInstance.result.then( 500 modalInstance.result.then(
533 function(cheque) { 501 function(cheque) {
534 var cobro = { 502 var cobro = {
535 COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, 503 COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
536 numero: cheque.numero, 504 numero: cheque.numero,
537 banco: cheque.banco, 505 banco: cheque.banco,
538 FEC: cheque.fechaEmision.toLocaleDateString() + '-' + 506 FEC: cheque.fechaEmision.toLocaleDateString() + '-' +
539 cheque.fechaPresentacion.toLocaleDateString(), 507 cheque.fechaPresentacion.toLocaleDateString(),
540 fechaPresentacion: cheque.fechaPresentacion, 508 fechaPresentacion: cheque.fechaPresentacion,
541 fechaEmision: cheque.fechaEmision, 509 fechaEmision: cheque.fechaEmision,
542 IMP: cheque.importe, 510 IMP: cheque.importe,
543 localidad: cheque.localidad, 511 localidad: cheque.localidad,
544 librador: cheque.librador, 512 librador: cheque.librador,
545 provincia: cheque.provincia, 513 provincia: cheque.provincia,
546 observaciones: cheque.observaciones, 514 observaciones: cheque.observaciones,
547 TIL: 'EF' 515 TIL: 'EF'
548 }; 516 };
549 pushearCobro(cobro, cheque.$$hashKey); 517 pushearCobro(cobro, cheque.$$hashKey);
550 }, function() { 518 }, function() {
551 519
552 } 520 }
553 ); 521 );
554 } else { 522 } else {
555 focaModalService.alert('Esta cobranza no se puede editar'); 523 focaModalService.alert('Esta cobranza no se puede editar');
556 return; 524 return;
557 } 525 }
558 526
559 }; 527 };
560 528
561 $scope.seleccionarEfectivo = function() { 529 $scope.seleccionarEfectivo = function() {
562 if ($scope.cobranza.id === undefined) { 530 if ($scope.cobranza.id === undefined) {
563 var importe = 0; 531 var importe = 0;
564 $scope.cobranza.cobros.filter(function(a) { 532 $scope.cobranza.cobros.filter(function(a) {
565 if (a.COM === 'Efectivo') { 533 if (a.COM === 'Efectivo') {
566 importe = a.IMP; 534 importe = a.IMP;
567 } 535 }
568 }); 536 });
569 537
570 var modalInstance = $uibModal.open( 538 var modalInstance = $uibModal.open(
571 { 539 {
572 ariaLabelledBy: 'Carga de cheques', 540 ariaLabelledBy: 'Carga de cheques',
573 templateUrl: 'modal-efectivo.html', 541 templateUrl: 'modal-efectivo.html',
574 controller: 'focaModalEfectivoController', 542 controller: 'focaModalEfectivoController',
575 size: 'sm', 543 size: 'sm',
576 resolve: { 544 resolve: {
577 sugerido: function() { 545 sugerido: function() {
578 return parseFloat(getSugerido()) + parseFloat(importe); 546 return parseFloat(getSugerido()) + parseFloat(importe);
579 } 547 }
580 } 548 }
581 } 549 }
582 ); 550 );
583 modalInstance.result.then( 551 modalInstance.result.then(
584 function(efectivo) { 552 function(efectivo) {
585 553
586 var cobro = { 554 var cobro = {
587 COM: 'Efectivo', 555 COM: 'Efectivo',
588 FEC: new Date(), 556 FEC: new Date(),
589 IMP: efectivo, 557 IMP: efectivo,
590 TIL: 'EF' 558 TIL: 'EF'
591 }; 559 };
592 560
593 $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { 561 $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) {
594 return a.COM !== 'Efectivo'; 562 return a.COM !== 'Efectivo';
595 }); 563 });
596 564
597 $scope.cobranza.cobros.push(cobro); 565 $scope.cobranza.cobros.push(cobro);
598 }, function() { 566 }, function() {
599 567
600 } 568 }
601 ); 569 );
602 } else { 570 } else {
603 focaModalService.alert('Esta cobranza no se puede editar'); 571 focaModalService.alert('Esta cobranza no se puede editar');
604 return; 572 return;
605 } 573 }
606 }; 574 };
607 575
608 $scope.seleccionarDetalles = function(detalle) { 576 $scope.seleccionarDetalles = function(detalle) {
609 if ($scope.cobranza.id === undefined) { 577 if ($scope.cobranza.id === undefined) {
610 var parametro = {}; 578 var parametro = {};
611 579
612 if (!detalle) { 580 if (!detalle) {
613 parametro = { 581 parametro = {
614 importe: getSugerido(), 582 importe: getSugerido(),
615 files: [] 583 files: []
616 }; 584 };
617 } else { 585 } else {
618 parametro = detalle; 586 parametro = detalle;
619 parametro.importe = detalle.IMP; 587 parametro.importe = detalle.IMP;
620 parametro.files= detalle.imgs; 588 parametro.files= detalle.imgs;
621 } 589 }
622 590
623 var modalInstance = $uibModal.open( 591 var modalInstance = $uibModal.open(
624 { 592 {
625 ariaLabelledBy: 'Carga de detalles', 593 ariaLabelledBy: 'Carga de detalles',
626 templateUrl: 'modal-detalles.html', 594 templateUrl: 'modal-detalles.html',
627 controller: 'focaModalDetallesController', 595 controller: 'focaModalDetallesController',
628 size: 'lg', 596 size: 'lg',
629 resolve: { 597 resolve: {
630 parametros: function() { 598 parametros: function() {
631 return parametro; 599 return parametro;
632 } 600 }
633 } 601 }
634 } 602 }
635 ); 603 );
636 modalInstance.result.then( 604 modalInstance.result.then(
637 function(detalles) { 605 function(detalles) {
638 606
639 var cobro = { 607 var cobro = {
640 COM: 'de(COBRO POR DETALLES)', 608 COM: 'de(COBRO POR DETALLES)',
641 FEC: new Date(), 609 FEC: new Date(),
642 IMP: detalles.importe, 610 IMP: detalles.importe,
643 imgs: detalles.files, 611 imgs: detalles.files,
644 TIL: 'DE', 612 TIL: 'DE',
645 observacion: detalles.observacion 613 observacion: detalles.observacion
646 }; 614 };
647 pushearCobro(cobro, detalles.$$hashKey); 615 pushearCobro(cobro, detalles.$$hashKey);
648 }, function() {} 616 }, function() {}
649 ); 617 );
650 } else { 618 } else {
651 focaModalService.alert('Esta cobranza no se puede editar'); 619 focaModalService.alert('Esta cobranza no se puede editar');
652 return; 620 return;
653 } 621 }
654 }; 622 };
655 623
656 $scope.seleccionarMoneda = function() { 624 $scope.seleccionarMoneda = function() {
657 if ($scope.cobranza.id === undefined) { 625 if ($scope.cobranza.id === undefined) {
658 var parametrosModal = { 626 var parametrosModal = {
659 titulo: 'Búsqueda de monedas', 627 titulo: 'Búsqueda de monedas',
660 query: '/moneda', 628 query: '/moneda',
661 columnas: [ 629 columnas: [
662 { 630 {
663 propiedad: 'DETALLE', 631 propiedad: 'DETALLE',
664 nombre: 'Nombre' 632 nombre: 'Nombre'
665 }, 633 },
666 { 634 {
667 propiedad: 'SIMBOLO', 635 propiedad: 'SIMBOLO',
668 nombre: 'Símbolo' 636 nombre: 'Símbolo'
669 } 637 }
670 ], 638 ],
671 size: 'md' 639 size: 'md'
672 }; 640 };
673 focaModalService.modal(parametrosModal).then( 641 focaModalService.modal(parametrosModal).then(
674 function(moneda) { 642 function(moneda) {
675 $scope.seleccionarCotizacion(moneda); 643 $scope.seleccionarCotizacion(moneda);
676 }, function() { 644 }, function() {
677 645
678 } 646 }
679 ); 647 );
680 } else { 648 } else {
681 focaModalService.alert('Esta cobranza no se puede editar'); 649 focaModalService.alert('Esta cobranza no se puede editar');
682 return; 650 return;
683 } 651 }
684 652
685 }; 653 };
686 654
687 $scope.seleccionarCotizacion = function(moneda) { 655 $scope.seleccionarCotizacion = function(moneda) {
688 var modalInstance = $uibModal.open( 656 var modalInstance = $uibModal.open(
689 { 657 {
690 ariaLabelledBy: 'Busqueda de Cotización', 658 ariaLabelledBy: 'Busqueda de Cotización',
691 templateUrl: 'modal-cotizacion.html', 659 templateUrl: 'modal-cotizacion.html',
692 controller: 'focaModalCotizacionController', 660 controller: 'focaModalCotizacionController',
693 size: 'lg', 661 size: 'lg',
694 resolve: {idMoneda: function() {return moneda.ID;}} 662 resolve: {idMoneda: function() {return moneda.ID;}}
695 } 663 }
696 ); 664 );
697 modalInstance.result.then( 665 modalInstance.result.then(
698 function(cotizacion) { 666 function(cotizacion) {
699 $scope.cobranza.moneda = moneda; 667 $scope.cobranza.moneda = moneda;
700 $scope.cobranza.moneda.cotizacion = cotizacion; 668 $scope.cobranza.moneda.cotizacion = cotizacion;
701 if (moneda.DETALLE === 'PESOS ARGENTINOS') { 669 if (moneda.DETALLE === 'PESOS ARGENTINOS') {
702 $scope.$broadcast('removeCabecera', 'Moneda:'); 670 $scope.$broadcast('removeCabecera', 'Moneda:');
703 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 671 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
704 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 672 $scope.$broadcast('removeCabecera', 'Cotizacion:');
705 } else { 673 } else {
706 $scope.$broadcast('addCabecera', { 674 $scope.$broadcast('addCabecera', {
707 label: 'Moneda:', 675 label: 'Moneda:',
708 valor: moneda.DETALLE 676 valor: moneda.DETALLE
709 }); 677 });
710 $scope.$broadcast('addCabecera', { 678 $scope.$broadcast('addCabecera', {
711 label: 'Fecha cotizacion:', 679 label: 'Fecha cotizacion:',
712 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 680 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
713 }); 681 });
714 $scope.$broadcast('addCabecera', { 682 $scope.$broadcast('addCabecera', {
715 label: 'Cotizacion:', 683 label: 'Cotizacion:',
716 valor: $filter('number')(cotizacion.VENDEDOR, '2') 684 valor: $filter('number')(cotizacion.VENDEDOR, '2')
717 }); 685 });
718 } 686 }
719 687
720 $filter('filter')( $scope.botonera, { 688 $filter('filter')( $scope.botonera, {
721 label: 'Moneda' 689 label: 'Moneda'
722 })[0].checked = true; 690 })[0].checked = true;
723 691
724 }, function() { 692 }, function() {
725 693
726 } 694 }
727 ); 695 );
728 }; 696 };
729 697
730 $scope.getTotalDeuda = function() { 698 $scope.getTotalDeuda = function() {
731 var total = 0; 699 var total = 0;
732 for (var i = 0; i < $scope.cobranza.facturas.length; i++) { 700 for (var i = 0; i < $scope.cobranza.facturas.length; i++) {
733 total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; 701 total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA;
734 } 702 }
735 return parseFloat(total.toFixed(2)); 703 return parseFloat(total.toFixed(2));
736 }; 704 };
737 705
738 $scope.getTotalCobrado = function() { 706 $scope.getTotalCobrado = function() {
739 var total = 0; 707 var total = 0;
740 for (var i = 0; i < $scope.cobranza.cobros.length; i++) { 708 for (var i = 0; i < $scope.cobranza.cobros.length; i++) {
741 total += $scope.cobranza.cobros[i].IMP; 709 total += $scope.cobranza.cobros[i].IMP;
742 } 710 }
743 return parseFloat(total.toFixed(2)); 711 return parseFloat(total.toFixed(2));
744 }; 712 };
745 713
746 $scope.getSubTotal = function() { 714 $scope.getSubTotal = function() {
747 if ($scope.articuloACargar) { 715 if ($scope.articuloACargar) {
748 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 716 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
749 } 717 }
750 }; 718 };
751 //Recibe aviso si el teclado está en uso 719 //Recibe aviso si el teclado está en uso
752 // $rootScope.$on('usarTeclado', function(event, data) { 720 // $rootScope.$on('usarTeclado', function(event, data) {
753 // if(data) { 721 // if(data) {
754 // $scope.mostrarTeclado = true; 722 // $scope.mostrarTeclado = true;
755 // return; 723 // return;
756 // } 724 // }
757 // $scope.mostrarTeclado = false; 725 // $scope.mostrarTeclado = false;
758 // }) 726 // })
759 $scope.selectFocus = function($event) { 727 $scope.selectFocus = function($event) {
760 //Si el teclado esta en uso no selecciona el valor 728 //Si el teclado esta en uso no selecciona el valor
761 // if($scope.mostrarTeclado) { 729 // if($scope.mostrarTeclado) {
762 // return; 730 // return;
763 // } 731 // }
764 $event.target.select(); 732 $event.target.select();
765 }; 733 };
766 734
767 $scope.salir = function() { 735 $scope.salir = function() {
768 $location.path('/'); 736 $location.path('/');
769 }; 737 };
770 738
771 $scope.parsearATexto = function(articulo) { 739 $scope.parsearATexto = function(articulo) {
772 articulo.cantidad = parseFloat(articulo.cantidad); 740 articulo.cantidad = parseFloat(articulo.cantidad);
773 articulo.precio = parseFloat(articulo.precio); 741 articulo.precio = parseFloat(articulo.precio);
774 }; 742 };
775 743
776 $scope.quitarFactura = function(key) { 744 $scope.quitarFactura = function(key) {
777 if ($scope.cobranza.id === undefined) { 745 if ($scope.cobranza.id === undefined) {
778 $scope.cobranza.facturas.splice(key, 1); 746 $scope.cobranza.facturas.splice(key, 1);
779 } else { 747 } else {
780 focaModalService.alert('Esta comprobante no se puede eliminar'); 748 focaModalService.alert('Esta comprobante no se puede eliminar');
781 return; 749 return;
782 } 750 }
783 }; 751 };
784 752
785 $scope.quitarCobro = function(key) { 753 $scope.quitarCobro = function(key) {
786 if ($scope.cobranza.id === undefined) { 754 if ($scope.cobranza.id === undefined) {
787 $scope.cobranza.cobros.splice(key, 1); 755 $scope.cobranza.cobros.splice(key, 1);
788 } else { 756 } else {
789 focaModalService.alert('Esta comprobante no se puede eliminar'); 757 focaModalService.alert('Esta comprobante no se puede eliminar');
790 return; 758 return;
791 } 759 }
792 }; 760 };
793 761
794 $scope.editarCobro = function(cobro) { 762 $scope.editarCobro = function(cobro) {
795 if(cobro.COM === 'Efectivo') { 763 if(cobro.COM === 'Efectivo') {
796 $scope.seleccionarEfectivo(); 764 $scope.seleccionarEfectivo();
797 } else if(cobro.COM.substring(0, 2) === 'de') { 765 } else if(cobro.COM.substring(0, 2) === 'de') {
798 $scope.seleccionarDetalles(cobro); 766 $scope.seleccionarDetalles(cobro);
799 } else if(cobro.COM.substring(0, 2) === 'ch') { 767 } else if(cobro.COM.substring(0, 2) === 'ch') {
800 $scope.seleccionarCheque(cobro); 768 $scope.seleccionarCheque(cobro);
801 } 769 }
802 }; 770 };
803 771
804 $scope.$watch('cobranza.facturas', function() { 772 $scope.$watch('cobranza.facturas', function() {
805 if ($scope.cobranza.facturas.length) { 773 if ($scope.cobranza.facturas.length) {
806 $filter('filter')( $scope.botonera, { 774 $filter('filter')( $scope.botonera, {
807 label: 'Comprobantes' 775 label: 'Comprobantes'
808 })[0].checked = true; 776 })[0].checked = true;
809 } else { 777 } else {
810 $filter('filter')( $scope.botonera, { 778 $filter('filter')( $scope.botonera, {
811 label: 'Comprobantes' 779 label: 'Comprobantes'
812 })[0].checked = false; 780 })[0].checked = false;
813 } 781 }
814 }, true); 782 }, true);
815 783
816 $scope.$watch('cobranza.cobros', function() { 784 $scope.$watch('cobranza.cobros', function() {
817 if ($scope.cobranza.cobros.length) { 785 if ($scope.cobranza.cobros.length) {
818 $filter('filter')( $scope.botonera, { 786 $filter('filter')( $scope.botonera, {
819 label: 'Cobros' 787 label: 'Cobros'
820 })[0].checked = true; 788 })[0].checked = true;
821 } else { 789 } else {
822 $filter('filter')( $scope.botonera, { 790 $filter('filter')( $scope.botonera, {
823 label: 'Cobros' 791 label: 'Cobros'
824 })[0].checked = false; 792 })[0].checked = false;
825 } 793 }
826 }, true); 794 }, true);
827 795
828 function pushearCobro(cobro, hashKey) { 796 function pushearCobro(cobro, hashKey) {
829 var existe; 797 var existe;
830 798
831 $scope.cobranza.cobros.forEach(function(c, idx) { 799 $scope.cobranza.cobros.forEach(function(c, idx) {
832 if(c.$$hashKey === hashKey) { 800 if(c.$$hashKey === hashKey) {
833 $scope.cobranza.cobros[idx] = cobro; 801 $scope.cobranza.cobros[idx] = cobro;
834 existe = true; 802 existe = true;
835 } 803 }
836 }); 804 });
837 if (!existe) { 805 if (!existe) {
838 $scope.cobranza.cobros.push(cobro); 806 $scope.cobranza.cobros.push(cobro);
839 } 807 }
840 } 808 }
841 809
842 function salir() { 810 function salir() {
843 var confirmacion = false; 811 var confirmacion = false;
844 812
845 if (!angular.equals($scope.cobranza, $scope.inicial)) { 813 if (!angular.equals($scope.cobranza, $scope.inicial)) {
846 confirmacion = true; 814 confirmacion = true;
847 } 815 }
848 816
849 if (confirmacion) { 817 if (confirmacion) {
850 focaModalService.confirm( 818 focaModalService.confirm(
851 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 819 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
852 ).then(function(data) { 820 ).then(function(data) {
853 if (data) { 821 if (data) {
854 $location.path('/'); 822 $location.path('/');
855 } 823 }
856 }); 824 });
857 } else { 825 } else {
858 $location.path('/'); 826 $location.path('/');
859 } 827 }
860 } 828 }
861 829
862 function setearCobranza(cobranza) { 830 function setearCobranza(cobranza) {
863 $scope.editando = true; 831 $scope.editando = true;
864 $scope.$broadcast('cleanCabecera'); 832 $scope.$broadcast('cleanCabecera');
865 833
866 if (cobranza.cliente) { 834 if (cobranza.cliente) {
867 $scope.$broadcast('addCabecera', { 835 $scope.$broadcast('addCabecera', {
868 label: 'Cliente:', 836 label: 'Cliente:',
869 valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' + 837 valor: $filter('rellenarDigitos')(cobranza.cliente.COD, 5) + ' - ' +
870 cobranza.cliente.NOM 838 cobranza.cliente.NOM
871 }); 839 });
872 840
873 $filter('filter')( $scope.botonera, { 841 $filter('filter')( $scope.botonera, {
874 label: 'Cliente' 842 label: 'Cliente'
875 })[0].checked = true; 843 })[0].checked = true;
876 } 844 }
877 if (cobranza.cobrador && cobranza.cobrador.NUM) { 845 if (cobranza.cobrador && cobranza.cobrador.NUM) {
878 $scope.$broadcast('addCabecera', { 846 $scope.$broadcast('addCabecera', {
879 label: 'Cobrador:', 847 label: 'Cobrador:',
880 valor: (cobranza.cobrador.NUM) ? 848 valor: (cobranza.cobrador.NUM) ?
881 $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' + 849 $filter('rellenarDigitos')(cobranza.cobrador.NUM, 5) + ' - ' +
882 cobranza.cobrador.NOM : cobranza.cobrador 850 cobranza.cobrador.NOM : cobranza.cobrador
883 851
884 }); 852 });
885 } 853 }
886 854
887 // TODO: Setear moneda 855 // TODO: Setear moneda
888 if (cobranza.moneda) { 856 if (cobranza.moneda) {
889 $filter('filter')( $scope.botonera, { 857 $filter('filter')( $scope.botonera, {
890 label: 'Moneda' 858 label: 'Moneda'
891 })[0].checked = true; 859 })[0].checked = true;
892 } 860 }
893 861
894 $scope.cobranza = cobranza; 862 $scope.cobranza = cobranza;
895 } 863 }
896 864
897 function getLSCobranza() { 865 function getLSCobranza() {
898 var cobranza = JSON.parse($localStorage.cobranza || null); 866 var cobranza = JSON.parse($localStorage.cobranza || null);
899 if (cobranza) { 867 if (cobranza) {
900 setearCobranza(cobranza); 868 setearCobranza(cobranza);
901 delete $localStorage.cobranza; 869 delete $localStorage.cobranza;
902 } 870 }
903 } 871 }
904 872
905 function enviarMail(recibo) { 873 function enviarMail(recibo) {
906 focaModalService.mail( 874 focaModalService.mail(
907 { 875 {
908 titulo: 'Enviar recibo', 876 titulo: 'Enviar recibo',
909 descarga: { 877 descarga: {
910 nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf', 878 nombre: recibo.recibo.PVE + '-' + recibo.recibo.NCO + '.pdf',
911 url: '/mail/recibo/descargar', 879 url: '/mail/recibo/descargar',
912 }, 880 },
913 envio: { 881 envio: {
914 mailCliente: recibo.cliente.MAIL, 882 mailCliente: recibo.cliente.MAIL,
915 url: '/mail/recibo', 883 url: '/mail/recibo',
916 }, 884 },
917 options: { 885 options: {
918 recibo: recibo 886 recibo: recibo
919 } 887 }
920 } 888 }
921 ); 889 );
922 } 890 }
923 891
924 function getSugerido() { 892 function getSugerido() {
925 var result; 893 var result;
926 894
927 var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); 895 var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado();
928 896
929 if (valor < 0) { 897 if (valor < 0) {
930 result = Math.abs(valor).toFixed(4); 898 result = Math.abs(valor).toFixed(4);
931 } 899 }
932 900