Commit f5af55e1d304c16a64d65e7b9aaa3adb17e12e37
1 parent
7c0585b502
Exists in
master
refactor guardar todo de una sola vez
Showing
2 changed files
with
51 additions
and
67 deletions
Show diff stats
src/js/businessService.js
| 1 | 1 | angular.module('focaCrearRemito') |
| 2 | - .factory('remitoBusinessService', [ | |
| 3 | - 'crearRemitoService', | |
| 4 | - function(crearRemitoService) { | |
| 2 | + .factory('remitoBusinessService', ['crearRemitoService', 'focaModalService', | |
| 3 | + function(crearRemitoService, focaModalService) { | |
| 5 | 4 | return { |
| 6 | - addArticulos: function(articulosRemito, idRemito, cotizacion) { | |
| 5 | + quitarCotizacion: function(articulosRemito, cotizacion) { | |
| 6 | + | |
| 7 | 7 | for(var i = 0; i < articulosRemito.length; i++) { |
| 8 | + | |
| 8 | 9 | delete articulosRemito[i].editCantidad; |
| 9 | 10 | delete articulosRemito[i].editPrecio; |
| 10 | - articulosRemito[i].idRemito = articulosRemito[i].idRemito !== -1 ? | |
| 11 | - idRemito : articulosRemito[i].idRemito; | |
| 12 | - articulosRemito[i].precio = articulosRemito[i].precio * cotizacion; | |
| 13 | 11 | delete articulosRemito[i].idNotaPedido; |
| 14 | - crearRemitoService.crearArticulosParaRemito(articulosRemito[i]); | |
| 12 | + | |
| 13 | + articulosRemito[i].precio = articulosRemito[i].precio * cotizacion; | |
| 15 | 14 | } |
| 15 | + | |
| 16 | + return articulosRemito; | |
| 17 | + | |
| 16 | 18 | }, |
| 17 | 19 | addEstado: function(idRemito, idVendedor) { |
| 18 | 20 | var date = new Date(); |
| 19 | 21 | var estado = { |
| 20 | 22 | idRemito: idRemito, |
| 21 | 23 | fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 22 | - .toISOString().slice(0, 19).replace('T', ' '), | |
| 24 | + .toISOString().slice(0, 19).replace('T', ' '), | |
| 23 | 25 | estado: 0, |
| 24 | 26 | idVendedor: idVendedor |
| 25 | 27 | }; |
| ... | ... | @@ -37,18 +39,45 @@ angular.module('focaCrearRemito') |
| 37 | 39 | } |
| 38 | 40 | return result.trim(); |
| 39 | 41 | }, |
| 40 | - addPuntosDescarga: function(idRemito, puntosDescarga) { | |
| 42 | + addPuntosDescarga: function(puntosDescarga) { | |
| 41 | 43 | |
| 42 | 44 | var puntos = []; |
| 43 | 45 | |
| 44 | 46 | puntosDescarga.forEach(function(punto) { |
| 45 | 47 | puntos.push({ |
| 46 | 48 | idPuntoDescarga: punto.puntoDescarga.id, |
| 47 | - idRemito: idRemito, | |
| 48 | 49 | }); |
| 49 | 50 | }); |
| 50 | 51 | |
| 51 | - return crearRemitoService.crearPuntosDescarga(puntos); | |
| 52 | + return puntos; | |
| 53 | + }, | |
| 54 | + validarRemito: function (remito, articulos) { | |
| 55 | + | |
| 56 | + if (!remito.vendedor.NUM) { | |
| 57 | + focaModalService.alert('Ingrese Vendedor'); | |
| 58 | + return false; | |
| 59 | + } else if (!remito.cliente.COD) { | |
| 60 | + focaModalService.alert('Ingrese Cliente'); | |
| 61 | + return false; | |
| 62 | + } else if (!remito.proveedor.COD) { | |
| 63 | + focaModalService.alert('Ingrese Proveedor'); | |
| 64 | + return false; | |
| 65 | + } else if (!remito.cotizacion.moneda.id && | |
| 66 | + !remito.cotizacion.moneda.ID) { | |
| 67 | + focaModalService.alert('Ingrese Moneda'); | |
| 68 | + return false; | |
| 69 | + } else if (!remito.cotizacion.ID) { | |
| 70 | + focaModalService.alert('Ingrese Cotizaciรณn'); | |
| 71 | + return false; | |
| 72 | + } else if (remito.flete === undefined || remito.flete === null) { | |
| 73 | + focaModalService.alert('Ingrese Flete'); | |
| 74 | + return false; | |
| 75 | + } else if (articulos.length === 0) { | |
| 76 | + focaModalService.alert('Debe cargar al menos un articulo'); | |
| 77 | + return false; | |
| 78 | + } | |
| 79 | + | |
| 80 | + return true; | |
| 52 | 81 | } |
| 53 | 82 | }; |
| 54 | 83 | }]); |
src/js/controller.js
| ... | ... | @@ -285,27 +285,9 @@ angular.module('focaCrearRemito').controller('remitoController', |
| 285 | 285 | }; |
| 286 | 286 | //validacion por domicilio y por plazo pago |
| 287 | 287 | $scope.crearRemito = function () { |
| 288 | - if (!$scope.remito.vendedor.NUM) { | |
| 289 | - focaModalService.alert('Ingrese Vendedor'); | |
| 290 | - return; | |
| 291 | - } else if (!$scope.remito.cliente.COD) { | |
| 292 | - focaModalService.alert('Ingrese Cliente'); | |
| 293 | - return; | |
| 294 | - } else if (!$scope.remito.proveedor.COD) { | |
| 295 | - focaModalService.alert('Ingrese Proveedor'); | |
| 296 | - return; | |
| 297 | - } else if (!$scope.remito.cotizacion.moneda.id && | |
| 298 | - !$scope.remito.cotizacion.moneda.ID) { | |
| 299 | - focaModalService.alert('Ingrese Moneda'); | |
| 300 | - return; | |
| 301 | - } else if (!$scope.remito.cotizacion.ID) { | |
| 302 | - focaModalService.alert('Ingrese Cotizaciรณn'); | |
| 303 | - return; | |
| 304 | - } else if ($scope.remito.flete === undefined || $scope.remito.flete === null) { | |
| 305 | - focaModalService.alert('Ingrese Flete'); | |
| 306 | - return; | |
| 307 | - } else if ($scope.articulosFiltro().length === 0) { | |
| 308 | - focaModalService.alert('Debe cargar al menos un articulo'); | |
| 288 | + | |
| 289 | + if (!remitoBusinessService.validarRemito($scope.remito, $scope.articulosFiltro())) | |
| 290 | + { | |
| 309 | 291 | return; |
| 310 | 292 | } |
| 311 | 293 | |
| ... | ... | @@ -358,7 +340,12 @@ angular.module('focaCrearRemito').controller('remitoController', |
| 358 | 340 | destinoVenta: 0,//TODO |
| 359 | 341 | operacionTipo: 0, //TODO |
| 360 | 342 | }, |
| 361 | - notaPedido: $scope.notaPedido | |
| 343 | + notaPedido: $scope.notaPedido, | |
| 344 | + articulos: remitoBusinessService.quitarCotizacion($scope.articulosFiltro(), | |
| 345 | + $scope.remito.cotizacion.VENDEDOR), | |
| 346 | + puntosDescarga: remitoBusinessService.addPuntosDescarga( | |
| 347 | + $scope.remito.remitoPuntoDescarga), | |
| 348 | + plazos: $scope.remito.remitoPlazo | |
| 362 | 349 | }; |
| 363 | 350 | crearRemitoService.crearRemito(save).then( |
| 364 | 351 | function (data) { |
| ... | ... | @@ -366,39 +353,16 @@ angular.module('focaCrearRemito').controller('remitoController', |
| 366 | 353 | focaBotoneraLateralService.endGuardar(true); |
| 367 | 354 | $scope.saveLoading = false; |
| 368 | 355 | |
| 369 | - $scope.remito.numeroRemito = data.data.numero; | |
| 370 | - | |
| 371 | - if ($scope.remito.remitoPuntoDescarga.length > 0) { | |
| 372 | - remitoBusinessService.addPuntosDescarga(data.data.id, | |
| 373 | - $scope.remito.remitoPuntoDescarga); | |
| 374 | - } | |
| 375 | - | |
| 376 | 356 | if (data.status === 500) { |
| 377 | 357 | focaModalService.alert(data.data); |
| 378 | 358 | return; |
| 379 | 359 | } |
| 380 | 360 | |
| 381 | - // TODO: updatear plazos | |
| 382 | - if ($scope.remito.id === 0) { | |
| 383 | - | |
| 384 | - remitoBusinessService.addArticulos($scope.remito.articulosRemito, | |
| 385 | - data.data.id, $scope.remito.cotizacion.VENDEDOR); | |
| 386 | - | |
| 387 | - var plazos = $scope.remito.remitoPlazo; | |
| 388 | - | |
| 389 | - for (var j = 0; j < plazos.length; j++) { | |
| 390 | - var json = { | |
| 391 | - idRemito: data.data.id, | |
| 392 | - dias: plazos[j].dias | |
| 393 | - }; | |
| 394 | - crearRemitoService.crearPlazosParaRemito(json); | |
| 395 | - } | |
| 396 | - } | |
| 397 | 361 | abrirModalMail(data.data.id, |
| 398 | 362 | $scope.remito.cliente, |
| 399 | 363 | $filter('comprobante')([ |
| 400 | 364 | $scope.puntoVenta, |
| 401 | - $scope.remito.numeroRemito | |
| 365 | + data.data.numero | |
| 402 | 366 | ]) |
| 403 | 367 | ); |
| 404 | 368 | |
| ... | ... | @@ -675,15 +639,6 @@ angular.module('focaCrearRemito').controller('remitoController', |
| 675 | 639 | if (domicilio.verPuntos) { |
| 676 | 640 | delete $scope.remito.domicilio.verPuntos; |
| 677 | 641 | $scope.seleccionarPuntosDeDescarga(); |
| 678 | - } else { | |
| 679 | - crearRemitoService | |
| 680 | - .getPuntosDescargaByClienDom(domicilio.id, | |
| 681 | - $scope.remito.cliente.COD) | |
| 682 | - .then(function (res) { | |
| 683 | - if (res.data.length) { | |
| 684 | - $scope.seleccionarPuntosDeDescarga(); | |
| 685 | - } | |
| 686 | - }); | |
| 687 | 642 | } |
| 688 | 643 | |
| 689 | 644 | $filter('filter')($scope.botonera, |