Commit 6ee7bd2ecb1ff4826b6d658b4f152cd2ec838591

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

See merge request !98
... ... @@ -4,6 +4,7 @@
4 4 "description": "Listado y ABM nota de pedidos",
5 5 "main": "index.js",
6 6 "scripts": {
  7 + "refresh": "gulp uglify && cp tmp/foca-crear-nota-pedido.js ../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/foca-crear-nota-pedido.min.js",
7 8 "test": "test.html",
8 9 "compile": "gulp uglify",
9 10 "gulp-pre-commit": "gulp pre-commit",
src/js/controller.js
1   -angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
  1 +angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl',
2 2 [
3 3 '$scope',
4 4 '$uibModal',
... ... @@ -14,11 +14,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
14 14 'APP',
15 15 'focaLoginService',
16 16 '$localStorage',
17   - function(
  17 + function (
18 18 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService,
19 19 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
20   - $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage)
21   - {
  20 + $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) {
22 21 config();
23 22 var cotizacionPArgentino = {};
24 23  
... ... @@ -38,9 +37,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
38 37 maxDate: new Date(),
39 38 minDate: new Date(2010, 0, 1)
40 39 };
41   -
  40 +
42 41 //SETEO BOTONERA LATERAL
43   - $timeout(function() {
  42 + $timeout(function () {
44 43 focaBotoneraLateralService.showSalir(false);
45 44 focaBotoneraLateralService.showPausar(true);
46 45 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
... ... @@ -52,10 +51,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
52 51 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador;
53 52 }
54 53  
55   - crearNotaPedidoService.getParametros().then(function(res) {
  54 + crearNotaPedidoService.getParametros().then(function (res) {
56 55 var parametros = JSON.parse(res.data[0].jsonText);
57 56 if ($localStorage.notaPedido) {
58   - $timeout(function() { getLSNotaPedido();} );
  57 + $timeout(function () { getLSNotaPedido(); });
59 58 } else {
60 59 for (var property in parametros) {
61 60 $scope.notaPedido[property] = parametros[property];
... ... @@ -76,7 +75,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
76 75 id: 0,
77 76 cliente: {},
78 77 proveedor: {},
79   - domicilio: {dom: ''},
  78 + domicilio: { dom: '' },
80 79 vendedor: {},
81 80 fechaCarga: new Date(),
82 81 cotizacion: {},
... ... @@ -87,16 +86,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
87 86 $scope.idLista = undefined;
88 87  
89 88 crearNotaPedidoService.getNumeroNotaPedido().then(
90   - function(res) {
  89 + function (res) {
91 90 $scope.puntoVenta = $filter('rellenarDigitos')(
92 91 res.data.sucursal, 4
93 92 );
94   -
  93 +
95 94 $scope.comprobante = $filter('rellenarDigitos')(
96 95 res.data.numeroNotaPedido, 8
97 96 );
98 97 },
99   - function(err) {
  98 + function (err) {
100 99 focaModalService.alert('La terminal no esta configurada correctamente');
101 100 console.info(err);
102 101 }
... ... @@ -104,7 +103,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
104 103  
105 104 if (APP === 'distribuidor') {
106 105 crearNotaPedidoService.getVendedorById($scope.idVendedor).then(
107   - function(res) {
  106 + function (res) {
108 107 var vendedor = res.data;
109 108 $scope.$broadcast('addCabecera', {
110 109 label: 'Vendedor:',
... ... @@ -121,14 +120,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
121 120 $scope.inicial = angular.copy($scope.notaPedido);
122 121 }
123 122  
124   - $scope.$watch('notaPedido', function(newValue) {
  123 + $scope.$watch('notaPedido', function (newValue) {
125 124 focaBotoneraLateralService.setPausarData({
126 125 label: 'notaPedido',
127 126 val: newValue
128 127 });
129 128 }, true);
130 129  
131   - $scope.crearNotaPedido = function() {
  130 + $scope.crearNotaPedido = function () {
132 131 if (!$scope.notaPedido.cliente.COD) {
133 132 focaModalService.alert('Ingrese Cliente');
134 133 return;
... ... @@ -148,8 +147,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
148 147 focaModalService.alert('Ingrese Precios y Condiciones');
149 148 return;
150 149 } else if (
151   - $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
152   - {
  150 + $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) {
153 151 focaModalService.alert('Ingrese Flete');
154 152 return;
155 153 } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
... ... @@ -173,7 +171,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
173 171 idProveedor: $scope.notaPedido.proveedor.COD,
174 172 idDomicilio: $scope.notaPedido.domicilio.id,
175 173 idCotizacion: $scope.notaPedido.cotizacion.ID,
176   - idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
  174 + idListaPrecio: $scope.notaPedido.idPrecioCondicion,
177 175 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
178 176 flete: $scope.notaPedido.flete,
179 177 fob: $scope.notaPedido.fob,
... ... @@ -185,7 +183,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
185 183 total: $scope.getTotal()
186 184 };
187 185 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
188   - function(data) {
  186 + function (data) {
189 187 // Al guardar los datos de la nota de pedido logueamos la
190 188 // actividad para su seguimiento.
191 189 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR?
... ... @@ -197,15 +195,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
197 195 notaPedidoBusinessService.addArticulos(
198 196 $scope.notaPedido.articulosNotaPedido,
199 197 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR);
200   -
201   - if ($scope.notaPedido.notaPedidoPuntoDescarga) {
  198 +
  199 + if ($scope.notaPedido.notaPedidoPuntoDescarga.length > 0) {
202 200 notaPedidoBusinessService.addPuntosDescarga(data.data.id,
203 201 $scope.notaPedido.notaPedidoPuntoDescarga);
204 202 }
205 203  
206 204 var plazos = $scope.notaPedido.notaPedidoPlazo;
207 205 var plazosACrear = [];
208   - plazos.forEach(function(plazo) {
  206 + plazos.forEach(function (plazo) {
209 207 plazosACrear.push({
210 208 idNotaPedido: data.data.id,
211 209 dias: plazo.dias
... ... @@ -223,7 +221,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
223 221 $scope.saveLoading = false;
224 222  
225 223 config();
226   - }, function(error) {
  224 + }, function (error) {
227 225 focaModalService.alert('Hubo un error al crear la nota de pedido');
228 226 focaBotoneraLateralService.endGuardar();
229 227 $scope.saveLoading = false;
... ... @@ -231,7 +229,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
231 229 });
232 230 };
233 231  
234   - $scope.seleccionarNotaPedido = function() {
  232 + $scope.seleccionarNotaPedido = function () {
235 233 var modalInstance = $uibModal.open(
236 234 {
237 235 ariaLabelledBy: 'Busqueda de Nota de Pedido',
... ... @@ -239,8 +237,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
239 237 controller: 'focaModalNotaPedidoController',
240 238 size: 'lg',
241 239 resolve: {
242   - usadoPor: function() {return 'notaPedido';},
243   - idVendedor: function() {
  240 + usadoPor: function () { return 'notaPedido'; },
  241 + idVendedor: function () {
244 242 if (APP === 'distribuidor')
245 243 return $scope.notaPedido.vendedor.id;
246 244 else
... ... @@ -252,12 +250,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
252 250 modalInstance.result.then(setearNotaPedido);
253 251 };
254 252  
255   - $scope.seleccionarProductos = function() {
  253 + $scope.seleccionarProductos = function () {
  254 +
256 255 if ($scope.idLista === undefined) {
257   - focaModalService.alert(
258   - 'Primero seleccione una lista de precio y condicion');
  256 + focaModalService.alert('Primero seleccione una lista de precio y condición');
  257 + return;
  258 + } else if (!validarNotaRemitada()) {
259 259 return;
260 260 }
  261 +
261 262 var modalInstance = $uibModal.open(
262 263 {
263 264 ariaLabelledBy: 'Busqueda de Productos',
... ... @@ -274,7 +275,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
274 275 }
275 276 );
276 277 modalInstance.result.then(
277   - function(producto) {
  278 + function (producto) {
278 279 var newArt =
279 280 {
280 281 id: 0,
... ... @@ -292,7 +293,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
292 293 ivaUnitario: producto.IMPIVA,
293 294 impuestoInternoUnitario: producto.ImpInt,
294 295 impuestoInterno1Unitario: producto.ImpInt2,
295   - impuestoInterno2Unitario: producto.ImpInt3,
  296 + impuestoInterno2Unitario: producto.ImpInt3,
296 297 precioLista: producto.precio,
297 298 combustible: 1,
298 299 facturado: 0,
... ... @@ -305,13 +306,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
305 306  
306 307 $scope.articuloACargar = newArt;
307 308 $scope.cargando = false;
308   - }, function() {
  309 + }, function () {
309 310 // funcion ejecutada cuando se cancela el modal
310 311 }
311 312 );
312 313 };
313 314  
314   - $scope.seleccionarPuntosDeDescarga = function() {
  315 + $scope.seleccionarPuntosDeDescarga = function () {
315 316 if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) {
316 317 focaModalService.alert('Primero seleccione un cliente y un domicilio');
317 318 return;
... ... @@ -334,29 +335,29 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
334 335 }
335 336 );
336 337 modalInstance.result.then(
337   - function(puntoDescarga) {
  338 + function (puntoDescarga) {
338 339  
339   - puntoDescarga.forEach(function(punto) {
  340 + puntoDescarga.forEach(function (punto) {
340 341 $scope.notaPedido.notaPedidoPuntoDescarga.push(
341 342 {
342 343 puntoDescarga: punto
343 344 }
344   - )
  345 + );
345 346 });
346 347  
347 348 $scope.$broadcast('addCabecera', {
348 349 label: 'Puntos de descarga:',
349 350 valor: getCabeceraPuntoDescarga(puntoDescarga)
350 351 });
351   - }, function() {
  352 + }, function () {
352 353 $scope.abrirModalDomicilios($scope.cliente);
353 354 }
354 355 );
355 356 }
356 357 };
357 358  
358   - $scope.seleccionarProveedor = function() {
359   - $scope.abrirModalProveedores(function() {
  359 + $scope.seleccionarProveedor = function () {
  360 + $scope.abrirModalProveedores(function () {
360 361 if (validarNotaRemitada()) {
361 362 var modalInstance = $uibModal.open(
362 363 {
... ... @@ -366,12 +367,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
366 367 size: 'lg',
367 368 resolve: {
368 369 parametrosFlete:
369   - function() {
  370 + function () {
370 371 return {
371 372 flete: $scope.notaPedido.fob ? 'FOB' :
372   - ( $scope.notaPedido.flete ? '1' :
373   - ($scope.notaPedido.flete === undefined ?
374   - null : '0')),
  373 + ($scope.notaPedido.flete ? '1' :
  374 + ($scope.notaPedido.flete === undefined ?
  375 + null : '0')),
375 376 bomba: $scope.notaPedido.bomba ? '1' :
376 377 ($scope.notaPedido.bomba === undefined ?
377 378 null : '0'),
... ... @@ -382,7 +383,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
382 383 }
383 384 );
384 385 modalInstance.result.then(
385   - function(datos) {
  386 + function (datos) {
386 387 $scope.notaPedido.flete = datos.flete;
387 388 $scope.notaPedido.fob = datos.FOB;
388 389 $scope.notaPedido.bomba = datos.bomba;
... ... @@ -408,8 +409,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
408 409 }
409 410  
410 411 $filter('filter')($scope.botonera,
411   - { label: 'Proveedor'})[0].checked = true;
412   - }, function() {
  412 + { label: 'Proveedor' })[0].checked = true;
  413 + }, function () {
413 414 $scope.seleccionarTransportista();
414 415 }
415 416 );
... ... @@ -417,7 +418,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
417 418 });
418 419 };
419 420  
420   - $scope.seleccionarVendedor = function(callback, ocultarVendedor) {
  421 + $scope.seleccionarVendedor = function (callback, ocultarVendedor) {
421 422 if (APP === 'distribuidor' || ocultarVendedor) {
422 423 callback();
423 424 return;
... ... @@ -444,7 +445,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
444 445 size: 'md'
445 446 };
446 447 focaModalService.modal(parametrosModal).then(
447   - function(vendedor) {
  448 + function (vendedor) {
448 449 $scope.$broadcast('addCabecera', {
449 450 label: 'Vendedor:',
450 451 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
... ... @@ -453,39 +454,36 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
453 454 $scope.notaPedido.vendedor = vendedor;
454 455 deleteCliente();
455 456 callback();
456   - }, function() {}
  457 + }, function () { }
457 458 );
458 459 }
459 460 };
460 461  
461   - $scope.seleccionarCliente = function(ocultarVendedor) {
462   - $scope.seleccionarVendedor(function() {
463   - if (validarNotaRemitada()) {
464   - var modalInstance = $uibModal.open(
465   - {
466   - ariaLabelledBy: 'Busqueda de Cliente',
467   - templateUrl: 'foca-busqueda-cliente-modal.html',
468   - controller: 'focaBusquedaClienteModalController',
469   - resolve: {
470   - vendedor: function() { return $scope.notaPedido.vendedor; },
471   - cobrador: function() { return null; }
472   - },
473   - size: 'lg'
474   - }
475   - );
476   - modalInstance.result.then(
477   - function(cliente) {
478   - $scope.abrirModalDomicilios(cliente);
479   - $scope.cliente = cliente;
480   - }, function() {
481   - if (APP !== 'distribuidor') $scope.seleccionarCliente();
482   - }
483   - );
484   - }
485   - }, ocultarVendedor);
  462 + $scope.seleccionarCliente = function () {
  463 + if (validarNotaRemitada()) {
  464 + var modalInstance = $uibModal.open(
  465 + {
  466 + ariaLabelledBy: 'Busqueda de Cliente',
  467 + templateUrl: 'foca-busqueda-cliente-modal.html',
  468 + controller: 'focaBusquedaClienteModalController',
  469 + resolve: {
  470 + vendedor: function () { return null; },
  471 + cobrador: function () { return null; }
  472 + },
  473 + size: 'lg'
  474 + }
  475 + );
  476 + modalInstance.result.then(
  477 + function (cliente) {
  478 + cliente.mod = cliente.mod;
  479 + $scope.abrirModalDomicilios(cliente);
  480 + $scope.cliente = cliente;
  481 + }, function () { }
  482 + );
  483 + }
486 484 };
487 485  
488   - $scope.abrirModalProveedores = function(callback) {
  486 + $scope.abrirModalProveedores = function (callback) {
489 487 if (validarNotaRemitada()) {
490 488 var parametrosModal = {
491 489 titulo: 'Búsqueda de Proveedor',
... ... @@ -509,10 +507,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
509 507 }
510 508 ],
511 509 tipo: 'POST',
512   - json: {razonCuitCod: ''}
  510 + json: { razonCuitCod: '' }
513 511 };
514 512 focaModalService.modal(parametrosModal).then(
515   - function(proveedor) {
  513 + function (proveedor) {
516 514 $scope.notaPedido.proveedor = proveedor;
517 515 $scope.$broadcast('addCabecera', {
518 516 label: 'Proveedor:',
... ... @@ -520,66 +518,81 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
520 518 proveedor.NOM
521 519 });
522 520 callback();
523   - }, function() {
  521 + }, function () {
524 522  
525 523 }
526 524 );
527 525 }
528 526 };
529 527  
530   - $scope.abrirModalDomicilios = function(cliente) {
  528 + $scope.abrirModalDomicilios = function (cliente) {
531 529 var modalInstanceDomicilio = $uibModal.open(
532 530 {
533 531 ariaLabelledBy: 'Busqueda de Domicilios',
534 532 templateUrl: 'modal-domicilio.html',
535 533 controller: 'focaModalDomicilioController',
536   - resolve: {
537   - idCliente: function() { return cliente.cod; },
538   - esNuevo: function() { return cliente.esNuevo; }
  534 + resolve: {
  535 + idCliente: function () { return cliente.cod; },
  536 + esNuevo: function () { return cliente.esNuevo; }
539 537 },
540 538 size: 'lg',
541 539 }
542 540 );
543 541 modalInstanceDomicilio.result.then(
544   - function(domicilio) {
  542 + function (domicilio) {
545 543 $scope.notaPedido.domicilio = domicilio;
546 544 $scope.notaPedido.cliente = {
547 545 COD: cliente.cod,
548 546 CUIT: cliente.cuit,
549 547 NOM: cliente.nom,
550   - MOD: cliente.mod
  548 + MOD: cliente.mod,
  549 + VEN: cliente.ven
551 550 };
552   - var domicilioStamp =
553   - domicilio.Calle + ' ' + domicilio.Numero + ', ' +
554   - domicilio.Localidad + ', ' + domicilio.Provincia;
555   - $scope.notaPedido.domicilioStamp = domicilioStamp;
556   -
557   - $scope.$broadcast('addCabecera', {
558   - label: 'Cliente:',
559   - valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom
560   - });
  551 + crearNotaPedidoService.getVendedorById($scope.notaPedido.cliente.VEN)
  552 + .then(function (res) {
  553 + if (res.data !== '') {
  554 + $scope.notaPedido.vendedor = res.data;
  555 + $scope.$broadcast('addCabecera', {
  556 + label: 'Vendedor:',
  557 + valor: $filter('rellenarDigitos')
  558 + ($scope.notaPedido.vendedor.NUM, 3) +
  559 + ' - ' + $scope.notaPedido.vendedor.NOM
  560 + });
  561 + }
  562 + var domicilioStamp =
  563 + domicilio.Calle + ' ' + domicilio.Numero + ', ' +
  564 + domicilio.Localidad + ', ' + domicilio.Provincia;
  565 + $scope.notaPedido.domicilioStamp = domicilioStamp;
561 566  
562   - $scope.$broadcast('addCabecera', {
563   - label: 'Domicilio:',
564   - valor: domicilioStamp
565   - });
  567 + $scope.$broadcast('addCabecera', {
  568 + label: 'Cliente:',
  569 + valor: $filter('rellenarDigitos')(cliente.cod, 5) +
  570 + ' - ' + cliente.nom
  571 + });
566 572  
567   - if (domicilio.verPuntos) {
568   - delete $scope.notaPedido.domicilio.verPuntos;
569   - $scope.seleccionarPuntosDeDescarga();
570   - }
  573 + $scope.$broadcast('addCabecera', {
  574 + label: 'Domicilio:',
  575 + valor: domicilioStamp
  576 + });
571 577  
572   - // Seteo checked en botonera
573   - $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true;
  578 + if (domicilio.verPuntos) {
  579 + delete $scope.notaPedido.domicilio.verPuntos;
  580 + $scope.seleccionarPuntosDeDescarga();
  581 + }
574 582  
575   - }, function() {
  583 + // Seteo checked en botonera
  584 + $filter('filter')($scope.botonera,
  585 + { label: 'Cliente' })[0].checked = true;
  586 + })
  587 + .catch(function (e) { console.log(e); });
  588 + }, function () {
576 589 $scope.seleccionarCliente(true);
577 590 return;
578 591 }
579 592 );
580 593 };
581 594  
582   - $scope.getTotal = function() {
  595 + $scope.getTotal = function () {
583 596 var total = 0;
584 597 if ($scope.notaPedido.articulosNotaPedido) {
585 598 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido;
... ... @@ -590,24 +603,29 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
590 603 return parseFloat(total.toFixed(2));
591 604 };
592 605  
593   - $scope.getSubTotal = function() {
  606 + $scope.getSubTotal = function () {
594 607 if ($scope.articuloACargar) {
595 608 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
596 609 }
597 610 };
598 611  
599   - $scope.seleccionarPreciosYCondiciones = function() {
  612 + $scope.seleccionarPreciosYCondiciones = function () {
  613 +
  614 + if (!validarNotaRemitada()) {
  615 + return;
  616 + }
  617 +
600 618 if (!$scope.notaPedido.cliente.COD) {
601 619 focaModalService.alert('Primero seleccione un cliente');
602 620 return;
603 621 }
604 622 if ($scope.notaPedido.articulosNotaPedido.length !== 0) {
605   - focaModalService.confirm('Se perderan los productos ingresados')
606   - .then(function(data) {
607   - if (data) {
608   - abrirModal();
609   - }
610   - });
  623 + focaModalService.confirm('Se perderan los productos ingresados')
  624 + .then(function (data) {
  625 + if (data) {
  626 + abrirModal();
  627 + }
  628 + });
611 629 } else if (validarNotaRemitada()) {
612 630 abrirModal();
613 631 }
... ... @@ -619,31 +637,31 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
619 637 controller: 'focaModalPrecioCondicionController',
620 638 size: 'lg',
621 639 resolve: {
622   - idListaPrecio: function() {
623   - return $scope.notaPedido.cliente.MOD || null;
624   - }
  640 + idListaPrecio: function () { return $scope.notaPedido.cliente.MOD || null; },
  641 + idCliente: function () { return $scope.notaPedido.cliente.COD }
625 642 }
626 643 }
627 644 );
628 645  
629   - modalInstance.result.then(
630   - function(precioCondicion) {
  646 + modalInstance.result
  647 + .then(function (precioCondicion) {
631 648 var cabecera = '';
632 649 var plazosConcat = '';
633 650 if (!Array.isArray(precioCondicion)) {
634 651 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
635 652 $scope.notaPedido.precioCondicion = precioCondicion;
636   - $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
637   - $scope.idLista = precioCondicion.idListaPrecio;
  653 + $scope.notaPedido.idPrecioCondicion = precioCondicion.listaPrecio.ID;
  654 + $scope.idLista = precioCondicion.listaPrecio.ID;
638 655 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
639   - plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
  656 + plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
640 657 }
641   - cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
642   - ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
  658 + plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
  659 + cabecera = $filter('rellenarDigitos')(parseInt(precioCondicion.listaPrecio.ID), 4) +
  660 + ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim();
643 661 } else { //Cuando se ingresan los plazos manualmente
644 662 $scope.notaPedido.idPrecioCondicion = 0;
645 663 //-1, el modal productos busca todos los productos
646   - $scope.idLista = -1;
  664 + $scope.idLista = -1;
647 665 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
648 666 for (var j = 0; j < precioCondicion.length; j++) {
649 667 plazosConcat += precioCondicion[j].dias + ' ';
... ... @@ -657,15 +675,16 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
657 675 });
658 676  
659 677 $filter('filter')($scope.botonera,
660   - { label: 'Precios y Condiciones'})[0].checked = true;
661   - }, function() {
  678 + { label: 'Precios y Condiciones' })[0].checked = true;
  679 + })
  680 + .catch(function (e) {
  681 + console.log(e);
  682 + })
662 683  
663   - }
664   - );
665 684 }
666 685 };
667 686  
668   - $scope.seleccionarMoneda = function() {
  687 + $scope.seleccionarMoneda = function () {
669 688 if (validarNotaRemitada()) {
670 689 var parametrosModal = {
671 690 titulo: 'Búsqueda de monedas',
... ... @@ -683,7 +702,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
683 702 size: 'md'
684 703 };
685 704 focaModalService.modal(parametrosModal).then(
686   - function(moneda) {
  705 + function (moneda) {
687 706  
688 707 if (moneda.ID !== 1) {
689 708 $scope.abrirModalCotizacion(moneda);
... ... @@ -704,7 +723,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
704 723 }
705 724 };
706 725  
707   - $scope.seleccionarObservaciones = function() {
  726 + $scope.seleccionarObservaciones = function () {
708 727 var observacion = {
709 728 titulo: 'Ingrese Observaciones',
710 729 value: $scope.notaPedido.observaciones,
... ... @@ -714,12 +733,12 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
714 733  
715 734 focaModalService
716 735 .prompt(observacion)
717   - .then(function(observaciones) {
  736 + .then(function (observaciones) {
718 737 $scope.notaPedido.observaciones = observaciones;
719 738 });
720 739 };
721 740  
722   - $scope.abrirModalCotizacion = function(moneda) {
  741 + $scope.abrirModalCotizacion = function (moneda) {
723 742 var modalInstance = $uibModal.open(
724 743 {
725 744 ariaLabelledBy: 'Busqueda de Cotización',
... ... @@ -727,29 +746,29 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
727 746 controller: 'focaModalCotizacionController',
728 747 size: 'lg',
729 748 resolve: {
730   - idMoneda: function() {
  749 + idMoneda: function () {
731 750 return moneda.ID;
732 751 }
733 752 }
734 753 }
735 754 );
736 755 modalInstance.result.then(
737   - function(cotizacion) {
  756 + function (cotizacion) {
738 757  
739 758 cotizacion.moneda = moneda;
740 759 actualizarCabeceraMoneda(cotizacion);
741 760  
742 761 $scope.notaPedido.cotizacion = cotizacion;
743   - $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true;
744   - }, function() {
  762 + $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
  763 + }, function () {
745 764  
746 765 }
747 766 );
748 767 };
749 768  
750   - function actualizarCabeceraMoneda (cotizacion) {
  769 + function actualizarCabeceraMoneda(cotizacion) {
751 770  
752   - $scope.notaPedido.articulosNotaPedido.forEach(function(art) {
  771 + $scope.notaPedido.articulosNotaPedido.forEach(function (art) {
753 772 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4);
754 773 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
755 774 });
... ... @@ -774,13 +793,11 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
774 793 }
775 794 }
776 795  
777   - $scope.agregarATabla = function(key) {
  796 + $scope.agregarATabla = function (key) {
778 797 if (key === 13) {
779   - if ($scope.articuloACargar.cantidad === undefined ||
780   - $scope.articuloACargar.cantidad === 0 ||
781   - $scope.articuloACargar.cantidad === null ) {
782   - focaModalService.alert('El valor debe ser al menos 1');
783   - return;
  798 + if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
  799 + focaModalService.alert('El valor debe ser al menos 1');
  800 + return;
784 801 }
785 802 delete $scope.articuloACargar.sectorCodigo;
786 803 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar);
... ... @@ -788,13 +805,15 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
788 805 }
789 806 };
790 807  
791   - $scope.quitarArticulo = function(key) {
792   - $scope.notaPedido.articulosNotaPedido.splice(key, 1);
  808 + $scope.quitarArticulo = function (key) {
  809 + if (validarNotaRemitada()) {
  810 + $scope.notaPedido.articulosNotaPedido.splice(key, 1);
  811 + }
793 812 };
794 813  
795   - $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) {
  814 + $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
796 815 if (key === 13) {
797   - if (!articulo.cantidad || !articulo.precio) {
  816 + if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
798 817 focaModalService.alert('Los valores deben ser al menos 1');
799 818 return;
800 819 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
... ... @@ -808,13 +827,13 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
808 827 }
809 828 };
810 829  
811   - $scope.cancelarEditar = function(articulo) {
  830 + $scope.cancelarEditar = function (articulo) {
812 831 $scope.tmpCantidad = articulo.cantidad;
813 832 $scope.tmpPrecio = articulo.precio;
814 833 articulo.editCantidad = articulo.editPrecio = false;
815 834 };
816 835  
817   - $scope.cambioEdit = function(articulo, propiedad) {
  836 + $scope.cambioEdit = function (articulo, propiedad) {
818 837 if (propiedad === 'cantidad') {
819 838 articulo.editCantidad = true;
820 839 } else if (propiedad === 'precio') {
... ... @@ -822,12 +841,12 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
822 841 }
823 842 };
824 843  
825   - $scope.resetFilter = function() {
  844 + $scope.resetFilter = function () {
826 845 $scope.articuloACargar = {};
827 846 $scope.cargando = true;
828 847 };
829 848 //Recibe aviso si el teclado está en uso
830   - $rootScope.$on('usarTeclado', function(event, data) {
  849 + $rootScope.$on('usarTeclado', function (event, data) {
831 850 if (data) {
832 851 $scope.mostrarTeclado = true;
833 852 return;
... ... @@ -835,7 +854,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
835 854 $scope.mostrarTeclado = false;
836 855 });
837 856  
838   - $scope.selectFocus = function($event) {
  857 + $scope.selectFocus = function ($event) {
839 858 // Si el teclado esta en uso no selecciona el valor
840 859 if ($scope.mostrarTeclado) {
841 860 return;
... ... @@ -843,23 +862,23 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
843 862 $event.target.select();
844 863 };
845 864  
846   - $scope.salir = function() {
  865 + $scope.salir = function () {
847 866 $location.path('/');
848 867 };
849 868  
850   - $scope.parsearATexto = function(articulo) {
  869 + $scope.parsearATexto = function (articulo) {
851 870 articulo.cantidad = parseFloat(articulo.cantidad);
852 871 articulo.precio = parseFloat(articulo.precio);
853 872 };
854 873  
855 874 // TODO: quitar watch usar función de articulos pedido cuando se haga
856   - $scope.$watch('notaPedido.articulosNotaPedido', function() {
  875 + $scope.$watch('notaPedido.articulosNotaPedido', function () {
857 876 if ($scope.notaPedido.articulosNotaPedido.length) {
858 877 $filter('filter')($scope.botonera,
859   - { label: 'Productos'})[0].checked = true;
  878 + { label: 'Productos' })[0].checked = true;
860 879 } else {
861 880 $filter('filter')($scope.botonera,
862   - { label: 'Productos'})[0].checked = false;
  881 + { label: 'Productos' })[0].checked = false;
863 882 }
864 883 }, true);
865 884  
... ... @@ -895,7 +914,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
895 914 }
896 915  
897 916 if (notaPedido.cotizacion.moneda) {
898   - $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true;
  917 + $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
899 918 }
900 919  
901 920 if (notaPedido.vendedor.NUM) {
... ... @@ -916,7 +935,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
916 935 valor: notaPedido.domicilioStamp
917 936 });
918 937  
919   - $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true;
  938 + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
920 939 }
921 940  
922 941 if (notaPedido.proveedor.COD) {
... ... @@ -926,7 +945,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
926 945 ' - ' + notaPedido.proveedor.NOM
927 946 });
928 947  
929   - $filter('filter')($scope.botonera, { label: 'Proveedor'})[0].checked = true;
  948 + $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
930 949 }
931 950  
932 951 if (notaPedido.notaPedidoPlazo.length) {
... ... @@ -938,7 +957,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
938 957 });
939 958  
940 959 $filter('filter')($scope.botonera,
941   - { label: 'Precios y condiciones'})[0].checked = true;
  960 + { label: 'Precios y condiciones' })[0].checked = true;
942 961 }
943 962  
944 963 if (notaPedido.flete !== undefined) {
... ... @@ -988,7 +1007,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
988 1007  
989 1008 if (notaPedido.notaPedidoPuntoDescarga.length) {
990 1009 var puntos = [];
991   - notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) {
  1010 + notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) {
992 1011 puntos.push(notaPedidoPuntoDescarga.puntoDescarga);
993 1012 });
994 1013 cabeceras.push({
... ... @@ -1009,7 +1028,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
1009 1028  
1010 1029 function getCabeceraPuntoDescarga(puntoDescarga) {
1011 1030 var puntosStamp = '';
1012   - puntoDescarga.forEach(function(punto, idx, arr) {
  1031 + puntoDescarga.forEach(function (punto, idx, arr) {
1013 1032 puntosStamp += punto.descripcion;
1014 1033 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1015 1034 });
... ... @@ -1044,7 +1063,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
1044 1063 if (confirmacion) {
1045 1064 focaModalService.confirm(
1046 1065 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1047   - ).then(function(data) {
  1066 + ).then(function (data) {
1048 1067 if (data) {
1049 1068 $location.path('/');
1050 1069 }
... ... @@ -1065,12 +1084,12 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
1065 1084 function deleteCliente() {
1066 1085 $scope.notaPedido.domicilioStamp = '';
1067 1086 $scope.notaPedido.notaPedidoPuntoDescarga = [];
1068   - $scope.notaPedido.domicilio = {dom: ''};
  1087 + $scope.notaPedido.domicilio = { dom: '' };
1069 1088 $scope.notaPedido.cliente = {};
1070 1089 $scope.$broadcast('removeCabecera', 'Cliente:');
1071 1090 $scope.$broadcast('removeCabecera', 'Domicilio:');
1072 1091 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1073   - $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = false;
  1092 + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
1074 1093 }
1075 1094 }
1076 1095 ]);
... ... @@ -99,7 +99,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
99 99 return $http.get(API_ENDPOINT.URL + '/proveedor/' + id);
100 100 },
101 101 getParametros: function() {
102   - return $http.get(API_ENDPOINT.URL + '/parametros/' + 'notaPedido')
  102 + return $http.get(API_ENDPOINT.URL + '/parametros/' + 'notaPedido');
103 103 }
104 104 };
105 105 }]);