Commit 1e517a46b473ccf37943dff3a80476c85c8ea8d6

Authored by Luigi
1 parent c751723719
Exists in master

fechas - validar articulos cisterna

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