Commit abc937748d849af1b146ddbfbde546951cd0ff88

Authored by Eric Fernandez
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'develop'

Master

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