Commit 8b76f7d0e80a79131f7e8920529fa90c60c5cb26
Exists in
master
Merge branch 'develop' of git.focasoftware.com:npm/foca-crear-remito
# Conflicts: # src/js/controller.js
Showing
3 changed files
Show diff stats
package.json
src/js/controller.js
... | ... | @@ -9,6 +9,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
9 | 9 | { |
10 | 10 | config(); |
11 | 11 | |
12 | + var cotizacionPArgentino = {}; | |
13 | + | |
12 | 14 | function config() { |
13 | 15 | $scope.tmpCantidad = Number; |
14 | 16 | $scope.tmpPrecio = Number; |
... | ... | @@ -25,18 +27,18 @@ angular.module('focaCrearRemito') .controller('remitoController', |
25 | 27 | minDate: new Date(2010, 0, 1) |
26 | 28 | }; |
27 | 29 | |
28 | - var monedaPorDefecto; | |
29 | - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | |
30 | - crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { | |
31 | - monedaPorDefecto = res.data[0]; | |
32 | - | |
33 | - $scope.remito.cotizacion = Object.assign( | |
34 | - {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] | |
35 | - ); | |
36 | - $scope.inicial.cotizacion = $scope.remito.cotizacion; | |
37 | - $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion); | |
38 | 30 | |
39 | - $timeout(function() { getLSRemito(); }); | |
31 | + crearRemitoService.getParametros().then(function(res) { | |
32 | + var parametros = JSON.parse(res.data[0].jsonText); | |
33 | + if ($localStorage.remito) { | |
34 | + $timeout(function() { getLSRemito();} ); | |
35 | + } else { | |
36 | + for (var property in parametros) { | |
37 | + $scope.remito[property] = parametros[property]; | |
38 | + $scope.inicial[property] = parametros[property]; | |
39 | + } | |
40 | + setearRemito($scope.remito); | |
41 | + } | |
40 | 42 | }); |
41 | 43 | |
42 | 44 | //SETEO BOTONERA LATERAL |
... | ... | @@ -48,6 +50,7 @@ angular.module('focaCrearRemito') .controller('remitoController', |
48 | 50 | }); |
49 | 51 | |
50 | 52 | init(); |
53 | + | |
51 | 54 | } |
52 | 55 | |
53 | 56 | function init() { |
... | ... | @@ -114,7 +117,7 @@ angular.module('focaCrearRemito') .controller('remitoController', |
114 | 117 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
115 | 118 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
116 | 119 | var puntosDescarga = []; |
117 | - notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedido, idx, arr) { | |
120 | + notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedido) { | |
118 | 121 | puntosDescarga.push(notaPedido.puntoDescarga); |
119 | 122 | }); |
120 | 123 | var cabeceras = [ |
... | ... | @@ -166,10 +169,28 @@ angular.module('focaCrearRemito') .controller('remitoController', |
166 | 169 | }, |
167 | 170 | { |
168 | 171 | label: 'Puntos de descarga: ', |
169 | - valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga)) | |
172 | + valor: $filter('rellenarDigitos')( | |
173 | + getCabeceraPuntoDescarga(puntosDescarga)) | |
170 | 174 | } |
171 | 175 | ]; |
172 | 176 | |
177 | + // Seteo checked en cabeceras | |
178 | + $filter('filter')($scope.botonera, | |
179 | + { label: 'Cliente' })[0].checked = true; | |
180 | + $filter('filter')($scope.botonera, | |
181 | + { label: 'Proveedor' })[0].checked = true; | |
182 | + $filter('filter')($scope.botonera, | |
183 | + { label: 'Moneda' })[0].checked = true; | |
184 | + $filter('filter')($scope.botonera, | |
185 | + { label: 'Nota pedido' })[0].checked = true; | |
186 | + $filter('filter')($scope.botonera, | |
187 | + { label: 'Precios y condiciones' })[0].checked = true; | |
188 | + | |
189 | + if (notaPedido.observaciones) { | |
190 | + $filter('filter')($scope.botonera, | |
191 | + { label: 'Observaciones' })[0].checked = true; | |
192 | + } | |
193 | + | |
173 | 194 | function valorPrecioCondicion() { |
174 | 195 | if (notaPedido.idPrecioCondicion > 0) { |
175 | 196 | return notaPedido.precioCondicion.nombre; |
... | ... | @@ -198,10 +219,12 @@ angular.module('focaCrearRemito') .controller('remitoController', |
198 | 219 | $scope.remito.id = 0; |
199 | 220 | $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; |
200 | 221 | |
201 | - for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { | |
202 | - notaPedido.articulosNotaPedido[i].id = 0; | |
203 | - notaPedido.articulosNotaPedido[i].idRemito = 0; | |
204 | - } | |
222 | + notaPedido.articulosNotaPedido.forEach(function (articulo) { | |
223 | + articulo.id = 0; | |
224 | + articulo.idRemito = 0; | |
225 | + articulo.precio = | |
226 | + (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); | |
227 | + }); | |
205 | 228 | |
206 | 229 | $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; |
207 | 230 | |
... | ... | @@ -272,29 +295,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
272 | 295 | idCliente: $scope.remito.cliente.COD, |
273 | 296 | nombreCliente: $scope.remito.cliente.NOM, |
274 | 297 | cuitCliente: $scope.remito.cliente.CUIT, |
275 | - responsabilidadIvaCliente: 0,//TODO, | |
276 | - descuento: 0,//TODO, | |
277 | - importeNeto: 0,//TODO | |
278 | - importeExento: 0,//TODO | |
279 | - importeIva: 0,//TODO | |
280 | - importeIvaServicios: 0,//TODO | |
281 | - importeImpuestoInterno: 0,//TODO | |
282 | - importeImpuestoInterno1: 0,//TODO | |
283 | - importeImpuestoInterno2: 0,//TODO | |
284 | - percepcion: 0,//TODO | |
285 | - percepcionIva: 0,//TODO | |
286 | - redondeo: 0,//TODO | |
287 | 298 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, |
288 | 299 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
289 | - anulado: false, | |
290 | - planilla: 0,//TODO | |
291 | - lugar: 0,//TODO | |
292 | - cuentaMadre: 0,// | |
293 | - cuentaContable: 0,//TODO | |
294 | - asiento: 0,//TODO | |
295 | - e_hd: '',//TODO | |
296 | - c_hd: '', | |
297 | - numeroLiquidoProducto: 0,//TODO | |
298 | 300 | idVendedor: $scope.remito.idVendedor, |
299 | 301 | idProveedor: $scope.remito.idProveedor, |
300 | 302 | idDomicilio: $scope.remito.idDomicilio, |
... | ... | @@ -305,12 +307,33 @@ angular.module('focaCrearRemito') .controller('remitoController', |
305 | 307 | bomba: $scope.remito.bomba, |
306 | 308 | kilometros: $scope.remito.kilometros, |
307 | 309 | domicilioStamp: $scope.remito.domicilioStamp, |
308 | - estado: 0,//TODO | |
309 | - destinoVenta: 0,//TODO | |
310 | - operacionTipo: 0, //TODO | |
311 | 310 | observaciones: $scope.remito.observaciones, |
312 | 311 | numeroRemito: parseInt($scope.comprobante), |
313 | - sucursal: parseInt($scope.puntoVenta) | |
312 | + sucursal: parseInt($scope.puntoVenta), | |
313 | + responsabilidadIvaCliente: $scope.remito.cliente.IVA, | |
314 | + descuento: 0,//TODO, | |
315 | + importeNeto: getImporte('netoUnitario'), | |
316 | + importeExento: getImporte('exentoUnitario'), | |
317 | + importeIva: getImporte('ivaUnitario'), | |
318 | + importeIvaServicios: 0,//TODO | |
319 | + importeImpuestoInterno: getImporte('impuestoInternoUnitario'), | |
320 | + importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), | |
321 | + importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), | |
322 | + percepcion: 0,//TODO | |
323 | + percepcionIva: 0,//TODO | |
324 | + redondeo: 0,//TODO | |
325 | + anulado: false, | |
326 | + planilla: $filter('date')($scope.now, 'ddMMyyyy'), | |
327 | + lugar: parseInt($scope.puntoVenta), | |
328 | + cuentaMadre: 0,//TODO | |
329 | + cuentaContable: 0,//TODO | |
330 | + asiento: 0,//TODO | |
331 | + e_hd: '',//TODO | |
332 | + c_hd: '', | |
333 | + numeroLiquidoProducto: 0,//TODO | |
334 | + estado: 0, | |
335 | + destinoVenta: 0,//TODO | |
336 | + operacionTipo: 0, //TODO | |
314 | 337 | }, |
315 | 338 | notaPedido: $scope.notaPedido |
316 | 339 | }; |
... | ... | @@ -353,7 +376,7 @@ angular.module('focaCrearRemito') .controller('remitoController', |
353 | 376 | ]) |
354 | 377 | ); |
355 | 378 | |
356 | - init(); | |
379 | + config(); | |
357 | 380 | |
358 | 381 | }, function(error) { |
359 | 382 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); |
... | ... | @@ -447,7 +470,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
447 | 470 | |
448 | 471 | $scope.$broadcast('addCabecera', { |
449 | 472 | label: 'Puntos de descarga:', |
450 | - valor: getCabeceraPuntoDescarga($scope.remito.domicilio.puntosDescarga) | |
473 | + valor: getCabeceraPuntoDescarga( | |
474 | + $scope.remito.domicilio.puntosDescarga ) | |
451 | 475 | }); |
452 | 476 | }, function() { |
453 | 477 | $scope.abrirModalDomicilios($scope.cliente); |
... | ... | @@ -578,12 +602,14 @@ angular.module('focaCrearRemito') .controller('remitoController', |
578 | 602 | modalInstanceDomicilio.result.then( |
579 | 603 | function(domicilio) { |
580 | 604 | $scope.remito.domicilio = domicilio; |
605 | + console.log(cliente); | |
581 | 606 | $scope.remito.cliente = { |
582 | 607 | COD: cliente.cod, |
583 | 608 | CUIT: cliente.cuit, |
584 | 609 | NOM: cliente.nom, |
585 | 610 | MAIL: cliente.mail, |
586 | - MOD: cliente.mod | |
611 | + MOD: cliente.mod, | |
612 | + IVA: cliente.iva | |
587 | 613 | }; |
588 | 614 | |
589 | 615 | var domicilioStamp = |
... | ... | @@ -609,6 +635,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
609 | 635 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); |
610 | 636 | }); |
611 | 637 | } |
638 | + | |
639 | + $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; | |
612 | 640 | }, function() { |
613 | 641 | $scope.seleccionarCliente(true); |
614 | 642 | return; |
... | ... | @@ -637,12 +665,13 @@ angular.module('focaCrearRemito') .controller('remitoController', |
637 | 665 | return; |
638 | 666 | } |
639 | 667 | |
640 | - if ($scope.remito.articulosRemito !== 0) { | |
641 | - focaModalService.confirm('Se perderan los productos ingresados').then(function(data) { | |
642 | - if (data && varlidarRemitoFacturado()) { | |
643 | - abrirModal(); | |
644 | - } | |
645 | - }); | |
668 | + if ($scope.remito.articulosRemito.length !== 0) { | |
669 | + focaModalService.confirm('Se perderan los productos ingresados') | |
670 | + .then(function(data) { | |
671 | + if (data && varlidarRemitoFacturado()) { | |
672 | + abrirModal(); | |
673 | + } | |
674 | + }); | |
646 | 675 | } else { |
647 | 676 | abrirModal(); |
648 | 677 | } |
... | ... | @@ -690,6 +719,9 @@ angular.module('focaCrearRemito') .controller('remitoController', |
690 | 719 | valor: cabecera |
691 | 720 | }); |
692 | 721 | $scope.remito.precioCondicion = precioCondicion; |
722 | + | |
723 | + $filter('filter')($scope.botonera, | |
724 | + { label: 'Precios y Condiciones'})[0].checked = true; | |
693 | 725 | }, function() { |
694 | 726 | |
695 | 727 | } |
... | ... | @@ -757,6 +789,9 @@ angular.module('focaCrearRemito') .controller('remitoController', |
757 | 789 | $scope.remito.bomba = false; |
758 | 790 | $scope.remito.kilometros = null; |
759 | 791 | } |
792 | + | |
793 | + $filter('filter')($scope.botonera, | |
794 | + { label: 'Proveedor'})[0].checked = true; | |
760 | 795 | }, function() { |
761 | 796 | $scope.seleccionarTransportista(); |
762 | 797 | } |
... | ... | @@ -783,7 +818,22 @@ angular.module('focaCrearRemito') .controller('remitoController', |
783 | 818 | }; |
784 | 819 | focaModalService.modal(parametrosModal).then( |
785 | 820 | function(moneda) { |
786 | - $scope.abrirModalCotizacion(moneda); | |
821 | + | |
822 | + if (moneda.ID !== 1) { | |
823 | + $scope.abrirModalCotizacion(moneda); | |
824 | + return; | |
825 | + } | |
826 | + | |
827 | + crearRemitoService.getCotizacionByIdMoneda(1) | |
828 | + .then(function (res) { | |
829 | + | |
830 | + cotizacionPArgentino = res.data[0].cotizaciones[0]; | |
831 | + cotizacionPArgentino.moneda = moneda; | |
832 | + | |
833 | + actualizarCabeceraMoneda(cotizacionPArgentino); | |
834 | + | |
835 | + $scope.remito.cotizacion = cotizacionPArgentino; | |
836 | + }); | |
787 | 837 | }, function() { |
788 | 838 | |
789 | 839 | } |
... | ... | @@ -816,40 +866,44 @@ angular.module('focaCrearRemito') .controller('remitoController', |
816 | 866 | ); |
817 | 867 | modalInstance.result.then( |
818 | 868 | function(cotizacion) { |
819 | - var articulosTablaTemp = $scope.remito.articulosRemito; | |
820 | - for(var i = 0; i < articulosTablaTemp.length; i++) { | |
821 | - articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | |
822 | - $scope.remito.cotizacion.VENDEDOR; | |
823 | - articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | |
824 | - cotizacion.VENDEDOR; | |
825 | - } | |
826 | - $scope.remito.articulosRemito = articulosTablaTemp; | |
869 | + | |
870 | + cotizacion.moneda = moneda; | |
871 | + | |
872 | + actualizarCabeceraMoneda(cotizacion); | |
827 | 873 | $scope.remito.cotizacion = cotizacion; |
828 | - $scope.remito.cotizacion.moneda = moneda; | |
829 | - if (moneda.DETALLE === 'PESOS ARGENTINOS') { | |
830 | - $scope.$broadcast('removeCabecera', 'Moneda:'); | |
831 | - $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | |
832 | - $scope.$broadcast('removeCabecera', 'Cotizacion:'); | |
833 | - } else { | |
834 | - $scope.$broadcast('addCabecera',{ | |
835 | - label: 'Moneda:', | |
836 | - valor: moneda.DETALLE | |
837 | - }); | |
838 | - $scope.$broadcast('addCabecera',{ | |
839 | - label: 'Fecha cotizacion:', | |
840 | - valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | |
841 | - }); | |
842 | - $scope.$broadcast('addCabecera',{ | |
843 | - label: 'Cotizacion:', | |
844 | - valor: $filter('number')(cotizacion.VENDEDOR, '2') | |
845 | - }); | |
846 | - } | |
847 | 874 | }, function() { |
848 | 875 | |
849 | 876 | } |
850 | 877 | ); |
851 | 878 | }; |
852 | 879 | |
880 | + function actualizarCabeceraMoneda (cotizacion) { | |
881 | + | |
882 | + $scope.remito.articulosRemito.forEach(function(art) { | |
883 | + art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); | |
884 | + art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | |
885 | + }); | |
886 | + | |
887 | + if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | |
888 | + $scope.$broadcast('removeCabecera', 'Moneda:'); | |
889 | + $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | |
890 | + $scope.$broadcast('removeCabecera', 'Cotizacion:'); | |
891 | + } else { | |
892 | + $scope.$broadcast('addCabecera', { | |
893 | + label: 'Moneda:', | |
894 | + valor: cotizacion.moneda.DETALLE | |
895 | + }); | |
896 | + $scope.$broadcast('addCabecera', { | |
897 | + label: 'Fecha cotizacion:', | |
898 | + valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | |
899 | + }); | |
900 | + $scope.$broadcast('addCabecera', { | |
901 | + label: 'Cotizacion:', | |
902 | + valor: $filter('number')(cotizacion.VENDEDOR, '2') | |
903 | + }); | |
904 | + } | |
905 | + } | |
906 | + | |
853 | 907 | $scope.agregarATabla = function(key) { |
854 | 908 | if (key === 13) { |
855 | 909 | if ($scope.articuloACargar.cantidad === undefined || |
... | ... | @@ -873,6 +927,13 @@ angular.module('focaCrearRemito') .controller('remitoController', |
873 | 927 | var result = $scope.remito.articulosRemito.filter(function(articulo) { |
874 | 928 | return articulo.idRemito >= 0; |
875 | 929 | }); |
930 | + | |
931 | + // Agrego checked en cabecera si hay datos | |
932 | + if (result.length) { | |
933 | + $filter('filter')($scope.botonera, { label: 'Productos'})[0].checked = true; | |
934 | + } else { | |
935 | + $filter('filter')($scope.botonera, { label: 'Productos'})[0].checked = false; | |
936 | + } | |
876 | 937 | return result; |
877 | 938 | }; |
878 | 939 | |
... | ... | @@ -1004,6 +1065,11 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1004 | 1065 | '2') |
1005 | 1066 | }); |
1006 | 1067 | } |
1068 | + | |
1069 | + if (remito.cotizacion.moneda) { | |
1070 | + $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | |
1071 | + } | |
1072 | + | |
1007 | 1073 | if (remito.cliente.COD) { |
1008 | 1074 | cabeceras.push({ |
1009 | 1075 | label: 'Cliente:', |
... | ... | @@ -1014,6 +1080,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1014 | 1080 | label: 'Domicilio:', |
1015 | 1081 | valor: remito.domicilioStamp |
1016 | 1082 | }); |
1083 | + | |
1084 | + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | |
1017 | 1085 | } |
1018 | 1086 | if (remito.vendedor.NUM) { |
1019 | 1087 | cabeceras.push({ |
... | ... | @@ -1028,6 +1096,8 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1028 | 1096 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + |
1029 | 1097 | ' - ' + remito.proveedor.NOM |
1030 | 1098 | }); |
1099 | + | |
1100 | + $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; | |
1031 | 1101 | } |
1032 | 1102 | if (remito.flete !== undefined && remito.fob !== undefined) { |
1033 | 1103 | cabeceras.push({ |
... | ... | @@ -1042,6 +1112,9 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1042 | 1112 | valor: valorPrecioCondicion() + ' ' + |
1043 | 1113 | remitoBusinessService.plazoToString(remito.remitoPlazo) |
1044 | 1114 | }); |
1115 | + | |
1116 | + $filter('filter')($scope.botonera, | |
1117 | + { label: 'Precios y condiciones' })[0].checked = true; | |
1045 | 1118 | } |
1046 | 1119 | function valorPrecioCondicion() { |
1047 | 1120 | if (remito.idPrecioCondicion > 0) { |
... | ... | @@ -1080,6 +1153,14 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1080 | 1153 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga)) |
1081 | 1154 | }); |
1082 | 1155 | } |
1156 | + | |
1157 | + if ($scope.remito.articulosRemito.length) { | |
1158 | + $scope.remito.articulosRemito.forEach(function (articulo) { | |
1159 | + articulo.precio = | |
1160 | + (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4); | |
1161 | + }); | |
1162 | + } | |
1163 | + | |
1083 | 1164 | addArrayCabecera(cabeceras); |
1084 | 1165 | } |
1085 | 1166 | |
... | ... | @@ -1135,5 +1216,20 @@ angular.module('focaCrearRemito') .controller('remitoController', |
1135 | 1216 | } |
1136 | 1217 | }); |
1137 | 1218 | } |
1219 | + //recibo la propiedad por la cual quiero obtener el valor | |
1220 | + function getImporte(propiedad) { | |
1221 | + var importe = 0; | |
1222 | + | |
1223 | + $scope.articulosFiltro().forEach(function (articulo) { | |
1224 | + | |
1225 | + if (articulo[propiedad]) { | |
1226 | + importe += articulo[propiedad] * articulo.cantidad; | |
1227 | + } | |
1228 | + return; | |
1229 | + | |
1230 | + }); | |
1231 | + | |
1232 | + return importe; | |
1233 | + } | |
1138 | 1234 | } |
1139 | 1235 | ]); |
src/js/service.js
... | ... | @@ -29,6 +29,9 @@ angular.module('focaCrearRemito') |
29 | 29 | return $http.post(route + '/articulos/remito', |
30 | 30 | {articuloRemito: articuloRemito}); |
31 | 31 | }, |
32 | + getProveedorById: function(id) { | |
33 | + return $http.get(API_ENDPOINT.URL + '/proveedor/' + id); | |
34 | + }, | |
32 | 35 | getDomiciliosByIdRemito: function(id) { |
33 | 36 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); |
34 | 37 | }, |
... | ... | @@ -72,6 +75,9 @@ angular.module('focaCrearRemito') |
72 | 75 | enviarCorreo: function(options) { |
73 | 76 | return $http.post(API_ENDPOINT.URL + '/remito/mail', options); |
74 | 77 | }, |
78 | + getParametros: function() { | |
79 | + return $http.get(API_ENDPOINT.URL + '/parametros/remito'); | |
80 | + }, | |
75 | 81 | getBotonera: function() { |
76 | 82 | return [ |
77 | 83 | { |