Commit e4acefe54f3ec359ffd2bbce434389e8142a505b

Authored by Marcelo Puebla
1 parent 79a4a484d0
Exists in master and in 2 other branches develop, lab

Codigo identado

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