Commit 79a4a484d0c518b79f888947605009ff65d64d1f

Authored by Marcelo Puebla
Exists in master

Merge branch 'develop' of git.focasoftware.com:npm/foca-crear-hoja-ruta

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