Commit f312e4edb1b1af80395af8f17c9faeb5c3002a15

Authored by Luigi
1 parent e2b3485e54
Exists in master

Botonera - borrar articulos

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