Commit 24c7093d71bef134185148a207d2d0d7124377ce

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

Merge branch 'master' into 'master'

Master

See merge request !19
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.editar = false; 8 $scope.editar = false;
8 $scope.now = new Date(); 9 $scope.now = new Date();
9 $scope.cisterna = {}; 10 $scope.cisterna = {};
10 11
11 $scope.focused = 1; 12 $scope.focused = $scope.nuevo ? 1 : 2;
12 $scope.next = function(key) { 13 $scope.next = function(key) {
13 if (key === 13) $scope.focused++; 14 if (key === 13) $scope.focused++;
14 }; 15 };
15 $scope.capacidadVechiulo = 0; 16 $scope.capacidadVechiulo = 0;
16 $scope.transportista = ''; 17 $scope.transportista = '';
17 18
18 //SETEO BOTONERA LATERAL 19 //SETEO BOTONERA LATERAL
19 $timeout(function() { 20 $timeout(function() {
20 focaBotoneraLateralService.showSalir(false); 21 focaBotoneraLateralService.showSalir(false);
21 focaBotoneraLateralService.showPausar(false); 22 focaBotoneraLateralService.showPausar(false);
22 focaBotoneraLateralService.showCancelar(true); 23 focaBotoneraLateralService.showCancelar(true);
23 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 24 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
24 }); 25 });
25 26
26 27
27 if($routeParams.idTemp != undefined) { 28 if($routeParams.idTemp != undefined) {
28 $scope.cisterna = focaAbmVehiculoService.getCisternasLocal()[$routeParams.idTemp]; 29 $scope.cisterna = focaAbmVehiculoService.getCisternasLocal()[$routeParams.idTemp];
29 }else { 30 }else {
30 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { 31 focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) {
31 if(res.data) $scope.cisterna = res.data; 32 if(res.data) $scope.cisterna = res.data;
32 }); 33 });
33 } 34 }
34 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 35 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
35 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 36 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
36 $scope.transportista = res.data.transportista.COD; 37 $scope.transportista = res.data.transportista.COD;
37 $scope.capacidadVechiulo = res.data.capacidad; 38 $scope.capacidadVechiulo = res.data.capacidad;
38 $scope.$broadcast('addCabecera', { 39 $scope.$broadcast('addCabecera', {
39 label: 'Transportista:', 40 label: 'Transportista:',
40 valor: codigo + ' - ' + res.data.transportista.NOM 41 valor: codigo + ' - ' + res.data.transportista.NOM
41 }); 42 });
42 $scope.$broadcast('addCabecera', { 43 $scope.$broadcast('addCabecera', {
43 label: 'Unidad:', 44 label: 'Unidad:',
44 valor: res.data.codigo 45 valor: res.data.codigo
45 }); 46 });
46 $scope.$broadcast('addCabecera', { 47 $scope.$broadcast('addCabecera', {
47 label: 'Capacidad total vehículo:', 48 label: 'Capacidad total vehículo:',
48 valor: res.data.capacidad 49 valor: res.data.capacidad
49 }); 50 });
50 }); 51 });
51 $scope.cancelar = function() { 52 $scope.cancelar = function() {
52 $location.path('/vehiculo/' + $routeParams.idVehiculo); 53 $location.path('/vehiculo/' + $routeParams.idVehiculo);
53 }; 54 };
54 $scope.guardar = function() { 55 $scope.guardar = function() {
55 if(!$scope.cisterna.unidadMedida) { 56 if(!$scope.cisterna.unidadMedida) {
56 focaModalService.alert('Ingrese unidad de medida'); 57 focaModalService.alert('Ingrese unidad de medida');
57 return; 58 return;
58 } 59 }
59 validaCodigoCapacidad().then(function() { 60 validaCodigoCapacidad().then(function() {
60 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); 61 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
61 delete $scope.cisterna.vehiculo; 62 delete $scope.cisterna.vehiculo;
62 63
63 if($routeParams.idTemp != undefined) { 64 if($routeParams.idTemp != undefined) {
64 //SI SE EDITA UNA CISTERNA LOCALMENTE 65 //SI SE EDITA UNA CISTERNA LOCALMENTE
65 focaAbmVehiculoService 66 focaAbmVehiculoService
66 .guardarCisternaLocal($scope.cisterna, $routeParams.idTemp); 67 .guardarCisternaLocal($scope.cisterna, $routeParams.idTemp);
67 }else if($scope.cisterna.id) { 68 }else if($scope.cisterna.id) {
68 //SI SE EDITA UNA CISTERNA PREVIAMENTE GUARDADA 69 //SI SE EDITA UNA CISTERNA PREVIAMENTE GUARDADA
69 focaAbmVehiculoService.deleteCisterna($scope.cisterna.id); 70 focaAbmVehiculoService.deleteCisterna($scope.cisterna.id);
70 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); 71 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna);
71 }else { 72 }else {
72 //SI SE EDITA CREA UNA NUEVA CISTERNA 73 //SI SE EDITA CREA UNA NUEVA CISTERNA
73 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); 74 focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna);
74 } 75 }
75 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + 76 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo +
76 '/' + $scope.transportista); 77 '/' + $scope.transportista);
77 }, function(err) { 78 }, function(err) {
78 focaModalService.alert(err); 79 focaModalService.alert(err);
79 }); 80 });
80 81
81 }; 82 };
82 83
83 $scope.seleccionarUnidadMedida = function() { 84 $scope.seleccionarUnidadMedida = function() {
84 var modalInstance = $uibModal.open( 85 var modalInstance = $uibModal.open(
85 { 86 {
86 ariaLabelledBy: 'Busqueda de Unidades de medida', 87 ariaLabelledBy: 'Busqueda de Unidades de medida',
87 templateUrl: 'modal-unidad-medida.html', 88 templateUrl: 'modal-unidad-medida.html',
88 controller: 'focaModalUnidadMedidaCtrl', 89 controller: 'focaModalUnidadMedidaCtrl',
89 size: 'lg' 90 size: 'lg'
90 } 91 }
91 ); 92 );
92 modalInstance.result.then(function(unidaMedida) { 93 modalInstance.result.then(function(unidaMedida) {
93 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 94 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
94 $scope.cisterna.unidadMedida = unidaMedida; 95 $scope.cisterna.unidadMedida = unidaMedida;
95 }); 96 });
96 }; 97 };
97 98
98 function validaCodigoCapacidad() { 99 function validaCodigoCapacidad() {
99 return new Promise(function(resolve, reject) { 100 return new Promise(function(resolve, reject) {
100 focaAbmVehiculoService 101 focaAbmVehiculoService
101 .getCisternadoPorVehiculo($routeParams.idVehiculo) 102 .getCisternadoPorVehiculo($routeParams.idVehiculo)
102 .then(function(res) { 103 .then(function(res) {
103 var cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data); 104 var cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data);
104 var totalCargado = 0; 105 var totalCargado = 0;
105 106
106 cisternas.forEach(function(cisterna) { 107 cisternas.forEach(function(cisterna) {
107 //SI EL CODIGO YA EXISTE 108 //SI EL CODIGO YA EXISTE
108 if(cisterna.codigo === $scope.cisterna.codigo && 109 if(cisterna.codigo === $scope.cisterna.codigo &&
109 (cisterna.id !== $scope.cisterna.id || 110 (cisterna.id !== $scope.cisterna.id ||
110 cisterna.idTemp !== $scope.cisterna.idTemp)) { 111 cisterna.idTemp !== $scope.cisterna.idTemp)) {
111 reject('Código de cisterna existente'); 112 reject('Código de cisterna existente');
112 } 113 }
113 if(cisterna.id !== $scope.cisterna.id) { 114 if(cisterna.id !== $scope.cisterna.id) {
114 totalCargado += cisterna.capacidad; 115 totalCargado += cisterna.capacidad;
115 } 116 }
116 }); 117 });
117 118
118 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO 119 //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO
119 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); 120 totalCargado = totalCargado + parseInt($scope.cisterna.capacidad);
120 if(totalCargado > $scope.capacidadVechiulo) { 121 if(totalCargado > $scope.capacidadVechiulo) {
121 reject('La capacidad total de las cisternas' + 122 reject('La capacidad total de las cisternas' +
122 ' no debe ser mayor a la del vehiculo'); 123 ' no debe ser mayor a la del vehiculo');
123 }else { 124 }else {
124 resolve(); 125 resolve();
125 } 126 }
126 }); 127 });
127 }); 128 });
128 } 129 }
129 } 130 }
130 ]); 131 ]);
131 132
src/views/foca-abm-cisterna-item.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehículo cisterna'" 3 titulo="'Vehículo cisterna'"
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"></div> 8 <div class="row"></div>
9 <form name="formCisterna"> 9 <form name="formCisterna">
10 <div class="form-group row"> 10 <div class="form-group row">
11 <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label> 11 <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label>
12 <div class="col-sm-4"> 12 <div class="col-sm-4">
13 <input 13 <input
14 class="form-control" 14 class="form-control"
15 type="text" 15 type="text"
16 ng-required="true" 16 ng-required="true"
17 ng-model="cisterna.codigo" 17 ng-model="cisterna.codigo"
18 ng-keypress="next($event.keyCode)" 18 ng-keypress="next($event.keyCode)"
19 foca-focus="focused == 1" 19 foca-focus="focused == 1"
20 ng-focus="focused = 1" 20 ng-focus="focused = 1"
21 ng-disabled="!nuevo"
21 teclado-virtual 22 teclado-virtual
22 /> 23 />
23 </div> 24 </div>
24 </div> 25 </div>
25 <div class="form-group row"> 26 <div class="form-group row">
26 <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label> 27 <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label>
27 <div class="col-sm-4"> 28 <div class="col-sm-4">
28 <input 29 <input
29 class="form-control" 30 class="form-control"
30 type="text" 31 type="text"
31 teclado-virtual 32 teclado-virtual
32 foca-tipo-input 33 foca-tipo-input
33 ng-model="cisterna.capacidad" 34 ng-model="cisterna.capacidad"
34 ng-required="true" 35 ng-required="true"
35 ng-keypress="next($event.keyCode)" 36 ng-keypress="next($event.keyCode)"
36 foca-focus="focused == 2" 37 foca-focus="focused == 2"
37 ng-focus="focused = 2" 38 ng-focus="focused = 2"
38 /> 39 />
39 </div> 40 </div>
40 </div> 41 </div>
41 <div class="form-group row"> 42 <div class="form-group row">
42 <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label> 43 <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label>
43 <div class="col-sm-4 input-group"> 44 <div class="col-sm-4 input-group">
44 <input 45 <input
45 ng-model="cisterna.unidadMedida.NOM" 46 ng-model="cisterna.unidadMedida.NOM"
46 class="form-control" 47 class="form-control"
47 readonly 48 readonly
48 /> 49 />
49 <div class="input-group-append"> 50 <div class="input-group-append">
50 <button 51 <button
51 ladda="searchLoading" 52 ladda="searchLoading"
52 class="btn btn-outline-secondary form-control" 53 class="btn btn-outline-secondary form-control"
53 type="button" 54 type="button"
54 ng-click="seleccionarUnidadMedida()" 55 ng-click="seleccionarUnidadMedida()"
55 foca-focus="focused == 3" 56 foca-focus="focused == 3"
56 > 57 >
57 <i class="fa fa-search" aria-hidden="true"></i> 58 <i class="fa fa-search" aria-hidden="true"></i>
58 </button> 59 </button>
59 </div> 60 </div>
60 </div> 61 </div>
61 </div> 62 </div>
62 </form> 63 </form>
63 64
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-4">Unidad</label> 14 <label class="col-form-label col-md-4">Unidad</label>
15 <div class="input-group col-md-8 pl-0"> 15 <div class="input-group col-md-8 pl-0">
16 <input 16 <input
17 class="form-control" 17 class="form-control"
18 type="text" 18 type="text"
19 teclado-virtual 19 teclado-virtual
20 ng-model="vehiculo.codigo" 20 ng-model="vehiculo.codigo"
21 foca-focus="focused == 1" 21 foca-focus="focused == 1"
22 ng-focus="focused = 1" 22 ng-focus="focused = 1"
23 ng-keypress="next($event.keyCode)" 23 ng-keypress="next($event.keyCode)"
24 ng-disabled="!nuevo"
24 /> 25 />
25 </div> 26 </div>
26 </div> 27 </div>
27 <div class="form-group d-flex mb-2 col-md-6"> 28 <div class="form-group d-flex mb-2 col-md-6">
28 <label class="col-form-label col-md-4">Dominio tractor</label> 29 <label class="col-form-label col-md-4">Dominio tractor</label>
29 <div class="input-group col-md-8 pl-0"> 30 <div class="input-group col-md-8 pl-0">
30 <input 31 <input
31 class="form-control" 32 class="form-control"
32 type="text" 33 type="text"
33 teclado-virtual 34 teclado-virtual
34 ng-model="vehiculo.tractor" 35 ng-model="vehiculo.tractor"
35 ng-required="true" 36 ng-required="true"
36 foca-focus="focused == 2" 37 foca-focus="focused == 2"
37 ng-focus="focused = 2" 38 ng-focus="focused = 2"
38 ng-keypress="next($event.keyCode)" 39 ng-keypress="next($event.keyCode)"
39 /> 40 />
40 </div> 41 </div>
41 </div> 42 </div>
42 <div class="form-group d-flex mb-2 col-md-6"> 43 <div class="form-group d-flex mb-2 col-md-6">
43 <label class="col-form-label col-md-4">Dominio semi</label> 44 <label class="col-form-label col-md-4">Dominio semi</label>
44 <div class="input-group col-md-8 pl-0"> 45 <div class="input-group col-md-8 pl-0">
45 <input 46 <input
46 class="form-control" 47 class="form-control"
47 type="text" 48 type="text"
48 teclado-virtual 49 teclado-virtual
49 ng-model="vehiculo.semi" 50 ng-model="vehiculo.semi"
50 ng-required="true" 51 ng-required="true"
51 foca-focus="focused == 3" 52 foca-focus="focused == 3"
52 ng-focus="focused = 3" 53 ng-focus="focused = 3"
53 ng-keypress="next($event.keyCode)" 54 ng-keypress="next($event.keyCode)"
54 /> 55 />
55 </div> 56 </div>
56 </div> 57 </div>
57 <div class="form-group d-flex mb-2 col-md-6"> 58 <div class="form-group d-flex mb-2 col-md-6">
58 <label class="col-form-label col-md-4">Capacidad total</label> 59 <label class="col-form-label col-md-4">Capacidad total</label>
59 <div class="input-group col-md-8 pl-0"> 60 <div class="input-group col-md-8 pl-0">
60 <input 61 <input
61 class="form-control" 62 class="form-control"
62 type="text" 63 type="text"
63 teclado-virtual 64 teclado-virtual
64 ng-model="vehiculo.capacidad" 65 ng-model="vehiculo.capacidad"
65 ng-required="true" 66 ng-required="true"
66 foca-focus="focused == 4" 67 foca-focus="focused == 4"
67 ng-focus="focused = 4" 68 ng-focus="focused = 4"
68 ng-keypress="guardar($event.keyCode)" 69 ng-keypress="guardar($event.keyCode)"
69 /> 70 />
70 </div> 71 </div>
71 </div> 72 </div>
72 </div> 73 </div>
73 </form> 74 </form>
74 <div ng-show="!nuevo"> 75 <div ng-show="!nuevo">
75 <h5 class="pl-4 table-title">Cisternas</h5> 76 <h5 class="pl-4 table-title">Cisternas</h5>
76 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 77 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
77 <thead> 78 <thead>
78 <tr> 79 <tr>
79 <th class="px-5">Código</th> 80 <th class="px-5">Código</th>
80 <th class="text-right px-5">Capacidad</th> 81 <th class="text-right px-5">Capacidad</th>
81 <th class="text-center px-4"> 82 <th class="text-center px-4">
82 <button 83 <button
83 class="btn btn-outline-debo boton-accion" 84 class="btn btn-outline-debo boton-accion"
84 title="Agregar" 85 title="Agregar"
85 ng-click="editar()"> 86 ng-click="editar()">
86 <i class="fa fa-plus"></i> 87 <i class="fa fa-plus"></i>
87 </button> 88 </button>
88 </th> 89 </th>
89 </tr> 90 </tr>
90 </thead> 91 </thead>
91 <tbody> 92 <tbody>
92 <tr ng-repeat="cisterna in cisternas | filter:filtros"> 93 <tr ng-repeat="cisterna in cisternas | filter:filtros">
93 <td ng-bind="cisterna.codigo" class="px-5"></td> 94 <td ng-bind="cisterna.codigo" class="px-5"></td>
94 <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> 95 <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td>
95 <td class="text-center px-4"> 96 <td class="text-center px-4">
96 <button 97 <button
97 class="btn btn-outline-dark boton-accion" 98 class="btn btn-outline-dark boton-accion"
98 title="Editar" 99 title="Editar"
99 ng-click="editar(cisterna)" 100 ng-click="editar(cisterna)"
100 > 101 >
101 <i class="fa fa-pencil"></i> 102 <i class="fa fa-pencil"></i>
102 </button> 103 </button>
103 <button 104 <button
104 class="btn btn-outline-dark boton-accion" 105 class="btn btn-outline-dark boton-accion"
105 title="Eliminar" 106 title="Eliminar"
106 ng-click="solicitarConfirmacionCisterna(cisterna)" 107 ng-click="solicitarConfirmacionCisterna(cisterna)"
107 > 108 >
108 <i class="fa fa-trash"></i> 109 <i class="fa fa-trash"></i>
109 </button> 110 </button>
110 </td> 111 </td>
111 </tr> 112 </tr>
112 </body> 113 </body>
113 </table> 114 </table>
114 </div> 115 </div>
115 </div> 116 </div>
116 </div> 117 </div>
117 118