Commit 4bdc05ab710e98c40ba626452b2a201829467686
1 parent
0de2d23fd5
Exists in
develop
Fix
Cantidad restante
Showing
2 changed files
with
6 additions
and
2 deletions
Show diff stats
src/app/shared/header-publicidad/header-publicidad.component.ts
| 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; | 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; |
| 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; | 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; |
| 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; | 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; |
| 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 6 | import { PromocionComponent } from '../promocion/promocion.component'; | 6 | import { PromocionComponent } from '../promocion/promocion.component'; |
| 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; |
| 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; | 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; |
| 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
| 13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
| 14 | 14 | ||
| 15 | @Component({ | 15 | @Component({ |
| 16 | selector: 'app-header-publicidad', | 16 | selector: 'app-header-publicidad', |
| 17 | templateUrl: './header-publicidad.component.html', | 17 | templateUrl: './header-publicidad.component.html', |
| 18 | styleUrls: ['./header-publicidad.component.scss'] | 18 | styleUrls: ['./header-publicidad.component.scss'] |
| 19 | }) | 19 | }) |
| 20 | export class HeaderPublicidadComponent implements OnInit { | 20 | export class HeaderPublicidadComponent implements OnInit { |
| 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
| 22 | publicidades: IPublicidad[] = []; | 22 | publicidades: IPublicidad[] = []; |
| 23 | modalRef: BsModalRef; | 23 | modalRef: BsModalRef; |
| 24 | modalSinonimo: BsModalRef; | 24 | modalSinonimo: BsModalRef; |
| 25 | 25 | ||
| 26 | constructor( | 26 | constructor( |
| 27 | private publicidadService: PublicidadService, | 27 | private publicidadService: PublicidadService, |
| 28 | private articuloService: ArticuloService, | 28 | private articuloService: ArticuloService, |
| 29 | private modalService: BsModalService, | 29 | private modalService: BsModalService, |
| 30 | private sinonimoService: SinonimoService | 30 | private sinonimoService: SinonimoService |
| 31 | ) { } | 31 | ) { } |
| 32 | 32 | ||
| 33 | ngOnInit() { | 33 | ngOnInit() { |
| 34 | this.getPublicidades(); | 34 | this.getPublicidades(); |
| 35 | this.mediaPantalla(); | 35 | this.mediaPantalla(); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | getPublicidades() { | 38 | getPublicidades() { |
| 39 | this.publicidadService.getAll() | 39 | this.publicidadService.getAll() |
| 40 | .subscribe((res: IPublicidad[]) => { | 40 | .subscribe((res: IPublicidad[]) => { |
| 41 | this.publicidades = res; | 41 | this.publicidades = res; |
| 42 | }, err => console.error(err)); | 42 | }, err => console.error(err)); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | elegirArticulo(publicidad: IPublicidad) { | 45 | elegirArticulo(publicidad: IPublicidad) { |
| 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | getByID(id: number) { | 49 | getByID(id: number) { |
| 50 | this.articuloService.getById(id) | 50 | this.articuloService.getById(id) |
| 51 | .subscribe((res: IArticulo) => { | 51 | .subscribe((res: IArticulo) => { |
| 52 | if (res.FPP) { | 52 | if (res.FPP) { |
| 53 | this.openModalPromos(res); | 53 | this.openModalPromos(res); |
| 54 | return; | 54 | return; |
| 55 | } else { | 55 | } else { |
| 56 | this.openModalConfirmacion(res); | 56 | this.openModalConfirmacion(res); |
| 57 | return; | 57 | return; |
| 58 | } | 58 | } |
| 59 | }, err => console.error(err)); | 59 | }, err => console.error(err)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | openModalPromos(articulo: IArticulo) { | 62 | openModalPromos(articulo: IArticulo) { |
| 63 | if (this.modalRef) return; | 63 | if (this.modalRef) return; |
| 64 | this.modalRef = this.modalService.show(PromocionComponent, | 64 | this.modalRef = this.modalService.show(PromocionComponent, |
| 65 | { | 65 | { |
| 66 | initialState: { | 66 | initialState: { |
| 67 | idArticulo: articulo.id | 67 | idArticulo: articulo.id |
| 68 | }, | 68 | }, |
| 69 | class: 'modal-dialog-centered' | 69 | class: 'modal-dialog-centered' |
| 70 | }); | 70 | }); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | openModalConfirmacion(articulo: IArticulo) { | 73 | openModalConfirmacion(articulo: IArticulo) { |
| 74 | if (this.modalRef) return; | 74 | if (this.modalRef) return; |
| 75 | this.articuloService.setArticulosSinImagen([articulo]); | 75 | this.articuloService.setArticulosSinImagen([articulo]); |
| 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, |
| 77 | { | 77 | { |
| 78 | initialState: { | 78 | initialState: { |
| 79 | titleMessage: articulo.DET_LAR, | 79 | titleMessage: articulo.DET_LAR, |
| 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', |
| 81 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, | 81 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, |
| 82 | footerMessageSecond: `a tu carrito?`, | 82 | footerMessageSecond: `a tu carrito?`, |
| 83 | footerConfirmation: articulo.PreVen | 83 | footerConfirmation: articulo.PreVen |
| 84 | }, | 84 | }, |
| 85 | ignoreBackdropClick: true, | 85 | ignoreBackdropClick: true, |
| 86 | class: 'modal-dialog-centered' | 86 | class: 'modal-dialog-centered' |
| 87 | }); | 87 | }); |
| 88 | this.modalRef.content.onClose.subscribe((resClose) => { | 88 | this.modalRef.content.onClose.subscribe((resClose) => { |
| 89 | this.modalRef = null; | 89 | this.modalRef = null; |
| 90 | if (!resClose) return; | 90 | if (!resClose) return; |
| 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 92 | .subscribe((res: ISinonimo[]) => { | 92 | .subscribe((res: ISinonimo[]) => { |
| 93 | if (res.length) { | 93 | if (res.length) { |
| 94 | const sinonimos = []; | 94 | const sinonimos = []; |
| 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 96 | Object.keys(gruposArticulos).forEach(key => { | 96 | Object.keys(gruposArticulos).forEach((key, i) => { |
| 97 | sinonimos.push({ productos: gruposArticulos[key] }); | 97 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 98 | sinonimos[i].cantidad = articulo.productos[i].cantidad; | ||
| 99 | sinonimos[i].cantidadRestante = articulo.productos[i].cantidad; | ||
| 98 | }); | 100 | }); |
| 99 | res = sinonimos; | 101 | res = sinonimos; |
| 100 | this.openModalSinonimos(res, articulo); | 102 | this.openModalSinonimos(res, articulo); |
| 101 | } else { | 103 | } else { |
| 102 | articulo.cantidad = 1; | 104 | articulo.cantidad = 1; |
| 103 | this.articuloService.setArticulo(articulo); | 105 | this.articuloService.setArticulo(articulo); |
| 104 | } | 106 | } |
| 105 | }, err => console.error(err)); | 107 | }, err => console.error(err)); |
| 106 | }); | 108 | }); |
| 107 | this.mediaPantalla(); | 109 | this.mediaPantalla(); |
| 108 | } | 110 | } |
| 109 | 111 | ||
| 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 112 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 111 | if (this.modalSinonimo) return; | 113 | if (this.modalSinonimo) return; |
| 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 114 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 113 | initialState: { | 115 | initialState: { |
| 114 | sinonimos: sinonimosData, | 116 | sinonimos: sinonimosData, |
| 115 | articulo | 117 | articulo |
| 116 | }, | 118 | }, |
| 117 | class: 'modal-dialog-centered' | 119 | class: 'modal-dialog-centered' |
| 118 | }); | 120 | }); |
| 119 | this.modalSinonimo.content.onClose | 121 | this.modalSinonimo.content.onClose |
| 120 | .subscribe((res: any) => { | 122 | .subscribe((res: any) => { |
| 121 | this.modalSinonimo = null; | 123 | this.modalSinonimo = null; |
| 122 | if (!res) return; | 124 | if (!res) return; |
| 123 | articulo.productos = res.articulos; | 125 | articulo.productos = res.articulos; |
| 124 | this.articuloService.setArticulo(articulo); | 126 | this.articuloService.setArticulo(articulo); |
| 125 | }); | 127 | }); |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | mediaPantalla() { | 130 | mediaPantalla() { |
| 129 | if ($('body').hasClass('media-pantalla')) { | 131 | if ($('body').hasClass('media-pantalla')) { |
| 130 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 132 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
| 131 | } | 133 | } |
| 132 | } | 134 | } |
| 133 | } | 135 | } |
| 134 | 136 |
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 => { | 54 | Object.keys(gruposArticulos).forEach((key, i) => { |
| 55 | sinonimos.push({ productos: gruposArticulos[key] }); | 55 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 56 | sinonimos[i].cantidad = promo.productos[i].cantidad; | ||
| 57 | sinonimos[i].cantidadRestante = promo.productos[i].cantidad; | ||
| 56 | }); | 58 | }); |
| 57 | res = sinonimos; | 59 | res = sinonimos; |
| 58 | this.openModalSinonimos(res, promo); | 60 | this.openModalSinonimos(res, promo); |
| 59 | } else { | 61 | } else { |
| 60 | promo.cantidad = 1; | 62 | promo.cantidad = 1; |
| 61 | this.articuloService.setArticulo(promo); | 63 | this.articuloService.setArticulo(promo); |
| 62 | this.onClose.next(); | 64 | this.onClose.next(); |
| 63 | this.modalPromocion.hide(); | 65 | this.modalPromocion.hide(); |
| 64 | } | 66 | } |
| 65 | }, err => console.error(err)); | 67 | }, err => console.error(err)); |
| 66 | }, err => console.error(err)); | 68 | }, err => console.error(err)); |
| 67 | this.mediaPantalla(); | 69 | this.mediaPantalla(); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 72 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 71 | if (this.modalSinonimo) return; | 73 | if (this.modalSinonimo) return; |
| 72 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 74 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 73 | initialState: { | 75 | initialState: { |
| 74 | sinonimos: sinonimosData, | 76 | sinonimos: sinonimosData, |
| 75 | articulo | 77 | articulo |
| 76 | }, | 78 | }, |
| 77 | class: 'modal-dialog-centered', | 79 | class: 'modal-dialog-centered', |
| 78 | ignoreBackdropClick: true, | 80 | ignoreBackdropClick: true, |
| 79 | }); | 81 | }); |
| 80 | 82 | ||
| 81 | this.modalSinonimo.content.onClose | 83 | this.modalSinonimo.content.onClose |
| 82 | .subscribe((res: any) => { | 84 | .subscribe((res: any) => { |
| 83 | this.modalSinonimo = null; | 85 | this.modalSinonimo = null; |
| 84 | if (!res) { | 86 | if (!res) { |
| 85 | this.onClose.next(); | 87 | this.onClose.next(); |
| 86 | this.modalPromocion.hide(); | 88 | this.modalPromocion.hide(); |
| 87 | return; | 89 | return; |
| 88 | } | 90 | } |
| 89 | articulo.productos = res.articulos; | 91 | articulo.productos = res.articulos; |
| 90 | this.articuloService.setArticulo(articulo); | 92 | this.articuloService.setArticulo(articulo); |
| 91 | this.onClose.next(); | 93 | this.onClose.next(); |
| 92 | this.modalPromocion.hide(); | 94 | this.modalPromocion.hide(); |
| 93 | }); | 95 | }); |
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | getPromociones() { | 98 | getPromociones() { |
| 97 | const sector = this.articulosPromo[0].CodSec; | 99 | const sector = this.articulosPromo[0].CodSec; |
| 98 | const codigo = this.articulosPromo[0].CodArt; | 100 | const codigo = this.articulosPromo[0].CodArt; |
| 99 | this.promocionService.getPromociones(sector, codigo) | 101 | this.promocionService.getPromociones(sector, codigo) |
| 100 | .subscribe((res: IArticulo[]) => { | 102 | .subscribe((res: IArticulo[]) => { |
| 101 | this.promociones = res; | 103 | this.promociones = res; |
| 102 | this.loading = false; | 104 | this.loading = false; |
| 103 | }, error => { console.error(error); }); | 105 | }, error => { console.error(error); }); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | @HostListener('document:click', ['$event']) | 108 | @HostListener('document:click', ['$event']) |
| 107 | eventListener(event: Event) { | 109 | eventListener(event: Event) { |
| 108 | clearTimeout(this.inactiveScreen.timerReposo); | 110 | clearTimeout(this.inactiveScreen.timerReposo); |
| 109 | this.inactiveScreen.startTimeOutInactividad(); | 111 | this.inactiveScreen.startTimeOutInactividad(); |
| 110 | } | 112 | } |
| 111 | 113 | ||
| 112 | @HostListener('scroll', ['$event']) | 114 | @HostListener('scroll', ['$event']) |
| 113 | scrollEvent(event: Event) { | 115 | scrollEvent(event: Event) { |
| 114 | clearTimeout(this.inactiveScreen.timerReposo); | 116 | clearTimeout(this.inactiveScreen.timerReposo); |
| 115 | this.inactiveScreen.startTimeOutInactividad(); | 117 | this.inactiveScreen.startTimeOutInactividad(); |
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | mediaPantalla() { | 120 | mediaPantalla() { |
| 119 | if ($('body').hasClass('media-pantalla')) { | 121 | if ($('body').hasClass('media-pantalla')) { |
| 120 | $('.modal-content').addClass('media-pantalla'); | 122 | $('.modal-content').addClass('media-pantalla'); |
| 121 | } | 123 | } |
| 122 | } | 124 | } |
| 123 | } | 125 | } |
| 124 | 126 |