Commit 534017d21c0281ce88450b9cd1f275dac1f46477

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

bug limpiar pantalla al dar al botón crear después de editar

See merge request modulos-npm/foca-crear-nota-pedido!4
src/js/controller.js
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .controller('notaPedidoCtrl', 2 .controller('notaPedidoCtrl',
3 [ 3 [
4 '$scope', 4 '$scope',
5 '$uibModal', 5 '$uibModal',
6 '$location', 6 '$location',
7 'crearNotaPedidoService', 7 'crearNotaPedidoService',
8 function($scope, $uibModal, $location, crearNotaPedidoService) { 8 function($scope, $uibModal, $location, crearNotaPedidoService) {
9 $scope.notaPedido = {}; 9 $scope.notaPedido = {};
10 $scope.articulosTabla = []; 10 $scope.articulosTabla = [];
11 var idLista; 11 var idLista;
12 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 12 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
13 $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1); 13 $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1);
14 crearNotaPedidoService.getPrecioCondicion().then( 14 crearNotaPedidoService.getPrecioCondicion().then(
15 function(res) { 15 function(res) {
16 $scope.precioCondiciones = res.data; 16 $scope.precioCondiciones = res.data;
17 } 17 }
18 ); 18 );
19 if (notaPedidoTemp != undefined) { 19 if (notaPedidoTemp != undefined) {
20 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 20 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
21 $scope.notaPedido = notaPedidoTemp; 21 $scope.notaPedido = notaPedidoTemp;
22 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 22 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
23 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 23 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
24 idLista = $scope.notaPedido.precioCondicion; 24 idLista = $scope.notaPedido.precioCondicion;
25 crearNotaPedidoService.getArticulosByIdNotaPedido($scope.notaPedido.id).then( 25 crearNotaPedidoService.getArticulosByIdNotaPedido($scope.notaPedido.id).then(
26 function(res) { 26 function(res) {
27 $scope.articulosTabla = res.data; 27 $scope.articulosTabla = res.data;
28 } 28 }
29 ); 29 );
30 crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 30 crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
31 function(res) { 31 function(res) {
32 $scope.notaPedido.domicilio = res.data; 32 $scope.notaPedido.domicilio = res.data;
33 } 33 }
34 ) 34 )
35 } else { 35 } else {
36 $scope.notaPedido.fechaCarga = new Date(); 36 $scope.notaPedido.fechaCarga = new Date();
37 $scope.notaPedido.domicilio = [{ id: 0 }] 37 $scope.notaPedido.domicilio = [{ id: 0 }]
38 $scope.notaPedido.bomba = '1'; 38 $scope.notaPedido.bomba = '1';
39 $scope.notaPedido.flete = '1'; 39 $scope.notaPedido.flete = '1';
40 idLista = undefined; 40 idLista = undefined;
41 } 41 }
42 $scope.addNewDom = function() { 42 $scope.addNewDom = function() {
43 $scope.notaPedido.domicilio.push({ 'id': 0 }); 43 $scope.notaPedido.domicilio.push({ 'id': 0 });
44 } 44 }
45 $scope.removeNewChoice = function(choice) { 45 $scope.removeNewChoice = function(choice) {
46 if ($scope.notaPedido.domicilio.length > 1) { 46 if ($scope.notaPedido.domicilio.length > 1) {
47 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1) 47 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1)
48 } 48 }
49 } 49 }
50 $scope.crearNotaPedido = function() { 50 $scope.crearNotaPedido = function() {
51 var notaPedido = { 51 var notaPedido = {
52 id: 0, 52 id: 0,
53 precioCondicion: $scope.notaPedido.precioCondicion, 53 precioCondicion: $scope.notaPedido.precioCondicion,
54 fechaCarga: $scope.notaPedido.fechaCarga, 54 fechaCarga: $scope.notaPedido.fechaCarga,
55 vendedor: $scope.notaPedido.vendedor, 55 vendedor: $scope.notaPedido.vendedor,
56 cliente: $scope.notaPedido.cliente, 56 cliente: $scope.notaPedido.cliente,
57 producto: $scope.notaPedido.producto, 57 producto: $scope.notaPedido.producto,
58 bomba: $scope.notaPedido.bomba, 58 bomba: $scope.notaPedido.bomba,
59 petrolera: $scope.notaPedido.petrolera, 59 petrolera: $scope.notaPedido.petrolera,
60 domicilio: $scope.notaPedido.domicilio, 60 domicilio: $scope.notaPedido.domicilio,
61 kilometros: $scope.notaPedido.kilometros, 61 kilometros: $scope.notaPedido.kilometros,
62 jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB, 62 jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB,
63 costoFinanciacion: $scope.notaPedido.costoFinanciacion, 63 costoFinanciacion: $scope.notaPedido.costoFinanciacion,
64 flete: $scope.notaPedido.flete, 64 flete: $scope.notaPedido.flete,
65 costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete 65 costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete
66 } 66 }
67 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 67 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
68 function(res) { 68 function(res) {
69 alert('Nota pedido creada'); 69 alert('Nota pedido creada');
70 $location.path('/venta-nota-pedido'); 70 $location.path('/venta-nota-pedido');
71 } 71 }
72 ) 72 )
73 var articulosNotaPedido = $scope.articulosTabla; 73 var articulosNotaPedido = $scope.articulosTabla;
74 for(var i = 0; i< articulosNotaPedido.length;i++) { 74 for(var i = 0; i< articulosNotaPedido.length;i++) {
75 crearNotaPedidoService.crearArticulosParaNotaPedido(articulosNotaPedido[i]).then( 75 crearNotaPedidoService.crearArticulosParaNotaPedido(articulosNotaPedido[i]).then(
76 function(res) { 76 function(res) {
77 return; 77 return;
78 } 78 }
79 ) 79 )
80 } 80 }
81 81
82 } 82 }
83 $scope.siguienteTab = function() { 83 $scope.siguienteTab = function() {
84 $scope.active = 1; 84 $scope.active = 1;
85 } 85 }
86 $scope.seleccionarArticulo = function() { 86 $scope.seleccionarArticulo = function() {
87 if (idLista == undefined) { 87 if (idLista == undefined) {
88 alert('primero seleccione una lista de precio y condicion'); 88 alert('primero seleccione una lista de precio y condicion');
89 return; 89 return;
90 } 90 }
91 var modalInstance = $uibModal.open( 91 var modalInstance = $uibModal.open(
92 { 92 {
93 ariaLabelledBy: 'Busqueda de Productos', 93 ariaLabelledBy: 'Busqueda de Productos',
94 templateUrl: 'modal-busqueda-productos.html', 94 templateUrl: 'modal-busqueda-productos.html',
95 controller: 'modalBusquedaProductosCtrl', 95 controller: 'modalBusquedaProductosCtrl',
96 resolve: { idLista: function() { return idLista } }, 96 resolve: { idLista: function() { return idLista } },
97 size: 'lg' 97 size: 'lg'
98 } 98 }
99 ) 99 )
100 modalInstance.result.then( 100 modalInstance.result.then(
101 function(producto) { 101 function(producto) {
102 var newArt = 102 var newArt =
103 { 103 {
104 id: 0, 104 id: 0,
105 codigo: producto.FiltroSectorCodigo, 105 codigo: producto.FiltroSectorCodigo,
106 item: $scope.articulosTabla.length + 1, 106 item: $scope.articulosTabla.length + 1,
107 nombre: producto.descripcion, 107 nombre: producto.descripcion,
108 precio: producto.precio, 108 precio: producto.precio,
109 costoUnitario: producto.costo, 109 costoUnitario: producto.costo,
110 cantidad: 1 110 cantidad: 1
111 } 111 }
112 $scope.articulosTabla.unshift(newArt); 112 $scope.articulosTabla.unshift(newArt);
113 }, function() { 113 }, function() {
114 // funcion ejecutada cuando se cancela el modal 114 // funcion ejecutada cuando se cancela el modal
115 } 115 }
116 ); 116 );
117 } 117 }
118 $scope.seleccionarVendedor = function() { 118 $scope.seleccionarVendedor = function() {
119 var modalInstance = $uibModal.open( 119 var modalInstance = $uibModal.open(
120 { 120 {
121 ariaLabelledBy: 'Busqueda de Vendedores', 121 ariaLabelledBy: 'Busqueda de Vendedores',
122 templateUrl: 'modal-vendedores.html', 122 templateUrl: 'modal-vendedores.html',
123 controller: 'modalVendedoresCtrl', 123 controller: 'modalVendedoresCtrl',
124 size: 'lg' 124 size: 'lg'
125 } 125 }
126 ) 126 )
127 modalInstance.result.then( 127 modalInstance.result.then(
128 function(vendedor) { 128 function(vendedor) {
129 $scope.notaPedido.vendedor = vendedor.NomVen; 129 $scope.notaPedido.vendedor = vendedor.NomVen;
130 }, function() { 130 }, function() {
131 131
132 } 132 }
133 ); 133 );
134 } 134 }
135 $scope.seleccionarPetrolera = function() { 135 $scope.seleccionarPetrolera = function() {
136 var modalInstance = $uibModal.open( 136 var modalInstance = $uibModal.open(
137 { 137 {
138 ariaLabelledBy: 'Busqueda de Petrolera', 138 ariaLabelledBy: 'Busqueda de Petrolera',
139 templateUrl: 'modal-petroleras.html', 139 templateUrl: 'modal-petroleras.html',
140 controller: 'modalPetrolerasCtrl', 140 controller: 'modalPetrolerasCtrl',
141 size: 'lg' 141 size: 'lg'
142 } 142 }
143 ) 143 )
144 modalInstance.result.then( 144 modalInstance.result.then(
145 function(petrolera) { 145 function(petrolera) {
146 $scope.notaPedido.petrolera = petrolera.NOM; 146 $scope.notaPedido.petrolera = petrolera.NOM;
147 }, function() { 147 }, function() {
148 148
149 } 149 }
150 ); 150 );
151 } 151 }
152 $scope.seleccionarCliente = function() { 152 $scope.seleccionarCliente = function() {
153 var modalInstance = $uibModal.open( 153 var modalInstance = $uibModal.open(
154 { 154 {
155 ariaLabelledBy: 'Busqueda de Cliente', 155 ariaLabelledBy: 'Busqueda de Cliente',
156 templateUrl: 'foca-busqueda-cliente-modal.html', 156 templateUrl: 'foca-busqueda-cliente-modal.html',
157 controller: 'focaBusquedaClienteModalController', 157 controller: 'focaBusquedaClienteModalController',
158 size: 'lg' 158 size: 'lg'
159 } 159 }
160 ) 160 )
161 modalInstance.result.then( 161 modalInstance.result.then(
162 function(cliente) { 162 function(cliente) {
163 $scope.notaPedido.cliente = cliente.nom; 163 $scope.notaPedido.cliente = cliente.nom;
164 }, function() { 164 }, function() {
165 165
166 } 166 }
167 ); 167 );
168 } 168 }
169 $scope.obtenerDomicilios = function(id) { 169 $scope.obtenerDomicilios = function(id) {
170 crearNotaPedidoService.getDomicilios(id).then( 170 crearNotaPedidoService.getDomicilios(id).then(
171 function(res) { 171 function(res) {
172 $scope.notaPedido.domicilio = res.data; 172 $scope.notaPedido.domicilio = res.data;
173 } 173 }
174 ) 174 )
175 } 175 }
176 $scope.getSubTotal = function(item) { 176 $scope.getSubTotal = function(item) {
177 var subTotal = 0; 177 var subTotal = 0;
178 var array = $scope.articulosTabla.filter(a => a.item <= item); 178 var array = $scope.articulosTabla.filter(a => a.item <= item);
179 for (var i = 0; i < array.length; i++) { 179 for (var i = 0; i < array.length; i++) {
180 subTotal += array[i].precio * array[i].cantidad 180 subTotal += array[i].precio * array[i].cantidad
181 } 181 }
182 return subTotal.toFixed(2); 182 return subTotal.toFixed(2);
183 } 183 }
184 $scope.cargarArticulos = function() { 184 $scope.cargarArticulos = function() {
185 idLista = $scope.notaPedido.precioCondicion; 185 idLista = $scope.notaPedido.precioCondicion;
186 $scope.articulosTabla = []; 186 $scope.articulosTabla = [];
187 } 187 }
188 } 188 }
189 ] 189 ]
190 ) 190 )
191 .controller('notaPedidoListaCtrl', [ 191 .controller('notaPedidoListaCtrl', [
192 '$scope', 192 '$scope',
193 'crearNotaPedidoService', 193 'crearNotaPedidoService',
194 '$location', 194 '$location',
195 function($scope, crearNotaPedidoService, $location) { 195 function($scope, crearNotaPedidoService, $location) {
196 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 196 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
197 $scope.notaPedidos = datos.data; 197 $scope.notaPedidos = datos.data;
198 }); 198 });
199 $scope.editar = function(notaPedido) { 199 $scope.editar = function(notaPedido) {
200 crearNotaPedidoService.setNotaPedido(notaPedido); 200 crearNotaPedidoService.setNotaPedido(notaPedido);
201 $location.path('/venta-nota-pedido/abm/'); 201 $location.path('/venta-nota-pedido/abm/');
202 } 202 }
203 $scope.crearPedido = function() { 203 $scope.crearPedido = function() {
204 crearNotaPedidoService.clearNotaPedido();
204 $location.path('/venta-nota-pedido/abm/'); 205 $location.path('/venta-nota-pedido/abm/');
205 } 206 }
206 } 207 }
207 ]) 208 ])
208 209
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT',function($http, API_ENDPOINT) { 2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT',function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 var notaPedido; 4 var notaPedido;
5 return { 5 return {
6 crearNotaPedido: function(notaPedido) { 6 crearNotaPedido: function(notaPedido) {
7 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); 7 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido});
8 }, 8 },
9 obtenerNotaPedido: function() { 9 obtenerNotaPedido: function() {
10 return $http.get(route +'/nota-pedido'); 10 return $http.get(route +'/nota-pedido');
11 }, 11 },
12 setNotaPedido: function(notaPedido) { 12 setNotaPedido: function(notaPedido) {
13 this.notaPedido = notaPedido; 13 this.notaPedido = notaPedido;
14 }, 14 },
15 clearNotaPedido: function() {
16 this.notaPedido = undefined;
17 },
15 getNotaPedido: function() { 18 getNotaPedido: function() {
16 return this.notaPedido; 19 return this.notaPedido;
17 }, 20 },
18 getArticulosByIdNotaPedido: function(id) { 21 getArticulosByIdNotaPedido: function(id) {
19 return $http.get(route+'/articulos/nota-pedido/'+id); 22 return $http.get(route+'/articulos/nota-pedido/'+id);
20 }, 23 },
21 crearArticulosParaNotaPedido: function(articuloNotaPedido) { 24 crearArticulosParaNotaPedido: function(articuloNotaPedido) {
22 return $http.post(route + '/articulos/nota-pedido', {articuloNotaPedido}); 25 return $http.post(route + '/articulos/nota-pedido', {articuloNotaPedido});
23 }, 26 },
24 getDomiciliosByIdNotaPedido: function(id) { 27 getDomiciliosByIdNotaPedido: function(id) {
25 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 28 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
26 }, 29 },
27 //EN DESARROLLO 30 //EN DESARROLLO
28 getDomicilios: function(id) { 31 getDomicilios: function(id) {
29 // return $http.get(route + '/'+id) 32 // return $http.get(route + '/'+id)
30 var domicilio = [ 33 var domicilio = [
31 { 34 {
32 id: 1, 35 id: 1,
33 dom: 'RISSO PATRON 781' 36 dom: 'RISSO PATRON 781'
34 }, 37 },
35 { 38 {
36 id: 2, 39 id: 2,
37 dom: 'MARIANO MORENO 533' 40 dom: 'MARIANO MORENO 533'
38 }, 41 },
39 { 42 {
40 id: 3, 43 id: 3,
41 dom: 'SALTA 796' 44 dom: 'SALTA 796'
42 } 45 }
43 ] 46 ]
44 return domicilio; 47 return domicilio;
45 }, 48 },
46 getPrecioCondicion: function() { 49 getPrecioCondicion: function() {
47 return $http.get(route + '/precio-condicion') 50 return $http.get(route + '/precio-condicion')
48 }, 51 },
49 getPrecioCondicionById: function(id) { 52 getPrecioCondicionById: function(id) {
50 return $http.get(route + '/precio-condicion/' + id) 53 return $http.get(route + '/precio-condicion/' + id)
51 }, 54 },
52 getPlazoPagoByPrecioCondicion: function(id) { 55 getPlazoPagoByPrecioCondicion: function(id) {
53 return $http.get(route + '/plazo-pago/precio-condicion/'+ id) 56 return $http.get(route + '/plazo-pago/precio-condicion/'+ id)
54 } 57 }
55 } 58 }
56 }]) 59 }])
57 60