Commit 2168366bdd4c974ffcca7958b1b7ebfaf8ef3338

Authored by Luigi
1 parent 1e517a46b4
Exists in master

botonera principal (diferencias al guardar)

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