Commit 3ef714ffcb3c4ebd0e1c8c489ed120a384fe8384

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

See merge request !53
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 $scope.mostrarDetalle($scope.hojaRuta);
728
729 }, function () { 727 }, function () {
730 // funcion ejecutada cuando se cancela el modal 728 // funcion ejecutada cuando se cancela el modal
731 } 729 }
732 ); 730 );
733 }; 731 };
734 732
735 $scope.seleccionarVehiculo = function () { 733 $scope.seleccionarVehiculo = function () {
736 if (!eligioFecha() || eligioPreConfirmado()) return; 734 if (!eligioFecha() || eligioPreConfirmado()) return;
737 modalVehiculos(); 735 modalVehiculos();
738 }; 736 };
739 737
740 $scope.seleccionarTarifario = function () { 738 $scope.seleccionarTarifario = function () {
741 focaModalService 739 focaModalService
742 .prompt({ 740 .prompt({
743 titulo: 'Tarifa flete', 741 titulo: 'Tarifa flete',
744 value: $scope.hojaRuta.tarifario 742 value: $scope.hojaRuta.tarifario
745 }) 743 })
746 .then(function (costo) { 744 .then(function (costo) {
747 if (isNaN(costo)) { 745 if (isNaN(costo)) {
748 focaModalService 746 focaModalService
749 .alert('Ingrese un valor válido') 747 .alert('Ingrese un valor válido')
750 .then(function () { 748 .then(function () {
751 $scope.seleccionarTarifario(); 749 $scope.seleccionarTarifario();
752 }); 750 });
753 751
754 return; 752 return;
755 } 753 }
756 754
757 $scope.hojaRuta.tarifario = costo; 755 $scope.hojaRuta.tarifario = costo;
758 $scope.$broadcast('addCabecera', { 756 $scope.$broadcast('addCabecera', {
759 label: 'Tarifario:', 757 label: 'Tarifario:',
760 valor: costo 758 valor: costo
761 }); 759 });
762 760
763 $filter('filter')($scope.botonera, { 761 $filter('filter')($scope.botonera, {
764 label: 'Tarifario', 762 label: 'Tarifario',
765 })[0].checked = true; 763 })[0].checked = true;
766 }); 764 });
767 }; 765 };
768 766
769 $scope.seleccionarRemitos = function () { 767 $scope.seleccionarRemitos = function () {
770 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 768 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
771 var modalInstance = $uibModal.open( 769 var modalInstance = $uibModal.open(
772 { 770 {
773 ariaLabelledBy: 'Busqueda de Remito', 771 ariaLabelledBy: 'Busqueda de Remito',
774 templateUrl: 'foca-modal-remito.html', 772 templateUrl: 'foca-modal-remito.html',
775 controller: 'focaModalRemitoController', 773 controller: 'focaModalRemitoController',
776 size: 'lg', 774 size: 'lg',
777 resolve: { usadoPor: function () { return 'hojaRuta'; } } 775 resolve: { usadoPor: function () { return 'hojaRuta'; } }
778 } 776 }
779 ); 777 );
780 modalInstance.result.then( 778 modalInstance.result.then(
781 function (remito) { 779 function (remito) {
782 // TODO: borrar cuando no se use definitivamente 780 // TODO: borrar cuando no se use definitivamente
783 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { 781 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
784 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { 782 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
785 // focaModalService.alert('Remito ya incluido'); 783 // focaModalService.alert('Remito ya incluido');
786 // return; 784 // return;
787 // } 785 // }
788 // } 786 // }
789 787
790 // var litros = 0; 788 // var litros = 0;
791 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 789 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
792 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 790 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
793 // } 791 // }
794 792
795 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 793 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
796 // focaModalService.alert( 794 // focaModalService.alert(
797 // 'Debe ingresar toda la información para el transporte' 795 // 'Debe ingresar toda la información para el transporte'
798 // ); 796 // );
799 // return; 797 // return;
800 // } 798 // }
801 799
802 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 800 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
803 // { 801 // {
804 // var litrostotales = litros; 802 // var litrostotales = litros;
805 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 803 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
806 // focaModalService.alert( 804 // focaModalService.alert(
807 // 'La carga excede la capacidad disponible del vehiculo. ' + 805 // 'La carga excede la capacidad disponible del vehiculo. ' +
808 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 806 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
809 // ); 807 // );
810 // } 808 // }
811 809
812 // remito.litros = litros; 810 // remito.litros = litros;
813 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 811 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
814 $scope.cargarCisterna(remito.id).then(function () { 812 $scope.cargarCisterna(remito.id).then(function () {
815 $scope.hojaRuta.remitosTabla.push(remito); 813 $scope.hojaRuta.remitosTabla.push(remito);
816 $filter('filter')($scope.botonera, { 814 $filter('filter')($scope.botonera, {
817 label: 'Remitos', 815 label: 'Remitos',
818 })[0].checked = true; 816 })[0].checked = true;
819 817
820 }, function (error) { 818 }, function (error) {
821 error.then($scope.seleccionarRemitos); 819 error.then($scope.seleccionarRemitos);
822 }); 820 });
823 }, function () { 821 }, function () {
824 // funcion ejecutada cuando se cancela el modal 822 // funcion ejecutada cuando se cancela el modal
825 } 823 }
826 ); 824 );
827 }; 825 };
828 826
829 $scope.seleccionarVehiculosPrecargados = function () { 827 $scope.seleccionarVehiculosPrecargados = function () {
830 if (!eligioFecha()) return; 828 if (!eligioFecha()) return;
831 modalVehiculos(true); 829 modalVehiculos(true);
832 }; 830 };
833 831
834 $scope.cargarCisterna = function (idRemito) { 832 $scope.cargarCisterna = function (idRemito) {
835 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 833 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
836 var modalInstance = $uibModal.open( 834 var modalInstance = $uibModal.open(
837 { 835 {
838 ariaLabelledBy: 'Busqueda de Vehiculo', 836 ariaLabelledBy: 'Busqueda de Vehiculo',
839 templateUrl: 'foca-detalle-vehiculo.html', 837 templateUrl: 'foca-detalle-vehiculo.html',
840 controller: 'focaDetalleVehiculo', 838 controller: 'focaDetalleVehiculo',
841 size: 'lg', 839 size: 'lg',
842 resolve: { 840 resolve: {
843 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; }, 841 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; },
844 idRemito: function () { return idRemito; }, 842 idRemito: function () { return idRemito; },
845 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; } 843 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; }
846 } 844 }
847 } 845 }
848 ); 846 );
849 return modalInstance.result; 847 return modalInstance.result;
850 }; 848 };
851 849
852 $scope.seleccionarFechaEntrega = function () { 850 $scope.seleccionarFechaEntrega = function () {
853 851
854 var confirmacion = false; 852 var confirmacion = false;
855 853
856 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 854 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
857 confirmacion = true; 855 confirmacion = true;
858 } 856 }
859 857
860 if (confirmacion) { 858 if (confirmacion) {
861 focaModalService 859 focaModalService
862 .confirm('Si cambia la fecha se perderán los datos actuales') 860 .confirm('Si cambia la fecha se perderán los datos actuales')
863 .then(function (data) { 861 .then(function (data) {
864 if (data) { 862 if (data) {
865 $scope.hojaRuta.vehiculo.id = undefined; 863 $scope.hojaRuta.vehiculo.id = undefined;
866 $scope.hojaRuta.tarifario = null; 864 $scope.hojaRuta.tarifario = null;
867 $scope.hojaRuta.transportista = {}; 865 $scope.hojaRuta.transportista = {};
868 $scope.hojaRuta.chofer = {}; 866 $scope.hojaRuta.chofer = {};
869 $scope.hojaRuta.datosExtra = undefined; 867 $scope.hojaRuta.datosExtra = undefined;
870 elegirFecha(); 868 elegirFecha();
871 } 869 }
872 }, function () { 870 }, function () {
873 return; 871 return;
874 }); 872 });
875 } else { 873 } else {
876 elegirFecha(); 874 elegirFecha();
877 } 875 }
878 }; 876 };
879 877
880 function setearFecha(fecha) { 878 function setearFecha(fecha) {
881 $timeout(function () { 879 $timeout(function () {
882 $scope.$broadcast('addCabecera', { 880 $scope.$broadcast('addCabecera', {
883 label: 'Fecha de entrega: ', 881 label: 'Fecha de entrega: ',
884 valor: fecha.toLocaleDateString() 882 valor: fecha.toLocaleDateString()
885 }); 883 });
886 $scope.hojaRuta.fechaReparto = fecha; 884 $scope.hojaRuta.fechaReparto = fecha;
887 $scope.inicial.fechaReparto = fecha; 885 $scope.inicial.fechaReparto = fecha;
888 }); 886 });
889 } 887 }
890 888
891 $scope.seleccionarDatosExtra = function () { 889 $scope.seleccionarDatosExtra = function () {
892 var datosHojaRuta = $scope.hojaRuta.datosExtra; 890 var datosHojaRuta = $scope.hojaRuta.datosExtra;
893 var modalInstance = $uibModal.open( 891 var modalInstance = $uibModal.open(
894 { 892 {
895 templateUrl: 'foca-modal-datos-hoja-ruta.html', 893 templateUrl: 'foca-modal-datos-hoja-ruta.html',
896 controller: 'focaModalDatosHojaRutaCtrl', 894 controller: 'focaModalDatosHojaRutaCtrl',
897 size: 'lg', 895 size: 'lg',
898 resolve: { 896 resolve: {
899 parametrosDatos: function () { 897 parametrosDatos: function () {
900 return { 898 return {
901 datosHojaRuta: datosHojaRuta 899 datosHojaRuta: datosHojaRuta
902 }; 900 };
903 } 901 }
904 } 902 }
905 } 903 }
906 ); 904 );
907 return modalInstance.result.then(function (datosExtra) { 905 return modalInstance.result.then(function (datosExtra) {
908 906
909 $filter('filter')($scope.botonera, { 907 $filter('filter')($scope.botonera, {
910 label: 'Datos extra', 908 label: 'Datos extra',
911 })[0].checked = true; 909 })[0].checked = true;
912 910
913 $scope.hojaRuta.datosExtra = datosExtra; 911 $scope.hojaRuta.datosExtra = datosExtra;
914 }, function () { 912 }, function () {
915 //se ejecuta cuando se cancela el modal 913 //se ejecuta cuando se cancela el modal
916 }); 914 });
917 }; 915 };
918 916
919 $scope.desasociarRemito = function (key, idRemito) { 917 $scope.desasociarRemito = function (key, idRemito) {
920 var idsRemito = [idRemito]; 918 var idsRemito = [idRemito];
921 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 919 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
922 ' vehículo?').then(function () { 920 ' vehículo?').then(function () {
923 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 921 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
924 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) 922 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1)
925 .then(function () { 923 .then(function () {
926 $scope.hojaRuta.remitosTabla.splice(key, 1); 924 $scope.hojaRuta.remitosTabla.splice(key, 1);
927 focaModalService.alert('Remito desasociado con éxito'); 925 focaModalService.alert('Remito desasociado con éxito');
928 }); 926 });
929 }); 927 });
930 }; 928 };
931 929
932 $scope.verProductosRemito = function (idRemito) { 930 $scope.verProductosRemito = function (idRemito) {
933 var parametrosModal = { 931 var parametrosModal = {
934 titulo: 'Articulos remito', 932 titulo: 'Articulos remito',
935 query: '/articulos/remito/' + idRemito, 933 query: '/articulos/remito/' + idRemito,
936 soloMostrar: true, 934 soloMostrar: true,
937 columnas: [ 935 columnas: [
938 { 936 {
939 nombre: 'Código', 937 nombre: 'Código',
940 propiedad: 'codigo' 938 propiedad: 'codigo'
941 }, 939 },
942 { 940 {
943 nombre: 'Descripción', 941 nombre: 'Descripción',
944 propiedad: 'descripcion' 942 propiedad: 'descripcion'
945 }, 943 },
946 { 944 {
947 nombre: 'Cantidad', 945 nombre: 'Cantidad',
948 propiedad: 'cantidad' 946 propiedad: 'cantidad'
949 } 947 }
950 ] 948 ]
951 }; 949 };
952 focaModalService.modal(parametrosModal).then(); 950 focaModalService.modal(parametrosModal).then();
953 }; 951 };
954 952
955 $scope.mostrarDetalle = function (hojasRutas) { 953 $scope.mostrarDetalle = function (hojasRutas) {
956 var modalInstance =$uibModal.open( 954 var modalInstance =$uibModal.open(
957 { 955 {
958 ariaLabelledBy: '', 956 ariaLabelledBy: '',
959 templateUrl: 'modal-detalle-carga.html', 957 templateUrl: 'modal-detalle-carga.html',
960 controller: 'focaModalDetalleController', 958 controller: 'focaModalDetalleController',
961 resolve: { 959 resolve: {
962 hojasRutas: function () { return hojasRutas; } 960 hojasRutas: function () { return hojasRutas; }
963 }, 961 },
964 size: 'lg', 962 size: 'lg',
965 backdrop: false 963 backdrop: false
966 } 964 }
967 ); 965 );
968 return modalInstance.result.then(function (res) { 966 return modalInstance.result.then(function (res) {
969 res.cisternas.forEach( function (cisterna) { 967 res.cisternas.forEach( function (cisterna) {
970 $scope.cisternaCargas.push(cisterna.cisternaCarga); 968 $scope.cisternaCargas.push(cisterna.cisternaCarga);
971 }); 969 });
972 $scope.cisternaMovimientos = res.movimientos; 970 $scope.cisternaMovimientos = res.movimientos;
973 $scope.articulosRecibidos = res.articulos; 971 $scope.articulosRecibidos = res.articulos;
974 $scope.articulos = res.articulos; 972 $scope.articulos = res.articulos;
973 $filter('filter')($scope.botonera, {
974 label: 'Detalle de Carga',
975 })[0].checked = true;
975 }, function () { 976 }, function () {
976 //se ejecuta cuando se cancela el modal 977 //se ejecuta cuando se cancela el modal
977 }); 978 });
978 }; 979 };
979 980
980 function elegirFecha() { 981 function elegirFecha() {
981 var fechaEntrega = { 982 var fechaEntrega = {
982 titulo: 'Fecha de entrega', 983 titulo: 'Fecha de entrega',
983 minDate: new Date() 984 minDate: new Date()
984 }; 985 };
985 focaModalService.modalFecha(fechaEntrega).then(function (fecha) { 986 focaModalService.modalFecha(fechaEntrega).then(function (fecha) {
986 987
987 $scope.hojaRuta.fechaReparto = fecha; 988 $scope.hojaRuta.fechaReparto = fecha;
988 989
989 $scope.$broadcast('addCabecera', { 990 $scope.$broadcast('addCabecera', {
990 label: 'Fecha de entrega: ', 991 label: 'Fecha de entrega: ',
991 valor: fecha.toLocaleDateString() 992 valor: fecha.toLocaleDateString()
992 }); 993 });
993 //habilitar los otros botones 994 //habilitar los otros botones
994 var temp = []; 995 var temp = [];
995 if ($scope.botonera.length > 1) { 996 if ($scope.botonera.length > 1) {
996 limpiarBotonera($scope.botonera); 997 limpiarBotonera($scope.botonera);
997 } else if ($scope.precargado) { 998 } else if ($scope.precargado) {
998 temp = focaCrearHojaRutaService.getBotoneraPrecargado(); 999 temp = focaCrearHojaRutaService.getBotoneraPrecargado();
999 modalVehiculos(true); 1000 modalVehiculos(true);
1000 } else if ($scope.cargaRemito && $scope.precargado === false) { 1001 } else if ($scope.cargaRemito && $scope.precargado === false) {
1001 temp = focaCrearHojaRutaService.getBotoneraCargarRemito(); 1002 temp = focaCrearHojaRutaService.getBotoneraCargarRemito();
1002 } else { 1003 } else {
1003 temp = focaCrearHojaRutaService.getBotoneraCargarRemito(); 1004 temp = focaCrearHojaRutaService.getBotoneraCargarRemito();
1004 modalVehiculos(true); 1005 modalVehiculos(true);
1005 } 1006 }
1006 temp.forEach(function (e) { 1007 temp.forEach(function (e) {
1007 $scope.botonera.push(e); 1008 $scope.botonera.push(e);
1008 }); 1009 });
1009 1010
1010 $filter('filter')($scope.botonera, { 1011 $filter('filter')($scope.botonera, {
1011 label: 'Fecha Entrega', 1012 label: 'Fecha Entrega',
1012 })[0].checked = true; 1013 })[0].checked = true;
1013 }); 1014 });
1014 } 1015 }
1015 1016
1016 function eligioPreConfirmado() { 1017 function eligioPreConfirmado() {
1017 if ($scope.eligioPreConfirmado) { 1018 if ($scope.eligioPreConfirmado) {
1018 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 1019 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
1019 return true; 1020 return true;
1020 } 1021 }
1021 return false; 1022 return false;
1022 } 1023 }
1023 1024
1024 function eligioFecha() { 1025 function eligioFecha() {
1025 if (!$scope.hojaRuta.fechaReparto) { 1026 if (!$scope.hojaRuta.fechaReparto) {
1026 focaModalService.alert('Primero seleccione fecha de reparto'); 1027 focaModalService.alert('Primero seleccione fecha de reparto');
1027 return false; 1028 return false;
1028 } 1029 }
1029 return true; 1030 return true;
1030 } 1031 }
1031 1032
1032 function eligioVehiculo() { 1033 function eligioVehiculo() {
1033 if (!$scope.hojaRuta.vehiculo.id) { 1034 if (!$scope.hojaRuta.vehiculo.id) {
1034 focaModalService.alert('Primero seleccione vehiculo'); 1035 focaModalService.alert('Primero seleccione vehiculo');
1035 return false; 1036 return false;
1036 } 1037 }
1037 return true; 1038 return true;
1038 } 1039 }
1039 1040
1040 function modalVehiculos(preCargados) { 1041 function modalVehiculos(preCargados) {
1041 var parametrosModal = {}; 1042 var parametrosModal = {};
1042 if (preCargados) { 1043 if (preCargados) {
1043 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 1044 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
1044 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); 1045 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
1045 parametrosModal.titulo = 'Búsqueda de vehiculos precargados'; 1046 parametrosModal.titulo = 'Búsqueda de vehiculos precargados';
1046 } else { 1047 } else {
1047 parametrosModal.query = '/vehiculo'; 1048 parametrosModal.query = '/vehiculo';
1048 parametrosModal.titulo = 'Búsqueda de vehículos'; 1049 parametrosModal.titulo = 'Búsqueda de vehículos';
1049 } 1050 }
1050 parametrosModal.columnas = [ 1051 parametrosModal.columnas = [
1051 { 1052 {
1052 propiedad: 'codigo', 1053 propiedad: 'codigo',
1053 nombre: 'Código' 1054 nombre: 'Código'
1054 }, 1055 },
1055 { 1056 {
1056 propiedad: 'tractor', 1057 propiedad: 'tractor',
1057 nombre: 'tractor' 1058 nombre: 'tractor'
1058 }, 1059 },
1059 { 1060 {
1060 propiedad: 'semi', 1061 propiedad: 'semi',
1061 nombre: 'Semi' 1062 nombre: 'Semi'
1062 } 1063 }
1063 ]; 1064 ];
1064 focaModalService.modal(parametrosModal).then(function (vehiculo) { 1065 focaModalService.modal(parametrosModal).then(function (vehiculo) {
1065 if (!preCargados && vehiculoEnUso(vehiculo)) return; 1066 if (!preCargados && vehiculoEnUso(vehiculo)) return;
1066 $scope.hojaRuta.vehiculo = vehiculo; 1067 $scope.hojaRuta.vehiculo = vehiculo;
1067 $scope.hojaRuta.transportista = vehiculo.transportista; 1068 $scope.hojaRuta.transportista = vehiculo.transportista;
1068 // mostrarDetalle(vehiculo); 1069 // mostrarDetalle(vehiculo);
1069 if (preCargados) { 1070 if (preCargados) {
1070 $scope.eligioPreConfirmado = true; 1071 $scope.eligioPreConfirmado = true;
1071 $scope.hojaRuta.vehiculo = vehiculo; 1072 $scope.hojaRuta.vehiculo = vehiculo;
1072 $scope.$broadcast('addCabecera', { 1073 $scope.$broadcast('addCabecera', {
1073 label: 'Transportista:', 1074 label: 'Transportista:',
1074 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 1075 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
1075 ' - ' + vehiculo.transportista.NOM 1076 ' - ' + vehiculo.transportista.NOM
1076 }); 1077 });
1077 focaCrearHojaRutaService 1078 focaCrearHojaRutaService
1078 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) 1079 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
1079 .then(function (res) { 1080 .then(function (res) {
1080 $filter('filter')($scope.botonera, { 1081 $filter('filter')($scope.botonera, {
1081 label: 'Transportista', 1082 label: 'Transportista',
1082 })[0].checked = true; 1083 })[0].checked = true;
1083 1084
1084 $filter('filter')($scope.botonera, { 1085 $filter('filter')($scope.botonera, {
1085 label: 'Vehiculo', 1086 label: 'Vehiculo',
1086 })[0].checked = true; 1087 })[0].checked = true;
1087 1088
1088 $scope.hojaRuta.remitosTabla = res.data; 1089 $scope.hojaRuta.remitosTabla = res.data;
1089 }); 1090 });
1090 } else { 1091 } else {
1091 focaCrearHojaRutaService 1092 focaCrearHojaRutaService
1092 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) 1093 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
1093 .then(function (res) { 1094 .then(function (res) {
1094 1095
1095 $filter('filter')($scope.botonera, { 1096 $filter('filter')($scope.botonera, {
1096 label: 'Vehiculo', 1097 label: 'Vehiculo',
1097 })[0].checked = true; 1098 })[0].checked = true;
1098 1099
1099 $scope.hojaRuta.remitosTabla = res.data; 1100 $scope.hojaRuta.remitosTabla = res.data;
1100 }); 1101 });
1101 } 1102 }
1102 $scope.$broadcast('addCabecera', { 1103 $scope.$broadcast('addCabecera', {
1103 label: 'Tractor:', 1104 label: 'Tractor:',
1104 valor: vehiculo.tractor 1105 valor: vehiculo.tractor
1105 }); 1106 });
1106 $scope.$broadcast('addCabecera', { 1107 $scope.$broadcast('addCabecera', {
1107 label: 'Semi:', 1108 label: 'Semi:',
1108 valor: vehiculo.semi 1109 valor: vehiculo.semi
1109 }); 1110 });
1110 $scope.$broadcast('addCabecera', { 1111 $scope.$broadcast('addCabecera', {
1111 label: 'Capacidad:', 1112 label: 'Capacidad:',
1112 valor: vehiculo.capacidad 1113 valor: vehiculo.capacidad
1113 }); 1114 });
1114 1115
1115 }); 1116 });
1116 } 1117 }
1117 1118
1118 function vehiculoEnUso(vehiculo) { 1119 function vehiculoEnUso(vehiculo) {
1119 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 1120 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
1120 for (var i = 0; i < vehiculo.cisternas.length; i++) { 1121 for (var i = 0; i < vehiculo.cisternas.length; i++) {
1121 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 1122 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
1122 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 1123 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
1123 if (cisternaCarga.fechaReparto.substring(0, 10) === 1124 if (cisternaCarga.fechaReparto.substring(0, 10) ===
1124 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && 1125 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
1125 cisternaCarga.idUsuarioProceso && 1126 cisternaCarga.idUsuarioProceso &&
1126 cisternaCarga.idUsuarioProceso !== idUsuario) { 1127 cisternaCarga.idUsuarioProceso !== idUsuario) {
1127 focaModalService.alert('El vehículo está siendo usado por otro' + 1128 focaModalService.alert('El vehículo está siendo usado por otro' +
1128 ' usuario'); 1129 ' usuario');
1129 return true; 1130 return true;
1130 } 1131 }
1131 } 1132 }
1132 } 1133 }
1133 return false; 1134 return false;
1134 } 1135 }
1135 1136
1136 function salir() { 1137 function salir() {
1137 var confirmacion = false; 1138 var confirmacion = false;
1138 1139
1139 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 1140 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
1140 confirmacion = true; 1141 confirmacion = true;
1141 } 1142 }
1142 1143
1143 if (confirmacion) { 1144 if (confirmacion) {
1144 focaModalService.confirm( 1145 focaModalService.confirm(
1145 '¿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.'
1146 ).then(function (data) { 1147 ).then(function (data) {
1147 if (data) { 1148 if (data) {
1148 $location.path('/'); 1149 $location.path('/');
1149 } 1150 }
1150 }); 1151 });
1151 } else { 1152 } else {
1152 $location.path('/'); 1153 $location.path('/');
1153 } 1154 }
1154 } 1155 }
1155 1156
1156 function limpiarBotonera(botonera) { 1157 function limpiarBotonera(botonera) {
1157 botonera.forEach(function (boton) { 1158 botonera.forEach(function (boton) {
1158 boton.checked = false; 1159 boton.checked = false;
1159 }); 1160 });
1160 } 1161 }
1161 function setearHojaRuta(hojaRuta) { 1162 function setearHojaRuta(hojaRuta) {
1162 $scope.$broadcast('cleanCabecera'); 1163 $scope.$broadcast('cleanCabecera');
1163 1164
1164 var cabeceras = []; 1165 var cabeceras = [];
1165 if (hojaRuta.fechaReparto) { 1166 if (hojaRuta.fechaReparto) {
1166 cabeceras.push({ 1167 cabeceras.push({
1167 label: 'Fecha de entrega:', 1168 label: 'Fecha de entrega:',
1168 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 1169 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
1169 }); 1170 });
1170 1171
1171 $filter('filter')($scope.botonera, { 1172 $filter('filter')($scope.botonera, {
1172 label: 'Fecha Entrega' 1173 label: 'Fecha Entrega'
1173 })[0].checked = true; 1174 })[0].checked = true;
1174 } 1175 }
1175 if (hojaRuta.transportista.COD) { 1176 if (hojaRuta.transportista.COD) {
1176 cabeceras.push({ 1177 cabeceras.push({
1177 label: 'Transportista:', 1178 label: 'Transportista:',
1178 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + 1179 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
1179 hojaRuta.transportista.NOM 1180 hojaRuta.transportista.NOM
1180 }); 1181 });
1181 1182
1182 $filter('filter')($scope.botonera, { 1183 $filter('filter')($scope.botonera, {
1183 label: 'Transportista' 1184 label: 'Transportista'
1184 })[0].checked = true; 1185 })[0].checked = true;
1185 } 1186 }
1186 if (hojaRuta.chofer.id) { 1187 if (hojaRuta.chofer.id) {
1187 cabeceras.push({ 1188 cabeceras.push({
1188 label: 'Chofer:', 1189 label: 'Chofer:',
1189 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + 1190 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
1190 ' - ' + hojaRuta.chofer.nombre 1191 ' - ' + hojaRuta.chofer.nombre
1191 }); 1192 });
1192 1193
1193 $filter('filter')($scope.botonera, { 1194 $filter('filter')($scope.botonera, {
1194 label: 'Chofer' 1195 label: 'Chofer'
1195 })[0].checked = true; 1196 })[0].checked = true;
1196 } 1197 }
1197 if (hojaRuta.vehiculo.id) { 1198 if (hojaRuta.vehiculo.id) {
1198 cabeceras.push({ 1199 cabeceras.push({
1199 label: 'Tractor:', 1200 label: 'Tractor:',
1200 valor: hojaRuta.vehiculo.tractor 1201 valor: hojaRuta.vehiculo.tractor
1201 }); 1202 });
1202 cabeceras.push({ 1203 cabeceras.push({
1203 label: 'Semi:', 1204 label: 'Semi:',
1204 valor: hojaRuta.vehiculo.semi 1205 valor: hojaRuta.vehiculo.semi
1205 }); 1206 });
1206 cabeceras.push({ 1207 cabeceras.push({
1207 label: 'Capacidad:', 1208 label: 'Capacidad:',
1208 valor: hojaRuta.vehiculo.capacidad 1209 valor: hojaRuta.vehiculo.capacidad
1209 }); 1210 });
1210 1211
1211 $filter('filter')($scope.botonera, { 1212 $filter('filter')($scope.botonera, {
1212 label: 'Vehiculo' 1213 label: 'Vehiculo'
1213 })[0].checked = true; 1214 })[0].checked = true;
1214 } 1215 }
1215 if (hojaRuta.tarifario) { 1216 if (hojaRuta.tarifario) {
1216 cabeceras.push({ 1217 cabeceras.push({
1217 label: 'Tarifario:', 1218 label: 'Tarifario:',
1218 valor: hojaRuta.tarifario 1219 valor: hojaRuta.tarifario
1219 }); 1220 });
1220 1221
1221 $filter('filter')($scope.botonera, { 1222 $filter('filter')($scope.botonera, {
1222 label: 'Tarifario' 1223 label: 'Tarifario'
1223 })[0].checked = true; 1224 })[0].checked = true;
1224 } 1225 }
1225 1226
1226 addArrayCabecera(cabeceras); 1227 addArrayCabecera(cabeceras);
1227 $scope.hojaRuta = hojaRuta; 1228 $scope.hojaRuta = hojaRuta;
1228 } 1229 }
1229 1230
1230 function getLSHojaRuta() { 1231 function getLSHojaRuta() {
1231 var hojaRuta = JSON.parse($localStorage.hojaRuta || null); 1232 var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
1232 if (hojaRuta) { 1233 if (hojaRuta) {
1233 setearHojaRuta(hojaRuta); 1234 setearHojaRuta(hojaRuta);
1234 delete $localStorage.hojaRuta; 1235 delete $localStorage.hojaRuta;
1235 } 1236 }
1236 } 1237 }
1237 function addArrayCabecera(array) { 1238 function addArrayCabecera(array) {
1238 for (var i = 0; i < array.length; i++) { 1239 for (var i = 0; i < array.length; i++) {
1239 $scope.$broadcast('addCabecera', { 1240 $scope.$broadcast('addCabecera', {
1240 label: array[i].label, 1241 label: array[i].label,
1241 valor: array[i].valor 1242 valor: array[i].valor
1242 }); 1243 });
1243 } 1244 }
1244 } 1245 }
1245 } 1246 }