Commit bc0a5820cdfd86bd28ecf5b5e26bb0b2b645d551

Authored by Eric Fernandez
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'develop'

Master(efernandez)

See merge request !70
src/js/businessService.js
1 angular.module('focaCrearHojaRuta') 1 angular.module('focaCrearHojaRuta')
2 .factory('hojaRutaBusinessService', [ 2 .factory('hojaRutaBusinessService', [
3 'focaCrearHojaRutaService', 3 'focaCrearHojaRutaService',
4 function(crearHojaRutaService) { 4 function(crearHojaRutaService) {
5 return { 5 return {
6 addArticulos: function(articulosHojaRuta, idRemito, cotizacion) { 6 addArticulos: function(articulosHojaRuta, cotizacion) {
7
7 for(var i = 0; i < articulosHojaRuta.length; i++) { 8 for(var i = 0; i < articulosHojaRuta.length; i++) {
8 delete articulosHojaRuta[i].editCantidad; 9 delete articulosHojaRuta[i].editCantidad;
9 delete articulosHojaRuta[i].editPrecio; 10 delete articulosHojaRuta[i].editPrecio;
10 delete articulosHojaRuta[i].sectorCodigo; 11 delete articulosHojaRuta[i].sectorCodigo;
11 articulosHojaRuta[i].idRemito = idRemito;
12 articulosHojaRuta[i].precio = articulosHojaRuta[i].precio * cotizacion; 12 articulosHojaRuta[i].precio = articulosHojaRuta[i].precio * cotizacion;
13 crearHojaRutaService.crearArticulosParaHojaRuta(articulosHojaRuta[i]);
14 } 13 }
14
15 return articulosHojaRuta;
15 }, 16 },
16 addEstado: function(idHojaRuta, idVendedor) { 17 addEstado: function(idHojaRuta, idVendedor) {
17 var date = new Date(); 18 var date = new Date();
18 var estado = { 19 var estado = {
19 idHojaRuta: idHojaRuta, 20 idHojaRuta: idHojaRuta,
20 fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 21 fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
21 .toISOString().slice(0, 19).replace('T', ' '), 22 .toISOString().slice(0, 19).replace('T', ' '),
22 estado: 0, 23 estado: 0,
23 idVendedor: idVendedor 24 idVendedor: idVendedor
24 }; 25 };
25 crearHojaRutaService.crearEstadoParaHojaRuta(estado); 26 crearHojaRutaService.crearEstadoParaHojaRuta(estado);
26 }, 27 },
27 }; 28 };
src/js/controller.js
1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl', 1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'focaCrearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 'focaLoginService', 11 'focaLoginService',
12 '$localStorage', 12 '$localStorage',
13 'hojaRutaBusinessService', 13 'hojaRutaBusinessService',
14 '$cookies', 14 '$cookies',
15 function ($scope, $uibModal, $location, $filter, $timeout, 15 function ($scope, $uibModal, $location, $filter, $timeout,
16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, 16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) { 17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) {
18 18
19 config(); 19 config();
20 20
21 function config() { 21 function config() {
22 22
23 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal = 23 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal =
24 focaCrearHojaRutaService.getBotones(); 24 focaCrearHojaRutaService.getBotones();
25 $scope.botonera = []; 25 $scope.botonera = [];
26 $scope.datepickerAbierto = false; 26 $scope.datepickerAbierto = false;
27 $scope.show = false; 27 $scope.show = false;
28 $scope.cisternaCargas = []; 28 $scope.cisternaCargas = [];
29 $scope.cargando = true; 29 $scope.cargando = true;
30 $scope.articulos = []; 30 $scope.articulos = [];
31 $scope.remito = { 31 $scope.remito = {
32 id: '', 32 id: '',
33 numeroRemito: '' 33 numeroRemito: ''
34 }; 34 };
35 $scope.now = new Date(); 35 $scope.now = new Date();
36 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 36 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
37 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 37 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
38 38
39 //SETEO BOTONERA LATERAL 39 //SETEO BOTONERA LATERAL
40 $timeout(function () { 40 $timeout(function () {
41 focaBotoneraLateralService.showSalir(false); 41 focaBotoneraLateralService.showSalir(false);
42 focaBotoneraLateralService.showPausar(true); 42 focaBotoneraLateralService.showPausar(true);
43 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 43 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
44 focaBotoneraLateralService.addCustomButton('Salir', salir); 44 focaBotoneraLateralService.addCustomButton('Salir', salir);
45 }); 45 });
46 46
47 focaCrearHojaRutaService.getParametros().then(function (res) { 47 focaCrearHojaRutaService.getParametros().then(function (res) {
48 48
49 var parametros = JSON.parse(res.data[0].jsonText); 49 var parametros = JSON.parse(res.data[0].jsonText);
50 50
51 $timeout(function () { 51 $timeout(function () {
52 getLSBotoneraPrincipal(); 52 getLSBotoneraPrincipal();
53 }); 53 });
54 54
55 if ($localStorage.data) { 55 if ($localStorage.data) {
56 $timeout(function () { 56 $timeout(function () {
57 getLSHojaRuta(); 57 getLSHojaRuta();
58 }); 58 });
59 59
60 } else { 60 } else {
61 for (var property in parametros) { 61 for (var property in parametros) {
62 $scope.hojaRuta[property] = parametros[property]; 62 $scope.hojaRuta[property] = parametros[property];
63 $scope.inicial[property] = parametros[property]; 63 $scope.inicial[property] = parametros[property];
64 } 64 }
65 //Setear Hoja de Ruta 65 //Setear Hoja de Ruta
66 66
67 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) { 67 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) {
68 setearHojaRuta($scope.hojaRuta); 68 setearHojaRuta($scope.hojaRuta);
69 } 69 }
70 } 70 }
71 }); 71 });
72 init(); 72 init();
73 } 73 }
74 function init() { 74 function init() {
75 $scope.$broadcast('cleanCabecera'); 75 $scope.$broadcast('cleanCabecera');
76 76
77 $scope.hojaRuta = { 77 $scope.hojaRuta = {
78 fecha: new Date(), 78 fecha: new Date(),
79 litros: 0, 79 litros: 0,
80 chofer: {}, 80 chofer: {},
81 vehiculo: { 81 vehiculo: {
82 capacidad: 0 82 capacidad: 0
83 }, 83 },
84 transportista: {}, 84 transportista: {},
85 remitosTabla: [] 85 remitosTabla: []
86 }; 86 };
87 $scope.idLista = undefined; 87 $scope.idLista = undefined;
88 88
89 focaCrearHojaRutaService.getNumeroHojaRuta().then( 89 focaCrearHojaRutaService.getNumeroHojaRuta().then(
90 function (res) { 90 function (res) {
91 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); 91 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4);
92 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); 92 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8);
93 }, 93 },
94 function (err) { 94 function (err) {
95 focaModalService.alert('La terminal no esta configurada correctamente'); 95 focaModalService.alert('La terminal no esta configurada correctamente');
96 console.info(err); 96 console.info(err);
97 } 97 }
98 ); 98 );
99 $scope.inicial = angular.copy($scope.hojaRuta); 99 $scope.inicial = angular.copy($scope.hojaRuta);
100 } 100 }
101 101
102 $scope.$watchGroup(['hojaRuta', 'precargado', 'cargaRemito', 'remitoAbierto'], 102 $scope.$watchGroup(['hojaRuta', 'precargado', 'cargaRemito', 'remitoAbierto'],
103 function (newValues) { 103 function (newValues) {
104 focaBotoneraLateralService.setPausarData( 104 focaBotoneraLateralService.setPausarData(
105 { 105 {
106 label: 'data', 106 label: 'data',
107 val: newValues 107 val: newValues
108 } 108 }
109 ); 109 );
110 }); 110 });
111 111
112 $scope.seleccionarRemitoAbierto = function () { 112 $scope.seleccionarRemitoAbierto = function () {
113 $scope.remitoAbierto = true; 113 $scope.remitoAbierto = true;
114 $scope.cargaRemito = false; 114 $scope.cargaRemito = false;
115 $scope.precargado = false; 115 $scope.precargado = false;
116 116
117 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 117 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
118 $scope.$broadcast('cleanCabecera'); 118 $scope.$broadcast('cleanCabecera');
119 focaModalService.confirm('Se perderan los cambios') 119 focaModalService.confirm('Se perderan los cambios')
120 .then(function () { 120 .then(function () {
121 limpiarBotonera($scope.botonera); 121 limpiarBotonera($scope.botonera);
122 limpiarBotonera($scope.botoneraPrincipal); 122 limpiarBotonera($scope.botoneraPrincipal);
123 $filter('filter')($scope.botoneraPrincipal, { 123 $filter('filter')($scope.botoneraPrincipal, {
124 label: 'Remito Abierto', 124 label: 'Remito Abierto',
125 })[0].checked = true; 125 })[0].checked = true;
126 126
127 config(); 127 config();
128 128
129 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 129 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
130 }); 130 });
131 } else { 131 } else {
132 $scope.$broadcast('cleanCabecera'); 132 $scope.$broadcast('cleanCabecera');
133 limpiarBotonera($scope.botoneraPrincipal); 133 limpiarBotonera($scope.botoneraPrincipal);
134 $filter('filter')($scope.botoneraPrincipal, { 134 $filter('filter')($scope.botoneraPrincipal, {
135 label: 'Remito Abierto', 135 label: 'Remito Abierto',
136 })[0].checked = true; 136 })[0].checked = true;
137 137
138 config(); 138 config();
139 139
140 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 140 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
141 } 141 }
142 }; 142 };
143 143
144 $scope.seleccionarCargarRemitos = function () { 144 $scope.seleccionarCargarRemitos = function () {
145 $scope.cargaRemito = true; 145 $scope.cargaRemito = true;
146 $scope.remitoAbierto = false; 146 $scope.remitoAbierto = false;
147 $scope.precargado = false; 147 $scope.precargado = false;
148 148
149 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 149 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
150 $scope.$broadcast('cleanCabecera'); 150 $scope.$broadcast('cleanCabecera');
151 focaModalService.confirm('Se perderan los cambios') 151 focaModalService.confirm('Se perderan los cambios')
152 .then(function () { 152 .then(function () {
153 limpiarBotonera($scope.botonera); 153 limpiarBotonera($scope.botonera);
154 limpiarBotonera($scope.botoneraPrincipal); 154 limpiarBotonera($scope.botoneraPrincipal);
155 $scope.preCargados = false; 155 $scope.preCargados = false;
156 $filter('filter')($scope.botoneraPrincipal, { 156 $filter('filter')($scope.botoneraPrincipal, {
157 label: 'Cargar Remitos', 157 label: 'Cargar Remitos',
158 })[0].checked = true; 158 })[0].checked = true;
159 159
160 config(); 160 config();
161 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 161 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
162 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 162 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
163 }); 163 });
164 } else { 164 } else {
165 $scope.$broadcast('cleanCabecera'); 165 $scope.$broadcast('cleanCabecera');
166 limpiarBotonera($scope.botoneraPrincipal); 166 limpiarBotonera($scope.botoneraPrincipal);
167 $filter('filter')($scope.botoneraPrincipal, { 167 $filter('filter')($scope.botoneraPrincipal, {
168 label: 'Cargar Remitos', 168 label: 'Cargar Remitos',
169 })[0].checked = true; 169 })[0].checked = true;
170 config(); 170 config();
171 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 171 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
172 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 172 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
173 } 173 }
174 $scope.precargado = false; 174 $scope.precargado = false;
175 }; 175 };
176 176
177 $scope.seleccionarPrecargados = function () { 177 $scope.seleccionarPrecargados = function () {
178 $scope.precargado = true; 178 $scope.precargado = true;
179 $scope.cargaRemito = false; 179 $scope.cargaRemito = false;
180 $scope.remitoAbierto = false; 180 $scope.remitoAbierto = false;
181 181
182 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 182 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
183 focaModalService.confirm('Se perderan los cambios') 183 focaModalService.confirm('Se perderan los cambios')
184 .then(function () { 184 .then(function () {
185 $scope.$broadcast('cleanCabecera'); 185 $scope.$broadcast('cleanCabecera');
186 limpiarBotonera($scope.botonera); 186 limpiarBotonera($scope.botonera);
187 limpiarBotonera($scope.botoneraPrincipal); 187 limpiarBotonera($scope.botoneraPrincipal);
188 $filter('filter')($scope.botoneraPrincipal, { 188 $filter('filter')($scope.botoneraPrincipal, {
189 label: 'Precargado', 189 label: 'Precargado',
190 })[0].checked = true; 190 })[0].checked = true;
191 191
192 config(); 192 config();
193 193
194 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 194 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
195 }); 195 });
196 } else { 196 } else {
197 $scope.$broadcast('cleanCabecera'); 197 $scope.$broadcast('cleanCabecera');
198 limpiarBotonera($scope.botoneraPrincipal); 198 limpiarBotonera($scope.botoneraPrincipal);
199 $filter('filter')($scope.botoneraPrincipal, { 199 $filter('filter')($scope.botoneraPrincipal, {
200 label: 'Precargado', 200 label: 'Precargado',
201 })[0].checked = true; 201 })[0].checked = true;
202 202
203 config(); 203 config();
204 204
205 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 205 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
206 } 206 }
207 }; 207 };
208 208
209 $scope.quitarArticulo = function (key) { 209 $scope.quitarArticulo = function (key) {
210 $scope.articulos.splice(key, 1); 210 $scope.articulos.splice(key, 1);
211 }; 211 };
212 212
213 function validarHojaRuta() { 213 function validarHojaRuta() {
214 if ($scope.precargado) { 214 if ($scope.precargado) {
215 if (!$scope.hojaRuta.chofer.id) { 215 if (!$scope.hojaRuta.chofer.id) {
216 focaModalService.alert('Ingrese Chofer'); 216 focaModalService.alert('Ingrese Chofer');
217 return false; 217 return false;
218 } 218 }
219 if (!$scope.hojaRuta.vehiculo.id) { 219 if (!$scope.hojaRuta.vehiculo.id) {
220 focaModalService.alert('Ingrese Vehiculo'); 220 focaModalService.alert('Ingrese Vehiculo');
221 return false; 221 return false;
222 } 222 }
223 if (!$scope.hojaRuta.transportista.COD) { 223 if (!$scope.hojaRuta.transportista.COD) {
224 focaModalService.alert('Ingrese Transportista'); 224 focaModalService.alert('Ingrese Transportista');
225 return false; 225 return false;
226 } 226 }
227 if (!$scope.hojaRuta.datosExtra) { 227 if (!$scope.hojaRuta.datosExtra) {
228 focaModalService.alert('Ingrese Datos extra'); 228 focaModalService.alert('Ingrese Datos extra');
229 return false; 229 return false;
230 } 230 }
231 } else if ($scope.cargaRemito) { 231 } else if ($scope.cargaRemito) {
232 if (!$scope.hojaRuta.remitosTabla.length) { 232 if (!$scope.hojaRuta.remitosTabla.length) {
233 focaModalService.alert('Ingrese Remitos'); 233 focaModalService.alert('Ingrese Remitos');
234 return false; 234 return false;
235 } else if (!$scope.hojaRuta.chofer.id) { 235 } else if (!$scope.hojaRuta.chofer.id) {
236 focaModalService.alert('Ingrese Chofer'); 236 focaModalService.alert('Ingrese Chofer');
237 return false; 237 return false;
238 } 238 }
239 if (!$scope.hojaRuta.vehiculo.id) { 239 if (!$scope.hojaRuta.vehiculo.id) {
240 focaModalService.alert('Ingrese Vehiculo'); 240 focaModalService.alert('Ingrese Vehiculo');
241 return false; 241 return false;
242 } 242 }
243 if (!$scope.hojaRuta.transportista.COD) { 243 if (!$scope.hojaRuta.transportista.COD) {
244 focaModalService.alert('Ingrese Transportista'); 244 focaModalService.alert('Ingrese Transportista');
245 return false; 245 return false;
246 } 246 }
247 if (!$scope.hojaRuta.datosExtra) { 247 if (!$scope.hojaRuta.datosExtra) {
248 focaModalService.alert('Ingrese Datos extra'); 248 focaModalService.alert('Ingrese Datos extra');
249 return false; 249 return false;
250 } 250 }
251 } else if ($scope.remitoAbierto) { 251 } else if ($scope.remitoAbierto) {
252 if (!$scope.hojaRuta.transportista.COD) { 252 if (!$scope.hojaRuta.transportista.COD) {
253 focaModalService.alert('Ingrese Transportista'); 253 focaModalService.alert('Ingrese Transportista');
254 return false; 254 return false;
255 } else if (!$scope.hojaRuta.vehiculo.id) { 255 } else if (!$scope.hojaRuta.vehiculo.id) {
256 focaModalService.alert('Ingrese Vehiculo'); 256 focaModalService.alert('Ingrese Vehiculo');
257 return false; 257 return false;
258 } else if (!$scope.hojaRuta.chofer.id) { 258 } else if (!$scope.hojaRuta.chofer.id) {
259 focaModalService.alert('Ingrese Chofer'); 259 focaModalService.alert('Ingrese Chofer');
260 return false; 260 return false;
261 } else if (!$scope.hojaRuta.proveedor.COD) { 261 } else if (!$scope.hojaRuta.proveedor.COD) {
262 focaModalService.alert('Ingrese Proveedor'); 262 focaModalService.alert('Ingrese Proveedor');
263 return false; 263 return false;
264 } else if (!$scope.hojaRuta.cliente.COD) { 264 } else if (!$scope.hojaRuta.cliente.COD) {
265 focaModalService.alert('Ingrese un Cliente'); 265 focaModalService.alert('Ingrese un Cliente');
266 return; 266 return;
267 } 267 }
268 } 268 }
269 return true; 269 return true;
270 270
271 } 271 }
272 272
273 function getImporte(propiedad) { 273 function getImporte(propiedad) {
274 var importe = 0; 274 var importe = 0;
275 275
276 $scope.articulos.forEach(function (articulo) { 276 $scope.articulos.forEach(function (articulo) {
277 277
278 if (articulo[propiedad]) { 278 if (articulo[propiedad]) {
279 importe += articulo[propiedad] * articulo.cantidad; 279 importe += articulo[propiedad] * articulo.cantidad;
280 } 280 }
281 return; 281 return;
282 282
283 }); 283 });
284 284
285 return importe; 285 return importe;
286 } 286 }
287 287
288 function guardarRemitoAbierto() { 288 function guardarRemitoAbierto() {
289 //guardar nuevo objeto (?) 289 //guardar nuevo objeto (?)
290 var date = new Date(); 290 var date = new Date();
291 if ($scope.hojaRuta !== null) { 291 if ($scope.hojaRuta !== null) {
292 focaBotoneraLateralService.startGuardar(); 292 focaBotoneraLateralService.startGuardar();
293 var save = { 293 var save = {
294 remito: { 294 remito: {
295 id: 0, 295 id: 0,
296 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 296 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
297 idCliente: $scope.hojaRuta.cliente.COD, 297 idCliente: $scope.hojaRuta.cliente.COD,
298 nombreCliente: $scope.hojaRuta.cliente.NOM, 298 nombreCliente: $scope.hojaRuta.cliente.NOM,
299 cuitCliente: $scope.hojaRuta.cliente.CUIT, 299 cuitCliente: $scope.hojaRuta.cliente.CUIT,
300 idVendedor: $cookies.get('vendedorCobrador'), 300 idVendedor: $scope.hojaRuta.cliente.VEN,
301 idProveedor: $scope.hojaRuta.proveedor.COD, 301 idProveedor: parseInt($scope.hojaRuta.proveedor.COD),
302 idDomicilio: $scope.hojaRuta.idDomicilio || 302 idDomicilio: $scope.hojaRuta.idDomicilio ||
303 $scope.hojaRuta.domicilio.id, 303 $scope.hojaRuta.domicilio.id,
304 idCotizacion: $scope.hojaRuta.cotizacion.ID, 304 idCotizacion: $scope.hojaRuta.cotizacion.ID,
305 domicilioStamp: $scope.hojaRuta.domicilioStamp, 305 domicilioStamp: $scope.hojaRuta.domicilioStamp,
306 observaciones: $scope.hojaRuta.observaciones, 306 observaciones: $scope.hojaRuta.observaciones,
307 idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(), 307 idListaPrecio: parseInt($scope.hojaRuta.cliente.MOD.trim()),
308 total: getImporte('total') || 0, 308 total: getImporte('total') || 0,
309 descuento: 0,//TODO, 309 descuento: 0,//TODO,
310 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar, 310 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar,
311 importeExento: getImporte('exentoUnitario'), 311 importeExento: getImporte('exentoUnitario'),
312 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar 312 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar
313 importeIvaServicios: 0,//TODO 313 importeIvaServicios: 0,//TODO
314 importeImpuestoInterno: getImporte('impuestoInternoUnitario'), 314 importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
315 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), 315 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
316 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), 316 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
317 percepcion: 0,//TODO 317 percepcion: 0,//TODO
318 percepcionIva: 0,//TODO 318 percepcionIva: 0,//TODO
319 redondeo: 0,//TODO 319 redondeo: 0,//TODO
320 anulado: false, 320 anulado: false,
321 planilla: $filter('date')($scope.now, 'ddMMyyyy'), 321 planilla: $filter('date')($scope.now, 'ddMMyyyy'),
322 lugar: parseInt($scope.puntoVenta), 322 lugar: parseInt($scope.puntoVenta),
323 cuentaMadre: 0,//TODO 323 cuentaMadre: 0,//TODO
324 cuentaContable: 0,//TODO 324 cuentaContable: 0,//TODO
325 asiento: 0,//TODO 325 asiento: 0,//TODO
326 e_hd: '',//TODO 326 e_hd: '',//TODO
327 c_hd: '', 327 c_hd: '',
328 numeroLiquidoProducto: 0,//TODO 328 numeroLiquidoProducto: 0,//TODO
329 estado: 0, 329 estado: 0,
330 destinoVenta: 0,//TODO 330 destinoVenta: 0,//TODO
331 operacionTipo: 0, //TODO 331 operacionTipo: 0, //TODO
332 flete: false, 332 flete: false,
333 fob: false, 333 fob: false,
334 bomba: false, 334 bomba: false,
335 }, 335 },
336 notaPedido: { 336 notaPedido: {
337 id: 0 337 id: 0
338 } 338 },
339 articulos: hojaRutaBusinessService.addArticulos($scope.articulosRecibidos,
340 $scope.hojaRuta.cotizacion.VENDEDOR),
341 puntosDescarga: [],
342 plazos: []
339 }; 343 };
340 focaCrearHojaRutaService.crearRemito(save).then( 344 focaCrearHojaRutaService.crearRemito(save).then(
341 function (data) { 345 function (data) {
342 focaBotoneraLateralService.endGuardar(true); 346 focaBotoneraLateralService.endGuardar(true);
343 $scope.saveLoading = false; 347 $scope.saveLoading = false;
344 348
345 $scope.remito.id = data.data.id; 349 $scope.remito.id = data.data.id;
346 350
347 focaCrearHojaRutaService.guardarCisternas({ 351 focaCrearHojaRutaService.guardarCisternas({
348 cisternaCargas: $scope.cisternaCargas, 352 cisternaCargas: $scope.cisternaCargas,
349 cisternaMovimientos: $scope.cisternaMovimientos, 353 cisternaMovimientos: $scope.cisternaMovimientos,
350 fechaReparto: $scope.hojaRuta.fechaReparto, 354 fechaReparto: $scope.hojaRuta.fechaReparto,
351 idVehiculo: $scope.hojaRuta.vehiculo.id 355 idVehiculo: $scope.hojaRuta.vehiculo.id
352 }, data.data.id); 356 }, data.data.id);
353 $scope.remito.numeroRemito = data.data.numero; 357 $scope.remito.numeroRemito = data.data.numero;
354 358
355 // if ($scope.remito.remitoPuntoDescarga.length > 0) {
356 // remitoBusinessService.addPuntosDescarga(data.data.id,
357 // $scope.remito.remitoPuntoDescarga);
358 // }
359
360 hojaRutaBusinessService.addArticulos($scope.articulosRecibidos,
361 data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR);
362
363 guardarHojaRuta(data.data.id); 359 guardarHojaRuta(data.data.id);
364 360
365 }, function (error) { 361 }, function (error) {
366 focaModalService.alert( 362 focaModalService.alert(
367 error.data || 'Hubo un error al crear el remito'); 363 error.data || 'Hubo un error al crear el remito');
368 focaBotoneraLateralService.endGuardar(); 364 focaBotoneraLateralService.endGuardar();
369 $scope.saveLoading = false; 365 $scope.saveLoading = false;
370 console.info(error); 366 console.info(error);
371 } 367 }
372 ); 368 );
373 369
374 function guardarHojaRuta(idRemito) { 370 function guardarHojaRuta(idRemito) {
375 371
376 var save2 = { 372 var save2 = {
377 hojaRuta: { 373 hojaRuta: {
378 id: 0, 374 id: 0,
379 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 375 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
380 .replace('T', ' '), 376 .replace('T', ' '),
381 idTransportista: $scope.hojaRuta.transportista.COD, 377 idTransportista: $scope.hojaRuta.transportista.COD,
382 idChofer: $scope.hojaRuta.chofer.id, 378 idChofer: $scope.hojaRuta.chofer.id,
383 idVehiculo: $scope.hojaRuta.vehiculo.id, 379 idVehiculo: $scope.hojaRuta.vehiculo.id,
384 proveedor: $scope.hojaRuta.proveedor.id, 380 proveedor: $scope.hojaRuta.proveedor.id,
385 fechaReparto: new Date($scope.hojaRuta.fechaReparto) 381 fechaReparto: new Date($scope.hojaRuta.fechaReparto)
386 .toISOString() 382 .toISOString()
387 .substring(0, 10), 383 .substring(0, 10),
388 estado: 0, 384 estado: 0,
389 abierta: 1 385 abierta: 1
390 }, 386 },
391 remitos: [{ id: idRemito }] 387 remitos: [{ id: idRemito }]
392 }; 388 };
393 389
394 save2.hojaRuta = angular 390 save2.hojaRuta = angular
395 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra); 391 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra);
396 focaCrearHojaRutaService.crearHojaRuta(save2).then( 392 focaCrearHojaRutaService.crearHojaRuta(save2).then(
397 function (data) { 393 function (data) {
398 var remitoNumero; 394 var remitoNumero;
399 data.data.remitos.forEach(function (idRemitos) { 395 data.data.remitos.forEach(function (idRemitos) {
400 remitoNumero = idRemitos; 396 remitoNumero = idRemitos;
401 }); 397 });
402 focaModalService.alert( 398 focaModalService.alert(
403 'Hoja ruta creada Nº: ' + 399 'Hoja ruta creada Nº: ' +
404 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 400 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
405 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + 401 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) +
406 '\nRemito Abierto Nº: ' + 402 '\nRemito Abierto Nº: ' +
407 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' + 403 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' +
408 $filter('rellenarDigitos')(remitoNumero.numeroRemito, 8) 404 $filter('rellenarDigitos')(remitoNumero.numeroRemito, 8)
409 ); 405 );
410 406
411 config(); 407 config();
412 }, 408 },
413 function (error) { 409 function (error) {
414 410
415 focaModalService 411 focaModalService
416 .alert('Hubo un error al crear la hoja de ruta'); 412 .alert('Hubo un error al crear la hoja de ruta');
417 413
418 console.info(error); 414 console.info(error);
419 } 415 }
420 ); 416 );
421 } 417 }
422 } 418 }
423 } 419 }
424 420
425 $scope.seleccionarCliente = function () { 421 $scope.seleccionarCliente = function () {
426 var modalInstance = $uibModal.open( 422 var modalInstance = $uibModal.open(
427 { 423 {
428 ariaLabelledBy: 'Busqueda de Cliente', 424 ariaLabelledBy: 'Busqueda de Cliente',
429 templateUrl: 'foca-busqueda-cliente-modal.html', 425 templateUrl: 'foca-busqueda-cliente-modal.html',
430 controller: 'focaBusquedaClienteModalController', 426 controller: 'focaBusquedaClienteModalController',
431 resolve: { 427 resolve: {
432 parametros: function () { 428 parametros: function () {
433 return { 429 return {
434 vendedor: function () { return null; }, 430 vendedor: function () { return null; },
435 cobrador: function () { return null; } 431 cobrador: function () { return null; }
436 } 432 }
437 } 433 }
438 }, 434 },
439 size: 'lg' 435 size: 'lg'
440 } 436 }
441 ); 437 );
442 modalInstance.result.then($scope.abrirModalDomicilios); 438 modalInstance.result.then($scope.abrirModalDomicilios);
443 }; 439 };
444 440
445 $scope.abrirModalDomicilios = function (cliente) { 441 $scope.abrirModalDomicilios = function (cliente) {
446 var modalInstanceDomicilio = $uibModal.open( 442 var modalInstanceDomicilio = $uibModal.open(
447 { 443 {
448 ariaLabelledBy: 'Busqueda de Domicilios', 444 ariaLabelledBy: 'Busqueda de Domicilios',
449 templateUrl: 'modal-domicilio.html', 445 templateUrl: 'modal-domicilio.html',
450 controller: 'focaModalDomicilioController', 446 controller: 'focaModalDomicilioController',
451 size: 'lg', 447 size: 'lg',
452 resolve: { 448 resolve: {
453 idCliente: function () { return cliente.COD; }, 449 idCliente: function () { return cliente.COD; },
454 esNuevo: function () { return cliente.esNuevo; } 450 esNuevo: function () { return cliente.esNuevo; }
455 } 451 }
456 } 452 }
457 ); 453 );
458 modalInstanceDomicilio.result.then( 454 modalInstanceDomicilio.result.then(
459 function (domicilio) { 455 function (domicilio) {
460 $scope.hojaRuta.domicilio = domicilio; 456 $scope.hojaRuta.domicilio = domicilio;
461 $scope.hojaRuta.cliente = cliente; 457 $scope.hojaRuta.cliente = cliente;
462 458
463 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN) 459 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN)
464 .then(function (res) { 460 .then(function (res) {
465 if (res.data !== '') { 461 if (res.data !== '') {
466 $scope.hojaRuta.vendedor = res.data; 462 $scope.hojaRuta.vendedor = res.data;
467 $scope.$broadcast('addCabecera', { 463 $scope.$broadcast('addCabecera', {
468 label: 'Vendedor:', 464 label: 'Vendedor:',
469 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor 465 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor
470 .NUM, 3) + ' - ' + $scope.hojaRuta.vendedor.NOM 466 .NUM, 3) + ' - ' + $scope.hojaRuta.vendedor.NOM
471 }); 467 });
472 } 468 }
473 var domicilioStamp = 469 var domicilioStamp =
474 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 470 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
475 domicilio.Localidad + ', ' + domicilio.Provincia; 471 domicilio.Localidad + ', ' + domicilio.Provincia;
476 $scope.hojaRuta.domicilioStamp = domicilioStamp; 472 $scope.hojaRuta.domicilioStamp = domicilioStamp;
477 $scope.$broadcast('addCabecera', { 473 $scope.$broadcast('addCabecera', {
478 label: 'Cliente:', 474 label: 'Cliente:',
479 valor: $filter('rellenarDigitos')(cliente.COD, 3) + 475 valor: $filter('rellenarDigitos')(cliente.COD, 3) +
480 ' - ' + cliente.NOM 476 ' - ' + cliente.NOM
481 }); 477 });
482 $scope.$broadcast('addCabecera', { 478 $scope.$broadcast('addCabecera', {
483 label: 'Domicilio:', 479 label: 'Domicilio:',
484 valor: domicilioStamp 480 valor: domicilioStamp
485 }); 481 });
486 482
487 if (domicilio.verPuntos) { 483 if (domicilio.verPuntos) {
488 delete $scope.hojaRuta.domicilio.verPuntos; 484 delete $scope.hojaRuta.domicilio.verPuntos;
489 $scope.seleccionarPuntosDeDescarga(); 485 $scope.seleccionarPuntosDeDescarga();
490 } else { 486 } else {
491 focaCrearHojaRutaService 487 focaCrearHojaRutaService
492 .getPuntosDescargaByClienDom(domicilio.id, cliente.COD) 488 .getPuntosDescargaByClienDom(domicilio.id, cliente.COD)
493 .then(function (res) { 489 .then(function (res) {
494 if (res.data.length) { 490 if (res.data.length) {
495 $scope.seleccionarPuntosDeDescarga(); 491 $scope.seleccionarPuntosDeDescarga();
496 } 492 }
497 }); 493 });
498 } 494 }
499 495
500 $filter('filter')($scope.botonera, { 496 $filter('filter')($scope.botonera, {
501 label: 'Cliente', 497 label: 'Cliente',
502 })[0].checked = true; 498 })[0].checked = true;
503 }) 499 })
504 .catch(function (e) { console.log(e); }); 500 .catch(function (e) { console.log(e); });
505 }, function () { 501 }, function () {
506 $scope.seleccionarCliente(true); 502 $scope.seleccionarCliente(true);
507 return; 503 return;
508 } 504 }
509 ); 505 );
510 }; 506 };
511 507
512 $scope.seleccionarPuntosDeDescarga = function () { 508 $scope.seleccionarPuntosDeDescarga = function () {
513 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) { 509 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) {
514 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 510 focaModalService.alert('Primero seleccione un cliente y un domicilio');
515 return; 511 return;
516 } else { 512 } else {
517 var modalInstance = $uibModal.open( 513 var modalInstance = $uibModal.open(
518 { 514 {
519 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 515 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
520 templateUrl: 'modal-punto-descarga.html', 516 templateUrl: 'modal-punto-descarga.html',
521 controller: 'focaModalPuntoDescargaController', 517 controller: 'focaModalPuntoDescargaController',
522 size: 'lg', 518 size: 'lg',
523 resolve: { 519 resolve: {
524 filters: { 520 filters: {
525 idDomicilio: $scope.remito.domicilio.id, 521 idDomicilio: $scope.remito.domicilio.id,
526 idCliente: $scope.remito.cliente.COD, 522 idCliente: $scope.remito.cliente.COD,
527 articulos: $scope.remito.articulosRemito, 523 articulos: $scope.remito.articulosRemito,
528 puntosDescarga: $scope.remito.remitoPuntoDescarga, 524 puntosDescarga: $scope.remito.remitoPuntoDescarga,
529 domicilio: $scope.remito.domicilio 525 domicilio: $scope.remito.domicilio
530 } 526 }
531 } 527 }
532 } 528 }
533 ); 529 );
534 modalInstance.result.then( 530 modalInstance.result.then(
535 function (puntosDescarga) { 531 function (puntosDescarga) {
536 532
537 puntosDescarga.forEach(function (punto) { 533 puntosDescarga.forEach(function (punto) {
538 $scope.hojaRuta.remitoPuntoDescarga.push( 534 $scope.hojaRuta.remitoPuntoDescarga.push(
539 { 535 {
540 puntoDescarga: punto 536 puntoDescarga: punto
541 } 537 }
542 ); 538 );
543 }); 539 });
544 540
545 $scope.$broadcast('addCabecera', { 541 $scope.$broadcast('addCabecera', {
546 label: 'Puntos de descarga:', 542 label: 'Puntos de descarga:',
547 valor: getCabeceraPuntoDescarga(puntosDescarga) 543 valor: getCabeceraPuntoDescarga(puntosDescarga)
548 }); 544 });
549 }, function () { 545 }, function () {
550 $scope.abrirModalDomicilios($scope.cliente); 546 $scope.abrirModalDomicilios($scope.cliente);
551 } 547 }
552 ); 548 );
553 } 549 }
554 }; 550 };
555 551
556 $scope.seleccionarDetalleDeCarga = function () { 552 $scope.seleccionarDetalleDeCarga = function () {
557 if ($scope.hojaRuta.vehiculo.capacidad === 0) { 553 if ($scope.hojaRuta.vehiculo.capacidad === 0) {
558 focaModalService.alert('Debe ingresar vehiculo'); 554 focaModalService.alert('Debe ingresar vehiculo');
559 return; 555 return;
560 } else { 556 } else {
561 $scope.mostrarDetalle($scope.hojaRuta); 557 $scope.mostrarDetalle($scope.hojaRuta);
562 } 558 }
563 }; 559 };
564 560
565 function getCabeceraPuntoDescarga(puntosDescarga) { 561 function getCabeceraPuntoDescarga(puntosDescarga) {
566 var puntosStamp = ''; 562 var puntosStamp = '';
567 puntosDescarga.forEach(function (punto, idx, arr) { 563 puntosDescarga.forEach(function (punto, idx, arr) {
568 puntosStamp += punto.descripcion; 564 puntosStamp += punto.descripcion;
569 if ((idx + 1) !== arr.length) puntosStamp += ', '; 565 if ((idx + 1) !== arr.length) puntosStamp += ', ';
570 }); 566 });
571 return puntosStamp; 567 return puntosStamp;
572 } 568 }
573 569
574 $scope.crearHojaRuta = function () { 570 $scope.crearHojaRuta = function () {
575 571
576 var continuar = validarHojaRuta(); 572 var continuar = validarHojaRuta();
577 if (!continuar) { 573 if (!continuar) {
578 return; 574 return;
579 } else if ($scope.remitoAbierto) { 575 } else if ($scope.remitoAbierto) {
580 guardarRemitoAbierto(); 576 guardarRemitoAbierto();
581 return; 577 return;
582 } 578 }
583 var date = new Date(); 579 var date = new Date();
584 var save = { 580 var save = {
585 hojaRuta: { 581 hojaRuta: {
586 id: 0, 582 id: 0,
587 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 583 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
588 .replace('T', ' '), 584 .replace('T', ' '),
589 idTransportista: $scope.hojaRuta.transportista.COD, 585 idTransportista: $scope.hojaRuta.transportista.COD,
590 idChofer: $scope.hojaRuta.chofer.id, 586 idChofer: $scope.hojaRuta.chofer.id,
591 idVehiculo: $scope.hojaRuta.vehiculo.id, 587 idVehiculo: $scope.hojaRuta.vehiculo.id,
592 tarifaFlete: $scope.hojaRuta.tarifario, 588 tarifaFlete: $scope.hojaRuta.tarifario,
593 fechaReparto: 589 fechaReparto:
594 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), 590 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10),
595 estado: 0 591 estado: 0
596 }, 592 },
597 remitos: $scope.hojaRuta.remitosTabla 593 remitos: $scope.hojaRuta.remitosTabla
598 }; 594 };
599 595
600 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 596 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
601 focaCrearHojaRutaService.crearHojaRuta(save).then( 597 focaCrearHojaRutaService.crearHojaRuta(save).then(
602 function (data) { 598 function (data) {
603 focaModalService.alert( 599 focaModalService.alert(
604 'Hoja ruta creada Nº: ' + 600 'Hoja ruta creada Nº: ' +
605 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 601 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
606 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' + 602 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' +
607 $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' + 603 $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' +
608 $scope.hojaRuta.orden 604 $scope.hojaRuta.orden
609 ); 605 );
610 606
611 config(); 607 config();
612 }, 608 },
613 function (error) { 609 function (error) {
614 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 610 focaModalService.alert('Hubo un error al crear la hoja de ruta');
615 console.info(error); 611 console.info(error);
616 } 612 }
617 ); 613 );
618 }; 614 };
619 615
620 $scope.seleccionarProveedor = function () { 616 $scope.seleccionarProveedor = function () {
621 var parametrosModal = { 617 var parametrosModal = {
622 titulo: 'Búsqueda de Proveedor', 618 titulo: 'Búsqueda de Proveedor',
623 query: '/proveedor', 619 query: '/proveedor',
624 columnas: [ 620 columnas: [
625 { 621 {
626 nombre: 'Código', 622 nombre: 'Código',
627 propiedad: 'COD', 623 propiedad: 'COD',
628 filtro: { 624 filtro: {
629 nombre: 'rellenarDigitos', 625 nombre: 'rellenarDigitos',
630 parametro: 5 626 parametro: 5
631 } 627 }
632 }, 628 },
633 { 629 {
634 nombre: 'Nombre', 630 nombre: 'Nombre',
635 propiedad: 'NOM' 631 propiedad: 'NOM'
636 }, 632 },
637 { 633 {
638 nombre: 'CUIT', 634 nombre: 'CUIT',
639 propiedad: 'CUIT' 635 propiedad: 'CUIT'
640 } 636 }
641 ], 637 ],
642 tipo: 'POST', 638 tipo: 'POST',
643 json: { razonCuitCod: '' } 639 json: { razonCuitCod: '' }
644 }; 640 };
645 focaModalService.modal(parametrosModal).then( 641 focaModalService.modal(parametrosModal).then(
646 function (proveedor) { 642 function (proveedor) {
647 $filter('filter')($scope.botonera, { 643 $filter('filter')($scope.botonera, {
648 label: 'Proveedor', 644 label: 'Proveedor',
649 })[0].checked = true; 645 })[0].checked = true;
650 646
651 $scope.$broadcast('addCabecera', { 647 $scope.$broadcast('addCabecera', {
652 label: 'Proveedor:', 648 label: 'Proveedor:',
653 valor: proveedor.COD + ' - ' + proveedor.NOM 649 valor: proveedor.COD + ' - ' + proveedor.NOM
654 }); 650 });
655 $scope.hojaRuta.proveedor = proveedor; 651 $scope.hojaRuta.proveedor = proveedor;
656 }, function () { } 652 }, function () { }
657 ); 653 );
658 }; 654 };
659 655
660 $scope.seleccionarTransportista = function () { 656 $scope.seleccionarTransportista = function () {
661 if (eligioPreConfirmado()) return; 657 if (eligioPreConfirmado()) return;
662 var parametrosModal = { 658 var parametrosModal = {
663 titulo: 'Búsqueda de transportista', 659 titulo: 'Búsqueda de transportista',
664 query: '/transportista', 660 query: '/transportista',
665 columnas: [ 661 columnas: [
666 { 662 {
667 nombre: 'Código', 663 nombre: 'Código',
668 propiedad: 'COD' 664 propiedad: 'COD'
669 }, 665 },
670 { 666 {
671 nombre: 'Nombre', 667 nombre: 'Nombre',
672 propiedad: 'NOM' 668 propiedad: 'NOM'
673 }, 669 },
674 { 670 {
675 nombre: 'CUIT', 671 nombre: 'CUIT',
676 propiedad: 'CUIT' 672 propiedad: 'CUIT'
677 } 673 }
678 ] 674 ]
679 }; 675 };
680 focaModalService.modal(parametrosModal).then( 676 focaModalService.modal(parametrosModal).then(
681 function (proveedor) { 677 function (proveedor) {
682 $scope.hojaRuta.transportista = proveedor; 678 $scope.hojaRuta.transportista = proveedor;
683 $scope.$broadcast('addCabecera', { 679 $scope.$broadcast('addCabecera', {
684 label: 'Transportista:', 680 label: 'Transportista:',
685 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 681 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
686 proveedor.NOM 682 proveedor.NOM
687 }); 683 });
688 684
689 $filter('filter')($scope.botonera, { 685 $filter('filter')($scope.botonera, {
690 label: 'Transportista', 686 label: 'Transportista',
691 })[0].checked = true; 687 })[0].checked = true;
692 }, function () { 688 }, function () {
693 689
694 } 690 }
695 ); 691 );
696 }; 692 };
697 693
698 $scope.seleccionarChofer = function () { 694 $scope.seleccionarChofer = function () {
699 var parametrosModal = { 695 var parametrosModal = {
700 titulo: 'Búsqueda de Chofer', 696 titulo: 'Búsqueda de Chofer',
701 query: '/chofer', 697 query: '/chofer',
702 columnas: [ 698 columnas: [
703 { 699 {
704 propiedad: 'id', 700 propiedad: 'id',
705 nombre: 'Código', 701 nombre: 'Código',
706 filtro: { 702 filtro: {
707 nombre: 'rellenarDigitos', 703 nombre: 'rellenarDigitos',
708 parametro: 3 704 parametro: 3
709 } 705 }
710 }, 706 },
711 { 707 {
712 propiedad: 'nombre', 708 propiedad: 'nombre',
713 nombre: 'Nombre' 709 nombre: 'Nombre'
714 }, 710 },
715 { 711 {
716 propiedad: 'dni', 712 propiedad: 'dni',
717 nombre: 'DNI' 713 nombre: 'DNI'
718 }, 714 },
719 { 715 {
720 propiedad: 'telefono', 716 propiedad: 'telefono',
721 nombre: 'Teléfono' 717 nombre: 'Teléfono'
722 } 718 }
723 ] 719 ]
724 }; 720 };
725 focaModalService.modal(parametrosModal).then( 721 focaModalService.modal(parametrosModal).then(
726 function (chofer) { 722 function (chofer) {
727 $scope.hojaRuta.chofer = chofer; 723 $scope.hojaRuta.chofer = chofer;
728 $scope.$broadcast('addCabecera', { 724 $scope.$broadcast('addCabecera', {
729 label: 'Chofer:', 725 label: 'Chofer:',
730 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre 726 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre
731 }); 727 });
732 728
733 $filter('filter')($scope.botonera, { 729 $filter('filter')($scope.botonera, {
734 label: 'Chofer', 730 label: 'Chofer',
735 })[0].checked = true; 731 })[0].checked = true;
736 }, function () { 732 }, function () {
737 // funcion ejecutada cuando se cancela el modal 733 // funcion ejecutada cuando se cancela el modal
738 } 734 }
739 ); 735 );
740 }; 736 };
741 737
742 $scope.seleccionarVehiculo = function () { 738 $scope.seleccionarVehiculo = function () {
743 if (!eligioFecha() || eligioPreConfirmado()) return; 739 if (!eligioFecha() || eligioPreConfirmado()) return;
744 modalVehiculos(); 740 modalVehiculos();
745 }; 741 };
746 742
747 $scope.seleccionarTarifario = function () { 743 $scope.seleccionarTarifario = function () {
748 focaModalService 744 focaModalService
749 .prompt({ 745 .prompt({
750 titulo: 'Tarifa flete', 746 titulo: 'Tarifa flete',
751 value: $scope.hojaRuta.tarifario 747 value: $scope.hojaRuta.tarifario
752 }) 748 })
753 .then(function (costo) { 749 .then(function (costo) {
754 if (isNaN(costo)) { 750 if (isNaN(costo)) {
755 focaModalService 751 focaModalService
756 .alert('Ingrese un valor válido') 752 .alert('Ingrese un valor válido')
757 .then(function () { 753 .then(function () {
758 $scope.seleccionarTarifario(); 754 $scope.seleccionarTarifario();
759 }); 755 });
760 756
761 return; 757 return;
762 } 758 }
763 759
764 $scope.hojaRuta.tarifario = costo; 760 $scope.hojaRuta.tarifario = costo;
765 $scope.$broadcast('addCabecera', { 761 $scope.$broadcast('addCabecera', {
766 label: 'Tarifario:', 762 label: 'Tarifario:',
767 valor: costo 763 valor: costo
768 }); 764 });
769 765
770 $filter('filter')($scope.botonera, { 766 $filter('filter')($scope.botonera, {
771 label: 'Tarifario', 767 label: 'Tarifario',
772 })[0].checked = true; 768 })[0].checked = true;
773 }); 769 });
774 }; 770 };
775 771
776 $scope.seleccionarRemitos = function () { 772 $scope.seleccionarRemitos = function () {
777 773
778 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 774 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
779 775
780 var modalInstance = $uibModal.open( 776 var modalInstance = $uibModal.open(
781 { 777 {
782 ariaLabelledBy: 'Busqueda de Remito', 778 ariaLabelledBy: 'Busqueda de Remito',
783 templateUrl: 'foca-modal-remito.html', 779 templateUrl: 'foca-modal-remito.html',
784 controller: 'focaModalRemitoController', 780 controller: 'focaModalRemitoController',
785 size: 'lg', 781 size: 'lg',
786 resolve: { usadoPor: function () { return 'hojaRuta'; } } 782 resolve: { usadoPor: function () { return 'hojaRuta'; } }
787 } 783 }
788 ); 784 );
789 modalInstance.result 785 modalInstance.result
790 .then(function (remito) { 786 .then(function (remito) {
791 // TODO: borrar cuando no se use definitivamente 787 // TODO: borrar cuando no se use definitivamente
792 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { 788 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
793 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { 789 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
794 // focaModalService.alert('Remito ya incluido'); 790 // focaModalService.alert('Remito ya incluido');
795 // return; 791 // return;
796 // } 792 // }
797 // } 793 // }
798 794
799 // var litros = 0; 795 // var litros = 0;
800 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 796 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
801 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 797 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
802 // } 798 // }
803 799
804 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 800 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
805 // focaModalService.alert( 801 // focaModalService.alert(
806 // 'Debe ingresar toda la información para el transporte' 802 // 'Debe ingresar toda la información para el transporte'
807 // ); 803 // );
808 // return; 804 // return;
809 // } 805 // }
810 806
811 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 807 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
812 // { 808 // {
813 // var litrostotales = litros; 809 // var litrostotales = litros;
814 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 810 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
815 // focaModalService.alert( 811 // focaModalService.alert(
816 // 'La carga excede la capacidad disponible del vehiculo. ' + 812 // 'La carga excede la capacidad disponible del vehiculo. ' +
817 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 813 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
818 // ); 814 // );
819 // } 815 // }
820 816
821 // remito.litros = litros; 817 // remito.litros = litros;
822 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 818 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
823 $scope.cargarCisterna(remito.id) 819 $scope.cargarCisterna(remito.id)
824 .then(function () { 820 .then(function () {
825 $scope.hojaRuta.remitosTabla.push(remito); 821 $scope.hojaRuta.remitosTabla.push(remito);
826 $filter('filter')($scope.botonera, { 822 $filter('filter')($scope.botonera, {
827 label: 'Remitos', 823 label: 'Remitos',
828 })[0].checked = true; 824 })[0].checked = true;
829 825
830 }) 826 })
831 .catch(function (error) { 827 .catch(function (error) {
832 console.error(error); 828 console.error(error);
833 $scope.seleccionarRemitos(); 829 $scope.seleccionarRemitos();
834 }); 830 });
835 }) 831 })
836 .catch(function (e) { console.error(e); }); 832 .catch(function (e) { console.error(e); });
837 }; 833 };
838 834
839 $scope.seleccionarVehiculosPrecargados = function () { 835 $scope.seleccionarVehiculosPrecargados = function () {
840 if (!eligioFecha()) return; 836 if (!eligioFecha()) return;
841 modalVehiculos(true); 837 modalVehiculos(true);
842 }; 838 };
843 839
844 $scope.cargarCisterna = function (idRemito) { 840 $scope.cargarCisterna = function (idRemito) {
845 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 841 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
846 var modalInstance = $uibModal.open( 842 var modalInstance = $uibModal.open(
847 { 843 {
848 ariaLabelledBy: 'Busqueda de Vehiculo', 844 ariaLabelledBy: 'Busqueda de Vehiculo',
849 templateUrl: 'foca-detalle-vehiculo.html', 845 templateUrl: 'foca-detalle-vehiculo.html',
850 controller: 'focaDetalleVehiculo', 846 controller: 'focaDetalleVehiculo',
851 size: 'lg', 847 size: 'lg',
852 resolve: { 848 resolve: {
853 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; }, 849 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; },
854 idRemito: function () { return idRemito; }, 850 idRemito: function () { return idRemito; },
855 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; }, 851 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; },
856 orden: function () { return $scope.hojaRuta.orden; } 852 orden: function () { return $scope.hojaRuta.orden; }
857 } 853 }
858 } 854 }
859 ); 855 );
860 return modalInstance.result; 856 return modalInstance.result;
861 }; 857 };
862 858
863 $scope.seleccionarFechaEntrega = function () { 859 $scope.seleccionarFechaEntrega = function () {
864 860
865 var confirmacion = false; 861 var confirmacion = false;
866 862
867 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 863 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
868 confirmacion = true; 864 confirmacion = true;
869 } 865 }
870 866
871 if (confirmacion) { 867 if (confirmacion) {
872 focaModalService 868 focaModalService
873 .confirm('Si cambia la fecha se perderán los datos actuales') 869 .confirm('Si cambia la fecha se perderán los datos actuales')
874 .then(function (data) { 870 .then(function (data) {
875 if (data) { 871 if (data) {
876 $scope.hojaRuta.vehiculo.id = undefined; 872 $scope.hojaRuta.vehiculo.id = undefined;
877 $scope.hojaRuta.tarifario = null; 873 $scope.hojaRuta.tarifario = null;
878 $scope.hojaRuta.transportista = {}; 874 $scope.hojaRuta.transportista = {};
879 $scope.hojaRuta.chofer = {}; 875 $scope.hojaRuta.chofer = {};
880 $scope.hojaRuta.datosExtra = undefined; 876 $scope.hojaRuta.datosExtra = undefined;
881 elegirFecha(); 877 elegirFecha();
882 } 878 }
883 }, function () { 879 }, function () {
884 return; 880 return;
885 }); 881 });
886 } else { 882 } else {
887 elegirFecha(); 883 elegirFecha();
888 } 884 }
889 }; 885 };
890 886
891 function setearFecha(fecha) { 887 function setearFecha(fecha) {
892 $timeout(function () { 888 $timeout(function () {
893 $scope.$broadcast('addCabecera', { 889 $scope.$broadcast('addCabecera', {
894 label: 'Fecha de entrega: ', 890 label: 'Fecha de entrega: ',
895 valor: fecha.toLocaleDateString() 891 valor: fecha.toLocaleDateString()
896 }); 892 });
897 $scope.hojaRuta.fechaReparto = fecha; 893 $scope.hojaRuta.fechaReparto = fecha;
898 $scope.inicial.fechaReparto = fecha; 894 $scope.inicial.fechaReparto = fecha;
899 }); 895 });
900 } 896 }
901 897
902 $scope.seleccionarDatosExtra = function () { 898 $scope.seleccionarDatosExtra = function () {
903 var datosHojaRuta = $scope.hojaRuta.datosExtra; 899 var datosHojaRuta = $scope.hojaRuta.datosExtra;
904 var modalInstance = $uibModal.open( 900 var modalInstance = $uibModal.open(
905 { 901 {
906 templateUrl: 'foca-modal-datos-hoja-ruta.html', 902 templateUrl: 'foca-modal-datos-hoja-ruta.html',
907 controller: 'focaModalDatosHojaRutaCtrl', 903 controller: 'focaModalDatosHojaRutaCtrl',
908 size: 'lg', 904 size: 'lg',
909 resolve: { 905 resolve: {
910 parametrosDatos: function () { 906 parametrosDatos: function () {
911 return { 907 return {
912 datosHojaRuta: datosHojaRuta 908 datosHojaRuta: datosHojaRuta
913 }; 909 };
914 } 910 }
915 } 911 }
916 } 912 }
917 ); 913 );
918 return modalInstance.result.then(function (datosExtra) { 914 return modalInstance.result.then(function (datosExtra) {
919 915
920 $filter('filter')($scope.botonera, { 916 $filter('filter')($scope.botonera, {
921 label: 'Datos extra', 917 label: 'Datos extra',
922 })[0].checked = true; 918 })[0].checked = true;
923 919
924 $scope.hojaRuta.datosExtra = datosExtra; 920 $scope.hojaRuta.datosExtra = datosExtra;
925 }, function () { 921 }, function () {
926 //se ejecuta cuando se cancela el modal 922 //se ejecuta cuando se cancela el modal
927 }); 923 });
928 }; 924 };
929 925
930 $scope.desasociarRemito = function (key, idRemito) { 926 $scope.desasociarRemito = function (key, idRemito) {
931 var idsRemito = [idRemito]; 927 var idsRemito = [idRemito];
932 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 928 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
933 ' vehículo?').then(function () { 929 ' vehículo?').then(function () {
934 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 930 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
935 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) 931 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1)
936 .then(function () { 932 .then(function () {
937 $scope.hojaRuta.remitosTabla.splice(key, 1); 933 $scope.hojaRuta.remitosTabla.splice(key, 1);
938 focaModalService.alert('Remito desasociado con éxito'); 934 focaModalService.alert('Remito desasociado con éxito');
939 }); 935 });
940 }); 936 });
941 }; 937 };
942 938
943 $scope.verProductosRemito = function (idRemito) { 939 $scope.verProductosRemito = function (idRemito) {
944 var parametrosModal = { 940 var parametrosModal = {
945 titulo: 'Articulos remito', 941 titulo: 'Articulos remito',
946 query: '/articulos/remito/' + idRemito, 942 query: '/articulos/remito/' + idRemito,
947 soloMostrar: true, 943 soloMostrar: true,
948 columnas: [ 944 columnas: [
949 { 945 {
950 nombre: 'Código', 946 nombre: 'Código',
951 propiedad: 'codigo' 947 propiedad: 'codigo'
952 }, 948 },
953 { 949 {
954 nombre: 'Descripción', 950 nombre: 'Descripción',
955 propiedad: 'descripcion' 951 propiedad: 'descripcion'
956 }, 952 },
957 { 953 {
958 nombre: 'Cantidad', 954 nombre: 'Cantidad',
959 propiedad: 'cantidad' 955 propiedad: 'cantidad'
960 } 956 }
961 ] 957 ]
962 }; 958 };
963 focaModalService.modal(parametrosModal).then(); 959 focaModalService.modal(parametrosModal).then();
964 }; 960 };
965 961
966 $scope.mostrarDetalle = function (hojasRutas) { 962 $scope.mostrarDetalle = function (hojasRutas) {
967 var modalInstance = $uibModal.open( 963 var modalInstance = $uibModal.open(
968 { 964 {
969 ariaLabelledBy: '', 965 ariaLabelledBy: '',
970 templateUrl: 'modal-detalle-carga.html', 966 templateUrl: 'modal-detalle-carga.html',
971 controller: 'focaModalDetalleController', 967 controller: 'focaModalDetalleController',
972 resolve: { 968 resolve: {
973 parametrosModal: function () { 969 parametrosModal: function () {
974 return { 970 return {
975 hojasRutas: hojasRutas, 971 hojasRutas: hojasRutas,
976 orden: $scope.hojaRuta.orden 972 orden: $scope.hojaRuta.orden
977 }; 973 };
978 } 974 }
979 }, 975 },
980 size: 'lg', 976 size: 'lg',
981 backdrop: false 977 backdrop: false
982 } 978 }
983 ); 979 );
984 return modalInstance.result 980 return modalInstance.result
985 .then(function (res) { 981 .then(function (res) {
986 res.cisternas.forEach(function (cisterna) { 982 res.cisternas.forEach(function (cisterna) {
987 $scope.cisternaCargas.push(cisterna.cisternaCarga); 983 $scope.cisternaCargas.push(cisterna.cisternaCarga);
988 }); 984 });
989 $scope.cisternaMovimientos = res.movimientos; 985 $scope.cisternaMovimientos = res.movimientos;
990 $scope.articulosRecibidos = res.articulos; 986 $scope.articulosRecibidos = res.articulos;
991 $scope.articulos = res.articulos; 987 $scope.articulos = res.articulos;
992 $filter('filter')($scope.botonera, { 988 $filter('filter')($scope.botonera, {
993 label: 'Detalle de Carga', 989 label: 'Detalle de Carga',
994 })[0].checked = true; 990 })[0].checked = true;
995 }) 991 })
996 .catch(function (e) { console.error(e); }); 992 .catch(function (e) { console.error(e); });
997 }; 993 };
998 994
999 function elegirFecha() { 995 function elegirFecha() {
1000 var fechaEntrega = { 996 var fechaEntrega = {
1001 titulo: 'Fecha de entrega', 997 titulo: 'Fecha de entrega',
1002 minDate: new Date() 998 minDate: new Date()
1003 }; 999 };
1004 focaModalService.modalFecha(fechaEntrega).then(function (fecha) { 1000 focaModalService.modalFecha(fechaEntrega).then(function (fecha) {
1005 1001
1006 $scope.hojaRuta.fechaReparto = fecha; 1002 $scope.hojaRuta.fechaReparto = fecha;
1007 1003
1008 $scope.$broadcast('addCabecera', { 1004 $scope.$broadcast('addCabecera', {
1009 label: 'Fecha de entrega: ', 1005 label: 'Fecha de entrega: ',
1010 valor: fecha.toLocaleDateString() 1006 valor: fecha.toLocaleDateString()
1011 }); 1007 });
1012 1008
1013 $filter('filter')($scope.botonera, { 1009 $filter('filter')($scope.botonera, {
1014 label: 'Fecha Entrega', 1010 label: 'Fecha Entrega',
1015 })[0].checked = true; 1011 })[0].checked = true;
1016 }); 1012 });
1017 } 1013 }
1018 1014
1019 function eligioPreConfirmado() { 1015 function eligioPreConfirmado() {
1020 if ($scope.eligioPreConfirmado) { 1016 if ($scope.eligioPreConfirmado) {
1021 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 1017 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
1022 return true; 1018 return true;
1023 } 1019 }
1024 return false; 1020 return false;
1025 } 1021 }
1026 1022
1027 function eligioFecha() { 1023 function eligioFecha() {
1028 if (!$scope.hojaRuta.fechaReparto) { 1024 if (!$scope.hojaRuta.fechaReparto) {
1029 focaModalService.alert('Primero seleccione fecha de reparto'); 1025 focaModalService.alert('Primero seleccione fecha de reparto');
1030 return false; 1026 return false;
1031 } 1027 }
1032 return true; 1028 return true;
1033 } 1029 }
1034 1030
1035 function eligioVehiculo() { 1031 function eligioVehiculo() {
1036 if (!$scope.hojaRuta.vehiculo.id) { 1032 if (!$scope.hojaRuta.vehiculo.id) {
1037 focaModalService.alert('Primero seleccione vehiculo'); 1033 focaModalService.alert('Primero seleccione vehiculo');
1038 return false; 1034 return false;
1039 } 1035 }
1040 return true; 1036 return true;
1041 } 1037 }
1042 1038
1043 function modalVehiculos(preCargados) { 1039 function modalVehiculos(preCargados) {
1044 1040
1045 var parametrosModal = {}; 1041 var parametrosModal = {};
1046 if (preCargados) { 1042 if (preCargados) {
1047 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 1043 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
1048 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); 1044 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
1049 parametrosModal.titulo = 'Búsqueda de vehiculos precargados'; 1045 parametrosModal.titulo = 'Búsqueda de vehiculos precargados';
1050 } else { 1046 } else {
1051 parametrosModal.query = '/vehiculo'; 1047 parametrosModal.query = '/vehiculo';
1052 parametrosModal.titulo = 'Búsqueda de vehículos'; 1048 parametrosModal.titulo = 'Búsqueda de vehículos';
1053 } 1049 }
1054 parametrosModal.columnas = [ 1050 parametrosModal.columnas = [
1055 { 1051 {
1056 propiedad: 'codigo', 1052 propiedad: 'codigo',
1057 nombre: 'Código' 1053 nombre: 'Código'
1058 }, 1054 },
1059 { 1055 {
1060 propiedad: 'tractor', 1056 propiedad: 'tractor',
1061 nombre: 'tractor' 1057 nombre: 'tractor'
1062 }, 1058 },
1063 { 1059 {
1064 propiedad: 'semi', 1060 propiedad: 'semi',
1065 nombre: 'Semi' 1061 nombre: 'Semi'
1066 } 1062 }
1067 ]; 1063 ];
1068 1064
1069 focaModalService.modal(parametrosModal).then(function (vehiculo) { 1065 focaModalService.modal(parametrosModal).then(function (vehiculo) {
1070 if (!preCargados && vehiculoEnUso(vehiculo)) return; 1066 if (!preCargados && vehiculoEnUso(vehiculo)) return;
1071 $scope.hojaRuta.vehiculo = vehiculo; 1067 $scope.hojaRuta.vehiculo = vehiculo;
1072 $scope.hojaRuta.transportista = vehiculo.transportista; 1068 $scope.hojaRuta.transportista = vehiculo.transportista;
1073 // mostrarDetalle(vehiculo); 1069 // mostrarDetalle(vehiculo);
1074 if (preCargados) { 1070 if (preCargados) {
1075 $scope.eligioPreConfirmado = true; 1071 $scope.eligioPreConfirmado = true;
1076 $scope.hojaRuta.vehiculo = vehiculo; 1072 $scope.hojaRuta.vehiculo = vehiculo;
1077 $scope.$broadcast('addCabecera', { 1073 $scope.$broadcast('addCabecera', {
1078 label: 'Transportista:', 1074 label: 'Transportista:',
1079 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 1075 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
1080 ' - ' + vehiculo.transportista.NOM 1076 ' - ' + vehiculo.transportista.NOM
1081 }); 1077 });
1082 focaCrearHojaRutaService 1078 focaCrearHojaRutaService
1083 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) 1079 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
1084 .then(function (res) { 1080 .then(function (res) {
1085 $filter('filter')($scope.botonera, { 1081 $filter('filter')($scope.botonera, {
1086 label: 'Transportista', 1082 label: 'Transportista',
1087 })[0].checked = true; 1083 })[0].checked = true;
1088 1084
1089 $filter('filter')($scope.botonera, { 1085 $filter('filter')($scope.botonera, {
1090 label: 'Vehiculo', 1086 label: 'Vehiculo',
1091 })[0].checked = true; 1087 })[0].checked = true;
1092 1088
1093 $scope.hojaRuta.remitosTabla = res.data; 1089 $scope.hojaRuta.remitosTabla = res.data;
1094 }); 1090 });
1095 } else { 1091 } else {
1096 focaCrearHojaRutaService 1092 focaCrearHojaRutaService
1097 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) 1093 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
1098 .then(function (res) { 1094 .then(function (res) {
1099 1095
1100 $filter('filter')($scope.botonera, { 1096 $filter('filter')($scope.botonera, {
1101 label: 'Vehiculo', 1097 label: 'Vehiculo',
1102 })[0].checked = true; 1098 })[0].checked = true;
1103 1099
1104 $scope.hojaRuta.remitosTabla = res.data; 1100 $scope.hojaRuta.remitosTabla = res.data;
1105 }); 1101 });
1106 } 1102 }
1107 1103
1108 focaCrearHojaRutaService 1104 focaCrearHojaRutaService
1109 .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto) 1105 .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto)
1110 .then(function (res) { 1106 .then(function (res) {
1111 $scope.hojaRuta.orden = res.data; 1107 $scope.hojaRuta.orden = res.data;
1112 }); 1108 });
1113 1109
1114 $scope.$broadcast('addCabecera', { 1110 $scope.$broadcast('addCabecera', {
1115 label: 'Tractor:', 1111 label: 'Tractor:',
1116 valor: vehiculo.tractor 1112 valor: vehiculo.tractor
1117 }); 1113 });
1118 $scope.$broadcast('addCabecera', { 1114 $scope.$broadcast('addCabecera', {
1119 label: 'Semi:', 1115 label: 'Semi:',
1120 valor: vehiculo.semi 1116 valor: vehiculo.semi
1121 }); 1117 });
1122 $scope.$broadcast('addCabecera', { 1118 $scope.$broadcast('addCabecera', {
1123 label: 'Capacidad:', 1119 label: 'Capacidad:',
1124 valor: vehiculo.capacidad 1120 valor: vehiculo.capacidad
1125 }); 1121 });
1126 1122
1127 }); 1123 });
1128 } 1124 }
1129 1125
1130 function vehiculoEnUso(vehiculo) { 1126 function vehiculoEnUso(vehiculo) {
1131 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 1127 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
1132 for (var i = 0; i < vehiculo.cisternas.length; i++) { 1128 for (var i = 0; i < vehiculo.cisternas.length; i++) {
1133 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 1129 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
1134 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 1130 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
1135 if (cisternaCarga.fechaReparto.substring(0, 10) === 1131 if (cisternaCarga.fechaReparto.substring(0, 10) ===
1136 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && 1132 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
1137 cisternaCarga.idUsuarioProceso && 1133 cisternaCarga.idUsuarioProceso &&
1138 cisternaCarga.idUsuarioProceso !== idUsuario) { 1134 cisternaCarga.idUsuarioProceso !== idUsuario) {
1139 focaModalService.alert('El vehículo está siendo usado por otro' + 1135 focaModalService.alert('El vehículo está siendo usado por otro' +
1140 ' usuario'); 1136 ' usuario');
1141 return true; 1137 return true;
1142 } 1138 }
1143 } 1139 }
1144 } 1140 }
1145 return false; 1141 return false;
1146 } 1142 }
1147 1143
1148 function salir() { 1144 function salir() {
1149 var confirmacion = false; 1145 var confirmacion = false;
1150 1146
1151 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 1147 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
1152 confirmacion = true; 1148 confirmacion = true;
1153 } 1149 }
1154 1150
1155 if (confirmacion) { 1151 if (confirmacion) {
1156 focaModalService.confirm( 1152 focaModalService.confirm(
1157 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1153 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1158 ).then(function (data) { 1154 ).then(function (data) {
1159 if (data) { 1155 if (data) {
1160 $location.path('/'); 1156 $location.path('/');
1161 } 1157 }
1162 }); 1158 });
1163 } else { 1159 } else {
1164 $location.path('/'); 1160 $location.path('/');
1165 } 1161 }
1166 } 1162 }
1167 1163
1168 function limpiarBotonera(botonera) { 1164 function limpiarBotonera(botonera) {
1169 botonera.forEach(function (boton) { 1165 botonera.forEach(function (boton) {
1170 boton.checked = false; 1166 boton.checked = false;
1171 }); 1167 });
1172 } 1168 }
1173 function setearHojaRuta(hojaRuta) { 1169 function setearHojaRuta(hojaRuta) {
1174 $scope.$broadcast('cleanCabecera'); 1170 $scope.$broadcast('cleanCabecera');
1175 1171
1176 var cabeceras = []; 1172 var cabeceras = [];
1177 if (hojaRuta.fechaReparto) { 1173 if (hojaRuta.fechaReparto) {
1178 cabeceras.push({ 1174 cabeceras.push({
1179 label: 'Fecha de entrega:', 1175 label: 'Fecha de entrega:',
1180 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 1176 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
1181 }); 1177 });
1182 1178
1183 $filter('filter')($scope.botonera, { 1179 $filter('filter')($scope.botonera, {
1184 label: 'Fecha Entrega' 1180 label: 'Fecha Entrega'
1185 })[0].checked = true; 1181 })[0].checked = true;
1186 } 1182 }
1187 if (hojaRuta.transportista.COD) { 1183 if (hojaRuta.transportista.COD) {
1188 cabeceras.push({ 1184 cabeceras.push({
1189 label: 'Transportista:', 1185 label: 'Transportista:',
1190 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + 1186 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
1191 hojaRuta.transportista.NOM 1187 hojaRuta.transportista.NOM
1192 }); 1188 });
1193 1189
1194 $filter('filter')($scope.botonera, { 1190 $filter('filter')($scope.botonera, {
1195 label: 'Transportista' 1191 label: 'Transportista'
1196 })[0].checked = true; 1192 })[0].checked = true;
1197 } 1193 }
1198 if (hojaRuta.chofer.id) { 1194 if (hojaRuta.chofer.id) {
1199 cabeceras.push({ 1195 cabeceras.push({
1200 label: 'Chofer:', 1196 label: 'Chofer:',
1201 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + 1197 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
1202 ' - ' + hojaRuta.chofer.nombre 1198 ' - ' + hojaRuta.chofer.nombre
1203 }); 1199 });
1204 1200
1205 $filter('filter')($scope.botonera, { 1201 $filter('filter')($scope.botonera, {
1206 label: 'Chofer' 1202 label: 'Chofer'
1207 })[0].checked = true; 1203 })[0].checked = true;
1208 } 1204 }
1209 if (hojaRuta.vehiculo.id) { 1205 if (hojaRuta.vehiculo.id) {
1210 cabeceras.push({ 1206 cabeceras.push({
1211 label: 'Tractor:', 1207 label: 'Tractor:',
1212 valor: hojaRuta.vehiculo.tractor 1208 valor: hojaRuta.vehiculo.tractor
1213 }); 1209 });
1214 cabeceras.push({ 1210 cabeceras.push({
1215 label: 'Semi:', 1211 label: 'Semi:',
1216 valor: hojaRuta.vehiculo.semi 1212 valor: hojaRuta.vehiculo.semi
1217 }); 1213 });
1218 cabeceras.push({ 1214 cabeceras.push({
1219 label: 'Capacidad:', 1215 label: 'Capacidad:',
1220 valor: hojaRuta.vehiculo.capacidad 1216 valor: hojaRuta.vehiculo.capacidad
1221 }); 1217 });
1222 1218
1223 $filter('filter')($scope.botonera, { 1219 $filter('filter')($scope.botonera, {
1224 label: 'Vehiculo' 1220 label: 'Vehiculo'
1225 })[0].checked = true; 1221 })[0].checked = true;
1226 } 1222 }
1227 if (hojaRuta.tarifario) { 1223 if (hojaRuta.tarifario) {
1228 cabeceras.push({ 1224 cabeceras.push({
1229 label: 'Tarifario:', 1225 label: 'Tarifario:',
1230 valor: hojaRuta.tarifario 1226 valor: hojaRuta.tarifario
1231 }); 1227 });
1232 1228
1233 $filter('filter')($scope.botonera, { 1229 $filter('filter')($scope.botonera, {
1234 label: 'Tarifario' 1230 label: 'Tarifario'
1235 })[0].checked = true; 1231 })[0].checked = true;
1236 } 1232 }
1237 1233
1238 addArrayCabecera(cabeceras); 1234 addArrayCabecera(cabeceras);
1239 $scope.hojaRuta = hojaRuta; 1235 $scope.hojaRuta = hojaRuta;
1240 } 1236 }
1241 1237
1242 function getLSHojaRuta() { 1238 function getLSHojaRuta() {
1243 if ($localStorage.data === undefined) return; 1239 if ($localStorage.data === undefined) return;
1244 1240
1245 var hojaRuta = (JSON.parse($localStorage.data))[0] || null; 1241 var hojaRuta = (JSON.parse($localStorage.data))[0] || null;
1246 if (hojaRuta) { 1242 if (hojaRuta) {
1247 setearHojaRuta(hojaRuta); 1243 setearHojaRuta(hojaRuta);
1248 delete $localStorage.data; 1244 delete $localStorage.data;
1249 } 1245 }
1250 } 1246 }
1251 1247
1252 function getLSBotoneraPrincipal() { 1248 function getLSBotoneraPrincipal() {
1253 if ($localStorage.data === undefined) return; 1249 if ($localStorage.data === undefined) return;
1254 1250
1255 var precargado = (JSON.parse($localStorage.data))[1] || null; 1251 var precargado = (JSON.parse($localStorage.data))[1] || null;
1256 var cargaRemito = (JSON.parse($localStorage.data))[2] || null; 1252 var cargaRemito = (JSON.parse($localStorage.data))[2] || null;
1257 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null; 1253 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null;
1258 if (remitoAbierto) { 1254 if (remitoAbierto) {
1259 $scope.remitoAbierto = remitoAbierto; 1255 $scope.remitoAbierto = remitoAbierto;
1260 $filter('filter')($scope.botoneraPrincipal, { 1256 $filter('filter')($scope.botoneraPrincipal, {
1261 label: 'Remito Abierto' 1257 label: 'Remito Abierto'
1262 })[0].checked = $scope.remitoAbierto; 1258 })[0].checked = $scope.remitoAbierto;
1263 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 1259 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
1264 } 1260 }
1265 if (precargado) { 1261 if (precargado) {
1266 $scope.precargado = precargado; 1262 $scope.precargado = precargado;
1267 $filter('filter')($scope.botoneraPrincipal, { 1263 $filter('filter')($scope.botoneraPrincipal, {
1268 label: 'Precargados' 1264 label: 'Precargados'
1269 })[0].checked = $scope.precargado; 1265 })[0].checked = $scope.precargado;
1270 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1266 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1271 Array.prototype.push.apply($scope.botonera, 1267 Array.prototype.push.apply($scope.botonera,
1272 focaCrearHojaRutaService.getBotoneraPrecargado()); 1268 focaCrearHojaRutaService.getBotoneraPrecargado());
1273 } 1269 }
1274 if (cargaRemito) { 1270 if (cargaRemito) {
1275 $scope.cargaRemito = cargaRemito; 1271 $scope.cargaRemito = cargaRemito;
1276 $filter('filter')($scope.botoneraPrincipal, { 1272 $filter('filter')($scope.botoneraPrincipal, {
1277 label: 'Cargar Remitos' 1273 label: 'Cargar Remitos'
1278 })[0].checked = $scope.cargaRemito; 1274 })[0].checked = $scope.cargaRemito;
1279 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1275 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1280 Array.prototype.push.apply($scope.botonera, 1276 Array.prototype.push.apply($scope.botonera,
1281 focaCrearHojaRutaService.getBotoneraCargarRemito()); 1277 focaCrearHojaRutaService.getBotoneraCargarRemito());
1282 } 1278 }
1283 } 1279 }
1284 1280
1285 function addArrayCabecera(array) { 1281 function addArrayCabecera(array) {
1286 for (var i = 0; i < array.length; i++) { 1282 for (var i = 0; i < array.length; i++) {
1287 $scope.$broadcast('addCabecera', { 1283 $scope.$broadcast('addCabecera', {
1288 label: array[i].label, 1284 label: array[i].label,
1289 valor: array[i].valor 1285 valor: array[i].valor
1290 }); 1286 });
1291 } 1287 }