Commit 8f2576328be8a8686e150eaa7e7848e30c24f066
Exists in
master
Merge remote-tracking branch 'upstream/develop'
Showing
2 changed files
Show diff stats
src/js/businessService.js
src/js/controller.js
... | ... | @@ -20,6 +20,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
20 | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
21 | 21 | { |
22 | 22 | config(); |
23 | + var cotizacionPArgentino = {}; | |
23 | 24 | |
24 | 25 | function config() { |
25 | 26 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
... | ... | @@ -37,7 +38,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
37 | 38 | maxDate: new Date(), |
38 | 39 | minDate: new Date(2010, 0, 1) |
39 | 40 | }; |
40 | - | |
41 | + | |
41 | 42 | //SETEO BOTONERA LATERAL |
42 | 43 | $timeout(function() { |
43 | 44 | focaBotoneraLateralService.showSalir(false); |
... | ... | @@ -252,11 +253,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
252 | 253 | }; |
253 | 254 | |
254 | 255 | $scope.seleccionarProductos = function() { |
256 | + | |
255 | 257 | if ($scope.idLista === undefined) { |
256 | 258 | focaModalService.alert( |
257 | 259 | 'Primero seleccione una lista de precio y condicion'); |
258 | 260 | return; |
261 | + } else if (!validarNotaRemitada()) { | |
262 | + return; | |
259 | 263 | } |
264 | + | |
260 | 265 | var modalInstance = $uibModal.open( |
261 | 266 | { |
262 | 267 | ariaLabelledBy: 'Busqueda de Productos', |
... | ... | @@ -334,7 +339,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
334 | 339 | ); |
335 | 340 | modalInstance.result.then( |
336 | 341 | function(puntoDescarga) { |
337 | - $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; | |
342 | + | |
343 | + puntoDescarga.forEach(function(punto) { | |
344 | + $scope.notaPedido.notaPedidoPuntoDescarga.push( | |
345 | + { | |
346 | + puntoDescarga: punto | |
347 | + } | |
348 | + ) | |
349 | + }); | |
338 | 350 | |
339 | 351 | $scope.$broadcast('addCabecera', { |
340 | 352 | label: 'Puntos de descarga:', |
... | ... | @@ -546,8 +558,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
546 | 558 | domicilio.Localidad + ', ' + domicilio.Provincia; |
547 | 559 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
548 | 560 | |
549 | - $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; | |
550 | - | |
551 | 561 | $scope.$broadcast('addCabecera', { |
552 | 562 | label: 'Cliente:', |
553 | 563 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
... | ... | @@ -561,12 +571,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
561 | 571 | if (domicilio.verPuntos) { |
562 | 572 | delete $scope.notaPedido.domicilio.verPuntos; |
563 | 573 | $scope.seleccionarPuntosDeDescarga(); |
564 | - } else { | |
565 | - crearNotaPedidoService | |
566 | - .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | |
567 | - .then(function(res) { | |
568 | - if (res.data.length) $scope.seleccionarPuntosDeDescarga(); | |
569 | - }); | |
570 | 574 | } |
571 | 575 | |
572 | 576 | // Seteo checked en botonera |
... | ... | @@ -597,6 +601,11 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
597 | 601 | }; |
598 | 602 | |
599 | 603 | $scope.seleccionarPreciosYCondiciones = function() { |
604 | + | |
605 | + if (!validarNotaRemitada()) { | |
606 | + return; | |
607 | + } | |
608 | + | |
600 | 609 | if (!$scope.notaPedido.cliente.COD) { |
601 | 610 | focaModalService.alert('Primero seleccione un cliente'); |
602 | 611 | return; |
... | ... | @@ -684,9 +693,21 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
684 | 693 | }; |
685 | 694 | focaModalService.modal(parametrosModal).then( |
686 | 695 | function(moneda) { |
687 | - $scope.abrirModalCotizacion(moneda); | |
688 | - }, function() { | |
689 | 696 | |
697 | + if (moneda.ID !== 1) { | |
698 | + $scope.abrirModalCotizacion(moneda); | |
699 | + return; | |
700 | + } | |
701 | + | |
702 | + crearNotaPedidoService.getCotizacionByIdMoneda(1) | |
703 | + .then(function (res) { | |
704 | + | |
705 | + cotizacionPArgentino = res.data[0].cotizaciones[0]; | |
706 | + cotizacionPArgentino.moneda = moneda; | |
707 | + | |
708 | + actualizarCabeceraMoneda(cotizacionPArgentino); | |
709 | + $scope.notaPedido.cotizacion = cotizacionPArgentino; | |
710 | + }); | |
690 | 711 | } |
691 | 712 | ); |
692 | 713 | } |
... | ... | @@ -723,35 +744,11 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
723 | 744 | ); |
724 | 745 | modalInstance.result.then( |
725 | 746 | function(cotizacion) { |
726 | - var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | |
727 | - for (var i = 0; i < articulosTablaTemp.length; i++) { | |
728 | - articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | |
729 | - $scope.notaPedido.cotizacion.VENDEDOR; | |
730 | - articulosTablaTemp[i].precio = (articulosTablaTemp[i].precio / | |
731 | - cotizacion.VENDEDOR).toFixed(4); | |
732 | - } | |
733 | - $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | |
734 | - $scope.notaPedido.cotizacion = cotizacion; | |
735 | - $scope.notaPedido.cotizacion.moneda = moneda; | |
736 | - if (moneda.DETALLE === 'PESOS ARGENTINOS') { | |
737 | - $scope.$broadcast('removeCabecera', 'Moneda:'); | |
738 | - $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | |
739 | - $scope.$broadcast('removeCabecera', 'Cotizacion:'); | |
740 | - } else { | |
741 | - $scope.$broadcast('addCabecera', { | |
742 | - label: 'Moneda:', | |
743 | - valor: moneda.DETALLE | |
744 | - }); | |
745 | - $scope.$broadcast('addCabecera', { | |
746 | - label: 'Fecha cotizacion:', | |
747 | - valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | |
748 | - }); | |
749 | - $scope.$broadcast('addCabecera', { | |
750 | - label: 'Cotizacion:', | |
751 | - valor: $filter('number')(cotizacion.VENDEDOR, '2') | |
752 | - }); | |
753 | - } | |
754 | 747 | |
748 | + cotizacion.moneda = moneda; | |
749 | + actualizarCabeceraMoneda(cotizacion); | |
750 | + | |
751 | + $scope.notaPedido.cotizacion = cotizacion; | |
755 | 752 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; |
756 | 753 | }, function() { |
757 | 754 | |
... | ... | @@ -759,6 +756,33 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
759 | 756 | ); |
760 | 757 | }; |
761 | 758 | |
759 | + function actualizarCabeceraMoneda (cotizacion) { | |
760 | + | |
761 | + $scope.notaPedido.articulosNotaPedido.forEach(function(art) { | |
762 | + art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | |
763 | + art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | |
764 | + }); | |
765 | + | |
766 | + if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | |
767 | + $scope.$broadcast('removeCabecera', 'Moneda:'); | |
768 | + $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | |
769 | + $scope.$broadcast('removeCabecera', 'Cotizacion:'); | |
770 | + } else { | |
771 | + $scope.$broadcast('addCabecera', { | |
772 | + label: 'Moneda:', | |
773 | + valor: cotizacion.moneda.DETALLE | |
774 | + }); | |
775 | + $scope.$broadcast('addCabecera', { | |
776 | + label: 'Fecha cotizacion:', | |
777 | + valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | |
778 | + }); | |
779 | + $scope.$broadcast('addCabecera', { | |
780 | + label: 'Cotizacion:', | |
781 | + valor: $filter('number')(cotizacion.VENDEDOR, '2') | |
782 | + }); | |
783 | + } | |
784 | + } | |
785 | + | |
762 | 786 | $scope.agregarATabla = function(key) { |
763 | 787 | if (key === 13) { |
764 | 788 | if ($scope.articuloACargar.cantidad === undefined || |
... | ... | @@ -774,7 +798,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
774 | 798 | }; |
775 | 799 | |
776 | 800 | $scope.quitarArticulo = function(key) { |
777 | - $scope.notaPedido.articulosNotaPedido.splice(key, 1); | |
801 | + if (validarNotaRemitada()) { | |
802 | + $scope.notaPedido.articulosNotaPedido.splice(key, 1); | |
803 | + } | |
778 | 804 | }; |
779 | 805 | |
780 | 806 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { |
... | ... | @@ -923,7 +949,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
923 | 949 | }); |
924 | 950 | |
925 | 951 | $filter('filter')($scope.botonera, |
926 | - { label: 'Precios y Condiciones'})[0].checked = true; | |
952 | + { label: 'Precios y condiciones'})[0].checked = true; | |
927 | 953 | } |
928 | 954 | |
929 | 955 | if (notaPedido.flete !== undefined) { |
... | ... | @@ -974,7 +1000,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
974 | 1000 | if (notaPedido.notaPedidoPuntoDescarga.length) { |
975 | 1001 | var puntos = []; |
976 | 1002 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { |
977 | - puntos.push(notaPedidoPuntoDescarga); | |
1003 | + puntos.push(notaPedidoPuntoDescarga.puntoDescarga); | |
978 | 1004 | }); |
979 | 1005 | cabeceras.push({ |
980 | 1006 | label: 'Puntos de descarga: ', |
... | ... | @@ -1048,13 +1074,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
1048 | 1074 | } |
1049 | 1075 | |
1050 | 1076 | function deleteCliente() { |
1051 | - delete $scope.notaPedido.domicilioStamp; | |
1052 | - delete $scope.notaPedido.notaPedidoPuntoDescarga; | |
1077 | + $scope.notaPedido.domicilioStamp = ''; | |
1078 | + $scope.notaPedido.notaPedidoPuntoDescarga = []; | |
1053 | 1079 | $scope.notaPedido.domicilio = {dom: ''}; |
1054 | 1080 | $scope.notaPedido.cliente = {}; |
1055 | 1081 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
1056 | 1082 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
1057 | 1083 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
1084 | + $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = false; | |
1058 | 1085 | } |
1059 | 1086 | } |
1060 | 1087 | ]); |