Commit 598fe7adedbc20bd6a472c48e783317cc6ca794c

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

Merge branch 'master' into 'master'

arreglo error al guardar

See merge request !11
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, '/vehiculo'); 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 //Valida si existe numero de unidad 139 //Valida si existe numero de unidad
140 existeCodigoUnidad().then(function() { 140 existeCodigoUnidad().then(function() {
141 delete $scope.vehiculo.transportista; 141 delete $scope.vehiculo.transportista;
142 delete $scope.vehiculo.cisternas;
142 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 143 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
143 .then(function(res){ 144 .then(function(res){
144 if($scope.nuevo) { 145 if($scope.nuevo) {
145 $location.path('/vehiculo/' + res.data.id + 146 $location.path('/vehiculo/' + res.data.id +
146 '/' + res.data.idTransportista); 147 '/' + res.data.idTransportista);
147 } else { 148 } else {
148 $location.path('/vehiculo'); 149 $location.path('/vehiculo');
149 } 150 }
150 }); 151 });
151 }, function(){ 152 }, function(){
152 focaModalService.alert('Código de unidad existente'); 153 focaModalService.alert('Código de unidad existente');
153 }); 154 });
154 155
155 }; 156 };
156 $scope.solicitarConfirmacionCisterna = function(cisterna) { 157 $scope.solicitarConfirmacionCisterna = function(cisterna) {
157 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 158 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
158 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 159 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
159 function(data) { 160 function(data) {
160 if(data) { 161 if(data) {
161 focaAbmVehiculoService.deleteCisterna(cisterna.id); 162 focaAbmVehiculoService.deleteCisterna(cisterna.id);
162 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); 163 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1);
163 } 164 }
164 } 165 }
165 ); 166 );
166 }; 167 };
167 $scope.seleccionarTransportista = function() { 168 $scope.seleccionarTransportista = function() {
168 var modalInstance = $uibModal.open( 169 var modalInstance = $uibModal.open(
169 { 170 {
170 ariaLabelledBy: 'Busqueda de Transportista', 171 ariaLabelledBy: 'Busqueda de Transportista',
171 templateUrl: 'modal-proveedor.html', 172 templateUrl: 'modal-proveedor.html',
172 controller: 'focaModalProveedorCtrl', 173 controller: 'focaModalProveedorCtrl',
173 size: 'lg', 174 size: 'lg',
174 resolve: { 175 resolve: {
175 transportista: function() { 176 transportista: function() {
176 return true; 177 return true;
177 } 178 }
178 } 179 }
179 } 180 }
180 ); 181 );
181 modalInstance.result.then( 182 modalInstance.result.then(
182 function(transportista) { 183 function(transportista) {
183 $scope.vehiculo.idTransportista = transportista.COD; 184 $scope.vehiculo.idTransportista = transportista.COD;
184 $scope.vehiculo.transportista = transportista; 185 $scope.vehiculo.transportista = transportista;
185 }, function() { 186 }, function() {
186 187
187 } 188 }
188 ); 189 );
189 }; 190 };
190 191
191 function existeCodigoUnidad(){ 192 function existeCodigoUnidad(){
192 return new Promise(function(resolve, reject) { 193 return new Promise(function(resolve, reject) {
193 focaAbmVehiculoService 194 focaAbmVehiculoService
194 .getVehiculosPorTransportista($routeParams.idTransportista) 195 .getVehiculosPorTransportista($routeParams.idTransportista)
195 .then(function(res){ 196 .then(function(res){
196 //Valida si existe numero de unidad 197 //Valida si existe numero de unidad
197 var existe = res.data.filter(function(vehiculo) { 198 var existe = res.data.filter(function(vehiculo) {
198 return vehiculo.codigo === $scope.vehiculo.codigo && 199 return vehiculo.codigo === $scope.vehiculo.codigo &&
199 vehiculo.id !== $scope.vehiculo.id; 200 vehiculo.id !== $scope.vehiculo.id;
200 }); 201 });
201 202
202 if(existe.length){ 203 if(existe.length){
203 reject(existe); 204 reject(existe);
204 } else { 205 } else {
205 resolve(); 206 resolve();
206 } 207 }
207 }); 208 });
208 }); 209 });
209 } 210 }
210 } 211 }
211 ]); 212 ]);
212 213