Commit 99dd25f66b64dc35b776cd73b230515d75c93457
1 parent
aed323a955
Exists in
master
función eliminar remitos de hoja ruta
Showing
1 changed file
with
23 additions
and
0 deletions
Show diff stats
src/js/controllerHojaRuta.js
1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
2 | .controller('focaModalCrearHojaRuta', [ | 2 | .controller('focaModalCrearHojaRuta', [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModalInstance', | 4 | '$uibModalInstance', |
5 | '$uibModal', | 5 | '$uibModal', |
6 | 'focaLogisticaPedidoRutaService', | 6 | 'focaLogisticaPedidoRutaService', |
7 | 'idVehiculo', | 7 | 'idVehiculo', |
8 | 'focaModalService', | 8 | 'focaModalService', |
9 | '$filter', | 9 | '$filter', |
10 | function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, | 10 | function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, |
11 | idVehiculo, focaModalService, $filter) { | 11 | idVehiculo, focaModalService, $filter) { |
12 | $scope.vehiculo = {}; | 12 | $scope.vehiculo = {}; |
13 | $scope.remitos = []; | 13 | $scope.remitos = []; |
14 | $scope.now = new Date(); | 14 | $scope.now = new Date(); |
15 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { | 15 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { |
16 | $scope.vehiculo = res.data; | 16 | $scope.vehiculo = res.data; |
17 | }); | 17 | }); |
18 | //TODO: refactor código esta rre feo | 18 | //TODO: refactor código esta rre feo |
19 | focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) { | 19 | focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) { |
20 | $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data); | 20 | $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data); |
21 | }); | 21 | }); |
22 | 22 | ||
23 | focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { | 23 | focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { |
24 | $scope.sucursal = res.data.sucursal; | 24 | $scope.sucursal = res.data.sucursal; |
25 | $scope.numero = res.data.numeroHojaRuta; | 25 | $scope.numero = res.data.numeroHojaRuta; |
26 | }); | 26 | }); |
27 | $scope.cancelar = function() { | 27 | $scope.cancelar = function() { |
28 | $uibModalInstance.close(); | 28 | $uibModalInstance.close(); |
29 | }; | 29 | }; |
30 | $scope.aceptar = function() { | 30 | $scope.aceptar = function() { |
31 | var save = { | 31 | var save = { |
32 | hojaRuta: { | 32 | hojaRuta: { |
33 | id: 0, | 33 | id: 0, |
34 | fechaCreacion: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 34 | fechaCreacion: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
35 | idTransportista: $scope.vehiculo.idTransportista, | 35 | idTransportista: $scope.vehiculo.idTransportista, |
36 | idChofer: $scope.chofer.id, | 36 | idChofer: $scope.chofer.id, |
37 | idVehiculo: $scope.vehiculo.id, | 37 | idVehiculo: $scope.vehiculo.id, |
38 | tarifaFlete: $scope.tarifaFlete | 38 | tarifaFlete: $scope.tarifaFlete |
39 | }, | 39 | }, |
40 | remitos: $scope.remitos, | 40 | remitos: $scope.remitos, |
41 | idVehiculo: $scope.vehiculo.id | 41 | idVehiculo: $scope.vehiculo.id |
42 | }; | 42 | }; |
43 | focaLogisticaPedidoRutaService.crearHojaRuta(save).then(function() { | 43 | focaLogisticaPedidoRutaService.crearHojaRuta(save).then(function() { |
44 | $uibModalInstance.close(); | 44 | $uibModalInstance.close(); |
45 | focaModalService.alert('Hoja de ruta guardada con éxito'); | 45 | focaModalService.alert('Hoja de ruta guardada con éxito'); |
46 | }); | 46 | }); |
47 | }; | 47 | }; |
48 | $scope.seleccionarChofer = function() { | 48 | $scope.seleccionarChofer = function() { |
49 | var modalInstance = $uibModal.open( | 49 | var modalInstance = $uibModal.open( |
50 | { | 50 | { |
51 | ariaLabelledBy: 'Busqueda de Chofer', | 51 | ariaLabelledBy: 'Busqueda de Chofer', |
52 | templateUrl: 'modal-chofer.html', | 52 | templateUrl: 'modal-chofer.html', |
53 | controller: 'focaModalChoferController', | 53 | controller: 'focaModalChoferController', |
54 | size: 'lg' | 54 | size: 'lg' |
55 | } | 55 | } |
56 | ); | 56 | ); |
57 | 57 | ||
58 | modalInstance.result.then( | 58 | modalInstance.result.then( |
59 | function(chofer) { | 59 | function(chofer) { |
60 | $scope.chofer = chofer; | 60 | $scope.chofer = chofer; |
61 | }, function() { | 61 | }, function() { |
62 | // funcion ejecutada cuando se cancela el modal | 62 | // funcion ejecutada cuando se cancela el modal |
63 | } | 63 | } |
64 | ); | 64 | ); |
65 | }; | 65 | }; |
66 | $scope.eliminarRemitos = function() { | ||
67 | var remitosDel = $filter('filter')($scope.remitos, {checked: true}); | ||
68 | focaModalService.alert('¿Seguro que desea desasociar estos remitos del vehículo?') | ||
69 | .then(function() { | ||
70 | eliminarRemitos(remitosDel); | ||
71 | } | ||
72 | ); | ||
73 | function eliminarRemitos(remitosDel) { | ||
74 | var nuevosRemitos = $filter('filter')($scope.remitos, {checked: !true}); | ||
75 | focaLogisticaPedidoRutaService.desasociarRemitos(remitosDel, $scope.vehiculo.id, | ||
76 | nuevosRemitos ? true : false).then(function() { | ||
77 | alertaEliminados(); | ||
78 | $scope.remitos = nuevosRemitos; | ||
79 | }); | ||
80 | } | ||
81 | function alertaEliminados() { | ||
82 | focaModalService.alert('Remitos desasociados con éxito'); | ||
83 | } | ||
84 | }; | ||
85 | $scope.minimoUnoChecked = function() { | ||
86 | var remitosChequeados = $filter('filter')($scope.remitos, {checked: true}); | ||
87 | return !remitosChequeados.length; | ||
88 | }; | ||
66 | }]); | 89 | }]); |
67 | 90 |