Commit 8cb24dc5b7f9ea04ccea060416535f92953dfa4f
1 parent
10ea0c99c4
Exists in
master
and in
1 other branch
Espacio en IF y c.Log
Showing
1 changed file
with
2 additions
and
2 deletions
Show diff stats
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.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? 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 | codigo: '', | 11 | codigo: '', |
12 | capacidad: '', | 12 | capacidad: '', |
13 | unidadMedida: {} | 13 | unidadMedida: {} |
14 | }; | 14 | }; |
15 | 15 | ||
16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; |
17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { |
18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; |
19 | }; | 19 | }; |
20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; |
21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; |
22 | 22 | ||
23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL |
24 | $timeout(function() { | 24 | $timeout(function() { |
25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); |
26 | focaBotoneraLateralService.showPausar(false); | 26 | focaBotoneraLateralService.showPausar(false); |
27 | focaBotoneraLateralService.showCancelar(true); | 27 | focaBotoneraLateralService.showCancelar(true); |
28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
29 | }); | 29 | }); |
30 | 30 | ||
31 | if($routeParams.idx != -1) { | 31 | if ($routeParams.idx != -1) { |
32 | console.log('asd'); | 32 | |
33 | $scope.cisterna = [$routeParams.idx]; | 33 | $scope.cisterna = [$routeParams.idx]; |
34 | focaAbmVehiculoService | 34 | focaAbmVehiculoService |
35 | .getCisternas($routeParams.idVehiculo) | 35 | .getCisternas($routeParams.idVehiculo) |
36 | .then(function(res) { | 36 | .then(function(res) { |
37 | $scope.cisterna = res[$routeParams.idx]; | 37 | $scope.cisterna = res[$routeParams.idx]; |
38 | }); | 38 | }); |
39 | } | 39 | } |
40 | 40 | ||
41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
43 | $scope.transportista = res.data.transportista.COD; | 43 | $scope.transportista = res.data.transportista.COD; |
44 | $scope.capacidadVechiulo = res.data.capacidad; | 44 | $scope.capacidadVechiulo = res.data.capacidad; |
45 | $scope.$broadcast('addCabecera', { | 45 | $scope.$broadcast('addCabecera', { |
46 | label: 'Transportista:', | 46 | label: 'Transportista:', |
47 | valor: codigo + ' - ' + res.data.transportista.NOM | 47 | valor: codigo + ' - ' + res.data.transportista.NOM |
48 | }); | 48 | }); |
49 | $scope.$broadcast('addCabecera', { | 49 | $scope.$broadcast('addCabecera', { |
50 | label: 'Unidad:', | 50 | label: 'Unidad:', |
51 | valor: res.data.codigo | 51 | valor: res.data.codigo |
52 | }); | 52 | }); |
53 | $scope.$broadcast('addCabecera', { | 53 | $scope.$broadcast('addCabecera', { |
54 | label: 'Capacidad total vehículo:', | 54 | label: 'Capacidad total vehículo:', |
55 | valor: res.data.capacidad | 55 | valor: res.data.capacidad |
56 | }); | 56 | }); |
57 | }); | 57 | }); |
58 | $scope.cancelar = function() { | 58 | $scope.cancelar = function() { |
59 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 59 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
60 | }; | 60 | }; |
61 | $scope.guardar = function() { | 61 | $scope.guardar = function() { |
62 | 62 | ||
63 | if (!$scope.cisterna.codigo) { | 63 | if (!$scope.cisterna.codigo) { |
64 | focaModalService.alert('Ingrese codigo de cisterna'); | 64 | focaModalService.alert('Ingrese codigo de cisterna'); |
65 | return; | 65 | return; |
66 | } else if (!$scope.cisterna.capacidad) { | 66 | } else if (!$scope.cisterna.capacidad) { |
67 | focaModalService.alert('Ingrese capacidad'); | 67 | focaModalService.alert('Ingrese capacidad'); |
68 | return; | 68 | return; |
69 | } else if (!$scope.cisterna.idUnidadMedida) { | 69 | } else if (!$scope.cisterna.idUnidadMedida) { |
70 | focaModalService.alert('Ingrese unidad de medida'); | 70 | focaModalService.alert('Ingrese unidad de medida'); |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | 73 | ||
74 | validaCodigo() | 74 | validaCodigo() |
75 | .then(function() { | 75 | .then(function() { |
76 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 76 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
77 | delete $scope.cisterna.vehiculo; | 77 | delete $scope.cisterna.vehiculo; |
78 | 78 | ||
79 | focaAbmVehiculoService | 79 | focaAbmVehiculoService |
80 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 80 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
81 | 81 | ||
82 | $timeout(function() { | 82 | $timeout(function() { |
83 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 83 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
84 | '/' + $scope.transportista); | 84 | '/' + $scope.transportista); |
85 | }, 0); | 85 | }, 0); |
86 | }, function(err) { | 86 | }, function(err) { |
87 | focaModalService.alert(err); | 87 | focaModalService.alert(err); |
88 | }); | 88 | }); |
89 | 89 | ||
90 | }; | 90 | }; |
91 | 91 | ||
92 | $scope.seleccionarUnidadMedida = function() { | 92 | $scope.seleccionarUnidadMedida = function() { |
93 | var modalInstance = $uibModal.open( | 93 | var modalInstance = $uibModal.open( |
94 | { | 94 | { |
95 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 95 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
96 | templateUrl: 'modal-unidad-medida.html', | 96 | templateUrl: 'modal-unidad-medida.html', |
97 | controller: 'focaModalUnidadMedidaCtrl', | 97 | controller: 'focaModalUnidadMedidaCtrl', |
98 | size: 'lg' | 98 | size: 'lg' |
99 | } | 99 | } |
100 | ); | 100 | ); |
101 | modalInstance.result.then(function(unidaMedida) { | 101 | modalInstance.result.then(function(unidaMedida) { |
102 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 102 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
103 | $scope.cisterna.unidadMedida = unidaMedida; | 103 | $scope.cisterna.unidadMedida = unidaMedida; |
104 | }); | 104 | }); |
105 | }; | 105 | }; |
106 | 106 | ||
107 | function validaCodigo() { | 107 | function validaCodigo() { |
108 | return new Promise(function(resolve, reject) { | 108 | return new Promise(function(resolve, reject) { |
109 | focaAbmVehiculoService | 109 | focaAbmVehiculoService |
110 | .getCisternas($routeParams.idVehiculo) | 110 | .getCisternas($routeParams.idVehiculo) |
111 | .then(function(res) { | 111 | .then(function(res) { |
112 | var cisternas = res; | 112 | var cisternas = res; |
113 | var totalCargado = 0; | 113 | var totalCargado = 0; |
114 | cisternas.forEach(function(cisterna, idx) { | 114 | cisternas.forEach(function(cisterna, idx) { |
115 | //SI EL CODIGO YA EXISTE | 115 | //SI EL CODIGO YA EXISTE |
116 | if(cisterna.codigo === $scope.cisterna.codigo && | 116 | if(cisterna.codigo === $scope.cisterna.codigo && |
117 | idx != $routeParams.idx && | 117 | idx != $routeParams.idx && |
118 | !cisterna.desactivado) { | 118 | !cisterna.desactivado) { |
119 | reject('Código de cisterna existente'); | 119 | reject('Código de cisterna existente'); |
120 | } | 120 | } |
121 | if(idx != $routeParams.idx && | 121 | if(idx != $routeParams.idx && |
122 | !cisterna.desactivado) { | 122 | !cisterna.desactivado) { |
123 | totalCargado += cisterna.capacidad; | 123 | totalCargado += cisterna.capacidad; |
124 | } | 124 | } |
125 | }); | 125 | }); |
126 | resolve(); | 126 | resolve(); |
127 | }); | 127 | }); |
128 | }); | 128 | }); |
129 | } | 129 | } |
130 | } | 130 | } |
131 | ]); | 131 | ]); |
132 | 132 |