Commit 0010b1bc356c922f6feadbdc13c4c75d9fe64b19

Authored by Marcelo Puebla
1 parent dd83d1edbd

Agregado pago electronico

Showing 1 changed file with 1 additions and 1 deletions   Show diff stats
src/app/services/articulo/articulo.service.ts
1 import { Injectable } from '@angular/core'; 1 import { Injectable } from '@angular/core';
2 import { HttpClient } from '@angular/common/http'; 2 import { HttpClient } from '@angular/common/http';
3 import { APP_SETTINGS } from '../../../etc/AppSettings'; 3 import { APP_SETTINGS } from '../../../etc/AppSettings';
4 import { IArticulo } from '../../interfaces/IArticulo'; 4 import { IArticulo } from '../../interfaces/IArticulo';
5 import { ClienteService } from '../cliente/cliente.service'; 5 import { ClienteService } from '../cliente/cliente.service';
6 import { Observable } from 'rxjs'; 6 import { Observable } from 'rxjs';
7 7
8 @Injectable() 8 @Injectable()
9 export class ArticuloService { 9 export class ArticuloService {
10 carrito: IArticulo[] = []; 10 carrito: IArticulo[] = [];
11 articuloAcargar: IArticulo; 11 articuloAcargar: IArticulo;
12 promoAcargar: IArticulo; 12 promoAcargar: IArticulo;
13 mostrar: string; 13 mostrar: string;
14 esPromoPersonalizada: boolean = false; 14 esPromoPersonalizada: boolean = false;
15 urlDeboSuite = APP_SETTINGS.apiDeboSuite; 15 urlDeboSuite = APP_SETTINGS.apiDeboSuite;
16 medioPago: number; 16 medioPago: number;
17 idComanda: number; 17 idComanda: number;
18 18
19 constructor( 19 constructor(
20 private http: HttpClient, 20 private http: HttpClient,
21 private clienteService: ClienteService, 21 private clienteService: ClienteService,
22 ) { } 22 ) { }
23 23
24 getById(id) { 24 getById(id) {
25 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); 25 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`);
26 } 26 }
27 27
28 getAll() { 28 getAll() {
29 return this.http.get(`${this.urlDeboSuite}/articulos/`); 29 return this.http.get(`${this.urlDeboSuite}/articulos/`);
30 } 30 }
31 31
32 getAllWithPaginator(page: number = 1) { 32 getAllWithPaginator(page: number = 1) {
33 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); 33 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`);
34 } 34 }
35 35
36 setArticulo(articulo: IArticulo) { 36 setArticulo(articulo: IArticulo) {
37 for (let i = 0; i < this.carrito.length; i++) { 37 for (let i = 0; i < this.carrito.length; i++) {
38 if (this.carrito[i].id === articulo.id) { 38 if (this.carrito[i].id === articulo.id) {
39 if (articulo.PRO) break; 39 if (articulo.PRO) break;
40 this.carrito[i].cantidad++; 40 this.carrito[i].cantidad++;
41 return; 41 return;
42 } 42 }
43 } 43 }
44 this.carrito.unshift(articulo); 44 this.carrito.unshift(articulo);
45 } 45 }
46 46
47 pay(dataPago: any) { 47 pay(dataPago: any) {
48 return new Observable((observer) => { 48 return new Observable((observer) => {
49 this.clienteService.getById(-1) 49 this.clienteService.getById(-1)
50 .subscribe(cliente => { 50 .subscribe(cliente => {
51 let puntoVenta = APP_SETTINGS.puntoVenta; 51 let puntoVenta = APP_SETTINGS.puntoVenta;
52 this.markArticuloInPromoAsRemoved(); 52 this.markArticuloInPromoAsRemoved();
53 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { 53 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, {
54 productos: this.carrito, 54 productos: this.carrito,
55 cliente: cliente, 55 cliente: cliente,
56 origen: 'autoservicio', 56 origen: 'autoservicio',
57 codigoVendedor: 5, 57 codigoVendedor: 5,
58 puntoVenta: this.medioPago === 9 ? -1 * puntoVenta : puntoVenta, 58 puntoVenta: puntoVenta,
59 pedidoAnombreDe: dataPago.pedidoAnombreDe, 59 pedidoAnombreDe: dataPago.pedidoAnombreDe,
60 numeroPlanilla: APP_SETTINGS.numeroPlanilla, 60 numeroPlanilla: APP_SETTINGS.numeroPlanilla,
61 }) 61 })
62 .subscribe((data) => { 62 .subscribe((data) => {
63 observer.next(data); 63 observer.next(data);
64 observer.complete(); 64 observer.complete();
65 }); 65 });
66 }); 66 });
67 }); 67 });
68 } 68 }
69 69
70 cleanShoppingCar() { 70 cleanShoppingCar() {
71 this.articuloAcargar = undefined; 71 this.articuloAcargar = undefined;
72 this.promoAcargar = undefined; 72 this.promoAcargar = undefined;
73 this.carrito = []; 73 this.carrito = [];
74 } 74 }
75 75
76 setArticulosSinImagen(articulos: IArticulo[]) { 76 setArticulosSinImagen(articulos: IArticulo[]) {
77 articulos.forEach((articulo: IArticulo) => { 77 articulos.forEach((articulo: IArticulo) => {
78 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : 78 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] :
79 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; 79 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes;
80 }); 80 });
81 } 81 }
82 82
83 markArticuloInPromoAsRemoved() { 83 markArticuloInPromoAsRemoved() {
84 this.carrito.forEach((articulo: IArticulo) => { 84 this.carrito.forEach((articulo: IArticulo) => {
85 if (articulo.PRO) { 85 if (articulo.PRO) {
86 articulo.productos.forEach((articulo: IArticulo) => { 86 articulo.productos.forEach((articulo: IArticulo) => {
87 if (articulo.cantidadAdicionada === 0) { 87 if (articulo.cantidadAdicionada === 0) {
88 articulo.cantidad = 0; 88 articulo.cantidad = 0;
89 articulo.importeValorExtra = 0; 89 articulo.importeValorExtra = 0;
90 } 90 }
91 }); 91 });
92 } 92 }
93 }); 93 });
94 } 94 }
95 } 95 }
96 96