Commit 4bcdeb329ca2d5797426f7c3465c6a62f511af1d

Authored by Jose Pinto
1 parent 772ec922f8
Exists in master

codigo de vehiculo y cisterna unicos

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 = ['Transportista']; 9 $scope.botonera = ['Transportista'];
10 10
11 //SETEO BOTONERA LATERAL 11 //SETEO BOTONERA LATERAL
12 focaBotoneraLateralService.showSalir(true); 12 focaBotoneraLateralService.showSalir(true);
13 focaBotoneraLateralService.showPausar(false); 13 focaBotoneraLateralService.showPausar(false);
14 focaBotoneraLateralService.showCancelar(false); 14 focaBotoneraLateralService.showCancelar(false);
15 focaBotoneraLateralService.showGuardar(false); 15 focaBotoneraLateralService.showGuardar(false);
16 16
17 if(focaAbmVehiculoService.transportistaSeleccionado.COD) { 17 if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
18 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 18 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
19 } 19 }
20 20
21 $scope.editar = function(id) { 21 $scope.editar = function(id) {
22 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 22 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
23 }; 23 };
24 $scope.solicitarConfirmacion = function(vehiculo) { 24 $scope.solicitarConfirmacion = function(vehiculo) {
25 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 25 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
26 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 26 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
27 function(data) { 27 function(data) {
28 if(data) { 28 if(data) {
29 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 29 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
30 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 30 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
31 } 31 }
32 } 32 }
33 ); 33 );
34 }; 34 };
35 $scope.seleccionarTransportista = function() { 35 $scope.seleccionarTransportista = function() {
36 var modalInstance = $uibModal.open( 36 var modalInstance = $uibModal.open(
37 { 37 {
38 ariaLabelledBy: 'Busqueda de Transportista', 38 ariaLabelledBy: 'Busqueda de Transportista',
39 templateUrl: 'modal-proveedor.html', 39 templateUrl: 'modal-proveedor.html',
40 controller: 'focaModalProveedorCtrl', 40 controller: 'focaModalProveedorCtrl',
41 size: 'lg', 41 size: 'lg',
42 resolve: { 42 resolve: {
43 transportista: function() { 43 transportista: function() {
44 return true; 44 return true;
45 } 45 }
46 } 46 }
47 } 47 }
48 ); 48 );
49 modalInstance.result.then( 49 modalInstance.result.then(
50 function(transportista) { 50 function(transportista) {
51 elegirTransportista(transportista); 51 elegirTransportista(transportista);
52 focaAbmVehiculoService.transportistaSeleccionado = transportista; 52 focaAbmVehiculoService.transportistaSeleccionado = transportista;
53 }, function() { 53 }, function() {
54 54
55 } 55 }
56 ); 56 );
57 }; 57 };
58 58
59 function elegirTransportista(transportista) { 59 function elegirTransportista(transportista) {
60 var codigo = ('00000' + transportista.COD).slice(-5); 60 var codigo = ('00000' + transportista.COD).slice(-5);
61 $scope.idTransportista = transportista.COD; 61 $scope.idTransportista = transportista.COD;
62 $scope.filtros = transportista.NOM.trim(); 62 $scope.filtros = transportista.NOM.trim();
63 $timeout(function() { 63 $timeout(function() {
64 $scope.$broadcast('addCabecera', { 64 $scope.$broadcast('addCabecera', {
65 label: 'Transportista:', 65 label: 'Transportista:',
66 valor: codigo + ' - ' + transportista.NOM 66 valor: codigo + ' - ' + transportista.NOM
67 }); 67 });
68 }); 68 });
69 buscar(transportista.COD); 69 buscar(transportista.COD);
70 } 70 }
71 71
72 function buscar(idTransportista) { 72 function buscar(idTransportista) {
73 focaAbmVehiculoService 73 focaAbmVehiculoService
74 .getVehiculosPorTransportista(idTransportista) 74 .getVehiculosPorTransportista(idTransportista)
75 .then(function(datos) { 75 .then(function(datos) {
76 $scope.vehiculos = datos.data; 76 $scope.vehiculos = datos.data;
77 }); 77 });
78 } 78 }
79 } 79 }
80 ]) 80 ])
81 .controller('focaAbmVehiculoController', [ 81 .controller('focaAbmVehiculoController', [
82 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 82 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
83 'focaModalService', '$timeout', 'focaBotoneraLateralService', 83 'focaModalService', '$timeout', 'focaBotoneraLateralService',
84 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 84 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
85 focaModalService, $timeout, focaBotoneraLateralService) { 85 focaModalService, $timeout, focaBotoneraLateralService) {
86 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 86 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
87 $scope.now = new Date(); 87 $scope.now = new Date();
88 $scope.focused = 1; 88 $scope.focused = 1;
89 89
90 $timeout(function() { 90 $timeout(function() {
91 focaBotoneraLateralService.showSalir(false); 91 focaBotoneraLateralService.showSalir(false);
92 focaBotoneraLateralService.showPausar(false); 92 focaBotoneraLateralService.showPausar(false);
93 focaBotoneraLateralService.showCancelar(true); 93 focaBotoneraLateralService.showCancelar(true, '/vehiculo');
94 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 94 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
95 }); 95 });
96 96
97 if($scope.nuevo) { 97 if($scope.nuevo) {
98 focaAbmVehiculoService 98 focaAbmVehiculoService
99 .getTransportistaPorId($routeParams.idTransportista) 99 .getTransportistaPorId($routeParams.idTransportista)
100 .then(function(res) { 100 .then(function(res) {
101 var codigo = ('00000' + res.data.COD).slice(-5); 101 var codigo = ('00000' + res.data.COD).slice(-5);
102 $scope.vehiculo.idTransportista = res.data.COD; 102 $scope.vehiculo.idTransportista = res.data.COD;
103 $scope.vehiculo.transportista = res.data; 103 $scope.vehiculo.transportista = res.data;
104 $scope.$broadcast('addCabecera', { 104 $scope.$broadcast('addCabecera', {
105 label: 'Transportista:', 105 label: 'Transportista:',
106 valor: codigo + ' - ' + res.data.NOM 106 valor: codigo + ' - ' + res.data.NOM
107 }); 107 });
108 }); 108 });
109 } 109 }
110 $scope.vehiculo = {}; 110 $scope.vehiculo = {};
111 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 111 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
112 if(res.data) { 112 if(res.data) {
113 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 113 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
114 $scope.vehiculo = res.data; 114 $scope.vehiculo = res.data;
115 $scope.$broadcast('addCabecera', { 115 $scope.$broadcast('addCabecera', {
116 label: 'Transportista:', 116 label: 'Transportista:',
117 valor: codigo + ' - ' + res.data.transportista.NOM 117 valor: codigo + ' - ' + res.data.transportista.NOM
118 }); 118 });
119 $scope.$broadcast('addCabecera', { 119 $scope.$broadcast('addCabecera', {
120 label: 'Unidad:', 120 label: 'Unidad:',
121 valor: res.data.codigo 121 valor: res.data.codigo
122 }); 122 });
123 } 123 }
124 }); 124 });
125 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) 125 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo)
126 .then(function(res) { 126 .then(function(res) {
127 $scope.cisternas = res.data; 127 $scope.cisternas = res.data;
128 }); 128 });
129 $scope.next = function(key) { 129 $scope.next = function(key) {
130 if (key === 13) $scope.focused++; 130 if (key === 13) $scope.focused++;
131 }; 131 };
132 $scope.cancelar = function() { 132 $scope.cancelar = function() {
133 $location.path('/vehiculo'); 133 $location.path('/vehiculo');
134 }; 134 };
135 $scope.editar = function(id) { 135 $scope.editar = function(id) {
136 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id); 136 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id);
137 }; 137 };
138 $scope.guardar = function() { 138 $scope.guardar = function() {
139 if(!$scope.vehiculo.transportista) { 139 if(!$scope.vehiculo.transportista) {
140 focaModalService.alert('Elija Transportista'); 140 focaModalService.alert('Elija Transportista');
141 return; 141 return;
142 } 142 }
143 delete $scope.vehiculo.transportista; 143 focaAbmVehiculoService.getVehiculosPorTransportista($routeParams.idTransportista)
144 focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) { 144 .then(function(res) {
145 if($scope.nuevo) { 145 var existe = res.data.filter(function(vehiculo) {
146 $location.path('/vehiculo/' + res.data.id + '/' + res.data.idTransportista); 146 return vehiculo.codigo === $scope.vehiculo.codigo &&
147 } else { 147 vehiculo.id !== $scope.vehiculo.id;
148 $location.path('/vehiculo'); 148 });
149 } 149
150 }); 150 if(existe.length > 0) {
151 return Promise.reject('Existe codigo de unidad');
152 }else {
153 delete $scope.vehiculo.transportista;
154 return focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo);
155 }
156 }).then(function(res) {
157 if($scope.nuevo) {
158 $location.path('/vehiculo/' + res.data.id +
159 '/' + res.data.idTransportista);
160 }else {
161 $location.path('/vehiculo');
162 }
163 }, function(rej) {
164 focaModalService.alert(rej);
165 });
151 }; 166 };
152 $scope.solicitarConfirmacionCisterna = function(cisterna) { 167 $scope.solicitarConfirmacionCisterna = function(cisterna) {
153 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 168 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
154 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 169 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
155 function(data) { 170 function(data) {
156 if(data) { 171 if(data) {
157 focaAbmVehiculoService.deleteCisterna(cisterna.id); 172 focaAbmVehiculoService.deleteCisterna(cisterna.id);
158 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); 173 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1);
159 } 174 }
160 } 175 }
161 ); 176 );
162 }; 177 };
163 $scope.seleccionarTransportista = function() { 178 $scope.seleccionarTransportista = function() {
164 var modalInstance = $uibModal.open( 179 var modalInstance = $uibModal.open(
165 { 180 {
166 ariaLabelledBy: 'Busqueda de Transportista', 181 ariaLabelledBy: 'Busqueda de Transportista',
167 templateUrl: 'modal-proveedor.html', 182 templateUrl: 'modal-proveedor.html',
168 controller: 'focaModalProveedorCtrl', 183 controller: 'focaModalProveedorCtrl',
169 size: 'lg', 184 size: 'lg',
170 resolve: { 185 resolve: {
171 transportista: function() { 186 transportista: function() {
172 return true; 187 return true;
173 } 188 }
174 } 189 }
175 } 190 }
176 ); 191 );
177 modalInstance.result.then( 192 modalInstance.result.then(
178 function(transportista) { 193 function(transportista) {
179 $scope.vehiculo.idTransportista = transportista.COD; 194 $scope.vehiculo.idTransportista = transportista.COD;
180 $scope.vehiculo.transportista = transportista; 195 $scope.vehiculo.transportista = transportista;
181 }, function() { 196 }, function() {
182 197
183 } 198 }
184 ); 199 );
185 }; 200 };
186 } 201 }
187 ]); 202 ]);
188 203
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',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout) { 6 focaModalService, focaBotoneraLateralService, $timeout) {
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 19
20 //SETEO BOTONERA LATERAL 20 //SETEO BOTONERA LATERAL
21 $timeout(function() { 21 $timeout(function() {
22 focaBotoneraLateralService.showSalir(false); 22 focaBotoneraLateralService.showSalir(false);
23 focaBotoneraLateralService.showPausar(false); 23 focaBotoneraLateralService.showPausar(false);
24 focaBotoneraLateralService.showCancelar(true); 24 focaBotoneraLateralService.showCancelar(true);
25 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 25 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
26 }); 26 });
27 27
28 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { 28 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) {
29 if(res.data) { 29 if(res.data) {
30 $scope.cisterna = res.data; 30 $scope.cisterna = res.data;
31 $scope.editar = true; 31 $scope.editar = true;
32 }else { 32 }else {
33 $scope.editar = false; 33 $scope.editar = false;
34 } 34 }
35 }); 35 });
36 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 36 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
37 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 37 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
38 $scope.$broadcast('addCabecera', { 38 $scope.$broadcast('addCabecera', {
39 label: 'Transportista:', 39 label: 'Transportista:',
40 valor: codigo + ' - ' + res.data.transportista.NOM 40 valor: codigo + ' - ' + res.data.transportista.NOM
41 }); 41 });
42 $scope.$broadcast('addCabecera', { 42 $scope.$broadcast('addCabecera', {
43 label: 'Unidad:', 43 label: 'Unidad:',
44 valor: res.data.codigo 44 valor: res.data.codigo
45 }); 45 });
46 }); 46 });
47 $scope.cancelar = function() { 47 $scope.cancelar = function() {
48 $location.path('/vehiculo/' + $routeParams.idVehiculo); 48 $location.path('/vehiculo/' + $routeParams.idVehiculo);
49 }; 49 };
50 $scope.guardar = function() { 50 $scope.guardar = function() {
51 if(!$scope.cisterna.unidadMedida) { 51 if(!$scope.cisterna.unidadMedida) {
52 focaModalService.alert('Ingrese unidad de medida'); 52 focaModalService.alert('Ingrese unidad de medida');
53 return; 53 return;
54 } 54 }
55 if(!$scope.cisterna.cisternaCarga.articulo) { 55 if(!$scope.cisterna.cisternaCarga.articulo) {
56 focaModalService.alert('Ingrese producto'); 56 focaModalService.alert('Ingrese producto');
57 return; 57 return;
58 } 58 }
59 $scope.cisterna.idVehiculo = $routeParams.idVehiculo; 59 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo)
60 delete $scope.cisterna.unidadMedida; 60 .then(function(res) {
61 delete $scope.cisterna.cisternaCarga.articulo; 61 var existe = res.data.filter(function(cisterna) {
62 focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function() { 62 return cisterna.codigo === $scope.cisterna.codigo;
63 $location.path('/vehiculo/' + $routeParams.idVehiculo); 63 });
64 }); 64 if(existe.length > 0) {
65 return Promise.reject('Existe codigo de cisterna');
66 }else {
67 $scope.cisterna.idVehiculo = $routeParams.idVehiculo;
68 delete $scope.cisterna.unidadMedida;
69 delete $scope.cisterna.cisternaCarga.articulo;
70 return focaAbmVehiculoService.guardarCisterna($scope.cisterna);
71 }
72 }).then(function() {
73 $location.path('/vehiculo/' + $routeParams.idVehiculo);
74 }, function(rej) {
75 focaModalService.alert(rej);
76 });
65 }; 77 };
66 78
67 // $scope.seleccionarArticulo = function() { 79 // $scope.seleccionarArticulo = function() {
68 // var modalInstance = $uibModal.open( 80 // var modalInstance = $uibModal.open(
69 // { 81 // {
70 // ariaLabelledBy: 'Busqueda de Productos', 82 // ariaLabelledBy: 'Busqueda de Productos',
71 // templateUrl: 'modal-busqueda-productos.html', 83 // templateUrl: 'modal-busqueda-productos.html',
72 // controller: 'modalBusquedaProductosCtrl', 84 // controller: 'modalBusquedaProductosCtrl',
73 // resolve: { 85 // resolve: {
74 // parametroProducto: { 86 // parametroProducto: {
75 // idLista: -1, 87 // idLista: -1,
76 // cotizacion: 1, 88 // cotizacion: 1,
77 // simbolo: '$' 89 // simbolo: '$'
78 // } 90 // }
79 // }, 91 // },
80 // size: 'lg' 92 // size: 'lg'
81 // } 93 // }
82 // ); 94 // );
83 // modalInstance.result.then( 95 // modalInstance.result.then(
84 // function(producto) { 96 // function(producto) {
85 // $scope.cisterna.cisternaCarga.idProducto = producto.id, 97 // $scope.cisterna.cisternaCarga.idProducto = producto.id,
86 // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; 98 // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion;
87 // }, function() { 99 // }, function() {
88 // // funcion ejecutada cuando se cancela el modal 100 // // funcion ejecutada cuando se cancela el modal
89 // } 101 // }
90 // ); 102 // );
91 // }; 103 // };
92 104
93 $scope.seleccionarUnidadMedida = function() { 105 $scope.seleccionarUnidadMedida = function() {
94 var modalInstance = $uibModal.open( 106 var modalInstance = $uibModal.open(
95 { 107 {
96 ariaLabelledBy: 'Busqueda de Unidades de medida', 108 ariaLabelledBy: 'Busqueda de Unidades de medida',
97 templateUrl: 'modal-unidad-medida.html', 109 templateUrl: 'modal-unidad-medida.html',
98 controller: 'focaModalUnidadMedidaCtrl', 110 controller: 'focaModalUnidadMedidaCtrl',
99 size: 'lg' 111 size: 'lg'
100 } 112 }
101 ); 113 );
102 modalInstance.result.then(function(unidaMedida) { 114 modalInstance.result.then(function(unidaMedida) {
103 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 115 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
104 $scope.cisterna.unidadMedida = unidaMedida; 116 $scope.cisterna.unidadMedida = unidaMedida;
105 }); 117 });
106 }; 118 };
107 } 119 }
108 ]); 120 ]);
109 121