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