Commit 8c061c999aff0b7c53f596998b2d33cd17112d60

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

codigo de vehiculo y cisterna unicos, codigos con ceros

See merge request !9
src/js/controller.js
... ... @@ -57,12 +57,13 @@ angular.module('focaAbmVehiculo')
57 57 };
58 58  
59 59 function elegirTransportista(transportista) {
  60 + var codigo = ('00000' + transportista.COD).slice(-5);
60 61 $scope.idTransportista = transportista.COD;
61 62 $scope.filtros = transportista.NOM.trim();
62 63 $timeout(function() {
63 64 $scope.$broadcast('addCabecera', {
64 65 label: 'Transportista:',
65   - valor: transportista.COD + ' - ' + transportista.NOM
  66 + valor: codigo + ' - ' + transportista.NOM
66 67 });
67 68 });
68 69 buscar(transportista.COD);
... ... @@ -89,7 +90,7 @@ angular.module('focaAbmVehiculo')
89 90 $timeout(function() {
90 91 focaBotoneraLateralService.showSalir(false);
91 92 focaBotoneraLateralService.showPausar(false);
92   - focaBotoneraLateralService.showCancelar(true);
  93 + focaBotoneraLateralService.showCancelar(true, '/vehiculo');
93 94 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
94 95 });
95 96  
... ... @@ -97,21 +98,23 @@ angular.module('focaAbmVehiculo')
97 98 focaAbmVehiculoService
98 99 .getTransportistaPorId($routeParams.idTransportista)
99 100 .then(function(res) {
  101 + var codigo = ('00000' + res.data.COD).slice(-5);
100 102 $scope.vehiculo.idTransportista = res.data.COD;
101 103 $scope.vehiculo.transportista = res.data;
102 104 $scope.$broadcast('addCabecera', {
103 105 label: 'Transportista:',
104   - valor: res.data.COD + ' - ' + res.data.NOM
  106 + valor: codigo + ' - ' + res.data.NOM
105 107 });
106 108 });
107 109 }
108 110 $scope.vehiculo = {};
109 111 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
110 112 if(res.data) {
  113 + var codigo = ('00000' + res.data.transportista.COD).slice(-5);
111 114 $scope.vehiculo = res.data;
112 115 $scope.$broadcast('addCabecera', {
113 116 label: 'Transportista:',
114   - valor: res.data.transportista.COD + ' - ' + res.data.transportista.NOM
  117 + valor: codigo + ' - ' + res.data.transportista.NOM
115 118 });
116 119 $scope.$broadcast('addCabecera', {
117 120 label: 'Unidad:',
... ... @@ -133,18 +136,22 @@ angular.module('focaAbmVehiculo')
133 136 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id);
134 137 };
135 138 $scope.guardar = function() {
136   - if(!$scope.vehiculo.transportista) {
137   - focaModalService.alert('Elija Transportista');
138   - return;
139   - }
140   - delete $scope.vehiculo.transportista;
141   - focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) {
142   - if($scope.nuevo) {
143   - $location.path('/vehiculo/' + res.data.id + '/' + res.data.idTransportista);
144   - } else {
145   - $location.path('/vehiculo');
146   - }
  139 + //Valida si existe numero de unidad
  140 + existeCodigoUnidad().then(function() {
  141 + delete $scope.vehiculo.transportista;
  142 + focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
  143 + .then(function(res){
  144 + if($scope.nuevo) {
  145 + $location.path('/vehiculo/' + res.data.id +
  146 + '/' + res.data.idTransportista);
  147 + } else {
  148 + $location.path('/vehiculo');
  149 + }
  150 + });
  151 + }, function(){
  152 + focaModalService.alert('Código de unidad existente');
147 153 });
  154 +
148 155 };
149 156 $scope.solicitarConfirmacionCisterna = function(cisterna) {
150 157 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
... ... @@ -180,5 +187,25 @@ angular.module('focaAbmVehiculo')
180 187 }
181 188 );
182 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
  197 + var existe = res.data.filter(function(vehiculo) {
  198 + return vehiculo.codigo === $scope.vehiculo.codigo &&
  199 + vehiculo.id !== $scope.vehiculo.id;
  200 + });
  201 +
  202 + if(existe.length){
  203 + reject(existe);
  204 + } else {
  205 + resolve();
  206 + }
  207 + });
  208 + });
  209 + }
183 210 }
184 211 ]);
src/js/controllerCisterna.js
... ... @@ -34,9 +34,10 @@ angular.module('focaAbmVehiculo')
34 34 }
35 35 });
36 36 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
  37 + var codigo = ('00000' + res.data.transportista.COD).slice(-5);
37 38 $scope.$broadcast('addCabecera', {
38 39 label: 'Transportista:',
39   - valor: res.data.transportista.COD + ' - ' + res.data.transportista.NOM
  40 + valor: codigo + ' - ' + res.data.transportista.NOM
40 41 });
41 42 $scope.$broadcast('addCabecera', {
42 43 label: 'Unidad:',
... ... @@ -55,12 +56,17 @@ angular.module('focaAbmVehiculo')
55 56 focaModalService.alert('Ingrese producto');
56 57 return;
57 58 }
58   - $scope.cisterna.idVehiculo = $routeParams.idVehiculo;
59   - delete $scope.cisterna.unidadMedida;
60   - delete $scope.cisterna.cisternaCarga.articulo;
61   - focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function() {
62   - $location.path('/vehiculo/' + $routeParams.idVehiculo);
  59 + existeCodigoCisterna().then(function() {
  60 + $scope.cisterna.idVehiculo = $routeParams.idVehiculo;
  61 + delete $scope.cisterna.unidadMedida;
  62 + delete $scope.cisterna.cisternaCarga.articulo;
  63 + focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){
  64 + $location.path('/vehiculo/' + $routeParams.idVehiculo);
  65 + });
  66 + }, function() {
  67 + focaModalService.alert('Código de cisterna existente');
63 68 });
  69 +
64 70 };
65 71  
66 72 // $scope.seleccionarArticulo = function() {
... ... @@ -103,5 +109,24 @@ angular.module('focaAbmVehiculo')
103 109 $scope.cisterna.unidadMedida = unidaMedida;
104 110 });
105 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 +
  123 + if(existe.length){
  124 + reject(existe);
  125 + } else {
  126 + resolve();
  127 + }
  128 + });
  129 + });
  130 + }
106 131 }
107 132 ]);
... ... @@ -10,7 +10,7 @@ angular.module('focaAbmVehiculo')
10 10 getTransportistas: function() {
11 11 return $http.get(API_ENDPOINT.URL + '/transportista');
12 12 },
13   - guerdarVehiculo: function(vehiculo) {
  13 + guardarVehiculo: function(vehiculo) {
14 14 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
15 15 },
16 16 deleteVehiculo: function(id) {