Commit 9a0552610be7063adab17f74433da93431d3fa41

Authored by Marcelo Puebla
1 parent b023575075
Exists in develop

Add

Modal de error en forma de pago
src/app/modules/pago-electronico/pago-electronico.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { ArticuloService } from 'src/app/services/articulo/articulo.service'; 2 import { ArticuloService } from 'src/app/services/articulo/articulo.service';
3 import { Router } from '@angular/router'; 3 import { Router } from '@angular/router';
4 import { APP_SETTINGS } from 'src/etc/AppSettings'; 4 import { APP_SETTINGS } from 'src/etc/AppSettings';
5 import { BsModalService } from 'ngx-bootstrap/modal';
6 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
5 7
6 @Component({ 8 @Component({
7 selector: 'app-pago-electronico', 9 selector: 'app-pago-electronico',
8 templateUrl: './pago-electronico.component.html', 10 templateUrl: './pago-electronico.component.html',
9 styleUrls: ['./pago-electronico.component.scss'] 11 styleUrls: ['./pago-electronico.component.scss']
10 }) 12 })
11 export class PagoElectronicoComponent implements OnInit { 13 export class PagoElectronicoComponent implements OnInit, OnDestroy {
12 urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`; 14 urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`;
13 15
14 constructor( 16 constructor(
15 private articuloService: ArticuloService, 17 private articuloService: ArticuloService,
16 private router: Router, 18 private router: Router,
19 private modalService: BsModalService,
17 ) { } 20 ) { }
18 21
19 ngOnInit() { 22 ngOnInit() {
20 if (!this.articuloService.carrito.length) { 23 if (!this.articuloService.carrito.length) {
21 this.router.navigate(['']); 24 this.router.navigate(['']);
22 return; 25 return;
23 } 26 }
24 const dataPago = { 27 const dataPago = {
25 pedidoAnombreDe: '' 28 pedidoAnombreDe: ''
26 }; 29 };
27 dataPago.pedidoAnombreDe = ''; 30 dataPago.pedidoAnombreDe = '';
28 this.articuloService.pay(dataPago) 31 this.articuloService.pay(dataPago)
29 .subscribe((res: any) => { 32 .subscribe((res: any) => {
30 this.articuloService.idComanda = res.data; 33 this.articuloService.idComanda = res.data;
31 this.router.navigate(['mensaje-final']); 34 this.router.navigate(['mensaje-final']);
32 }, err => console.error(err)); 35 }, (err) => {
36 this.modalService.show(ErrorFormaPagoComponent, {
37 class: 'modal-lg modal-dialog-centered',
38 ignoreBackdropClick: true,
39 });
40 });
33 this.mediaPantalla(); 41 this.mediaPantalla();
34 } 42 }
43
44 ngOnDestroy() {
45 for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
46 this.modalService.hide(i);
47 }
48 }
49
35 mediaPantalla() { 50 mediaPantalla() {
36 if ($('body').hasClass('media-pantalla')) { 51 if ($('body').hasClass('media-pantalla')) {
37 $('.qr-mt').addClass('media-pantalla'); 52 $('.qr-mt').addClass('media-pantalla');
38 } 53 }
39 } 54 }
40 } 55 }
41 56
src/app/modules/pago-electronico/pago-electronico.module.ts
1 import { NgModule } from '@angular/core'; 1 import { NgModule } from '@angular/core';
2 import { CommonModule } from '@angular/common'; 2 import { CommonModule } from '@angular/common';
3 3
4 import { PagoElectronicoRoutingModule } from './pago-electronico-routing.module'; 4 import { PagoElectronicoRoutingModule } from './pago-electronico-routing.module';
5 import { PagoElectronicoComponent } from './pago-electronico.component'; 5 import { PagoElectronicoComponent } from './pago-electronico.component';
6 import { PagoTarjetaModule } from '../pago-tarjeta/pago-tarjeta.module';
6 7
7 8
8 @NgModule({ 9 @NgModule({
9 declarations: [PagoElectronicoComponent], 10 declarations: [PagoElectronicoComponent],
10 imports: [ 11 imports: [
11 CommonModule, 12 CommonModule,
12 PagoElectronicoRoutingModule 13 PagoElectronicoRoutingModule,
13 ] 14 PagoTarjetaModule,
15 ],
16 entryComponents: []
14 }) 17 })
15 export class PagoElectronicoModule { } 18 export class PagoElectronicoModule { }
16 19
src/app/modules/pago-tarjeta/pago-tarjeta.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { ArticuloService } from 'src/app/services/articulo/articulo.service'; 2 import { ArticuloService } from 'src/app/services/articulo/articulo.service';
3 import { Router } from '@angular/router'; 3 import { Router } from '@angular/router';
4 import { BsModalService } from 'ngx-bootstrap/modal';
5 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
4 6
5 @Component({ 7 @Component({
6 selector: 'app-pago-tarjeta', 8 selector: 'app-pago-tarjeta',
7 templateUrl: './pago-tarjeta.component.html', 9 templateUrl: './pago-tarjeta.component.html',
8 styleUrls: ['./pago-tarjeta.component.scss'] 10 styleUrls: ['./pago-tarjeta.component.scss']
9 }) 11 })
10 export class PagoTarjetaComponent implements OnInit { 12 export class PagoTarjetaComponent implements OnInit, OnDestroy {
11 13
12 constructor( 14 constructor(
13 private articuloService: ArticuloService, 15 private articuloService: ArticuloService,
14 private router: Router, 16 private router: Router,
17 private modalService: BsModalService,
15 ) { } 18 ) { }
16 19
17 ngOnInit() { 20 ngOnInit() {
18 if (!this.articuloService.carrito.length) { 21 if (!this.articuloService.carrito.length) {
19 this.router.navigate(['']); 22 this.router.navigate(['']);
20 return; 23 return;
21 } 24 }
22 const dataPago = { 25 const dataPago = {
23 pedidoAnombreDe: '' 26 pedidoAnombreDe: ''
24 }; 27 };
25 this.articuloService.pay(dataPago) 28 this.articuloService.pay(dataPago)
26 .subscribe((res: any) => { 29 .subscribe((res: any) => {
27 this.articuloService.idComanda = res.data; 30 this.articuloService.idComanda = res.data;
28 this.router.navigate(['mensaje-final']); 31 this.router.navigate(['mensaje-final']);
29 }, err => console.error(err)); 32 }, (err) => {
33 this.modalService.show(ErrorFormaPagoComponent, {
34 class: 'modal-lg modal-dialog-centered',
35 ignoreBackdropClick: true,
36 });
37 });
30 this.mediaPantalla(); 38 this.mediaPantalla();
31 } 39 }
32 40
41 ngOnDestroy() {
42 for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
43 this.modalService.hide(i);
44 }
45 }
46
33 mediaPantalla() { 47 mediaPantalla() {
34 if ($('body').hasClass('media-pantalla')) { 48 if ($('body').hasClass('media-pantalla')) {
35 $('.pago-tarjeta').addClass('media-pantalla'); 49 $('.pago-tarjeta').addClass('media-pantalla');
36 } 50 }
37 } 51 }
38 } 52 }
39 53
src/app/modules/pago-tarjeta/pago-tarjeta.module.ts
1 import { NgModule } from '@angular/core'; 1 import { NgModule } from '@angular/core';
2 import { CommonModule } from '@angular/common'; 2 import { CommonModule } from '@angular/common';
3 3
4 import { PagoTarjetaRoutingModule } from './pago-tarjeta-routing.module'; 4 import { PagoTarjetaRoutingModule } from './pago-tarjeta-routing.module';
5 import { PagoTarjetaComponent } from './pago-tarjeta.component'; 5 import { PagoTarjetaComponent } from './pago-tarjeta.component';
6 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
7 import { ModalModule } from 'ngx-bootstrap/modal';
6 8
7 9
8 @NgModule({ 10 @NgModule({
9 declarations: [PagoTarjetaComponent], 11 declarations: [
12 PagoTarjetaComponent,
13 ErrorFormaPagoComponent,
14 ],
10 imports: [ 15 imports: [
11 CommonModule, 16 CommonModule,
12 PagoTarjetaRoutingModule 17 PagoTarjetaRoutingModule,
13 ] 18 ModalModule.forRoot(),
19 ],
20 entryComponents: [ErrorFormaPagoComponent]
14 }) 21 })
15 export class PagoTarjetaModule { } 22 export class PagoTarjetaModule { }
16 23
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 = false; 14 esPromoPersonalizada = false;
15 urlDeboSuite = APP_SETTINGS.apiDeboSuite; 15 urlDeboSuite = APP_SETTINGS.apiDeboSuite;
16 medioPago: number; 16 medioPago: number;
17 idComanda: number; 17 idComanda: number;
18 subTotal = 0; 18 subTotal = 0;
19 maxCantidad = 50; 19 maxCantidad = 50;
20 20
21 constructor( 21 constructor(
22 private http: HttpClient, 22 private http: HttpClient,
23 private clienteService: ClienteService, 23 private clienteService: ClienteService,
24 ) { } 24 ) { }
25 25
26 getById(id) { 26 getById(id) {
27 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); 27 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`);
28 } 28 }
29 29
30 getAll() { 30 getAll() {
31 return this.http.get(`${this.urlDeboSuite}/articulos/`); 31 return this.http.get(`${this.urlDeboSuite}/articulos/`);
32 } 32 }
33 33
34 getAllWithPaginator(page: number = 1) { 34 getAllWithPaginator(page: number = 1) {
35 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); 35 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`);
36 } 36 }
37 37
38 substractCant(articulo: IArticulo) { 38 substractCant(articulo: IArticulo) {
39 if (articulo.cantidad === 1) return; 39 if (articulo.cantidad === 1) return;
40 articulo.cantidad--; 40 articulo.cantidad--;
41 this.calcularTotal(); 41 this.calcularTotal();
42 } 42 }
43 43
44 addCant(articulo: IArticulo) { 44 addCant(articulo: IArticulo) {
45 if (articulo.cantidad >= this.maxCantidad) return; 45 if (articulo.cantidad >= this.maxCantidad) return;
46 articulo.cantidad++; 46 articulo.cantidad++;
47 this.calcularTotal(); 47 this.calcularTotal();
48 } 48 }
49 49
50 calcularTotal() { 50 calcularTotal() {
51 this.subTotal = 0; 51 this.subTotal = 0;
52 this.carrito.forEach(articulo => { 52 this.carrito.forEach(articulo => {
53 this.subTotal += (articulo.PreVen * articulo.cantidad); 53 this.subTotal += (articulo.PreVen * articulo.cantidad);
54 }); 54 });
55 } 55 }
56 56
57 setArticulo(articulo: IArticulo) { 57 setArticulo(articulo: IArticulo) {
58 articulo.cantidad = 1; 58 articulo.cantidad = 1;
59 for (const articuloCarrito of this.carrito) { 59 for (const articuloCarrito of this.carrito) {
60 if (articuloCarrito.id === articulo.id && !articulo.productos) { 60 if (articuloCarrito.id === articulo.id && !articulo.productos) {
61 articuloCarrito.cantidad++; 61 articuloCarrito.cantidad++;
62 this.calcularTotal(); 62 this.calcularTotal();
63 return; 63 return;
64 } 64 }
65 } 65 }
66 this.setArticulosSinImagen([articulo]); 66 this.setArticulosSinImagen([articulo]);
67 this.carrito.unshift(articulo); 67 this.carrito.unshift(articulo);
68 this.calcularTotal(); 68 this.calcularTotal();
69 } 69 }
70 70
71 deleteArticulo(index: number) { 71 deleteArticulo(index: number) {
72 this.carrito.splice(index, 1); 72 this.carrito.splice(index, 1);
73 this.calcularTotal(); 73 this.calcularTotal();
74 } 74 }
75 75
76 pay(dataPago: any) { 76 pay(dataPago: any) {
77 return new Observable((observer) => { 77 return new Observable((observer) => {
78 this.clienteService.getById(-1) 78 this.clienteService.getById(-1)
79 .subscribe(cliente => { 79 .subscribe(cliente => {
80 this.markArticuloInPromoAsRemoved(); 80 this.markArticuloInPromoAsRemoved();
81 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { 81 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, {
82 productos: this.carrito, 82 productos: this.carrito,
83 cliente, 83 cliente,
84 origen: 'autoservicio', 84 origen: 'autoservicio',
85 codigoVendedor: 5, 85 codigoVendedor: 5,
86 puntoVenta: APP_SETTINGS.puntoVenta, 86 puntoVenta: APP_SETTINGS.puntoVenta,
87 pedidoAnombreDe: dataPago.pedidoAnombreDe, 87 pedidoAnombreDe: dataPago.pedidoAnombreDe,
88 numeroPlanilla: APP_SETTINGS.numeroPlanilla, 88 numeroPlanilla: APP_SETTINGS.numeroPlanilla,
89 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), 89 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'),
90 }) 90 })
91 .subscribe((data) => { 91 .subscribe((data) => {
92 observer.next(data); 92 observer.next(data);
93 observer.complete(); 93 observer.complete();
94 }, err => {
95 observer.error(err);
96 observer.complete();
94 }); 97 });
95 }); 98 });
96 }); 99 });
97 } 100 }
98 101
99 cleanShoppingCar() { 102 cleanShoppingCar() {
100 this.articuloAcargar = undefined; 103 this.articuloAcargar = undefined;
101 this.promoAcargar = undefined; 104 this.promoAcargar = undefined;
102 this.carrito = []; 105 this.carrito = [];
103 } 106 }
104 107
105 setArticulosSinImagen(articulos: IArticulo[]) { 108 setArticulosSinImagen(articulos: IArticulo[]) {
106 articulos.forEach((articulo: IArticulo) => { 109 articulos.forEach((articulo: IArticulo) => {
107 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : 110 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] :
108 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; 111 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes;
109 }); 112 });
110 } 113 }
111 114
112 markArticuloInPromoAsRemoved() { 115 markArticuloInPromoAsRemoved() {
113 this.carrito.forEach((articuloCarrito: IArticulo) => { 116 this.carrito.forEach((articuloCarrito: IArticulo) => {
114 if (articuloCarrito.PRO) { 117 if (articuloCarrito.PRO) {
115 articuloCarrito.productos.forEach((articulo: IArticulo) => { 118 articuloCarrito.productos.forEach((articulo: IArticulo) => {
116 if (articulo.cantidadAdicionada === 0) { 119 if (articulo.cantidadAdicionada === 0) {
117 articulo.cantidad = 0; 120 articulo.cantidad = 0;
118 articulo.importeValorExtra = 0; 121 articulo.importeValorExtra = 0;
119 } 122 }
120 }); 123 });
121 } 124 }
122 }); 125 });
123 } 126 }
124 } 127 }
125 128
src/app/shared/error-forma-pago/error-forma-pago.component.html
File was created 1 <div class="bg-primary text-center rounded">
2 <div class="modal-body">
3 <img
4 draggable="false"
5 ondragstart="return false;"
6 (contextmenu)="false"
7 class="d-block mx-auto icon-50"
8 src="assets/img/x-amarilla.svg">
9 <p class="text-white text-center m-3">Algo salió mal, intentalo de nuevo o probá con otra forma de pago</p>
10 <div
11 class="d-inline-block py-1 btn-effect bg-white badge-pill"
12 (click)="continuar()">
13 CONTINUAR
14 <img
15 draggable="false"
16 ondragstart="return false;"
17 (contextmenu)="false"
18 class="icon-30"
19 src="assets/img/ir-color.svg">
20 </div>
21 </div>
22 </div>
23
src/app/shared/error-forma-pago/error-forma-pago.component.scss
src/app/shared/error-forma-pago/error-forma-pago.component.spec.ts
File was created 1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { ErrorFormaPagoComponent } from './error-forma-pago.component';
4
5 describe('ErrorFormaPagoComponent', () => {
6 let component: ErrorFormaPagoComponent;
7 let fixture: ComponentFixture<ErrorFormaPagoComponent>;
8
9 beforeEach(async(() => {
10 TestBed.configureTestingModule({
11 declarations: [ ErrorFormaPagoComponent ]
12 })
13 .compileComponents();
14 }));
15
16 beforeEach(() => {
17 fixture = TestBed.createComponent(ErrorFormaPagoComponent);
18 component = fixture.componentInstance;
19 fixture.detectChanges();
20 });
21
22 it('should create', () => {
23 expect(component).toBeTruthy();
24 });
25 });
26
src/app/shared/error-forma-pago/error-forma-pago.component.ts
File was created 1 import { Component, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3 import { BsModalRef } from 'ngx-bootstrap/modal';
4
5 @Component({
6 selector: 'app-error-forma-pago',
7 templateUrl: './error-forma-pago.component.html',
8 styleUrls: ['./error-forma-pago.component.scss']
9 })
10 export class ErrorFormaPagoComponent implements OnInit {
11
12 constructor(
13 private router: Router,
14 private modalRef: BsModalRef,
15 ) { }
16
17 ngOnInit() { }
18
19 continuar() {
20 this.router.navigate(['forma-pago']);
21 this.modalRef.hide();
22 }
23
24 }
25
src/assets/img/x-amarilla.svg
File was created 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3 <!-- Creator: CorelDRAW X7 -->
4 <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="28.6378mm" height="28.6378mm" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
5 viewBox="0 0 1704 1704"
6 xmlns:xlink="http://www.w3.org/1999/xlink">
7 <defs>
8 <style type="text/css">
9 <![CDATA[
10 .fil0 {fill:#F4B223;fill-rule:nonzero}
11 ]]>
12 </style>
13 </defs>
14 <g id="Capa_x0020_1">
15 <metadata id="CorelCorpID_0Corel-Layer"/>
16 <polygon class="fil0" points="510,422 852,790 1194,422 1252,471 910,852 1252,1233 1194,1283 852,914 510,1283 452,1233 794,852 452,471 "/>
17 <path class="fil0" d="M852 0c235,0 448,95 603,250 154,154 249,367 249,602 0,235 -95,448 -249,603 -155,154 -368,249 -603,249 -235,0 -448,-95 -602,-249 -155,-155 -250,-368 -250,-603 0,-235 95,-448 250,-602 154,-155 367,-250 602,-250zm562 290c-144,-143 -343,-232 -562,-232 -219,0 -418,89 -562,232 -143,144 -232,343 -232,562 0,219 89,418 232,562 144,144 343,232 562,232 219,0 418,-88 562,-232 144,-144 232,-343 232,-562 0,-219 -88,-418 -232,-562z"/>
18 </g>
19 </svg>
20