Commit 7c8f5850ff90f1537880ed5ff0ffee4f203a3a9a

Authored by Eric Fernandez
1 parent 0bc4382d1a
Exists in master and in 2 other branches develop, lab

hoja de ruta con orden

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