Commit a741af2953a290daea9ab893d6aa008ff9ed50fd
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !159
Showing
12 changed files
Show diff stats
src/app/interfaces/IArticulo.ts
src/app/modules/carrito/carrito.component.html
... | ... | @@ -91,7 +91,7 @@ |
91 | 91 | class="row mx-3 mt-4 h-auto justify-content-end"> |
92 | 92 | <div |
93 | 93 | class="col-auto py-2 px-3 align-self-center btn-effect bg-primary badge-pill text-white" |
94 | - [routerLink]="['/forma-pago']"> | |
94 | + (click)="validateCarrito()"> | |
95 | 95 | <span> |
96 | 96 | <small class="pr-2">CONTINUAR</small> |
97 | 97 | <img |
src/app/modules/carrito/carrito.component.ts
... | ... | @@ -3,9 +3,11 @@ import { Location } from '@angular/common'; |
3 | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
4 | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
5 | 5 | import { Router } from '@angular/router'; |
6 | -import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; | |
6 | +import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | |
7 | 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
8 | 8 | import { ANIMATIONS } from 'src/app/utils/animations'; |
9 | +import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; | |
10 | +import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; | |
9 | 11 | |
10 | 12 | @Component({ |
11 | 13 | selector: 'app-carrito', |
... | ... | @@ -23,6 +25,7 @@ export class CarritoComponent implements OnInit, OnDestroy { |
23 | 25 | private location: Location, |
24 | 26 | private router: Router, |
25 | 27 | private inactiveScreen: InactiveScreenService, |
28 | + private modalService: BsModalService | |
26 | 29 | ) { } |
27 | 30 | |
28 | 31 | ngOnInit() { |
... | ... | @@ -41,6 +44,20 @@ export class CarritoComponent implements OnInit, OnDestroy { |
41 | 44 | this.articuloService.deleteArticulo(index); |
42 | 45 | } |
43 | 46 | |
47 | + validateCarrito() { | |
48 | + const res = this.articuloService.validateCarrito() | |
49 | + if (res.valid) { | |
50 | + this.router.navigate(['forma-pago']); | |
51 | + } else { | |
52 | + this.modalService.show( | |
53 | + ErrorStockComponent, | |
54 | + { | |
55 | + initialState: { articulo: res.articulo }, | |
56 | + class: 'modal-dialog-centered' | |
57 | + }); | |
58 | + } | |
59 | + } | |
60 | + | |
44 | 61 | goBack() { |
45 | 62 | this.location.back(); |
46 | 63 | } |
src/app/modules/carrito/carrito.module.ts
... | ... | @@ -5,14 +5,19 @@ import { CarritoRoutingModule } from './carrito-routing.module'; |
5 | 5 | import { CarritoComponent } from './carrito.component'; |
6 | 6 | import { SeleccionArticulosModule } from '../seleccion-articulos/seleccion-articulos.module'; |
7 | 7 | import { SharedModule } from '../shared/shared.module'; |
8 | +import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; | |
8 | 9 | |
9 | 10 | @NgModule({ |
10 | - declarations: [CarritoComponent], | |
11 | + declarations: [ | |
12 | + CarritoComponent, | |
13 | + ErrorStockComponent | |
14 | + ], | |
11 | 15 | imports: [ |
12 | 16 | CommonModule, |
13 | 17 | CarritoRoutingModule, |
14 | 18 | SeleccionArticulosModule, |
15 | 19 | SharedModule, |
16 | - ] | |
20 | + ], | |
21 | + entryComponents: [ErrorStockComponent] | |
17 | 22 | }) |
18 | 23 | export class CarritoModule { } |
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
... | ... | @@ -133,10 +133,10 @@ export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDes |
133 | 133 | Object.keys(gruposArticulos).forEach(key => { |
134 | 134 | sinonimos.push({ productos: gruposArticulos[key], }); |
135 | 135 | }); |
136 | - for (let j = 0; j < articulo.productos.length; j++) { | |
136 | + for (const a of articulo.productos) { | |
137 | 137 | Object.keys(gruposArticulos).forEach((key, i) => { |
138 | - if (gruposArticulos[key][i].ID_SIN.toString() === articulo.productos[j].idSinonimo.toString()) { | |
139 | - sinonimos[i].cantidad = sinonimos[i].cantidadRestante = articulo.productos[j].cantidad; | |
138 | + if (gruposArticulos[key][i].ID_SIN.toString() === a.idSinonimo.toString()) { | |
139 | + sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | |
140 | 140 | } |
141 | 141 | }); |
142 | 142 | } |
src/app/services/articulo/articulo.service.ts
... | ... | @@ -41,7 +41,6 @@ export class ArticuloService { |
41 | 41 | } |
42 | 42 | |
43 | 43 | addCant(articulo: IArticulo) { |
44 | - if (articulo.cantidad >= articulo.ExiVta) return; | |
45 | 44 | articulo.cantidad++; |
46 | 45 | this.calcularTotal(); |
47 | 46 | } |
... | ... | @@ -56,9 +55,14 @@ export class ArticuloService { |
56 | 55 | setArticulo(articulo: IArticulo) { |
57 | 56 | articulo.cantidad = 1; |
58 | 57 | for (const articuloCarrito of this.carrito) { |
59 | - if (articuloCarrito.id === articulo.id && !articulo.productos) { | |
60 | - articuloCarrito.cantidad++; | |
61 | - this.calcularTotal(); | |
58 | + if (articuloCarrito.id === articulo.id) { | |
59 | + if (!articuloCarrito.productos) break; | |
60 | + let samePromo = false; | |
61 | + articuloCarrito.productos.forEach((a, i) => { | |
62 | + samePromo = (a.id === articulo.productos[i].id); | |
63 | + }); | |
64 | + if (!samePromo) break; | |
65 | + this.addCant(articuloCarrito); | |
62 | 66 | return; |
63 | 67 | } |
64 | 68 | } |
... | ... | @@ -100,6 +104,17 @@ export class ArticuloService { |
100 | 104 | }); |
101 | 105 | } |
102 | 106 | |
107 | + validateCarrito() { | |
108 | + for (const articulo of this.carrito) { | |
109 | + if (articulo.productos) { | |
110 | + for (const a of articulo.productos) { | |
111 | + if (a.ExiVta - (a.cantidad * articulo.cantidad) < 0) return { valid: false, articulo }; | |
112 | + } | |
113 | + } else if (articulo.ExiVta - articulo.cantidad < 0) return { valid: false, articulo }; | |
114 | + } | |
115 | + return { valid: true }; | |
116 | + } | |
117 | + | |
103 | 118 | cleanShoppingCar() { |
104 | 119 | this.articuloAcargar = undefined; |
105 | 120 | this.promoAcargar = undefined; |
src/app/shared/error-stock/error-stock.component.html
... | ... | @@ -0,0 +1,10 @@ |
1 | +<div class="bg-primary text-center rounded"> | |
2 | + <div class="modal-body"> | |
3 | + <p class="h4 text-white text-center mx-3 mb-3">El articulo {{articulo.MKT_DESC}} no tiene stock</p> | |
4 | + <div | |
5 | + class="m-0 h4 d-inline-block py-2 btn-effect bg-white badge-pill" | |
6 | + (click)="modalRef.hide()"> | |
7 | + Aceptar | |
8 | + </div> | |
9 | + </div> | |
10 | +</div> |
src/app/shared/error-stock/error-stock.component.scss
src/app/shared/error-stock/error-stock.component.spec.ts
... | ... | @@ -0,0 +1,25 @@ |
1 | +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
2 | + | |
3 | +import { ErrorStockComponent } from './error-stock.component'; | |
4 | + | |
5 | +describe('ErrorStockComponent', () => { | |
6 | + let component: ErrorStockComponent; | |
7 | + let fixture: ComponentFixture<ErrorStockComponent>; | |
8 | + | |
9 | + beforeEach(async(() => { | |
10 | + TestBed.configureTestingModule({ | |
11 | + declarations: [ ErrorStockComponent ] | |
12 | + }) | |
13 | + .compileComponents(); | |
14 | + })); | |
15 | + | |
16 | + beforeEach(() => { | |
17 | + fixture = TestBed.createComponent(ErrorStockComponent); | |
18 | + component = fixture.componentInstance; | |
19 | + fixture.detectChanges(); | |
20 | + }); | |
21 | + | |
22 | + it('should create', () => { | |
23 | + expect(component).toBeTruthy(); | |
24 | + }); | |
25 | +}); |
src/app/shared/error-stock/error-stock.component.ts
... | ... | @@ -0,0 +1,19 @@ |
1 | +import { Component, OnInit } from '@angular/core'; | |
2 | +import { BsModalRef } from 'ngx-bootstrap/modal'; | |
3 | +import { IArticulo } from 'src/app/interfaces/IArticulo'; | |
4 | + | |
5 | +@Component({ | |
6 | + selector: 'app-error-stock', | |
7 | + templateUrl: './error-stock.component.html', | |
8 | + styleUrls: ['./error-stock.component.scss'] | |
9 | +}) | |
10 | +export class ErrorStockComponent implements OnInit { | |
11 | + articulo: IArticulo; | |
12 | + | |
13 | + constructor( | |
14 | + private modalRef: BsModalRef, | |
15 | + ) { } | |
16 | + | |
17 | + ngOnInit() { } | |
18 | + | |
19 | +} |
src/app/shared/header-publicidad/header-publicidad.component.ts
... | ... | @@ -108,10 +108,10 @@ export class HeaderPublicidadComponent implements OnInit { |
108 | 108 | Object.keys(gruposArticulos).forEach(key => { |
109 | 109 | sinonimos.push({ productos: gruposArticulos[key], }); |
110 | 110 | }); |
111 | - for (let j = 0; j < articulo.productos.length; j++) { | |
111 | + for (const a of articulo.productos) { | |
112 | 112 | Object.keys(gruposArticulos).forEach((key, i) => { |
113 | - if (gruposArticulos[key][i].ID_SIN.toString() === articulo.productos[j].idSinonimo.toString()) { | |
114 | - sinonimos[i].cantidad = sinonimos[i].cantidadRestante = articulo.productos[j].cantidad; | |
113 | + if (gruposArticulos[key][i].ID_SIN.toString() === a.idSinonimo.toString()) { | |
114 | + sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | |
115 | 115 | } |
116 | 116 | }); |
117 | 117 | } |
src/app/shared/promocion/promocion.component.ts
... | ... | @@ -54,14 +54,13 @@ export class PromocionComponent implements OnInit { |
54 | 54 | Object.keys(gruposArticulos).forEach(key => { |
55 | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
56 | 56 | }); |
57 | - for (let j = 0; j < promo.productos.length; j++) { | |
57 | + for (const promoProducto of promo.productos) { | |
58 | 58 | Object.keys(gruposArticulos).forEach((key, i) => { |
59 | - if (gruposArticulos[key][i].ID_SIN.toString() === promo.productos[j].idSinonimo.toString()) { | |
60 | - sinonimos[i].cantidad = sinonimos[i].cantidadRestante = promo.productos[j].cantidad; | |
59 | + if (gruposArticulos[key][i].ID_SIN.toString() === promoProducto.idSinonimo.toString()) { | |
60 | + sinonimos[i].cantidad = sinonimos[i].cantidadRestante = promoProducto.cantidad; | |
61 | 61 | } |
62 | 62 | }); |
63 | 63 | } |
64 | - res = sinonimos; | |
65 | 64 | this.openModalSinonimos(res, promo); |
66 | 65 | } else { |
67 | 66 | promo.cantidad = 1; |