Commit e2c80cacc7e3600714500112ca577d8040d329a9

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

Merge branch 'master' into 'develop'

Master(efernandez)

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