Commit e26d0fc934232e9194a35eecca1a8fbed7ec4269

Authored by Luigi
1 parent 2168366bdd
Exists in master

sin console.g

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