Commit c75172371947d8f45d465d281c30dd8a1437ac38

Authored by Luigi
1 parent 751e6eec4a
Exists in master and in 2 other branches develop, lab

alerta fecha

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