Commit 140f63a366a574e70b378db6040c3080bdaeae0f

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

Se hardcodea el campo flete, bomba, fob al generar un remito abierto desde hoja de ruta.

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