Commit 1ca67421a564b465e76735362317a73f2ebb5279
1 parent
a34091f647
Exists in
develop
Fix
Al seleccionar sinonimo
Showing
4 changed files
with
16 additions
and
24 deletions
Show diff stats
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 | 15 | ||
| 16 | @Component({ | 16 | @Component({ |
| 17 | selector: 'app-seleccion-articulos', | 17 | selector: 'app-seleccion-articulos', |
| 18 | templateUrl: './seleccion-articulos.component.html', | 18 | templateUrl: './seleccion-articulos.component.html', |
| 19 | styleUrls: ['./seleccion-articulos.component.scss'], | 19 | styleUrls: ['./seleccion-articulos.component.scss'], |
| 20 | animations: [ANIMATIONS.EnterLeaveY] | 20 | animations: [ANIMATIONS.EnterLeaveY] |
| 21 | }) | 21 | }) |
| 22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { | 22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { |
| 23 | loading = true; | 23 | loading = true; |
| 24 | timeoutHandler: any; | 24 | timeoutHandler: any; |
| 25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
| 26 | articulos: IArticulo[] = []; | 26 | articulos: IArticulo[] = []; |
| 27 | auxArticulos: IArticulo[] = []; | 27 | auxArticulos: IArticulo[] = []; |
| 28 | showQuantity = 100; | 28 | showQuantity = 100; |
| 29 | searchTerm = ''; | 29 | searchTerm = ''; |
| 30 | ordenandoByVendidos = true; | 30 | ordenandoByVendidos = true; |
| 31 | modalRef: BsModalRef; | 31 | modalRef: BsModalRef; |
| 32 | total = 0; | 32 | total = 0; |
| 33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; | 33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; |
| 34 | 34 | ||
| 35 | constructor( | 35 | constructor( |
| 36 | public articuloService: ArticuloService, | 36 | public articuloService: ArticuloService, |
| 37 | private sinonimoService: SinonimoService, | 37 | private sinonimoService: SinonimoService, |
| 38 | private modalService: BsModalService, | 38 | private modalService: BsModalService, |
| 39 | private inactiveScreen: InactiveScreenService, | 39 | private inactiveScreen: InactiveScreenService, |
| 40 | ) { } | 40 | ) { } |
| 41 | 41 | ||
| 42 | ngOnInit() { } | 42 | ngOnInit() { } |
| 43 | 43 | ||
| 44 | ngAfterViewInit(): void { | 44 | ngAfterViewInit(): void { |
| 45 | this.filtroCategorias.getCategorias(); | 45 | this.filtroCategorias.getCategorias(); |
| 46 | this.mediaPantalla(); | 46 | this.mediaPantalla(); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | ngOnDestroy() { | 49 | ngOnDestroy() { |
| 50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { |
| 51 | this.modalService.hide(i); | 51 | this.modalService.hide(i); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | getProductos() { | 55 | getProductos() { |
| 56 | this.articuloService.getAll() | 56 | this.articuloService.getAll() |
| 57 | .subscribe((result: IArticulo[]) => { | 57 | .subscribe((result: IArticulo[]) => { |
| 58 | this.articuloService.setArticulosSinImagen(result); | 58 | this.articuloService.setArticulosSinImagen(result); |
| 59 | if (this.filtroCategorias.queMostrar === 'ordenar') { | 59 | if (this.filtroCategorias.queMostrar === 'ordenar') { |
| 60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { | 60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { |
| 61 | const tempArticulos = result.filter((articulo: IArticulo) => { | 61 | const tempArticulos = result.filter((articulo: IArticulo) => { |
| 62 | return articulo.categoria_selfservice === categoria.id; | 62 | return articulo.categoria_selfservice === categoria.id; |
| 63 | }); | 63 | }); |
| 64 | result = tempArticulos; | 64 | result = tempArticulos; |
| 65 | }); | 65 | }); |
| 66 | } | 66 | } |
| 67 | localStorage.setItem('articulos', JSON.stringify(result)); | 67 | localStorage.setItem('articulos', JSON.stringify(result)); |
| 68 | this.setProductos(); | 68 | this.setProductos(); |
| 69 | }, (error) => { | 69 | }, (error) => { |
| 70 | console.error(error); | 70 | console.error(error); |
| 71 | }); | 71 | }); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | setProductos() { | 74 | setProductos() { |
| 75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
| 76 | this.filterItems(); | 76 | this.filterItems(); |
| 77 | this.loading = false; | 77 | this.loading = false; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | filterItems() { | 80 | filterItems() { |
| 81 | if (this.filtroCategorias.categoriaActive === 0) { | 81 | if (this.filtroCategorias.categoriaActive === 0) { |
| 82 | this.auxArticulos = this.articulos; | 82 | this.auxArticulos = this.articulos; |
| 83 | return; | 83 | return; |
| 84 | } | 84 | } |
| 85 | this.auxArticulos = this.articulos.filter(x => { | 85 | this.auxArticulos = this.articulos.filter(x => { |
| 86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; | 86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; |
| 87 | }); | 87 | }); |
| 88 | this.ordenar(); | 88 | this.ordenar(); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | ordenar() { | 91 | ordenar() { |
| 92 | if (this.ordenandoByVendidos) { | 92 | if (this.ordenandoByVendidos) { |
| 93 | this.auxArticulos.sort((a, b) => { | 93 | this.auxArticulos.sort((a, b) => { |
| 94 | return b.cantidadVendida - a.cantidadVendida; | 94 | return b.cantidadVendida - a.cantidadVendida; |
| 95 | }); | 95 | }); |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | selectArticulo(articulo: IArticulo) { | 99 | selectArticulo(articulo: IArticulo) { |
| 100 | this.getByID(articulo.id); | 100 | this.getByID(articulo.id); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | getByID(id: number) { | 103 | getByID(id: number) { |
| 104 | this.articuloService.getById(id) | 104 | this.articuloService.getById(id) |
| 105 | .subscribe((res: IArticulo) => { | 105 | .subscribe((res: IArticulo) => { |
| 106 | if (res.FPP) { | 106 | if (res.FPP) { |
| 107 | this.openModalPromos(res); | 107 | this.openModalPromos(res); |
| 108 | } else { | 108 | } else { |
| 109 | this.getSinonimos(res); | 109 | this.getSinonimos(res); |
| 110 | } | 110 | } |
| 111 | }, err => console.error(err)); | 111 | }, err => console.error(err)); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | getSinonimos(articulo: IArticulo) { | 114 | getSinonimos(articulo: IArticulo) { |
| 115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 116 | .subscribe((res: any[]) => { | 116 | .subscribe((res: any[]) => { |
| 117 | if (res.length) { | 117 | if (res.length) { |
| 118 | const sinonimos = []; | 118 | const sinonimos = []; |
| 119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 120 | Object.keys(gruposArticulos).forEach(key => { | 120 | Object.keys(gruposArticulos).forEach(key => { |
| 121 | sinonimos.push({ productos: gruposArticulos[key] }); | 121 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 122 | }); | 122 | }); |
| 123 | res = sinonimos; | 123 | res = sinonimos; |
| 124 | this.openModalSinonimos(res, articulo); | 124 | this.openModalSinonimos(res, articulo); |
| 125 | } else { | 125 | } else { |
| 126 | this.articuloService.setArticulo(articulo); | 126 | this.articuloService.setArticulo(articulo); |
| 127 | } | 127 | } |
| 128 | }); | 128 | }); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | openModalPromos(articulo: IArticulo) { | 131 | openModalPromos(articulo: IArticulo) { |
| 132 | if (this.modalRef) return; | 132 | if (this.modalRef) return; |
| 133 | this.articuloService.setArticulosSinImagen([articulo]); | 133 | this.articuloService.setArticulosSinImagen([articulo]); |
| 134 | this.modalRef = this.modalService.show(PromocionComponent, { | 134 | this.modalRef = this.modalService.show(PromocionComponent, { |
| 135 | initialState: { articulosPromo: [articulo] }, | 135 | initialState: { articulosPromo: [articulo] }, |
| 136 | class: 'modal-dialog-centered', | 136 | class: 'modal-dialog-centered', |
| 137 | ignoreBackdropClick: true, | 137 | ignoreBackdropClick: true, |
| 138 | }); | 138 | }); |
| 139 | this.modalRef.content.onClose | 139 | this.modalRef.content.onClose |
| 140 | .subscribe(() => this.modalRef = null); | 140 | .subscribe(() => this.modalRef = null); |
| 141 | this.mediaPantalla(); | 141 | this.mediaPantalla(); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 144 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 145 | if (this.modalRef) return; | 145 | if (this.modalRef) return; |
| 146 | this.modalRef = this.modalService.show(SinonimoComponent, { | 146 | this.modalRef = this.modalService.show(SinonimoComponent, { |
| 147 | initialState: { | 147 | initialState: { |
| 148 | sinonimos: sinonimosData, | 148 | sinonimos: sinonimosData, |
| 149 | articulo | 149 | articulo |
| 150 | }, | 150 | }, |
| 151 | class: 'modal-dialog-centered', | 151 | class: 'modal-dialog-centered', |
| 152 | ignoreBackdropClick: true, | 152 | ignoreBackdropClick: true, |
| 153 | }); | 153 | }); |
| 154 | 154 | ||
| 155 | this.modalRef.content.onClose | 155 | this.modalRef.content.onClose |
| 156 | .subscribe((res: any) => { | 156 | .subscribe((res: any) => { |
| 157 | this.modalRef = null; | 157 | this.modalRef = null; |
| 158 | if (!res) return; | ||
| 158 | for (const a of articulo.productos) { | 159 | for (const a of articulo.productos) { |
| 159 | for (const aRes of res.articulos) { | 160 | for (const aRes of res.articulos) { |
| 160 | if (a.idSinonimo === aRes.ID_SIN) { | 161 | if (a.idSinonimo === aRes.ID_SIN) { |
| 161 | a.CODA = aRes.CodArt; | 162 | this.articuloService.changeArticulo(a, aRes); |
| 162 | a.CodArt = aRes.CodArt; | ||
| 163 | a.SECA = aRes.CodSec; | ||
| 164 | aRes.CodSec = aRes.CodSec; | ||
| 165 | a.PreVen = aRes.PreVen; | ||
| 166 | a.id = aRes.id; | ||
| 167 | a.DET_LAR = aRes.DET_LAR; | ||
| 168 | a.DetArt = aRes.DetArt; | ||
| 169 | } | 163 | } |
| 170 | } | 164 | } |
| 171 | } | 165 | } |
| 172 | this.articuloService.setArticulo(articulo); | 166 | this.articuloService.setArticulo(articulo); |
| 173 | }); | 167 | }); |
| 174 | this.mediaPantalla(); | 168 | this.mediaPantalla(); |
| 175 | } | 169 | } |
| 176 | 170 | ||
| 177 | deleteArticulo(index: number) { | 171 | deleteArticulo(index: number) { |
| 178 | this.articuloService.deleteArticulo(index); | 172 | this.articuloService.deleteArticulo(index); |
| 179 | } | 173 | } |
| 180 | 174 | ||
| 181 | increaseShow() { | 175 | increaseShow() { |
| 182 | this.showQuantity += 100; | 176 | this.showQuantity += 100; |
| 183 | } | 177 | } |
| 184 | 178 | ||
| 185 | @HostListener('scroll', ['$event']) | 179 | @HostListener('scroll', ['$event']) |
| 186 | scrollEvent(event: Event) { | 180 | scrollEvent(event: Event) { |
| 187 | clearTimeout(this.inactiveScreen.timerReposo); | 181 | clearTimeout(this.inactiveScreen.timerReposo); |
| 188 | this.inactiveScreen.startTimeOutInactividad(); | 182 | this.inactiveScreen.startTimeOutInactividad(); |
| 189 | } | 183 | } |
| 190 | 184 | ||
| 191 | mouseup() { | 185 | mouseup() { |
| 192 | if (!this.timeoutHandler) return; | 186 | if (!this.timeoutHandler) return; |
| 193 | clearInterval(this.timeoutHandler); | 187 | clearInterval(this.timeoutHandler); |
| 194 | } | 188 | } |
| 195 | 189 | ||
| 196 | scrollY(el: HTMLElement, value) { | 190 | scrollY(el: HTMLElement, value) { |
| 197 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 191 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 198 | this.timeoutHandler = setInterval(() => { | 192 | this.timeoutHandler = setInterval(() => { |
| 199 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 193 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 200 | }, 500); | 194 | }, 500); |
| 201 | } | 195 | } |
| 202 | 196 | ||
| 203 | scrollX(el: HTMLElement, value) { | 197 | scrollX(el: HTMLElement, value) { |
| 204 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 198 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 205 | this.timeoutHandler = setInterval(() => { | 199 | this.timeoutHandler = setInterval(() => { |
| 206 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 200 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 207 | }, 500); | 201 | }, 500); |
| 208 | } | 202 | } |
| 209 | 203 | ||
| 210 | mediaPantalla() { | 204 | mediaPantalla() { |
| 211 | if ($('body').hasClass('media-pantalla')) { | 205 | if ($('body').hasClass('media-pantalla')) { |
| 212 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 206 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
| 213 | .cat-box,.img-categoria, .modal-content`) | 207 | .cat-box,.img-categoria, .modal-content`) |
| 214 | .addClass('media-pantalla') | 208 | .addClass('media-pantalla') |
| 215 | .addBack('media-pantalla'); | 209 | .addBack('media-pantalla'); |
| 216 | } | 210 | } |
| 217 | } | 211 | } |
| 218 | } | 212 | } |
src/app/services/articulo/articulo.service.ts
| 1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
| 2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
| 3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; | 3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; |
| 4 | import { IArticulo } from '../../interfaces/IArticulo'; | 4 | import { IArticulo } from '../../interfaces/IArticulo'; |
| 5 | import { ClienteService } from '../cliente/cliente.service'; | 5 | import { ClienteService } from '../cliente/cliente.service'; |
| 6 | import { Observable } from 'rxjs'; | 6 | import { Observable } from 'rxjs'; |
| 7 | 7 | ||
| 8 | @Injectable() | 8 | @Injectable() |
| 9 | export class ArticuloService { | 9 | export class ArticuloService { |
| 10 | carrito: IArticulo[] = []; | 10 | carrito: IArticulo[] = []; |
| 11 | articuloAcargar: IArticulo; | 11 | articuloAcargar: IArticulo; |
| 12 | promoAcargar: IArticulo; | 12 | promoAcargar: IArticulo; |
| 13 | mostrar: string; | 13 | mostrar: string; |
| 14 | esPromoPersonalizada = false; | 14 | esPromoPersonalizada = false; |
| 15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; |
| 16 | medioPago: number; | 16 | medioPago: number; |
| 17 | idComanda: number; | 17 | idComanda: number; |
| 18 | total = 0; | 18 | total = 0; |
| 19 | maxCantidad = 50; | 19 | maxCantidad = 50; |
| 20 | 20 | ||
| 21 | constructor( | 21 | constructor( |
| 22 | private http: HttpClient, | 22 | private http: HttpClient, |
| 23 | private clienteService: ClienteService, | 23 | private clienteService: ClienteService, |
| 24 | ) { } | 24 | ) { } |
| 25 | 25 | ||
| 26 | getById(id) { | 26 | getById(id) { |
| 27 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); | 27 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | getAll() { | 30 | getAll() { |
| 31 | return this.http.get(`${this.urlDeboSuite}/articulos/`); | 31 | return this.http.get(`${this.urlDeboSuite}/articulos/`); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | getAllWithPaginator(page: number = 1) { | 34 | getAllWithPaginator(page: number = 1) { |
| 35 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); | 35 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | substractCant(articulo: IArticulo) { | 38 | substractCant(articulo: IArticulo) { |
| 39 | if (articulo.cantidad === 1) return; | 39 | if (articulo.cantidad === 1) return; |
| 40 | articulo.cantidad--; | 40 | articulo.cantidad--; |
| 41 | this.calcularTotal(); | 41 | this.calcularTotal(); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | addCant(articulo: IArticulo) { | 44 | addCant(articulo: IArticulo) { |
| 45 | if (articulo.cantidad >= this.maxCantidad) return; | 45 | if (articulo.cantidad >= this.maxCantidad) return; |
| 46 | articulo.cantidad++; | 46 | articulo.cantidad++; |
| 47 | this.calcularTotal(); | 47 | this.calcularTotal(); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | calcularTotal() { | 50 | calcularTotal() { |
| 51 | this.total = 0; | 51 | this.total = 0; |
| 52 | this.carrito.forEach(articulo => { | 52 | this.carrito.forEach(articulo => { |
| 53 | this.total += (articulo.PreVen * articulo.cantidad); | 53 | this.total += (articulo.PreVen * articulo.cantidad); |
| 54 | }); | 54 | }); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | setArticulo(articulo: IArticulo) { | 57 | setArticulo(articulo: IArticulo) { |
| 58 | articulo.cantidad = 1; | 58 | articulo.cantidad = 1; |
| 59 | for (const articuloCarrito of this.carrito) { | 59 | for (const articuloCarrito of this.carrito) { |
| 60 | if (articuloCarrito.id === articulo.id && !articulo.productos) { | 60 | if (articuloCarrito.id === articulo.id && !articulo.productos) { |
| 61 | articuloCarrito.cantidad++; | 61 | articuloCarrito.cantidad++; |
| 62 | this.calcularTotal(); | 62 | this.calcularTotal(); |
| 63 | return; | 63 | return; |
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | this.setArticulosSinImagen([articulo]); | 66 | this.setArticulosSinImagen([articulo]); |
| 67 | this.carrito.unshift(articulo); | 67 | this.carrito.unshift(articulo); |
| 68 | this.calcularTotal(); | 68 | this.calcularTotal(); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | deleteArticulo(index: number) { | 71 | deleteArticulo(index: number) { |
| 72 | this.carrito.splice(index, 1); | 72 | this.carrito.splice(index, 1); |
| 73 | this.calcularTotal(); | 73 | this.calcularTotal(); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | pay(dataPago: any) { | 76 | pay(dataPago: any) { |
| 77 | return new Observable((observer) => { | 77 | return new Observable((observer) => { |
| 78 | this.clienteService.getById(-1) | 78 | this.clienteService.getById(-1) |
| 79 | .subscribe(cliente => { | 79 | .subscribe(cliente => { |
| 80 | this.markArticuloInPromoAsRemoved(); | 80 | this.markArticuloInPromoAsRemoved(); |
| 81 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { | 81 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { |
| 82 | productos: this.carrito, | 82 | productos: this.carrito, |
| 83 | cliente, | 83 | cliente, |
| 84 | origen: 'autoservicio', | 84 | origen: 'autoservicio', |
| 85 | codigoVendedor: 5, | 85 | codigoVendedor: 5, |
| 86 | puntoVenta: APP_SETTINGS.puntoVenta, | 86 | puntoVenta: APP_SETTINGS.puntoVenta, |
| 87 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 87 | pedidoAnombreDe: dataPago.pedidoAnombreDe, |
| 88 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, | 88 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, |
| 89 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), | 89 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), |
| 90 | terminal: APP_SETTINGS.terminal | 90 | terminal: APP_SETTINGS.terminal |
| 91 | }) | 91 | }) |
| 92 | .subscribe((data) => { | 92 | .subscribe((data) => { |
| 93 | observer.next(data); | 93 | observer.next(data); |
| 94 | observer.complete(); | 94 | observer.complete(); |
| 95 | }, err => { | 95 | }, err => { |
| 96 | observer.error(err); | 96 | observer.error(err); |
| 97 | observer.complete(); | 97 | observer.complete(); |
| 98 | }); | 98 | }); |
| 99 | }); | 99 | }); |
| 100 | }); | 100 | }); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | cleanShoppingCar() { | 103 | cleanShoppingCar() { |
| 104 | this.articuloAcargar = undefined; | 104 | this.articuloAcargar = undefined; |
| 105 | this.promoAcargar = undefined; | 105 | this.promoAcargar = undefined; |
| 106 | this.carrito = []; | 106 | this.carrito = []; |
| 107 | this.calcularTotal(); | 107 | this.calcularTotal(); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | setArticulosSinImagen(articulos: IArticulo[]) { | 110 | setArticulosSinImagen(articulos: IArticulo[]) { |
| 111 | articulos.forEach((articulo: IArticulo) => { | 111 | articulos.forEach((articulo: IArticulo) => { |
| 112 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 112 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : |
| 113 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 113 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; |
| 114 | }); | 114 | }); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | markArticuloInPromoAsRemoved() { | 117 | markArticuloInPromoAsRemoved() { |
| 118 | this.carrito.forEach((articuloCarrito: IArticulo) => { | 118 | this.carrito.forEach((articuloCarrito: IArticulo) => { |
| 119 | if (articuloCarrito.PRO) { | 119 | if (articuloCarrito.PRO) { |
| 120 | articuloCarrito.productos.forEach((articulo: IArticulo) => { | 120 | articuloCarrito.productos.forEach((articulo: IArticulo) => { |
| 121 | if (articulo.cantidadAdicionada === 0) { | 121 | if (articulo.cantidadAdicionada === 0) { |
| 122 | articulo.cantidad = 0; | 122 | articulo.cantidad = 0; |
| 123 | articulo.importeValorExtra = 0; | 123 | articulo.importeValorExtra = 0; |
| 124 | } | 124 | } |
| 125 | }); | 125 | }); |
| 126 | } | 126 | } |
| 127 | }); | 127 | }); |
| 128 | } | 128 | } |
| 129 | |||
| 130 | changeArticulo(articuloToChange: IArticulo, articuloData: any) { | ||
| 131 | articuloToChange.CODA = articuloData.CodArt; | ||
| 132 | articuloToChange.CodArt = articuloData.CodArt; | ||
| 133 | articuloToChange.SECA = articuloData.CodSec; | ||
| 134 | articuloToChange.CodSec = articuloData.CodSec; | ||
| 135 | articuloToChange.PreVen = articuloData.PreVen; | ||
| 136 | articuloToChange.id = articuloData.id; | ||
| 137 | articuloToChange.DET_LAR = articuloData.DET_LAR; | ||
| 138 | articuloToChange.DetArt = articuloData.DetArt; | ||
| 139 | articuloToChange.MKT_DESC = articuloData.MKT_DESC; | ||
| 140 | } | ||
| 129 | } | 141 | } |
| 130 | 142 |
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 => { |
| 97 | sinonimos.push({ productos: gruposArticulos[key] }); | 97 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 98 | }); | 98 | }); |
| 99 | res = sinonimos; | 99 | res = sinonimos; |
| 100 | this.openModalSinonimos(res, articulo); | 100 | this.openModalSinonimos(res, articulo); |
| 101 | } else { | 101 | } else { |
| 102 | articulo.cantidad = 1; | 102 | articulo.cantidad = 1; |
| 103 | this.articuloService.setArticulo(articulo); | 103 | this.articuloService.setArticulo(articulo); |
| 104 | } | 104 | } |
| 105 | }, err => console.error(err)); | 105 | }, err => console.error(err)); |
| 106 | }); | 106 | }); |
| 107 | this.mediaPantalla(); | 107 | this.mediaPantalla(); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 111 | if (this.modalSinonimo) return; | 111 | if (this.modalSinonimo) return; |
| 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 113 | initialState: { | 113 | initialState: { |
| 114 | sinonimos: sinonimosData, | 114 | sinonimos: sinonimosData, |
| 115 | articulo | 115 | articulo |
| 116 | }, | 116 | }, |
| 117 | class: 'modal-dialog-centered' | 117 | class: 'modal-dialog-centered' |
| 118 | }); | 118 | }); |
| 119 | this.modalSinonimo.content.onClose | 119 | this.modalSinonimo.content.onClose |
| 120 | .subscribe((res: any) => { | 120 | .subscribe((res: any) => { |
| 121 | for (const a of articulo.productos) { | 121 | for (const a of articulo.productos) { |
| 122 | for (const aRes of res.articulos) { | 122 | for (const aRes of res.articulos) { |
| 123 | if (a.idSinonimo === aRes.ID_SIN) { | 123 | if (a.idSinonimo === aRes.ID_SIN) { |
| 124 | a.CODA = aRes.CodArt; | 124 | this.articuloService.changeArticulo(a, aRes); |
| 125 | a.CodArt = aRes.CodArt; | ||
| 126 | a.SECA = aRes.CodSec; | ||
| 127 | aRes.CodSec = aRes.CodSec; | ||
| 128 | a.PreVen = aRes.PreVen; | ||
| 129 | a.id = aRes.id; | ||
| 130 | a.DET_LAR = aRes.DET_LAR; | ||
| 131 | a.DetArt = aRes.DetArt; | ||
| 132 | } | 125 | } |
| 133 | } | 126 | } |
| 134 | } | 127 | } |
| 135 | this.articuloService.setArticulo(articulo); | 128 | this.articuloService.setArticulo(articulo); |
| 136 | }); | 129 | }); |
| 137 | } | 130 | } |
| 138 | 131 | ||
| 139 | mediaPantalla() { | 132 | mediaPantalla() { |
| 140 | if ($('body').hasClass('media-pantalla')) { | 133 | if ($('body').hasClass('media-pantalla')) { |
| 141 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 134 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
| 142 | } | 135 | } |
| 143 | } | 136 | } |
| 144 | } | 137 | } |
| 145 | 138 |
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.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 46 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
| 47 | .subscribe((res: ISinonimo[]) => { | 47 | .subscribe((res: ISinonimo[]) => { |
| 48 | if (res.length) { | 48 | if (res.length) { |
| 49 | const sinonimos = []; | 49 | const sinonimos = []; |
| 50 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 50 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 51 | Object.keys(gruposArticulos).forEach(key => { | 51 | Object.keys(gruposArticulos).forEach(key => { |
| 52 | sinonimos.push({ productos: gruposArticulos[key] }); | 52 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 53 | }); | 53 | }); |
| 54 | res = sinonimos; | 54 | res = sinonimos; |
| 55 | this.openModalSinonimos(res, promo); | 55 | this.openModalSinonimos(res, promo); |
| 56 | } else { | 56 | } else { |
| 57 | promo.cantidad = 1; | 57 | promo.cantidad = 1; |
| 58 | this.articuloService.setArticulo(promo); | 58 | this.articuloService.setArticulo(promo); |
| 59 | this.onClose.next(); | 59 | this.onClose.next(); |
| 60 | this.modalPromocion.hide(); | 60 | this.modalPromocion.hide(); |
| 61 | } | 61 | } |
| 62 | }, err => console.error(err)); | 62 | }, err => console.error(err)); |
| 63 | this.mediaPantalla(); | 63 | this.mediaPantalla(); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 66 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 67 | if (this.modalSinonimo) return; | 67 | if (this.modalSinonimo) return; |
| 68 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 68 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 69 | initialState: { | 69 | initialState: { |
| 70 | sinonimos: sinonimosData, | 70 | sinonimos: sinonimosData, |
| 71 | articulo | 71 | articulo |
| 72 | }, | 72 | }, |
| 73 | class: 'modal-dialog-centered', | 73 | class: 'modal-dialog-centered', |
| 74 | ignoreBackdropClick: true, | 74 | ignoreBackdropClick: true, |
| 75 | }); | 75 | }); |
| 76 | 76 | ||
| 77 | this.modalSinonimo.content.onClose | 77 | this.modalSinonimo.content.onClose |
| 78 | .subscribe((res: any) => { | 78 | .subscribe((res: any) => { |
| 79 | this.modalSinonimo = null; | 79 | this.modalSinonimo = null; |
| 80 | if (!res) { | 80 | if (!res) { |
| 81 | this.onClose.next(); | 81 | this.onClose.next(); |
| 82 | this.modalPromocion.hide(); | 82 | this.modalPromocion.hide(); |
| 83 | return; | 83 | return; |
| 84 | } | 84 | } |
| 85 | for (const a of articulo.productos) { | 85 | for (const a of articulo.productos) { |
| 86 | for (const aRes of res.articulos) { | 86 | for (const aRes of res.articulos) { |
| 87 | if (a.idSinonimo === aRes.ID_SIN) { | 87 | if (a.idSinonimo === aRes.ID_SIN) { |
| 88 | a.CODA = aRes.CodArt; | 88 | this.articuloService.changeArticulo(a, aRes); |
| 89 | a.CodArt = aRes.CodArt; | ||
| 90 | a.SECA = aRes.CodSec; | ||
| 91 | aRes.CodSec = aRes.CodSec; | ||
| 92 | a.PreVen = aRes.PreVen; | ||
| 93 | a.id = aRes.id; | ||
| 94 | a.DET_LAR = aRes.DET_LAR; | ||
| 95 | a.DetArt = aRes.DetArt; | ||
| 96 | } | 89 | } |
| 97 | } | 90 | } |
| 98 | } | 91 | } |
| 99 | this.articuloService.setArticulo(articulo); | 92 | this.articuloService.setArticulo(articulo); |
| 100 | this.onClose.next(); | 93 | this.onClose.next(); |
| 101 | this.modalPromocion.hide(); | 94 | this.modalPromocion.hide(); |
| 102 | }); | 95 | }); |
| 103 | } | 96 | } |
| 104 | 97 | ||
| 105 | getPromociones() { | 98 | getPromociones() { |
| 106 | const sector = this.articulosPromo[0].CodSec; | 99 | const sector = this.articulosPromo[0].CodSec; |
| 107 | const codigo = this.articulosPromo[0].CodArt; | 100 | const codigo = this.articulosPromo[0].CodArt; |
| 108 | this.promocionService.getPromociones(sector, codigo) | 101 | this.promocionService.getPromociones(sector, codigo) |
| 109 | .subscribe((res: IArticulo[]) => { | 102 | .subscribe((res: IArticulo[]) => { |
| 110 | this.promociones = res; | 103 | this.promociones = res; |
| 111 | this.loading = false; | 104 | this.loading = false; |
| 112 | }, error => { console.error(error); }); | 105 | }, error => { console.error(error); }); |
| 113 | } | 106 | } |
| 114 | 107 | ||
| 115 | @HostListener('document:click', ['$event']) | 108 | @HostListener('document:click', ['$event']) |
| 116 | eventListener(event: Event) { | 109 | eventListener(event: Event) { |
| 117 | clearTimeout(this.inactiveScreen.timerReposo); | 110 | clearTimeout(this.inactiveScreen.timerReposo); |
| 118 | this.inactiveScreen.startTimeOutInactividad(); | 111 | this.inactiveScreen.startTimeOutInactividad(); |
| 119 | } | 112 | } |
| 120 | 113 | ||
| 121 | @HostListener('scroll', ['$event']) | 114 | @HostListener('scroll', ['$event']) |
| 122 | scrollEvent(event: Event) { | 115 | scrollEvent(event: Event) { |
| 123 | clearTimeout(this.inactiveScreen.timerReposo); | 116 | clearTimeout(this.inactiveScreen.timerReposo); |
| 124 | this.inactiveScreen.startTimeOutInactividad(); | 117 | this.inactiveScreen.startTimeOutInactividad(); |
| 125 | } | 118 | } |
| 126 | 119 | ||
| 127 | mediaPantalla() { | 120 | mediaPantalla() { |
| 128 | if ($('body').hasClass('media-pantalla')) { | 121 | if ($('body').hasClass('media-pantalla')) { |
| 129 | $('.modal-content').addClass('media-pantalla'); | 122 | $('.modal-content').addClass('media-pantalla'); |
| 130 | } | 123 | } |
| 131 | } | 124 | } |
| 132 | } | 125 | } |
| 133 | 126 |