Commit 2c319982ac8b9a21870618e24355c196f293bf0a
1 parent
103858e63e
Exists in
master
and in
1 other branch
busqueda by codigo de barras
Showing
2 changed files
with
35 additions
and
10 deletions
Show diff stats
src/app/components/inicio/inicio.component.ts
| 1 | import { Component, OnInit, ViewChild } from '@angular/core'; | 1 | import { Component, OnInit, ViewChild } from '@angular/core'; |
| 2 | import { PopoverDirective } from 'ngx-bootstrap'; | 2 | import { PopoverDirective } from 'ngx-bootstrap'; |
| 3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { appSettings } from 'src/etc/AppSettings'; |
| 4 | import { Producto } from 'src/app/wrappers/producto'; | 4 | import { Producto } from 'src/app/wrappers/producto'; |
| 5 | import { ProductoService } from 'src/app/services/producto.service'; | 5 | import { ProductoService } from 'src/app/services/producto.service'; |
| 6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
| 7 | import { Promocion } from 'src/app/wrappers/promocion'; | 7 | import { Promocion } from 'src/app/wrappers/promocion'; |
| 8 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; | 8 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
| 9 | import { HostListener } from '@angular/core'; | 9 | import { HostListener } from '@angular/core'; |
| 10 | 10 | ||
| 11 | @Component({ | 11 | @Component({ |
| 12 | selector: 'app-inicio', | 12 | selector: 'app-inicio', |
| 13 | templateUrl: './inicio.component.html', | 13 | templateUrl: './inicio.component.html', |
| 14 | styleUrls: ['./inicio.component.scss'] | 14 | styleUrls: ['./inicio.component.scss'] |
| 15 | }) | 15 | }) |
| 16 | export class InicioComponent implements OnInit { | 16 | export class InicioComponent implements OnInit { |
| 17 | 17 | ||
| 18 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { | 18 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { |
| 19 | this.busqueda += e.key; | 19 | |
| 20 | if (e.keyCode == 13) { | ||
| 21 | this.buscarByCodigoBarras(this.busqueda); | ||
| 22 | this.busqueda = ''; | ||
| 23 | } else { | ||
| 24 | this.busqueda += e.key; | ||
| 25 | } | ||
| 26 | |||
| 20 | }; | 27 | }; |
| 21 | 28 | ||
| 22 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; | 29 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; |
| 23 | private productoAcargar: Producto; | 30 | private productoAcargar: Producto; |
| 31 | private productos: Producto[]; | ||
| 24 | private promoAcargar: Promocion; | 32 | private promoAcargar: Promocion; |
| 25 | private tienePromo = false; | 33 | private tienePromo = false; |
| 26 | private productoEsPromo = false; | 34 | private productoEsPromo = false; |
| 27 | private busqueda: string = ''; | 35 | private busqueda: string = ''; |
| 28 | private sinonimoAcargar: Sinonimo; | 36 | private sinonimoAcargar: Sinonimo; |
| 29 | 37 | ||
| 30 | promociones: Promocion[] = []; | 38 | promociones: Promocion[] = []; |
| 31 | sinonimos: Sinonimo[] = []; | 39 | sinonimos: Sinonimo[] = []; |
| 32 | apiUrl: string = appSettings.apiUrl | 40 | apiUrl: string = appSettings.apiUrl |
| 33 | 41 | ||
| 34 | constructor( | 42 | constructor( |
| 35 | private router: Router, | 43 | private router: Router, |
| 36 | private productoService: ProductoService) { } | 44 | private productoService: ProductoService) { } |
| 37 | 45 | ||
| 38 | ngOnInit() { | 46 | ngOnInit() { |
| 39 | 47 | ||
| 40 | this.vaciarBusqueda(); | ||
| 41 | |||
| 42 | this.productoAcargar = this.productoService.productoAcargar; | 48 | this.productoAcargar = this.productoService.productoAcargar; |
| 43 | this.getPromociones(); | 49 | this.getPromociones(); |
| 50 | this.getProductos(); | ||
| 44 | } | 51 | } |
| 45 | 52 | ||
| 46 | getPromociones() { | 53 | getPromociones() { |
| 47 | if (this.productoAcargar) { | 54 | if (this.productoAcargar) { |
| 48 | var sector = this.productoAcargar.CodSec; | 55 | var sector = this.productoAcargar.CodSec; |
| 49 | var codigo = this.productoAcargar.CodArt; | 56 | var codigo = this.productoAcargar.CodArt; |
| 50 | this.productoService.getPromocion(sector, codigo) | 57 | this.productoService.getPromocion(sector, codigo) |
| 51 | .subscribe((res: Promocion[]) => { | 58 | .subscribe((res: Promocion[]) => { |
| 52 | 59 | ||
| 53 | if (res.length === 0) { | 60 | if (res.length === 0) { |
| 54 | //Si no tiene promociones la cargará al carrito despues de un tiempo | 61 | //Si no tiene promociones la cargará al carrito despues de un tiempo |
| 55 | setTimeout(() => { | 62 | setTimeout(() => { |
| 56 | this.productoService.productos.push(this.productoAcargar); | 63 | this.productoService.productos.push(this.productoAcargar); |
| 57 | this.productoAcargar = undefined; | 64 | this.productoAcargar = undefined; |
| 58 | }, 2000) | 65 | }, 2000) |
| 59 | } else { | 66 | } else { |
| 60 | 67 | ||
| 61 | this.promociones = res; | 68 | this.promociones = res; |
| 62 | this.popoverDirective.show(); | 69 | this.popoverDirective.show(); |
| 63 | } | 70 | } |
| 64 | }, error => { console.error(error); }) | 71 | }, error => { console.error(error); }) |
| 65 | } | 72 | } |
| 66 | } | 73 | } |
| 67 | 74 | ||
| 68 | showPopover() { | 75 | showPopover() { |
| 69 | 76 | ||
| 70 | this.popoverDirective.show(); | 77 | this.popoverDirective.show(); |
| 71 | } | 78 | } |
| 72 | 79 | ||
| 80 | getProductos() { | ||
| 81 | this.productoService.getAll() | ||
| 82 | .subscribe((productos: Producto[]) => { | ||
| 83 | this.productos = productos; | ||
| 84 | }); | ||
| 85 | } | ||
| 86 | |||
| 73 | private goPage(pageUrl) { | 87 | private goPage(pageUrl) { |
| 74 | 88 | ||
| 75 | this.router.navigate([pageUrl]); | 89 | this.router.navigate([pageUrl]); |
| 76 | } | 90 | } |
| 77 | 91 | ||
| 78 | deshacerCarga() { | 92 | deshacerCarga() { |
| 79 | 93 | ||
| 80 | if (this.sinonimoAcargar || this.sinonimos.length > 0) { | 94 | if (this.sinonimoAcargar || this.sinonimos.length > 0) { |
| 81 | this.sinonimos = []; | 95 | this.sinonimos = []; |
| 82 | this.sinonimoAcargar = undefined; | 96 | this.sinonimoAcargar = undefined; |
| 83 | this.popoverDirective.hide(); | 97 | this.popoverDirective.hide(); |
| 84 | } | 98 | } |
| 85 | 99 | ||
| 86 | if (this.promoAcargar) { | 100 | if (this.promoAcargar) { |
| 87 | this.promoAcargar = undefined; | 101 | this.promoAcargar = undefined; |
| 88 | this.popoverDirective.show(); | 102 | this.popoverDirective.show(); |
| 89 | } else { | 103 | } else { |
| 90 | this.productoAcargar = undefined; | 104 | this.productoAcargar = undefined; |
| 91 | this.promociones = []; | 105 | this.promociones = []; |
| 92 | this.popoverDirective.hide(); | 106 | this.popoverDirective.hide(); |
| 93 | } | 107 | } |
| 94 | } | 108 | } |
| 95 | 109 | ||
| 96 | promoSeleccionada($event: Promocion) { | 110 | promoSeleccionada($event: Promocion) { |
| 97 | 111 | ||
| 98 | this.promoAcargar = $event; | 112 | this.promoAcargar = $event; |
| 99 | this.popoverDirective.hide(); | 113 | this.popoverDirective.hide(); |
| 100 | if (this.promoAcargar.sinonimos) { | 114 | if (this.promoAcargar.sinonimos) { |
| 101 | var sector = this.promoAcargar.sector; | 115 | var sector = this.promoAcargar.sector; |
| 102 | var codigo = this.promoAcargar.codigo; | 116 | var codigo = this.promoAcargar.codigo; |
| 103 | this.productoService.getPromocionSinonimos(sector, codigo) | 117 | this.productoService.getPromocionSinonimos(sector, codigo) |
| 104 | .subscribe((res: Sinonimo[]) => { | 118 | .subscribe((res: Sinonimo[]) => { |
| 105 | res.forEach(resSinonimo => { | 119 | res.forEach(resSinonimo => { |
| 106 | resSinonimo.productos.forEach(productoSinonimo => { | 120 | resSinonimo.productos.forEach(productoSinonimo => { |
| 107 | this.promoAcargar.productos.forEach(productoPromo => { | 121 | this.promoAcargar.productos.forEach(productoPromo => { |
| 108 | if (productoPromo.id === productoSinonimo.id) { | 122 | if (productoPromo.id === productoSinonimo.id) { |
| 109 | productoSinonimo.esPadre = true; | 123 | productoSinonimo.esPadre = true; |
| 110 | } | 124 | } |
| 111 | }); | 125 | }); |
| 112 | 126 | ||
| 113 | }) | 127 | }) |
| 114 | }) | 128 | }) |
| 115 | this.sinonimos = res; | 129 | this.sinonimos = res; |
| 116 | this.showPopover(); | 130 | this.showPopover(); |
| 117 | }) | 131 | }) |
| 118 | } | 132 | } |
| 119 | } | 133 | } |
| 120 | 134 | ||
| 121 | vaciarBusqueda() { | ||
| 122 | |||
| 123 | setTimeout(() => { | ||
| 124 | this.busqueda = ''; | ||
| 125 | }, 2000); | ||
| 126 | } | ||
| 127 | |||
| 128 | sinonimoSeleccionado($event: Sinonimo) { | 135 | sinonimoSeleccionado($event: Sinonimo) { |
| 129 | 136 | ||
| 130 | console.log($event); | 137 | console.log($event); |
| 131 | this.sinonimoAcargar = $event; | 138 | this.sinonimoAcargar = $event; |
| 132 | } | 139 | } |
| 133 | 140 | ||
| 141 | buscarByCodigoBarras(busqueda) { | ||
| 142 | |||
| 143 | let producto = this.productos.filter(producto => { | ||
| 144 | return producto.codigoBarra == busqueda; | ||
| 145 | }); | ||
| 146 | |||
| 147 | if (producto.length) { | ||
| 148 | |||
| 149 | this.productoAcargar = producto[0]; | ||
| 150 | this.getPromociones(); |
src/app/wrappers/producto.ts
| 1 | export interface Producto { | 1 | export interface Producto { |
| 2 | CodSec: number; | 2 | CodSec: number; |
| 3 | CodArt: number; | 3 | CodArt: number; |
| 4 | DetArt: string; | 4 | DetArt: string; |
| 5 | CodRub: number; | 5 | CodRub: number; |
| 6 | Costo: number; | 6 | Costo: number; |
| 7 | PreNet: number; | 7 | PreNet: number; |
| 8 | ImpInt: number; | 8 | ImpInt: number; |
| 9 | UniVen: number; | 9 | UniVen: number; |
| 10 | FecCos: Date; | 10 | FecCos: Date; |
| 11 | UltAct: Date; | 11 | UltAct: Date; |
| 12 | CodPro: number; | 12 | CodPro: number; |
| 13 | ExiDep: number; | 13 | ExiDep: number; |
| 14 | ExiVta: number; | 14 | ExiVta: number; |
| 15 | MinDep: number; | 15 | MinDep: number; |
| 16 | MaxDep: number; | 16 | MaxDep: number; |
| 17 | MinPVE: number; | 17 | MinPVE: number; |
| 18 | MaxPVE: number; | 18 | MaxPVE: number; |
| 19 | ENTTur: number; | 19 | ENTTur: number; |
| 20 | SINTur: number; | 20 | SINTur: number; |
| 21 | SALTur: number; | 21 | SALTur: number; |
| 22 | IvaSN: boolean; | 22 | IvaSN: boolean; |
| 23 | DepSN: boolean; | 23 | DepSN: boolean; |
| 24 | RubMay: number; | 24 | RubMay: number; |
| 25 | PreVen: number; | 25 | PreVen: number; |
| 26 | IvaCO: number; | 26 | IvaCO: number; |
| 27 | TIP: string; | 27 | TIP: string; |
| 28 | IMPIVA: number; | 28 | IMPIVA: number; |
| 29 | ENTADM: number; | 29 | ENTADM: number; |
| 30 | SALADM: number; | 30 | SALADM: number; |
| 31 | CODIIN: number; | 31 | CODIIN: number; |
| 32 | PRO: boolean; | 32 | PRO: boolean; |
| 33 | FPP: boolean; | 33 | FPP: boolean; |
| 34 | ESS: boolean; | 34 | ESS: boolean; |
| 35 | FID: Date; | 35 | FID: Date; |
| 36 | NID: number; | 36 | NID: number; |
| 37 | FIV: Date; | 37 | FIV: Date; |
| 38 | NIV: number; | 38 | NIV: number; |
| 39 | COO: string; | 39 | COO: string; |
| 40 | CAG: string; | 40 | CAG: string; |
| 41 | CAP: number; | 41 | CAP: number; |
| 42 | UTL: number; | 42 | UTL: number; |
| 43 | NHA: boolean; | 43 | NHA: boolean; |
| 44 | PID: boolean; | 44 | PID: boolean; |
| 45 | PRV: number; | 45 | PRV: number; |
| 46 | PRD: number; | 46 | PRD: number; |
| 47 | ImpInt2: number; | 47 | ImpInt2: number; |
| 48 | E_HD: string; | 48 | E_HD: string; |
| 49 | C_HD: string; | 49 | C_HD: string; |
| 50 | CLA: number; | 50 | CLA: number; |
| 51 | UNICAP: number; | 51 | UNICAP: number; |
| 52 | ELBPRO: string; | 52 | ELBPRO: string; |
| 53 | PPP: number; | 53 | PPP: number; |
| 54 | ALI: number; | 54 | ALI: number; |
| 55 | BAL_TIPO: string; | 55 | BAL_TIPO: string; |
| 56 | PER_MAY: boolean; | 56 | PER_MAY: boolean; |
| 57 | ES_MAY: boolean; | 57 | ES_MAY: boolean; |
| 58 | CLA_MAY: number; | 58 | CLA_MAY: number; |
| 59 | PME_CMP: string; | 59 | PME_CMP: string; |
| 60 | USA_BAL: boolean; | 60 | USA_BAL: boolean; |
| 61 | DET_LAR: string; | 61 | DET_LAR: string; |
| 62 | ROTULO: string; | 62 | ROTULO: string; |
| 63 | REC_MANUAL: boolean; | 63 | REC_MANUAL: boolean; |
| 64 | E_HD1: string; | 64 | E_HD1: string; |
| 65 | C_HD1: string; | 65 | C_HD1: string; |
| 66 | ImpInt3: number; | 66 | ImpInt3: number; |
| 67 | FUA_MAE_YPF: Date; | 67 | FUA_MAE_YPF: Date; |
| 68 | CPQ: number; | 68 | CPQ: number; |
| 69 | EPQ: string; | 69 | EPQ: string; |
| 70 | BPQ: number; | 70 | BPQ: number; |
| 71 | PUPQ: number; | 71 | PUPQ: number; |
| 72 | CORVTO: boolean; | 72 | CORVTO: boolean; |
| 73 | CORVTO_COSTO: number; | 73 | CORVTO_COSTO: number; |
| 74 | UTLFR: number; | 74 | UTLFR: number; |
| 75 | FAMILIA: number; | 75 | FAMILIA: number; |
| 76 | ES_LUB: boolean; | 76 | ES_LUB: boolean; |
| 77 | ES_FERT: boolean; | 77 | ES_FERT: boolean; |
| 78 | AutoFac: boolean; | 78 | AutoFac: boolean; |
| 79 | LitrosPCD: number; | 79 | LitrosPCD: number; |
| 80 | LisPCD: number; | 80 | LisPCD: number; |
| 81 | ImpLey23966: boolean; | 81 | ImpLey23966: boolean; |
| 82 | es_bio: boolean; | 82 | es_bio: boolean; |
| 83 | ExpArbaRev: boolean; | 83 | ExpArbaRev: boolean; |
| 84 | ES_AGROQ: boolean; | 84 | ES_AGROQ: boolean; |
| 85 | ES_PLAST: boolean; | 85 | ES_PLAST: boolean; |
| 86 | es_bio_por: string; | 86 | es_bio_por: string; |
| 87 | IMP_IMP_INT: boolean; | 87 | IMP_IMP_INT: boolean; |
| 88 | id: number; | 88 | id: number; |
| 89 | nombreImagen?: any; | 89 | nombreImagen?: any; |
| 90 | categoria_selfservice: number; | 90 | categoria_selfservice: number; |
| 91 | cantidad?: number; | 91 | cantidad?: number; |
| 92 | showCargarProducto?: boolean; | 92 | showCargarProducto?: boolean; |
| 93 | esPadre?: boolean; | 93 | esPadre?: boolean; |
| 94 | codigoBarra: string; | ||
| 94 | } | 95 | } |
| 95 | 96 |