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