Commit 81f17d1b0c98274a40d5336d38da94c679e24390

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

Merge branch 'master' into 'develop'

Master

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