Commit f169c8378c0666de9e0b7f521609079fcb51fb11
1 parent
5c7b72302b
Exists in
develop
Fix
Seleccion de sinonimo
Showing
7 changed files
with
76 additions
and
46 deletions
Show diff stats
package-lock.json
| ... | ... | @@ -1981,6 +1981,12 @@ |
| 1981 | 1981 | "@types/sizzle": "*" |
| 1982 | 1982 | } |
| 1983 | 1983 | }, |
| 1984 | + "@types/lodash": { | |
| 1985 | + "version": "4.14.149", | |
| 1986 | + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz", | |
| 1987 | + "integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==", | |
| 1988 | + "dev": true | |
| 1989 | + }, | |
| 1984 | 1990 | "@types/minimatch": { |
| 1985 | 1991 | "version": "3.0.3", |
| 1986 | 1992 | "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", |
| ... | ... | @@ -7847,8 +7853,7 @@ |
| 7847 | 7853 | "lodash": { |
| 7848 | 7854 | "version": "4.17.15", |
| 7849 | 7855 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", |
| 7850 | - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", | |
| 7851 | - "dev": true | |
| 7856 | + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" | |
| 7852 | 7857 | }, |
| 7853 | 7858 | "lodash.clonedeep": { |
| 7854 | 7859 | "version": "4.5.0", |
package.json
| ... | ... | @@ -30,6 +30,7 @@ |
| 30 | 30 | "hammerjs": "^2.0.8", |
| 31 | 31 | "jquery": "^3.4.1", |
| 32 | 32 | "js-sha256": "^0.9.0", |
| 33 | + "lodash": "^4.17.15", | |
| 33 | 34 | "ngx-bootstrap": "^5.2.0", |
| 34 | 35 | "popper.js": "^1.16.0", |
| 35 | 36 | "rxjs": "~6.4.0", |
| ... | ... | @@ -44,6 +45,7 @@ |
| 44 | 45 | "@fortawesome/fontawesome-free": "^5.12.0", |
| 45 | 46 | "@types/jasmine": "~3.3.8", |
| 46 | 47 | "@types/jasminewd2": "~2.0.3", |
| 48 | + "@types/lodash": "^4.14.149", | |
| 47 | 49 | "@types/node": "~8.9.4", |
| 48 | 50 | "codelyzer": "^5.0.0", |
| 49 | 51 | "devtron": "^1.4.0", |
src/app/interfaces/ISinonimo.ts
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
| ... | ... | @@ -12,6 +12,7 @@ import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 12 | 12 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; |
| 13 | 13 | import { trigger, state, style, transition, animate } from '@angular/animations'; |
| 14 | 14 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; |
| 15 | +import * as _ from 'lodash'; | |
| 15 | 16 | |
| 16 | 17 | @Component({ |
| 17 | 18 | selector: 'app-seleccion-articulos', |
| ... | ... | @@ -125,7 +126,13 @@ export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDes |
| 125 | 126 | |
| 126 | 127 | getSinonimos(articulo: IArticulo) { |
| 127 | 128 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 128 | - .subscribe((res: ISinonimo[]) => { | |
| 129 | + .subscribe((res: any[]) => { | |
| 130 | + const sinonimos = []; | |
| 131 | + const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | |
| 132 | + Object.keys(gruposArticulos).forEach(key => { | |
| 133 | + sinonimos.push({ productos: gruposArticulos[key] }); | |
| 134 | + }); | |
| 135 | + res = sinonimos; | |
| 129 | 136 | if (res.length) { |
| 130 | 137 | this.openModalSinonimos(res, articulo); |
| 131 | 138 | } else { |
| ... | ... | @@ -150,15 +157,17 @@ export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDes |
| 150 | 157 | this.modalRef.content.onClose |
| 151 | 158 | .subscribe((res: any) => { |
| 152 | 159 | for (const a of articulo.productos) { |
| 153 | - if (a.idSinonimo === res.ID_SIN) { | |
| 154 | - a.CODA = res.articulo.CodArt; | |
| 155 | - a.CodArt = res.articulo.CodArt; | |
| 156 | - a.SECA = res.articulo.CodSec; | |
| 157 | - a.CodSec = res.articulo.CodSec; | |
| 158 | - a.PreVen = res.articulo.PreVen; | |
| 159 | - a.id = res.articulo.id; | |
| 160 | - a.DET_LAR = res.articulo.DET_LAR; | |
| 161 | - a.DetArt = res.articulo.DetArt; | |
| 160 | + for (const aRes of res.articulos) { | |
| 161 | + if (a.idSinonimo === aRes.ID_SIN) { | |
| 162 | + a.CODA = aRes.CodArt; | |
| 163 | + a.CodArt = aRes.CodArt; | |
| 164 | + a.SECA = aRes.CodSec; | |
| 165 | + aRes.CodSec = aRes.CodSec; | |
| 166 | + a.PreVen = aRes.PreVen; | |
| 167 | + a.id = aRes.id; | |
| 168 | + a.DET_LAR = aRes.DET_LAR; | |
| 169 | + a.DetArt = aRes.DetArt; | |
| 170 | + } | |
| 162 | 171 | } |
| 163 | 172 | } |
| 164 | 173 | this.articuloService.setArticulo(articulo); |
src/app/shared/promocion/promocion.component.ts
| ... | ... | @@ -59,15 +59,17 @@ export class PromocionComponent implements OnInit { |
| 59 | 59 | modalSinonimo.content.onClose |
| 60 | 60 | .subscribe((res: any) => { |
| 61 | 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; | |
| 62 | + for (const aRes of res.articulos) { | |
| 63 | + if (a.idSinonimo === aRes.ID_SIN) { | |
| 64 | + a.CODA = aRes.CodArt; | |
| 65 | + a.CodArt = aRes.CodArt; | |
| 66 | + a.SECA = aRes.CodSec; | |
| 67 | + aRes.CodSec = aRes.CodSec; | |
| 68 | + a.PreVen = aRes.PreVen; | |
| 69 | + a.id = aRes.id; | |
| 70 | + a.DET_LAR = aRes.DET_LAR; | |
| 71 | + a.DetArt = aRes.DetArt; | |
| 72 | + } | |
| 71 | 73 | } |
| 72 | 74 | } |
| 73 | 75 | this.articuloService.setArticulo(articulo); |
src/app/shared/sinonimo/sinonimo.component.html
| ... | ... | @@ -3,17 +3,16 @@ |
| 3 | 3 | <p class="h4">Elige una opciรณn</p> |
| 4 | 4 | </div> |
| 5 | 5 | |
| 6 | - <div class="modal-body"> | |
| 7 | - <div | |
| 8 | - class="lista-sinonimos scroll-y-visible" | |
| 9 | - *ngFor="let s of sinonimos"> | |
| 6 | + <div class="modal-body lista-sinonimos scroll-y-visible my-2 mr-2"> | |
| 7 | + <div *ngFor="let s of sinonimos; let i = index"> | |
| 8 | + <br> | |
| 10 | 9 | <div *ngFor="let articulo of s.productos"> |
| 11 | 10 | <div class="custom-control custom-checkbox"> |
| 12 | 11 | <input |
| 13 | 12 | type="checkbox" |
| 14 | 13 | class="custom-control-input" |
| 15 | 14 | [(ngModel)]="articulo.seleccionado" |
| 16 | - (click)="selectArticulo(articulo)" | |
| 15 | + (click)="selectSinonimo(i, articulo)" | |
| 17 | 16 | [id]="articulo.id"> |
| 18 | 17 | <label |
| 19 | 18 | class="custom-control-label" |
src/app/shared/sinonimo/sinonimo.component.ts
| ... | ... | @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; |
| 2 | 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 3 | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 4 | 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
| 5 | -import { Subject } from 'rxjs'; | |
| 5 | +import { Subject, forkJoin } from 'rxjs'; | |
| 6 | 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 7 | 7 | |
| 8 | 8 | @Component({ |
| ... | ... | @@ -14,49 +14,61 @@ export class SinonimoComponent implements OnInit { |
| 14 | 14 | sinonimos: ISinonimo[] = []; |
| 15 | 15 | isValid: boolean; |
| 16 | 16 | onClose: Subject<any>; |
| 17 | - articuloSelected: IArticulo; | |
| 17 | + articulosSelected: IArticulo[] = []; | |
| 18 | 18 | |
| 19 | 19 | constructor( |
| 20 | 20 | private modalRef: BsModalRef, |
| 21 | 21 | private articuloService: ArticuloService, |
| 22 | 22 | ) { |
| 23 | 23 | this.onClose = new Subject(); |
| 24 | + this.articulosSelected.length = this.sinonimos.length; | |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | - ngOnInit() { | |
| 27 | - } | |
| 27 | + ngOnInit() { } | |
| 28 | 28 | |
| 29 | - selectArticulo(articulo: IArticulo) { | |
| 30 | - for (const s of this.sinonimos) { | |
| 31 | - for (const a of s.productos) { | |
| 32 | - a.seleccionado = false; | |
| 33 | - } | |
| 29 | + selectSinonimo(index: number, articulo: IArticulo) { | |
| 30 | + for (const a of this.sinonimos[index].productos) { | |
| 31 | + a.seleccionado = false; | |
| 34 | 32 | } |
| 35 | 33 | articulo.seleccionado = true; |
| 36 | - this.articuloSelected = articulo; | |
| 34 | + this.articulosSelected[index] = articulo; | |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | 37 | validate() { |
| 40 | - this.isValid = false; | |
| 38 | + this.isValid = true; | |
| 41 | 39 | for (const s of this.sinonimos) { |
| 42 | - for (const articulo of s.productos) { | |
| 43 | - if (articulo.seleccionado) { | |
| 44 | - this.isValid = true; | |
| 45 | - } | |
| 40 | + for (const a of s.productos) { | |
| 41 | + this.isValid = (!a.seleccionado) ? false : true; | |
| 42 | + if (this.isValid) break; | |
| 46 | 43 | } |
| 44 | + if (!this.isValid) break; | |
| 47 | 45 | } |
| 48 | 46 | return !this.isValid ? 'disabled' : 'btn-effect'; |
| 49 | 47 | } |
| 50 | 48 | |
| 51 | 49 | continue() { |
| 52 | 50 | if (!this.isValid) return; |
| 53 | - const ID_SIN = this.articuloSelected.ID_SIN; | |
| 54 | - this.articuloService.getById(this.articuloSelected.id) | |
| 55 | - .subscribe((res: IArticulo) => { | |
| 51 | + const ID_SINS = []; | |
| 52 | + const observables = []; | |
| 53 | + | |
| 54 | + for (const articulo of this.articulosSelected) { | |
| 55 | + ID_SINS.push(articulo.ID_SIN); | |
| 56 | + } | |
| 57 | + | |
| 58 | + for (const articulo of this.articulosSelected) { | |
| 59 | + observables.push(this.articuloService.getById(articulo.id)); | |
| 60 | + } | |
| 61 | + | |
| 62 | + forkJoin(observables) | |
| 63 | + .subscribe((res: IArticulo[]) => { | |
| 64 | + for (const articulo of res) { | |
| 65 | + for (const ID_SIN of ID_SINS) { | |
| 66 | + articulo.ID_SIN = ID_SIN; | |
| 67 | + } | |
| 68 | + } | |
| 56 | 69 | this.modalRef.hide(); |
| 57 | 70 | this.onClose.next({ |
| 58 | - articulo: res, | |
| 59 | - ID_SIN | |
| 71 | + articulos: res, | |
| 60 | 72 | }); |
| 61 | 73 | }, err => console.error(err)); |
| 62 | 74 | } |