Commit 7eea5ec2fa8ca8a6b2a9323f6c49452235fd8aa5

Authored by Luigi
1 parent 8e9196cac3
Exists in master and in 2 other branches develop, lab

Checked boton detalle de carga

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