Commit 06fd25490c754425dee8cef27c976e34f06f3067

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

validacion capacidad cisternas igual a capacidad total vehiculo

See merge request !14
src/js/controller.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculosController', [ 2 .controller('focaAbmVehiculosController', [
3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
4 '$uibModal', 'focaBotoneraLateralService', '$timeout', 4 '$uibModal', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaAbmVehiculoService, $location, focaModalService, 5 function($scope, focaAbmVehiculoService, $location, focaModalService,
6 $uibModal, focaBotoneraLateralService, $timeout) { 6 $uibModal, focaBotoneraLateralService, $timeout) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.botonera = [{ 9 $scope.botonera = [{
10 label: 'Transportista', 10 label: 'Transportista',
11 image: 'cliente.png' 11 image: 'cliente.png'
12 }]; 12 }];
13 13
14 //SETEO BOTONERA LATERAL 14 //SETEO BOTONERA LATERAL
15 focaBotoneraLateralService.showSalir(true); 15 focaBotoneraLateralService.showSalir(true);
16 focaBotoneraLateralService.showPausar(false); 16 focaBotoneraLateralService.showPausar(false);
17 focaBotoneraLateralService.showCancelar(false); 17 focaBotoneraLateralService.showCancelar(false);
18 focaBotoneraLateralService.showGuardar(false); 18 focaBotoneraLateralService.showGuardar(false);
19 19
20 if(focaAbmVehiculoService.transportistaSeleccionado.COD) { 20 if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
21 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 21 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
22 } 22 }
23 23 focaAbmVehiculoService.cleanCisternasLocal();
24 $scope.editar = function(id) { 24 $scope.editar = function(id) {
25 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 25 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
26 }; 26 };
27 $scope.solicitarConfirmacion = function(vehiculo) { 27 $scope.solicitarConfirmacion = function(vehiculo) {
28 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 28 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
29 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 29 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
30 function(data) { 30 function(data) {
31 if(data) { 31 if(data) {
32 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 32 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
33 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 33 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
34 } 34 }
35 } 35 }
36 ); 36 );
37 }; 37 };
38 $scope.seleccionarTransportista = function() { 38 $scope.seleccionarTransportista = function() {
39 var modalInstance = $uibModal.open( 39 var modalInstance = $uibModal.open(
40 { 40 {
41 ariaLabelledBy: 'Busqueda de Transportista', 41 ariaLabelledBy: 'Busqueda de Transportista',
42 templateUrl: 'modal-proveedor.html', 42 templateUrl: 'modal-proveedor.html',
43 controller: 'focaModalProveedorCtrl', 43 controller: 'focaModalProveedorCtrl',
44 size: 'lg', 44 size: 'lg',
45 resolve: { 45 resolve: {
46 transportista: function() { 46 transportista: function() {
47 return true; 47 return true;
48 } 48 }
49 } 49 }
50 } 50 }
51 ); 51 );
52 modalInstance.result.then( 52 modalInstance.result.then(
53 function(transportista) { 53 function(transportista) {
54 elegirTransportista(transportista); 54 elegirTransportista(transportista);
55 focaAbmVehiculoService.transportistaSeleccionado = transportista; 55 focaAbmVehiculoService.transportistaSeleccionado = transportista;
56 }, function() { 56 }, function() {
57 57
58 } 58 }
59 ); 59 );
60 }; 60 };
61 61
62 function elegirTransportista(transportista) { 62 function elegirTransportista(transportista) {
63 var codigo = ('00000' + transportista.COD).slice(-5); 63 var codigo = ('00000' + transportista.COD).slice(-5);
64 $scope.idTransportista = transportista.COD; 64 $scope.idTransportista = transportista.COD;
65 $scope.filtros = transportista.NOM.trim(); 65 $scope.filtros = transportista.NOM.trim();
66 $timeout(function() { 66 $timeout(function() {
67 $scope.$broadcast('addCabecera', { 67 $scope.$broadcast('addCabecera', {
68 label: 'Transportista:', 68 label: 'Transportista:',
69 valor: codigo + ' - ' + transportista.NOM 69 valor: codigo + ' - ' + transportista.NOM
70 }); 70 });
71 }); 71 });
72 buscar(transportista.COD); 72 buscar(transportista.COD);
73 } 73 }
74 74
75 function buscar(idTransportista) { 75 function buscar(idTransportista) {
76 focaAbmVehiculoService 76 focaAbmVehiculoService
77 .getVehiculosPorTransportista(idTransportista) 77 .getVehiculosPorTransportista(idTransportista)
78 .then(function(datos) { 78 .then(function(datos) {
79 $scope.vehiculos = datos.data; 79 $scope.vehiculos = datos.data;
80 }); 80 });
81 } 81 }
82 } 82 }
83 ]) 83 ])
84 .controller('focaAbmVehiculoController', [ 84 .controller('focaAbmVehiculoController', [
85 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 85 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
86 'focaModalService', '$timeout', 'focaBotoneraLateralService', 86 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window',
87 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 87 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
88 focaModalService, $timeout, focaBotoneraLateralService) { 88 focaModalService, $timeout, focaBotoneraLateralService, $window) {
89 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 89 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
90 $scope.now = new Date(); 90 $scope.now = new Date();
91 $scope.focused = 1; 91 $scope.focused = 1;
92 $scope.transportistaStamp = ''; 92 $scope.transportistaStamp = '';
93 $scope.cisternas = [];
93 94
94 $timeout(function() { 95 $timeout(function() {
95 focaBotoneraLateralService.showSalir(false); 96 focaBotoneraLateralService.showSalir(true);
96 focaBotoneraLateralService.showPausar(false); 97 focaBotoneraLateralService.showPausar(false);
97 focaBotoneraLateralService.showCancelar(true, '/vehiculo'); 98 focaBotoneraLateralService.showCancelar();
98 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 99 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
99 }); 100 });
100 101
101 if($scope.nuevo) { 102 if($scope.nuevo) {
102 focaAbmVehiculoService 103 focaAbmVehiculoService
103 .getTransportistaPorId($routeParams.idTransportista) 104 .getTransportistaPorId($routeParams.idTransportista)
104 .then(function(res) { 105 .then(function(res) {
105 var codigo = ('00000' + res.data.COD).slice(-5); 106 var codigo = ('00000' + res.data.COD).slice(-5);
106 $scope.vehiculo.idTransportista = res.data.COD; 107 $scope.vehiculo.idTransportista = res.data.COD;
107 $scope.vehiculo.transportista = res.data; 108 $scope.vehiculo.transportista = res.data;
108 $scope.$broadcast('addCabecera', { 109 $scope.$broadcast('addCabecera', {
109 label: 'Transportista:', 110 label: 'Transportista:',
110 valor: codigo + ' - ' + res.data.NOM 111 valor: codigo + ' - ' + res.data.NOM
111 }); 112 });
112 }); 113 });
113 } 114 }
114 $scope.vehiculo = {}; 115 $scope.vehiculo = {};
115 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 116 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
116 if(res.data) { 117 if(res.data) {
117 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 118 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
118 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM 119 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM
119 120
120 $scope.vehiculo = res.data; 121 $scope.vehiculo = res.data;
121 $scope.$broadcast('addCabecera', { 122 $scope.$broadcast('addCabecera', {
122 label: 'Transportista:', 123 label: 'Transportista:',
123 valor: $scope.transportistaStamp 124 valor: $scope.transportistaStamp
124 }); 125 });
125 $scope.$broadcast('addCabecera', { 126 $scope.$broadcast('addCabecera', {
126 label: 'Unidad:', 127 label: 'Unidad:',
127 valor: res.data.codigo 128 valor: res.data.codigo
128 }); 129 });
129 } 130 }
130 }); 131 });
131 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) 132 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo)
132 .then(function(res) { 133 .then(function(res) {
133 $scope.cisternas = res.data; 134 //CONCATENA LAS CISTERNAS DEL SERVICIO Y LAS DE LA BASE DE DATOS
135 $scope.cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data);
134 }); 136 });
135 $scope.next = function(key) { 137 $scope.next = function(key) {
136 if (key === 13) $scope.focused++; 138 if (key === 13) $scope.focused++;
137 }; 139 };
138 $scope.cancelar = function() { 140 $scope.cancelar = function() {
139 $location.path('/vehiculo'); 141 $location.path('/vehiculo');
140 }; 142 };
141 $scope.editar = function(id) { 143 $scope.editar = function(cisterna) {
142 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id); 144 if(cisterna) {
145 if(cisterna.idTemp != undefined) {
146 $location.path('/vehiculo/' + $routeParams.idVehiculo +
147 '/cisterna/0/' + cisterna.idTemp);
148 }else {
149 $location.path('/vehiculo/' + $routeParams.idVehiculo +
150 '/cisterna/' + cisterna.id);
151 }
152 }else {
153 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/');
154 }
143 }; 155 };
144 $scope.guardar = function() { 156 $scope.guardar = function() {
145 //Valida si existe numero de unidad 157 //Valida si existe numero de unidad
146 existeCodigoUnidad().then(function() { 158 if(!validaTotalCargas()) {
159 focaModalService.alert('La suma de las capacidades de las cisternas' +
160 ' debe ser igual a la capacidad total del vehículo');
161 return;
162 }
163 validaCodigoUnidad().then(function() {
147 delete $scope.vehiculo.transportista; 164 delete $scope.vehiculo.transportista;
148 delete $scope.vehiculo.cisternas; 165 delete $scope.vehiculo.cisternas;
149 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 166 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
150 .then(function(res){ 167 .then(function(res) {
151 if($scope.nuevo) { 168 if($scope.nuevo) {
152 $location.path('/vehiculo/' + res.data.id + 169 $location.path('/vehiculo/' + res.data.id +
153 '/' + res.data.idTransportista); 170 '/' + res.data.idTransportista);
154 } else { 171 }else {
155 $location.path('/vehiculo'); 172 guardarCisternas().then(function() {
173 $window.location.assign('/#!/vehiculo');
174 });
156 } 175 }
157 }); 176 });
158 }, function(){ 177 }, function(){
159 focaModalService.alert('Código de unidad existente'); 178 focaModalService.alert('Código de unidad existente');
160 }); 179 });
161 180
162 }; 181 };
163 $scope.solicitarConfirmacionCisterna = function(cisterna) { 182 $scope.solicitarConfirmacionCisterna = function(cisterna) {
164 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 183 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
165 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 184 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
166 function(data) { 185 function(data) {
167 if(data) { 186 if(data) {
168 focaAbmVehiculoService.deleteCisterna(cisterna.id); 187 if(cisterna.id) {
188 focaAbmVehiculoService.deleteCisterna(cisterna.id);
189 }
169 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); 190 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1);
170 } 191 }
171 } 192 }
172 ); 193 );
173 }; 194 };
174 $scope.seleccionarTransportista = function() {
175 var modalInstance = $uibModal.open(
176 {
177 ariaLabelledBy: 'Busqueda de Transportista',
178 templateUrl: 'modal-proveedor.html',
179 controller: 'focaModalProveedorCtrl',
180 size: 'lg',
181 resolve: {
182 transportista: function() {
183 return true;
184 }
185 }
186 }
187 );
188 modalInstance.result.then(
189 function(transportista) {
190 $scope.vehiculo.idTransportista = transportista.COD;
191 $scope.vehiculo.transportista = transportista;
192 }, function() {
193
194 }
195 );
196 };
197 195
198 function existeCodigoUnidad(){ 196 function validaCodigoUnidad() {
199 return new Promise(function(resolve, reject) { 197 return new Promise(function(resolve, reject) {
200 focaAbmVehiculoService 198 focaAbmVehiculoService
201 .getVehiculosPorTransportista($routeParams.idTransportista) 199 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
202 .then(function(res){ 200 .then(function(res) {
203 //Valida si existe numero de unidad 201 //Valida si existe numero de unidad
204 var existe = res.data.filter(function(vehiculo) { 202 var existe = res.data.filter(function(vehiculo) {
205 return vehiculo.codigo === $scope.vehiculo.codigo && 203 return vehiculo.codigo === $scope.vehiculo.codigo &&
206 vehiculo.id !== $scope.vehiculo.id; 204 vehiculo.id !== $scope.vehiculo.id;
207 }); 205 });
208 206
209 if(existe.length){ 207 if(existe.length) {
210 reject(existe); 208 reject(existe);
211 } else { 209 }else {
212 resolve(); 210 resolve();
213 } 211 }
214 }); 212 });
215 }); 213 });
src/js/controllerCisterna.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculoCisternaController', [ 2 .controller('focaAbmVehiculoCisternaController', [
3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout) { 6 focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 $scope.editar = false; 7 $scope.editar = false;
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.cisterna = { 9 $scope.cisterna = {
10 cisternaCarga: { 10 cisternaCarga: {
11 articulo: {} 11 articulo: {}
12 } 12 }
13 }; 13 };
14 14
15 $scope.focused = 1; 15 $scope.focused = 1;
16 $scope.next = function(key) { 16 $scope.next = function(key) {
17 if (key === 13) $scope.focused++; 17 if (key === 13) $scope.focused++;
18 }; 18 };
19 $scope.capacidadVechiulo = 0; 19 $scope.capacidadVechiulo = 0;
20 $scope.transportista = '';
20 21
21 //SETEO BOTONERA LATERAL 22 //SETEO BOTONERA LATERAL
22 $timeout(function() { 23 $timeout(function() {
23 focaBotoneraLateralService.showSalir(false); 24 focaBotoneraLateralService.showSalir(false);
24 focaBotoneraLateralService.showPausar(false); 25 focaBotoneraLateralService.showPausar(false);
25 focaBotoneraLateralService.showCancelar(true); 26 focaBotoneraLateralService.showCancelar(true);
26 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 27 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
27 }); 28 });
28 29
29 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { 30
30 if(res.data) { 31 if($routeParams.idTemp != undefined) {
31 $scope.cisterna = res.data; 32 $scope.cisterna = focaAbmVehiculoService.getCisternasLocal()[$routeParams.idTemp];
32 $scope.editar = true; 33 }else {
33 }else { 34 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) {
34 $scope.editar = false; 35 if(res.data) $scope.cisterna = res.data;
35 } 36 });
36 }); 37 }
37 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 38 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
38 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 39 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
40 $scope.transportista = res.data.transportista.COD;
39 $scope.capacidadVechiulo = res.data.capacidad; 41 $scope.capacidadVechiulo = res.data.capacidad;
40 $scope.$broadcast('addCabecera', { 42 $scope.$broadcast('addCabecera', {
41 label: 'Transportista:', 43 label: 'Transportista:',
42 valor: codigo + ' - ' + res.data.transportista.NOM 44 valor: codigo + ' - ' + res.data.transportista.NOM
43 }); 45 });
44 $scope.$broadcast('addCabecera', { 46 $scope.$broadcast('addCabecera', {
45 label: 'Unidad:', 47 label: 'Unidad:',
46 valor: res.data.codigo 48 valor: res.data.codigo
47 }); 49 });
50 $scope.$broadcast('addCabecera', {
51 label: 'Capacidad total vehículo:',
52 valor: res.data.capacidad
53 });
48 }); 54 });
49 $scope.cancelar = function() { 55 $scope.cancelar = function() {
50 $location.path('/vehiculo/' + $routeParams.idVehiculo); 56 $location.path('/vehiculo/' + $routeParams.idVehiculo);
51 }; 57 };
52 $scope.guardar = function() { 58 $scope.guardar = function() {
53 if(!$scope.cisterna.unidadMedida) { 59 if(!$scope.cisterna.unidadMedida) {
54 focaModalService.alert('Ingrese unidad de medida'); 60 focaModalService.alert('Ingrese unidad de medida');
55 return; 61 return;
56 } 62 }
57 validaCodigoCapacidad().then(function() { 63 validaCodigoCapacidad().then(function() {
58 $scope.cisterna.idVehiculo = $routeParams.idVehiculo; 64 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
59 delete $scope.cisterna.vehiculo; 65 delete $scope.cisterna.vehiculo;
60 delete $scope.cisterna.unidadMedida;
61 delete $scope.cisterna.cisternaCarga.articulo; 66 delete $scope.cisterna.cisternaCarga.articulo;
62 focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ 67
63 $location.path('/vehiculo/' + $routeParams.idVehiculo); 68 if($routeParams.idTemp != undefined) {
64 }); 69 //SI SE EDITA UNA CISTERNA LOCALMENTE
70 focaAbmVehiculoService
71 .guardarCisternaLocal($scope.cisterna, $routeParams.idTemp);
72 }else if($scope.cisterna.id) {
73 //SI SE EDITA UNA CISTERNA PREVIAMENTE GUARDADA
74 focaAbmVehiculoService.deleteCisterna($scope.cisterna.id);
75 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna);
76 }else {
77 //SI SE EDITA CREA UNA NUEVA CISTERNA
78 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna);
79 }
80 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo +
81 '/' + $scope.transportista);
65 }, function(err) { 82 }, function(err) {
66 focaModalService.alert(err); 83 focaModalService.alert(err);
67 }); 84 });
68 85
69 }; 86 };
70 87
71 $scope.seleccionarUnidadMedida = function() { 88 $scope.seleccionarUnidadMedida = function() {
72 var modalInstance = $uibModal.open( 89 var modalInstance = $uibModal.open(
73 { 90 {
74 ariaLabelledBy: 'Busqueda de Unidades de medida', 91 ariaLabelledBy: 'Busqueda de Unidades de medida',
75 templateUrl: 'modal-unidad-medida.html', 92 templateUrl: 'modal-unidad-medida.html',
76 controller: 'focaModalUnidadMedidaCtrl', 93 controller: 'focaModalUnidadMedidaCtrl',
77 size: 'lg' 94 size: 'lg'
78 } 95 }
79 ); 96 );
80 modalInstance.result.then(function(unidaMedida) { 97 modalInstance.result.then(function(unidaMedida) {
81 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 98 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
82 $scope.cisterna.unidadMedida = unidaMedida; 99 $scope.cisterna.unidadMedida = unidaMedida;
83 }); 100 });
84 }; 101 };
85 102
86 function validaCodigoCapacidad() { 103 function validaCodigoCapacidad() {
87 return new Promise(function(resolve, reject) { 104 return new Promise(function(resolve, reject) {
88 focaAbmVehiculoService 105 focaAbmVehiculoService
89 .getCisternadoPorVehiculo($routeParams.idVehiculo) 106 .getCisternadoPorVehiculo($routeParams.idVehiculo)
90 .then(function(res) { 107 .then(function(res) {
91 108 var cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data);
92 var totalCargado = 0; 109 var totalCargado = 0;
93 110
94 res.data.forEach(function(cisterna) { 111 cisternas.forEach(function(cisterna) {
95 //SI EL CODIGO YA EXISTE 112 //SI EL CODIGO YA EXISTE
96 if(cisterna.codigo === $scope.cisterna.codigo && 113 if(cisterna.codigo === $scope.cisterna.codigo &&
97 cisterna.id !== $scope.cisterna.id) { 114 (cisterna.id !== $scope.cisterna.id ||
115 cisterna.idTemp !== $scope.cisterna.idTemp)) {
98 reject('Código de cisterna existente'); 116 reject('Código de cisterna existente');
99 } 117 }
100 if(cisterna.id !== $scope.cisterna.id) { 118 if(cisterna.id !== $scope.cisterna.id) {
101 totalCargado += cisterna.capacidad; 119 totalCargado += cisterna.capacidad;
102 } 120 }
103 }); 121 });
104 122
105 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO 123 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO
106 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); 124 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad);
107 if(totalCargado > $scope.capacidadVechiulo) { 125 if(totalCargado > $scope.capacidadVechiulo) {
108 reject('La capacidad total de las cisternas' + 126 reject('La capacidad total de las cisternas' +
109 ' debe ser menor o igual a la del vehiculo'); 127 ' no debe ser mayor a la del vehiculo');
110 }else { 128 }else {
111 resolve(); 129 resolve();
112 } 130 }
113 }); 131 });
114 }); 132 });
115 } 133 }
116 } 134 }
117 ]); 135 ]);
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .config([ 2 .config([
3 '$routeProvider', 3 '$routeProvider',
4 function($routeProvider) { 4 function($routeProvider) {
5 $routeProvider.when('/vehiculo', { 5 $routeProvider.when('/vehiculo', {
6 controller: 'focaAbmVehiculosController', 6 controller: 'focaAbmVehiculosController',
7 templateUrl: 'src/views/foca-abm-vehiculos-listado.html' 7 templateUrl: 'src/views/foca-abm-vehiculos-listado.html'
8 }); 8 });
9 } 9 }
10 ]) 10 ])
11 .config([ 11 .config([
12 '$routeProvider', 12 '$routeProvider',
13 function($routeProvider) { 13 function($routeProvider) {
14 $routeProvider.when('/vehiculo/:idVehiculo/:idTransportista', { 14 $routeProvider.when('/vehiculo/:idVehiculo/:idTransportista', {
15 controller: 'focaAbmVehiculoController', 15 controller: 'focaAbmVehiculoController',
16 templateUrl: 'src/views/foca-abm-vehiculos-item.html' 16 templateUrl: 'src/views/foca-abm-vehiculos-item.html'
17 }); 17 });
18 } 18 }
19 ]) 19 ])
20 .config([ 20 .config([
21 '$routeProvider', 21 '$routeProvider',
22 function($routeProvider) { 22 function($routeProvider) {
23 $routeProvider.when('/vehiculo/:idVehiculo', { 23 $routeProvider.when('/vehiculo/:idVehiculo', {
24 controller: 'focaAbmVehiculoController', 24 controller: 'focaAbmVehiculoController',
25 templateUrl: 'src/views/foca-abm-vehiculos-item.html' 25 templateUrl: 'src/views/foca-abm-vehiculos-item.html'
26 }); 26 });
27 } 27 }
28 ]) 28 ])
29 .config([ 29 .config([
30 '$routeProvider', 30 '$routeProvider',
31 function($routeProvider) { 31 function($routeProvider) {
32 $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id', { 32 $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id', {
33 controller: 'focaAbmVehiculoCisternaController', 33 controller: 'focaAbmVehiculoCisternaController',
34 templateUrl: 'src/views/foca-abm-cisterna-item.html' 34 templateUrl: 'src/views/foca-abm-cisterna-item.html'
35 }); 35 });
36 } 36 }
37 ])
38 .config([
39 '$routeProvider',
40 function($routeProvider) {
41 $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id/:idTemp', {
42 controller: 'focaAbmVehiculoCisternaController',
43 templateUrl: 'src/views/foca-abm-cisterna-item.html'
44 });
45 }
37 ]); 46 ]);
38 47
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var cisternas = [];
3 return { 4 return {
4 getVehiculos: function() { 5 getVehiculos: function() {
5 return $http.get(API_ENDPOINT.URL + '/vehiculo'); 6 return $http.get(API_ENDPOINT.URL + '/vehiculo');
6 }, 7 },
7 getVehiculo: function(id) { 8 getVehiculo: function(id) {
8 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); 9 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
9 }, 10 },
10 getTransportistas: function() { 11 getTransportistas: function() {
11 return $http.get(API_ENDPOINT.URL + '/transportista'); 12 return $http.get(API_ENDPOINT.URL + '/transportista');
12 }, 13 },
13 guardarVehiculo: function(vehiculo) { 14 guardarVehiculo: function(vehiculo) {
14 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); 15 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
15 }, 16 },
16 deleteVehiculo: function(id) { 17 deleteVehiculo: function(id) {
17 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); 18 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
18 }, 19 },
19 getCisternadoPorVehiculo: function(idVehiculo) { 20 getCisternadoPorVehiculo: function(idVehiculo) {
20 return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo); 21 return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo);
21 }, 22 },
22 getCisterna: function(id) { 23 getCisterna: function(id) {
23 return $http.get(API_ENDPOINT.URL + '/cisterna/obtener/' + id); 24 return $http.get(API_ENDPOINT.URL + '/cisterna/obtener/' + id);
24 }, 25 },
26 getCisternasLocal: function() {
27 return cisternas;
28 },
29 guardarCisternaLocal: function(cisterna, idTemp) {
30 if(idTemp){
31 cisterna.idTemp = idTemp;
32 cisternas[idTemp] = cisterna;
33 }else {
34 cisterna.idTemp = cisternas.length;
35 cisternas.push(cisterna);
36 }
37 },
38 cleanCisternasLocal: function(){
39 cisternas = [];
40 },
25 guardarCisterna: function(cisterna) { 41 guardarCisterna: function(cisterna) {
26 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna}); 42 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna});
27 }, 43 },
28 deleteCisterna: function(id) { 44 deleteCisterna: function(id) {
29 return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); 45 return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id);
30 }, 46 },
31 getVehiculosPorTransportista: function(id) { 47 getVehiculosPorTransportista: function(id) {
32 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); 48 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
33 }, 49 },
34 getTransportistaPorId: function(id) { 50 getTransportistaPorId: function(id) {
35 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 51 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
36 }, 52 },
37 transportistaSeleccionado: {} 53 transportistaSeleccionado: {}
38 }; 54 };
39 }]); 55 }]);
40 56
src/views/foca-abm-vehiculos-item.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehículo'" 3 titulo="'Vehículo'"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <form name="formVehiculo" class="px-3"> 10 <form name="formVehiculo" class="px-3">
11 <input type="hidden" name="id" ng-model="sector.id" /> 11 <input type="hidden" name="id" ng-model="sector.id" />
12 <div class="row mt-3"> 12 <div class="row mt-3">
13 <div class="form-group d-flex mb-2 col-md-6"> 13 <div class="form-group d-flex mb-2 col-md-6">
14 <label class="col-form-label col-md-3">Transportista</label> 14 <label class="col-form-label col-md-3">Transportista</label>
15 <div class="input-group col-md-9 pl-0"> 15 <div class="input-group col-md-9 pl-0">
16 <input 16 <input
17 class="form-control" 17 class="form-control"
18 type="text" 18 type="text"
19 ng-value="transportistaStamp" 19 ng-value="transportistaStamp"
20 readonly 20 readonly
21 /> 21 />
22 </div> 22 </div>
23 </div> 23 </div>
24 <div class="form-group d-flex mb-2 col-md-6"> 24 <div class="form-group d-flex mb-2 col-md-6">
25 <label class="col-form-label col-md-3">Unidad</label> 25 <label class="col-form-label col-md-3">Unidad</label>
26 <div class="input-group col-md-9 pl-0"> 26 <div class="input-group col-md-9 pl-0">
27 <input 27 <input
28 class="form-control" 28 class="form-control"
29 type="text" 29 type="text"
30 teclado-virtual 30 teclado-virtual
31 ng-model="vehiculo.codigo" 31 ng-model="vehiculo.codigo"
32 foca-focus="focused == 3" 32 foca-focus="focused == 3"
33 ng-focus="focused = 3" 33 ng-focus="focused = 3"
34 ng-keypress="next($event.keyCode)" 34 ng-keypress="next($event.keyCode)"
35 /> 35 />
36 </div> 36 </div>
37 </div> 37 </div>
38 <div class="form-group d-flex mb-2 col-md-6"> 38 <div class="form-group d-flex mb-2 col-md-6">
39 <label class="col-form-label col-md-4">Dominio tractor</label> 39 <label class="col-form-label col-md-4">Dominio tractor</label>
40 <div class="input-group col-md-8 pl-0"> 40 <div class="input-group col-md-8 pl-0">
41 <input 41 <input
42 class="form-control" 42 class="form-control"
43 type="text" 43 type="text"
44 teclado-virtual 44 teclado-virtual
45 ng-model="vehiculo.tractor" 45 ng-model="vehiculo.tractor"
46 ng-required="true" 46 ng-required="true"
47 foca-focus="focused == 1" 47 foca-focus="focused == 1"
48 ng-focus="focused = 1" 48 ng-focus="focused = 1"
49 ng-keypress="next($event.keyCode)" 49 ng-keypress="next($event.keyCode)"
50 /> 50 />
51 </div> 51 </div>
52 </div> 52 </div>
53 <div class="form-group d-flex mb-2 col-md-6"> 53 <div class="form-group d-flex mb-2 col-md-6">
54 <label class="col-form-label col-md-4">Dominio semi</label> 54 <label class="col-form-label col-md-4">Dominio semi</label>
55 <div class="input-group col-md-8 pl-0"> 55 <div class="input-group col-md-8 pl-0">
56 <input 56 <input
57 class="form-control" 57 class="form-control"
58 type="text" 58 type="text"
59 teclado-virtual 59 teclado-virtual
60 ng-model="vehiculo.semi" 60 ng-model="vehiculo.semi"
61 ng-required="true" 61 ng-required="true"
62 foca-focus="focused == 4" 62 foca-focus="focused == 4"
63 ng-focus="focused = 4" 63 ng-focus="focused = 4"
64 ng-keypress="next($event.keyCode)" 64 ng-keypress="next($event.keyCode)"
65 /> 65 />
66 </div> 66 </div>
67 </div> 67 </div>
68 <div class="form-group d-flex mb-2 col-md-6"> 68 <div class="form-group d-flex mb-2 col-md-6">
69 <label class="col-form-label col-md-4">Capacidad total</label> 69 <label class="col-form-label col-md-4">Capacidad total</label>
70 <div class="input-group col-md-8 pl-0"> 70 <div class="input-group col-md-8 pl-0">
71 <input 71 <input
72 class="form-control" 72 class="form-control"
73 type="text" 73 type="text"
74 teclado-virtual 74 teclado-virtual
75 ng-model="vehiculo.capacidad" 75 ng-model="vehiculo.capacidad"
76 ng-required="true" 76 ng-required="true"
77 foca-focus="focused == 2" 77 foca-focus="focused == 2"
78 ng-focus="focused = 2" 78 ng-focus="focused = 2"
79 ng-keypress="next($event.keyCode)" 79 ng-keypress="next($event.keyCode)"
80 /> 80 />
81 </div> 81 </div>
82 </div> 82 </div>
83 </div> 83 </div>
84 </form> 84 </form>
85 <div ng-show="!nuevo"> 85 <div ng-show="!nuevo">
86 <h5 class="pl-4 table-title">Cisternas</h5> 86 <h5 class="pl-4 table-title">Cisternas</h5>
87 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 87 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
88 <thead> 88 <thead>
89 <tr> 89 <tr>
90 <th class="px-5">Código</th> 90 <th class="px-5">Código</th>
91 <th class="text-right px-5">Capacidad</th> 91 <th class="text-right px-5">Capacidad</th>
92 <th class="text-center px-4"> 92 <th class="text-center px-4">
93 <button 93 <button
94 class="btn btn-outline-debo boton-accion" 94 class="btn btn-outline-debo boton-accion"
95 title="Agregar" 95 title="Agregar"
96 ng-click="editar(0)"> 96 ng-click="editar()">
97 <i class="fa fa-plus"></i> 97 <i class="fa fa-plus"></i>
98 </button> 98 </button>
99 </th> 99 </th>
100 </tr> 100 </tr>
101 </thead> 101 </thead>
102 <tbody> 102 <tbody>
103 <tr ng-repeat="cisterna in cisternas | filter:filtros"> 103 <tr ng-repeat="cisterna in cisternas | filter:filtros">
104 <td ng-bind="cisterna.codigo" class="px-5"></td> 104 <td ng-bind="cisterna.codigo" class="px-5"></td>
105 <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> 105 <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td>
106 <td class="text-center px-4"> 106 <td class="text-center px-4">
107 <button 107 <button
108 class="btn btn-outline-dark boton-accion" 108 class="btn btn-outline-dark boton-accion"
109 title="Editar" 109 title="Editar"
110 ng-click="editar(cisterna.id)" 110 ng-click="editar(cisterna)"
111 > 111 >
112 <i class="fa fa-pencil"></i> 112 <i class="fa fa-pencil"></i>
113 </button> 113 </button>
114 <button 114 <button
115 class="btn btn-outline-dark boton-accion" 115 class="btn btn-outline-dark boton-accion"
116 title="Eliminar" 116 title="Eliminar"
117 ng-click="solicitarConfirmacionCisterna(cisterna)" 117 ng-click="solicitarConfirmacionCisterna(cisterna)"
118 > 118 >
119 <i class="fa fa-trash"></i> 119 <i class="fa fa-trash"></i>
120 </button> 120 </button>
121 </td> 121 </td>
122 </tr> 122 </tr>
123 </body> 123 </body>
124 </table> 124 </table>
125 </div> 125 </div>
126 </div> 126 </div>
127 </div> 127 </div>
128 128
src/views/foca-abm-vehiculos-listado.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehículos'" 3 titulo="'Vehículos'"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <div class="row px-5 py-2 botonera-secundaria"> 10 <div class="row px-5 py-2 botonera-secundaria">
11 <div class="col-12"> 11 <div class="col-12">
12 <foca-botonera-facturador botones="botonera" extra="5" class="row"></foca-botonera-facturador> 12 <foca-botonera-facturador botones="botonera" extra="5" class="row"></foca-botonera-facturador>
13 </div> 13 </div>
14 </div> 14 </div>
15 <!-- <div class="col-6 form-group"> 15 <!-- <div class="col-6 form-group">
16 <input seleccionarTransportista() 16 <input seleccionarTransportista()
17 type="text" 17 type="text"
18 teclado-virtual 18 teclado-virtual
19 class="form-control form-control-sm" 19 class="form-control form-control-sm"
20 placeholder="Búsqueda" 20 placeholder="Búsqueda"
21 ng-model="filtros" 21 ng-model="filtros"
22 /> 22 />
23 </div> --> 23 </div> -->
24 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 24 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
25 <thead> 25 <thead>
26 <tr> 26 <tr>
27 <th class="text-center">Unidad</th> 27 <th class="text-center">Unidad</th>
28 <th>Dominio Tractor</th> 28 <th>Dominio Tractor</th>
29 <th>Dominio Semi</th> 29 <th>Dominio Semi</th>
30 <th class="text-right">Capacidad</th> 30 <th class="text-right">Capacidad</th>
31 <th class="text-center"> 31 <th class="text-center">
32 <button 32 <button
33 ng-disabled="!idTransportista" 33 ng-disabled="!idTransportista"
34 class="btn btn-outline-debo boton-accion" 34 class="btn btn-outline-debo boton-accion"
35 title="Agregar" 35 title="Agregar"
36 ng-click="editar(0)" 36 ng-click="editar(0)"
37 ><i class="fa fa-plus"></i> 37 ><i class="fa fa-plus"></i>
38 </button> 38 </button>
39 </th> 39 </th>
40 </tr> 40 </tr>
41 </thead> 41 </thead>
42 <tbody> 42 <tbody>
43 <tr ng-repeat="vehiculo in vehiculos | filter:filtros"> 43 <tr ng-repeat="vehiculo in vehiculos | filter:filtros">
44 <td ng-bind="vehiculo.codigo" class="text-center"></td> 44 <td ng-bind="vehiculo.codigo" class="text-center"></td>
45 <td ng-bind="vehiculo.tractor"></td> 45 <td ng-bind="vehiculo.tractor"></td>
46 <td ng-bind="vehiculo.semi"></td> 46 <td ng-bind="vehiculo.semi"></td>
47 <td ng-bind="vehiculo.capacidadTotalCisternas" class="text-right"></td> 47 <td ng-bind="vehiculo.capacidad" class="text-right"></td>
48 <td class="text-center"> 48 <td class="text-center">
49 <button 49 <button
50 class="btn btn-outline-dark boton-accion" 50 class="btn btn-outline-dark boton-accion"
51 title="Editar" 51 title="Editar"
52 ng-click="editar(vehiculo.id)" 52 ng-click="editar(vehiculo.id)"
53 > 53 >
54 <i class="fa fa-pencil"></i> 54 <i class="fa fa-pencil"></i>
55 </button> 55 </button>
56 <button 56 <button
57 class="btn btn-outline-dark boton-accion" 57 class="btn btn-outline-dark boton-accion"
58 title="Eliminar" 58 title="Eliminar"
59 ng-click="solicitarConfirmacion(vehiculo)" 59 ng-click="solicitarConfirmacion(vehiculo)"
60 > 60 >
61 <i class="fa fa-trash"></i> 61 <i class="fa fa-trash"></i>
62 </button> 62 </button>
63 </td> 63 </td>
64 </tr> 64 </tr>
65 </body> 65 </body>
66 </table> 66 </table>
67 </div> 67 </div>
68 </div> 68 </div>
69 69