Commit 751e6eec4ab571bda0c6f5ef1505eb7c04978c93

Authored by Luigi
1 parent df412d96bc
Exists in master

limpio cabecera

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