Commit e0bcd2abf4a19f91250d2a34a6414099345f5caa
1 parent
e50a0127bf
Exists in
master
función para abrir modal en el controlador
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') | 1 | angular.module('focaCrearNotaPedido') |
2 | .controller('notaPedidoCtrl', | 2 | .controller('notaPedidoCtrl', |
3 | ['$scope', '$uibModal', '$location', 'crearNotaPedidoService', | 3 | ['$scope', '$uibModal', '$location', 'crearNotaPedidoService', |
4 | function($scope, $uibModal, $location, crearNotaPedidoService) { | 4 | function($scope, $uibModal, $location, crearNotaPedidoService) { |
5 | $scope.show = false; | 5 | $scope.show = false; |
6 | 6 | ||
7 | $scope.dateOptions = { | 7 | $scope.dateOptions = { |
8 | maxDate: new Date(), | 8 | maxDate: new Date(), |
9 | minDate: new Date(2010,0,1) | 9 | minDate: new Date(2010,0,1) |
10 | }; | 10 | }; |
11 | 11 | ||
12 | $scope.notaPedido = {}; | 12 | $scope.notaPedido = {}; |
13 | $scope.articulosTabla = []; | 13 | $scope.articulosTabla = []; |
14 | var idLista; | 14 | var idLista; |
15 | var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); | 15 | var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); |
16 | $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1); | 16 | $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1); |
17 | crearNotaPedidoService.getPrecioCondicion().then( | 17 | crearNotaPedidoService.getPrecioCondicion().then( |
18 | function(res) { | 18 | function(res) { |
19 | $scope.precioCondiciones = res.data; | 19 | $scope.precioCondiciones = res.data; |
20 | } | 20 | } |
21 | ); | 21 | ); |
22 | if (notaPedidoTemp !== undefined) { | 22 | if (notaPedidoTemp !== undefined) { |
23 | notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); | 23 | notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); |
24 | $scope.notaPedido = notaPedidoTemp; | 24 | $scope.notaPedido = notaPedidoTemp; |
25 | $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); | 25 | $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); |
26 | $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); | 26 | $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); |
27 | idLista = $scope.notaPedido.precioCondicion; | 27 | idLista = $scope.notaPedido.precioCondicion; |
28 | crearNotaPedidoService | 28 | crearNotaPedidoService |
29 | .getArticulosByIdNotaPedido($scope.notaPedido.id).then( | 29 | .getArticulosByIdNotaPedido($scope.notaPedido.id).then( |
30 | function(res) { | 30 | function(res) { |
31 | $scope.articulosTabla = res.data; | 31 | $scope.articulosTabla = res.data; |
32 | } | 32 | } |
33 | ); | 33 | ); |
34 | crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( | 34 | crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( |
35 | function(res) { | 35 | function(res) { |
36 | $scope.notaPedido.domicilio = res.data; | 36 | $scope.notaPedido.domicilio = res.data; |
37 | } | 37 | } |
38 | ); | 38 | ); |
39 | } else { | 39 | } else { |
40 | $scope.notaPedido.fechaCarga = new Date(); | 40 | $scope.notaPedido.fechaCarga = new Date(); |
41 | $scope.notaPedido.domicilio = [{ id: 0 }]; | 41 | $scope.notaPedido.domicilio = [{ id: 0 }]; |
42 | $scope.notaPedido.bomba = '1'; | 42 | $scope.notaPedido.bomba = '1'; |
43 | $scope.notaPedido.flete = '1'; | 43 | $scope.notaPedido.flete = '1'; |
44 | idLista = undefined; | 44 | idLista = undefined; |
45 | } | 45 | } |
46 | $scope.addNewDom = function() { | 46 | $scope.addNewDom = function() { |
47 | $scope.notaPedido.domicilio.push({ 'id': 0 }); | 47 | $scope.notaPedido.domicilio.push({ 'id': 0 }); |
48 | }; | 48 | }; |
49 | $scope.removeNewChoice = function(choice) { | 49 | $scope.removeNewChoice = function(choice) { |
50 | if ($scope.notaPedido.domicilio.length > 1) { | 50 | if ($scope.notaPedido.domicilio.length > 1) { |
51 | $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( | 51 | $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( |
52 | function(c) { | 52 | function(c) { |
53 | return c.$$hashKey === choice.$$hashKey; | 53 | return c.$$hashKey === choice.$$hashKey; |
54 | } | 54 | } |
55 | ), 1); | 55 | ), 1); |
56 | } | 56 | } |
57 | }; | 57 | }; |
58 | $scope.crearNotaPedido = function() { | 58 | $scope.crearNotaPedido = function() { |
59 | var notaPedido = { | 59 | var notaPedido = { |
60 | id: 0, | 60 | id: 0, |
61 | precioCondicion: $scope.notaPedido.precioCondicion, | 61 | precioCondicion: $scope.notaPedido.precioCondicion, |
62 | fechaCarga: $scope.notaPedido.fechaCarga, | 62 | fechaCarga: $scope.notaPedido.fechaCarga, |
63 | vendedor: $scope.notaPedido.vendedor, | 63 | vendedor: $scope.notaPedido.vendedor, |
64 | cliente: $scope.notaPedido.cliente, | 64 | cliente: $scope.notaPedido.cliente, |
65 | producto: $scope.notaPedido.producto, | 65 | producto: $scope.notaPedido.producto, |
66 | bomba: $scope.notaPedido.bomba, | 66 | bomba: $scope.notaPedido.bomba, |
67 | petrolera: $scope.notaPedido.petrolera, | 67 | petrolera: $scope.notaPedido.petrolera, |
68 | domicilio: $scope.notaPedido.domicilio, | 68 | domicilio: $scope.notaPedido.domicilio, |
69 | kilometros: $scope.notaPedido.kilometros, | 69 | kilometros: $scope.notaPedido.kilometros, |
70 | jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB, | 70 | jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB, |
71 | costoFinanciacion: $scope.notaPedido.costoFinanciacion, | 71 | costoFinanciacion: $scope.notaPedido.costoFinanciacion, |
72 | flete: $scope.notaPedido.flete, | 72 | flete: $scope.notaPedido.flete, |
73 | costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete, | 73 | costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete, |
74 | total: $scope.articulosTabla[0].subTotal | 74 | total: $scope.articulosTabla[0].subTotal |
75 | }; | 75 | }; |
76 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 76 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
77 | function() { | 77 | function() { |
78 | alert('Nota pedido creada'); | 78 | alert('Nota pedido creada'); |
79 | $location.path('/venta-nota-pedido'); | 79 | $location.path('/venta-nota-pedido'); |
80 | } | 80 | } |
81 | ); | 81 | ); |
82 | var articulosNotaPedido = $scope.articulosTabla; | 82 | var articulosNotaPedido = $scope.articulosTabla; |
83 | for(var i = 0; i< articulosNotaPedido.length;i++) { | 83 | for(var i = 0; i< articulosNotaPedido.length;i++) { |
84 | crearNotaPedidoService | 84 | crearNotaPedidoService |
85 | .crearArticulosParaNotaPedido(articulosNotaPedido[i]).then( | 85 | .crearArticulosParaNotaPedido(articulosNotaPedido[i]).then( |
86 | function() { | 86 | function() { |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | ); | 89 | ); |
90 | } | 90 | } |
91 | 91 | ||
92 | }; | 92 | }; |
93 | $scope.siguienteTab = function() { | 93 | $scope.siguienteTab = function() { |
94 | $scope.active = 1; | 94 | $scope.active = 1; |
95 | }; | 95 | }; |
96 | $scope.seleccionarArticulo = function() { | 96 | $scope.seleccionarArticulo = function() { |
97 | if (idLista === undefined) { | 97 | if (idLista === undefined) { |
98 | alert('primero seleccione una lista de precio y condicion'); | 98 | alert('primero seleccione una lista de precio y condicion'); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | var modalInstance = $uibModal.open( | 101 | var modalInstance = $uibModal.open( |
102 | { | 102 | { |
103 | ariaLabelledBy: 'Busqueda de Productos', | 103 | ariaLabelledBy: 'Busqueda de Productos', |
104 | templateUrl: 'modal-busqueda-productos.html', | 104 | templateUrl: 'modal-busqueda-productos.html', |
105 | controller: 'modalBusquedaProductosCtrl', | 105 | controller: 'modalBusquedaProductosCtrl', |
106 | resolve: { idLista: function() { return idLista; } }, | 106 | resolve: { idLista: function() { return idLista; } }, |
107 | size: 'lg' | 107 | size: 'lg' |
108 | } | 108 | } |
109 | ); | 109 | ); |
110 | modalInstance.result.then( | 110 | modalInstance.result.then( |
111 | function(producto) { | 111 | function(producto) { |
112 | var newArt = | 112 | var newArt = |
113 | { | 113 | { |
114 | id: 0, | 114 | id: 0, |
115 | codigo: producto.FiltroSectorCodigo, | 115 | codigo: producto.FiltroSectorCodigo, |
116 | item: $scope.articulosTabla.length + 1, | 116 | item: $scope.articulosTabla.length + 1, |
117 | nombre: producto.descripcion, | 117 | nombre: producto.descripcion, |
118 | precio: producto.precio, | 118 | precio: producto.precio, |
119 | costoUnitario: producto.costo, | 119 | costoUnitario: producto.costo, |
120 | cantidad: 1 | 120 | cantidad: 1 |
121 | }; | 121 | }; |
122 | $scope.articulosTabla.unshift(newArt); | 122 | $scope.articulosTabla.unshift(newArt); |
123 | }, function() { | 123 | }, function() { |
124 | // funcion ejecutada cuando se cancela el modal | 124 | // funcion ejecutada cuando se cancela el modal |
125 | } | 125 | } |
126 | ); | 126 | ); |
127 | }; | 127 | }; |
128 | $scope.seleccionarVendedor = function() { | 128 | $scope.seleccionarVendedor = function() { |
129 | var modalInstance = $uibModal.open( | 129 | var modalInstance = $uibModal.open( |
130 | { | 130 | { |
131 | ariaLabelledBy: 'Busqueda de Vendedores', | 131 | ariaLabelledBy: 'Busqueda de Vendedores', |
132 | templateUrl: 'modal-vendedores.html', | 132 | templateUrl: 'modal-vendedores.html', |
133 | controller: 'modalVendedoresCtrl', | 133 | controller: 'modalVendedoresCtrl', |
134 | size: 'lg' | 134 | size: 'lg' |
135 | } | 135 | } |
136 | ); | 136 | ); |
137 | modalInstance.result.then( | 137 | modalInstance.result.then( |
138 | function(vendedor) { | 138 | function(vendedor) { |
139 | $scope.notaPedido.vendedor = vendedor.NomVen; | 139 | $scope.notaPedido.vendedor = vendedor.NomVen; |
140 | }, function() { | 140 | }, function() { |
141 | 141 | ||
142 | } | 142 | } |
143 | ); | 143 | ); |
144 | }; | 144 | }; |
145 | $scope.seleccionarPetrolera = function() { | 145 | $scope.seleccionarPetrolera = function() { |
146 | var modalInstance = $uibModal.open( | 146 | var modalInstance = $uibModal.open( |
147 | { | 147 | { |
148 | ariaLabelledBy: 'Busqueda de Petrolera', | 148 | ariaLabelledBy: 'Busqueda de Petrolera', |
149 | templateUrl: 'modal-petroleras.html', | 149 | templateUrl: 'modal-petroleras.html', |
150 | controller: 'modalPetrolerasCtrl', | 150 | controller: 'modalPetrolerasCtrl', |
151 | size: 'lg' | 151 | size: 'lg' |
152 | } | 152 | } |
153 | ); | 153 | ); |
154 | modalInstance.result.then( | 154 | modalInstance.result.then( |
155 | function(petrolera) { | 155 | function(petrolera) { |
156 | $scope.notaPedido.petrolera = petrolera.NOM; | 156 | $scope.notaPedido.petrolera = petrolera.NOM; |
157 | }, function() { | 157 | }, function() { |
158 | 158 | ||
159 | } | 159 | } |
160 | ); | 160 | ); |
161 | }; | 161 | }; |
162 | $scope.seleccionarCliente = function() { | 162 | $scope.seleccionarCliente = function() { |
163 | var modalInstance = $uibModal.open( | 163 | var modalInstance = $uibModal.open( |
164 | { | 164 | { |
165 | ariaLabelledBy: 'Busqueda de Cliente', | 165 | ariaLabelledBy: 'Busqueda de Cliente', |
166 | templateUrl: 'foca-busqueda-cliente-modal.html', | 166 | templateUrl: 'foca-busqueda-cliente-modal.html', |
167 | controller: 'focaBusquedaClienteModalController', | 167 | controller: 'focaBusquedaClienteModalController', |
168 | size: 'lg' | 168 | size: 'lg' |
169 | } | 169 | } |
170 | ); | 170 | ); |
171 | modalInstance.result.then( | 171 | modalInstance.result.then( |
172 | function(cliente) { | 172 | function(cliente) { |
173 | $scope.notaPedido.cliente = cliente.nom; | 173 | $scope.notaPedido.cliente = cliente.nom; |
174 | }, function() { | 174 | }, function() { |
175 | 175 | ||
176 | } | 176 | } |
177 | ); | 177 | ); |
178 | }; | 178 | }; |
179 | $scope.obtenerDomicilios = function(id) { | 179 | $scope.obtenerDomicilios = function(id) { |
180 | crearNotaPedidoService.getDomicilios(id).then( | 180 | crearNotaPedidoService.getDomicilios(id).then( |
181 | function(res) { | 181 | function(res) { |
182 | $scope.notaPedido.domicilio = res.data; | 182 | $scope.notaPedido.domicilio = res.data; |
183 | } | 183 | } |
184 | ); | 184 | ); |
185 | }; | 185 | }; |
186 | $scope.getSubTotal = function(item) { | 186 | $scope.getSubTotal = function(item) { |
187 | var subTotal = 0; | 187 | var subTotal = 0; |
188 | var array = $scope.articulosTabla.filter( | 188 | var array = $scope.articulosTabla.filter( |
189 | function(a) { | 189 | function(a) { |
190 | return a.item <= item; | 190 | return a.item <= item; |
191 | } | 191 | } |
192 | ); | 192 | ); |
193 | for (var i = 0; i < array.length; i++) { | 193 | for (var i = 0; i < array.length; i++) { |
194 | subTotal += array[i].precio * array[i].cantidad; | 194 | subTotal += array[i].precio * array[i].cantidad; |
195 | } | 195 | } |
196 | return subTotal.toFixed(2); | 196 | return subTotal.toFixed(2); |
197 | }; | 197 | }; |
198 | $scope.cargarArticulos = function() { | 198 | $scope.cargarArticulos = function() { |
199 | idLista = $scope.notaPedido.precioCondicion; | 199 | idLista = $scope.notaPedido.precioCondicion; |
200 | $scope.articulosTabla = []; | 200 | $scope.articulosTabla = []; |
201 | }; | 201 | }; |
202 | $scope.abrirModalListaPrecio = function() { | ||
203 | var modalInstance = $uibModal.open( | ||
204 | { | ||
205 | ariaLabelledBy: 'Busqueda de Precio Condición', | ||
206 | templateUrl: 'modal-precio-condicion.html', | ||
207 | controller: 'focaModalPrecioCondicionController', | ||
208 | size: 'lg' | ||
209 | } | ||
210 | ); | ||
211 | modalInstance.result.then( | ||
212 | function(precioCondicion) { | ||
213 | $scope.notaPedido.precioCondicion = precioCondicion.nombre; | ||
214 | }, function() { | ||
215 | |||
216 | } | ||
217 | ); | ||
218 | }; | ||
202 | } | 219 | } |
203 | ] | 220 | ] |
204 | ) | 221 | ) |
205 | .controller('notaPedidoListaCtrl', [ | 222 | .controller('notaPedidoListaCtrl', [ |
206 | '$scope', | 223 | '$scope', |
207 | 'crearNotaPedidoService', | 224 | 'crearNotaPedidoService', |
208 | '$location', | 225 | '$location', |
209 | function($scope, crearNotaPedidoService, $location) { | 226 | function($scope, crearNotaPedidoService, $location) { |
210 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 227 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
211 | $scope.notaPedidos = datos.data; | 228 | $scope.notaPedidos = datos.data; |
212 | }); | 229 | }); |
213 | $scope.editar = function(notaPedido) { | 230 | $scope.editar = function(notaPedido) { |
214 | crearNotaPedidoService.setNotaPedido(notaPedido); | 231 | crearNotaPedidoService.setNotaPedido(notaPedido); |
215 | $location.path('/venta-nota-pedido/abm/'); | 232 | $location.path('/venta-nota-pedido/abm/'); |
216 | }; | 233 | }; |
217 | $scope.crearPedido = function() { | 234 | $scope.crearPedido = function() { |
218 | crearNotaPedidoService.clearNotaPedido(); | 235 | crearNotaPedidoService.clearNotaPedido(); |
219 | $location.path('/venta-nota-pedido/abm/'); | 236 | $location.path('/venta-nota-pedido/abm/'); |
220 | }; | 237 | }; |
221 | } | 238 | } |
222 | ]); | 239 | ]); |
223 | 240 |