Commit 8cf19703ca19ffbd33a76bb670155631003fe9ef
1 parent
4918233aae
Exists in
develop
Fix
Orden en que se muestran los sinonimos
Showing
4 changed files
with
28 additions
and
24 deletions
Show diff stats
src/app/interfaces/IArticulo.ts
| 1 | export interface IArticulo { | 1 | export interface IArticulo { |
| 2 | cantidad?: number; | 2 | cantidad?: number; |
| 3 | cantidadAdicionada?: number; | 3 | cantidadAdicionada?: number; |
| 4 | cantidadVendida?: number; | 4 | cantidadVendida?: number; |
| 5 | categoria_selfservice?: number; | 5 | categoria_selfservice?: number; |
| 6 | CodArt: number; | 6 | CodArt: number; |
| 7 | codigoBarra?: ICodigoBarra[]; | 7 | codigoBarra?: ICodigoBarra[]; |
| 8 | CodSec: number; | 8 | CodSec: number; |
| 9 | DetArt: string; | 9 | DetArt: string; |
| 10 | DET_LAR: string; | 10 | DET_LAR: string; |
| 11 | ELBPRO: string; | 11 | ELBPRO: string; |
| 12 | esAdicionable?: boolean; | 12 | esAdicionable?: boolean; |
| 13 | esSustraible?: boolean; | 13 | esSustraible?: boolean; |
| 14 | FPP?: boolean; | 14 | FPP?: boolean; |
| 15 | id: number; | 15 | id: number; |
| 16 | idSinonimo?: number; | 16 | idSinonimo?: number; |
| 17 | ID_SIN?: number; | 17 | ID_SIN?: number; |
| 18 | imagenes?: any[]; | 18 | imagenes?: any[]; |
| 19 | ImpInt: number; | 19 | ImpInt: number; |
| 20 | ImpInt2: number; | 20 | ImpInt2: number; |
| 21 | ImpInt3: number; | 21 | ImpInt3: number; |
| 22 | importeValorExtra?: number; | 22 | importeValorExtra?: number; |
| 23 | PreVen: number; | 23 | PreVen: number; |
| 24 | PRO: boolean; | 24 | PRO: boolean; |
| 25 | productos?: IArticulo[]; | 25 | productos?: IArticulo[]; |
| 26 | seleccionado?: boolean; | 26 | seleccionado?: boolean; |
| 27 | tieneSinonimo?: boolean; | 27 | tieneSinonimo?: boolean; |
| 28 | tipo_articulo?: number; | 28 | tipo_articulo?: number; |
| 29 | CODA?: number; | 29 | CODA?: number; |
| 30 | CODP?: number; | 30 | CODP?: number; |
| 31 | SECA?: number; | 31 | SECA?: number; |
| 32 | SECP?: number; | 32 | SECP?: number; |
| 33 | MKT_DESC?: string; | 33 | MKT_DESC?: string; |
| 34 | NHA?: boolean; | 34 | NHA?: boolean; |
| 35 | FECHA_VIGENCIA_HASTA?: Date; | 35 | FECHA_VIGENCIA_HASTA?: Date; |
| 36 | FECHA_VIGENCIA_DESDE?: Date; | 36 | FECHA_VIGENCIA_DESDE?: Date; |
| 37 | ExiVta?: number; | 37 | ExiVta?: number; |
| 38 | ORDEN_P? : number; | ||
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | export interface ICodigoBarra { | 41 | export interface ICodigoBarra { |
| 41 | CodBar: string; | 42 | CodBar: string; |
| 42 | CodArt: number; | 43 | CodArt: number; |
| 43 | CodSec: string; | 44 | CodSec: string; |
| 44 | } | 45 | } |
| 45 | 46 |
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
| 1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } from '@angular/core'; |
| 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
| 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 4 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 4 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 6 | import { ICategoria } from 'src/app/interfaces/ICategoria'; | 6 | import { ICategoria } from 'src/app/interfaces/ICategoria'; |
| 7 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 7 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 8 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; | 8 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; |
| 9 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 9 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
| 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; |
| 12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; | 12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; |
| 13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
| 14 | import { ANIMATIONS } from 'src/app/utils/animations'; | 14 | import { ANIMATIONS } from 'src/app/utils/animations'; |
| 15 | import { NoStockComponent } from './no-stock/no-stock.component'; | 15 | import { NoStockComponent } from './no-stock/no-stock.component'; |
| 16 | import { DateExtension } from 'src/app/utils/dateExtension'; | 16 | import { DateExtension } from 'src/app/utils/dateExtension'; |
| 17 | 17 | ||
| 18 | @Component({ | 18 | @Component({ |
| 19 | selector: 'app-seleccion-articulos', | 19 | selector: 'app-seleccion-articulos', |
| 20 | templateUrl: './seleccion-articulos.component.html', | 20 | templateUrl: './seleccion-articulos.component.html', |
| 21 | styleUrls: ['./seleccion-articulos.component.scss'], | 21 | styleUrls: ['./seleccion-articulos.component.scss'], |
| 22 | animations: [ANIMATIONS.EnterLeaveY] | 22 | animations: [ANIMATIONS.EnterLeaveY] |
| 23 | }) | 23 | }) |
| 24 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { | 24 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { |
| 25 | loading = true; | 25 | loading = true; |
| 26 | timeoutHandler: any; | 26 | timeoutHandler: any; |
| 27 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 27 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
| 28 | articulos: IArticulo[] = []; | 28 | articulos: IArticulo[] = []; |
| 29 | auxArticulos: IArticulo[] = []; | 29 | auxArticulos: IArticulo[] = []; |
| 30 | showQuantity = 100; | 30 | showQuantity = 100; |
| 31 | searchTerm = ''; | 31 | searchTerm = ''; |
| 32 | ordenandoByVendidos = true; | 32 | ordenandoByVendidos = true; |
| 33 | modalRef: BsModalRef; | 33 | modalRef: BsModalRef; |
| 34 | total = 0; | 34 | total = 0; |
| 35 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; | 35 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; |
| 36 | 36 | ||
| 37 | constructor( | 37 | constructor( |
| 38 | public articuloService: ArticuloService, | 38 | public articuloService: ArticuloService, |
| 39 | private sinonimoService: SinonimoService, | 39 | private sinonimoService: SinonimoService, |
| 40 | private modalService: BsModalService, | 40 | private modalService: BsModalService, |
| 41 | private inactiveScreen: InactiveScreenService, | 41 | private inactiveScreen: InactiveScreenService, |
| 42 | ) { } | 42 | ) { } |
| 43 | 43 | ||
| 44 | ngOnInit() { } | 44 | ngOnInit() { } |
| 45 | 45 | ||
| 46 | ngAfterViewInit(): void { | 46 | ngAfterViewInit(): void { |
| 47 | this.filtroCategorias.getCategorias(); | 47 | this.filtroCategorias.getCategorias(); |
| 48 | this.mediaPantalla(); | 48 | this.mediaPantalla(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | ngOnDestroy() { | 51 | ngOnDestroy() { |
| 52 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 52 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { |
| 53 | this.modalService.hide(i); | 53 | this.modalService.hide(i); |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | getProductos() { | 57 | getProductos() { |
| 58 | this.articuloService.getAll() | 58 | this.articuloService.getAll() |
| 59 | .subscribe((result: IArticulo[]) => { | 59 | .subscribe((result: IArticulo[]) => { |
| 60 | this.articuloService.setArticulosSinImagen(result); | 60 | this.articuloService.setArticulosSinImagen(result); |
| 61 | if (this.filtroCategorias.queMostrar === 'ordenar') { | 61 | if (this.filtroCategorias.queMostrar === 'ordenar') { |
| 62 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { | 62 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { |
| 63 | const tempArticulos = result.filter((articulo: IArticulo) => { | 63 | const tempArticulos = result.filter((articulo: IArticulo) => { |
| 64 | return articulo.categoria_selfservice === categoria.id; | 64 | return articulo.categoria_selfservice === categoria.id; |
| 65 | }); | 65 | }); |
| 66 | result = tempArticulos; | 66 | result = tempArticulos; |
| 67 | }); | 67 | }); |
| 68 | } | 68 | } |
| 69 | localStorage.setItem('articulos', JSON.stringify(result)); | 69 | localStorage.setItem('articulos', JSON.stringify(result)); |
| 70 | this.setProductos(); | 70 | this.setProductos(); |
| 71 | }, (error) => { | 71 | }, (error) => { |
| 72 | console.error(error); | 72 | console.error(error); |
| 73 | }); | 73 | }); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | setProductos() { | 76 | setProductos() { |
| 77 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 77 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
| 78 | this.filterItems(); | 78 | this.filterItems(); |
| 79 | this.loading = false; | 79 | this.loading = false; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | filterItems() { | 82 | filterItems() { |
| 83 | if (this.filtroCategorias.categoriaActive === 0) { | 83 | if (this.filtroCategorias.categoriaActive === 0) { |
| 84 | this.auxArticulos = this.articulos; | 84 | this.auxArticulos = this.articulos; |
| 85 | return; | 85 | return; |
| 86 | } | 86 | } |
| 87 | this.auxArticulos = this.articulos.filter(x => { | 87 | this.auxArticulos = this.articulos.filter(x => { |
| 88 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; | 88 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; |
| 89 | }); | 89 | }); |
| 90 | this.ordenar(); | 90 | this.ordenar(); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | ordenar() { | 93 | ordenar() { |
| 94 | if (this.ordenandoByVendidos) { | 94 | if (this.ordenandoByVendidos) { |
| 95 | this.auxArticulos.sort((a, b) => { | 95 | this.auxArticulos.sort((a, b) => { |
| 96 | return b.cantidadVendida - a.cantidadVendida; | 96 | return b.cantidadVendida - a.cantidadVendida; |
| 97 | }); | 97 | }); |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | selectArticulo(articulo: IArticulo) { | 101 | selectArticulo(articulo: IArticulo) { |
| 102 | if (articulo.ExiVta < 1) { | 102 | if (articulo.ExiVta < 1) { |
| 103 | if (this.modalRef) return; | 103 | if (this.modalRef) return; |
| 104 | this.modalRef = this.modalService.show(NoStockComponent, { | 104 | this.modalRef = this.modalService.show(NoStockComponent, { |
| 105 | class: 'modal-dialog-centered', | 105 | class: 'modal-dialog-centered', |
| 106 | backdrop: false, | 106 | backdrop: false, |
| 107 | ignoreBackdropClick: true, | 107 | ignoreBackdropClick: true, |
| 108 | }); | 108 | }); |
| 109 | this.modalRef.content.onClose | 109 | this.modalRef.content.onClose |
| 110 | .subscribe(() => this.modalRef = null); | 110 | .subscribe(() => this.modalRef = null); |
| 111 | } else { | 111 | } else { |
| 112 | this.getByID(articulo.id); | 112 | this.getByID(articulo.id); |
| 113 | } | 113 | } |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | getByID(id: number) { | 116 | getByID(id: number) { |
| 117 | this.articuloService.getById(id) | 117 | this.articuloService.getById(id) |
| 118 | .subscribe((res: IArticulo) => { | 118 | .subscribe((res: IArticulo) => { |
| 119 | if (res.FPP) { | 119 | if (res.FPP) { |
| 120 | this.openModalPromos(res); | 120 | this.openModalPromos(res); |
| 121 | } else { | 121 | } else { |
| 122 | this.getSinonimos(res); | 122 | this.getSinonimos(res); |
| 123 | } | 123 | } |
| 124 | }, err => console.error(err)); | 124 | }, err => console.error(err)); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | getSinonimos(articulo: IArticulo) { | 127 | getSinonimos(articulo: IArticulo) { |
| 128 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 128 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 129 | .subscribe((res: any[]) => { | 129 | .subscribe((res: any[]) => { |
| 130 | if (res.length) { | 130 | if (res.length) { |
| 131 | const sinonimos = []; | 131 | const sinonimos = []; |
| 132 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 132 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); |
| 133 | Object.keys(gruposArticulos).forEach((key, i) => { | 133 | Object.keys(gruposArticulos).forEach(key => { |
| 134 | sinonimos.push({ productos: gruposArticulos[key], }); | 134 | sinonimos.push({ productos: gruposArticulos[key], }); |
| 135 | for (const a of articulo.productos) { | ||
| 136 | if (key === a.idSinonimo.toString()) { | ||
| 137 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
| 138 | continue; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | }); | 135 | }); |
| 136 | for (let j = 0; j < articulo.productos.length; j++) { | ||
| 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; | ||
| 140 | } | ||
| 141 | }); | ||
| 142 | } | ||
| 142 | res = sinonimos; | 143 | res = sinonimos; |
| 143 | this.openModalSinonimos(res, articulo); | 144 | this.openModalSinonimos(res, articulo); |
| 144 | } else { | 145 | } else { |
| 145 | this.articuloService.setArticulo(articulo); | 146 | this.articuloService.setArticulo(articulo); |
| 146 | } | 147 | } |
| 147 | }); | 148 | }); |
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | openModalPromos(articulo: IArticulo) { | 151 | openModalPromos(articulo: IArticulo) { |
| 151 | if (this.modalRef) return; | 152 | if (this.modalRef) return; |
| 152 | this.articuloService.setArticulosSinImagen([articulo]); | 153 | this.articuloService.setArticulosSinImagen([articulo]); |
| 153 | this.modalRef = this.modalService.show(PromocionComponent, { | 154 | this.modalRef = this.modalService.show(PromocionComponent, { |
| 154 | initialState: { articulosPromo: [articulo] }, | 155 | initialState: { articulosPromo: [articulo] }, |
| 155 | class: 'modal-dialog-centered', | 156 | class: 'modal-dialog-centered', |
| 156 | ignoreBackdropClick: true, | 157 | ignoreBackdropClick: true, |
| 157 | }); | 158 | }); |
| 158 | this.modalRef.content.onClose | 159 | this.modalRef.content.onClose |
| 159 | .subscribe(() => this.modalRef = null); | 160 | .subscribe(() => this.modalRef = null); |
| 160 | this.mediaPantalla(); | 161 | this.mediaPantalla(); |
| 161 | } | 162 | } |
| 162 | 163 | ||
| 163 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 164 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 164 | if (this.modalRef) return; | 165 | if (this.modalRef) return; |
| 165 | this.modalRef = this.modalService.show(SinonimoComponent, { | 166 | this.modalRef = this.modalService.show(SinonimoComponent, { |
| 166 | initialState: { | 167 | initialState: { |
| 167 | sinonimos: sinonimosData, | 168 | sinonimos: sinonimosData, |
| 168 | articulo | 169 | articulo |
| 169 | }, | 170 | }, |
| 170 | class: 'modal-dialog-centered', | 171 | class: 'modal-dialog-centered', |
| 171 | ignoreBackdropClick: true, | 172 | ignoreBackdropClick: true, |
| 172 | }); | 173 | }); |
| 173 | 174 | ||
| 174 | this.modalRef.content.onClose | 175 | this.modalRef.content.onClose |
| 175 | .subscribe((res: any) => { | 176 | .subscribe((res: any) => { |
| 176 | this.modalRef = null; | 177 | this.modalRef = null; |
| 177 | if (!res) return; | 178 | if (!res) return; |
| 178 | articulo.productos = res.articulos; | 179 | articulo.productos = res.articulos; |
| 179 | this.articuloService.setArticulo(articulo); | 180 | this.articuloService.setArticulo(articulo); |
| 180 | }); | 181 | }); |
| 181 | this.mediaPantalla(); | 182 | this.mediaPantalla(); |
| 182 | } | 183 | } |
| 183 | 184 | ||
| 184 | deleteArticulo(index: number) { | 185 | deleteArticulo(index: number) { |
| 185 | this.articuloService.deleteArticulo(index); | 186 | this.articuloService.deleteArticulo(index); |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | increaseShow() { | 189 | increaseShow() { |
| 189 | this.showQuantity += 100; | 190 | this.showQuantity += 100; |
| 190 | } | 191 | } |
| 191 | 192 | ||
| 192 | 193 | ||
| 193 | validarFecha(fechaInicio: string, fechaFin: string) { | 194 | validarFecha(fechaInicio: string, fechaFin: string) { |
| 194 | return DateExtension.ValidateDateRange(fechaInicio, fechaFin); | 195 | return DateExtension.ValidateDateRange(fechaInicio, fechaFin); |
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | @HostListener('scroll', ['$event']) | 198 | @HostListener('scroll', ['$event']) |
| 198 | scrollEvent(event: Event) { | 199 | scrollEvent(event: Event) { |
| 199 | clearTimeout(this.inactiveScreen.timerReposo); | 200 | clearTimeout(this.inactiveScreen.timerReposo); |
| 200 | this.inactiveScreen.startTimeOutInactividad(); | 201 | this.inactiveScreen.startTimeOutInactividad(); |
| 201 | } | 202 | } |
| 202 | 203 | ||
| 203 | mouseup() { | 204 | mouseup() { |
| 204 | if (!this.timeoutHandler) return; | 205 | if (!this.timeoutHandler) return; |
| 205 | clearInterval(this.timeoutHandler); | 206 | clearInterval(this.timeoutHandler); |
| 206 | } | 207 | } |
| 207 | 208 | ||
| 208 | scrollY(el: HTMLElement, value) { | 209 | scrollY(el: HTMLElement, value) { |
| 209 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 210 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 210 | this.timeoutHandler = setInterval(() => { | 211 | this.timeoutHandler = setInterval(() => { |
| 211 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 212 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 212 | }, 500); | 213 | }, 500); |
| 213 | } | 214 | } |
| 214 | 215 | ||
| 215 | scrollX(el: HTMLElement, value) { | 216 | scrollX(el: HTMLElement, value) { |
| 216 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 217 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 217 | this.timeoutHandler = setInterval(() => { | 218 | this.timeoutHandler = setInterval(() => { |
| 218 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 219 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 219 | }, 500); | 220 | }, 500); |
| 220 | } | 221 | } |
| 221 | 222 | ||
| 222 | mediaPantalla() { | 223 | mediaPantalla() { |
| 223 | if ($('body').hasClass('media-pantalla')) { | 224 | if ($('body').hasClass('media-pantalla')) { |
| 224 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 225 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
| 225 | .cat-box,.img-categoria, .modal-content`) | 226 | .cat-box,.img-categoria, .modal-content`) |
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 | import { NoStockComponent } from 'src/app/modules/seleccion-articulos/no-stock/no-stock.component'; | 14 | import { NoStockComponent } from 'src/app/modules/seleccion-articulos/no-stock/no-stock.component'; |
| 15 | 15 | ||
| 16 | @Component({ | 16 | @Component({ |
| 17 | selector: 'app-header-publicidad', | 17 | selector: 'app-header-publicidad', |
| 18 | templateUrl: './header-publicidad.component.html', | 18 | templateUrl: './header-publicidad.component.html', |
| 19 | styleUrls: ['./header-publicidad.component.scss'] | 19 | styleUrls: ['./header-publicidad.component.scss'] |
| 20 | }) | 20 | }) |
| 21 | export class HeaderPublicidadComponent implements OnInit { | 21 | export class HeaderPublicidadComponent implements OnInit { |
| 22 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 22 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
| 23 | publicidades: IPublicidad[] = []; | 23 | publicidades: IPublicidad[] = []; |
| 24 | modalRef: BsModalRef; | 24 | modalRef: BsModalRef; |
| 25 | modalSinonimo: BsModalRef; | 25 | modalSinonimo: BsModalRef; |
| 26 | 26 | ||
| 27 | constructor( | 27 | constructor( |
| 28 | private publicidadService: PublicidadService, | 28 | private publicidadService: PublicidadService, |
| 29 | private articuloService: ArticuloService, | 29 | private articuloService: ArticuloService, |
| 30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
| 31 | private sinonimoService: SinonimoService | 31 | private sinonimoService: SinonimoService |
| 32 | ) { } | 32 | ) { } |
| 33 | 33 | ||
| 34 | ngOnInit() { | 34 | ngOnInit() { |
| 35 | this.getPublicidades(); | 35 | this.getPublicidades(); |
| 36 | this.mediaPantalla(); | 36 | this.mediaPantalla(); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | getPublicidades() { | 39 | getPublicidades() { |
| 40 | this.publicidadService.getAll() | 40 | this.publicidadService.getAll() |
| 41 | .subscribe((res: IPublicidad[]) => { | 41 | .subscribe((res: IPublicidad[]) => { |
| 42 | this.publicidades = res; | 42 | this.publicidades = res; |
| 43 | }, err => console.error(err)); | 43 | }, err => console.error(err)); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | elegirArticulo(publicidad: IPublicidad) { | 46 | elegirArticulo(publicidad: IPublicidad) { |
| 47 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 47 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | getByID(id: number) { | 50 | getByID(id: number) { |
| 51 | this.articuloService.getById(id) | 51 | this.articuloService.getById(id) |
| 52 | .subscribe((res: IArticulo) => { | 52 | .subscribe((res: IArticulo) => { |
| 53 | if (res.ExiVta < 1) { | 53 | if (res.ExiVta < 1) { |
| 54 | if (this.modalRef) return; | 54 | if (this.modalRef) return; |
| 55 | this.modalRef = this.modalService.show(NoStockComponent, { | 55 | this.modalRef = this.modalService.show(NoStockComponent, { |
| 56 | class: 'modal-dialog-centered', | 56 | class: 'modal-dialog-centered', |
| 57 | backdrop: false, | 57 | backdrop: false, |
| 58 | ignoreBackdropClick: true, | 58 | ignoreBackdropClick: true, |
| 59 | }); | 59 | }); |
| 60 | this.modalRef.content.onClose | 60 | this.modalRef.content.onClose |
| 61 | .subscribe(() => this.modalRef = null); | 61 | .subscribe(() => this.modalRef = null); |
| 62 | } else { | 62 | } else { |
| 63 | if (res.FPP) { | 63 | if (res.FPP) { |
| 64 | this.openModalPromos(res); | 64 | this.openModalPromos(res); |
| 65 | return; | 65 | return; |
| 66 | } else { | 66 | } else { |
| 67 | this.openModalConfirmacion(res); | 67 | this.openModalConfirmacion(res); |
| 68 | return; | 68 | return; |
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | openModalPromos(articulo: IArticulo) { | 74 | openModalPromos(articulo: IArticulo) { |
| 75 | if (this.modalRef) return; | 75 | if (this.modalRef) return; |
| 76 | this.modalRef = this.modalService.show(PromocionComponent, | 76 | this.modalRef = this.modalService.show(PromocionComponent, |
| 77 | { | 77 | { |
| 78 | initialState: { | 78 | initialState: { |
| 79 | idArticulo: articulo.id | 79 | idArticulo: articulo.id |
| 80 | }, | 80 | }, |
| 81 | class: 'modal-dialog-centered' | 81 | class: 'modal-dialog-centered' |
| 82 | }); | 82 | }); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | openModalConfirmacion(articulo: IArticulo) { | 85 | openModalConfirmacion(articulo: IArticulo) { |
| 86 | if (this.modalRef) return; | 86 | if (this.modalRef) return; |
| 87 | this.articuloService.setArticulosSinImagen([articulo]); | 87 | this.articuloService.setArticulosSinImagen([articulo]); |
| 88 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 88 | this.modalRef = this.modalService.show(ConfirmacionComponent, |
| 89 | { | 89 | { |
| 90 | initialState: { | 90 | initialState: { |
| 91 | titleMessage: articulo.DET_LAR, | 91 | titleMessage: articulo.DET_LAR, |
| 92 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 92 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', |
| 93 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, | 93 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, |
| 94 | footerMessageSecond: `a tu carrito?`, | 94 | footerMessageSecond: `a tu carrito?`, |
| 95 | footerConfirmation: articulo.PreVen | 95 | footerConfirmation: articulo.PreVen |
| 96 | }, | 96 | }, |
| 97 | ignoreBackdropClick: true, | 97 | ignoreBackdropClick: true, |
| 98 | class: 'modal-dialog-centered' | 98 | class: 'modal-dialog-centered' |
| 99 | }); | 99 | }); |
| 100 | this.modalRef.content.onClose.subscribe((resClose) => { | 100 | this.modalRef.content.onClose.subscribe((resClose) => { |
| 101 | this.modalRef = null; | 101 | this.modalRef = null; |
| 102 | if (!resClose) return; | 102 | if (!resClose) return; |
| 103 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 103 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 104 | .subscribe((res: ISinonimo[]) => { | 104 | .subscribe((res: ISinonimo[]) => { |
| 105 | if (res.length) { | 105 | if (res.length) { |
| 106 | const sinonimos = []; | 106 | const sinonimos = []; |
| 107 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 107 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); |
| 108 | Object.keys(gruposArticulos).forEach((key, i) => { | 108 | Object.keys(gruposArticulos).forEach(key => { |
| 109 | sinonimos.push({ productos: gruposArticulos[key], }); | 109 | sinonimos.push({ productos: gruposArticulos[key], }); |
| 110 | for (const a of articulo.productos) { | ||
| 111 | if (key === a.idSinonimo.toString()) { | ||
| 112 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
| 113 | continue; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | }); | 110 | }); |
| 111 | for (let j = 0; j < articulo.productos.length; j++) { | ||
| 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; | ||
| 115 | } | ||
| 116 | }); | ||
| 117 | } | ||
| 117 | res = sinonimos; | 118 | res = sinonimos; |
| 118 | this.openModalSinonimos(res, articulo); | 119 | this.openModalSinonimos(res, articulo); |
| 119 | } else { | 120 | } else { |
| 120 | articulo.cantidad = 1; | 121 | articulo.cantidad = 1; |
| 121 | this.articuloService.setArticulo(articulo); | 122 | this.articuloService.setArticulo(articulo); |
| 122 | } | 123 | } |
| 123 | }, err => console.error(err)); | 124 | }, err => console.error(err)); |
| 124 | }); | 125 | }); |
| 125 | this.mediaPantalla(); | 126 | this.mediaPantalla(); |
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 129 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 129 | if (this.modalSinonimo) return; | 130 | if (this.modalSinonimo) return; |
| 130 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 131 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 131 | initialState: { | 132 | initialState: { |
| 132 | sinonimos: sinonimosData, | 133 | sinonimos: sinonimosData, |
| 133 | articulo | 134 | articulo |
| 134 | }, | 135 | }, |
| 135 | class: 'modal-dialog-centered' | 136 | class: 'modal-dialog-centered' |
| 136 | }); | 137 | }); |
| 137 | this.modalSinonimo.content.onClose | 138 | this.modalSinonimo.content.onClose |
| 138 | .subscribe((res: any) => { | 139 | .subscribe((res: any) => { |
| 139 | this.modalSinonimo = null; | 140 | this.modalSinonimo = null; |
| 140 | if (!res) return; | 141 | if (!res) return; |
| 141 | articulo.productos = res.articulos; | 142 | articulo.productos = res.articulos; |
| 142 | this.articuloService.setArticulo(articulo); | 143 | this.articuloService.setArticulo(articulo); |
| 143 | }); | 144 | }); |
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | mediaPantalla() { | 147 | mediaPantalla() { |
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, 'ORDEN_P'); |
| 54 | Object.keys(gruposArticulos).forEach((key, i) => { | 54 | Object.keys(gruposArticulos).forEach(key => { |
| 55 | sinonimos.push({ productos: gruposArticulos[key], }); | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
| 56 | for (const a of promo.productos) { | ||
| 57 | if (key === a.idSinonimo.toString()) { | ||
| 58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
| 59 | continue; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | }); | 56 | }); |
| 57 | for (let j = 0; j < promo.productos.length; j++) { | ||
| 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; | ||
| 61 | } | ||
| 62 | }); | ||
| 63 | } | ||
| 63 | res = sinonimos; | 64 | res = sinonimos; |
| 64 | this.openModalSinonimos(res, promo); | 65 | this.openModalSinonimos(res, promo); |
| 65 | } else { | 66 | } else { |
| 66 | promo.cantidad = 1; | 67 | promo.cantidad = 1; |
| 67 | this.articuloService.setArticulo(promo); | 68 | this.articuloService.setArticulo(promo); |
| 68 | this.onClose.next(); | 69 | this.onClose.next(); |
| 69 | this.modalPromocion.hide(); | 70 | this.modalPromocion.hide(); |
| 70 | } | 71 | } |
| 71 | }, err => console.error(err)); | 72 | }, err => console.error(err)); |
| 72 | }, err => console.error(err)); | 73 | }, err => console.error(err)); |
| 73 | this.mediaPantalla(); | 74 | this.mediaPantalla(); |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 77 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 77 | if (this.modalSinonimo) return; | 78 | if (this.modalSinonimo) return; |
| 78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 79 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 79 | initialState: { | 80 | initialState: { |
| 80 | sinonimos: sinonimosData, | 81 | sinonimos: sinonimosData, |
| 81 | articulo | 82 | articulo |
| 82 | }, | 83 | }, |
| 83 | class: 'modal-dialog-centered', | 84 | class: 'modal-dialog-centered', |
| 84 | ignoreBackdropClick: true, | 85 | ignoreBackdropClick: true, |
| 85 | }); | 86 | }); |
| 86 | 87 | ||
| 87 | this.modalSinonimo.content.onClose | 88 | this.modalSinonimo.content.onClose |
| 88 | .subscribe((res: any) => { | 89 | .subscribe((res: any) => { |
| 89 | this.modalSinonimo = null; | 90 | this.modalSinonimo = null; |
| 90 | if (!res) { | 91 | if (!res) { |
| 91 | this.onClose.next(); | 92 | this.onClose.next(); |
| 92 | this.modalPromocion.hide(); | 93 | this.modalPromocion.hide(); |
| 93 | return; | 94 | return; |
| 94 | } | 95 | } |
| 95 | articulo.productos = res.articulos; | 96 | articulo.productos = res.articulos; |
| 96 | this.articuloService.setArticulo(articulo); | 97 | this.articuloService.setArticulo(articulo); |
| 97 | this.onClose.next(); | 98 | this.onClose.next(); |
| 98 | this.modalPromocion.hide(); | 99 | this.modalPromocion.hide(); |
| 99 | }); | 100 | }); |
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | getPromociones() { | 103 | getPromociones() { |
| 103 | const sector = this.articulosPromo[0].CodSec; | 104 | const sector = this.articulosPromo[0].CodSec; |
| 104 | const codigo = this.articulosPromo[0].CodArt; | 105 | const codigo = this.articulosPromo[0].CodArt; |
| 105 | this.promocionService.getPromociones(sector, codigo) | 106 | this.promocionService.getPromociones(sector, codigo) |
| 106 | .subscribe((res: IArticulo[]) => { | 107 | .subscribe((res: IArticulo[]) => { |
| 107 | res = res.filter(a => a.ExiVta > 0); | 108 | res = res.filter(a => a.ExiVta > 0); |
| 108 | this.loading = false; | 109 | this.loading = false; |
| 109 | this.promociones = res; | 110 | this.promociones = res; |
| 110 | }, error => { console.error(error); }); | 111 | }, error => { console.error(error); }); |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | @HostListener('document:click', ['$event']) | 114 | @HostListener('document:click', ['$event']) |
| 114 | eventListener(event: Event) { | 115 | eventListener(event: Event) { |
| 115 | clearTimeout(this.inactiveScreen.timerReposo); | 116 | clearTimeout(this.inactiveScreen.timerReposo); |
| 116 | this.inactiveScreen.startTimeOutInactividad(); | 117 | this.inactiveScreen.startTimeOutInactividad(); |
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | @HostListener('scroll', ['$event']) | 120 | @HostListener('scroll', ['$event']) |
| 120 | scrollEvent(event: Event) { | 121 | scrollEvent(event: Event) { |
| 121 | clearTimeout(this.inactiveScreen.timerReposo); | 122 | clearTimeout(this.inactiveScreen.timerReposo); |
| 122 | this.inactiveScreen.startTimeOutInactividad(); | 123 | this.inactiveScreen.startTimeOutInactividad(); |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | mediaPantalla() { | 126 | mediaPantalla() { |