Commit 628295ece3b9455eb32a1830b3419c18bec1450d

Authored by Marcelo Puebla
Exists in master and in 1 other branch develop

Merge remote-tracking branch 'origin/master'

1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const clean = require('gulp-clean'); 2 const clean = require('gulp-clean');
3 const concat = require('gulp-concat'); 3 const concat = require('gulp-concat');
4 const htmlmin = require('gulp-htmlmin'); 4 const htmlmin = require('gulp-htmlmin');
5 const rename = require('gulp-rename'); 5 const rename = require('gulp-rename');
6 const uglify = require('gulp-uglify'); 6 const uglify = require('gulp-uglify');
7 const gulp = require('gulp'); 7 const gulp = require('gulp');
8 const pump = require('pump'); 8 const pump = require('pump');
9 const jshint = require('gulp-jshint'); 9 const jshint = require('gulp-jshint');
10 const replace = require('gulp-replace'); 10 const replace = require('gulp-replace');
11 const connect = require('gulp-connect'); 11 const connect = require('gulp-connect');
12 const header = require('gulp-header');
13 const footer = require('gulp-footer');
14 const gulpSequence = require('gulp-sequence');
12 15
13 var paths = { 16 var paths = {
14 srcJS: 'src/js/*.js', 17 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 18 srcViews: 'src/views/*.html',
19 specs: 'spec/*.js',
16 tmp: 'tmp', 20 tmp: 'tmp',
17 dist: 'dist/' 21 dist: 'dist/'
18 }; 22 };
19 23
24 gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app'));
25
20 gulp.task('templates', ['clean'], function() { 26 gulp.task('templates', ['clean'], function() {
21 return pump( 27 return pump(
22 [ 28 [
23 gulp.src(paths.srcViews), 29 gulp.src(paths.srcViews),
24 htmlmin(), 30 htmlmin(),
25 templateCache('views.js', { 31 templateCache('views.js', {
26 module: 'focaCrearRemito', 32 module: 'focaCrearRemito',
27 root: '' 33 root: ''
28 }), 34 }),
29 gulp.dest(paths.tmp) 35 gulp.dest(paths.tmp)
30 ] 36 ]
31 ); 37 );
32 }); 38 });
33 39
34 gulp.task('uglify', ['templates'], function() { 40 gulp.task('uglify-app', function() {
35 return pump( 41 return pump(
36 [ 42 [
37 gulp.src([ 43 gulp.src([
38 paths.srcJS, 44 paths.srcJS,
39 'tmp/views.js' 45 'tmp/views.js'
40 ]), 46 ]),
41 concat('foca-crear-remito.js'), 47 concat('foca-crear-remito.js'),
42 replace('src/views/', ''), 48 replace('src/views/', ''),
43 gulp.dest(paths.tmp), 49 gulp.dest(paths.tmp),
44 rename('foca-crear-remito.min.js'), 50 rename('foca-crear-remito.min.js'),
45 uglify(), 51 uglify(),
46 gulp.dest(paths.dist) 52 gulp.dest(paths.dist)
47 ] 53 ]
48 ); 54 );
49 }); 55 });
50 56
57 gulp.task('uglify-spec', function() {
58 return pump(
59 [
60 gulp.src(paths.specs),
61 concat('foca-crear-remito.spec.js'),
62 replace('src/views/', ''),
63 header("describe('Módulo foca-crear-remito', function() { \n"),
64 footer("});"),
65 gulp.dest(paths.dist)
66 ]
67 );
68 });
69
51 gulp.task('clean', function() { 70 gulp.task('clean', function() {
52 return gulp.src(['tmp', 'dist'], {read: false}) 71 return gulp.src(['tmp', 'dist'], {read: false})
53 .pipe(clean()); 72 .pipe(clean());
54 }); 73 });
55 74
56 gulp.task('pre-commit', function() { 75 gulp.task('pre-commit', function() {
57 return pump( 76 return pump(
58 [ 77 [
59 gulp.src(paths.srcJS), 78 gulp.src([paths.srcJS, paths.specs]),
60 jshint('.jshintrc'), 79 jshint('.jshintrc'),
61 jshint.reporter('default'), 80 jshint.reporter('default'),
62 jshint.reporter('fail') 81 jshint.reporter('fail')
63 ] 82 ]
64 ); 83 );
65 84
66 gulp.start('uglify'); 85 gulp.start('uglify');
67 }); 86 });
68 87
69 gulp.task('webserver', function() { 88 gulp.task('webserver', function() {
70 pump [ 89 pump [
71 connect.server({port: 3300, host: '0.0.0.0'}) 90 connect.server({port: 3300, host: '0.0.0.0'})
72 ] 91 ]
73 }); 92 });
74 93
75 gulp.task('clean-post-install', function() { 94 gulp.task('clean-post-install', function() {
76 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 95 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
77 'index.html'], {read: false}) 96 'index.html'], {read: false})
78 .pipe(clean()); 97 .pipe(clean());
79 }); 98 });
80 99
81 gulp.task('default', ['webserver']); 100 gulp.task('default', ['webserver']);
82 101
83 gulp.task('watch', function() { 102 gulp.task('watch', function() {
84 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 103 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
85 }); 104 });
86 105
87 gulp.task('copy', ['uglify'], function() { 106 gulp.task('copy', ['uglify'], function() {
88 return gulp.src('dist/*.js') 107 return gulp.src('dist/*.js')
89 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/')); 108 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/'));
90 }); 109 });
91 110
92 gulp.task('watchAndCopy', function() { 111 gulp.task('watchAndCopy', function() {
93 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); 112 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
94 }); 113 });
95 114
spec/controllerSpec.js
1 describe('Controlador modulo crear remito', function() {
2
3 var $controller;
4
5 beforeEach(function() {
6
7 module('focaCrearRemito');
8
9 inject(function(_$controller_) {
10 $controller = _$controller_;
11 });
12 });
13
14 describe('Controlador remitoController', function() {
15
16 var timeout;
17
18 beforeEach(function() {
19
20 inject(function($timeout) {
21 timeout = $timeout;
22 });
23 });
24
25 it('Existe el controlador remitoController', function() {
26
27 //act
28 var controlador = $controller('remitoController', {
29 $scope: {
30 $broadcast: function() { },
31 $watch: function() { }
32 },
33 $uibModal: {},
34 $location: {},
35 $filter: {},
36 crearRemitoService: {
37 getBotonera: function() { },
38 getCotizacionByIdMoneda: function() {
39 return {
40 then: function() { }
41 };
42 },
43 getNumeroRemito: function() {
44 return {
45 then: function() { }
46 };
47 }
48 },
49 $timeout: timeout,
50 focaModalService: {},
51 remitoBusinessService: {},
52 $rootScope: {
53 $on: function() { }
54 },
55 focaBotoneraLateralService: {},
56 $localStorage: {}
57 });
58
59 //assert
60 expect(typeof controlador).toEqual('object');
61
62 });
63
64 it('seleccionarNotaPedido levanta modal', function() {
65
66 //arrange
67 var scope = {
68 $broadcast: function() { },
69 $watch: function() { }
70 };
71 var uibModal = {
72 open: function() { }
73 };
74
75 $controller('remitoController', {
76 $scope: scope,
77 $uibModal: uibModal,
78 $location: {},
79 $filter: {},
80 crearRemitoService: {
81 getBotonera: function() { },
82 getCotizacionByIdMoneda: function() {
83 return {
84 then: function() { }
85 };
86 },
87 getNumeroRemito: function() {
88 return {
89 then: function() { }
90 };
91 }
92 },
93 $timeout: timeout,
94 focaModalService: {},
95 remitoBusinessService: {},
96 $rootScope: {
97 $on: function() { }
98 },
99 focaBotoneraLateralService: {},
100 $localStorage: {}
101 });
102
103 //act
104 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
105 spyOn(scope, 'seleccionarNotaPedido');
106 scope.seleccionarNotaPedido();
107
108 //assert
109 expect(scope.seleccionarNotaPedido).toHaveBeenCalled();
110
111 });
112
113 it('seleccionarRemito levanta modal', function() {
114
115 //arrange
116 var scope = {
117 $broadcast: function() { },
118 $watch: function() { }
119 };
120 var uibModal = {
121 open: function() { }
122 };
123
124 $controller('remitoController', {
125 $scope: scope,
126 $uibModal: uibModal,
127 $location: {},
128 $filter: {},
129 crearRemitoService: {
130 getBotonera: function() { },
131 getCotizacionByIdMoneda: function() {
132 return {
133 then: function() { }
134 };
135 },
136 getNumeroRemito: function() {
137 return {
138 then: function() { }
139 };
140 }
141 },
142 $timeout: timeout,
143 focaModalService: {},
144 remitoBusinessService: {},
145 $rootScope: {
146 $on: function() { }
147 },
148 focaBotoneraLateralService: {},
149 $localStorage: {}
150 });
151
152 //act
153 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
154 spyOn(scope, 'seleccionarRemito');
155 scope.seleccionarRemito();
156
157 //assert
158 expect(scope.seleccionarRemito).toHaveBeenCalled();
159
160 });
161
162 it('crearRemito muestra alerta cuando no se eligió vendedor', function() {
163
164 //arrange
165 var scope = {
166 $broadcast: function() { },
167 $watch: function() { }
168 };
169 var focaModalService = {
170 alert: function() { }
171 };
172
173 $controller('remitoController', {
174 $scope: scope,
175 $uibModal: {},
176 $location: {},
177 $filter: {},
178 crearRemitoService: {
179 getBotonera: function() { },
180 getCotizacionByIdMoneda: function() {
181 return {
182 then: function() { }
183 };
184 },
185 getNumeroRemito: function() {
186 return {
187 then: function() { }
188 };
189 }
190 },
191 $timeout: timeout,
192 focaModalService: focaModalService,
193 remitoBusinessService: {},
194 $rootScope: {
195 $on: function() { }
196 },
197 focaBotoneraLateralService: {},
198 $localStorage: {}
199 });
200
201 //act
202 spyOn(focaModalService, 'alert');
203 scope.crearRemito();
204
205 //assert
206 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor');
207
208 });
209
210 it('crearRemito muestra alerta cuando no se eligió cliente', function() {
211
212 //arrange
213 var scope = {
214 $broadcast: function() { },
215 $watch: function() { }
216 };
217 var focaModalService = {
218 alert: function() { }
219 };
220
221 $controller('remitoController', {
222 $scope: scope,
223 $uibModal: {},
224 $location: {},
225 $filter: {},
226 crearRemitoService: {
227 getBotonera: function() { },
228 getCotizacionByIdMoneda: function() {
229 return {
230 then: function() { }
231 };
232 },
233 getNumeroRemito: function() {
234 return {
235 then: function() { }
236 };
237 }
238 },
239 $timeout: timeout,
240 focaModalService: focaModalService,
241 remitoBusinessService: {},
242 $rootScope: {
243 $on: function() { }
244 },
245 focaBotoneraLateralService: {},
246 $localStorage: {}
247 });
248
249 scope.remito = {
250 vendedor: { NUM: true },
251 cliente: {}
252 };
253
254 //act
255 spyOn(focaModalService, 'alert');
256 scope.crearRemito();
257
258 //assert
259 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente');
260
261 });
262
263 it('crearRemito muestra alerta cuando no se eligió Proveedor', function() {
264
265 //arrange
266 var scope = {
267 $broadcast: function() { },
268 $watch: function() { }
269 };
270 var focaModalService = {
271 alert: function() { }
272 };
273
274 $controller('remitoController', {
275 $scope: scope,
276 $uibModal: {},
277 $location: {},
278 $filter: {},
279 crearRemitoService: {
280 getBotonera: function() { },
281 getCotizacionByIdMoneda: function() {
282 return {
283 then: function() { }
284 };
285 },
286 getNumeroRemito: function() {
287 return {
288 then: function() { }
289 };
290 }
291 },
292 $timeout: timeout,
293 focaModalService: focaModalService,
294 remitoBusinessService: {},
295 $rootScope: {
296 $on: function() { }
297 },
298 focaBotoneraLateralService: {},
299 $localStorage: {}
300 });
301
302 scope.remito = {
303 vendedor: { NUM: true },
304 cliente: { COD: true }
305 };
306
307 //act
308 spyOn(focaModalService, 'alert');
309 scope.crearRemito();
310
311 //assert
312 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor');
313
314 });
315
316 it('crearRemito muestra alerta cuando no se eligió moneda', function() {
317
318 //arrange
319 var scope = {
320 $broadcast: function() { },
321 $watch: function() { }
322 };
323 var focaModalService = {
324 alert: function() { }
325 };
326
327 $controller('remitoController', {
328 $scope: scope,
329 $uibModal: {},
330 $location: {},
331 $filter: {},
332 crearRemitoService: {
333 getBotonera: function() { },
334 getCotizacionByIdMoneda: function() {
335 return {
336 then: function() { }
337 };
338 },
339 getNumeroRemito: function() {
340 return {
341 then: function() { }
342 };
343 }
344 },
345 $timeout: timeout,
346 focaModalService: focaModalService,
347 remitoBusinessService: {},
348 $rootScope: {
349 $on: function() { }
350 },
351 focaBotoneraLateralService: {},
352 $localStorage: {}
353 });
354
355 scope.remito = {
356 vendedor: { NUM: true },
357 cliente: { COD: true },
358 proveedor: {},
359 cotizacion: { moneda: {} }
360 };
361
362 //act
363 spyOn(focaModalService, 'alert');
364 scope.crearRemito();
365
366 //assert
367 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda');
368
369 });
370
371 it('crearRemito muestra alerta cuando no se eligió Cotización', function() {
372
373 //arrange
374 var scope = {
375 $broadcast: function() { },
376 $watch: function() { }
377 };
378 var focaModalService = {
379 alert: function() { }
380 };
381
382 $controller('remitoController', {
383 $scope: scope,
384 $uibModal: {},
385 $location: {},
386 $filter: {},
387 crearRemitoService: {
388 getBotonera: function() { },
389 getCotizacionByIdMoneda: function() {
390 return {
391 then: function() { }
392 };
393 },
394 getNumeroRemito: function() {
395 return {
396 then: function() { }
397 };
398 }
399 },
400 $timeout: timeout,
401 focaModalService: focaModalService,
402 remitoBusinessService: {},
403 $rootScope: {
404 $on: function() { }
405 },
406 focaBotoneraLateralService: {},
407 $localStorage: {}
408 });
409
410 scope.remito = {
411 vendedor: { NUM: true },
412 cliente: { COD: true },
413 proveedor: {},
414 cotizacion: { moneda: { id: true } }
415 };
416
417 //act
418 spyOn(focaModalService, 'alert');
419 scope.crearRemito();
420
421 //assert
422 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización');
423
424 });
425
426 it('crearRemito muestra alerta cuando no se eligió flete', function() {
427
428 //arrange
429 var scope = {
430 $broadcast: function() { },
431 $watch: function() { }
432 };
433 var focaModalService = {
434 alert: function() { }
435 };
436
437 $controller('remitoController', {
438 $scope: scope,
439 $uibModal: {},
440 $location: {},
441 $filter: {},
442 crearRemitoService: {
443 getBotonera: function() { },
444 getCotizacionByIdMoneda: function() {
445 return {
446 then: function() { }
447 };
448 },
449 getNumeroRemito: function() {
450 return {
451 then: function() { }
452 };
453 }
454 },
455 $timeout: timeout,
456 focaModalService: focaModalService,
457 remitoBusinessService: {},
458 $rootScope: {
459 $on: function() { }
460 },
461 focaBotoneraLateralService: {},
462 $localStorage: {}
463 });
464
465 scope.remito = {
466 vendedor: { NUM: true },
467 cliente: { COD: true },
468 proveedor: {},
469 cotizacion: {
470 moneda: { id: true },
471 ID: true
472 }
473 };
474
475 //act
476 spyOn(focaModalService, 'alert');
477 scope.crearRemito();
478
479 //assert
480 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete');
481
482 });
483
484 it('crearRemito muestra alerta cuando no se eligió articulos', function() {
485
486 //arrange
487 var scope = {
488 $broadcast: function() { },
489 $watch: function() { }
490 };
491 var focaModalService = {
492 alert: function() { }
493 };
494
495 $controller('remitoController', {
496 $scope: scope,
497 $uibModal: {},
498 $location: {},
499 $filter: {},
500 crearRemitoService: {
501 getBotonera: function() { },
502 getCotizacionByIdMoneda: function() {
503 return {
504 then: function() { }
505 };
506 },
507 getNumeroRemito: function() {
508 return {
509 then: function() { }
510 };
511 }
512 },
513 $timeout: timeout,
514 focaModalService: focaModalService,
515 remitoBusinessService: {},
516 $rootScope: {
517 $on: function() { }
518 },
519 focaBotoneraLateralService: {},
520 $localStorage: {}
521 });
522
523 scope.remito = {
524 vendedor: { NUM: true },
525 cliente: { COD: true },
526 proveedor: {},
527 cotizacion: {
528 moneda: { id: true },
529 ID: true
530 },
531 flete: true,
532 articulosRemito: []
533 };
534
535 //act
536 spyOn(focaModalService, 'alert');
537 scope.crearRemito();
538
539 //assert
540 expect(focaModalService.alert).toHaveBeenCalledWith('Debe cargar al menos un articulo');
541
542 });
543
544 it('crearRemito llama a startGuardar', function() {
545
546 //arrange
547 var scope = {
548 $broadcast: function() { },
549 $watch: function() { }
550 };
551 var focaBotoneraLateralService = {
552 startGuardar: function() { }
553 };
554
555 $controller('remitoController', {
556 $scope: scope,
557 $uibModal: {},
558 $location: {},
559 $filter: {},
560 crearRemitoService: {
561 getBotonera: function() { },
562 getCotizacionByIdMoneda: function() {
563 return {
564 then: function() { }
565 };
566 },
567 getNumeroRemito: function() {
568 return {
569 then: function() { }
570 };
571 },
572 crearRemito: function() {
573 return {
574 then: function() { }
575 };
576 }
577 },
578 $timeout: timeout,
579 focaModalService: {},
580 remitoBusinessService: {},
581 $rootScope: {
582 $on: function() { }
583 },
584 focaBotoneraLateralService: focaBotoneraLateralService,
585 $localStorage: {}
586 });
587
588 scope.remito = {
589 vendedor: { NUM: true },
590 cliente: { COD: true },
591 proveedor: {},
592 cotizacion: {
593 moneda: { id: true },
594 ID: true
595 },
596 flete: true,
597 articulosRemito: [ 1 ]
598 };
599
600 //act
601 spyOn(focaBotoneraLateralService, 'startGuardar');
602 scope.crearRemito();
603
604 //assert
605 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled();
606
607 });
608
609 it('crearRemito llama a endGuardar y abre modal', function(done) {
610
611 //arrange
612 var scope = {
613 $broadcast: function() { },
614 $watch: function() { }
615 };
616 var focaBotoneraLateralService = {
617 startGuardar: function() { },
618 endGuardar: function() { }
619 };
620 var uibModal = {
621 open: function() { }
622 };
623 var crearRemitoService = {
624 getBotonera: function() { },
625 getCotizacionByIdMoneda: function() {
626 return {
627 then: function() { }
628 };
629 },
630 getNumeroRemito: function() {
631 return {
632 then: function() { }
633 };
634 },
635 crearRemito: function() { }
636 };
637
638 $controller('remitoController', {
639 $scope: scope,
640 $uibModal: uibModal,
641 $location: {},
642 $filter: {},
643 crearRemitoService: crearRemitoService,
644 $timeout: timeout,
645 focaModalService: {},
646 remitoBusinessService: {
647 addArticulos: function() { }
648 },
649 $rootScope: {
650 $on: function() { }
651 },
652 focaBotoneraLateralService: focaBotoneraLateralService,
653 $localStorage: {}
654 });
655
656 scope.remito = {
657 vendedor: { NUM: true },
658 cliente: { COD: true },
659 proveedor: {},
660 cotizacion: {
661 moneda: { id: true },
662 ID: true
663 },
664 flete: true,
665 articulosRemito: [1]
666 };
667 var promiseRespond = Promise.resolve({ data: {} });
668
669 //act
670 spyOn(crearRemitoService, 'crearRemito').and.returnValue(promiseRespond);
671 spyOn(focaBotoneraLateralService, 'endGuardar');
672 spyOn(uibModal, 'open');
673 scope.crearRemito();
674
675 //assert
676 promiseRespond.then(function() {
677
678 expect(focaBotoneraLateralService.endGuardar).toHaveBeenCalled();
679 done();
680 });
681 });
682
683 it('seleccionarProductos abre modal', function() {
684
685 //arrange
686 var scope = {
687 $broadcast: function() { },
688 $watch: function() { }
689 };
690 var uibModal = {
691 open: function() { }
692 };
693
694 $controller('remitoController', {
695 $scope: scope,
696 $uibModal: uibModal,
697 $location: {},
698 $filter: {},
699 crearRemitoService: {
700 getBotonera: function() {},
701 getCotizacionByIdMoneda: function() {
702 return {
703 then: function() {}
704 };
705 },
706 getNumeroRemito: function() {
707 return {
708 then: function() {}
709 };
710 }
711 },
712 $timeout: timeout,
713 focaModalService: {},
714 remitoBusinessService: {
715 addArticulos: function() { }
716 },
717 $rootScope: {
718 $on: function() { }
719 },
720 focaBotoneraLateralService: {},
721 $localStorage: {}
722 });
723
724 scope.remito = {
725 cotizacion: {
726 moneda: { },
727 },
728 };
729 scope.idLista = true;
730
731 //act
732 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() {} } });
733 scope.seleccionarProductos();
734
735 //assert
736 expect(uibModal.open).toHaveBeenCalled();
737 });
738
739 it('seleccionarProductos abre alerta si no se eligió lista', function() {
740
741 //arrange
742 var scope = {
743 $broadcast: function() { },
744 $watch: function() { }
745 };
746 var focaModalService = {
747 alert: function() { }
748 };
749
750 $controller('remitoController', {
751 $scope: scope,
752 $uibModal: {},
753 $location: {},
754 $filter: {},
755 crearRemitoService: {
756 getBotonera: function() {},
757 getCotizacionByIdMoneda: function() {
758 return {
759 then: function() {}
760 };
761 },
762 getNumeroRemito: function() {
763 return {
764 then: function() {}
765 };
766 }
767 },
768 $timeout: timeout,
769 focaModalService: focaModalService,
770 remitoBusinessService: {
771 addArticulos: function() { }
772 },
773 $rootScope: {
774 $on: function() { }
775 },
776 focaBotoneraLateralService: {},
777 $localStorage: {}
778 });
779
780 //act
781 spyOn(focaModalService, 'alert');
782 scope.seleccionarProductos();
783
784 //assert
785 expect(focaModalService.alert)
786 .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion');
787 });
788
789 it('seleccionarPuntosDeDescarga abre modal', function() {
790
791 //arrange
792 var scope = {
793 $broadcast: function() { },
794 $watch: function() { }
795 };
796 var uibModal = {
797 open: function() { }
798 };
799
800 $controller('remitoController', {
801 $scope: scope,
802 $uibModal: uibModal,
803 $location: {},
804 $filter: {},
805 crearRemitoService: {
806 getBotonera: function() {},
807 getCotizacionByIdMoneda: function() {
808 return {
809 then: function() {}
810 };
811 },
812 getNumeroRemito: function() {
813 return {
814 then: function() {}
815 };
816 }
817 },
818 $timeout: timeout,
819 focaModalService: {},
820 remitoBusinessService: {
821 addArticulos: function() { }
822 },
823 $rootScope: {
824 $on: function() { }
825 },
826 focaBotoneraLateralService: {},
827 $localStorage: {}
828 });
829 scope.remito = {
830 cliente: { COD: true },
831 domicilio: { id: true }
832 };
833
834 //act
835 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
836 scope.seleccionarPuntosDeDescarga();
837
838 //assert
839 expect(uibModal.open).toHaveBeenCalled();
840 });
841
842 it('seleccionarVendedor abre modal', function() {
843
844 //arrange
845 var scope = {
846 $broadcast: function() { },
847 $watch: function() { }
848 };
849 var focaModalService = {
850 modal: function() { }
851 };
852
853 $controller('remitoController', {
854 $scope: scope,
855 $uibModal: {},
856 $location: {},
857 $filter: {},
858 crearRemitoService: {
859 getBotonera: function() {},
860 getCotizacionByIdMoneda: function() {
861 return {
862 then: function() {}
863 };
864 },
865 getNumeroRemito: function() {
866 return {
867 then: function() {}
868 };
869 }
870 },
871 $timeout: timeout,
872 focaModalService: focaModalService,
873 remitoBusinessService: {
874 addArticulos: function() { }
875 },
876 $rootScope: {
877 $on: function() { }
878 },
879 focaBotoneraLateralService: {},
880 $localStorage: {}
881 });
882
883 //act
884 spyOn(focaModalService, 'modal').and.returnValue({ then: function() { } });
885 scope.seleccionarVendedor();
886
887 //assert
888 expect(focaModalService.modal).toHaveBeenCalled();
889 });
890
891 it('seleccionarCliente abre modal', function() {
892
893 //arrange
894 var scope = {
895 $broadcast: function() { },
896 $watch: function() { }
897 };
898 var uibModal = {
899 open: function() { }
900 };
901
902 $controller('remitoController', {
903 $scope: scope,
904 $uibModal: uibModal,
905 $location: {},
906 $filter: {},
907 crearRemitoService: {
908 getBotonera: function() {},
909 getCotizacionByIdMoneda: function() {
910 return {
911 then: function() {}
912 };
913 },
914 getNumeroRemito: function() {
915 return {
916 then: function() {}
917 };
918 }
919 },
920 $timeout: timeout,
921 focaModalService: {},
922 remitoBusinessService: {
923 addArticulos: function() { }
924 },
925 $rootScope: {
926 $on: function() { }
927 },
928 focaBotoneraLateralService: {},
929 $localStorage: {}
930 });
931
932 //act
933 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
934 scope.seleccionarCliente(true);
935
936 //assert
937 expect(uibModal.open).toHaveBeenCalled();
938 });
939
940 it('seleccionarCliente setea cliente y llama a abrirModalDomicilios', function(done) {
941
942 //arrange
943 var scope = {
944 $broadcast: function() { },
945 $watch: function() { }
946 };
947 var uibModal = {
948 open: function() { }
949 };
950
951 $controller('remitoController', {
952 $scope: scope,
953 $uibModal: uibModal,
954 $location: {},
955 $filter: {},
956 crearRemitoService: {
957 getBotonera: function() {},
958 getCotizacionByIdMoneda: function() {
959 return {
960 then: function() {}
961 };
962 },
963 getNumeroRemito: function() {
964 return {
965 then: function() {}
966 };
967 }
968 },
969 $timeout: timeout,
970 focaModalService: {},
971 remitoBusinessService: {
972 addArticulos: function() { }
973 },
974 $rootScope: {
975 $on: function() { }
976 },
977 focaBotoneraLateralService: {},
978 $localStorage: {}
979 });
980 var response = 'test';
981 var promesa = { result: Promise.resolve(response) };
982
983 //act
984 spyOn(uibModal, 'open').and.returnValue(promesa);
985 spyOn(scope, 'abrirModalDomicilios');
986 scope.seleccionarCliente(true);
987
988 //assert
989 promesa.result.then(function() {
990 expect(scope.abrirModalDomicilios).toHaveBeenCalledWith(response);
991 expect(scope.cliente).toEqual(response);
992 done();
993 });
994 });
995
996 it('seleccionarProveedor abre modal', function() {
997
998 //arrange
999 var scope = {
1000 $broadcast: function() { },
1001 $watch: function() { }
1002 };
1003 var focaModalService = {
1004 modal: function() { }
1005 };
1006
1007 $controller('remitoController', {
1008 $scope: scope,
1009 $uibModal: {},
1010 $location: {},
1011 $filter: {},
1012 crearRemitoService: {
1013 getBotonera: function() {},
1014 getCotizacionByIdMoneda: function() {
1015 return {
1016 then: function() {}
1017 };
1018 },
1019 getNumeroRemito: function() {
1020 return {
1021 then: function() {}
1022 };
1023 }
1024 },
1025 $timeout: timeout,
1026 focaModalService: focaModalService,
1027 remitoBusinessService: {
1028 addArticulos: function() { }
1029 },
1030 $rootScope: {
1031 $on: function() { }
1032 },
1033 focaBotoneraLateralService: {},
1034 $localStorage: {}
1035 });
1036
1037 //act
1038 spyOn(focaModalService, 'modal').and.returnValue({ then: function() { } });
1039 scope.seleccionarProveedor();
1040
1041 //assert
1042 expect(focaModalService.modal).toHaveBeenCalled();
1043 });
1044
1045 it('seleccionarProveedor setea provedor y llama a callback', function(done) {
1046
1047 //arrange
1048 var scope = {
1049 $broadcast: function() { },
1050 $watch: function() { }
1051 };
1052 var focaModalService = {
1053 modal: function() { }
1054 };
1055
1056 $controller('remitoController', {
1057 $scope: scope,
1058 $uibModal: {},
1059 $location: {},
1060 $filter: function() {
1061 return function() { };
1062 },
1063 crearRemitoService: {
1064 getBotonera: function() {},
1065 getCotizacionByIdMoneda: function() {
1066 return {
1067 then: function() {}
1068 };
1069 },
1070 getNumeroRemito: function() {
1071 return {
1072 then: function() {}
1073 };
1074 }
1075 },
1076 $timeout: timeout,
1077 focaModalService: focaModalService,
1078 remitoBusinessService: {
1079 addArticulos: function() { }
1080 },
1081 $rootScope: {
1082 $on: function() { }
1083 },
1084 focaBotoneraLateralService: {},
1085 $localStorage: {}
1086 });
1087 var response = { COD: 1 };
1088 var promesa = Promise.resolve(response);
1089 window.callback = function() { };
1090
1091 //act
1092 spyOn(focaModalService, 'modal').and.returnValue(promesa);
1093 spyOn(window, 'callback');
1094 scope.seleccionarProveedor(window.callback);
1095
1096 //assert
1097 promesa.then(function() {
1098 expect(window.callback).toHaveBeenCalled();
1099 expect(scope.remito.proveedor).toBe(response);
1100 expect(scope.remito.idProveedor).toBe(response.COD);
1101 done();
1102 });
1103 });
1104
1105 it('abrirModalDomicilios abre modal', function() {
1106
1107 //arrange
1108 var scope = {
1109 $broadcast: function() { },
1110 $watch: function() { }
1111 };
1112 var uibModal = {
1113 open: function() { }
1114 };
1115
1116 $controller('remitoController', {
1117 $scope: scope,
1118 $uibModal: uibModal,
1119 $location: {},
1120 $filter: {},
1121 crearRemitoService: {
1122 getBotonera: function() {},
1123 getCotizacionByIdMoneda: function() {
1124 return {
1125 then: function() {}
1126 };
1127 },
1128 getNumeroRemito: function() {
1129 return {
1130 then: function() {}
1131 };
1132 }
1133 },
1134 $timeout: timeout,
1135 focaModalService: {},
1136 remitoBusinessService: {
1137 addArticulos: function() { }
1138 },
1139 $rootScope: {
1140 $on: function() { }
1141 },
1142 focaBotoneraLateralService: {},
1143 $localStorage: {}
1144 });
1145
1146 //act
1147 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
1148 scope.abrirModalDomicilios();
1149
1150 //assert
1151 expect(uibModal.open).toHaveBeenCalled();
1152
1153 });
1154
1155 it('getTotal devuelve correctamente', function() {
1156
1157 //arrange
1158 var scope = {
1159 $broadcast: function() { },
1160 $watch: function() { }
1161 };
1162
1163 $controller('remitoController', {
1164 $scope: scope,
1165 $uibModal: {},
1166 $location: {},
1167 $filter: {},
1168 crearRemitoService: {
1169 getBotonera: function() {},
1170 getCotizacionByIdMoneda: function() {
1171 return {
1172 then: function() {}
1173 };
1174 },
1175 getNumeroRemito: function() {
1176 return {
1177 then: function() {}
1178 };
1179 }
1180 },
1181 $timeout: timeout,
1182 focaModalService: {},
1183 remitoBusinessService: {
1184 addArticulos: function() { }
1185 },
1186 $rootScope: {
1187 $on: function() { }
1188 },
1189 focaBotoneraLateralService: {},
1190 $localStorage: {}
1191 });
1192 scope.remito = {
1193 articulosRemito: [
1194 {
1195 precio: 100,
1196 cantidad: 3
1197 }
1198 ]
1199 };
1200
1201 //act
1202 var result = scope.getTotal();
1203
1204 //assert
1205 expect(result).toEqual(300);
1206
1207 });
1208
1209 it('getSubTotal devuelve correctamente', function() {
1210
1211 //arrange
1212 var scope = {
1213 $broadcast: function() { },
1214 $watch: function() { }
1215 };
1216
1217 $controller('remitoController', {
1218 $scope: scope,
1219 $uibModal: {},
1220 $location: {},
1221 $filter: {},
1222 crearRemitoService: {
1223 getBotonera: function() {},
1224 getCotizacionByIdMoneda: function() {
1225 return {
1226 then: function() {}
1227 };
1228 },
1229 getNumeroRemito: function() {
1230 return {
1231 then: function() {}
1232 };
1233 }
1234 },
1235 $timeout: timeout,
1236 focaModalService: {},
1237 remitoBusinessService: {
1238 addArticulos: function() { }
1239 },
1240 $rootScope: {
1241 $on: function() { }
1242 },
1243 focaBotoneraLateralService: {},
1244 $localStorage: {}
1245 });
1246 scope.articuloACargar = {
1247 precio: 200,
1248 cantidad: 4
1249 };
1250
1251 //act
1252 var result = scope.getSubTotal();
1253
1254 //assert
1255 expect(result).toEqual(800);
1256
1257 });
1258
1259 it('seleccionarPreciosYCondiciones muestra alerta sino se eligió cliente', function() {
1260
1261 //arrange
1262 var scope = {
1263 $broadcast: function() { },
1264 $watch: function() { }
1265 };
1266 var focaModalService = {
1267 alert: function() {}
1268 };
1269
1270 $controller('remitoController', {
1271 $scope: scope,
1272 $uibModal: {},
1273 $location: {},
1274 $filter: {},
1275 crearRemitoService: {
1276 getBotonera: function() {},
1277 getCotizacionByIdMoneda: function() {
1278 return {
1279 then: function() {}
1280 };
1281 },
1282 getNumeroRemito: function() {
1283 return {
1284 then: function() {}
1285 };
1286 }
1287 },
1288 $timeout: timeout,
1289 focaModalService: focaModalService,
1290 remitoBusinessService: {
1291 addArticulos: function() { }
1292 },
1293 $rootScope: {
1294 $on: function() { }
1295 },
1296 focaBotoneraLateralService: {},
1297 $localStorage: {}
1298 });
1299
1300 //act
1301 spyOn(focaModalService, 'alert');
1302 scope.seleccionarPreciosYCondiciones();
1303
1304 //assert
1305 expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un cliente');
1306
1307 });
1308
1309 it('seleccionarPreciosYCondiciones abre modal', function() {
1310
1311 //arrange
1312 var scope = {
1313 $broadcast: function() { },
1314 $watch: function() { }
1315 };
1316 var uibModal = {
1317 open: function() {}
1318 };
1319
1320 $controller('remitoController', {
1321 $scope: scope,
1322 $uibModal: uibModal,
1323 $location: {},
1324 $filter: {},
1325 crearRemitoService: {
1326 getBotonera: function() {},
1327 getCotizacionByIdMoneda: function() {
1328 return {
1329 then: function() {}
1330 };
1331 },
1332 getNumeroRemito: function() {
1333 return {
1334 then: function() {}
1335 };
1336 }
1337 },
1338 $timeout: timeout,
1339 focaModalService: {},
1340 remitoBusinessService: {
1341 addArticulos: function() { }
1342 },
1343 $rootScope: {
1344 $on: function() { }
1345 },
1346 focaBotoneraLateralService: {},
1347 $localStorage: {}
1348 });
1349 scope.remito = {
1350 cliente: { COD: true }
1351 };
1352
1353 //act
1354 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
1355 scope.seleccionarPreciosYCondiciones();
1356
1357 //assert
1358 expect(uibModal.open).toHaveBeenCalled();
1359
1360 });
1361
1362 it('seleccionarMoneda abre modal y llama a cotizacion', function(done) {
1363
1364 //arrange
1365 var scope = {
1366 $broadcast: function() { },
1367 $watch: function() { }
1368 };
1369 var focaModalService = {
1370 modal: function() {}
1371 };
1372 var uibModal = {
1373 open: function() {
1374 return {
1375 result: {
1376 then: function() {}
1377 }
1378 };
1379 }
1380 };
1381
1382 $controller('remitoController', {
1383 $scope: scope,
1384 $uibModal: uibModal,
1385 $location: {},
1386 $filter: {},
1387 crearRemitoService: {
1388 getBotonera: function() {},
1389 getCotizacionByIdMoneda: function() {
1390 return {
1391 then: function() {}
1392 };
1393 },
1394 getNumeroRemito: function() {
1395 return {
1396 then: function() {}
1397 };
1398 }
1399 },
1400 $timeout: timeout,
1401 focaModalService: focaModalService,
1402 remitoBusinessService: {
1403 addArticulos: function() { }
1404 },
1405 $rootScope: {
1406 $on: function() { }
1407 },
1408 focaBotoneraLateralService: {},
1409 $localStorage: {}
1410 });
1411 var promesa = Promise.resolve('test');
1412
1413 //act
1414 spyOn(focaModalService, 'modal').and.returnValue(promesa);
1415 scope.seleccionarMoneda();
1416
1417 //assert
1418 promesa.then(function() {
1419 expect(focaModalService.modal).toHaveBeenCalled();
1420 done();
1421 });
1422 });
1423
1424 it('seleccionarObservaciones levanta prompt', function() {
1425
1426 //arrange
1427 var scope = {
1428 $broadcast: function() { },
1429 $watch: function() { }
1430 };
1431 var focaModalService = {
1432 prompt: function() {}
1433 };
1434
1435 $controller('remitoController', {
1436 $scope: scope,
1437 $uibModal: {},
1438 $location: {},
1439 $filter: {},
1440 crearRemitoService: {
1441 getBotonera: function() {},
1442 getCotizacionByIdMoneda: function() {
1443 return {
1444 then: function() {}
1445 };
1446 },
1447 getNumeroRemito: function() {
1448 return {
1449 then: function() {}
1450 };
1451 }
1452 },
1453 $timeout: timeout,
1454 focaModalService: focaModalService,
1455 remitoBusinessService: {
1456 addArticulos: function() { }
1457 },
1458 $rootScope: {
1459 $on: function() { }
1460 },
1461 focaBotoneraLateralService: {},
1462 $localStorage: {}
1463 });
1464
1465 //act
1466 spyOn(focaModalService, 'prompt').and.returnValue({ then: function() { } });
1467 scope.seleccionarObservaciones();
1468
1469 //assert
1470 expect(focaModalService.prompt).toHaveBeenCalled();
1471 });
1472
1473 it('abrirModalCotizacion abre modal', function() {
1474
1475 //arrange
1476 var scope = {
1477 $broadcast: function() { },
1478 $watch: function() { }
1479 };
1480 var uibModal = {
1481 open: function() {}
1482 };
1483
1484 $controller('remitoController', {
1485 $scope: scope,
1486 $uibModal: uibModal,
1487 $location: {},
1488 $filter: {},
1489 crearRemitoService: {
1490 getBotonera: function() {},
1491 getCotizacionByIdMoneda: function() {
1492 return {
1493 then: function() {}
1494 };
1495 },
1496 getNumeroRemito: function() {
1497 return {
1498 then: function() {}
1499 };
1500 }
1501 },
1502 $timeout: timeout,
1503 focaModalService: {},
1504 remitoBusinessService: {
1505 addArticulos: function() { }
1506 },
1507 $rootScope: {
1508 $on: function() { }
1509 },
1510 focaBotoneraLateralService: {},
1511 $localStorage: {}
1512 });
1513
1514 //act
1515 spyOn(uibModal, 'open').and.returnValue({ result: { then: function() { } } });
1516 scope.abrirModalCotizacion();
1517
1518 //assert
1519 expect(uibModal.open).toHaveBeenCalled();
1520 });
1521 });
1522 });
1523
1 describe('Servicios modulo crear remito', function() { 1 describe('Servicios modulo crear remito', function() {
2 2
3 beforeEach(function(){ 3 beforeEach(function(){
4 module('focaCrearRemito'); 4 module('focaCrearRemito');
5 inject(module(function($provide) { 5 inject(module(function($provide) {
6 $provide.value('API_ENDPOINT', { 6 $provide.value('API_ENDPOINT', {
7 URL: 'localhost' 7 URL: 'localhost'
8 }); 8 });
9 })); 9 }));
10 }); 10 });
11 11
12 describe('servicio crearRemitoService', function() { 12 describe('servicio crearRemitoService', function() {
13 13
14 var servicio, httpBackend; 14 var servicio, httpBackend;
15 15
16 beforeEach(function() { 16 beforeEach(function() {
17 inject(function($httpBackend, _crearRemitoService_) { 17 inject(function($httpBackend, _crearRemitoService_) {
18 servicio = _crearRemitoService_; 18 servicio = _crearRemitoService_;
19 httpBackend = $httpBackend; 19 httpBackend = $httpBackend;
20 }); 20 });
21 }) 21 });
22 22
23 it('existe el servicio crearRemitoService', function() { 23 it('existe el servicio crearRemitoService', function() {
24 24
25 //assert 25 //assert
26 expect(typeof servicio).toEqual('object'); 26 expect(typeof servicio).toEqual('object');
27 }); 27 });
28 28
29 it('función crearRemito llama a ruta correcta', function() { 29 it('función crearRemito llama a ruta correcta', function() {
30 30
31 //arrange 31 //arrange
32 var result; 32 var result;
33 var fakeParam = 1; 33 var fakeParam = 1;
34 var respond = 'test'; 34 var respond = 'test';
35 httpBackend.expectPOST('localhost/remito', fakeParam).respond(respond); 35 httpBackend.expectPOST('localhost/remito', fakeParam).respond(respond);
36 36
37 //act 37 //act
38 servicio.crearRemito(fakeParam).then(function(res) { 38 servicio.crearRemito(fakeParam).then(function(res) {
39 result = res.data; 39 result = res.data;
40 }); 40 });
41 httpBackend.flush(); 41 httpBackend.flush();
42 42
43 //assert 43 //assert
44 expect(result).toEqual(respond); 44 expect(result).toEqual(respond);
45 }); 45 });
46 46
47 it('función getRemitoById llama a ruta correcta', function() { 47 it('función getRemitoById llama a ruta correcta', function() {
48 48
49 //arrange 49 //arrange
50 var result; 50 var result;
51 var fakeParam = 1; 51 var fakeParam = 1;
52 var respond = 'test'; 52 var respond = 'test';
53 httpBackend.expectGET('localhost/remito/obtener/' + fakeParam).respond(respond); 53 httpBackend.expectGET('localhost/remito/obtener/' + fakeParam).respond(respond);
54 54
55 //act 55 //act
56 servicio.getRemitoById(fakeParam).then(function(res) { 56 servicio.getRemitoById(fakeParam).then(function(res) {
57 result = res.data; 57 result = res.data;
58 }); 58 });
59 httpBackend.flush(); 59 httpBackend.flush();
60 60
61 //assert 61 //assert
62 expect(result).toEqual(respond); 62 expect(result).toEqual(respond);
63 }); 63 });
64 64
65 it('función obtenerRemito llama a ruta correcta', function() { 65 it('función obtenerRemito llama a ruta correcta', function() {
66 66
67 //arrange 67 //arrange
68 var result; 68 var result;
69 var fakeParam = 1; 69 var fakeParam = 1;
70 var respond = 'test'; 70 var respond = 'test';
71 httpBackend.expectGET('localhost/nota-pedido').respond(respond); 71 httpBackend.expectGET('localhost/nota-pedido').respond(respond);
72 72
73 //act 73 //act
74 servicio.obtenerRemito(fakeParam).then(function(res) { 74 servicio.obtenerRemito(fakeParam).then(function(res) {
75 result = res.data; 75 result = res.data;
76 }); 76 });
77 httpBackend.flush(); 77 httpBackend.flush();
78 78
79 //assert 79 //assert
80 expect(result).toEqual(respond); 80 expect(result).toEqual(respond);
81 }); 81 });
82 82
83 it('función setRemito setea correctamente', function() { 83 it('función setRemito setea correctamente', function() {
84 84
85 //arrange 85 //arrange
86 var result;
87 var fakeParam = 1; 86 var fakeParam = 1;
88 87
89 //act 88 //act
90 servicio.setRemito(fakeParam); 89 servicio.setRemito(fakeParam);
91 90
92 //assert 91 //assert
93 expect(servicio.remito).toEqual(fakeParam); 92 expect(servicio.remito).toEqual(fakeParam);
94 }); 93 });
95 94
96 it('función clearRemito setea correctamente', function() { 95 it('función clearRemito setea correctamente', function() {
97 96
98 //act 97 //act
99 servicio.clearRemito(); 98 servicio.clearRemito();
100 99
101 //assert 100 //assert
102 expect(servicio.remito).toEqual(undefined); 101 expect(servicio.remito).toEqual(undefined);
103 }); 102 });
104 103
105 it('función getRemito trae correctamente', function() { 104 it('función getRemito trae correctamente', function() {
106 105
107 //arrange 106 //arrange
108 var fakeParam = 1; 107 var fakeParam = 1;
109 108
110 //act 109 //act
111 servicio.remito = fakeParam; 110 servicio.remito = fakeParam;
112 var result = servicio.getRemito(); 111 var result = servicio.getRemito();
113 112
114 //assert 113 //assert
115 expect(result).toEqual(fakeParam); 114 expect(result).toEqual(fakeParam);
116 }); 115 });
117 116
118 it('función getArticulosByIdRemito llama a ruta correcta', function() { 117 it('función getArticulosByIdRemito llama a ruta correcta', function() {
119 118
120 //arrange 119 //arrange
121 var result; 120 var result;
122 var fakeParam = 1; 121 var fakeParam = 1;
123 var respond = 'test'; 122 var respond = 'test';
124 httpBackend.expectGET('localhost/articulos/nota-pedido/' + fakeParam).respond(respond); 123 httpBackend.expectGET('localhost/articulos/nota-pedido/' + fakeParam).respond(respond);
125 124
126 //act 125 //act
127 servicio.getArticulosByIdRemito(fakeParam).then(function(res) { 126 servicio.getArticulosByIdRemito(fakeParam).then(function(res) {
128 result = res.data; 127 result = res.data;
129 }); 128 });
130 httpBackend.flush(); 129 httpBackend.flush();
131 130
132 //assert 131 //assert
133 expect(result).toEqual(respond); 132 expect(result).toEqual(respond);
134 }); 133 });
135 134
136 it('función crearArticulosParaRemito llama a ruta correcta', function() { 135 it('función crearArticulosParaRemito llama a ruta correcta', function() {
137 136
138 //arrange 137 //arrange
139 var result; 138 var result;
140 var fakeParam = 1; 139 var fakeParam = 1;
141 var respond = 'test'; 140 var respond = 'test';
142 httpBackend.expectPOST('localhost/articulos/remito', {articuloRemito: fakeParam}) 141 httpBackend.expectPOST('localhost/articulos/remito', {articuloRemito: fakeParam})
143 .respond(respond); 142 .respond(respond);
144 143
145 //act 144 //act
146 servicio.crearArticulosParaRemito(fakeParam).then(function(res) { 145 servicio.crearArticulosParaRemito(fakeParam).then(function(res) {
147 result = res.data; 146 result = res.data;
148 }); 147 });
149 httpBackend.flush(); 148 httpBackend.flush();
150 149
151 //assert 150 //assert
152 expect(result).toEqual(respond); 151 expect(result).toEqual(respond);
153 }); 152 });
154 153
155 it('función getDomiciliosByIdRemito llama a ruta correcta', function() { 154 it('función getDomiciliosByIdRemito llama a ruta correcta', function() {
156 155
157 //arrange 156 //arrange
158 var result; 157 var result;
159 var fakeParam = 1; 158 var fakeParam = 1;
160 var respond = 'test'; 159 var respond = 'test';
161 httpBackend.expectGET('localhost/nota-pedido/' + fakeParam + '/domicilios') 160 httpBackend.expectGET('localhost/nota-pedido/' + fakeParam + '/domicilios')
162 .respond(respond); 161 .respond(respond);
163 162
164 //act 163 //act
165 servicio.getDomiciliosByIdRemito(fakeParam).then(function(res) { 164 servicio.getDomiciliosByIdRemito(fakeParam).then(function(res) {
166 result = res.data; 165 result = res.data;
167 }); 166 });
168 httpBackend.flush(); 167 httpBackend.flush();
169 168
170 //assert 169 //assert
171 expect(result).toEqual(respond); 170 expect(result).toEqual(respond);
172 }); 171 });
173 172
174 it('función getDomiciliosByIdCliente llama a ruta correcta', function() { 173 it('función getDomiciliosByIdCliente llama a ruta correcta', function() {
175 174
176 //arrange 175 //arrange
177 var result; 176 var result;
178 var fakeParam = 1; 177 var fakeParam = 1;
179 var respond = 'test'; 178 var respond = 'test';
180 httpBackend.expectGET('localhost/domicilio/tipo/2/cliente/' + fakeParam) 179 httpBackend.expectGET('localhost/domicilio/tipo/2/cliente/' + fakeParam)
181 .respond(respond); 180 .respond(respond);
182 181
183 //act 182 //act
184 servicio.getDomiciliosByIdCliente(fakeParam).then(function(res) { 183 servicio.getDomiciliosByIdCliente(fakeParam).then(function(res) {
185 result = res.data; 184 result = res.data;
186 }); 185 });
187 httpBackend.flush(); 186 httpBackend.flush();
188 187
189 //assert 188 //assert
190 expect(result).toEqual(respond); 189 expect(result).toEqual(respond);
191 }); 190 });
192 191
193 it('función getPrecioCondicion llama a ruta correcta', function() { 192 it('función getPrecioCondicion llama a ruta correcta', function() {
194 193
195 //arrange 194 //arrange
196 var result; 195 var result;
197 var respond = 'test'; 196 var respond = 'test';
198 httpBackend.expectGET('localhost/precio-condicion').respond(respond); 197 httpBackend.expectGET('localhost/precio-condicion').respond(respond);
199 198
200 //act 199 //act
201 servicio.getPrecioCondicion().then(function(res) { 200 servicio.getPrecioCondicion().then(function(res) {
202 result = res.data; 201 result = res.data;
203 }); 202 });
204 httpBackend.flush(); 203 httpBackend.flush();
205 204
206 //assert 205 //assert
207 expect(result).toEqual(respond); 206 expect(result).toEqual(respond);
208 }); 207 });
209 208
210 it('función getPrecioCondicionById llama a ruta correcta', function() { 209 it('función getPrecioCondicionById llama a ruta correcta', function() {
211 210
212 //arrange 211 //arrange
213 var result; 212 var result;
214 var fakeParam = 1; 213 var fakeParam = 1;
215 var respond = 'test'; 214 var respond = 'test';
216 httpBackend.expectGET('localhost/precio-condicion/' + fakeParam).respond(respond); 215 httpBackend.expectGET('localhost/precio-condicion/' + fakeParam).respond(respond);
217 216
218 //act 217 //act
219 servicio.getPrecioCondicionById(fakeParam).then(function(res) { 218 servicio.getPrecioCondicionById(fakeParam).then(function(res) {
220 result = res.data; 219 result = res.data;
221 }); 220 });
222 httpBackend.flush(); 221 httpBackend.flush();
223 222
224 //assert 223 //assert
225 expect(result).toEqual(respond); 224 expect(result).toEqual(respond);
226 }); 225 });
227 226
228 it('función getPlazoPagoByPrecioCondicion llama a ruta correcta', function() { 227 it('función getPlazoPagoByPrecioCondicion llama a ruta correcta', function() {
229 228
230 //arrange 229 //arrange
231 var result; 230 var result;
232 var fakeParam = 1; 231 var fakeParam = 1;
233 var respond = 'test'; 232 var respond = 'test';
234 httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + fakeParam) 233 httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + fakeParam)
235 .respond(respond); 234 .respond(respond);
236 235
237 //act 236 //act
238 servicio.getPlazoPagoByPrecioCondicion(fakeParam).then(function(res) { 237 servicio.getPlazoPagoByPrecioCondicion(fakeParam).then(function(res) {
239 result = res.data; 238 result = res.data;
240 }); 239 });
241 httpBackend.flush(); 240 httpBackend.flush();
242 241
243 //assert 242 //assert
244 expect(result).toEqual(respond); 243 expect(result).toEqual(respond);
245 }); 244 });
246 245
247 it('función crearFlete llama a ruta correcta', function() { 246 it('función crearFlete llama a ruta correcta', function() {
248 247
249 //arrange 248 //arrange
250 var result; 249 var result;
251 var fakeParam = 1; 250 var fakeParam = 1;
252 var respond = 'test'; 251 var respond = 'test';
253 httpBackend.expectPOST('localhost/flete', {flete: fakeParam}).respond(respond); 252 httpBackend.expectPOST('localhost/flete', {flete: fakeParam}).respond(respond);
254 253
255 //act 254 //act
256 servicio.crearFlete(fakeParam).then(function(res) { 255 servicio.crearFlete(fakeParam).then(function(res) {
257 result = res.data; 256 result = res.data;
258 }); 257 });
259 httpBackend.flush(); 258 httpBackend.flush();
260 259
261 //assert 260 //assert
262 expect(result).toEqual(respond); 261 expect(result).toEqual(respond);
263 }); 262 });
264 263
265 it('función crearPlazosParaRemito llama a ruta correcta', function() { 264 it('función crearPlazosParaRemito llama a ruta correcta', function() {
266 265
267 //arrange 266 //arrange
268 var result; 267 var result;
269 var fakeParam = 1; 268 var fakeParam = 1;
270 var respond = 'test'; 269 var respond = 'test';
271 httpBackend.expectPOST('localhost/plazo-pago/remito', fakeParam).respond(respond); 270 httpBackend.expectPOST('localhost/plazo-pago/remito', fakeParam).respond(respond);
272 271
273 //act 272 //act
274 servicio.crearPlazosParaRemito(fakeParam).then(function(res) { 273 servicio.crearPlazosParaRemito(fakeParam).then(function(res) {
275 result = res.data; 274 result = res.data;
276 }); 275 });
277 httpBackend.flush(); 276 httpBackend.flush();
278 277
279 //assert 278 //assert
280 expect(result).toEqual(respond); 279 expect(result).toEqual(respond);
281 }); 280 });
282 281
283 it('función getCotizacionByIdMoneda llama a ruta correcta', function() { 282 it('función getCotizacionByIdMoneda llama a ruta correcta', function() {
284 283
285 //arrange 284 //arrange
286 var result; 285 var result;
287 var fakeParam = 1; 286 var fakeParam = 1;
288 var respond = 'test'; 287 var respond = 'test';
289 httpBackend.expectGET('localhost/moneda/' + fakeParam).respond(respond); 288 httpBackend.expectGET('localhost/moneda/' + fakeParam).respond(respond);
290 289
291 //act 290 //act
292 servicio.getCotizacionByIdMoneda(fakeParam).then(function(res) { 291 servicio.getCotizacionByIdMoneda(fakeParam).then(function(res) {
293 result = res.data; 292 result = res.data;
294 }); 293 });
295 httpBackend.flush(); 294 httpBackend.flush();
296 295
297 //assert 296 //assert
298 expect(result).toEqual(respond); 297 expect(result).toEqual(respond);
299 }); 298 });
300 299
301 it('función crearEstadoParaRemito llama a ruta correcta', function() { 300 it('función crearEstadoParaRemito llama a ruta correcta', function() {
302 301
303 //arrange 302 //arrange
304 var result; 303 var result;
305 var fakeParam = 1; 304 var fakeParam = 1;
306 var respond = 'test'; 305 var respond = 'test';
307 httpBackend.expectPOST('localhost/estado', { estado: fakeParam }).respond(respond); 306 httpBackend.expectPOST('localhost/estado', { estado: fakeParam }).respond(respond);
308 307
309 //act 308 //act
310 servicio.crearEstadoParaRemito(fakeParam).then(function(res) { 309 servicio.crearEstadoParaRemito(fakeParam).then(function(res) {
311 result = res.data; 310 result = res.data;
312 }); 311 });
313 httpBackend.flush(); 312 httpBackend.flush();
314 313
315 //assert 314 //assert
316 expect(result).toEqual(respond); 315 expect(result).toEqual(respond);
317 }); 316 });
318 317
319 it('función getNumeroRemito llama a ruta correcta', function() { 318 it('función getNumeroRemito llama a ruta correcta', function() {
320 319
321 //arrange 320 //arrange
322 var result; 321 var result;
323 var respond = 'test'; 322 var respond = 'test';
324 httpBackend.expectGET('localhost/remito/numero-siguiente').respond(respond); 323 httpBackend.expectGET('localhost/remito/numero-siguiente').respond(respond);
325 324
326 //act 325 //act
327 servicio.getNumeroRemito().then(function(res) { 326 servicio.getNumeroRemito().then(function(res) {
328 result = res.data; 327 result = res.data;
329 }); 328 });
330 httpBackend.flush(); 329 httpBackend.flush();
331 330
332 //assert 331 //assert
333 expect(result).toEqual(respond); 332 expect(result).toEqual(respond);
334 }); 333 });
335 334
336 it('función imprimirRemitoByIdRemito llama a ruta correcta', function() { 335 it('función imprimirRemitoByIdRemito llama a ruta correcta', function() {
337 336
338 //arrange 337 //arrange
339 var result; 338 var result;
340 var fakeParam = 1; 339 var fakeParam = 1;
341 var respond = new Blob(['test']); 340 var respond = new Blob(['test']);
342 httpBackend.expectGET('localhost/remito/comprobante/' + fakeParam) 341 httpBackend.expectGET('localhost/remito/comprobante/' + fakeParam)
343 .respond(respond); 342 .respond(respond);
344 343
345 //act 344 //act
346 servicio.imprimirRemitoByIdRemito(fakeParam).then(function(res) { 345 servicio.imprimirRemitoByIdRemito(fakeParam).then(function(res) {
347 result = res.data; 346 result = res.data;
348 }); 347 });
349 httpBackend.flush(); 348 httpBackend.flush();
350 349
351 //assert 350 //assert
352 expect(result).toEqual(respond); 351 expect(result).toEqual(respond);
353 }); 352 });
354 353
355 it('función getPuntosDescargaByClienDom llama a ruta correcta', function() { 354 it('función getPuntosDescargaByClienDom llama a ruta correcta', function() {
356 355
357 //arrange 356 //arrange
358 var result; 357 var result;
359 var fakeParam = 1; 358 var fakeParam = 1;
360 var respond = 'test'; 359 var respond = 'test';
361 httpBackend.expectGET('localhost/punto-descarga/' + fakeParam + '/' + fakeParam) 360 httpBackend.expectGET('localhost/punto-descarga/' + fakeParam + '/' + fakeParam)
362 .respond(respond); 361 .respond(respond);
363 362
364 //act 363 //act
365 servicio.getPuntosDescargaByClienDom(fakeParam, fakeParam).then(function(res) { 364 servicio.getPuntosDescargaByClienDom(fakeParam, fakeParam).then(function(res) {
366 result = res.data; 365 result = res.data;
367 }); 366 });
368 httpBackend.flush(); 367 httpBackend.flush();
369 368
370 //assert 369 //assert
371 expect(result).toEqual(respond); 370 expect(result).toEqual(respond);
372 }); 371 });
373 372
374 it('función enviarCorreo llama a ruta correcta', function() { 373 it('función enviarCorreo llama a ruta correcta', function() {
375 374
376 //arrange 375 //arrange
377 var result; 376 var result;
378 var fakeParam = 1; 377 var fakeParam = 1;
379 var respond = 'test'; 378 var respond = 'test';
380 httpBackend.expectPOST('localhost/remito/mail', fakeParam) 379 httpBackend.expectPOST('localhost/remito/mail', fakeParam)
381 .respond(respond); 380 .respond(respond);
382 381
383 //act 382 //act
384 servicio.enviarCorreo(fakeParam).then(function(res) { 383 servicio.enviarCorreo(fakeParam).then(function(res) {
385 result = res.data; 384 result = res.data;
386 }); 385 });
387 httpBackend.flush(); 386 httpBackend.flush();
388 387
389 //assert 388 //assert
390 expect(result).toEqual(respond); 389 expect(result).toEqual(respond);
391 }); 390 });
392 }); 391 });
393 }); 392 });
394 393
src/js/controller.js
1 angular.module('focaCrearRemito') .controller('remitoController', 1 angular.module('focaCrearRemito') .controller('remitoController',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout',
4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', 4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
5 '$localStorage', 5 '$localStorage',
6 function( 6 function(
7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, 7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService,
8 remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) 8 remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage)
9 { 9 {
10 config(); 10 config();
11 11
12 function config() { 12 function config() {
13 $scope.botonera = crearRemitoService.getBotonera(); 13 $scope.botonera = crearRemitoService.getBotonera();
14 $scope.isNumber = angular.isNumber; 14 $scope.isNumber = angular.isNumber;
15 $scope.datepickerAbierto = false; 15 $scope.datepickerAbierto = false;
16 $scope.show = false; 16 $scope.show = false;
17 $scope.cargando = true; 17 $scope.cargando = true;
18 $scope.now = new Date(); 18 $scope.now = new Date();
19 $scope.puntoVenta = rellenar(0, 4); 19 $scope.puntoVenta = rellenar(0, 4);
20 $scope.comprobante = rellenar(0, 8); 20 $scope.comprobante = rellenar(0, 8);
21 $scope.dateOptions = { 21 $scope.dateOptions = {
22 maxDate: new Date(), 22 maxDate: new Date(),
23 minDate: new Date(2010, 0, 1) 23 minDate: new Date(2010, 0, 1)
24 }; 24 };
25 25
26 var monedaPorDefecto; 26 var monedaPorDefecto;
27 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 27 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
28 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { 28 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
29 monedaPorDefecto = res.data[0]; 29 monedaPorDefecto = res.data[0];
30 30
31 $scope.remito.cotizacion = Object.assign( 31 $scope.remito.cotizacion = Object.assign(
32 {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] 32 {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0]
33 ); 33 );
34 $scope.inicial.cotizacion = $scope.remito.cotizacion; 34 $scope.inicial.cotizacion = $scope.remito.cotizacion;
35 $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion); 35 $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion);
36 }); 36 });
37 37
38 //SETEO BOTONERA LATERAL 38 //SETEO BOTONERA LATERAL
39 $timeout(function() { 39 $timeout(function() {
40 focaBotoneraLateralService.showSalir(false); 40 focaBotoneraLateralService.showSalir(false);
41 focaBotoneraLateralService.showPausar(true); 41 focaBotoneraLateralService.showPausar(true);
42 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); 42 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
43 focaBotoneraLateralService.addCustomButton('Salir', salir); 43 focaBotoneraLateralService.addCustomButton('Salir', salir);
44 }); 44 });
45 45
46 init(); 46 init();
47 $timeout(function() {getLSRemito();}); 47 $timeout(function() {getLSRemito();});
48 } 48 }
49 49
50 function init() { 50 function init() {
51 $scope.$broadcast('cleanCabecera'); 51 $scope.$broadcast('cleanCabecera');
52 52
53 $scope.remito = { 53 $scope.remito = {
54 id: 0, 54 id: 0,
55 estado: 0, 55 estado: 0,
56 vendedor: {}, 56 vendedor: {},
57 cliente: {}, 57 cliente: {},
58 proveedor: {}, 58 proveedor: {},
59 domicilio: {dom: ''}, 59 domicilio: {dom: ''},
60 moneda: {}, 60 moneda: {},
61 cotizacion: $scope.cotizacionPorDefecto || {}, 61 cotizacion: $scope.cotizacionPorDefecto || {},
62 articulosRemito: [] 62 articulosRemito: []
63 }; 63 };
64 64
65 $scope.notaPedido = { 65 $scope.notaPedido = {
66 id: 0 66 id: 0
67 }; 67 };
68 68
69 $scope.remito.articulosRemito = []; 69 $scope.remito.articulosRemito = [];
70 $scope.idLista = undefined; 70 $scope.idLista = undefined;
71 71
72 crearRemitoService.getNumeroRemito().then( 72 crearRemitoService.getNumeroRemito().then(
73 function(res) { 73 function(res) {
74 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 74 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
75 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 75 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
76 }, 76 },
77 function(err) { 77 function(err) {
78 focaModalService.alert('La terminal no esta configurada correctamente'); 78 focaModalService.alert('La terminal no esta configurada correctamente');
79 console.info(err); 79 console.info(err);
80 } 80 }
81 ); 81 );
82 82
83 $scope.inicial = angular.copy($scope.remito); 83 $scope.inicial = angular.copy($scope.remito);
84 } 84 }
85 85
86 $scope.$watch('remito', function(newValue) { 86 $scope.$watch('remito', function(newValue) {
87 focaBotoneraLateralService.setPausarData({ 87 focaBotoneraLateralService.setPausarData({
88 label: 'remito', 88 label: 'remito',
89 val: newValue 89 val: newValue
90 }); 90 });
91 }, true); 91 }, true);
92 92
93 $scope.seleccionarNotaPedido = function() { 93 $scope.seleccionarNotaPedido = function() {
94 if (varlidarRemitoFacturado()) { 94 if (varlidarRemitoFacturado()) {
95 var modalInstance = $uibModal.open( 95 var modalInstance = $uibModal.open(
96 { 96 {
97 ariaLabelledBy: 'Busqueda de Nota de Pedido', 97 ariaLabelledBy: 'Busqueda de Nota de Pedido',
98 templateUrl: 'foca-modal-nota-pedido.html', 98 templateUrl: 'foca-modal-nota-pedido.html',
99 controller: 'focaModalNotaPedidoController', 99 controller: 'focaModalNotaPedidoController',
100 size: 'lg', 100 size: 'lg',
101 resolve: { 101 resolve: {
102 usadoPor: function() { return 'remito'; }, 102 usadoPor: function() { return 'remito'; },
103 idVendedor: function() { return null; } 103 idVendedor: function() { return null; }
104 } 104 }
105 } 105 }
106 ); 106 );
107 modalInstance.result.then( 107 modalInstance.result.then(
108 function(notaPedido) { 108 function(notaPedido) {
109 //añado cabeceras 109 //añado cabeceras
110 $scope.notaPedido.id = notaPedido.id; 110 $scope.notaPedido.id = notaPedido.id;
111 $scope.$broadcast('removeCabecera', 'Bomba:'); 111 $scope.$broadcast('removeCabecera', 'Bomba:');
112 $scope.$broadcast('removeCabecera', 'Kilometros:'); 112 $scope.$broadcast('removeCabecera', 'Kilometros:');
113 var cabeceras = [ 113 var cabeceras = [
114 { 114 {
115 label: 'Moneda:', 115 label: 'Moneda:',
116 valor: notaPedido.cotizacion.moneda.DETALLE 116 valor: notaPedido.cotizacion.moneda.DETALLE
117 }, 117 },
118 { 118 {
119 label: 'Fecha cotizacion:', 119 label: 'Fecha cotizacion:',
120 valor: $filter('date')(notaPedido.cotizacion.FECHA, 120 valor: $filter('date')(notaPedido.cotizacion.FECHA,
121 'dd/MM/yyyy') 121 'dd/MM/yyyy')
122 }, 122 },
123 { 123 {
124 label: 'Cotizacion:', 124 label: 'Cotizacion:',
125 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 125 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
126 '2') 126 '2')
127 }, 127 },
128 { 128 {
129 label: 'Cliente:', 129 label: 'Cliente:',
130 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + 130 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) +
131 ' - ' + notaPedido.cliente.NOM 131 ' - ' + notaPedido.cliente.NOM
132 }, 132 },
133 { 133 {
134 label: 'Domicilio:', 134 label: 'Domicilio:',
135 valor: notaPedido.domicilioStamp 135 valor: notaPedido.domicilioStamp
136 }, 136 },
137 { 137 {
138 label: 'Vendedor:', 138 label: 'Vendedor:',
139 valor: $filter('rellenarDigitos')( 139 valor: $filter('rellenarDigitos')(
140 notaPedido.vendedor.NUM, 3 140 notaPedido.vendedor.NUM, 3
141 ) + ' - ' + notaPedido.vendedor.NOM 141 ) + ' - ' + notaPedido.vendedor.NOM
142 }, 142 },
143 { 143 {
144 label: 'Proveedor:', 144 label: 'Proveedor:',
145 valor: $filter('rellenarDigitos') 145 valor: $filter('rellenarDigitos')
146 (notaPedido.proveedor.COD, 5) + ' - ' + 146 (notaPedido.proveedor.COD, 5) + ' - ' +
147 notaPedido.proveedor.NOM 147 notaPedido.proveedor.NOM
148 }, 148 },
149 { 149 {
150 label: 'Precio condicion:', 150 label: 'Precio condicion:',
151 valor: valorPrecioCondicion() + ' ' + 151 valor: valorPrecioCondicion() + ' ' +
152 remitoBusinessService 152 remitoBusinessService
153 .plazoToString(notaPedido.notaPedidoPlazo) 153 .plazoToString(notaPedido.notaPedidoPlazo)
154 }, 154 },
155 { 155 {
156 label: 'Flete:', 156 label: 'Flete:',
157 valor: notaPedido.fob === 1 ? 'FOB' : ( 157 valor: notaPedido.fob === 1 ? 'FOB' : (
158 notaPedido.flete === 1 ? 'Si' : 'No') 158 notaPedido.flete === 1 ? 'Si' : 'No')
159 } 159 }
160 ]; 160 ];
161 161
162 if (notaPedido.observaciones) { 162 if (notaPedido.observaciones) {
163 cabeceras.push({ 163 cabeceras.push({
164 label: 'Observaciones:', 164 label: 'Observaciones:',
165 valor: notaPedido.observaciones 165 valor: notaPedido.observaciones
166 }); 166 });
167 } 167 }
168 168
169 function valorPrecioCondicion() { 169 function valorPrecioCondicion() {
170 if (notaPedido.idPrecioCondicion > 0) { 170 if (notaPedido.idPrecioCondicion > 0) {
171 return notaPedido.precioCondicion.nombre; 171 return notaPedido.precioCondicion.nombre;
172 } else { 172 } else {
173 return 'Ingreso Manual'; 173 return 'Ingreso Manual';
174 } 174 }
175 } 175 }
176 176
177 if (notaPedido.flete === 1) { 177 if (notaPedido.flete === 1) {
178 var cabeceraBomba = { 178 var cabeceraBomba = {
179 label: 'Bomba:', 179 label: 'Bomba:',
180 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 180 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
181 }; 181 };
182 if (notaPedido.kilometros) { 182 if (notaPedido.kilometros) {
183 var cabeceraKilometros = { 183 var cabeceraKilometros = {
184 label: 'Kilometros:', 184 label: 'Kilometros:',
185 valor: notaPedido.kilometros 185 valor: notaPedido.kilometros
186 }; 186 };
187 cabeceras.push(cabeceraKilometros); 187 cabeceras.push(cabeceraKilometros);
188 } 188 }
189 cabeceras.push(cabeceraBomba); 189 cabeceras.push(cabeceraBomba);
190 } 190 }
191 191
192 delete notaPedido.id; 192 delete notaPedido.id;
193 $scope.remito = notaPedido; 193 $scope.remito = notaPedido;
194 $scope.remito.id = 0; 194 $scope.remito.id = 0;
195 $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; 195 $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo;
196 196
197 for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { 197 for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) {
198 notaPedido.articulosNotaPedido[i].id = 0; 198 notaPedido.articulosNotaPedido[i].id = 0;
199 } 199 }
200 200
201 $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; 201 $scope.remito.articulosRemito = notaPedido.articulosNotaPedido;
202 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito, 202 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito,
203 notaPedido.cotizacion.VENDEDOR); 203 notaPedido.cotizacion.VENDEDOR);
204 204
205 if (notaPedido.idPrecioCondicion > 0) { 205 if (notaPedido.idPrecioCondicion > 0) {
206 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 206 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
207 }else { 207 }else {
208 $scope.idLista = -1; 208 $scope.idLista = -1;
209 } 209 }
210 210
211 enableObservaciones(notaPedido.observaciones ? true : false); 211 enableObservaciones(notaPedido.observaciones ? true : false);
212 addArrayCabecera(cabeceras); 212 addArrayCabecera(cabeceras);
213 213
214 }, function() { 214 }, function() {
215 // funcion ejecutada cuando se cancela el modal 215 // funcion ejecutada cuando se cancela el modal
216 } 216 }
217 ); 217 );
218 } 218 }
219 }; 219 };
220 220
221 $scope.seleccionarRemito = function() { 221 $scope.seleccionarRemito = function() {
222 var modalInstance = $uibModal.open( 222 var modalInstance = $uibModal.open(
223 { 223 {
224 ariaLabelledBy: 'Busqueda de Remito', 224 ariaLabelledBy: 'Busqueda de Remito',
225 templateUrl: 'foca-modal-remito.html', 225 templateUrl: 'foca-modal-remito.html',
226 controller: 'focaModalRemitoController', 226 controller: 'focaModalRemitoController',
227 size: 'lg', 227 size: 'lg',
228 resolve: {usadoPor: function() {return 'remito';}} 228 resolve: {usadoPor: function() {return 'remito';}}
229 } 229 }
230 ); 230 );
231 modalInstance.result.then( 231 modalInstance.result.then(
232 setearRemito, function() { 232 setearRemito, function() {
233 // funcion ejecutada cuando se cancela el modal 233 // funcion ejecutada cuando se cancela el modal
234 } 234 }
235 ); 235 );
236 }; 236 };
237 237
238 //validacion por domicilio y por plazo pago 238 //validacion por domicilio y por plazo pago
239 $scope.crearRemito = function() { 239 $scope.crearRemito = function() {
240 if (!$scope.remito.vendedor.NUM) { 240 if (!$scope.remito.vendedor.NUM) {
241 focaModalService.alert('Ingrese Vendedor'); 241 focaModalService.alert('Ingrese Vendedor');
242 return; 242 return;
243 } else if (!$scope.remito.cliente.COD) { 243 } else if (!$scope.remito.cliente.COD) {
244 focaModalService.alert('Ingrese Cliente'); 244 focaModalService.alert('Ingrese Cliente');
245 return; 245 return;
246 } else if (!$scope.remito.proveedor) { 246 } else if (!$scope.remito.proveedor) {
247 focaModalService.alert('Ingrese Proveedor'); 247 focaModalService.alert('Ingrese Proveedor');
248 return; 248 return;
249 } else if (!$scope.remito.cotizacion.moneda.id && 249 } else if (!$scope.remito.cotizacion.moneda.id &&
250 !$scope.remito.cotizacion.moneda.ID) 250 !$scope.remito.cotizacion.moneda.ID)
251 { 251 {
252 focaModalService.alert('Ingrese Moneda'); 252 focaModalService.alert('Ingrese Moneda');
253 return; 253 return;
254 } else if (!$scope.remito.cotizacion.ID) { 254 } else if (!$scope.remito.cotizacion.ID) {
255 focaModalService.alert('Ingrese Cotización'); 255 focaModalService.alert('Ingrese Cotización');
256 return; 256 return;
257 } else if ( 257 } else if (
258 $scope.remito.flete === undefined || $scope.remito.flete === null) 258 $scope.remito.flete === undefined || $scope.remito.flete === null)
259 { 259 {
260 focaModalService.alert('Ingrese Flete'); 260 focaModalService.alert('Ingrese Flete');
261 return; 261 return;
262 } else if ($scope.remito.articulosRemito.length === 0) { 262 } else if ($scope.remito.articulosRemito.length === 0) {
263 focaModalService.alert('Debe cargar al menos un articulo'); 263 focaModalService.alert('Debe cargar al menos un articulo');
264 return; 264 return;
265 } 265 }
266 focaBotoneraLateralService.startGuardar(); 266 focaBotoneraLateralService.startGuardar();
267 $scope.saveLoading = true; 267 $scope.saveLoading = true;
268 var save = { 268 var save = {
269 remito: { 269 remito: {
270 id: $scope.remito.id, 270 id: $scope.remito.id,
271 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 271 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
272 idCliente: $scope.remito.cliente.COD, 272 idCliente: $scope.remito.cliente.COD,
273 nombreCliente: $scope.remito.cliente.NOM, 273 nombreCliente: $scope.remito.cliente.NOM,
274 cuitCliente: $scope.remito.cliente.CUIT, 274 cuitCliente: $scope.remito.cliente.CUIT,
275 responsabilidadIvaCliente: 0,//TODO, 275 responsabilidadIvaCliente: 0,//TODO,
276 descuento: 0,//TODO, 276 descuento: 0,//TODO,
277 importeNeto: 0,//TODO 277 importeNeto: 0,//TODO
278 importeExento: 0,//TODO 278 importeExento: 0,//TODO
279 importeIva: 0,//TODO 279 importeIva: 0,//TODO
280 importeIvaServicios: 0,//TODO 280 importeIvaServicios: 0,//TODO
281 importeImpuestoInterno: 0,//TODO 281 importeImpuestoInterno: 0,//TODO
282 importeImpuestoInterno1: 0,//TODO 282 importeImpuestoInterno1: 0,//TODO
283 importeImpuestoInterno2: 0,//TODO 283 importeImpuestoInterno2: 0,//TODO
284 percepcion: 0,//TODO 284 percepcion: 0,//TODO
285 percepcionIva: 0,//TODO 285 percepcionIva: 0,//TODO
286 redondeo: 0,//TODO 286 redondeo: 0,//TODO
287 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, 287 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR,
288 numeroNotaPedido: $scope.remito.numeroNotaPedido, 288 numeroNotaPedido: $scope.remito.numeroNotaPedido,
289 anulado: false, 289 anulado: false,
290 planilla: 0,//TODO 290 planilla: 0,//TODO
291 lugar: 0,//TODO 291 lugar: 0,//TODO
292 cuentaMadre: 0,// 292 cuentaMadre: 0,//
293 cuentaContable: 0,//TODO 293 cuentaContable: 0,//TODO
294 asiento: 0,//TODO 294 asiento: 0,//TODO
295 e_hd: '',//TODO 295 e_hd: '',//TODO
296 c_hd: '', 296 c_hd: '',
297 numeroLiquidoProducto: 0,//TODO 297 numeroLiquidoProducto: 0,//TODO
298 idVendedor: $scope.remito.idVendedor, 298 idVendedor: $scope.remito.idVendedor,
299 idProveedor: $scope.remito.idProveedor, 299 idProveedor: $scope.remito.idProveedor,
300 idDomicilio: $scope.remito.idDomicilio, 300 idDomicilio: $scope.remito.idDomicilio,
301 idCotizacion: $scope.remito.cotizacion.ID, 301 idCotizacion: $scope.remito.cotizacion.ID,
302 idPrecioCondicion: $scope.remito.idPrecioCondicion, 302 idPrecioCondicion: $scope.remito.idPrecioCondicion,
303 flete: $scope.remito.flete, 303 flete: $scope.remito.flete,
304 fob: $scope.remito.fob, 304 fob: $scope.remito.fob,
305 bomba: $scope.remito.bomba, 305 bomba: $scope.remito.bomba,
306 kilometros: $scope.remito.kilometros, 306 kilometros: $scope.remito.kilometros,
307 domicilioStamp: $scope.remito.domicilioStamp, 307 domicilioStamp: $scope.remito.domicilioStamp,
308 estado: 0,//TODO 308 estado: 0,//TODO
309 destinoVenta: 0,//TODO 309 destinoVenta: 0,//TODO
310 operacionTipo: 0//TODO 310 operacionTipo: 0//TODO
311 }, 311 },
312 notaPedido: $scope.notaPedido 312 notaPedido: $scope.notaPedido
313 }; 313 };
314 314
315 crearRemitoService.crearRemito(save).then( 315 crearRemitoService.crearRemito(save).then(
316 function(data) { 316 function(data) {
317 remitoBusinessService.addArticulos($scope.remito.articulosRemito, 317 remitoBusinessService.addArticulos($scope.remito.articulosRemito,
318 data.data.id, $scope.remito.cotizacion.COTIZACION); 318 data.data.id, $scope.remito.cotizacion.COTIZACION);
319 319
320 focaBotoneraLateralService.endGuardar(true); 320 focaBotoneraLateralService.endGuardar(true);
321 $scope.saveLoading = false; 321 $scope.saveLoading = false;
322 322
323 //TODO: updatear plazos 323 //TODO: updatear plazos
324 if ($scope.remito.id === 0) { 324 if ($scope.remito.id === 0) {
325 var plazos = $scope.remito.remitoPlazo; 325 var plazos = $scope.remito.remitoPlazo;
326 326
327 for(var j = 0; j < plazos.length; j++) { 327 for(var j = 0; j < plazos.length; j++) {
328 var json = { 328 var json = {
329 idRemito: $scope.remito.id, 329 idRemito: $scope.remito.id,
330 dias: plazos[j].dias 330 dias: plazos[j].dias
331 }; 331 };
332 crearRemitoService.crearPlazosParaRemito(json); 332 crearRemitoService.crearPlazosParaRemito(json);
333 } 333 }
334 } 334 }
335 abrirModalMail(data.data.id, $scope.remito.cliente, $filter('comprobante')([ 335 abrirModalMail(data.data.id, $scope.remito.cliente, $filter('comprobante')([
336 data.data.sucursal, 336 data.data.sucursal,
337 data.data.numero 337 data.data.numero
338 ])); 338 ]));
339 339
340 init(); 340 init();
341 341
342 }, function(error) { 342 }, function(error) {
343 focaModalService.alert('Hubo un error al crear el remito'); 343 focaModalService.alert('Hubo un error al crear el remito');
344 focaBotoneraLateralService.endGuardar(); 344 focaBotoneraLateralService.endGuardar();
345 $scope.saveLoading = false; 345 $scope.saveLoading = false;
346 console.info(error); 346 console.info(error);
347 } 347 }
348 ); 348 );
349 }; 349 };
350 350
351 $scope.seleccionarProductos = function() { 351 $scope.seleccionarProductos = function() {
352 if ($scope.idLista === undefined) { 352 if ($scope.idLista === undefined) {
353 focaModalService.alert( 353 focaModalService.alert(
354 'Primero seleccione una lista de precio y condicion'); 354 'Primero seleccione una lista de precio y condicion');
355 return; 355 return;
356 } 356 }
357 var modalInstance = $uibModal.open( 357 var modalInstance = $uibModal.open(
358 { 358 {
359 ariaLabelledBy: 'Busqueda de Productos', 359 ariaLabelledBy: 'Busqueda de Productos',
360 templateUrl: 'modal-busqueda-productos.html', 360 templateUrl: 'modal-busqueda-productos.html',
361 controller: 'modalBusquedaProductosCtrl', 361 controller: 'modalBusquedaProductosCtrl',
362 resolve: { 362 resolve: {
363 parametroProducto: { 363 parametroProducto: {
364 idLista: $scope.idLista, 364 idLista: $scope.idLista,
365 cotizacion: $scope.remito.cotizacion.COTIZACION, 365 cotizacion: $scope.remito.cotizacion.COTIZACION,
366 simbolo: $scope.remito.cotizacion.moneda.simbolo 366 simbolo: $scope.remito.cotizacion.moneda.simbolo
367 } 367 }
368 }, 368 },
369 size: 'lg' 369 size: 'lg'
370 } 370 }
371 ); 371 );
372 modalInstance.result.then( 372 modalInstance.result.then(
373 function(producto) { 373 function(producto) {
374 var newArt = 374 var newArt =
375 { 375 {
376 id: 0, 376 id: 0,
377 codigo: producto.codigo, 377 codigo: producto.codigo,
378 sector: producto.sector, 378 sector: producto.sector,
379 sectorCodigo: producto.sector + '-' + producto.codigo, 379 sectorCodigo: producto.sector + '-' + producto.codigo,
380 descripcion: producto.descripcion, 380 descripcion: producto.descripcion,
381 item: $scope.remito.articulosRemito.length + 1, 381 item: $scope.remito.articulosRemito.length + 1,
382 nombre: producto.descripcion, 382 nombre: producto.descripcion,
383 precio: parseFloat(producto.precio.toFixed(4)), 383 precio: parseFloat(producto.precio.toFixed(4)),
384 costoUnitario: producto.costo, 384 costoUnitario: producto.costo,
385 editCantidad: false, 385 editCantidad: false,
386 editPrecio: false, 386 editPrecio: false,
387 rubro: producto.CodRub, 387 rubro: producto.CodRub,
388 exentoUnitario: producto.precio, 388 exentoUnitario: producto.precio,
389 ivaUnitario: producto.IMPIVA, 389 ivaUnitario: producto.IMPIVA,
390 impuestoInternoUnitario: producto.ImpInt, 390 impuestoInternoUnitario: producto.ImpInt,
391 impuestoInterno1Unitario: producto.ImpInt2, 391 impuestoInterno1Unitario: producto.ImpInt2,
392 impuestoInterno2Unitario: producto.ImpInt3, 392 impuestoInterno2Unitario: producto.ImpInt3,
393 precioLista: producto.precio, 393 precioLista: producto.precio,
394 combustible: 1, 394 combustible: 1,
395 facturado: 0 395 facturado: 0
396 }; 396 };
397 $scope.articuloACargar = newArt; 397 $scope.articuloACargar = newArt;
398 $scope.cargando = false; 398 $scope.cargando = false;
399 }, function() { 399 }, function() {
400 // funcion ejecutada cuando se cancela el modal 400 // funcion ejecutada cuando se cancela el modal
401 } 401 }
402 ); 402 );
403 }; 403 };
404 404
405 $scope.seleccionarPuntosDeDescarga = function() { 405 $scope.seleccionarPuntosDeDescarga = function() {
406 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { 406 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) {
407 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 407 focaModalService.alert('Primero seleccione un cliente y un domicilio');
408 return; 408 return;
409 }else { 409 }else {
410 var modalInstance = $uibModal.open( 410 var modalInstance = $uibModal.open(
411 { 411 {
412 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 412 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
413 templateUrl: 'modal-punto-descarga.html', 413 templateUrl: 'modal-punto-descarga.html',
414 controller: 'focaModalPuntoDescargaController', 414 controller: 'focaModalPuntoDescargaController',
415 size: 'lg', 415 size: 'lg',
416 resolve: { 416 resolve: {
417 filters: { 417 filters: {
418 idDomicilio: $scope.remito.domicilio.id, 418 idDomicilio: $scope.remito.domicilio.id,
419 idCliente: $scope.remito.cliente.COD, 419 idCliente: $scope.remito.cliente.COD,
420 articulos: $scope.remito.articulosRemito, 420 articulos: $scope.remito.articulosRemito,
421 puntosDescarga: $scope.remito.domicilio.puntosDescarga 421 puntosDescarga: $scope.remito.domicilio.puntosDescarga
422 } 422 }
423 } 423 }
424 } 424 }
425 ); 425 );
426 modalInstance.result.then( 426 modalInstance.result.then(
427 function(puntosDescarga) { 427 function(puntosDescarga) {
428 $scope.remito.puntosDescarga = puntosDescarga; 428 $scope.remito.puntosDescarga = puntosDescarga;
429 429
430 //AGREGO PUNTOS DE DESCARGA A CABECERA 430 //AGREGO PUNTOS DE DESCARGA A CABECERA
431 var puntosStamp = ''; 431 var puntosStamp = '';
432 puntosDescarga.forEach(function(punto, idx, arr) { 432 puntosDescarga.forEach(function(punto, idx, arr) {
433 puntosStamp += punto.descripcion; 433 puntosStamp += punto.descripcion;
434 if ((idx + 1) !== arr.length) puntosStamp += ', '; 434 if ((idx + 1) !== arr.length) puntosStamp += ', ';
435 }); 435 });
436 436
437 $scope.$broadcast('addCabecera', { 437 $scope.$broadcast('addCabecera', {
438 label: 'Puntos de descarga:', 438 label: 'Puntos de descarga:',
439 valor: puntosStamp 439 valor: puntosStamp
440 }); 440 });
441 }, function() { 441 }, function() {
442 $scope.abrirModalDomicilios($scope.cliente); 442 $scope.abrirModalDomicilios($scope.cliente);
443 } 443 }
444 ); 444 );
445 } 445 }
446 }; 446 };
447 447
448 $scope.seleccionarVendedor = function(callback, ocultarVendedor) { 448 $scope.seleccionarVendedor = function(callback, ocultarVendedor) {
449 if (ocultarVendedor) { 449 if (ocultarVendedor) {
450 callback(); 450 callback();
451 return; 451 return;
452 } 452 }
453 453
454 if (varlidarRemitoFacturado()) { 454 if (varlidarRemitoFacturado()) {
455 var parametrosModal = { 455 var parametrosModal = {
456 titulo: 'Búsqueda vendedores', 456 titulo: 'Búsqueda vendedores',
457 query: '/vendedor', 457 query: '/vendedor',
458 columnas: [ 458 columnas: [
459 { 459 {
460 propiedad: 'NUM', 460 propiedad: 'NUM',
461 nombre: 'Código', 461 nombre: 'Código',
462 filtro: { 462 filtro: {
463 nombre: 'rellenarDigitos', 463 nombre: 'rellenarDigitos',
464 parametro: 3 464 parametro: 3
465 } 465 }
466 }, 466 },
467 { 467 {
468 propiedad: 'NOM', 468 propiedad: 'NOM',
469 nombre: 'Nombre' 469 nombre: 'Nombre'
470 } 470 }
471 ], 471 ],
472 size: 'md' 472 size: 'md'
473 }; 473 };
474 focaModalService.modal(parametrosModal).then( 474 focaModalService.modal(parametrosModal).then(
475 function(vendedor) { 475 function(vendedor) {
476 $scope.$broadcast('addCabecera',{ 476 $scope.$broadcast('addCabecera',{
477 label: 'Vendedor:', 477 label: 'Vendedor:',
478 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 478 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
479 vendedor.NOM 479 vendedor.NOM
480 }); 480 });
481 $scope.remito.idVendedor = vendedor.id; 481 $scope.remito.idVendedor = vendedor.id;
482 $scope.remito.vendedor = vendedor; 482 $scope.remito.vendedor = vendedor;
483 deleteCliente(); 483 deleteCliente();
484 callback(); 484 callback();
485 }, function() { 485 }, function() {
486 486
487 } 487 }
488 ); 488 );
489 } 489 }
490 }; 490 };
491 491
492 $scope.seleccionarCliente = function(ocultarVendedor) { 492 $scope.seleccionarCliente = function(ocultarVendedor) {
493 493
494 $scope.seleccionarVendedor(function() { 494 $scope.seleccionarVendedor(function() {
495 if (varlidarRemitoFacturado()) { 495 if (varlidarRemitoFacturado()) {
496 var modalInstance = $uibModal.open( 496 var modalInstance = $uibModal.open(
497 { 497 {
498 ariaLabelledBy: 'Busqueda de Cliente', 498 ariaLabelledBy: 'Busqueda de Cliente',
499 templateUrl: 'foca-busqueda-cliente-modal.html', 499 templateUrl: 'foca-busqueda-cliente-modal.html',
500 controller: 'focaBusquedaClienteModalController', 500 controller: 'focaBusquedaClienteModalController',
501 resolve: { 501 resolve: {
502 vendedor: function() { return $scope.remito.vendedor; }, 502 vendedor: function() { return $scope.remito.vendedor; },
503 cobrador: function() { return null; } 503 cobrador: function() { return null; }
504 }, 504 },
505 size: 'lg' 505 size: 'lg'
506 } 506 }
507 ); 507 );
508 modalInstance.result.then( 508 modalInstance.result.then(
509 function(cliente) { 509 function(cliente) {
510 $scope.abrirModalDomicilios(cliente); 510 $scope.abrirModalDomicilios(cliente);
511 $scope.cliente = cliente; 511 $scope.cliente = cliente;
512 }, function() { 512 }, function() {
513 $scope.seleccionarCliente(); 513 $scope.seleccionarCliente();
514 } 514 }
515 ); 515 );
516 } 516 }
517 }, ocultarVendedor); 517 }, ocultarVendedor);
518 }; 518 };
519 519
520 $scope.seleccionarProveedor = function(callback) { 520 $scope.seleccionarProveedor = function(callback) {
521 if (varlidarRemitoFacturado()) { 521 if (varlidarRemitoFacturado()) {
522 var parametrosModal = { 522 var parametrosModal = {
523 titulo: 'Búsqueda de Proveedor', 523 titulo: 'Búsqueda de Proveedor',
524 query: '/proveedor', 524 query: '/proveedor',
525 columnas: [ 525 columnas: [
526 { 526 {
527 nombre: 'Código', 527 nombre: 'Código',
528 propiedad: 'COD', 528 propiedad: 'COD',
529 filtro: { 529 filtro: {
530 nombre: 'rellenarDigitos', 530 nombre: 'rellenarDigitos',
531 parametro: 5 531 parametro: 5
532 } 532 }
533 }, 533 },
534 { 534 {
535 nombre: 'Nombre', 535 nombre: 'Nombre',
536 propiedad: 'NOM' 536 propiedad: 'NOM'
537 }, 537 },
538 { 538 {
539 nombre: 'CUIT', 539 nombre: 'CUIT',
540 propiedad: 'CUIT' 540 propiedad: 'CUIT'
541 } 541 }
542 ], 542 ],
543 tipo: 'POST', 543 tipo: 'POST',
544 json: {razonCuitCod: ''} 544 json: {razonCuitCod: ''}
545 }; 545 };
546 focaModalService.modal(parametrosModal).then( 546 focaModalService.modal(parametrosModal).then(
547 function(proveedor) { 547 function(proveedor) {
548 $scope.remito.proveedor = proveedor; 548 $scope.remito.proveedor = proveedor;
549 $scope.remito.idProveedor = proveedor.COD; 549 $scope.remito.idProveedor = proveedor.COD;
550 550
551 $scope.$broadcast('addCabecera',{ 551 $scope.$broadcast('addCabecera',{
552 label: 'Proveedor:', 552 label: 'Proveedor:',
553 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 553 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
554 proveedor.NOM 554 proveedor.NOM
555 }); 555 });
556 callback(); 556 callback();
557 }, function() { } 557 }, function() { }
558 ); 558 );
559 } 559 }
560 }; 560 };
561 561
562 $scope.abrirModalDomicilios = function(cliente) { 562 $scope.abrirModalDomicilios = function(cliente) {
563 var modalInstanceDomicilio = $uibModal.open( 563 var modalInstanceDomicilio = $uibModal.open(
564 { 564 {
565 ariaLabelledBy: 'Busqueda de Domicilios', 565 ariaLabelledBy: 'Busqueda de Domicilios',
566 templateUrl: 'modal-domicilio.html', 566 templateUrl: 'modal-domicilio.html',
567 controller: 'focaModalDomicilioController', 567 controller: 'focaModalDomicilioController',
568 size: 'lg', 568 size: 'lg',
569 resolve: { 569 resolve: {
570 idCliente: function() { return cliente.cod; }, 570 idCliente: function() { return cliente.cod; },
571 esNuevo: function() { return cliente.esNuevo; } 571 esNuevo: function() { return cliente.esNuevo; }
572 } 572 }
573 } 573 }
574 ); 574 );
575 modalInstanceDomicilio.result.then( 575 modalInstanceDomicilio.result.then(
576 function(domicilio) { 576 function(domicilio) {
577 $scope.remito.domicilio = domicilio; 577 $scope.remito.domicilio = domicilio;
578 $scope.remito.cliente = { 578 $scope.remito.cliente = {
579 COD: cliente.cod, 579 COD: cliente.cod,
580 CUIT: cliente.cuit, 580 CUIT: cliente.cuit,
581 NOM: cliente.nom, 581 NOM: cliente.nom,
582 MAIL: cliente.mail, 582 MAIL: cliente.mail,
583 MOD: cliente.mod 583 MOD: cliente.mod
584 }; 584 };
585 585
586 586
587 var domicilioStamp = 587 var domicilioStamp =
588 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 588 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
589 domicilio.Localidad + ', ' + domicilio.Provincia; 589 domicilio.Localidad + ', ' + domicilio.Provincia;
590 $scope.remito.domicilioStamp = domicilioStamp; 590 $scope.remito.domicilioStamp = domicilioStamp;
591 591
592 $scope.$broadcast('addCabecera',{ 592 $scope.$broadcast('addCabecera',{
593 label: 'Cliente:', 593 label: 'Cliente:',
594 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 594 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
595 }); 595 });
596 $scope.$broadcast('addCabecera',{ 596 $scope.$broadcast('addCabecera',{
597 label: 'Domicilio:', 597 label: 'Domicilio:',
598 valor: domicilioStamp 598 valor: domicilioStamp
599 }); 599 });
600 600
601 if (domicilio.verPuntos) { 601 if (domicilio.verPuntos) {
602 delete $scope.remito.domicilio.verPuntos; 602 delete $scope.remito.domicilio.verPuntos;
603 $scope.seleccionarPuntosDeDescarga(); 603 $scope.seleccionarPuntosDeDescarga();
604 }else { 604 }else {
605 crearRemitoService 605 crearRemitoService
606 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 606 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
607 .then(function(res) { 607 .then(function(res) {
608 if (res.data.length) $scope.seleccionarPuntosDeDescarga(); 608 if (res.data.length) $scope.seleccionarPuntosDeDescarga();
609 }); 609 });
610 } 610 }
611 }, function() { 611 }, function() {
612 $scope.seleccionarCliente(true); 612 $scope.seleccionarCliente(true);
613 return; 613 return;
614 } 614 }
615 ); 615 );
616 }; 616 };
617 617
618 $scope.mostrarFichaCliente = function() { 618 $scope.getTotal = function() {
619 $uibModal.open( 619 var total = 0;
620 { 620 var arrayTempArticulos = $scope.remito.articulosRemito;
621 ariaLabelledBy: 'Datos del Cliente', 621 for(var i = 0; i < arrayTempArticulos.length; i++) {
622 templateUrl: 'foca-crear-remito-ficha-cliente.html', 622 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
623 controller: 'focaCrearRemitoFichaClienteController', 623 }
624 size: 'lg'
625 }
626 );
627 };
628
629 $scope.getTotal = function() {
630 var total = 0;
631 var arrayTempArticulos = $scope.remito.articulosRemito;
632 for(var i = 0; i < arrayTempArticulos.length; i++) {
633 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
634 }
635 return parseFloat(total.toFixed(2)); 624 return parseFloat(total.toFixed(2));
636 }; 625 };
637 626
638 $scope.getSubTotal = function() { 627 $scope.getSubTotal = function() {
639 if ($scope.articuloACargar) { 628 if ($scope.articuloACargar) {
640 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 629 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
641 } 630 }
642 }; 631 };
643 632
644 $scope.seleccionarPreciosYCondiciones = function() { 633 $scope.seleccionarPreciosYCondiciones = function() {
645 if (!$scope.remito.cliente.COD) { 634 if (!$scope.remito.cliente.COD) {
646 focaModalService.alert('Primero seleccione un cliente'); 635 focaModalService.alert('Primero seleccione un cliente');
647 return; 636 return;
648 } 637 }
649 if (varlidarRemitoFacturado()) { 638 if (varlidarRemitoFacturado()) {
650 var modalInstance = $uibModal.open( 639 var modalInstance = $uibModal.open(
651 { 640 {
652 ariaLabelledBy: 'Busqueda de Precio Condición', 641 ariaLabelledBy: 'Busqueda de Precio Condición',
653 templateUrl: 'modal-precio-condicion.html', 642 templateUrl: 'modal-precio-condicion.html',
654 controller: 'focaModalPrecioCondicionController', 643 controller: 'focaModalPrecioCondicionController',
655 size: 'lg', 644 size: 'lg',
656 resolve: { 645 resolve: {
657 idListaPrecio: function() { 646 idListaPrecio: function() {
658 return $scope.remito.cliente.MOD || null; 647 return $scope.remito.cliente.MOD || null;
659 } 648 }
660 } 649 }
661 } 650 }
662 ); 651 );
663 modalInstance.result.then( 652 modalInstance.result.then(
664 function(precioCondicion) { 653 function(precioCondicion) {
665 var cabecera = ''; 654 var cabecera = '';
666 var plazosConcat = ''; 655 var plazosConcat = '';
667 if (!Array.isArray(precioCondicion)) { 656 if (!Array.isArray(precioCondicion)) {
668 $scope.remito.idPrecioCondicion = precioCondicion.id; 657 $scope.remito.idPrecioCondicion = precioCondicion.id;
669 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 658 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
670 $scope.idLista = precioCondicion.idListaPrecio; 659 $scope.idLista = precioCondicion.idListaPrecio;
671 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 660 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
672 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 661 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
673 } 662 }
674 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 663 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
675 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 664 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
676 }else { //Cuando se ingresan los plazos manualmente 665 }else { //Cuando se ingresan los plazos manualmente
677 $scope.remito.idPrecioCondicion = 0; 666 $scope.remito.idPrecioCondicion = 0;
678 //-1, el modal productos busca todos los productos 667 //-1, el modal productos busca todos los productos
679 $scope.idLista = -1; 668 $scope.idLista = -1;
680 $scope.remito.remitoPlazo = precioCondicion; 669 $scope.remito.remitoPlazo = precioCondicion;
681 for(var j = 0; j < precioCondicion.length; j++) { 670 for(var j = 0; j < precioCondicion.length; j++) {
682 plazosConcat += precioCondicion[j].dias + ' '; 671 plazosConcat += precioCondicion[j].dias + ' ';
683 } 672 }
684 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 673 cabecera = 'Ingreso manual ' + plazosConcat.trim();
685 } 674 }
686 $scope.remito.articulosRemito = []; 675 $scope.remito.articulosRemito = [];
687 $scope.$broadcast('addCabecera',{ 676 $scope.$broadcast('addCabecera',{
688 label: 'Precios y condiciones:', 677 label: 'Precios y condiciones:',
689 valor: cabecera 678 valor: cabecera
690 }); 679 });
691 680
692 $scope.remito.precioCondicion = precioCondicion; 681 $scope.remito.precioCondicion = precioCondicion;
693 }, function() { 682 }, function() {
694 683
695 } 684 }
696 ); 685 );
697 } 686 }
698 }; 687 };
699 688
700 $scope.seleccionarTransportista = function() { 689 $scope.seleccionarTransportista = function() {
701 $scope.seleccionarProveedor(function() { 690 $scope.seleccionarProveedor(function() {
702 if (varlidarRemitoFacturado()) { 691 if (varlidarRemitoFacturado()) {
703 var modalInstance = $uibModal.open( 692 var modalInstance = $uibModal.open(
704 { 693 {
705 ariaLabelledBy: 'Busqueda de Flete', 694 ariaLabelledBy: 'Busqueda de Flete',
706 templateUrl: 'modal-flete.html', 695 templateUrl: 'modal-flete.html',
707 controller: 'focaModalFleteController', 696 controller: 'focaModalFleteController',
708 size: 'lg', 697 size: 'lg',
709 resolve: { 698 resolve: {
710 parametrosFlete: 699 parametrosFlete:
711 function() { 700 function() {
712 return { 701 return {
713 flete: $scope.remito.flete ? '1' : 702 flete: $scope.remito.flete ? '1' :
714 ($scope.remito.fob ? 'FOB' : 703 ($scope.remito.fob ? 'FOB' :
715 ($scope.remito.flete === undefined ? 704 ($scope.remito.flete === undefined ?
716 null : '0')), 705 null : '0')),
717 bomba: $scope.remito.bomba ? '1' : 706 bomba: $scope.remito.bomba ? '1' :
718 ($scope.remito.bomba === undefined ? 707 ($scope.remito.bomba === undefined ?
719 null : '0'), 708 null : '0'),
720 kilometros: $scope.remito.kilometros 709 kilometros: $scope.remito.kilometros
721 }; 710 };
722 } 711 }
723 } 712 }
724 } 713 }
725 ); 714 );
726 modalInstance.result.then( 715 modalInstance.result.then(
727 function(datos) { 716 function(datos) {
728 $scope.remito.flete = datos.flete; 717 $scope.remito.flete = datos.flete;
729 $scope.remito.fob = datos.FOB; 718 $scope.remito.fob = datos.FOB;
730 $scope.remito.bomba = datos.bomba; 719 $scope.remito.bomba = datos.bomba;
731 $scope.remito.kilometros = datos.kilometros; 720 $scope.remito.kilometros = datos.kilometros;
732 721
733 $scope.$broadcast('addCabecera',{ 722 $scope.$broadcast('addCabecera',{
734 label: 'Flete:', 723 label: 'Flete:',
735 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 724 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
736 }); 725 });
737 if (datos.flete) { 726 if (datos.flete) {
738 $scope.$broadcast('addCabecera',{ 727 $scope.$broadcast('addCabecera',{
739 label: 'Bomba:', 728 label: 'Bomba:',
740 valor: datos.bomba ? 'Si' : 'No' 729 valor: datos.bomba ? 'Si' : 'No'
741 }); 730 });
742 $scope.$broadcast('addCabecera',{ 731 $scope.$broadcast('addCabecera',{
743 label: 'Kilometros:', 732 label: 'Kilometros:',
744 valor: datos.kilometros 733 valor: datos.kilometros
745 }); 734 });
746 } else { 735 } else {
747 $scope.$broadcast('removeCabecera', 'Bomba:'); 736 $scope.$broadcast('removeCabecera', 'Bomba:');
748 $scope.$broadcast('removeCabecera', 'Kilometros:'); 737 $scope.$broadcast('removeCabecera', 'Kilometros:');
749 $scope.remito.fob = false; 738 $scope.remito.fob = false;
750 $scope.remito.bomba = false; 739 $scope.remito.bomba = false;
751 $scope.remito.kilometros = null; 740 $scope.remito.kilometros = null;
752 } 741 }
753 }, function() { 742 }, function() {
754 $scope.seleccionarTransportista(); 743 $scope.seleccionarTransportista();
755 } 744 }
756 ); 745 );
757 } 746 }
758 }); 747 });
759 }; 748 };
760 749
761 $scope.seleccionarMoneda = function() { 750 $scope.seleccionarMoneda = function() {
762 if (varlidarRemitoFacturado()) { 751 if (varlidarRemitoFacturado()) {
763 var parametrosModal = { 752 var parametrosModal = {
764 titulo: 'Búsqueda de monedas', 753 titulo: 'Búsqueda de monedas',
765 query: '/moneda', 754 query: '/moneda',
766 columnas: [ 755 columnas: [
767 { 756 {
768 propiedad: 'DETALLE', 757 propiedad: 'DETALLE',
769 nombre: 'Nombre' 758 nombre: 'Nombre'
770 }, 759 },
771 { 760 {
772 propiedad: 'SIMBOLO', 761 propiedad: 'SIMBOLO',
773 nombre: 'Símbolo' 762 nombre: 'Símbolo'
774 } 763 }
775 ], 764 ],
776 size: 'md' 765 size: 'md'
777 }; 766 };
778 focaModalService.modal(parametrosModal).then( 767 focaModalService.modal(parametrosModal).then(
779 function(moneda) { 768 function(moneda) {
780 $scope.abrirModalCotizacion(moneda); 769 $scope.abrirModalCotizacion(moneda);
781 }, function() { 770 }, function() {
782 771
783 } 772 }
784 ); 773 );
785 } 774 }
786 }; 775 };
787 776
788 $scope.seleccionarObservaciones = function() { 777 $scope.seleccionarObservaciones = function() {
789 focaModalService 778 focaModalService
790 .prompt({ 779 .prompt({
791 titulo: 'Observaciones', 780 titulo: 'Observaciones',
792 value: $scope.remito.observaciones, 781 value: $scope.remito.observaciones,
793 textarea: true, 782 textarea: true,
794 readonly: true 783 readonly: true
795 }) 784 })
796 .then(function(observaciones) { 785 .then(function(observaciones) {
797 $scope.remito.observaciones = observaciones; 786 $scope.remito.observaciones = observaciones;
798 }); 787 });
799 }; 788 };
800 789
801 $scope.abrirModalCotizacion = function(moneda) { 790 $scope.abrirModalCotizacion = function(moneda) {
802 var modalInstance = $uibModal.open( 791 var modalInstance = $uibModal.open(
803 { 792 {
804 ariaLabelledBy: 'Busqueda de Cotización', 793 ariaLabelledBy: 'Busqueda de Cotización',
805 templateUrl: 'modal-cotizacion.html', 794 templateUrl: 'modal-cotizacion.html',
806 controller: 'focaModalCotizacionController', 795 controller: 'focaModalCotizacionController',
807 size: 'lg', 796 size: 'lg',
808 resolve: {idMoneda: function() {return moneda.ID;}} 797 resolve: {idMoneda: function() {return moneda.ID;}}
809 } 798 }
810 ); 799 );
811 modalInstance.result.then( 800 modalInstance.result.then(
812 function(cotizacion) { 801 function(cotizacion) {
813 var articulosTablaTemp = $scope.remito.articulosRemito; 802 var articulosTablaTemp = $scope.remito.articulosRemito;
814 for(var i = 0; i < articulosTablaTemp.length; i++) { 803 for(var i = 0; i < articulosTablaTemp.length; i++) {
815 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 804 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
816 $scope.remito.cotizacion.COTIZACION; 805 $scope.remito.cotizacion.COTIZACION;
817 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 806 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
818 cotizacion.COTIZACION; 807 cotizacion.COTIZACION;
819 } 808 }
820 $scope.remito.articulosRemito = articulosTablaTemp; 809 $scope.remito.articulosRemito = articulosTablaTemp;
821 $scope.remito.cotizacion.moneda = moneda; 810 $scope.remito.cotizacion.moneda = moneda;
822 $scope.remito.cotizacion = cotizacion; 811 $scope.remito.cotizacion = cotizacion;
823 if (moneda.DETALLE === 'PESOS ARGENTINOS') { 812 if (moneda.DETALLE === 'PESOS ARGENTINOS') {
824 $scope.$broadcast('removeCabecera', 'Moneda:'); 813 $scope.$broadcast('removeCabecera', 'Moneda:');
825 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 814 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
826 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 815 $scope.$broadcast('removeCabecera', 'Cotizacion:');
827 }else { 816 }else {
828 $scope.$broadcast('addCabecera',{ 817 $scope.$broadcast('addCabecera',{
829 label: 'Moneda:', 818 label: 'Moneda:',
830 valor: moneda.DETALLE 819 valor: moneda.DETALLE
831 }); 820 });
832 $scope.$broadcast('addCabecera',{ 821 $scope.$broadcast('addCabecera',{
833 label: 'Fecha cotizacion:', 822 label: 'Fecha cotizacion:',
834 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 823 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
835 }); 824 });
836 $scope.$broadcast('addCabecera',{ 825 $scope.$broadcast('addCabecera',{
837 label: 'Cotizacion:', 826 label: 'Cotizacion:',
838 valor: $filter('number')(cotizacion.COTIZACION, '2') 827 valor: $filter('number')(cotizacion.COTIZACION, '2')
839 }); 828 });
840 } 829 }
841 }, function() { 830 }, function() {
842 831
843 } 832 }
844 ); 833 );
845 }; 834 };
846 835
847 $scope.agregarATabla = function(key) { 836 $scope.agregarATabla = function(key) {
848 if (key === 13) { 837 if (key === 13) {
849 if ($scope.articuloACargar.cantidad === undefined || 838 if ($scope.articuloACargar.cantidad === undefined ||
850 $scope.articuloACargar.cantidad === 0 || 839 $scope.articuloACargar.cantidad === 0 ||
851 $scope.articuloACargar.cantidad === null ) { 840 $scope.articuloACargar.cantidad === null ) {
852 focaModalService.alert('El valor debe ser al menos 1'); 841 focaModalService.alert('El valor debe ser al menos 1');
853 return; 842 return;
854 } 843 }
855 delete $scope.articuloACargar.sectorCodigo; 844 delete $scope.articuloACargar.sectorCodigo;
856 $scope.remito.articulosRemito.push($scope.articuloACargar); 845 $scope.remito.articulosRemito.push($scope.articuloACargar);
857 $scope.cargando = true; 846 $scope.cargando = true;
858 } 847 }
859 }; 848 };
860 849
861 $scope.quitarArticulo = function(key) { 850 $scope.quitarArticulo = function(key) {
862 $scope.remito.articulosRemito.splice(key, 1); 851 $scope.remito.articulosRemito.splice(key, 1);
863 }; 852 };
864 853
865 $scope.editarArticulo = function(key, articulo) { 854 $scope.editarArticulo = function(key, articulo) {
866 if (key === 13) { 855 if (key === 13) {
867 if (!articulo.cantidad || !articulo.precio) { 856 if (!articulo.cantidad || !articulo.precio) {
868 focaModalService.alert('Los valores deben ser al menos 1'); 857 focaModalService.alert('Los valores deben ser al menos 1');
869 return; 858 return;
870 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 859 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
871 focaModalService.alert('Los valores no pueden ser negativos'); 860 focaModalService.alert('Los valores no pueden ser negativos');
872 return; 861 return;
873 } 862 }
874 articulo.editCantidad = articulo.editPrecio = false; 863 articulo.editCantidad = articulo.editPrecio = false;
875 } 864 }
876 }; 865 };
877 866
878 $scope.cambioEdit = function(articulo, propiedad) { 867 $scope.cambioEdit = function(articulo, propiedad) {
879 if (propiedad === 'cantidad') { 868 if (propiedad === 'cantidad') {
880 articulo.editCantidad = true; 869 articulo.editCantidad = true;
881 } else if (propiedad === 'precio') { 870 } else if (propiedad === 'precio') {
882 articulo.editPrecio = true; 871 articulo.editPrecio = true;
883 } 872 }
884 }; 873 };
885 874
886 $scope.limpiarFlete = function() { 875 $scope.resetFilter = function() {
887 $scope.remito.fleteNombre = ''; 876 $scope.articuloACargar = {};
888 $scope.remito.chofer = ''; 877 $scope.cargando = true;
889 $scope.remito.vehiculo = ''; 878 };
890 $scope.remito.kilometros = ''; 879 //Recibe aviso si el teclado está en uso
891 $scope.remito.costoUnitarioKmFlete = ''; 880 $rootScope.$on('usarTeclado', function(event, data) {
892 $scope.choferes = '';
893 $scope.vehiculos = '';
894 };
895
896 $scope.limpiarPantalla = function() {
897 $scope.limpiarFlete();
898 $scope.remito.flete = '0';
899 $scope.remito.bomba = '0';
900 $scope.remito.precioCondicion = '';
901 $scope.remito.articulosRemito = [];
902 $scope.remito.vendedor.nombre = '';
903 $scope.remito.cliente = {nombre: ''};
904 $scope.remito.domicilio = {dom: ''};
905 $scope.domiciliosCliente = [];
906 };
907
908 $scope.resetFilter = function() {
909 $scope.articuloACargar = {};
910 $scope.cargando = true;
911 };
912 //Recibe aviso si el teclado está en uso
913 $rootScope.$on('usarTeclado', function(event, data) {
914 if (data) { 881 if (data) {
915 $scope.mostrarTeclado = true; 882 $scope.mostrarTeclado = true;
916 return; 883 return;
917 } 884 }
918 $scope.mostrarTeclado = false; 885 $scope.mostrarTeclado = false;
919 }); 886 });
920 887
921 $scope.selectFocus = function($event) { 888 $scope.selectFocus = function($event) {
922 // Si el teclado esta en uso no selecciona el valor 889 // Si el teclado esta en uso no selecciona el valor
923 if ($scope.mostrarTeclado) { 890 if ($scope.mostrarTeclado) {
924 return; 891 return;
925 } 892 }
926 $event.target.select(); 893 $event.target.select();
927 }; 894 };
928 895
929 function addArrayCabecera(array) { 896 function addArrayCabecera(array) {
930 for (var i = 0; i < array.length; i++) { 897 for (var i = 0; i < array.length; i++) {
931 $scope.$broadcast('addCabecera',{ 898 $scope.$broadcast('addCabecera',{
932 label: array[i].label, 899 label: array[i].label,
933 valor: array[i].valor 900 valor: array[i].valor
934 }); 901 });
935 } 902 }
936 } 903 }
937 904
938 function rellenar(relleno, longitud) { 905 function rellenar(relleno, longitud) {
939 relleno = '' + relleno; 906 relleno = '' + relleno;
940 while (relleno.length < longitud) { 907 while (relleno.length < longitud) {
941 relleno = '0' + relleno; 908 relleno = '0' + relleno;
942 } 909 }
943 910
944 return relleno; 911 return relleno;
945 } 912 }
946 913
947 function varlidarRemitoFacturado() { 914 function varlidarRemitoFacturado() {
948 if ($scope.remito.estado !== 5) { 915 if ($scope.remito.estado !== 5) {
949 return true; 916 return true;
950 } else { 917 } else {
951 focaModalService.alert('No se puede editar un remito facturado'); 918 focaModalService.alert('No se puede editar un remito facturado');
952 return false(); 919 return false();
953 } 920 }
954 } 921 }
955 922
956 function salir() { 923 function salir() {
957 var confirmacion = false; 924 var confirmacion = false;
958 925
959 if (!angular.equals($scope.remito, $scope.inicial)) { 926 if (!angular.equals($scope.remito, $scope.inicial)) {
960 confirmacion = true; 927 confirmacion = true;
961 } 928 }
962 929
963 if (confirmacion) { 930 if (confirmacion) {
964 focaModalService.confirm( 931 focaModalService.confirm(
965 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 932 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
966 ).then(function(data) { 933 ).then(function(data) {
967 if (data) { 934 if (data) {
968 $location.path('/'); 935 $location.path('/');
969 } 936 }
970 }); 937 });
971 } else { 938 } else {
972 $location.path('/'); 939 $location.path('/');
973 } 940 }
974 } 941 }
975 942
976 function enableObservaciones(val) { 943 function enableObservaciones(val) {
977 var boton = $scope.botonera.filter(function(botonObs) { 944 var boton = $scope.botonera.filter(function(botonObs) {
978 return botonObs.label === 'Observaciones'; 945 return botonObs.label === 'Observaciones';
979 }); 946 });
980 947
981 boton[0].disable = !val; 948 boton[0].disable = !val;
982 } 949 }
983 950
984 function setearRemito(remito) { 951 function setearRemito(remito) {
985 //añado cabeceras 952 //añado cabeceras
986 $scope.$broadcast('removeCabecera', 'Moneda:'); 953 $scope.$broadcast('removeCabecera', 'Moneda:');
987 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 954 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
988 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 955 $scope.$broadcast('removeCabecera', 'Cotizacion:');
989 956
990 var cabeceras = []; 957 var cabeceras = [];
991 958
992 if (remito.cotizacion.ID) { 959 if (remito.cotizacion.ID) {
993 cabeceras.push({ 960 cabeceras.push({
994 label: 'Moneda:', 961 label: 'Moneda:',
995 valor: remito.cotizacion.moneda.DETALLE 962 valor: remito.cotizacion.moneda.DETALLE
996 }); 963 });
997 cabeceras.push({ 964 cabeceras.push({
998 label: 'Fecha cotizacion:', 965 label: 'Fecha cotizacion:',
999 valor: $filter('date')(remito.cotizacion.FECHA, 966 valor: $filter('date')(remito.cotizacion.FECHA,
1000 'dd/MM/yyyy') 967 'dd/MM/yyyy')
1001 }); 968 });
1002 cabeceras.push({ 969 cabeceras.push({
1003 label: 'Cotizacion:', 970 label: 'Cotizacion:',
1004 valor: $filter('number')(remito.cotizacion.VENDEDOR, 971 valor: $filter('number')(remito.cotizacion.VENDEDOR,
1005 '2') 972 '2')
1006 }); 973 });
1007 } 974 }
1008 if (remito.cliente.COD) { 975 if (remito.cliente.COD) {
1009 cabeceras.push({ 976 cabeceras.push({
1010 label: 'Cliente:', 977 label: 'Cliente:',
1011 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 978 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
1012 remito.cliente.NOM 979 remito.cliente.NOM
1013 }); 980 });
1014 cabeceras.push({ 981 cabeceras.push({
1015 label: 'Domicilio:', 982 label: 'Domicilio:',
1016 valor: remito.domicilioStamp 983 valor: remito.domicilioStamp
1017 }); 984 });
1018 } 985 }
1019 if (remito.vendedor.NUM) { 986 if (remito.vendedor.NUM) {
1020 cabeceras.push({ 987 cabeceras.push({
1021 label: 'Vendedor:', 988 label: 'Vendedor:',
1022 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 989 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
1023 ' - ' + remito.vendedor.NOM 990 ' - ' + remito.vendedor.NOM
1024 }); 991 });
1025 } 992 }
1026 if (remito.proveedor.COD) { 993 if (remito.proveedor.COD) {
1027 cabeceras.push({ 994 cabeceras.push({
1028 label: 'Proveedor:', 995 label: 'Proveedor:',
1029 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 996 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1030 ' - ' + remito.proveedor.NOM 997 ' - ' + remito.proveedor.NOM
1031 }); 998 });
1032 } 999 }
1033 if (remito.flete !== undefined) { 1000 if (remito.flete !== undefined) {
1034 cabeceras.push({ 1001 cabeceras.push({
1035 label: 'Flete:', 1002 label: 'Flete:',
1036 valor: remito.fob === 1 ? 'FOB' : ( 1003 valor: remito.fob === 1 ? 'FOB' : (
1037 remito.flete === 1 ? 'Si' : 'No') 1004 remito.flete === 1 ? 'Si' : 'No')
1038 }); 1005 });
1039 } 1006 }
1040 if (remito.remitoPlazo) { 1007 if (remito.remitoPlazo) {
1041 cabeceras.push({ 1008 cabeceras.push({
1042 label: 'Precio condicion:', 1009 label: 'Precio condicion:',
1043 valor: valorPrecioCondicion() + ' ' + 1010 valor: valorPrecioCondicion() + ' ' +
1044 remitoBusinessService.plazoToString(remito.remitoPlazo) 1011 remitoBusinessService.plazoToString(remito.remitoPlazo)
1045 }); 1012 });
1046 } 1013 }
1047 1014
1048 function valorPrecioCondicion() { 1015 function valorPrecioCondicion() {
1049 if (remito.idPrecioCondicion > 0) { 1016 if (remito.idPrecioCondicion > 0) {
1050 return remito.precioCondicion.nombre; 1017 return remito.precioCondicion.nombre;
1051 } else { 1018 } else {
1052 return 'Ingreso Manual'; 1019 return 'Ingreso Manual';
1053 } 1020 }
1054 } 1021 }
1055 1022
1056 if (remito.flete === 1) { 1023 if (remito.flete === 1) {
1057 var cabeceraBomba = { 1024 var cabeceraBomba = {
1058 label: 'Bomba', 1025 label: 'Bomba',
1059 valor: remito.bomba === 1 ? 'Si' : 'No' 1026 valor: remito.bomba === 1 ? 'Si' : 'No'
1060 }; 1027 };
1061 if (remito.kilometros) { 1028 if (remito.kilometros) {
1062 var cabeceraKilometros = { 1029 var cabeceraKilometros = {
1063 label: 'Kilometros', 1030 label: 'Kilometros',
1064 valor: remito.kilometros 1031 valor: remito.kilometros
1065 }; 1032 };
1066 cabeceras.push(cabeceraKilometros); 1033 cabeceras.push(cabeceraKilometros);
1067 } 1034 }
1068 cabeceras.push(cabeceraBomba); 1035 cabeceras.push(cabeceraBomba);
1069 } 1036 }
1070 $scope.remito.articulosRemito = remito.articulosRemito; 1037 $scope.remito.articulosRemito = remito.articulosRemito;
1071 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito, 1038 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito,
1072 remito.cotizacion.VENDEDOR); 1039 remito.cotizacion.VENDEDOR);
1073 if (remito.idPrecioCondicion > 0) { 1040 if (remito.idPrecioCondicion > 0) {
1074 $scope.idLista = remito.precioCondicion.idListaPrecio; 1041 $scope.idLista = remito.precioCondicion.idListaPrecio;
1075 } else { 1042 } else {
1076 $scope.idLista = -1; 1043 $scope.idLista = -1;
1077 } 1044 }
1078 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1045 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1079 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1046 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1080 $scope.remito = remito; 1047 $scope.remito = remito;
1081 addArrayCabecera(cabeceras); 1048 addArrayCabecera(cabeceras);
1082 } 1049 }
1083 1050
1084 function getLSRemito() { 1051 function getLSRemito() {
1085 var remito = JSON.parse($localStorage.remito || null); 1052 var remito = JSON.parse($localStorage.remito || null);
1086 if (remito) { 1053 if (remito) {
1087 setearRemito(remito); 1054 setearRemito(remito);
1088 delete $localStorage.remito; 1055 delete $localStorage.remito;
1089 } 1056 }
1090 } 1057 }
1091 1058
1092 function deleteCliente() { 1059 function deleteCliente() {
1093 delete $scope.remito.domicilioStamp; 1060 delete $scope.remito.domicilioStamp;
1094 delete $scope.remito.puntosDescarga; 1061 delete $scope.remito.puntosDescarga;
1095 $scope.remito.domicilio = {dom: ''}; 1062 $scope.remito.domicilio = {dom: ''};
1096 $scope.remito.cliente = {}; 1063 $scope.remito.cliente = {};
1097 $scope.$broadcast('removeCabecera', 'Cliente:'); 1064 $scope.$broadcast('removeCabecera', 'Cliente:');
1098 $scope.$broadcast('removeCabecera', 'Domicilio:'); 1065 $scope.$broadcast('removeCabecera', 'Domicilio:');
1099 $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); 1066 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1100 } 1067 }
1101 1068
1102 function abrirModalMail(id, cliente, numeroRemito) { 1069 function abrirModalMail(id, cliente, numeroRemito) {
1103 focaModalService.mail( 1070 focaModalService.mail(
1104 { 1071 {
1105 titulo: 'Comprobante de remito Nº ' + numeroRemito, 1072 titulo: 'Comprobante de remito Nº ' + numeroRemito,
1106 descarga: { 1073 descarga: {
1107 nombre: numeroRemito + '.pdf', 1074 nombre: numeroRemito + '.pdf',
1108 url: '/remito/comprobante', 1075 url: '/remito/comprobante',
1109 }, 1076 },
1110 envio: { 1077 envio: {
1111 mailCliente: cliente.MAIL, 1078 mailCliente: cliente.MAIL,
1112 url: '/remito/mail', 1079 url: '/remito/mail',
1113 }, 1080 },
1114 options: { 1081 options: {
1115 idRemito: id 1082 idRemito: id
1116 } 1083 }
1117 } 1084 }
1118 ) 1085 )
1119 .then(function(res) { 1086 .then(function(res) {
1120 if (res === false) { 1087 if (res === false) {
1121 abrirModalMail(id); 1088 abrirModalMail(id);
1122 focaModalService.alert('Descarga o envíe su remito ' + 1089 focaModalService.alert('Descarga o envíe su remito ' +
1123 'antes de cerrar esta ventana'); 1090 'antes de cerrar esta ventana');
1124 } 1091 }
1125 }); 1092 });
1126 } 1093 }
1127 } 1094 }
1128 ]); 1095 ]);
1129 1096