Commit c6291d88104382b794dbaf64a73689127d9abd8c

Authored by Jose Pinto
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !25
1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const concat = require('gulp-concat'); 2 const concat = require('gulp-concat');
3 const htmlmin = require('gulp-htmlmin'); 3 const htmlmin = require('gulp-htmlmin');
4 const rename = require('gulp-rename'); 4 const rename = require('gulp-rename');
5 const uglify = require('gulp-uglify-es').default; 5 const uglify = require('gulp-uglify-es').default;
6 const gulp = require('gulp'); 6 const gulp = require('gulp');
7 const pump = require('pump'); 7 const pump = require('pump');
8 const jshint = require('gulp-jshint'); 8 const jshint = require('gulp-jshint');
9 const replace = require('gulp-replace'); 9 const replace = require('gulp-replace');
10 const connect = require('gulp-connect'); 10 const connect = require('gulp-connect');
11 const clean = require('gulp-clean'); 11 const clean = require('gulp-clean');
12 12
13 var paths = { 13 var paths = {
14 srcJS: 'src/js/*.js', 14 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 15 srcViews: 'src/views/*.html',
16 tmp: 'tmp', 16 tmp: 'tmp',
17 dist: 'dist/' 17 dist: 'dist/'
18 }; 18 };
19 19
20 gulp.task('templates', function() { 20 gulp.task('templates', function() {
21 return pump( 21 return pump(
22 [ 22 [
23 gulp.src(paths.srcViews), 23 gulp.src(paths.srcViews),
24 replace('views/', ''), 24 replace('views/', ''),
25 htmlmin(), 25 htmlmin(),
26 templateCache('views.js', { 26 templateCache('views.js', {
27 module: 'focaAbmVehiculo', 27 module: 'focaAbmVehiculo',
28 root: '' 28 root: ''
29 }), 29 }),
30 gulp.dest(paths.tmp) 30 gulp.dest(paths.tmp)
31 ] 31 ]
32 ); 32 );
33 }); 33 });
34 34
35 gulp.task('uglify', ['templates'], function() { 35 gulp.task('uglify', ['templates'], function() {
36 return pump( 36 return pump(
37 [ 37 [
38 gulp.src([ 38 gulp.src([
39 paths.srcJS, 39 paths.srcJS,
40 'tmp/views.js' 40 'tmp/views.js'
41 ]), 41 ]),
42 concat('foca-abm-vehiculo.js'), 42 concat('foca-abm-vehiculo.js'),
43 replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'), 43 replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'),
44 replace("src/views/", ''), 44 replace("src/views/", ''),
45 gulp.dest(paths.tmp), 45 gulp.dest(paths.tmp),
46 rename('foca-abm-vehiculo.min.js'), 46 rename('foca-abm-vehiculo.min.js'),
47 uglify(), 47 uglify(),
48 gulp.dest(paths.dist) 48 gulp.dest(paths.dist)
49 ] 49 ]
50 ); 50 );
51 }); 51 });
52 52
53 gulp.task('clean', function() { 53 gulp.task('clean', function() {
54 return gulp.src(['tmp', 'dist'], {read: false}) 54 return gulp.src(['tmp', 'dist'], {read: false})
55 .pipe(clean()); 55 .pipe(clean());
56 }); 56 });
57 57
58 gulp.task('pre-commit', function() { 58 gulp.task('pre-commit', function() {
59 pump( 59 return pump(
60 [ 60 [
61 gulp.src(paths.srcJS), 61 gulp.src(paths.srcJS),
62 jshint('.jshintrc'), 62 jshint('.jshintrc'),
63 jshint.reporter('default'), 63 jshint.reporter('default'),
64 jshint.reporter('fail') 64 jshint.reporter('fail')
65 ] 65 ]
66 ); 66 );
67
68 gulp.start('uglify');
69 }); 67 });
70 68
71 gulp.task('clean-post-install', function() { 69 gulp.task('clean-post-install', function() {
72 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 70 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
73 'index.html'], {read: false}) 71 'index.html'], {read: false})
74 .pipe(clean()); 72 .pipe(clean());
75 }); 73 });
76 74
77 gulp.task('compile', ['templates', 'uglify']); 75 gulp.task('compile', ['templates', 'uglify']);
78 76
79 gulp.task('watch', function() { 77 gulp.task('watch', function() {
80 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 78 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
81 }); 79 });
82 80
83 gulp.task('webserver', function() { 81 gulp.task('webserver', function() {
84 pump [ 82 pump [
85 connect.server({port: 3000}) 83 connect.server({port: 3000})
86 ] 84 ]
87 }); 85 });
88 86
89 gulp.task('default', ['webserver']); 87 gulp.task('default', ['webserver']);
90 88
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 focaAbmVehiculoService.cleanCisternas(); 14 focaAbmVehiculoService.cleanCisternas();
15 15
16 //SETEO BOTONERA LATERAL 16 //SETEO BOTONERA LATERAL
17 focaBotoneraLateralService.showSalir(false); 17 focaBotoneraLateralService.showSalir(false);
18 focaBotoneraLateralService.showPausar(false); 18 focaBotoneraLateralService.showPausar(false);
19 focaBotoneraLateralService.showCancelar(false); 19 focaBotoneraLateralService.showCancelar(false);
20 focaBotoneraLateralService.showGuardar(false); 20 focaBotoneraLateralService.showGuardar(false);
21 focaBotoneraLateralService.addCustomButton('Salir', salir); 21 focaBotoneraLateralService.addCustomButton('Salir', salir);
22 22
23 if(focaAbmVehiculoService.transportistaSeleccionado.COD) { 23 if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
25 } 25 }
26 $scope.editar = function(id) { 26 $scope.editar = function(id) {
27 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 27 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
28 }; 28 };
29 $scope.solicitarConfirmacion = function(vehiculo) { 29 $scope.solicitarConfirmacion = function(vehiculo) {
30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
31 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 31 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
32 function(data) { 32 function(data) {
33 if(data) { 33 if(data) {
34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
36 } 36 }
37 } 37 }
38 ); 38 );
39 }; 39 };
40 $scope.seleccionarTransportista = function() { 40 $scope.seleccionarTransportista = function() {
41 var parametrosModal = { 41 var parametrosModal = {
42 titulo: 'Búsqueda de Transportista', 42 titulo: 'Búsqueda de Transportista',
43 query: '/transportista', 43 query: '/transportista',
44 columnas: [ 44 columnas: [
45 { 45 {
46 nombre: 'Código', 46 nombre: 'Código',
47 propiedad: 'COD' 47 propiedad: 'COD'
48 }, 48 },
49 { 49 {
50 nombre: 'Nombre', 50 nombre: 'Nombre',
51 propiedad: 'NOM' 51 propiedad: 'NOM'
52 }, 52 },
53 { 53 {
54 nombre: 'CUIT', 54 nombre: 'CUIT',
55 propiedad: 'CUIT' 55 propiedad: 'CUIT'
56 } 56 }
57 ] 57 ]
58 }; 58 };
59 focaModalService.modal(parametrosModal).then( 59 focaModalService.modal(parametrosModal).then(
60 function(transportista) { 60 function(transportista) {
61 elegirTransportista(transportista); 61 elegirTransportista(transportista);
62 focaAbmVehiculoService.transportistaSeleccionado = transportista; 62 focaAbmVehiculoService.transportistaSeleccionado = transportista;
63 }, function() { 63 }, function() {
64 64
65 } 65 }
66 ); 66 );
67 }; 67 };
68 68
69 function elegirTransportista(transportista) { 69 function elegirTransportista(transportista) {
70 var codigo = ('00000' + transportista.COD).slice(-5); 70 var codigo = ('00000' + transportista.COD).slice(-5);
71 $scope.idTransportista = transportista.COD; 71 $scope.idTransportista = transportista.COD;
72 $scope.filtros = transportista.NOM.trim(); 72 $scope.filtros = transportista.NOM.trim();
73 $timeout(function() { 73 $timeout(function() {
74 $scope.$broadcast('addCabecera', { 74 $scope.$broadcast('addCabecera', {
75 label: 'Transportista:', 75 label: 'Transportista:',
76 valor: codigo + ' - ' + transportista.NOM 76 valor: codigo + ' - ' + transportista.NOM
77 }); 77 });
78 }); 78 });
79 buscar(transportista.COD); 79 buscar(transportista.COD);
80 } 80 }
81 81
82 function buscar(idTransportista) { 82 function buscar(idTransportista) {
83 focaAbmVehiculoService 83 focaAbmVehiculoService
84 .getVehiculosPorTransportista(idTransportista) 84 .getVehiculosPorTransportista(idTransportista)
85 .then(function(datos) { 85 .then(function(datos) {
86 $scope.vehiculos = datos.data; 86 $scope.vehiculos = datos.data;
87 }); 87 });
88 } 88 }
89 function salir() { 89 function salir() {
90 focaAbmVehiculoService.transportistaSeleccionado = {}; 90 focaAbmVehiculoService.transportistaSeleccionado = {};
91 $location.path('/'); 91 $location.path('/');
92 } 92 }
93 } 93 }
94 ]) 94 ])
95 .controller('focaAbmVehiculoController', [ 95 .controller('focaAbmVehiculoController', [
96 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 96 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
97 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', 97 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window',
98 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 98 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
99 focaModalService, $timeout, focaBotoneraLateralService, $window) { 99 focaModalService, $timeout, focaBotoneraLateralService, $window) {
100 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 100 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
101 $scope.now = new Date(); 101 $scope.now = new Date();
102 $scope.focused = 1; 102 $scope.focused = 1;
103 $scope.transportistaStamp = ''; 103 $scope.transportistaStamp = '';
104 $scope.cisternas = []; 104 $scope.cisternas = [];
105 105
106 $timeout(function() { 106 $timeout(function() {
107 focaBotoneraLateralService.showSalir(false); 107 focaBotoneraLateralService.showSalir(false);
108 focaBotoneraLateralService.showPausar(false); 108 focaBotoneraLateralService.showPausar(false);
109 focaBotoneraLateralService.showCancelar(false); 109 focaBotoneraLateralService.showCancelar(false);
110 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 110 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
111 focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); 111 focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar);
112 }); 112 });
113 113
114 if($scope.nuevo) { 114 if($scope.nuevo) {
115 focaAbmVehiculoService 115 focaAbmVehiculoService
116 .getTransportistaPorId($routeParams.idTransportista) 116 .getTransportistaPorId($routeParams.idTransportista)
117 .then(function(res) { 117 .then(function(res) {
118 var codigo = ('00000' + res.data.COD).slice(-5); 118 var codigo = ('00000' + res.data.COD).slice(-5);
119 $scope.vehiculo.idTransportista = res.data.COD; 119 $scope.vehiculo.idTransportista = res.data.COD;
120 $scope.vehiculo.transportista = res.data; 120 $scope.vehiculo.transportista = res.data;
121 $scope.$broadcast('addCabecera', { 121 $scope.$broadcast('addCabecera', {
122 label: 'Transportista:', 122 label: 'Transportista:',
123 valor: codigo + ' - ' + res.data.NOM 123 valor: codigo + ' - ' + res.data.NOM
124 }); 124 });
125 }); 125 });
126 } 126 }
127 $scope.vehiculo = {}; 127 $scope.vehiculo = {};
128 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 128 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
129 if(res.data) { 129 if(res.data) {
130 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 130 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
131 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; 131 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
132 132
133 $scope.vehiculo = res.data; 133 $scope.vehiculo = res.data;
134 $scope.$broadcast('addCabecera', { 134 $scope.$broadcast('addCabecera', {
135 label: 'Transportista:', 135 label: 'Transportista:',
136 valor: $scope.transportistaStamp 136 valor: $scope.transportistaStamp
137 }); 137 });
138 $scope.$broadcast('addCabecera', { 138 $scope.$broadcast('addCabecera', {
139 label: 'Unidad:', 139 label: 'Unidad:',
140 valor: res.data.codigo 140 valor: res.data.codigo
141 }); 141 });
142 focaAbmVehiculoService 142 focaAbmVehiculoService
143 .getCisternas($routeParams.idVehiculo) 143 .getCisternas($routeParams.idVehiculo)
144 .then(function(res) { 144 .then(function(res) {
145 $scope.cisternas = res; 145 $scope.cisternas = res;
146 $scope.$apply(); 146 $scope.$apply();
147 }); 147 });
148 } 148 }
149 }); 149 });
150 150
151 $scope.next = function(key) { 151 $scope.next = function(key) {
152 if (key === 13) $scope.focused++; 152 if (key === 13) $scope.focused++;
153 }; 153 };
154 $scope.cancelar = function() { 154 $scope.cancelar = function() {
155 $location.path('/vehiculo'); 155 $location.path('/vehiculo');
156 }; 156 };
157 $scope.editar = function(key) { 157 $scope.editar = function(key) {
158 if(key) { 158 if(key) {
159 $location.path('/vehiculo/' + $routeParams.idVehiculo + 159 $location.path('/vehiculo/' + $routeParams.idVehiculo +
160 '/cisterna/' + key); 160 '/cisterna/' + key);
161 }else { 161 }else {
162 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); 162 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/');
163 } 163 }
164 }; 164 };
165 $scope.guardar = function(key) { 165 $scope.guardar = function(key) {
166 key = (typeof key === 'undefined') ? 13 : key; 166 key = (typeof key === 'undefined') ? 13 : key;
167 if(key === 13) { 167 if(key === 13) {
168 //Valida si existe numero de unidad 168 //Valida si existe numero de unidad
169 if(!validaTotalCargas() && !$scope.nuevo) { 169 if(!validaTotalCargas() && !$scope.nuevo) {
170 focaModalService.alert('La suma de las capacidades de las cisternas' + 170 focaModalService.alert('La suma de las capacidades de las cisternas' +
171 ' debe ser igual a la capacidad total del vehículo'); 171 ' debe ser igual a la capacidad total del vehículo');
172 return; 172 return;
173 } 173 }
174 validaCodigoUnidad().then(function() { 174 validaCodigoUnidad().then(function() {
175 delete $scope.vehiculo.transportista; 175 delete $scope.vehiculo.transportista;
176 delete $scope.vehiculo.cisternas; 176 delete $scope.vehiculo.cisternas;
177 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 177 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
178 .then(function(res) { 178 .then(function(res) {
179 if($scope.nuevo) { 179 if($scope.nuevo) {
180 $location.path('/vehiculo/' + res.data.id + 180 $location.path('/vehiculo/' + res.data.id +
181 '/' + res.data.idTransportista); 181 '/' + res.data.idTransportista);
182 }else { 182 }else {
183 guardarCisternas().then(function() { 183 guardarCisternas().then(function() {
184 $window.location.assign('/#!/vehiculo'); 184 $window.location.assign('/#!/vehiculo');
185 }); 185 });
186 } 186 }
187 }); 187 });
188 }, function() { 188 }, function() {
189 focaModalService.alert('Código de unidad existente'); 189 focaModalService.alert('Código de unidad existente');
190 }); 190 });
191 } 191 }
192 192
193 }; 193 };
194 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { 194 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
195 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 195 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
196 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 196 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
197 function(data) { 197 function(data) {
198 if(data) { 198 if(data) {
199 focaAbmVehiculoService.deleteCisterna(idx); 199 focaAbmVehiculoService.deleteCisterna(idx);
200 focaAbmVehiculoService 200 focaAbmVehiculoService
201 .getCisternas($routeParams.idVehiculo) 201 .getCisternas($routeParams.idVehiculo)
202 .then(function(res) { 202 .then(function(res) {
203 $scope.cisternas = res; 203 $scope.cisternas = res;
204 }); 204 });
205 } 205 }
206 } 206 }
207 ); 207 );
208 }; 208 };
209 209
210 function validaCodigoUnidad() { 210 function validaCodigoUnidad() {
211 return new Promise(function(resolve, reject) { 211 return new Promise(function(resolve, reject) {
212 focaAbmVehiculoService 212 focaAbmVehiculoService
213 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 213 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
214 .then(function(res) { 214 .then(function(res) {
215 //Valida si existe numero de unidad 215 //Valida si existe numero de unidad
216 var existe = res.data.filter(function(vehiculo) { 216 var existe = res.data.filter(function(vehiculo) {
217 return vehiculo.codigo === $scope.vehiculo.codigo && 217 return vehiculo.codigo === $scope.vehiculo.codigo &&
218 vehiculo.id !== $scope.vehiculo.id; 218 vehiculo.id !== $scope.vehiculo.id;
219 }); 219 });
220 220
221 if(existe.length) { 221 if(existe.length) {
222 reject(existe); 222 reject(existe);
223 }else { 223 }else {
224 resolve(); 224 resolve();
225 } 225 }
226 }); 226 });
227 }); 227 });
228 } 228 }
229 229
230 function validaTotalCargas() { 230 function validaTotalCargas() {
231 var total = 0; 231 var total = 0;
232 $scope.cisternas.forEach(function(cisterna) { 232 $scope.cisternas.forEach(function(cisterna) {
233 if(!cisterna.desactivado) { 233 if(!cisterna.desactivado) {
234 total += parseInt(cisterna.capacidad); 234 total += parseInt(cisterna.capacidad);
235 } 235 }
236 }); 236 });
237 return $scope.vehiculo.capacidad == total; 237 return $scope.vehiculo.capacidad === total;
238 } 238 }
239 239
240 function guardarCisternas() { 240 function guardarCisternas() {
241 var cisternas = $scope.cisternas.map(function(cisterna) { 241 var cisternas = $scope.cisternas.map(function(cisterna) {
242 return { 242 return {
243 id: cisterna.id, 243 id: cisterna.id,
244 capacidad: parseFloat(cisterna.capacidad), 244 capacidad: parseFloat(cisterna.capacidad),
245 codigo: cisterna.codigo, 245 codigo: cisterna.codigo,
246 idUnidadMedida: cisterna.idUnidadMedida, 246 idUnidadMedida: cisterna.idUnidadMedida,
247 idVehiculo: $routeParams.idVehiculo, 247 idVehiculo: $routeParams.idVehiculo,
248 desactivado: cisterna.desactivado 248 desactivado: cisterna.desactivado
249 }; 249 };
250 }); 250 });
251 251
252 return focaAbmVehiculoService.guardarCisternas(cisternas); 252 return focaAbmVehiculoService.guardarCisternas(cisternas);
253 } 253 }
254 } 254 }
255 ]); 255 ]);
256 256
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', '$window', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout, $window) { 6 focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 $scope.nuevo = ($routeParams.id > 0) ? false : true; 7 $scope.nuevo = ($routeParams.id > 0) ? false : true;
8 $scope.editar = false; 8 $scope.editar = false;
9 $scope.now = new Date(); 9 $scope.now = new Date();
10 $scope.cisterna = {}; 10 $scope.cisterna = {};
11 11
12 $scope.focused = $scope.nuevo ? 1 : 2; 12 $scope.focused = $scope.nuevo ? 1 : 2;
13 $scope.next = function(key) { 13 $scope.next = function(key) {
14 if (key === 13) $scope.focused++; 14 if (key === 13) $scope.focused++;
15 }; 15 };
16 $scope.capacidadVechiulo = 0; 16 $scope.capacidadVechiulo = 0;
17 $scope.transportista = ''; 17 $scope.transportista = '';
18 18
19 //SETEO BOTONERA LATERAL 19 //SETEO BOTONERA LATERAL
20 $timeout(function() { 20 $timeout(function() {
21 focaBotoneraLateralService.showSalir(false); 21 focaBotoneraLateralService.showSalir(false);
22 focaBotoneraLateralService.showPausar(false); 22 focaBotoneraLateralService.showPausar(false);
23 focaBotoneraLateralService.showCancelar(true); 23 focaBotoneraLateralService.showCancelar(true);
24 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 24 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
25 }); 25 });
26 26
27 if($routeParams.idx !== -1) { 27 if($routeParams.idx !== -1) {
28 $scope.cisterna = [$routeParams.idx] 28 $scope.cisterna = [$routeParams.idx];
29 focaAbmVehiculoService 29 focaAbmVehiculoService
30 .getCisternas($routeParams.idVehiculo) 30 .getCisternas($routeParams.idVehiculo)
31 .then(function(res) { 31 .then(function(res) {
32 $scope.cisterna = res[$routeParams.idx]; 32 $scope.cisterna = res[$routeParams.idx];
33 }); 33 });
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.transportista = res.data.transportista.COD; 38 $scope.transportista = res.data.transportista.COD;
39 $scope.capacidadVechiulo = res.data.capacidad; 39 $scope.capacidadVechiulo = res.data.capacidad;
40 $scope.$broadcast('addCabecera', { 40 $scope.$broadcast('addCabecera', {
41 label: 'Transportista:', 41 label: 'Transportista:',
42 valor: codigo + ' - ' + res.data.transportista.NOM 42 valor: codigo + ' - ' + res.data.transportista.NOM
43 }); 43 });
44 $scope.$broadcast('addCabecera', { 44 $scope.$broadcast('addCabecera', {
45 label: 'Unidad:', 45 label: 'Unidad:',
46 valor: res.data.codigo 46 valor: res.data.codigo
47 }); 47 });
48 $scope.$broadcast('addCabecera', { 48 $scope.$broadcast('addCabecera', {
49 label: 'Capacidad total vehículo:', 49 label: 'Capacidad total vehículo:',
50 valor: res.data.capacidad 50 valor: res.data.capacidad
51 }); 51 });
52 }); 52 });
53 $scope.cancelar = function() { 53 $scope.cancelar = function() {
54 $location.path('/vehiculo/' + $routeParams.idVehiculo); 54 $location.path('/vehiculo/' + $routeParams.idVehiculo);
55 }; 55 };
56 $scope.guardar = function() { 56 $scope.guardar = function() {
57 if(!$scope.cisterna.unidadMedida) { 57 if(!$scope.cisterna.unidadMedida) {
58 focaModalService.alert('Ingrese unidad de medida'); 58 focaModalService.alert('Ingrese unidad de medida');
59 return; 59 return;
60 } 60 }
61 validaCodigoCapacidad() 61 validaCodigoCapacidad()
62 .then(function() { 62 .then(function() {
63 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); 63 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
64 delete $scope.cisterna.vehiculo; 64 delete $scope.cisterna.vehiculo;
65 65
66 focaAbmVehiculoService 66 focaAbmVehiculoService
67 .guardarCisterna($scope.cisterna, $routeParams.idx); 67 .guardarCisterna($scope.cisterna, $routeParams.idx);
68 68
69 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + 69 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo +
70 '/' + $scope.transportista); 70 '/' + $scope.transportista);
71 }, function(err) { 71 }, function(err) {
72 focaModalService.alert(err); 72 focaModalService.alert(err);
73 }); 73 });
74 74
75 }; 75 };
76 76
77 $scope.seleccionarUnidadMedida = function() { 77 $scope.seleccionarUnidadMedida = function() {
78 var modalInstance = $uibModal.open( 78 var modalInstance = $uibModal.open(
79 { 79 {
80 ariaLabelledBy: 'Busqueda de Unidades de medida', 80 ariaLabelledBy: 'Busqueda de Unidades de medida',
81 templateUrl: 'modal-unidad-medida.html', 81 templateUrl: 'modal-unidad-medida.html',
82 controller: 'focaModalUnidadMedidaCtrl', 82 controller: 'focaModalUnidadMedidaCtrl',
83 size: 'lg' 83 size: 'lg'
84 } 84 }
85 ); 85 );
86 modalInstance.result.then(function(unidaMedida) { 86 modalInstance.result.then(function(unidaMedida) {
87 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 87 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
88 $scope.cisterna.unidadMedida = unidaMedida; 88 $scope.cisterna.unidadMedida = unidaMedida;
89 }); 89 });
90 }; 90 };
91 91
92 function validaCodigoCapacidad() { 92 function validaCodigoCapacidad() {
93 return new Promise(function(resolve, reject) { 93 return new Promise(function(resolve, reject) {
94 focaAbmVehiculoService 94 focaAbmVehiculoService
95 .getCisternas($routeParams.idVehiculo) 95 .getCisternas($routeParams.idVehiculo)
96 .then(function(res) { 96 .then(function(res) {
97 var cisternas = res; 97 var cisternas = res;
98 var totalCargado = 0; 98 var totalCargado = 0;
99 cisternas.forEach(function(cisterna, idx) { 99 cisternas.forEach(function(cisterna, idx) {
100 //SI EL CODIGO YA EXISTE 100 //SI EL CODIGO YA EXISTE
101 if(cisterna.codigo === $scope.cisterna.codigo && 101 if(cisterna.codigo === $scope.cisterna.codigo &&
102 idx != $routeParams.idx && 102 idx !== $routeParams.idx &&
103 !cisterna.desactivado) { 103 !cisterna.desactivado) {
104 reject('Código de cisterna existente'); 104 reject('Código de cisterna existente');
105 } 105 }
106 if(idx != $routeParams.idx && 106 if(idx !== $routeParams.idx &&
107 !cisterna.desactivado) { 107 !cisterna.desactivado) {
108 totalCargado += cisterna.capacidad; 108 totalCargado += cisterna.capacidad;
109 } 109 }
110 }); 110 });
111 111
112 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO 112 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO
113 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); 113 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad);
114 if(totalCargado > $scope.capacidadVechiulo) { 114 if(totalCargado > $scope.capacidadVechiulo) {
115 reject('La capacidad total de las cisternas' + 115 reject('La capacidad total de las cisternas' +
116 ' no debe ser mayor a la del vehiculo'); 116 ' no debe ser mayor a la del vehiculo');
117 }else { 117 }else {
118 resolve(); 118 resolve();
119 } 119 }
120 }); 120 });
121 }); 121 });
122 } 122 }
123 } 123 }
124 ]); 124 ]);
125 125
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 var cisternas = [];
4 return { 4 return {
5 getVehiculos: function() { 5 getVehiculos: function() {
6 return $http.get(API_ENDPOINT.URL + '/vehiculo'); 6 return $http.get(API_ENDPOINT.URL + '/vehiculo');
7 }, 7 },
8 getVehiculo: function(id) { 8 getVehiculo: function(id) {
9 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); 9 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
10 }, 10 },
11 getTransportistas: function() { 11 getTransportistas: function() {
12 return $http.get(API_ENDPOINT.URL + '/transportista'); 12 return $http.get(API_ENDPOINT.URL + '/transportista');
13 }, 13 },
14 guardarVehiculo: function(vehiculo) { 14 guardarVehiculo: function(vehiculo) {
15 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); 15 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
16 }, 16 },
17 deleteVehiculo: function(id) { 17 deleteVehiculo: function(id) {
18 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); 18 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
19 }, 19 },
20 getCisternas: function(idVehiculo) { 20 getCisternas: function(idVehiculo) {
21 if(cisternas.length) { 21 if(cisternas.length) {
22 return Promise.resolve(angular.copy(cisternas)); 22 return Promise.resolve(angular.copy(cisternas));
23 }else { 23 }else {
24 return new Promise(function(resolve, reject) { 24 return new Promise(function(resolve) {
25 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) 25 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo)
26 .then(function(res) { 26 .then(function(res) {
27 cisternas = res.data; 27 cisternas = res.data;
28 resolve(res.data); 28 resolve(res.data);
29 }); 29 });
30 }); 30 });
31 } 31 }
32 }, 32 },
33 guardarCisterna: function(cisterna, idx) { 33 guardarCisterna: function(cisterna, idx) {
34 if(idx != -1) { 34 if(idx !== -1) {
35 //update 35 //update
36 cisternas[idx] = cisterna; 36 cisternas[idx] = cisterna;
37 }else { 37 }else {
38 //insert 38 //insert
39 cisternas.push(cisterna); 39 cisternas.push(cisterna);
40 } 40 }
41 }, 41 },
42 guardarCisternas: function(cisternas) { 42 guardarCisternas: function(cisternas) {
43 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); 43 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas});
44 }, 44 },
45 deleteCisterna: function(idx) { 45 deleteCisterna: function(idx) {
46 cisternas[idx].desactivado = true; 46 cisternas[idx].desactivado = true;
47 }, 47 },
48 cleanCisternas: function() { 48 cleanCisternas: function() {
49 cisternas = []; 49 cisternas = [];
50 }, 50 },
51 getVehiculosPorTransportista: function(id) { 51 getVehiculosPorTransportista: function(id) {
52 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); 52 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
53 }, 53 },
54 getTransportistaPorId: function(id) { 54 getTransportistaPorId: function(id) {
55 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 55 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
56 }, 56 },
57 transportistaSeleccionado: {} 57 transportistaSeleccionado: {}
58 }; 58 };
59 }]); 59 }]);
60 60