Commit 68d481eac1dbf29227fc1c4572a1d8d95e511c18
Exists in
master
Merge branch 'master' of https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido
# Conflicts: # src/js/controller.js
Showing
2 changed files
Show diff stats
src/js/controller.js
... | ... | @@ -7,17 +7,22 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
7 | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService |
8 | 8 | ) { |
9 | 9 | $scope.botonera = [ |
10 | - {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, | |
11 | - {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, | |
12 | - {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, | |
13 | - {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, | |
14 | - { | |
15 | - texto: 'Precios y condiciones', | |
16 | - accion: function() {$scope.abrirModalListaPrecio();}}, | |
17 | - {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, | |
10 | + {texto: 'Vendedor', accion: function() { | |
11 | + validarNotaRemitada($scope.seleccionarVendedor);}}, | |
12 | + {texto: 'Cliente', accion: function() { | |
13 | + validarNotaRemitada($scope.seleccionarCliente);}}, | |
14 | + {texto: 'Proveedor', accion: function() { | |
15 | + validarNotaRemitada($scope.seleccionarProveedor);}}, | |
16 | + {texto: 'Moneda', accion: function() { | |
17 | + validarNotaRemitada($scope.abrirModalMoneda);}}, | |
18 | + {texto: 'Precios y condiciones', accion: function() { | |
19 | + validarNotaRemitada($scope.abrirModalListaPrecio);}}, | |
20 | + {texto: 'Flete', accion: function() { | |
21 | + validarNotaRemitada($scope.abrirModalFlete);}}, | |
18 | 22 | {texto: '', accion: function() {}}, |
19 | 23 | {texto: '', accion: function() {}} |
20 | 24 | ]; |
25 | + | |
21 | 26 | $scope.datepickerAbierto = false; |
22 | 27 | |
23 | 28 | $scope.show = false; |
... | ... | @@ -28,6 +33,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
28 | 33 | }; |
29 | 34 | |
30 | 35 | $scope.notaPedido = { |
36 | + id: 0, | |
31 | 37 | vendedor: {}, |
32 | 38 | cliente: {}, |
33 | 39 | proveedor: {}, |
... | ... | @@ -38,13 +44,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
38 | 44 | var monedaPorDefecto; |
39 | 45 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
40 | 46 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
41 | - monedaPorDefecto = { | |
42 | - id: res.data[0].ID, | |
43 | - detalle: res.data[0].DETALLE, | |
44 | - simbolo: res.data[0].SIMBOLO, | |
45 | - cotizaciones: res.data[0].cotizaciones | |
46 | - }; | |
47 | - addCabecera('Moneda:', monedaPorDefecto.detalle); | |
47 | + monedaPorDefecto = res.data[0]; | |
48 | + addCabecera('Moneda:', monedaPorDefecto.DETALLE); | |
48 | 49 | addCabecera('Fecha cotizacion:', |
49 | 50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); |
50 | 51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); |
... | ... | @@ -120,16 +121,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
120 | 121 | // }; |
121 | 122 | |
122 | 123 | $scope.crearNotaPedido = function() { |
123 | - if(!$scope.notaPedido.vendedor.codigo) { | |
124 | + if(!$scope.notaPedido.vendedor.CodVen) { | |
124 | 125 | focaModalService.alert('Ingrese Vendedor'); |
125 | 126 | return; |
126 | - } else if(!$scope.notaPedido.cliente.cod) { | |
127 | + } else if(!$scope.notaPedido.cliente.COD) { | |
127 | 128 | focaModalService.alert('Ingrese Cliente'); |
128 | 129 | return; |
129 | - } else if(!$scope.notaPedido.proveedor.codigo) { | |
130 | + } else if(!$scope.notaPedido.proveedor.COD) { | |
130 | 131 | focaModalService.alert('Ingrese Proveedor'); |
131 | 132 | return; |
132 | - } else if(!$scope.notaPedido.moneda.id) { | |
133 | + } else if(!$scope.notaPedido.moneda.ID) { | |
133 | 134 | focaModalService.alert('Ingrese Moneda'); |
134 | 135 | return; |
135 | 136 | } else if(!$scope.notaPedido.cotizacion.ID) { |
... | ... | @@ -143,7 +144,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
143 | 144 | { |
144 | 145 | focaModalService.alert('Ingrese Flete'); |
145 | 146 | return; |
146 | - } else if(!$scope.notaPedido.domicilio.id) { | |
147 | + } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | |
147 | 148 | focaModalService.alert('Ingrese Domicilio'); |
148 | 149 | return; |
149 | 150 | } else if($scope.articulosTabla.length === 0) { |
... | ... | @@ -152,14 +153,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
152 | 153 | } |
153 | 154 | var date = new Date(); |
154 | 155 | var notaPedido = { |
155 | - id: 0, | |
156 | + id: $scope.notaPedido.id, | |
156 | 157 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
157 | 158 | .toISOString().slice(0, 19).replace('T', ' '), |
158 | - idVendedor: $scope.notaPedido.vendedor.codigo, | |
159 | - idCliente: $scope.notaPedido.cliente.cod, | |
160 | - nombreCliente: $scope.notaPedido.cliente.nom, | |
161 | - cuitCliente: $scope.notaPedido.cliente.cuit, | |
162 | - idProveedor: $scope.notaPedido.proveedor.codigo, | |
159 | + idVendedor: $scope.notaPedido.vendedor.CodVen, | |
160 | + idCliente: $scope.notaPedido.cliente.COD, | |
161 | + nombreCliente: $scope.notaPedido.cliente.NOM, | |
162 | + cuitCliente: $scope.notaPedido.cliente.CUIT, | |
163 | + idProveedor: $scope.notaPedido.proveedor.COD, | |
163 | 164 | idDomicilio: $scope.notaPedido.domicilio.id, |
164 | 165 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
165 | 166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
... | ... | @@ -206,6 +207,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
206 | 207 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
207 | 208 | ); |
208 | 209 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
210 | + crearNotaPedidoService.getNumeroNotaPedido().then( | |
211 | + function(res) { | |
212 | + $scope.puntoVenta = rellenar(res.data.sucursal, 4); | |
213 | + $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | |
214 | + }, | |
215 | + function(err) { | |
216 | + focaModalService.alert('La terminal no esta configurada correctamente'); | |
217 | + console.info(err); | |
218 | + } | |
219 | + ); | |
209 | 220 | $scope.notaPedido.vendedor = {}; |
210 | 221 | $scope.notaPedido.cliente = {}; |
211 | 222 | $scope.notaPedido.proveedor = {}; |
... | ... | @@ -222,7 +233,112 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
222 | 233 | } |
223 | 234 | ); |
224 | 235 | }; |
236 | + | |
237 | + $scope.seleccionarNotaPedido = function() { | |
238 | + var modalInstance = $uibModal.open( | |
239 | + { | |
240 | + ariaLabelledBy: 'Busqueda de Nota de Pedido', | |
241 | + templateUrl: 'foca-modal-nota-pedido.html', | |
242 | + controller: 'focaModalNotaPedidoController', | |
243 | + size: 'lg', | |
244 | + resolve: {usadoPor: 'notaPedido'} | |
245 | + } | |
246 | + ); | |
247 | + modalInstance.result.then( | |
248 | + function(notaPedido) { | |
249 | + //añado cabeceras | |
250 | + $scope.notaPedido.id = notaPedido.id; | |
251 | + removeCabecera('Moneda:'); | |
252 | + removeCabecera('Fecha cotizacion:'); | |
253 | + removeCabecera('Cotizacion:'); | |
254 | + var cabeceras = [ | |
255 | + { | |
256 | + label: 'Moneda', | |
257 | + valor: notaPedido.cotizacion[0].moneda[0].DETALLE | |
258 | + }, | |
259 | + { | |
260 | + label: 'Fecha cotizacion', | |
261 | + valor: $filter('date')(notaPedido.cotizacion[0].FECHA, | |
262 | + 'dd/MM/yyyy') | |
263 | + }, | |
264 | + { | |
265 | + label: 'Cotizacion', | |
266 | + valor: notaPedido.cotizacion[0].VENDEDOR | |
267 | + }, | |
268 | + { | |
269 | + label: 'Cliente:', | |
270 | + valor: notaPedido.cliente[0].NOM | |
271 | + }, | |
272 | + { | |
273 | + label: 'Domicilio:', | |
274 | + valor: notaPedido.domicilioStamp | |
275 | + }, | |
276 | + { | |
277 | + label: 'Vendedor:', | |
278 | + valor: notaPedido.vendedor[0].NomVen | |
279 | + }, | |
280 | + { | |
281 | + label: 'Proveedor:', | |
282 | + valor: notaPedido.proveedor[0].NOM | |
283 | + }, | |
284 | + { | |
285 | + label: 'Flete:', | |
286 | + valor: notaPedido.flete === 1 ? 'Si' : 'No' | |
287 | + }, | |
288 | + { | |
289 | + label: 'FOB:', | |
290 | + valor: notaPedido.fob === 1 ? 'Si' : 'No' | |
291 | + }, | |
292 | + { | |
293 | + label: 'Precio condicion:', | |
294 | + valor: valorPrecioCondicion() | |
295 | + } | |
296 | + ]; | |
297 | + //TODO MOSTRAR PLAZOS | |
298 | + function valorPrecioCondicion() { | |
299 | + if(notaPedido.idPrecioCondicion > 0) { | |
300 | + return notaPedido.precioCondicion[0].nombre; | |
301 | + } else { | |
302 | + return 'Ingreso Manual'; | |
303 | + } | |
304 | + } | |
305 | + | |
306 | + if(notaPedido.flete === 1) { | |
307 | + var cabeceraBomba = { | |
308 | + label: 'Bomba', | |
309 | + valor: notaPedido.bomba === 1 ? 'Si' : 'No' | |
310 | + }; | |
311 | + if(notaPedido.kilometros) { | |
312 | + var cabeceraKilometros = { | |
313 | + label: 'Kilometros', | |
314 | + valor: notaPedido.kilometros | |
315 | + }; | |
316 | + cabeceras.push(cabeceraKilometros); | |
317 | + } | |
318 | + cabeceras.push(cabeceraBomba); | |
319 | + } | |
320 | + $scope.articulosTabla = notaPedido.articulosNotaPedido; | |
321 | + if(notaPedido.precioCondicion.length > 0) { | |
322 | + $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; | |
323 | + } else { | |
324 | + $scope.idLista = -1; | |
325 | + } | |
326 | + $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | |
327 | + $scope.notaPedido = notaPedido; | |
328 | + $scope.notaPedido.vendedor = notaPedido.vendedor[0]; | |
329 | + $scope.notaPedido.cliente = notaPedido.cliente[0]; | |
330 | + $scope.notaPedido.proveedor = notaPedido.proveedor[0]; | |
331 | + $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; | |
332 | + $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; | |
333 | + $scope.plazosPagos = notaPedido.plazoPago; | |
334 | + addArrayCabecera(cabeceras); | |
225 | 335 | |
336 | + }, function() { | |
337 | + // funcion ejecutada cuando se cancela el modal | |
338 | + } | |
339 | + ); | |
340 | + } | |
341 | + | |
226 | 342 | $scope.seleccionarArticulo = function() { |
227 | 343 | if ($scope.idLista === undefined) { |
228 | 344 | focaModalService.alert( |
... | ... | @@ -289,7 +405,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
289 | 405 | modalInstance.result.then( |
290 | 406 | function(vendedor) { |
291 | 407 | addCabecera('Vendedor:', vendedor.NomVen); |
292 | - $scope.notaPedido.vendedor.codigo = vendedor.CodVen; | |
408 | + $scope.notaPedido.vendedor = vendedor; | |
293 | 409 | }, function() { |
294 | 410 | |
295 | 411 | } |
... | ... | @@ -312,7 +428,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
312 | 428 | ); |
313 | 429 | modalInstance.result.then( |
314 | 430 | function(proveedor) { |
315 | - $scope.notaPedido.proveedor.codigo = proveedor.COD; | |
431 | + $scope.notaPedido.proveedor = proveedor; | |
316 | 432 | addCabecera('Proveedor:', proveedor.NOM); |
317 | 433 | }, function() { |
318 | 434 | |
... | ... | @@ -351,8 +467,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
351 | 467 | ); |
352 | 468 | modalInstanceDomicilio.result.then( |
353 | 469 | function(domicilio) { |
354 | - $scope.notaPedido.domicilio.id = domicilio.id; | |
355 | - $scope.notaPedido.cliente = cliente; | |
470 | + $scope.notaPedido.domicilio = domicilio; | |
471 | + $scope.notaPedido.cliente = { | |
472 | + COD: cliente.cod, | |
473 | + CUIT: cliente.cuit, | |
474 | + NOM: cliente.nom | |
475 | + }; | |
356 | 476 | addCabecera('Cliente:', cliente.nom); |
357 | 477 | var domicilioStamp = |
358 | 478 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
... | ... | @@ -515,11 +635,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
515 | 635 | cotizacion.VENDEDOR; |
516 | 636 | } |
517 | 637 | $scope.articulosTabla = articulosTablaTemp; |
518 | - $scope.notaPedido.moneda = { | |
519 | - id: moneda.ID, | |
520 | - detalle: moneda.DETALLE, | |
521 | - simbolo: moneda.SIMBOLO | |
522 | - }; | |
638 | + $scope.notaPedido.moneda = moneda; | |
523 | 639 | $scope.notaPedido.cotizacion = cotizacion; |
524 | 640 | addCabecera('Moneda:', moneda.DETALLE); |
525 | 641 | addCabecera( |
... | ... | @@ -622,6 +738,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
622 | 738 | articulo.cantidad = parseFloat(articulo.cantidad); |
623 | 739 | articulo.precio = parseFloat(articulo.precio); |
624 | 740 | }; |
741 | + | |
742 | + function addArrayCabecera(array) { | |
743 | + for(var i = 0; i < array.length; i++) { | |
744 | + addCabecera(array[i].label, array[i].valor); | |
745 | + } | |
746 | + } | |
625 | 747 | |
626 | 748 | function addCabecera(label, valor) { |
627 | 749 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
... | ... | @@ -647,6 +769,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
647 | 769 | |
648 | 770 | return relleno; |
649 | 771 | } |
772 | + | |
773 | + function validarNotaRemitada(funcion) { | |
774 | + if($scope.notaPedido.idRemito) { | |
775 | + focaModalService.alert('No se puede editar una nota de pedido remitada'); | |
776 | + } | |
777 | + else { | |
778 | + funcion(); | |
779 | + } | |
780 | + } | |
650 | 781 | } |
651 | 782 | ] |
652 | 783 | ) |
src/views/nota-pedido.html
... | ... | @@ -10,6 +10,13 @@ |
10 | 10 | </div> |
11 | 11 | <div class="col-5 col-sm-4 numero-pedido" |
12 | 12 | >Nº {{puntoVenta}}-{{comprobante}} |
13 | + <button | |
14 | + class="btn btn-xs btn-outline-dark" | |
15 | + type="button" | |
16 | + ng-click="seleccionarNotaPedido()" | |
17 | + > | |
18 | + <i class="fa fa-search"></i> | |
19 | + </button> | |
13 | 20 | </div> |
14 | 21 | <div class="col-7 col-sm-4 text-right"> |
15 | 22 | Fecha: |