Commit 59e0b69f87eccf0406bc912a24c5c4da84fbdaea

Authored by Eric Fernandez
1 parent 353cd87214
Exists in master

nuevo modal productos2

src/js/controller.js
1 angular.module('focaCrearFactura').controller('facturaController', [ 1 angular.module('focaCrearFactura').controller('facturaController', [
2 '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', 2 '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout',
3 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', 3 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService',
4 '$localStorage', 4 '$localStorage',
5 function ( 5 function (
6 $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, 6 $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService,
7 crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage) { 7 crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage) {
8 8
9 config(); 9 config();
10 10
11 function config() { 11 function config() {
12 $scope.tmpCantidad = Number; 12 $scope.tmpCantidad = Number;
13 $scope.tmpPrecio = Number; 13 $scope.tmpPrecio = Number;
14 $scope.botonera = crearFacturaService.getBotonera(); 14 $scope.botonera = crearFacturaService.getBotonera();
15 $scope.isNumber = angular.isNumber; 15 $scope.isNumber = angular.isNumber;
16 $scope.datepickerAbierto = false; 16 $scope.datepickerAbierto = false;
17 $scope.show = false; 17 $scope.show = false;
18 $scope.cargando = true; 18 $scope.cargando = true;
19 $scope.now = new Date(); 19 $scope.now = new Date();
20 $scope.puntoVenta = rellenar(0, 4); 20 $scope.puntoVenta = rellenar(0, 4);
21 $scope.comprobante = rellenar(0, 8); 21 $scope.comprobante = rellenar(0, 8);
22 $scope.dateOptions = { 22 $scope.dateOptions = {
23 maxDate: new Date(), 23 maxDate: new Date(),
24 minDate: new Date(2010, 0, 1) 24 minDate: new Date(2010, 0, 1)
25 }; 25 };
26 $scope.cabeceras = []; 26 $scope.cabeceras = [];
27 crearFacturaService.getParametros().then(function (res) { 27 crearFacturaService.getParametros().then(function (res) {
28 28
29 var parametros = JSON.parse(res.data[0].jsonText); 29 var parametros = JSON.parse(res.data[0].jsonText);
30 30
31 if ($localStorage.factura) { 31 if ($localStorage.factura) {
32 32
33 $timeout(function () { getLSFactura(); }); 33 $timeout(function () { getLSFactura(); });
34 } else { 34 } else {
35 35
36 for (var property in parametros) { 36 for (var property in parametros) {
37 $scope.factura[property] = parametros[property]; 37 $scope.factura[property] = parametros[property];
38 $scope.inicial[property] = parametros[property]; 38 $scope.inicial[property] = parametros[property];
39 } 39 }
40 40
41 setearFactura($scope.factura); 41 setearFactura($scope.factura);
42 } 42 }
43 43
44 }); 44 });
45 45
46 //SETEO BOTONERA LATERAL 46 //SETEO BOTONERA LATERAL
47 $timeout(function () { 47 $timeout(function () {
48 focaBotoneraLateralService.showSalir(false); 48 focaBotoneraLateralService.showSalir(false);
49 focaBotoneraLateralService.showPausar(true); 49 focaBotoneraLateralService.showPausar(true);
50 focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); 50 focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago);
51 focaBotoneraLateralService.addCustomButton('Salir', salir); 51 focaBotoneraLateralService.addCustomButton('Salir', salir);
52 }); 52 });
53 53
54 init(); 54 init();
55 55
56 } 56 }
57 57
58 function init() { 58 function init() {
59 59
60 $scope.$broadcast('cleanCabecera'); 60 $scope.$broadcast('cleanCabecera');
61 61
62 $scope.factura = { 62 $scope.factura = {
63 id: 0, 63 id: 0,
64 estado: 0, 64 estado: 0,
65 vendedor: {}, 65 vendedor: {},
66 cliente: {}, 66 cliente: {},
67 proveedor: {}, 67 proveedor: {},
68 domicilio: { dom: '' }, 68 domicilio: { dom: '' },
69 moneda: {}, 69 moneda: {},
70 cotizacion: $scope.cotizacionPorDefecto || {}, 70 cotizacion: $scope.cotizacionPorDefecto || {},
71 articulosFactura: [], 71 articulosFactura: [],
72 despachos: [] 72 despachos: []
73 }; 73 };
74 74
75 $scope.factura.articulosFactura = []; 75 $scope.factura.articulosFactura = [];
76 $scope.idLista = undefined; 76 $scope.idLista = undefined;
77 77
78 crearRemitoService.getNumeroRemito().then( 78 crearRemitoService.getNumeroRemito().then(
79 function (res) { 79 function (res) {
80 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 80 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
81 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 81 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
82 }, 82 },
83 function (err) { 83 function (err) {
84 focaModalService.alert('La terminal no esta configurada correctamente'); 84 focaModalService.alert('La terminal no esta configurada correctamente');
85 console.info(err); 85 console.info(err);
86 } 86 }
87 ); 87 );
88 88
89 $scope.inicial = angular.copy($scope.factura); 89 $scope.inicial = angular.copy($scope.factura);
90 } 90 }
91 91
92 $scope.$watch('factura', function (newValue) { 92 $scope.$watch('factura', function (newValue) {
93 focaBotoneraLateralService.setPausarData({ 93 focaBotoneraLateralService.setPausarData({
94 label: 'factura', 94 label: 'factura',
95 val: newValue 95 val: newValue
96 }); 96 });
97 }, true); 97 }, true);
98 98
99 $scope.seleccionarFormaDePago = function () { 99 $scope.seleccionarFormaDePago = function () {
100 if (!validarGuardar()) return; 100 if (!validarGuardar()) return;
101 var modalInstance = $uibModal.open( 101 var modalInstance = $uibModal.open(
102 { 102 {
103 templateUrl: 'modal-forma-pago.html', 103 templateUrl: 'modal-forma-pago.html',
104 controller: 'focaModalFormaPagoController', 104 controller: 'focaModalFormaPagoController',
105 resolve: { 105 resolve: {
106 filters: function () { return null; }, 106 filters: function () { return null; },
107 }, 107 },
108 size: 'lg', 108 size: 'lg',
109 } 109 }
110 ); 110 );
111 modalInstance.result 111 modalInstance.result
112 .then(function (data) { 112 .then(function (data) {
113 console.log(data); 113 console.log(data);
114 $scope.crearFactura(); 114 $scope.crearFactura();
115 }) 115 })
116 .catch(function (e) { console.error(e); }); 116 .catch(function (e) { console.error(e); });
117 }; 117 };
118 118
119 $scope.crearFactura = function () { 119 $scope.crearFactura = function () {
120 120
121 var save = { 121 var save = {
122 factura: { 122 factura: {
123 123
124 BONIF: 0, 124 BONIF: 0,
125 CLI: $scope.factura.cliente.cod, 125 CLI: $scope.factura.cliente.cod,
126 CUI: $scope.factura.cliente.cuit, 126 CUI: $scope.factura.cliente.cuit,
127 CTA: $scope.factura.cliente.cod, 127 CTA: $scope.factura.cliente.cod,
128 DC1: '', 128 DC1: '',
129 DC2: '', 129 DC2: '',
130 DE1: '', 130 DE1: '',
131 DOM: $scope.factura.cliente.DOM, 131 DOM: $scope.factura.cliente.DOM,
132 FACAUT: 0, 132 FACAUT: 0,
133 DTO: 0, 133 DTO: 0,
134 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), 134 FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'),
135 FEC_ANT: '19000101', 135 FEC_ANT: '19000101',
136 FPA: 2, 136 FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente
137 IDEXCEPCION: 0, 137 IDEXCEPCION: 0,
138 IDLP: $scope.factura.cliente.mod.trim() || 0, 138 IDLP: $scope.factura.cliente.mod.trim() || 0,
139 IDPERSONERIA: 0, 139 IDPERSONERIA: 0,
140 IMI: 0, // TODO 140 IMI: 0, // TODO
141 IMI2: 0, // TODO 141 IMI2: 0, // TODO
142 IMI3: 0, // TODO 142 IMI3: 0, // TODO
143 IMP_LEY: 0, 143 IMP_LEY: 0,
144 IRI: 0, // TODO 144 IRI: 0, // TODO
145 IRS: 0, 145 IRS: 0,
146 LEG: '', 146 LEG: '',
147 LUG: $scope.factura.vendedor.LugVen, 147 LUG: $scope.factura.vendedor.LugVen,
148 MK_M: 0, 148 MK_M: 0,
149 NEE: 0, // TODO 149 NEE: 0, // TODO
150 NET: 0, // TODO 150 NET: 0, // TODO
151 NFI: '', 151 NFI: '',
152 NNP: 0, 152 NNP: 0,
153 NOM: $scope.factura.cliente.nom, 153 NOM: $scope.factura.cliente.nom,
154 OPE: $scope.factura.vendedor.CodVen, 154 OPE: $scope.factura.vendedor.CodVen,
155 PAG: $scope.getTotal(), 155 PAG: $scope.getTotal(),
156 PER: 0, 156 PER: 0,
157 PER_IVA: 0, 157 PER_IVA: 0,
158 PLA: $scope.factura.vendedor.NplVen, 158 PLA: $scope.factura.vendedor.NplVen,
159 PRO: '', 159 PRO: '',
160 REC_ANT: 0, 160 REC_ANT: 0,
161 SUC: parseInt($scope.puntoVenta), 161 SUC: parseInt($scope.puntoVenta),
162 TCA: 1, 162 TCA: 1,
163 TCO: 'FT', 163 TCO: 'FT',
164 TFI: '', 164 TFI: '',
165 TIP: $scope.factura.cliente.tipoFactura, 165 TIP: $scope.factura.cliente.tipoFactura,
166 TIV: 0, // TODO 166 TIV: 0, // TODO
167 TOT: $scope.getTotal(), 167 TOT: $scope.getTotal(),
168 TUR: 0, // TODO 168 TUR: 0, // TODO
169 VEN: $scope.factura.vendedor.CodVen, 169 VEN: $scope.factura.vendedor.CodVen,
170 VTO_CLI: '', 170 VTO_CLI: '',
171 ZON: 1, // TODO 171 ZON: 1, // TODO
172 OBSERVACIONES: $scope.factura.observaciones 172 OBSERVACIONES: $scope.factura.observaciones
173 }, 173 },
174 cuerpo: $scope.articulosFiltro(), 174 cuerpo: $scope.articulosFiltro(),
175 despachos: $scope.factura.despachos 175 despachos: $scope.factura.despachos
176 }; 176 };
177 177
178 crearFacturaService.guardarFactura(save).then(function(res) { 178 crearFacturaService.guardarFactura(save).then(function(res) {
179 179
180 focaBotoneraLateralService.endGuardar(true); 180 focaBotoneraLateralService.endGuardar(true);
181 181
182 focaModalService.alert('Comprobante guardado con éxito'); 182 focaModalService.alert('Comprobante guardado con éxito');
183 183
184 config(); 184 config();
185 185
186 }).catch(function(err) { 186 }).catch(function(err) {
187 focaModalService.alert('Hubo un error al guardar la factura'); 187 focaModalService.alert('Hubo un error al guardar la factura');
188 console.log(err); 188 console.log(err);
189 }); 189 });
190 190
191 }; 191 };
192 192
193 $scope.seleccionarCliente = function () { 193 $scope.seleccionarCliente = function () {
194 194
195 var modalInstance = $uibModal.open( 195 var modalInstance = $uibModal.open(
196 { 196 {
197 ariaLabelledBy: 'Busqueda de Cliente', 197 ariaLabelledBy: 'Busqueda de Cliente',
198 templateUrl: 'foca-busqueda-cliente-modal.html', 198 templateUrl: 'foca-busqueda-cliente-modal.html',
199 controller: 'focaBusquedaClienteModalController', 199 controller: 'focaBusquedaClienteModalController',
200 resolve: { 200 resolve: {
201 vendedor: function () { return null; }, 201 vendedor: function () { return null; },
202 cobrador: function () { return null; } 202 cobrador: function () { return null; }
203 }, 203 },
204 size: 'lg' 204 size: 'lg'
205 } 205 }
206 ); 206 );
207 modalInstance.result.then( 207 modalInstance.result.then(
208 function (cliente) { 208 function (cliente) {
209 $scope.factura.cliente = cliente; 209 $scope.factura.cliente = cliente;
210 210
211 $scope.$broadcast('addCabecera', { 211 $scope.$broadcast('addCabecera', {
212 label: 'Cliente:', 212 label: 'Cliente:',
213 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 213 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
214 }); 214 });
215 215
216 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 216 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
217 217
218 }, function () { 218 }, function () {
219 } 219 }
220 ); 220 );
221 221
222 }; 222 };
223 223
224 $scope.seleccionarVendedor = function() { 224 $scope.seleccionarVendedor = function() {
225 var parametrosModal = { 225 var parametrosModal = {
226 titulo: 'Búsqueda vendedores', 226 titulo: 'Búsqueda vendedores',
227 query: '/vendedor-playa', 227 query: '/vendedor-playa',
228 columnas: [ 228 columnas: [
229 { 229 {
230 propiedad: 'CodVen', 230 propiedad: 'CodVen',
231 nombre: 'Código', 231 nombre: 'Código',
232 filtro: { 232 filtro: {
233 nombre: 'rellenarDigitos', 233 nombre: 'rellenarDigitos',
234 parametro: 3 234 parametro: 3
235 } 235 }
236 }, 236 },
237 { 237 {
238 propiedad: 'NomVen', 238 propiedad: 'NomVen',
239 nombre: 'Nombre' 239 nombre: 'Nombre'
240 } 240 }
241 ], 241 ],
242 size: 'md' 242 size: 'md'
243 }; 243 };
244 focaModalService.modal(parametrosModal).then( 244 focaModalService.modal(parametrosModal).then(
245 function (vendedor) { 245 function (vendedor) {
246 246
247 indicarPassword(vendedor) 247 indicarPassword(vendedor)
248 .then(function() { 248 .then(function() {
249 validarPlanillaVendedor(vendedor) 249 validarPlanillaVendedor(vendedor)
250 .then(function() { 250 .then(function() {
251 251
252 $filter('filter')($scope.botonera, { 252 $filter('filter')($scope.botonera, {
253 label: 'Vendedor' 253 label: 'Vendedor'
254 })[0].checked = true; 254 })[0].checked = true;
255 255
256 $scope.$broadcast('addCabecera', { 256 $scope.$broadcast('addCabecera', {
257 label: 'Vendedor:', 257 label: 'Vendedor:',
258 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + 258 valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) +
259 ' - ' + 259 ' - ' +
260 vendedor.NomVen 260 vendedor.NomVen
261 }); 261 });
262 262
263 $scope.factura.vendedor = vendedor; 263 $scope.factura.vendedor = vendedor;
264 264
265 getProductosByPlanilla(vendedor.NplVen); 265 getProductosByPlanilla(vendedor.NplVen);
266 }) 266 })
267 .catch($scope.seleccionarVendedor); 267 .catch($scope.seleccionarVendedor);
268 }) 268 })
269 .catch(function(err) { 269 .catch(function(err) {
270 console.log(err) 270 console.log(err)
271 }); 271 });
272 272
273 }, function () { } 273 }, function () { }
274 ); 274 );
275 }; 275 };
276 276
277 $scope.seleccionarMoneda = function () { 277 $scope.seleccionarMoneda = function () {
278 278
279 var parametrosModal = { 279 var parametrosModal = {
280 titulo: 'Búsqueda de monedas', 280 titulo: 'Búsqueda de monedas',
281 query: '/moneda', 281 query: '/moneda',
282 columnas: [ 282 columnas: [
283 { 283 {
284 propiedad: 'DETALLE', 284 propiedad: 'DETALLE',
285 nombre: 'Nombre' 285 nombre: 'Nombre'
286 }, 286 },
287 { 287 {
288 propiedad: 'SIMBOLO', 288 propiedad: 'SIMBOLO',
289 nombre: 'Símbolo' 289 nombre: 'Símbolo'
290 } 290 }
291 ], 291 ],
292 size: 'md' 292 size: 'md'
293 }; 293 };
294 focaModalService.modal(parametrosModal).then( 294 focaModalService.modal(parametrosModal).then(
295 function (moneda) { 295 function (moneda) {
296 296
297 if (moneda.ID !== 1) { 297 if (moneda.ID !== 1) {
298 $scope.abrirModalCotizacion(moneda); 298 $scope.abrirModalCotizacion(moneda);
299 return; 299 return;
300 } 300 }
301 301
302 crearRemitoService.getCotizacionByIdMoneda(1) 302 crearRemitoService.getCotizacionByIdMoneda(1)
303 .then(function (res) { 303 .then(function (res) {
304 304
305 cotizacionPArgentino = res.data[0].cotizaciones[0]; 305 cotizacionPArgentino = res.data[0].cotizaciones[0];
306 cotizacionPArgentino.moneda = moneda; 306 cotizacionPArgentino.moneda = moneda;
307 307
308 actualizarCabeceraMoneda(cotizacionPArgentino); 308 actualizarCabeceraMoneda(cotizacionPArgentino);
309 309
310 $scope.remito.cotizacion = cotizacionPArgentino; 310 $scope.remito.cotizacion = cotizacionPArgentino;
311 }); 311 });
312 }, function () { 312 }, function () {
313 313
314 } 314 }
315 ); 315 );
316 }; 316 };
317 317
318 $scope.abrirModalCotizacion = function (moneda) { 318 $scope.abrirModalCotizacion = function (moneda) {
319 var modalInstance = $uibModal.open( 319 var modalInstance = $uibModal.open(
320 { 320 {
321 ariaLabelledBy: 'Busqueda de Cotización', 321 ariaLabelledBy: 'Busqueda de Cotización',
322 templateUrl: 'modal-cotizacion.html', 322 templateUrl: 'modal-cotizacion.html',
323 controller: 'focaModalCotizacionController', 323 controller: 'focaModalCotizacionController',
324 size: 'lg', 324 size: 'lg',
325 resolve: { idMoneda: function () { return moneda.ID; } } 325 resolve: { idMoneda: function () { return moneda.ID; } }
326 } 326 }
327 ); 327 );
328 modalInstance.result.then( 328 modalInstance.result.then(
329 function (cotizacion) { 329 function (cotizacion) {
330 330
331 cotizacion.moneda = moneda; 331 cotizacion.moneda = moneda;
332 actualizarCabeceraMoneda(cotizacion); 332 actualizarCabeceraMoneda(cotizacion);
333 $scope.factura.cotizacion = cotizacion; 333 $scope.factura.cotizacion = cotizacion;
334 334
335 }, function () { 335 }, function () {
336 336
337 } 337 }
338 ); 338 );
339 }; 339 };
340 340
341 $scope.seleccionarObservaciones = function () { 341 $scope.seleccionarObservaciones = function () {
342 var observacion = { 342 var observacion = {
343 titulo: 'Ingrese Observaciones', 343 titulo: 'Ingrese Observaciones',
344 value: $scope.factura.observaciones, 344 value: $scope.factura.observaciones,
345 maxlength: 155, 345 maxlength: 155,
346 textarea: true 346 textarea: true
347 }; 347 };
348 348
349 focaModalService 349 focaModalService
350 .prompt(observacion) 350 .prompt(observacion)
351 .then(function (observaciones) { 351 .then(function (observaciones) {
352 $scope.factura.observaciones = observaciones; 352 $scope.factura.observaciones = observaciones;
353 }); 353 });
354 }; 354 };
355 355
356 $scope.articulosFiltro = function () { 356 $scope.articulosFiltro = function () {
357 return $scope.factura.articulosFactura; 357 return $scope.factura.articulosFactura;
358 }; 358 };
359 359
360 $scope.getTotal = function () { 360 $scope.getTotal = function () {
361 361
362 var total = 0; 362 var total = 0;
363 363
364 $scope.articulosFiltro().forEach(function (articulo) { 364 $scope.articulosFiltro().forEach(function (articulo) {
365 total += articulo.PUN * articulo.CAN; 365 total += articulo.PUN * articulo.CAN;
366 }); 366 });
367 367
368 return parseFloat(total.toFixed(2)); 368 return parseFloat(total.toFixed(2));
369 }; 369 };
370 370
371 function getProductosByPlanilla(numeroPlanilla) { 371 function getProductosByPlanilla(numeroPlanilla) {
372 372
373 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function(res) { 373 crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function(res) {
374 374
375 res.data.forEach(function (producto) { 375 res.data.forEach(function (producto) {
376 376
377 $scope.botonera.push({ 377 $scope.botonera.push({
378 label: producto.DetArt, 378 label: producto.DetArt,
379 image: 'productos.png' 379 image: 'productos.png'
380 }); 380 });
381 381
382 382
383 crearFuncionesProductos(producto); 383 crearFuncionesProductos(producto);
384 384
385 }); 385 });
386 }); 386 });
387 } 387 }
388 388
389 function crearFuncionesProductos(producto) { 389 function crearFuncionesProductos(producto) {
390 390
391 $scope[nombreFuncion(producto.DetArt)] = function() { 391 $scope[nombreFuncion(producto.DetArt)] = function() {
392 392
393 if (angular.equals($scope.factura.cliente, {})) { 393 if (angular.equals($scope.factura.cliente, {})) {
394 focaModalService.alert('Seleccione cliente'); 394 focaModalService.alert('Seleccione cliente');
395 return; 395 return;
396 } 396 }
397 397
398 var parametrosModal = { 398 var modalInstance = $uibModal.open(
399 titulo: 'Despachos ' + producto.DetArt, 399 {
400 data: producto.despachos, 400 templateUrl: 'modal-combustibles.html',
401 columnas: [ 401 controller: 'focaModalCombustiblesController',
402 { 402 resolve: {
403 propiedad: 'FEC', 403 parametros: function() {
404 nombre: 'Fecha', 404 return {
405 filtro: { 405 despachos: producto.despachos,
406 nombre: 'date', 406 nombreProducto: producto.DetArt
407 parametro: 'dd/MM/yyyy HH:mm' 407 }
408 } 408 }
409 }, 409 },
410 { 410 size: 'lg'
411 propiedad: 'IMP', 411 }
412 nombre: 'Importe' 412 );
413 },
414 {
415 propiedad: 'LTS',
416 nombre: 'Litros'
417 }
418 ],
419 size: 'md'
420 };
421 413
422 focaModalService.modal(parametrosModal).then(function(despacho) { 414 modalInstance.result.then(function(despacho) {
423 415
424 var articulo = { 416 var articulo = {
425 TIP: $scope.factura.cliente.tipoFactura, 417 TIP: $scope.factura.cliente.tipoFactura,
426 TCO: 'FT', 418 TCO: 'FT',
427 SUC: parseInt($scope.puntoVenta), 419 SUC: parseInt($scope.puntoVenta),
428 ORD: $scope.articulosFiltro().length + 1, 420 ORD: $scope.articulosFiltro().length + 1,
429 SEC: despacho.SEC, 421 SEC: despacho.SEC,
430 ART: despacho.PRO, 422 ART: despacho.PRO,
431 RUB: producto.CodRub, 423 RUB: producto.CodRub,
432 DES: producto.DetArt, 424 DES: producto.DetArt,
433 CAN: despacho.LTS, 425 CAN: despacho.LTS,
434 PUN: producto.PreVen, // TODO 426 PUN: producto.PreVen, // TODO
435 IVA: producto.IMPIVA, // TODO 427 IVA: producto.IMPIVA, // TODO
436 NET: 0, // TODO 428 NET: 0, // TODO
437 NEX: 0, // TODO 429 NEX: 0, // TODO
438 IMI: producto.ImpInt, // TODO 430 IMI: producto.ImpInt, // TODO
439 IMI2: producto.ImpInt2, // TODO 431 IMI2: producto.ImpInt2, // TODO
440 IMI3: producto.ImpInt3, // TODO 432 IMI3: producto.ImpInt3, // TODO
441 PUT: producto.PreNet, // TODO 433 PUT: producto.PreNet, // TODO
442 SUR: despacho.SUR, 434 SUR: despacho.SUR,
443 PLA: despacho.PLA, 435 PLA: despacho.PLA,
444 LUG: despacho.LUG, 436 LUG: despacho.LUG,
445 LEG: $scope.factura.vendedor.CodVen, 437 LEG: $scope.factura.vendedor.CodVen,
446 TUR: $scope.factura.vendedor.TurVen, 438 TUR: $scope.factura.vendedor.TurVen,
447 ORDEN_PRECOMPRA: '', 439 ORDEN_PRECOMPRA: '',
448 ESC: producto.tipoFactura == 'L' ? 1 : 0, 440 ESC: producto.tipoFactura == 'L' ? 1 : 0,
449 CMF: 0, 441 CMF: 0,
450 PTA: 0, 442 PTA: 0,
451 IVS: 0, 443 IVS: 0,
452 TIVA: 0, 444 TIVA: 0,
453 CON: 0, 445 CON: 0,
454 SINO: '', 446 SINO: '',
455 ORD_TRA: 0, 447 ORD_TRA: 0,
456 IMP_DESP: 0, 448 IMP_DESP: 0,
457 PCD: 0, 449 PCD: 0,
458 RTO: '' 450 RTO: ''
459 }; 451 };
460 452
461 crearFacturaService.setearDespachoOcupado({ 453 crearFacturaService.setearDespachoOcupado({
462 surtidor: despacho.SUR, 454 surtidor: despacho.SUR,
463 producto: despacho.PRO, 455 producto: despacho.PRO,
464 carga: despacho.CAR 456 carga: despacho.CAR
465 }) 457 })
466 .then(function () { 458 .then(function () {
467 $scope.factura.articulosFactura.push(articulo); 459 $scope.factura.articulosFactura.push(articulo);
468 $scope.factura.despachos.push(despacho); 460 $scope.factura.despachos.push(despacho);
469 }) 461 })
470 .catch(function (err) { 462 .catch(function (err) {
471 463
472 focaModalService.alert('El despacho esta en uso'); 464 focaModalService.alert('El despacho esta en uso');
473 }); 465 });
474 466
475 }) 467 })
476 .catch(function (err) { 468 .catch(function (err) {
477 console.log(err); 469 console.log(err);
478 }); 470 });
479 471
480 }; 472 };
481 } 473 }
482 474
483 function nombreFuncion(string) { 475 function nombreFuncion(string) {
484 var texto = 'seleccionar'; 476 var texto = 'seleccionar';
485 var arr = string.split(' '); 477 var arr = string.split(' ');
486 arr.forEach(function(palabra) { 478 arr.forEach(function(palabra) {
487 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 479 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
488 texto += palabra; 480 texto += palabra;
489 }); 481 });
490 return texto; 482 return texto;
491 } 483 }
492 484
493 function indicarPassword(vendedor) { 485 function indicarPassword(vendedor) {
494 486
495 return new Promise(function(resolve, reject) { 487 return new Promise(function(resolve, reject) {
496 488
497 focaModalService 489 focaModalService
498 .prompt({ 490 .prompt({
499 titulo: 'Indique Contraseña', 491 titulo: 'Indique Contraseña',
500 value: '' 492 value: ''
501 }) 493 })
502 .then(function (contraseña) { 494 .then(function (contraseña) {
503 495
504 if (contraseña != vendedor.ClaVen.trim()) { 496 if (contraseña != vendedor.ClaVen.trim()) {
505 497
506 focaModalService.alert('Clave incorrecta').then(function() { 498 focaModalService.alert('Clave incorrecta').then(function() {
507 indicarPassword(vendedor); 499 indicarPassword(vendedor);
508 }); 500 });
509 } else { 501 } else {
510 resolve(); 502 resolve();
511 } 503 }
512 }) 504 })
513 .catch(reject); 505 .catch(reject);
514 }); 506 });
515 } 507 }
516 508
517 function validarPlanillaVendedor(vendedor) { 509 function validarPlanillaVendedor(vendedor) {
518 510
519 return new Promise(function(resolve, reject) { 511 return new Promise(function(resolve, reject) {
520 512
521 crearFacturaService 513 crearFacturaService
522 .validarPlanillaVendedor(vendedor.CodVen.trim()) 514 .validarPlanillaVendedor(vendedor.CodVen.trim())
523 .then(function (res) { 515 .then(function (res) {
524 516
525 if (!res.data.length) { 517 if (!res.data.length) {
526 518
527 focaModalService 519 focaModalService
528 .alert('No se encontró planilla abierta para el vendedor') 520 .alert('No se encontró planilla abierta para el vendedor')
529 .then(reject); 521 .then(reject);
530 522
531 } else { 523 } else {
532 resolve(); 524 resolve();
533 } 525 }
534 526
535 }) 527 })
536 .catch(reject); 528 .catch(reject);
537 }); 529 });
538 } 530 }
539 531
540 function rellenar(relleno, longitud) { 532 function rellenar(relleno, longitud) {
541 relleno = '' + relleno; 533 relleno = '' + relleno;
542 while (relleno.length < longitud) { 534 while (relleno.length < longitud) {
543 relleno = '0' + relleno; 535 relleno = '0' + relleno;
544 } 536 }
545 return relleno; 537 return relleno;
546 } 538 }
547 539
548 function salir() { 540 function salir() {
549 var confirmacion = false; 541 var confirmacion = false;
550 542
551 if (!angular.equals($scope.factura, $scope.inicial)) { 543 if (!angular.equals($scope.factura, $scope.inicial)) {
552 confirmacion = true; 544 confirmacion = true;
553 } 545 }
554 546
555 if (confirmacion) { 547 if (confirmacion) {
556 focaModalService.confirm( 548 focaModalService.confirm(
557 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 549 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
558 ).then(function (data) { 550 ).then(function (data) {
559 if (data) { 551 if (data) {
560 $location.path('/'); 552 $location.path('/');
561 } 553 }
562 }); 554 });
563 } else { 555 } else {
564 $location.path('/'); 556 $location.path('/');
565 } 557 }
566 } 558 }
567 559
568 function setearFactura(factura) { 560 function setearFactura(factura) {
569 561
570 $scope.$broadcast('cleanCabecera'); 562 $scope.$broadcast('cleanCabecera');
571 563
572 $scope.cabeceras = []; 564 $scope.cabeceras = [];
573 565
574 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 566 if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
575 $scope.cabeceras.push({ 567 $scope.cabeceras.push({
576 label: 'Moneda:', 568 label: 'Moneda:',
577 valor: factura.cotizacion.moneda.DETALLE 569 valor: factura.cotizacion.moneda.DETALLE
578 }); 570 });
579 $scope.cabeceras.push({ 571 $scope.cabeceras.push({
580 label: 'Fecha cotizacion:', 572 label: 'Fecha cotizacion:',
581 valor: $filter('date')(factura.cotizacion.FECHA, 573 valor: $filter('date')(factura.cotizacion.FECHA,
582 'dd/MM/yyyy') 574 'dd/MM/yyyy')
583 }); 575 });
584 $scope.cabeceras.push({ 576 $scope.cabeceras.push({
585 label: 'Cotizacion:', 577 label: 'Cotizacion:',
586 valor: $filter('number')(factura.cotizacion.VENDEDOR, 578 valor: $filter('number')(factura.cotizacion.VENDEDOR,
587 '2') 579 '2')
588 }); 580 });
589 } 581 }
590 582
591 if (factura.cotizacion && factura.cotizacion.moneda) { 583 if (factura.cotizacion && factura.cotizacion.moneda) {
592 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 584 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
593 } 585 }
594 586
595 if (factura.cliente && factura.cliente.cod) { 587 if (factura.cliente && factura.cliente.cod) {
596 $scope.cabeceras.push({ 588 $scope.cabeceras.push({
597 label: 'Cliente:', 589 label: 'Cliente:',
598 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + 590 valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' +
599 factura.cliente.nom 591 factura.cliente.nom
600 }); 592 });
601 593
602 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 594 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
603 } 595 }
604 596
605 $scope.puntoVenta = rellenar(factura.sucursal, 4); 597 $scope.puntoVenta = rellenar(factura.sucursal, 4);
606 $scope.comprobante = rellenar(factura.numerofactura, 8); 598 $scope.comprobante = rellenar(factura.numerofactura, 8);
607 $scope.factura = factura; 599 $scope.factura = factura;
608 600
609 addArrayCabecera($scope.cabeceras); 601 addArrayCabecera($scope.cabeceras);
610 } 602 }
611 603
612 function getLSFactura() { 604 function getLSFactura() {
613 var factura = JSON.parse($localStorage.factura || null); 605 var factura = JSON.parse($localStorage.factura || null);
614 if (factura) { 606 if (factura) {
615 setearFactura(factura); 607 setearFactura(factura);
616 delete $localStorage.factura; 608 delete $localStorage.factura;
617 } 609 }
618 } 610 }
619 611
620 function addArrayCabecera(array) { 612 function addArrayCabecera(array) {
621 for (var i = 0; i < array.length; i++) { 613 for (var i = 0; i < array.length; i++) {
622 $scope.$broadcast('addCabecera', { 614 $scope.$broadcast('addCabecera', {
623 label: array[i].label, 615 label: array[i].label,
624 valor: array[i].valor 616 valor: array[i].valor
625 }); 617 });
626 } 618 }
627 } 619 }
628 620
629 function actualizarCabeceraMoneda(cotizacion) { 621 function actualizarCabeceraMoneda(cotizacion) {
630 622
631 $scope.factura.articulosFactura.forEach(function (art) { 623 $scope.factura.articulosFactura.forEach(function (art) {
632 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); 624 art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4);
633 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); 625 art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4);
634 }); 626 });
635 627
636 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 628 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
637 $scope.$broadcast('removeCabecera', 'Moneda:'); 629 $scope.$broadcast('removeCabecera', 'Moneda:');
638 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 630 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
639 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 631 $scope.$broadcast('removeCabecera', 'Cotizacion:');
640 } else { 632 } else {
641 $scope.$broadcast('addCabecera', { 633 $scope.$broadcast('addCabecera', {
642 label: 'Moneda:', 634 label: 'Moneda:',
643 valor: cotizacion.moneda.DETALLE 635 valor: cotizacion.moneda.DETALLE
644 }); 636 });
645 $scope.$broadcast('addCabecera', { 637 $scope.$broadcast('addCabecera', {
646 label: 'Fecha cotizacion:', 638 label: 'Fecha cotizacion:',
647 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 639 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
648 }); 640 });
649 $scope.$broadcast('addCabecera', { 641 $scope.$broadcast('addCabecera', {
650 label: 'Cotizacion:', 642 label: 'Cotizacion:',
651 valor: $filter('number')(cotizacion.VENDEDOR, '2') 643 valor: $filter('number')(cotizacion.VENDEDOR, '2')
652 }); 644 });
653 } 645 }
654 } 646 }
655 647
656 function validarGuardar() { 648 function validarGuardar() {
657 649
658 if (angular.equals({}, $scope.factura.vendedor)) { 650 if (angular.equals({}, $scope.factura.vendedor)) {
659 651
660 focaModalService.alert('Seleccione Vendedor'); 652 focaModalService.alert('Seleccione Vendedor');
661 return false; 653 return false;
662 } else if (angular.equals({}, $scope.factura.cliente)) { 654 } else if (angular.equals({}, $scope.factura.cliente)) {
663 655
664 focaModalService.alert('Seleccione Cliente') 656 focaModalService.alert('Seleccione Cliente')
665 return false; 657 return false;
666 } else if (!$scope.articulosFiltro().length) { 658 } else if (!$scope.articulosFiltro().length) {
667 659
668 focaModalService.alert('Seleccione al menos un Articulo'); 660 focaModalService.alert('Seleccione al menos un Articulo');
669 return false; 661 return false;
670 } 662 }
671 663
672 return true; 664 return true;
673 } 665 }
674 } 666 }
675 ]); 667 ]);
676 668
src/js/controllerCombustibles.js
File was created 1 angular.module('focaCrearFactura')
2 .controller('focaModalCombustiblesController', [
3 '$filter',
4 '$scope',
5 '$uibModalInstance',
6 'parametros',
7 function($filter, $scope, $uibModalInstance, parametros) {
8
9 $scope.mangueras = [];
10
11 var productosByMangera = [];
12
13 parametros.despachos.forEach(function (despacho) {
14
15 var findCsu = productosByMangera.filter(function (csu) {
16 return csu.csu == despacho.CSU.trim();
17 })[0];
18
19 if (!findCsu) {
20
21 var mangera = {
22 csu: despacho.CSU.trim(),
23 despachos: [despacho]
24 };
25
26 productosByMangera.unshift(mangera);
27 } else {
28 findCsu.despachos.push(despacho);
29 }
30 });
31
32 $scope.mangueras = productosByMangera;
33
34 $scope.aceptar = function (despacho) {
35 $uibModalInstance.close(despacho);
36 };
37
38 $scope.cancel = function () {
39 $uibModalInstance.dismiss('cancel');
40 };
41 }
42 ]);
43
src/views/modal-combustibles.html
File was created 1 <div class="modal-header py-1">
2 <div class="row w-100">
3 <div class="col-lg-6">
4 <h5 class="modal-title my-1">Despachos Disponibles</h5>
5 </div>
6 </div>
7 </div>
8 <div class="modal-body" id="modal-body">
9 <div ng-repeat="(key, manguera) in mangueras">
10 <strong>
11 Manguera&nbsp;{{manguera.csu}}
12 </strong>
13 <button type="button" class="btn" ng-click="manguera.show = !manguera.show">
14 <i ng-show="manguera.show" class="fa fa-minus"></i>
15 <i ng-show="!manguera.show" class="fa fa-plus"></i>
16 </button>
17 <table class="table table-sm" ng-show="manguera.show">
18 <tbody>
19 <tr ng-repeat="(key, despacho) in manguera.despachos">
20 <td ng-bind="despacho.FEC | date:'dd/MM/yyyy hh:MM:ss'"></td>
21 <td ng-bind="despacho.LTS"></td>
22 <td ng-bind="despacho.IMP | currency: '$'"></td>
23 <td>
24 <button
25 type="button"
26 class="btn btn-xs p-1 float-right"
27 title="Seleccionar"
28 ng-click="aceptar(despacho)"
29 ><i class="fa fa-circle-thin" aria-hidden="true"></i>
30 </button>
31 </td>
32 </tr>
33 </tbody>
34 </table>
35 </div>
36
37 </div>
38 <div class="modal-footer py-1">
39 <nav ng-show="currentPageProveedores.length > 0 && primerBusqueda" class="mr-auto">
40 <ul class="pagination pagination-sm mb-0">
41 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
42 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
43 <span aria-hidden="true">&laquo;</span>
44 <span class="sr-only">Anterior</span>
45 </a>
46 </li>
47 <li
48 class="page-item"
49 ng-repeat="pagina in paginas"
50 ng-class="{'active': pagina == currentPage}"
51 >
52 <a
53 class="page-link"
54 href="javascript:void();"
55 ng-click="selectPage(pagina)"
56 ng-bind="pagina"
57 ></a>
58 </li>
59 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
60 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
61 <span aria-hidden="true">&raquo;</span>
62 <span class="sr-only">Siguiente</span>
63 </a>
64 </li>
65 </ul>
66 </nav>
67 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
68 </div>
69