Commit 6273a021e2401e13f3e363394eaa1c17034f9531
1 parent
039ca2889b
Exists in
develop
Add
Validacion al elegir articulo y sugerir promo que no tiene stock
Showing
2 changed files
with
13 additions
and
2 deletions
Show diff stats
src/app/shared/promocion/promocion.component.html
1 | <div class="bg-primary rounded"> | 1 | <div class="bg-primary rounded"> |
2 | <div class="modal-header" *ngIf="articulosPromo.length"> | 2 | <div class="modal-header" *ngIf="articulosPromo.length"> |
3 | <img | 3 | <img |
4 | draggable="false" | 4 | draggable="false" |
5 | ondragstart="return false;" | 5 | ondragstart="return false;" |
6 | (contextmenu)="false" | 6 | (contextmenu)="false" |
7 | (click)="selectPromo(articulosPromo[0])" | 7 | (click)="selectPromo(articulosPromo[0])" |
8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" | 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" |
9 | src="assets/img/icono-cancelar-blanco.svg"> | 9 | src="assets/img/icono-cancelar-blanco.svg"> |
10 | <div class="row w-100 no-gutters justify-content-between"> | 10 | <div class="row w-100 no-gutters justify-content-between"> |
11 | <div class="col align-self-center"> | 11 | <div class="col align-self-center"> |
12 | <p class="h3 text-white">{{articulosPromo[0].MKT_DESC ? articulosPromo[0].MKT_DESC.toUpperCase() : articulosPromo[0].DetArt.toUpperCase()}}</p> | 12 | <p class="h3 text-white">{{articulosPromo[0].MKT_DESC ? articulosPromo[0].MKT_DESC.toUpperCase() : articulosPromo[0].DetArt.toUpperCase()}}</p> |
13 | </div> | 13 | </div> |
14 | <div class="col-auto align-self-center mt-4 pl-2"> | 14 | <div class="col-auto align-self-center mt-4 pl-2"> |
15 | <div | 15 | <div |
16 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" | 16 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" |
17 | (click)="selectPromo(articulosPromo[0])"> | 17 | (click)="selectPromo(articulosPromo[0])"> |
18 | <div class="col-auto align-self-center text-primary"> | 18 | <div class="col-auto align-self-center text-primary"> |
19 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> | 19 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> |
20 | </div> | 20 | </div> |
21 | <div class="col-auto px-0"> | 21 | <div class="col-auto px-0"> |
22 | <img | 22 | <img |
23 | draggable="false" | 23 | draggable="false" |
24 | ondragstart="return false;" | 24 | ondragstart="return false;" |
25 | (contextmenu)="false" | 25 | (contextmenu)="false" |
26 | class="d-block ml-auto my-1 icon-20" | 26 | class="d-block ml-auto my-1 icon-20" |
27 | src="assets/img/ir-color.svg"> | 27 | src="assets/img/ir-color.svg"> |
28 | </div> | 28 | </div> |
29 | </div> | 29 | </div> |
30 | </div> | 30 | </div> |
31 | </div> | 31 | </div> |
32 | </div> | 32 | </div> |
33 | <div class="modal-body" *ngIf="articulosPromo.length"> | 33 | <div class="modal-body" *ngIf="articulosPromo.length"> |
34 | <div class="row no-gutters w-100"> | 34 | <div |
35 | class="row no-gutters w-100" | ||
36 | *ngIf="promociones.length && !loading"> | ||
35 | <div class="col-9 col-9 align-self-center"> | 37 | <div class="col-9 col-9 align-self-center"> |
36 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> | 38 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> |
37 | <p class="h1 text-white">en un combo?</p> | 39 | <p class="h1 text-white">en un combo?</p> |
38 | </div> | 40 | </div> |
39 | <div class="col-3"> | 41 | <div class="col-3"> |
40 | <img | 42 | <img |
41 | draggable="false" | 43 | draggable="false" |
42 | ondragstart="return false;" | 44 | ondragstart="return false;" |
43 | (contextmenu)="false" | 45 | (contextmenu)="false" |
44 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" | 46 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" |
45 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" | 47 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" |
46 | class="card-img-top img-fluid rounded-circle"> | 48 | class="card-img-top img-fluid rounded-circle"> |
47 | </div> | 49 | </div> |
48 | </div> | 50 | </div> |
51 | <div> | ||
52 | <div | ||
53 | class="row no-gutters w-100" | ||
54 | *ngIf="!promociones.length && !loading"> | ||
55 | <div class="col-12 text-center"> | ||
56 | <p class="text-white"><small>NO HAY PROMOS CON STOCK</small></p> | ||
57 | </div> | ||
58 | </div> | ||
49 | <div | 59 | <div |
50 | class="d-flex justify-content-center mt-2" | 60 | class="d-flex justify-content-center mt-2" |
51 | *ngIf="loading"> | 61 | *ngIf="loading"> |
52 | <div class="spinner-border text-white" role="status"> | 62 | <div class="spinner-border text-white" role="status"> |
53 | <span class="sr-only">Loading...</span> | 63 | <span class="sr-only">Loading...</span> |
54 | </div> | 64 | </div> |
55 | </div> | 65 | </div> |
56 | <div | 66 | <div |
57 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" | 67 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" |
58 | (scroll)="scrollEvent($event)"> | 68 | (scroll)="scrollEvent($event)"> |
59 | <div class="col-12"> | 69 | <div class="col-12"> |
60 | <div *ngFor="let promo of promociones; let i = index"> | 70 | <div *ngFor="let promo of promociones; let i = index"> |
61 | <div | 71 | <div |
62 | [ngClass]="{ 'mt-2': i !== 0 }" | 72 | [ngClass]="{ 'mt-2': i !== 0 }" |
63 | class="btn-effect bg-white badge-pill text-primary" | 73 | class="btn-effect bg-white badge-pill text-primary" |
64 | (click)="selectPromo(promo)"> | 74 | (click)="selectPromo(promo)"> |
65 | <div class="d-flex"> | 75 | <div class="d-flex"> |
66 | <p class="text-truncate mr-auto my-auto"><small>{{promo.MKT_DESC ? promo.MKT_DESC.toUpperCase() : promo.DetArt.toUpperCase()}}</small></p> | 76 | <p class="text-truncate mr-auto my-auto"><small>{{promo.MKT_DESC ? promo.MKT_DESC.toUpperCase() : promo.DetArt.toUpperCase()}}</small></p> |
67 | <p class="font-weight-bold ml-auto my-auto pr-2"> | 77 | <p class="font-weight-bold ml-auto my-auto pr-2"> |
68 | <span>{{promo.PreVen | currency}}</span> | 78 | <span>{{promo.PreVen | currency}}</span> |
69 | </p> | 79 | </p> |
70 | <img | 80 | <img |
71 | draggable="false" | 81 | draggable="false" |
72 | ondragstart="return false;" | 82 | ondragstart="return false;" |
73 | (contextmenu)="false" | 83 | (contextmenu)="false" |
74 | class="d-block py-1 icon-30" | 84 | class="d-block py-1 icon-30" |
75 | src="assets/img/ir-color.svg"> | 85 | src="assets/img/ir-color.svg"> |
76 | </div> | 86 | </div> |
77 | </div> | 87 | </div> |
78 | </div> | 88 | </div> |
79 | </div> | 89 | </div> |
80 | </div> | 90 | </div> |
81 | </div> | 91 | </div> |
82 | </div> | 92 | </div> |
83 | 93 |
src/app/shared/promocion/promocion.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; | 5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; |
6 | import { Subject } from 'rxjs'; | 6 | import { Subject } from 'rxjs'; |
7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
12 | import * as _ from 'lodash'; | 12 | import * as _ from 'lodash'; |
13 | 13 | ||
14 | @Component({ | 14 | @Component({ |
15 | selector: 'app-promocion', | 15 | selector: 'app-promocion', |
16 | templateUrl: './promocion.component.html', | 16 | templateUrl: './promocion.component.html', |
17 | styleUrls: ['./promocion.component.scss'] | 17 | styleUrls: ['./promocion.component.scss'] |
18 | }) | 18 | }) |
19 | export class PromocionComponent implements OnInit { | 19 | export class PromocionComponent implements OnInit { |
20 | articulosPromo: IArticulo[] = []; | 20 | articulosPromo: IArticulo[] = []; |
21 | promociones: IArticulo[] = []; | 21 | promociones: IArticulo[] = []; |
22 | onClose: Subject<any>; | 22 | onClose: Subject<any>; |
23 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 23 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
24 | loading = true; | 24 | loading = true; |
25 | modalSinonimo: BsModalRef; | 25 | modalSinonimo: BsModalRef; |
26 | isPromoSelected = false; | 26 | isPromoSelected = false; |
27 | 27 | ||
28 | constructor( | 28 | constructor( |
29 | private modalPromocion: BsModalRef, | 29 | private modalPromocion: BsModalRef, |
30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
31 | private articuloService: ArticuloService, | 31 | private articuloService: ArticuloService, |
32 | private promocionService: PromocionService, | 32 | private promocionService: PromocionService, |
33 | private sinonimoService: SinonimoService, | 33 | private sinonimoService: SinonimoService, |
34 | private inactiveScreen: InactiveScreenService, | 34 | private inactiveScreen: InactiveScreenService, |
35 | ) { | 35 | ) { |
36 | this.onClose = new Subject(); | 36 | this.onClose = new Subject(); |
37 | } | 37 | } |
38 | 38 | ||
39 | ngOnInit() { | 39 | ngOnInit() { |
40 | this.getPromociones(); | 40 | this.getPromociones(); |
41 | } | 41 | } |
42 | 42 | ||
43 | selectPromo(promo: IArticulo) { | 43 | selectPromo(promo: IArticulo) { |
44 | if (this.isPromoSelected) return; | 44 | if (this.isPromoSelected) return; |
45 | this.isPromoSelected = true; | 45 | this.isPromoSelected = true; |
46 | this.articuloService.getById(promo.id) | 46 | this.articuloService.getById(promo.id) |
47 | .subscribe((resPromo: IArticulo) => { | 47 | .subscribe((resPromo: IArticulo) => { |
48 | promo = resPromo; | 48 | promo = resPromo; |
49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
50 | .subscribe((res: ISinonimo[]) => { | 50 | .subscribe((res: ISinonimo[]) => { |
51 | if (res.length) { | 51 | if (res.length) { |
52 | const sinonimos = []; | 52 | const sinonimos = []; |
53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
54 | Object.keys(gruposArticulos).forEach((key, i) => { | 54 | Object.keys(gruposArticulos).forEach((key, i) => { |
55 | sinonimos.push({ productos: gruposArticulos[key], }); | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
56 | for (const a of promo.productos) { | 56 | for (const a of promo.productos) { |
57 | if (key === a.idSinonimo.toString()) { | 57 | if (key === a.idSinonimo.toString()) { |
58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | 58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; |
59 | continue; | 59 | continue; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | }); | 62 | }); |
63 | res = sinonimos; | 63 | res = sinonimos; |
64 | this.openModalSinonimos(res, promo); | 64 | this.openModalSinonimos(res, promo); |
65 | } else { | 65 | } else { |
66 | promo.cantidad = 1; | 66 | promo.cantidad = 1; |
67 | this.articuloService.setArticulo(promo); | 67 | this.articuloService.setArticulo(promo); |
68 | this.onClose.next(); | 68 | this.onClose.next(); |
69 | this.modalPromocion.hide(); | 69 | this.modalPromocion.hide(); |
70 | } | 70 | } |
71 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
72 | }, err => console.error(err)); | 72 | }, err => console.error(err)); |
73 | this.mediaPantalla(); | 73 | this.mediaPantalla(); |
74 | } | 74 | } |
75 | 75 | ||
76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
77 | if (this.modalSinonimo) return; | 77 | if (this.modalSinonimo) return; |
78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
79 | initialState: { | 79 | initialState: { |
80 | sinonimos: sinonimosData, | 80 | sinonimos: sinonimosData, |
81 | articulo | 81 | articulo |
82 | }, | 82 | }, |
83 | class: 'modal-dialog-centered', | 83 | class: 'modal-dialog-centered', |
84 | ignoreBackdropClick: true, | 84 | ignoreBackdropClick: true, |
85 | }); | 85 | }); |
86 | 86 | ||
87 | this.modalSinonimo.content.onClose | 87 | this.modalSinonimo.content.onClose |
88 | .subscribe((res: any) => { | 88 | .subscribe((res: any) => { |
89 | this.modalSinonimo = null; | 89 | this.modalSinonimo = null; |
90 | if (!res) { | 90 | if (!res) { |
91 | this.onClose.next(); | 91 | this.onClose.next(); |
92 | this.modalPromocion.hide(); | 92 | this.modalPromocion.hide(); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | articulo.productos = res.articulos; | 95 | articulo.productos = res.articulos; |
96 | this.articuloService.setArticulo(articulo); | 96 | this.articuloService.setArticulo(articulo); |
97 | this.onClose.next(); | 97 | this.onClose.next(); |
98 | this.modalPromocion.hide(); | 98 | this.modalPromocion.hide(); |
99 | }); | 99 | }); |
100 | } | 100 | } |
101 | 101 | ||
102 | getPromociones() { | 102 | getPromociones() { |
103 | const sector = this.articulosPromo[0].CodSec; | 103 | const sector = this.articulosPromo[0].CodSec; |
104 | const codigo = this.articulosPromo[0].CodArt; | 104 | const codigo = this.articulosPromo[0].CodArt; |
105 | this.promocionService.getPromociones(sector, codigo) | 105 | this.promocionService.getPromociones(sector, codigo) |
106 | .subscribe((res: IArticulo[]) => { | 106 | .subscribe((res: IArticulo[]) => { |
107 | this.promociones = res; | 107 | res = res.filter(a => a.ExiVta > 0); |
108 | this.loading = false; | 108 | this.loading = false; |
109 | this.promociones = res; | ||
109 | }, error => { console.error(error); }); | 110 | }, error => { console.error(error); }); |
110 | } | 111 | } |
111 | 112 | ||
112 | @HostListener('document:click', ['$event']) | 113 | @HostListener('document:click', ['$event']) |
113 | eventListener(event: Event) { | 114 | eventListener(event: Event) { |
114 | clearTimeout(this.inactiveScreen.timerReposo); | 115 | clearTimeout(this.inactiveScreen.timerReposo); |
115 | this.inactiveScreen.startTimeOutInactividad(); | 116 | this.inactiveScreen.startTimeOutInactividad(); |
116 | } | 117 | } |
117 | 118 | ||
118 | @HostListener('scroll', ['$event']) | 119 | @HostListener('scroll', ['$event']) |
119 | scrollEvent(event: Event) { | 120 | scrollEvent(event: Event) { |
120 | clearTimeout(this.inactiveScreen.timerReposo); | 121 | clearTimeout(this.inactiveScreen.timerReposo); |
121 | this.inactiveScreen.startTimeOutInactividad(); | 122 | this.inactiveScreen.startTimeOutInactividad(); |
122 | } | 123 | } |
123 | 124 | ||
124 | mediaPantalla() { | 125 | mediaPantalla() { |
125 | if ($('body').hasClass('media-pantalla')) { | 126 | if ($('body').hasClass('media-pantalla')) { |
126 | $('.modal-content').addClass('media-pantalla'); | 127 | $('.modal-content').addClass('media-pantalla'); |
127 | } | 128 | } |
128 | } | 129 | } |
129 | } | 130 | } |
130 | 131 |