Commit dd83d1edbda55ba400bed93536c051e5189135f2

Authored by Marcelo Puebla
1 parent 3d1313517b

Agregado pago electronico, agregada validacion cuando el carrito este vacio

src/app/modules/carrito/carrito.component.ts
... ... @@ -4,6 +4,7 @@ import { ArticuloService } from 'src/app/services/articulo/articulo.service';
4 4 import { APP_SETTINGS } from 'src/etc/AppSettings';
5 5 import { trigger, state, style, transition, animate } from '@angular/animations';
6 6 import { IArticulo } from 'src/app/interfaces/IArticulo';
  7 +import { Router } from '@angular/router';
7 8  
8 9 @Component({
9 10 selector: 'app-carrito',
... ... @@ -27,11 +28,17 @@ export class CarritoComponent implements OnInit {
27 28 maxCantidad = 50;
28 29  
29 30 constructor(
30   - private location: Location,
31 31 public articuloService: ArticuloService,
  32 + private location: Location,
  33 + private router: Router,
32 34 ) { }
33 35  
34   - ngOnInit() { }
  36 + ngOnInit() {
  37 + if (!this.articuloService.carrito.length) {
  38 + this.router.navigate(['']);
  39 + return;
  40 + }
  41 + }
35 42  
36 43 deleteArticulo(index: number) {
37 44 this.articuloService.carrito.splice(index, 1);
src/app/modules/forma-pago/forma-pago.component.html
... ... @@ -22,7 +22,7 @@
22 22 <div class="col-auto px-0 h-auto align-self-start">
23 23 <div
24 24 class="btn-effect col-auto align-self-center px-0 bg-white"
25   - [routerLink]="['/pago-electronico']">
  25 + (click)="medioPago(9)">
26 26 <div class="row mx-0 bg-primary badge-pill">
27 27 <div class="col-auto p-0">
28 28 <img
src/app/modules/forma-pago/forma-pago.component.ts
... ... @@ -15,6 +15,10 @@ export class FormaPagoComponent implements OnInit {
15 15 ) { }
16 16  
17 17 ngOnInit() {
  18 + if (!this.articuloService.carrito.length) {
  19 + this.router.navigate(['']);
  20 + return;
  21 + }
18 22 }
19 23  
20 24 medioPago(medioPago: number) {
src/app/modules/pago-electronico/pago-electronico.component.html
... ... @@ -25,7 +25,7 @@
25 25 ondragstart="return false;"
26 26 (contextmenu)="false"
27 27 class="d-block mx-auto img-fluid"
28   - src="assets/img/icono-mercado-pago.svg">
  28 + [src]="urlQr">
29 29 </div>
30 30 </div>
31 31 </div>
src/app/modules/pago-electronico/pago-electronico.component.ts
1 1 import { Component, OnInit } from '@angular/core';
  2 +import { ArticuloService } from 'src/app/services/articulo/articulo.service';
  3 +import { Router } from '@angular/router';
  4 +import { APP_SETTINGS } from 'src/etc/AppSettings';
2 5  
3 6 @Component({
4 7 selector: 'app-pago-electronico',
... ... @@ -6,10 +9,26 @@ import { Component, OnInit } from &#39;@angular/core&#39;;
6 9 styleUrls: ['./pago-electronico.component.scss']
7 10 })
8 11 export class PagoElectronicoComponent implements OnInit {
  12 + urlQr = `${APP_SETTINGS.apiDeboSuite}/qr/dev/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`;
9 13  
10   - constructor() { }
  14 + constructor(
  15 + private articuloService: ArticuloService,
  16 + private router: Router,
  17 + ) { }
11 18  
12 19 ngOnInit() {
  20 + if (!this.articuloService.carrito.length) {
  21 + this.router.navigate(['']);
  22 + return;
  23 + }
  24 + let dataPago = {
  25 + pedidoAnombreDe: ''
  26 + }
  27 + this.articuloService.pay(dataPago)
  28 + .subscribe((res: any) => {
  29 + this.articuloService.idComanda = res.data;
  30 + this.router.navigate(['mensaje-final']);
  31 + }, err => console.error(err));
13 32 }
14 33  
15 34 }
src/app/modules/pago-tarjeta/pago-tarjeta.component.ts
... ... @@ -15,6 +15,10 @@ export class PagoTarjetaComponent implements OnInit {
15 15 ) { }
16 16  
17 17 ngOnInit() {
  18 + if (!this.articuloService.carrito.length) {
  19 + this.router.navigate(['']);
  20 + return;
  21 + }
18 22 let dataPago = {
19 23 pedidoAnombreDe: ''
20 24 }
src/app/services/articulo/articulo.service.ts
... ... @@ -48,7 +48,7 @@ export class ArticuloService {
48 48 return new Observable((observer) => {
49 49 this.clienteService.getById(-1)
50 50 .subscribe(cliente => {
51   - let puntoVenta = 9998;
  51 + let puntoVenta = APP_SETTINGS.puntoVenta;
52 52 this.markArticuloInPromoAsRemoved();
53 53 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, {
54 54 productos: this.carrito,
... ... @@ -57,7 +57,7 @@ export class ArticuloService {
57 57 codigoVendedor: 5,
58 58 puntoVenta: this.medioPago === 9 ? -1 * puntoVenta : puntoVenta,
59 59 pedidoAnombreDe: dataPago.pedidoAnombreDe,
60   - numeroPlanilla: '11111',
  60 + numeroPlanilla: APP_SETTINGS.numeroPlanilla,
61 61 })
62 62 .subscribe((data) => {
63 63 observer.next(data);
src/etc/AppSettings.ejemplo.ts
1 1 // export const APP_SETTINGS = {
2   -// apiDeboSuite: 'http://localhost:9900'
  2 + // apiDeboSuite: 'http://localhost:9900',
  3 + // puntoVenta: 9998,
  4 + // numeroPlanilla: '1111',
  5 + // codigoP: 99996,
  6 + // terminal: 101
3 7 // }