Commit 8862ecdfd96fc9373f96b7419b989603e18d5e04

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

Merge branch 'develop' into 'master'

Develop

See merge request !77
src/js/controller.js
... ... @@ -23,6 +23,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
23 23  
24 24 function config() {
25 25 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
  26 + $scope.tmpCantidad = Number;
  27 + $scope.tmpPrecio = Number;
26 28 $scope.notaPedido = {};
27 29 $scope.isNumber = angular.isNumber;
28 30 $scope.datepickerAbierto = false;
... ... @@ -48,20 +50,30 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
48 50 if (APP === 'distribuidor') {
49 51 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador;
50 52 }
51   -
52 53 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
53   - crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
54   - var monedaPorDefecto = res.data[0];
  54 + //Trabajo con el proveedor YPF, por eso uso siempre la primera
  55 +
  56 + var promiseMoneda = crearNotaPedidoService.getCotizacionByIdMoneda(1);
  57 + var promiseProveedor = crearNotaPedidoService.getProveedorById(1);
  58 +
  59 + Promise.all([promiseMoneda, promiseProveedor]).then(function(res) {
  60 + var monedaPorDefecto = res[0].data[0];
55 61 $scope.notaPedido.cotizacion = Object.assign(
56 62 {moneda: monedaPorDefecto},
57 63 monedaPorDefecto.cotizaciones[0]
58 64 );
59 65 $scope.inicial.cotizacion = $scope.notaPedido.cotizacion;
  66 + var proveedorPorDefecto = res[1].data[0];
  67 + $scope.notaPedido.proveedor = Object.assign(
  68 + {proveedor: proveedorPorDefecto}
  69 + );
  70 + $scope.inicial.proveedor = $scope.notaPedido.proveedor;
  71 +
60 72 $timeout(function() {getLSNotaPedido();});
61 73 });
62 74  
63 75 init();
64   -
  76 +
65 77 }
66 78  
67 79 function init() {
... ... @@ -76,7 +88,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
76 88 fechaCarga: new Date(),
77 89 cotizacion: {},
78 90 articulosNotaPedido: [],
79   - notaPedidoPlazo: []
  91 + notaPedidoPlazo: [],
  92 + notaPedidoPuntoDescarga: {
  93 + puntoDescarga: {}
  94 + }
80 95 };
81 96 $scope.idLista = undefined;
82 97  
... ... @@ -125,6 +140,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
125 140 if (!$scope.notaPedido.cliente.COD) {
126 141 focaModalService.alert('Ingrese Cliente');
127 142 return;
  143 + } else if ($scope.notaPedido.idRemito === -1) {
  144 + focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido');
  145 + return;
128 146 } else if (!$scope.notaPedido.proveedor.COD) {
129 147 focaModalService.alert('Ingrese Proveedor');
130 148 return;
... ... @@ -149,6 +167,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
149 167 focaModalService.alert('Debe cargar al menos un articulo');
150 168 return;
151 169 }
  170 +
152 171 focaBotoneraLateralService.startGuardar();
153 172 $scope.saveLoading = true;
154 173 var notaPedido = {
... ... @@ -217,8 +236,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
217 236 focaBotoneraLateralService.endGuardar();
218 237 $scope.saveLoading = false;
219 238 console.info(error);
220   - }
221   - );
  239 + });
222 240 };
223 241  
224 242 $scope.seleccionarNotaPedido = function() {
... ... @@ -313,19 +331,19 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
313 331 idDomicilio: $scope.notaPedido.domicilio.id,
314 332 idCliente: $scope.notaPedido.cliente.COD,
315 333 articulos: $scope.notaPedido.articulosNotaPedido,
316   - puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga,
  334 + puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga,
317 335 domicilio: $scope.notaPedido.domicilio
318 336 }
319 337 }
320 338 }
321 339 );
322 340 modalInstance.result.then(
323   - function(puntosDescarga) {
324   - $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga;
  341 + function(puntoDescarga) {
  342 + $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga;
325 343  
326 344 $scope.$broadcast('addCabecera', {
327 345 label: 'Puntos de descarga:',
328   - valor: getCabeceraPuntoDescarga(puntosDescarga)
  346 + valor: getCabeceraPuntoDescarga(puntoDescarga)
329 347 });
330 348 }, function() {
331 349 $scope.abrirModalDomicilios($scope.cliente);
... ... @@ -530,7 +548,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
530 548 domicilio.Localidad + ', ' + domicilio.Provincia;
531 549 $scope.notaPedido.domicilioStamp = domicilioStamp;
532 550  
533   - $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga;
  551 + $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga;
534 552  
535 553 $scope.$broadcast('addCabecera', {
536 554 label: 'Cliente:',
... ... @@ -579,7 +597,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
579 597 focaModalService.alert('Primero seleccione un cliente');
580 598 return;
581 599 }
582   - if (validarNotaRemitada()) {
  600 + if ($scope.notaPedido.articulosNotaPedido.length !== 0) {
  601 + focaModalService.confirm('Se perderan los productos ingresados').then(function(data) {
  602 + if (data) {
  603 + abrirModal();
  604 + }
  605 + });
  606 + } else if (validarNotaRemitada()) {
  607 + abrirModal();
  608 + }
  609 + function abrirModal() {
583 610 var modalInstance = $uibModal.open(
584 611 {
585 612 ariaLabelledBy: 'Busqueda de Precio Condición',
... ... @@ -593,6 +620,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
593 620 }
594 621 }
595 622 );
  623 +
596 624 modalInstance.result.then(
597 625 function(precioCondicion) {
598 626 var cabecera = '';
... ... @@ -739,18 +767,28 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
739 767 $scope.notaPedido.articulosNotaPedido.splice(key, 1);
740 768 };
741 769  
742   - $scope.editarArticulo = function(key, articulo) {
  770 + $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) {
743 771 if (key === 13) {
744   - if (articulo.cantidad === null || articulo.cantidad === 0 ||
745   - articulo.cantidad === undefined) {
746   - focaModalService.alert('El valor debe ser al menos 1');
  772 + if (!articulo.cantidad || !articulo.precio) {
  773 + focaModalService.alert('Los valores deben ser al menos 1');
  774 + return;
  775 + } else if (articulo.cantidad < 0 || articulo.precio < 0) {
  776 + focaModalService.alert('Los valores no pueden ser negativos');
747 777 return;
748 778 }
749   - articulo.editCantidad = false;
750   - articulo.editPrecio = false;
  779 + articulo.cantidad = tmpCantidad;
  780 + articulo.precio = tmpPrecio;
  781 + $scope.getTotal();
  782 + articulo.editCantidad = articulo.editPrecio = false;
751 783 }
752 784 };
753 785  
  786 + $scope.cancelarEditar = function(articulo) {
  787 + $scope.tmpCantidad = articulo.cantidad;
  788 + $scope.tmpPrecio = articulo.precio;
  789 + articulo.editCantidad = articulo.editPrecio = false;
  790 + };
  791 +
754 792 $scope.cambioEdit = function(articulo, propiedad) {
755 793 if (propiedad === 'cantidad') {
756 794 articulo.editCantidad = true;
... ... @@ -902,19 +940,22 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
902 940 );
903 941  
904 942 if (notaPedido.notaPedidoPuntoDescarga) {
905   - var puntosDescarga = notaPedido.notaPedidoPuntoDescarga
  943 + var puntos = [];
  944 + notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga, idx, arr) {
  945 + puntos.push(notaPedidoPuntoDescarga.puntoDescarga);
  946 + });
906 947 cabeceras.push({
907 948 label: 'Puntos de descarga: ',
908   - valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))
  949 + valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos))
909 950 });
910 951 }
911 952  
912 953 addArrayCabecera(cabeceras);
913 954 }
914 955  
915   - function getCabeceraPuntoDescarga(puntosDescarga){
  956 + function getCabeceraPuntoDescarga(puntoDescarga){
916 957 var puntosStamp = '';
917   - puntosDescarga.forEach(function(punto, idx, arr) {
  958 + puntoDescarga.forEach(function(punto, idx, arr) {
918 959 puntosStamp += punto.descripcion;
919 960 if ((idx + 1) !== arr.length) puntosStamp += ', ';
920 961 });
... ... @@ -94,6 +94,10 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
94 94 },
95 95 getVendedorById: function(id) {
96 96 return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id);
  97 + },
  98 + getProveedorById: function(id) {
  99 + return $http.get(API_ENDPOINT.URL + '/proveedor/' + id);
97 100 }
  101 +
98 102 };
99 103 }]);
src/views/nota-pedido.html
... ... @@ -68,43 +68,48 @@
68 68 ></td>
69 69 <td class="col text-right">
70 70 <input
71   - ng-show="articulo.editCantidad"
72   - ng-model="articulo.cantidad"
  71 + ng-show="articulo.editCantidad && notaPedido.idRemito !== -1"
  72 + ng-model="tmpCantidad"
73 73 class="form-control"
74 74 foca-tipo-input
75 75 min="1"
76   - step="0.001"
77 76 foca-focus="articulo.editCantidad"
78   - ng-keypress="editarArticulo($event.keyCode, articulo)"
79   - ng-focus="selectFocus($event)"
  77 + ng-keypress="editarArticulo($event.keyCode, articulo, tmpCantidad, tmpPrecio);"
  78 + esc-key="cancelarEditar(articulo)"
  79 + ng-focus="selectFocus($event);
  80 + tmpCantidad = articulo.cantidad;
  81 + tmpPrecio = articulo.precio"
80 82 teclado-virtual
81 83 >
82 84 <i
83 85 class="selectable"
84 86 ng-click="cambioEdit(articulo, 'cantidad')"
85   - ng-hide="articulo.editCantidad"
  87 + ng-hide="articulo.editCantidad && notaPedido.idRemito !== -1"
86 88 ng-bind="articulo.cantidad">
87 89 </i>
88 90 </td>
89 91 <td class="col text-right">
90 92 <input
91   - ng-show="articulo.editPrecio"
92   - ng-model="articulo.precio"
  93 + ng-show="articulo.editPrecio && notaPedido.idRemito !== -1"
  94 + ng-model="tmpPrecio"
93 95 class="form-control"
94 96 foca-tipo-input
95   - min="0"
  97 + min="1"
96 98 step="0.0001"
97 99 foca-focus="articulo.editPrecio"
98   - ng-keypress="editarArticulo($event.keyCode, articulo)"
99   - ng-focus="selectFocus($event)"
  100 + ng-keypress="editarArticulo($event.keyCode, articulo, tmpCantidad, tmpPrecio);"
  101 + esc-key="cancelarEditar(articulo)"
  102 + ng-focus="selectFocus($event);
  103 + tmpCantidad = articulo.cantidad;
  104 + tmpPrecio = articulo.precio"
100 105 teclado-virtual
101 106 >
102 107 <i
103 108 class="selectable"
104   - ng-click="idLista == -1 && cambioEdit(articulo, 'precio')"
105   - ng-hide="articulo.editPrecio"
106   - ng-bind="articulo.precio |
107   - number: 4">
  109 + ng-click="cambioEdit(articulo, 'precio')"
  110 + ng-hide="articulo.editPrecio && notaPedido.idRemito !== -1"
  111 + ng-bind="articulo.precio | number: 4"
  112 + >
108 113 </i>
109 114 </td>
110 115 <td