Commit ab7cb335b79127fe340271e43e583e0157cb46fe

Authored by Marcelo Puebla
1 parent 9d4962bfe6
Exists in develop

Fix

Seleccion de sinonimos
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
1 import { Component, OnInit, OnDestroy, HostListener, ViewChild, ViewChildren, AfterViewInit } from '@angular/core'; 1 import { Component, OnInit, OnDestroy, HostListener, ViewChild, ViewChildren, 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 { CategoriaService } from 'src/app/services/categoria/categoria.service'; 8 import { CategoriaService } from 'src/app/services/categoria/categoria.service';
9 import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; 9 import { PromocionComponent } from 'src/app/shared/promocion/promocion.component';
10 import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; 10 import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service';
11 import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; 11 import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service';
12 import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; 12 import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component';
13 import { trigger, state, style, transition, animate } from '@angular/animations'; 13 import { trigger, state, style, transition, animate } from '@angular/animations';
14 import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; 14 import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component';
15 import * as _ from 'lodash'; 15 import * as _ from 'lodash';
16 16
17 @Component({ 17 @Component({
18 selector: 'app-seleccion-articulos', 18 selector: 'app-seleccion-articulos',
19 templateUrl: './seleccion-articulos.component.html', 19 templateUrl: './seleccion-articulos.component.html',
20 styleUrls: ['./seleccion-articulos.component.scss'], 20 styleUrls: ['./seleccion-articulos.component.scss'],
21 animations: [ 21 animations: [
22 trigger('EnterLeave', [ 22 trigger('EnterLeave', [
23 state('flyIn', style({ transform: 'translateY(0)' })), 23 state('flyIn', style({ transform: 'translateY(0)' })),
24 transition(':enter', [ 24 transition(':enter', [
25 style({ transform: 'translateY(-100%)' }), 25 style({ transform: 'translateY(-100%)' }),
26 animate('0.5s ease-in') 26 animate('0.5s ease-in')
27 ]), 27 ]),
28 transition(':leave', [ 28 transition(':leave', [
29 animate('0.5s ease-out', style({ transform: 'translateY(-100%)' })) 29 animate('0.5s ease-out', style({ transform: 'translateY(-100%)' }))
30 ]) 30 ])
31 ]) 31 ])
32 ] 32 ]
33 }) 33 })
34 export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { 34 export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy {
35 showSpinner = true; 35 showSpinner = true;
36 timeoutHandler: any; 36 timeoutHandler: any;
37 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; 37 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`;
38 articulos: IArticulo[] = []; 38 articulos: IArticulo[] = [];
39 auxArticulos: IArticulo[] = []; 39 auxArticulos: IArticulo[] = [];
40 showQuantity = 100; 40 showQuantity = 100;
41 searchTerm = ''; 41 searchTerm = '';
42 ordenandoByVendidos = true; 42 ordenandoByVendidos = true;
43 modalRef: BsModalRef; 43 modalRef: BsModalRef;
44 total = 0; 44 total = 0;
45 @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; 45 @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent;
46 46
47 constructor( 47 constructor(
48 public articuloService: ArticuloService, 48 public articuloService: ArticuloService,
49 private categoriaService: CategoriaService, 49 private categoriaService: CategoriaService,
50 private sinonimoService: SinonimoService, 50 private sinonimoService: SinonimoService,
51 private modalService: BsModalService, 51 private modalService: BsModalService,
52 private inactiveScreen: InactiveScreenService, 52 private inactiveScreen: InactiveScreenService,
53 ) { } 53 ) { }
54 54
55 ngOnInit() { } 55 ngOnInit() { }
56 56
57 ngAfterViewInit(): void { 57 ngAfterViewInit(): void {
58 this.filtroCategorias.getCategorias(); 58 this.filtroCategorias.getCategorias();
59 this.mediaPantalla(); 59 this.mediaPantalla();
60 } 60 }
61 61
62 ngOnDestroy() { 62 ngOnDestroy() {
63 for (let i = 1; i <= this.modalService.getModalsCount(); i++) { 63 for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
64 this.modalService.hide(i); 64 this.modalService.hide(i);
65 } 65 }
66 } 66 }
67 67
68 getProductos() { 68 getProductos() {
69 this.articuloService.getAll() 69 this.articuloService.getAll()
70 .subscribe((result: IArticulo[]) => { 70 .subscribe((result: IArticulo[]) => {
71 this.articuloService.setArticulosSinImagen(result); 71 this.articuloService.setArticulosSinImagen(result);
72 if (this.filtroCategorias.queMostrar === 'ordenar') { 72 if (this.filtroCategorias.queMostrar === 'ordenar') {
73 this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { 73 this.filtroCategorias.categorias.forEach((categoria: ICategoria) => {
74 const tempArticulos = result.filter((articulo: IArticulo) => { 74 const tempArticulos = result.filter((articulo: IArticulo) => {
75 return articulo.categoria_selfservice === categoria.id; 75 return articulo.categoria_selfservice === categoria.id;
76 }); 76 });
77 result = tempArticulos; 77 result = tempArticulos;
78 }); 78 });
79 } 79 }
80 localStorage.setItem('articulos', JSON.stringify(result)); 80 localStorage.setItem('articulos', JSON.stringify(result));
81 this.setProductos(); 81 this.setProductos();
82 }, (error) => { 82 }, (error) => {
83 this.showSpinner = false; 83 this.showSpinner = false;
84 console.error(error); 84 console.error(error);
85 }); 85 });
86 } 86 }
87 87
88 setProductos() { 88 setProductos() {
89 this.articulos = JSON.parse(localStorage.getItem('articulos')); 89 this.articulos = JSON.parse(localStorage.getItem('articulos'));
90 this.filterItems(); 90 this.filterItems();
91 } 91 }
92 92
93 filterItems() { 93 filterItems() {
94 if (this.filtroCategorias.categoriaActive === 0) { 94 if (this.filtroCategorias.categoriaActive === 0) {
95 this.auxArticulos = this.articulos; 95 this.auxArticulos = this.articulos;
96 return; 96 return;
97 } 97 }
98 this.auxArticulos = this.articulos.filter(x => { 98 this.auxArticulos = this.articulos.filter(x => {
99 return x.categoria_selfservice === this.filtroCategorias.categoriaActive; 99 return x.categoria_selfservice === this.filtroCategorias.categoriaActive;
100 }); 100 });
101 this.ordenar(); 101 this.ordenar();
102 } 102 }
103 103
104 ordenar() { 104 ordenar() {
105 if (this.ordenandoByVendidos) { 105 if (this.ordenandoByVendidos) {
106 this.auxArticulos.sort((a, b) => { 106 this.auxArticulos.sort((a, b) => {
107 return b.cantidadVendida - a.cantidadVendida; 107 return b.cantidadVendida - a.cantidadVendida;
108 }); 108 });
109 } 109 }
110 } 110 }
111 111
112 selectArticulo(articulo: IArticulo) { 112 selectArticulo(articulo: IArticulo) {
113 this.getByID(articulo.id); 113 this.getByID(articulo.id);
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 const sinonimos = [];
131 const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN');
132 Object.keys(gruposArticulos).forEach(key => {
133 sinonimos.push({ productos: gruposArticulos[key] });
134 });
135 res = sinonimos;
136 if (res.length) { 130 if (res.length) {
131 const sinonimos = [];
132 const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN');
133 Object.keys(gruposArticulos).forEach(key => {
134 sinonimos.push({ productos: gruposArticulos[key] });
135 });
136 res = sinonimos;
137 this.openModalSinonimos(res, articulo); 137 this.openModalSinonimos(res, articulo);
138 } else { 138 } else {
139 this.articuloService.setArticulo(articulo); 139 this.articuloService.setArticulo(articulo);
140 } 140 }
141 }); 141 });
142 } 142 }
143 143
144 openModalPromos(articulo: IArticulo) { 144 openModalPromos(articulo: IArticulo) {
145 this.modalRef = this.modalService.show(PromocionComponent, { 145 this.modalRef = this.modalService.show(PromocionComponent, {
146 initialState: { articulosPromo: [articulo] }, 146 initialState: { articulosPromo: [articulo] },
147 class: 'modal-promo modal-dialog-centered' 147 class: 'modal-promo modal-dialog-centered'
148 }); 148 });
149 } 149 }
150 150
151 openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { 151 openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) {
152 this.modalRef = this.modalService.show(SinonimoComponent, { 152 this.modalRef = this.modalService.show(SinonimoComponent, {
153 initialState: { sinonimos: sinonimosData }, 153 initialState: { sinonimos: sinonimosData },
154 class: 'modal-promo modal-dialog-centered' 154 class: 'modal-promo modal-dialog-centered'
155 }); 155 });
156 156
157 this.modalRef.content.onClose 157 this.modalRef.content.onClose
158 .subscribe((res: any) => { 158 .subscribe((res: any) => {
159 for (const a of articulo.productos) { 159 for (const a of articulo.productos) {
160 for (const aRes of res.articulos) { 160 for (const aRes of res.articulos) {
161 if (a.idSinonimo === aRes.ID_SIN) { 161 if (a.idSinonimo === aRes.ID_SIN) {
162 a.CODA = aRes.CodArt; 162 a.CODA = aRes.CodArt;
163 a.CodArt = aRes.CodArt; 163 a.CodArt = aRes.CodArt;
164 a.SECA = aRes.CodSec; 164 a.SECA = aRes.CodSec;
165 aRes.CodSec = aRes.CodSec; 165 aRes.CodSec = aRes.CodSec;
166 a.PreVen = aRes.PreVen; 166 a.PreVen = aRes.PreVen;
167 a.id = aRes.id; 167 a.id = aRes.id;
168 a.DET_LAR = aRes.DET_LAR; 168 a.DET_LAR = aRes.DET_LAR;
169 a.DetArt = aRes.DetArt; 169 a.DetArt = aRes.DetArt;
170 } 170 }
171 } 171 }
172 } 172 }
173 this.articuloService.setArticulo(articulo); 173 this.articuloService.setArticulo(articulo);
174 }); 174 });
175 } 175 }
176 176
177 deleteArticulo(index: number) { 177 deleteArticulo(index: number) {
178 this.articuloService.deleteArticulo(index); 178 this.articuloService.deleteArticulo(index);
179 } 179 }
180 180
181 increaseShow() { 181 increaseShow() {
182 this.showQuantity += 100; 182 this.showQuantity += 100;
183 } 183 }
184 184
185 @HostListener('scroll', ['$event']) 185 @HostListener('scroll', ['$event'])
186 scrollEvent(event: Event) { 186 scrollEvent(event: Event) {
187 clearTimeout(this.inactiveScreen.timerReposo); 187 clearTimeout(this.inactiveScreen.timerReposo);
188 this.inactiveScreen.startTimeOutInactividad(); 188 this.inactiveScreen.startTimeOutInactividad();
189 } 189 }
190 190
191 mouseup() { 191 mouseup() {
192 if (!this.timeoutHandler) return; 192 if (!this.timeoutHandler) return;
193 clearInterval(this.timeoutHandler); 193 clearInterval(this.timeoutHandler);
194 } 194 }
195 195
196 scrollY(el: HTMLElement, value) { 196 scrollY(el: HTMLElement, value) {
197 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 197 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
198 this.timeoutHandler = setInterval(() => { 198 this.timeoutHandler = setInterval(() => {
199 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 199 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
200 }, 500); 200 }, 500);
201 } 201 }
202 202
203 scrollX(el: HTMLElement, value) { 203 scrollX(el: HTMLElement, value) {
204 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); 204 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft });
205 this.timeoutHandler = setInterval(() => { 205 this.timeoutHandler = setInterval(() => {
206 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); 206 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft });
207 }, 500); 207 }, 500);
208 } 208 }
209 209
210 mediaPantalla() { 210 mediaPantalla() {
211 if ($('body').hasClass('media-pantalla')) { 211 if ($('body').hasClass('media-pantalla')) {
212 $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria') 212 $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria')
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 13
13 @Component({ 14 @Component({
14 selector: 'app-promocion', 15 selector: 'app-promocion',
15 templateUrl: './promocion.component.html', 16 templateUrl: './promocion.component.html',
16 styleUrls: ['./promocion.component.scss'] 17 styleUrls: ['./promocion.component.scss']
17 }) 18 })
18 export class PromocionComponent implements OnInit { 19 export class PromocionComponent implements OnInit {
19 articulosPromo: IArticulo[] = []; 20 articulosPromo: IArticulo[] = [];
20 promociones: IArticulo[] = []; 21 promociones: IArticulo[] = [];
21 onClose: Subject<any>; 22 onClose: Subject<any>;
22 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; 23 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`;
23 24
24 constructor( 25 constructor(
25 public modalPromocion: BsModalRef, 26 public modalPromocion: BsModalRef,
26 private modalService: BsModalService, 27 private modalService: BsModalService,
27 private articuloService: ArticuloService, 28 private articuloService: ArticuloService,
28 private promocionService: PromocionService, 29 private promocionService: PromocionService,
29 private sinonimoService: SinonimoService, 30 private sinonimoService: SinonimoService,
30 private inactiveScreen: InactiveScreenService, 31 private inactiveScreen: InactiveScreenService,
31 ) { 32 ) {
32 this.onClose = new Subject(); 33 this.onClose = new Subject();
33 } 34 }
34 35
35 ngOnInit() { 36 ngOnInit() {
36 this.getPromociones(); 37 this.getPromociones();
37 } 38 }
38 39
39 selectPromo(promo: IArticulo) { 40 selectPromo(promo: IArticulo) {
40 this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) 41 this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt)
41 .subscribe((res: ISinonimo[]) => { 42 .subscribe((res: ISinonimo[]) => {
42 if (res.length) { 43 if (res.length) {
44 const sinonimos = [];
45 const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN');
46 Object.keys(gruposArticulos).forEach(key => {
47 sinonimos.push({ productos: gruposArticulos[key] });
48 });
49 res = sinonimos;
43 this.openModalSinonimos(res, promo); 50 this.openModalSinonimos(res, promo);
44 } else { 51 } else {
45 promo.cantidad = 1; 52 promo.cantidad = 1;
46 this.articuloService.setArticulo(promo); 53 this.articuloService.setArticulo(promo);
47 this.modalPromocion.hide(); 54 this.modalPromocion.hide();
48 } 55 }
49 }, err => console.error(err)); 56 }, err => console.error(err));
50 this.mediaPantalla(); 57 this.mediaPantalla();
51 } 58 }
52 59
53 openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { 60 openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) {
54 const modalSinonimo = this.modalService.show(SinonimoComponent, { 61 const modalSinonimo = this.modalService.show(SinonimoComponent, {
55 initialState: { sinonimos: sinonimosData }, 62 initialState: { sinonimos: sinonimosData },
56 class: 'modal-promo modal-dialog-centered' 63 class: 'modal-promo modal-dialog-centered'
57 }); 64 });
58 65
59 modalSinonimo.content.onClose 66 modalSinonimo.content.onClose
60 .subscribe((res: any) => { 67 .subscribe((res: any) => {
61 for (const a of articulo.productos) { 68 for (const a of articulo.productos) {
62 for (const aRes of res.articulos) { 69 for (const aRes of res.articulos) {
63 if (a.idSinonimo === aRes.ID_SIN) { 70 if (a.idSinonimo === aRes.ID_SIN) {
64 a.CODA = aRes.CodArt; 71 a.CODA = aRes.CodArt;
65 a.CodArt = aRes.CodArt; 72 a.CodArt = aRes.CodArt;
66 a.SECA = aRes.CodSec; 73 a.SECA = aRes.CodSec;
67 aRes.CodSec = aRes.CodSec; 74 aRes.CodSec = aRes.CodSec;
68 a.PreVen = aRes.PreVen; 75 a.PreVen = aRes.PreVen;
69 a.id = aRes.id; 76 a.id = aRes.id;
70 a.DET_LAR = aRes.DET_LAR; 77 a.DET_LAR = aRes.DET_LAR;
71 a.DetArt = aRes.DetArt; 78 a.DetArt = aRes.DetArt;
72 } 79 }
73 } 80 }
74 } 81 }
75 this.articuloService.setArticulo(articulo); 82 this.articuloService.setArticulo(articulo);
76 this.modalPromocion.hide(); 83 this.modalPromocion.hide();
77 }); 84 });
78 } 85 }
79 86
80 getPromociones() { 87 getPromociones() {
81 const sector = this.articulosPromo[0].CodSec; 88 const sector = this.articulosPromo[0].CodSec;
82 const codigo = this.articulosPromo[0].CodArt; 89 const codigo = this.articulosPromo[0].CodArt;
83 this.promocionService.getPromociones(sector, codigo) 90 this.promocionService.getPromociones(sector, codigo)
84 .subscribe((res: IArticulo[]) => { 91 .subscribe((res: IArticulo[]) => {
85 this.promociones = res; 92 this.promociones = res;
86 }, error => { console.error(error); }); 93 }, error => { console.error(error); });
87 } 94 }
88 95
89 @HostListener('document:click', ['$event']) 96 @HostListener('document:click', ['$event'])
90 eventListener(event: Event) { 97 eventListener(event: Event) {
91 clearTimeout(this.inactiveScreen.timerReposo); 98 clearTimeout(this.inactiveScreen.timerReposo);
92 this.inactiveScreen.startTimeOutInactividad(); 99 this.inactiveScreen.startTimeOutInactividad();
93 } 100 }
94 101
95 @HostListener('scroll', ['$event']) 102 @HostListener('scroll', ['$event'])
96 scrollEvent(event: Event) { 103 scrollEvent(event: Event) {
97 clearTimeout(this.inactiveScreen.timerReposo); 104 clearTimeout(this.inactiveScreen.timerReposo);
98 this.inactiveScreen.startTimeOutInactividad(); 105 this.inactiveScreen.startTimeOutInactividad();
99 } 106 }
100 107
101 mediaPantalla() { 108 mediaPantalla() {
102 if ($('body').hasClass('media-pantalla')) { 109 if ($('body').hasClass('media-pantalla')) {
103 $('.modal-content').addClass('media-pantalla'); 110 $('.modal-content').addClass('media-pantalla');
104 } 111 }
105 } 112 }
106 } 113 }
107 114