Commit 281638edcc2e6e24a5ef43e12674c9f8c0487c36
1 parent
07521a74b4
Exists in
master
and in
1 other branch
fix inicializacion de moneda
Showing
1 changed file
with
29 additions
and
20 deletions
Show diff stats
src/js/controller.js
... | ... | @@ -34,18 +34,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
34 | 34 | minDate: new Date(2010, 0, 1) |
35 | 35 | }; |
36 | 36 | |
37 | - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | |
38 | - var monedaPorDefecto; | |
39 | - crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | |
40 | - monedaPorDefecto = res.data[0]; | |
41 | - | |
42 | - $scope.notaPedido.moneda = monedaPorDefecto; | |
43 | - $scope.inicial.notaPedido.moneda = $scope.notaPedido.moneda; | |
44 | - | |
45 | - $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | |
46 | - $scope.inicial.notaPedido.cotizacion = $scope.notaPedido.cotizacion; | |
47 | - }); | |
48 | - | |
49 | 37 | //SETEO BOTONERA LATERAL |
50 | 38 | $timeout(function() { |
51 | 39 | focaBotoneraLateralService.showSalir(false); |
... | ... | @@ -61,8 +49,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
61 | 49 | } else { |
62 | 50 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
63 | 51 | } |
64 | - | |
65 | - init(); | |
52 | + | |
53 | + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | |
54 | + crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | |
55 | + $scope.monedaDefecto = res.data[0]; | |
56 | + $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0]; | |
57 | + | |
58 | + init(); | |
59 | + }); | |
66 | 60 | } |
67 | 61 | |
68 | 62 | function init() { |
... | ... | @@ -73,7 +67,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
73 | 67 | cliente: {}, |
74 | 68 | proveedor: {}, |
75 | 69 | domicilio: {dom: ''}, |
76 | - vendedor: {} | |
70 | + vendedor: {}, | |
71 | + moneda: $scope.monedaDefecto, | |
72 | + cotizacion: $scope.cotizacionDefecto | |
77 | 73 | }; |
78 | 74 | |
79 | 75 | $scope.articulosTabla = []; |
... | ... | @@ -600,10 +596,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
600 | 596 | |
601 | 597 | $scope.getTotal = function() { |
602 | 598 | var total = 0; |
603 | - var arrayTempArticulos = $scope.articulosTabla; | |
604 | - for (var i = 0; i < arrayTempArticulos.length; i++) { | |
605 | - total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | |
599 | + | |
600 | + if ($scope.articulosTabla) { | |
601 | + var arrayTempArticulos = $scope.articulosTabla; | |
602 | + for (var i = 0; i < arrayTempArticulos.length; i++) { | |
603 | + total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | |
604 | + } | |
606 | 605 | } |
606 | + | |
607 | 607 | return parseFloat(total.toFixed(2)); |
608 | 608 | }; |
609 | 609 | |
... | ... | @@ -757,26 +757,35 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
757 | 757 | templateUrl: 'modal-cotizacion.html', |
758 | 758 | controller: 'focaModalCotizacionController', |
759 | 759 | size: 'lg', |
760 | - resolve: {idMoneda: function() {return moneda.ID;}} | |
760 | + resolve: { | |
761 | + idMoneda: function() { | |
762 | + return moneda.ID; | |
763 | + } | |
764 | + } | |
761 | 765 | } |
762 | 766 | ); |
763 | 767 | modalInstance.result.then( |
764 | 768 | function(cotizacion) { |
765 | 769 | var articulosTablaTemp = $scope.articulosTabla; |
770 | + | |
766 | 771 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
767 | 772 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
768 | 773 | $scope.notaPedido.cotizacion.VENDEDOR; |
769 | 774 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
770 | 775 | cotizacion.VENDEDOR; |
771 | 776 | } |
777 | + | |
772 | 778 | $scope.articulosTabla = articulosTablaTemp; |
773 | 779 | $scope.notaPedido.moneda = moneda; |
780 | + $scope.monedaDefecto = moneda; | |
781 | + $scope.cotizacionDefecto = cotizacion; | |
774 | 782 | $scope.notaPedido.cotizacion = cotizacion; |
783 | + | |
775 | 784 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
776 | 785 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
777 | 786 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
778 | 787 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
779 | - }else { | |
788 | + } else { | |
780 | 789 | $scope.$broadcast('addCabecera', { |
781 | 790 | label: 'Moneda:', |
782 | 791 | valor: moneda.DETALLE |