Commit 77ac48e5dd6f5002a69d0d5e6433c3fa1f057ecc

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

Merge branch 'develop' into 'master'

Develop

See merge request !89
... ... @@ -4,6 +4,7 @@
4 4 "description": "Listado y ABM nota de remitos",
5 5 "main": "index.js",
6 6 "scripts": {
  7 + "refresh": "gulp uglify && cp tmp/foca-crear-remito.js ../wrapper-demo/node_modules/foca-crear-remito/dist/foca-crear-remito.min.js",
7 8 "test": "test.html",
8 9 "compile": "gulp uglify",
9 10 "gulp-pre-commit": "gulp pre-commit",
src/js/controller.js
... ... @@ -26,7 +26,6 @@ angular.module('focaCrearRemito').controller('remitoController',
26 26 minDate: new Date(2010, 0, 1)
27 27 };
28 28  
29   -
30 29 crearRemitoService.getParametros().then(function (res) {
31 30 var parametros = JSON.parse(res.data[0].jsonText);
32 31 if ($localStorage.remito) {
... ... @@ -37,6 +36,7 @@ angular.module('focaCrearRemito').controller('remitoController',
37 36 $scope.inicial[property] = parametros[property];
38 37 }
39 38 setearRemito($scope.remito);
  39 + $scope.remitoIsDirty = true;
40 40 }
41 41 });
42 42  
... ... @@ -54,7 +54,6 @@ angular.module('focaCrearRemito').controller('remitoController',
54 54  
55 55 function init() {
56 56 $scope.$broadcast('cleanCabecera');
57   - $scope.remitoIsDirty = false;
58 57 $scope.remito = {
59 58 id: 0,
60 59 estado: 0,
... ... @@ -97,6 +96,17 @@ angular.module('focaCrearRemito').controller('remitoController',
97 96 }, true);
98 97  
99 98 $scope.seleccionarNotaPedido = function () {
  99 + if ($scope.remitoIsDirty) {
  100 + focaModalService.confirm('¿Desea continuar? Se perderan los cambios')
  101 + .then(function () {
  102 + $scope.getNotaPedidoModal();
  103 + });
  104 + } else {
  105 + $scope.getNotaPedidoModal();
  106 + }
  107 + };
  108 +
  109 + $scope.getNotaPedidoModal = function () {
100 110 if (varlidarRemitoFacturado()) {
101 111 var modalInstance = $uibModal.open(
102 112 {
... ... @@ -312,7 +322,7 @@ angular.module('focaCrearRemito').controller('remitoController',
312 322 idProveedor: $scope.remito.proveedor.COD,
313 323 idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id,
314 324 idCotizacion: $scope.remito.cotizacion.ID,
315   - idPrecioCondicion: $scope.remito.idPrecioCondicion,
  325 + idListaPrecio: $scope.remito.idListaPrecio,
316 326 flete: $scope.remito.flete,
317 327 fob: $scope.remito.fob,
318 328 bomba: $scope.remito.bomba,
... ... @@ -358,7 +368,7 @@ angular.module('focaCrearRemito').controller('remitoController',
358 368 $scope.remito.id = data.data.id;
359 369 $scope.remito.numeroRemito = data.data.numero;
360 370  
361   - if ($scope.remito.remitoPuntoDescarga.length) {
  371 + if ($scope.remito.remitoPuntoDescarga.length > 0) {
362 372 remitoBusinessService.addPuntosDescarga(data.data.id,
363 373 $scope.remito.remitoPuntoDescarga);
364 374 }
... ... @@ -402,7 +412,6 @@ angular.module('focaCrearRemito').controller('remitoController',
402 412 }
403 413 );
404 414 };
405   -
406 415 $scope.seleccionarProductos = function () {
407 416 if ($scope.idLista === undefined) {
408 417 focaModalService.alert(
... ... @@ -462,7 +471,6 @@ angular.module('focaCrearRemito').controller('remitoController',
462 471 }
463 472 );
464 473 };
465   -
466 474 $scope.seleccionarPuntosDeDescarga = function () {
467 475 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) {
468 476 focaModalService.alert('Primero seleccione un cliente y un domicilio');
... ... @@ -486,9 +494,9 @@ angular.module('focaCrearRemito').controller('remitoController',
486 494 }
487 495 );
488 496 modalInstance.result.then(
489   - function(puntosDescarga) {
  497 + function (puntosDescarga) {
490 498  
491   - puntosDescarga.forEach(function(punto) {
  499 + puntosDescarga.forEach(function (punto) {
492 500 $scope.remito.remitoPuntoDescarga.push(
493 501 {
494 502 puntoDescarga: punto
... ... @@ -506,80 +514,30 @@ angular.module('focaCrearRemito').controller('remitoController',
506 514 );
507 515 }
508 516 };
509   -
510   - $scope.seleccionarVendedor = function (callback, ocultarVendedor) {
511   - if (ocultarVendedor) {
512   - callback();
513   - return;
514   - }
515   -
  517 + $scope.seleccionarCliente = function () {
516 518 if (varlidarRemitoFacturado()) {
517   - var parametrosModal = {
518   - titulo: 'Búsqueda vendedores',
519   - query: '/vendedor',
520   - columnas: [
521   - {
522   - propiedad: 'NUM',
523   - nombre: 'Código',
524   - filtro: {
525   - nombre: 'rellenarDigitos',
526   - parametro: 3
527   - }
  519 + var modalInstance = $uibModal.open(
  520 + {
  521 + ariaLabelledBy: 'Busqueda de Cliente',
  522 + templateUrl: 'foca-busqueda-cliente-modal.html',
  523 + controller: 'focaBusquedaClienteModalController',
  524 + resolve: {
  525 + vendedor: function () { return null; },
  526 + cobrador: function () { return null; }
528 527 },
529   - {
530   - propiedad: 'NOM',
531   - nombre: 'Nombre'
532   - }
533   - ],
534   - size: 'md'
535   - };
536   - focaModalService.modal(parametrosModal).then(
537   - function (vendedor) {
538   - $scope.remitoIsDirty = true;
539   - $scope.$broadcast('addCabecera', {
540   - label: 'Vendedor:',
541   - valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
542   - vendedor.NOM
543   - });
544   - $scope.remito.idVendedor = vendedor.id;
545   - $scope.remito.vendedor = vendedor;
546   - deleteCliente();
547   - callback();
  528 + size: 'lg'
  529 + }
  530 + );
  531 + modalInstance.result.then(
  532 + function (cliente) {
  533 + $scope.abrirModalDomicilios(cliente);
  534 + $scope.cliente = cliente;
548 535 }, function () {
549   -
550 536 }
551 537 );
552 538 }
553 539 };
554 540  
555   - $scope.seleccionarCliente = function (ocultarVendedor) {
556   -
557   - $scope.seleccionarVendedor(function () {
558   - if (varlidarRemitoFacturado()) {
559   - var modalInstance = $uibModal.open(
560   - {
561   - ariaLabelledBy: 'Busqueda de Cliente',
562   - templateUrl: 'foca-busqueda-cliente-modal.html',
563   - controller: 'focaBusquedaClienteModalController',
564   - resolve: {
565   - vendedor: function () { return $scope.remito.vendedor; },
566   - cobrador: function () { return null; }
567   - },
568   - size: 'lg'
569   - }
570   - );
571   - modalInstance.result.then(
572   - function (cliente) {
573   - $scope.abrirModalDomicilios(cliente);
574   - $scope.cliente = cliente;
575   - }, function () {
576   - $scope.seleccionarCliente();
577   - }
578   - );
579   - }
580   - }, ocultarVendedor);
581   - };
582   -
583 541 $scope.seleccionarProveedor = function () {
584 542 if (varlidarRemitoFacturado()) {
585 543 var parametrosModal = {
... ... @@ -630,35 +588,56 @@ angular.module('focaCrearRemito').controller('remitoController',
630 588 modalInstanceDomicilio.result.then(
631 589 function (domicilio) {
632 590 $scope.remito.domicilio = domicilio;
633   - console.log(cliente);
634 591 $scope.remito.cliente = {
635 592 COD: cliente.cod,
636 593 CUIT: cliente.cuit,
637 594 NOM: cliente.nom,
638 595 MAIL: cliente.mail,
639 596 MOD: cliente.mod,
640   - IVA: cliente.iva
  597 + IVA: cliente.iva,
  598 + VEN: cliente.ven
641 599 };
  600 + crearRemitoService.getVendedorById($scope.remito.cliente.VEN)
  601 + .then(function (res) {
  602 + if (res.data !== '') {
  603 + $scope.remito.vendedor = res.data;
  604 + $scope.$broadcast('addCabecera', {
  605 + label: 'Vendedor:',
  606 + valor: $filter('rellenarDigitos')($scope.remito.vendedor
  607 + .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM
  608 + });
  609 + }
  610 + var domicilioStamp =
  611 + domicilio.Calle + ' ' + domicilio.Numero + ', ' +
  612 + domicilio.Localidad + ', ' + domicilio.Provincia;
  613 + $scope.remito.domicilioStamp = domicilioStamp;
  614 + $scope.$broadcast('addCabecera', {
  615 + label: 'Cliente:',
  616 + valor: $filter('rellenarDigitos')(cliente.cod, 3) +
  617 + ' - ' + cliente.nom
  618 + });
  619 + $scope.$broadcast('addCabecera', {
  620 + label: 'Domicilio:',
  621 + valor: domicilioStamp
  622 + });
642 623  
643   - var domicilioStamp =
644   - domicilio.Calle + ' ' + domicilio.Numero + ', ' +
645   - domicilio.Localidad + ', ' + domicilio.Provincia;
646   - $scope.remito.domicilioStamp = domicilioStamp;
647   - $scope.$broadcast('addCabecera', {
648   - label: 'Cliente:',
649   - valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
650   - });
651   - $scope.$broadcast('addCabecera', {
652   - label: 'Domicilio:',
653   - valor: domicilioStamp
654   - });
655   -
656   - if (domicilio.verPuntos) {
657   - delete $scope.remito.domicilio.verPuntos;
658   - $scope.seleccionarPuntosDeDescarga();
659   - }
  624 + if (domicilio.verPuntos) {
  625 + delete $scope.remito.domicilio.verPuntos;
  626 + $scope.seleccionarPuntosDeDescarga();
  627 + } else {
  628 + crearRemitoService
  629 + .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
  630 + .then(function (res) {
  631 + if (res.data.length) {
  632 + $scope.seleccionarPuntosDeDescarga();
  633 + }
  634 + });
  635 + }
660 636  
661   - $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
  637 + $filter('filter')($scope.botonera,
  638 + { label: 'Cliente' })[0].checked = true;
  639 + })
  640 + .catch(function (e) { console.log(e); });
662 641 }, function () {
663 642 $scope.seleccionarCliente(true);
664 643 return;
... ... @@ -706,9 +685,8 @@ angular.module('focaCrearRemito').controller('remitoController',
706 685 controller: 'focaModalPrecioCondicionController',
707 686 size: 'lg',
708 687 resolve: {
709   - idListaPrecio: function () {
710   - return $scope.remito.cliente.MOD || null;
711   - }
  688 + idListaPrecio: function () { return $scope.remito.cliente.MOD || null; },
  689 + idCliente: function () { return $scope.remito.cliente.COD; }
712 690 }
713 691 }
714 692 );
... ... @@ -717,14 +695,15 @@ angular.module('focaCrearRemito').controller('remitoController',
717 695 var cabecera = '';
718 696 var plazosConcat = '';
719 697 if (!Array.isArray(precioCondicion)) {
720   - $scope.remito.idPrecioCondicion = precioCondicion.id;
  698 + $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID;
721 699 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
722   - $scope.idLista = precioCondicion.idListaPrecio;
  700 + $scope.idLista = precioCondicion.listaPrecio.ID;
723 701 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
724   - plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
  702 + plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
725 703 }
726   - cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
727   - ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
  704 + plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
  705 + cabecera = $filter('rellenarDigitos')(parseInt(precioCondicion.listaPrecio.ID), 4) +
  706 + ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim();
728 707 } else { //Cuando se ingresan los plazos manualmente
729 708 $scope.remito.idPrecioCondicion = 0;
730 709 //-1, el modal productos busca todos los productos
... ... @@ -927,9 +906,7 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
927 906  
928 907 $scope.agregarATabla = function (key) {
929 908 if (key === 13) {
930   - if ($scope.articuloACargar.cantidad === undefined ||
931   - $scope.articuloACargar.cantidad === 0 ||
932   - $scope.articuloACargar.cantidad === null) {
  909 + if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
933 910 focaModalService.alert('El valor debe ser al menos 1');
934 911 return;
935 912 }
... ... @@ -960,7 +937,7 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
960 937  
961 938 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
962 939 if (key === 13) {
963   - if (!articulo.cantidad || !articulo.precio) {
  940 + if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
964 941 focaModalService.alert('Los valores deben ser al menos 1');
965 942 return;
966 943 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
... ... @@ -1067,10 +1044,11 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1067 1044 $scope.$broadcast('removeCabecera', 'Moneda:');
1068 1045 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
1069 1046 $scope.$broadcast('removeCabecera', 'Cotizacion:');
  1047 + $scope.$broadcast('removeCabecera', 'Vendedor:');
1070 1048  
1071 1049 var cabeceras = [];
1072 1050  
1073   - if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
  1051 + if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
1074 1052 cabeceras.push({
1075 1053 label: 'Moneda:',
1076 1054 valor: remito.cotizacion.moneda.DETALLE
... ... @@ -1087,11 +1065,11 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1087 1065 });
1088 1066 }
1089 1067  
1090   - if (remito.cotizacion.moneda) {
  1068 + if (remito.cotizacion && remito.cotizacion.moneda) {
1091 1069 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
1092 1070 }
1093 1071  
1094   - if (remito.cliente.COD) {
  1072 + if (remito.cliente && remito.cliente.COD) {
1095 1073 cabeceras.push({
1096 1074 label: 'Cliente:',
1097 1075 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
... ... @@ -1104,14 +1082,14 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1104 1082  
1105 1083 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
1106 1084 }
1107   - if (remito.vendedor.NUM) {
  1085 + if (remito.vendedor && remito.vendedor.NUM) {
1108 1086 cabeceras.push({
1109 1087 label: 'Vendedor:',
1110 1088 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
1111 1089 ' - ' + remito.vendedor.NOM
1112 1090 });
1113 1091 }
1114   - if (remito.proveedor.COD) {
  1092 + if (remito.proveedor && remito.proveedor.COD) {
1115 1093 cabeceras.push({
1116 1094 label: 'Proveedor:',
1117 1095 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
... ... @@ -1170,7 +1148,7 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1170 1148 if ($scope.remito.remitoPuntoDescarga.length) {
1171 1149 var puntoDescarga = [];
1172 1150  
1173   - $scope.remito.remitoPuntoDescarga.forEach(function(remitoPuntoDescarga) {
  1151 + $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) {
1174 1152 puntoDescarga.push(remitoPuntoDescarga.puntoDescarga);
1175 1153 });
1176 1154  
... ... @@ -1181,7 +1159,7 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1181 1159 }
1182 1160 $scope.remitoIsDirty = false;
1183 1161  
1184   - if ($scope.remito.articulosRemito.length) {
  1162 + if (remito.articulosRemito && $scope.remito.articulosRemito.length) {
1185 1163 $scope.remito.articulosRemito.forEach(function (articulo) {
1186 1164 articulo.precio =
1187 1165 (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4);
... ... @@ -1199,16 +1177,17 @@ angular.module(&#39;focaCrearRemito&#39;).controller(&#39;remitoController&#39;,
1199 1177 }
1200 1178 }
1201 1179  
1202   - function deleteCliente() {
1203   - $scope.remito.domicilioStamp = '';
1204   - $scope.remito.remitoPuntoDescarga = [];
1205   - $scope.remito.domicilio = { dom: '' };
1206   - $scope.remito.cliente = {};
1207   - $scope.$broadcast('removeCabecera', 'Cliente:');
1208   - $scope.$broadcast('removeCabecera', 'Domicilio:');
1209   - $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1210   - $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
1211   - }
  1180 + // TODO: Descomentar cuando se use
  1181 + // function deleteCliente() {
  1182 + // $scope.remito.domicilioStamp = '';
  1183 + // $scope.remito.remitoPuntoDescarga = [];
  1184 + // $scope.remito.domicilio = { dom: '' };
  1185 + // $scope.remito.cliente = {};
  1186 + // $scope.$broadcast('removeCabecera', 'Cliente:');
  1187 + // $scope.$broadcast('removeCabecera', 'Domicilio:');
  1188 + // $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
  1189 + // $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
  1190 + // }
1212 1191  
1213 1192 function getCabeceraPuntoDescarga(puntosDescarga) {
1214 1193 var puntosStamp = '';
... ... @@ -3,6 +3,9 @@ angular.module(&#39;focaCrearRemito&#39;)
3 3 function($http, API_ENDPOINT) {
4 4 var route = API_ENDPOINT.URL;
5 5 return {
  6 + getVendedorById: function (idVendedor) {
  7 + return $http.get(route + '/vendedor-cobrador/' + idVendedor);
  8 + },
6 9 crearRemito: function(remito) {
7 10 // TODO: Cambiar para usar el servicio /remito
8 11 return $http.post(route + '/remito', remito);