Commit ea4f42df1bf5c3830ce882a80205bc920e0f8ccc
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !41
Showing
1 changed file
Show diff stats
src/js/controllerCerrarVehiculo.js
1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
2 | .controller('focaModalCerrarVehiculo', [ | 2 | .controller('focaModalCerrarVehiculo', [ |
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 | 'fechaReparto', | 10 | 'fechaReparto', |
11 | 'cerrar', | 11 | 'cerrar', |
12 | function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, | 12 | function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, |
13 | idVehiculo, focaModalService, $filter, fechaReparto, cerrar) { | 13 | idVehiculo, focaModalService, $filter, fechaReparto, cerrar) { |
14 | $scope.cerrar = cerrar; | 14 | $scope.cerrar = cerrar; |
15 | $scope.vehiculo = {}; | 15 | $scope.vehiculo = {}; |
16 | $scope.remitos = []; | 16 | $scope.remitos = []; |
17 | $scope.now = fechaReparto; | 17 | $scope.now = fechaReparto; |
18 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { | 18 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { |
19 | $scope.vehiculo = res.data; | 19 | $scope.vehiculo = res.data; |
20 | }); | 20 | }); |
21 | focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(idVehiculo, 1, 1).then( | 21 | focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(idVehiculo, 1, 1).then( |
22 | function(res) { | 22 | function(res) { |
23 | $scope.remitos = res.data; | 23 | $scope.remitos = res.data; |
24 | }); | 24 | }); |
25 | focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { | 25 | focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { |
26 | $scope.sucursal = res.data.sucursal; | 26 | $scope.sucursal = res.data.sucursal; |
27 | $scope.numero = res.data.numeroHojaRuta; | 27 | $scope.numero = res.data.numeroHojaRuta; |
28 | }); | 28 | }); |
29 | $scope.cancelar = function() { | 29 | $scope.cancelar = function() { |
30 | $uibModalInstance.close(); | 30 | $uibModalInstance.close(); |
31 | }; | 31 | }; |
32 | $scope.aceptar = function() { | 32 | $scope.aceptar = function() { |
33 | var idsRemito = []; | 33 | var idsRemito = []; |
34 | $scope.remitos.forEach(function(remito) { | 34 | $scope.remitos.forEach(function(remito) { |
35 | idsRemito.push(remito.id); | 35 | idsRemito.push(remito.id); |
36 | }); | 36 | }); |
37 | var cierreDistribuicion = { | 37 | var cierreDistribuicion = { |
38 | idsRemito: idsRemito, | 38 | idsRemito: idsRemito, |
39 | fechaReparto: focaLogisticaPedidoRutaService.fecha | 39 | fechaReparto: focaLogisticaPedidoRutaService.fecha |
40 | }; | 40 | }; |
41 | focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion) | 41 | focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion) |
42 | .then(function() { | 42 | .then(function() { |
43 | focaModalService.alert('Vehículo cerrado con éxito'); | 43 | focaModalService.alert('Vehículo cerrado con éxito'); |
44 | } | 44 | } |
45 | ); | ||
46 | }; | ||
47 | $scope.seleccionarChofer = function() { | ||
48 | var modalInstance = $uibModal.open( | ||
49 | { | ||
50 | ariaLabelledBy: 'Busqueda de Chofer', | ||
51 | templateUrl: 'modal-chofer.html', | ||
52 | controller: 'focaModalChoferController', | ||
53 | size: 'lg' | ||
54 | } | ||
55 | ); | ||
56 | |||
57 | modalInstance.result.then( | ||
58 | function(chofer) { | ||
59 | $scope.chofer = chofer; | ||
60 | }, function() { | ||
61 | // funcion ejecutada cuando se cancela el modal | ||
62 | } | ||
63 | ); | 45 | ); |
64 | }; | 46 | }; |
65 | $scope.eliminarRemitos = function() { | 47 | $scope.eliminarRemitos = function() { |
66 | var remitosDel = $filter('filter')($scope.remitos, {checked: true}); | 48 | var remitosDel = $filter('filter')($scope.remitos, {checked: true}); |
67 | focaModalService.alert('¿Seguro que desea desasociar estos remitos del vehículo?') | 49 | focaModalService.alert('¿Seguro que desea desasociar estos remitos del vehículo?') |
68 | .then(function() { | 50 | .then(function() { |
69 | eliminarRemitos(remitosDel); | 51 | eliminarRemitos(remitosDel); |
70 | } | 52 | } |
71 | ); | 53 | ); |
72 | }; | 54 | }; |
73 | $scope.minimoUnoChecked = function() { | 55 | $scope.minimoUnoChecked = function() { |
74 | var remitosChequeados = $filter('filter')($scope.remitos, {checked: true}); | 56 | var remitosChequeados = $filter('filter')($scope.remitos, {checked: true}); |
75 | return !remitosChequeados.length; | 57 | return !remitosChequeados.length; |
76 | }; | 58 | }; |
77 | function eliminarRemitos(remitosDel) { | 59 | function eliminarRemitos(remitosDel) { |
78 | var nuevosRemitos = $filter('filter')($scope.remitos, {checked: !true}); | 60 | var nuevosRemitos = $filter('filter')($scope.remitos, {checked: !true}); |
79 | focaLogisticaPedidoRutaService.desasociarRemitos(remitosDel, $scope.vehiculo.id, | 61 | focaLogisticaPedidoRutaService.desasociarRemitos(remitosDel, $scope.vehiculo.id, |
80 | nuevosRemitos ? true : false).then(function() { | 62 | nuevosRemitos ? true : false).then(function() { |
81 | $scope.remitos = nuevosRemitos; | 63 | $scope.remitos = nuevosRemitos; |
82 | }); | 64 | }); |
83 | } | 65 | } |
84 | }]); | 66 | }]); |
85 | 67 |