Commit 10b0f94bf65c6b0a37f615d3735f8cc100804ce3
1 parent
4bcdeb329c
Exists in
master
refactor guardar
Showing
3 changed files
with
63 additions
and
42 deletions
Show diff stats
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 | if(!$scope.vehiculo.transportista) { | 139 | //Valida si existe numero de unidad |
140 | focaModalService.alert('Elija Transportista'); | 140 | existeCodigoUnidad().then(function() { |
141 | return; | 141 | delete $scope.vehiculo.transportista; |
142 | } | 142 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
143 | focaAbmVehiculoService.getVehiculosPorTransportista($routeParams.idTransportista) | 143 | .then(function(res){ |
144 | .then(function(res) { | 144 | if($scope.nuevo) { |
145 | var existe = res.data.filter(function(vehiculo) { | 145 | $location.path('/vehiculo/' + res.data.id + |
146 | return vehiculo.codigo === $scope.vehiculo.codigo && | 146 | '/' + res.data.idTransportista); |
147 | vehiculo.id !== $scope.vehiculo.id; | 147 | } else { |
148 | $location.path('/vehiculo'); | ||
149 | } | ||
148 | }); | 150 | }); |
151 | }, function(){ | ||
152 | focaModalService.alert('Código de unidad existente'); | ||
153 | }); | ||
149 | 154 | ||
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 | }); | ||
166 | }; | 155 | }; |
167 | $scope.solicitarConfirmacionCisterna = function(cisterna) { | 156 | $scope.solicitarConfirmacionCisterna = function(cisterna) { |
168 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 157 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
169 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 158 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
170 | function(data) { | 159 | function(data) { |
171 | if(data) { | 160 | if(data) { |
172 | focaAbmVehiculoService.deleteCisterna(cisterna.id); | 161 | focaAbmVehiculoService.deleteCisterna(cisterna.id); |
173 | $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); | 162 | $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); |
174 | } | 163 | } |
175 | } | 164 | } |
176 | ); | 165 | ); |
177 | }; | 166 | }; |
178 | $scope.seleccionarTransportista = function() { | 167 | $scope.seleccionarTransportista = function() { |
179 | var modalInstance = $uibModal.open( | 168 | var modalInstance = $uibModal.open( |
180 | { | 169 | { |
181 | ariaLabelledBy: 'Busqueda de Transportista', | 170 | ariaLabelledBy: 'Busqueda de Transportista', |
182 | templateUrl: 'modal-proveedor.html', | 171 | templateUrl: 'modal-proveedor.html', |
183 | controller: 'focaModalProveedorCtrl', | 172 | controller: 'focaModalProveedorCtrl', |
184 | size: 'lg', | 173 | size: 'lg', |
185 | resolve: { | 174 | resolve: { |
186 | transportista: function() { | 175 | transportista: function() { |
187 | return true; | 176 | return true; |
188 | } | 177 | } |
189 | } | 178 | } |
190 | } | 179 | } |
191 | ); | 180 | ); |
192 | modalInstance.result.then( | 181 | modalInstance.result.then( |
193 | function(transportista) { | 182 | function(transportista) { |
194 | $scope.vehiculo.idTransportista = transportista.COD; | 183 | $scope.vehiculo.idTransportista = transportista.COD; |
195 | $scope.vehiculo.transportista = transportista; | 184 | $scope.vehiculo.transportista = transportista; |
196 | }, function() { | 185 | }, function() { |
197 | 186 | ||
198 | } | 187 | } |
199 | ); | 188 | ); |
200 | }; | 189 | }; |
190 | |||
191 | function existeCodigoUnidad(){ | ||
192 | return new Promise(function(resolve, reject) { | ||
193 | focaAbmVehiculoService | ||
194 | .getVehiculosPorTransportista($routeParams.idTransportista) | ||
195 | .then(function(res){ | ||
196 | //Valida si existe numero de unidad |
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 | focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) | 59 | existeCodigoCisterna().then(function() { |
60 | .then(function(res) { | 60 | $scope.cisterna.idVehiculo = $routeParams.idVehiculo; |
61 | var existe = res.data.filter(function(cisterna) { | 61 | delete $scope.cisterna.unidadMedida; |
62 | return cisterna.codigo === $scope.cisterna.codigo; | 62 | delete $scope.cisterna.cisternaCarga.articulo; |
63 | }); | 63 | focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ |
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); | 64 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
74 | }, function(rej) { | ||
75 | focaModalService.alert(rej); | ||
76 | }); | 65 | }); |
66 | }, function() { | ||
67 | focaModalService.alert('Código de cisterna existente'); | ||
68 | }); | ||
69 | |||
77 | }; | 70 | }; |
78 | 71 | ||
79 | // $scope.seleccionarArticulo = function() { | 72 | // $scope.seleccionarArticulo = function() { |
80 | // var modalInstance = $uibModal.open( | 73 | // var modalInstance = $uibModal.open( |
81 | // { | 74 | // { |
82 | // ariaLabelledBy: 'Busqueda de Productos', | 75 | // ariaLabelledBy: 'Busqueda de Productos', |
83 | // templateUrl: 'modal-busqueda-productos.html', | 76 | // templateUrl: 'modal-busqueda-productos.html', |
84 | // controller: 'modalBusquedaProductosCtrl', | 77 | // controller: 'modalBusquedaProductosCtrl', |
85 | // resolve: { | 78 | // resolve: { |
86 | // parametroProducto: { | 79 | // parametroProducto: { |
87 | // idLista: -1, | 80 | // idLista: -1, |
88 | // cotizacion: 1, | 81 | // cotizacion: 1, |
89 | // simbolo: '$' | 82 | // simbolo: '$' |
90 | // } | 83 | // } |
91 | // }, | 84 | // }, |
92 | // size: 'lg' | 85 | // size: 'lg' |
93 | // } | 86 | // } |
94 | // ); | 87 | // ); |
95 | // modalInstance.result.then( | 88 | // modalInstance.result.then( |
96 | // function(producto) { | 89 | // function(producto) { |
97 | // $scope.cisterna.cisternaCarga.idProducto = producto.id, | 90 | // $scope.cisterna.cisternaCarga.idProducto = producto.id, |
98 | // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; | 91 | // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; |
99 | // }, function() { | 92 | // }, function() { |
100 | // // funcion ejecutada cuando se cancela el modal | 93 | // // funcion ejecutada cuando se cancela el modal |
101 | // } | 94 | // } |
102 | // ); | 95 | // ); |
103 | // }; | 96 | // }; |
104 | 97 | ||
105 | $scope.seleccionarUnidadMedida = function() { | 98 | $scope.seleccionarUnidadMedida = function() { |
106 | var modalInstance = $uibModal.open( | 99 | var modalInstance = $uibModal.open( |
107 | { | 100 | { |
108 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 101 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
109 | templateUrl: 'modal-unidad-medida.html', | 102 | templateUrl: 'modal-unidad-medida.html', |
110 | controller: 'focaModalUnidadMedidaCtrl', | 103 | controller: 'focaModalUnidadMedidaCtrl', |
111 | size: 'lg' | 104 | size: 'lg' |
112 | } | 105 | } |
113 | ); | 106 | ); |
114 | modalInstance.result.then(function(unidaMedida) { | 107 | modalInstance.result.then(function(unidaMedida) { |
115 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 108 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
116 | $scope.cisterna.unidadMedida = unidaMedida; | 109 | $scope.cisterna.unidadMedida = unidaMedida; |
117 | }); | 110 | }); |
118 | }; | 111 | }; |
112 | |||
113 | function existeCodigoCisterna(){ | ||
114 | return new Promise(function(resolve, reject) { | ||
115 | focaAbmVehiculoService | ||
116 | .getCisternadoPorVehiculo($routeParams.idVehiculo) | ||
117 | .then(function(res){ | ||
118 | //Valida si existe numero de unidad | ||
119 | var existe = res.data.filter(function(cisterna) { | ||
120 | return cisterna.codigo === $scope.cisterna.codigo; | ||
121 | }); | ||
122 |
src/js/service.js
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 | return { | 3 | return { |
4 | getVehiculos: function() { | 4 | getVehiculos: function() { |
5 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 5 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); |
6 | }, | 6 | }, |
7 | getVehiculo: function(id) { | 7 | getVehiculo: function(id) { |
8 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 8 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); |
9 | }, | 9 | }, |
10 | getTransportistas: function() { | 10 | getTransportistas: function() { |
11 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 11 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
12 | }, | 12 | }, |
13 | guerdarVehiculo: function(vehiculo) { | 13 | guardarVehiculo: function(vehiculo) { |
14 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 14 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); |
15 | }, | 15 | }, |
16 | deleteVehiculo: function(id) { | 16 | deleteVehiculo: function(id) { |
17 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 17 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
18 | }, | 18 | }, |
19 | getCisternadoPorVehiculo: function(idVehiculo) { | 19 | getCisternadoPorVehiculo: function(idVehiculo) { |
20 | return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo); | 20 | return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo); |
21 | }, | 21 | }, |
22 | getCisterna: function(id) { | 22 | getCisterna: function(id) { |
23 | return $http.get(API_ENDPOINT.URL + '/cisterna/obtener/' + id); | 23 | return $http.get(API_ENDPOINT.URL + '/cisterna/obtener/' + id); |
24 | }, | 24 | }, |
25 | guardarCisterna: function(cisterna) { | 25 | guardarCisterna: function(cisterna) { |
26 | return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna}); | 26 | return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna}); |
27 | }, | 27 | }, |
28 | deleteCisterna: function(id) { | 28 | deleteCisterna: function(id) { |
29 | return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); | 29 | return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); |
30 | }, | 30 | }, |
31 | getVehiculosPorTransportista: function(id) { | 31 | getVehiculosPorTransportista: function(id) { |
32 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 32 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); |
33 | }, | 33 | }, |
34 | getTransportistaPorId: function(id) { | 34 | getTransportistaPorId: function(id) { |
35 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 35 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); |
36 | }, | 36 | }, |
37 | transportistaSeleccionado: {} | 37 | transportistaSeleccionado: {} |
38 | }; | 38 | }; |
39 | }]); | 39 | }]); |
40 | 40 |