Commit a741af2953a290daea9ab893d6aa008ff9ed50fd
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !159
Showing
12 changed files
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 | ID_SIN?: number; |
18 | imagenes?: any[]; | 18 | imagenes?: any[]; |
19 | ImpInt: number; | 19 | ImpInt: number; |
20 | ImpInt2: number; | 20 | ImpInt2: number; |
21 | ImpInt3: number; | 21 | ImpInt3: number; |
22 | importeValorExtra?: number; | 22 | importeValorExtra?: number; |
23 | PreVen: number; | 23 | PreVen: number; |
24 | PRO: boolean; | 24 | PRO: boolean; |
25 | productos?: IArticulo[]; | 25 | productos?: IArticulo[]; |
26 | seleccionado?: boolean; | 26 | seleccionado?: boolean; |
27 | tieneSinonimo?: boolean; | 27 | tieneSinonimo?: boolean; |
28 | tipo_articulo?: number; | 28 | tipo_articulo?: number; |
29 | CODA?: number; | 29 | CODA?: number; |
30 | CODP?: number; | 30 | CODP?: number; |
31 | SECA?: number; | 31 | SECA?: number; |
32 | SECP?: number; | 32 | SECP?: number; |
33 | MKT_DESC?: string; | 33 | MKT_DESC?: string; |
34 | NHA?: boolean; | 34 | NHA?: boolean; |
35 | FECHA_VIGENCIA_HASTA?: Date; | 35 | FECHA_VIGENCIA_HASTA?: Date; |
36 | FECHA_VIGENCIA_DESDE?: Date; | 36 | FECHA_VIGENCIA_DESDE?: Date; |
37 | ExiVta?: number; | 37 | ExiVta?: number; |
38 | ORDEN_P? : number; | 38 | ORDEN_P?: number; |
39 | } | 39 | } |
40 | 40 | ||
41 | export interface ICodigoBarra { | 41 | export interface ICodigoBarra { |
42 | CodBar: string; | 42 | CodBar: string; |
43 | CodArt: number; | 43 | CodArt: number; |
44 | CodSec: string; | 44 | CodSec: string; |
45 | } | 45 | } |
46 | 46 |
src/app/modules/carrito/carrito.component.html
1 | <div class="h-92 bg-white fade-in-left"> | 1 | <div class="h-92 bg-white fade-in-left"> |
2 | <!-- PUBLICIDADES --> | 2 | <!-- PUBLICIDADES --> |
3 | <app-header-publicidad></app-header-publicidad> | 3 | <app-header-publicidad></app-header-publicidad> |
4 | 4 | ||
5 | <div class="h-75 carrito-content" #carritoContent> | 5 | <div class="h-75 carrito-content" #carritoContent> |
6 | <!-- CABECERA --> | 6 | <!-- CABECERA --> |
7 | <div class="row mx-3 h-auto border border-primary rounded-sm"> | 7 | <div class="row mx-3 h-auto border border-primary rounded-sm"> |
8 | <div class="col-12 px-0 py-2 align-self-center"> | 8 | <div class="col-12 px-0 py-2 align-self-center"> |
9 | <div class="px-3"> | 9 | <div class="px-3"> |
10 | <p class="h6 text-truncate">ESTE ES TÚ CARRITO DE COMPRAS</p> | 10 | <p class="h6 text-truncate">ESTE ES TÚ CARRITO DE COMPRAS</p> |
11 | </div> | 11 | </div> |
12 | </div> | 12 | </div> |
13 | </div> | 13 | </div> |
14 | 14 | ||
15 | <!-- CARRITO --> | 15 | <!-- CARRITO --> |
16 | <div | 16 | <div |
17 | class="row mx-2 mt-4 h-80 h-lg-60 align-content-start scroll-y-visible" | 17 | class="row mx-2 mt-4 h-80 h-lg-60 align-content-start scroll-y-visible" |
18 | (scroll)="scrollEvent($event)"> | 18 | (scroll)="scrollEvent($event)"> |
19 | <!-- MENSAJE DE ADVERTENCIA --> | 19 | <!-- MENSAJE DE ADVERTENCIA --> |
20 | <div class="col-10 align-self-center alert alert-primary" *ngIf="!articuloService.carrito.length"> | 20 | <div class="col-10 align-self-center alert alert-primary" *ngIf="!articuloService.carrito.length"> |
21 | <p class="h5 text-center">No hay artículos en el carrito</p> | 21 | <p class="h5 text-center">No hay artículos en el carrito</p> |
22 | </div> | 22 | </div> |
23 | <!-- ARTICULOS --> | 23 | <!-- ARTICULOS --> |
24 | <div | 24 | <div |
25 | class="col-12 col-xl-6 p-2 h-50 h-md-25 h-xl-40 text-center text-truncate carrito-articulo" | 25 | class="col-12 col-xl-6 p-2 h-50 h-md-25 h-xl-40 text-center text-truncate carrito-articulo" |
26 | [ngClass]="{'media-pantalla': carritoContent.classList.contains('media-pantalla')}" | 26 | [ngClass]="{'media-pantalla': carritoContent.classList.contains('media-pantalla')}" |
27 | *ngFor="let articulo of articuloService.carrito; let i = index;" | 27 | *ngFor="let articulo of articuloService.carrito; let i = index;" |
28 | @EnterLeaveX> | 28 | @EnterLeaveX> |
29 | <!-- ARTICULO --> | 29 | <!-- ARTICULO --> |
30 | <div class="h-100 border border-primary rounded-sm"> | 30 | <div class="h-100 border border-primary rounded-sm"> |
31 | <div class="row align-items-center mx-0 h-100"> | 31 | <div class="row align-items-center mx-0 h-100"> |
32 | <!-- NOMBRE E IMAGEN --> | 32 | <!-- NOMBRE E IMAGEN --> |
33 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> | 33 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> |
34 | <img | 34 | <img |
35 | draggable="false" | 35 | draggable="false" |
36 | ondragstart="return false;" | 36 | ondragstart="return false;" |
37 | (contextmenu)="false" | 37 | (contextmenu)="false" |
38 | class="d-none d-md-block mx-auto h-55 rounded-sm shadow-sm" | 38 | class="d-none d-md-block mx-auto h-55 rounded-sm shadow-sm" |
39 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 39 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" |
40 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'"> | 40 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'"> |
41 | <div class="row mx-0 h-100 h-md-45"> | 41 | <div class="row mx-0 h-100 h-md-45"> |
42 | <p class="col px-0 text-primary carrito-text-desc align-self-center"> | 42 | <p class="col px-0 text-primary carrito-text-desc align-self-center"> |
43 | <small>{{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}}</small> | 43 | <small>{{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}}</small> |
44 | </p> | 44 | </p> |
45 | </div> | 45 | </div> |
46 | </div> | 46 | </div> |
47 | <!-- CANTIDAD --> | 47 | <!-- CANTIDAD --> |
48 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> | 48 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> |
49 | <p class="h-40"><small>CANT</small></p> | 49 | <p class="h-40"><small>CANT</small></p> |
50 | <app-articulo-cantidad [articulo]="articulo"></app-articulo-cantidad> | 50 | <app-articulo-cantidad [articulo]="articulo"></app-articulo-cantidad> |
51 | </div> | 51 | </div> |
52 | <!-- PRECIO --> | 52 | <!-- PRECIO --> |
53 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> | 53 | <div class="col-6 col-md-3 h-50 h-md-100 border-right border-primary"> |
54 | <p class="h-40"><small>PRECIO</small></p> | 54 | <p class="h-40"><small>PRECIO</small></p> |
55 | <div class="py-1 badge-pill bg-dark text-white"> | 55 | <div class="py-1 badge-pill bg-dark text-white"> |
56 | <p><small>{{articulo.PreVen | currency}}</small></p> | 56 | <p><small>{{articulo.PreVen | currency}}</small></p> |
57 | </div> | 57 | </div> |
58 | </div> | 58 | </div> |
59 | <!-- ELIMINAR --> | 59 | <!-- ELIMINAR --> |
60 | <div class="col-6 col-md-3 align-self-center"> | 60 | <div class="col-6 col-md-3 align-self-center"> |
61 | <div class="row mx-0 justify-content-center"> | 61 | <div class="row mx-0 justify-content-center"> |
62 | <div | 62 | <div |
63 | class="col-auto px-3 py-1 btn-effect bg-primary badge-pill text-white" | 63 | class="col-auto px-3 py-1 btn-effect bg-primary badge-pill text-white" |
64 | (click)="deleteArticulo(i)"> | 64 | (click)="deleteArticulo(i)"> |
65 | <span> | 65 | <span> |
66 | <small class="pr-2">ELIMINAR</small> | 66 | <small class="pr-2">ELIMINAR</small> |
67 | <img | 67 | <img |
68 | draggable="false" | 68 | draggable="false" |
69 | ondragstart="return false;" | 69 | ondragstart="return false;" |
70 | (contextmenu)="false" | 70 | (contextmenu)="false" |
71 | class="icon-20 rotate-45" | 71 | class="icon-20 rotate-45" |
72 | src="assets/img/mas-blanco.svg"> | 72 | src="assets/img/mas-blanco.svg"> |
73 | </span> | 73 | </span> |
74 | </div> | 74 | </div> |
75 | </div> | 75 | </div> |
76 | </div> | 76 | </div> |
77 | </div> | 77 | </div> |
78 | </div> | 78 | </div> |
79 | </div> | 79 | </div> |
80 | </div> | 80 | </div> |
81 | <!-- TOTAL --> | 81 | <!-- TOTAL --> |
82 | <div class="row mx-3 mt-2 h-auto justify-content-end"> | 82 | <div class="row mx-3 mt-2 h-auto justify-content-end"> |
83 | <div class="col-auto font-weight-bold align-self-center text-primary py-2 h3">TOTAL</div> | 83 | <div class="col-auto font-weight-bold align-self-center text-primary py-2 h3">TOTAL</div> |
84 | <div class="col-auto align-self-center bg-primary badge-pill"> | 84 | <div class="col-auto align-self-center bg-primary badge-pill"> |
85 | <p class="text-center font-weight-bold text-white py-2 h3 px-2">{{articuloService.total | currency}}</p> | 85 | <p class="text-center font-weight-bold text-white py-2 h3 px-2">{{articuloService.total | currency}}</p> |
86 | </div> | 86 | </div> |
87 | </div> | 87 | </div> |
88 | <!-- CONTINUAR --> | 88 | <!-- CONTINUAR --> |
89 | <div | 89 | <div |
90 | *ngIf="articuloService.carrito.length" | 90 | *ngIf="articuloService.carrito.length" |
91 | class="row mx-3 mt-4 h-auto justify-content-end"> | 91 | class="row mx-3 mt-4 h-auto justify-content-end"> |
92 | <div | 92 | <div |
93 | class="col-auto py-2 px-3 align-self-center btn-effect bg-primary badge-pill text-white" | 93 | class="col-auto py-2 px-3 align-self-center btn-effect bg-primary badge-pill text-white" |
94 | [routerLink]="['/forma-pago']"> | 94 | (click)="validateCarrito()"> |
95 | <span> | 95 | <span> |
96 | <small class="pr-2">CONTINUAR</small> | 96 | <small class="pr-2">CONTINUAR</small> |
97 | <img | 97 | <img |
98 | draggable="false" | 98 | draggable="false" |
99 | ondragstart="return false;" | 99 | ondragstart="return false;" |
100 | (contextmenu)="false" | 100 | (contextmenu)="false" |
101 | class="icon-20" | 101 | class="icon-20" |
102 | src="assets/img/ir.svg"> | 102 | src="assets/img/ir.svg"> |
103 | </span> | 103 | </span> |
104 | </div> | 104 | </div> |
105 | </div> | 105 | </div> |
106 | </div> | 106 | </div> |
107 | 107 | ||
108 | </div> | 108 | </div> |
109 | 109 |
src/app/modules/carrito/carrito.component.ts
1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; |
2 | import { Location } from '@angular/common'; | 2 | import { Location } from '@angular/common'; |
3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
6 | import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; | 6 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
8 | import { ANIMATIONS } from 'src/app/utils/animations'; | 8 | import { ANIMATIONS } from 'src/app/utils/animations'; |
9 | import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; | ||
10 | import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; | ||
9 | 11 | ||
10 | @Component({ | 12 | @Component({ |
11 | selector: 'app-carrito', | 13 | selector: 'app-carrito', |
12 | templateUrl: './carrito.component.html', | 14 | templateUrl: './carrito.component.html', |
13 | styleUrls: ['./carrito.component.scss'], | 15 | styleUrls: ['./carrito.component.scss'], |
14 | animations: [ANIMATIONS.EnterLeaveX] | 16 | animations: [ANIMATIONS.EnterLeaveX] |
15 | }) | 17 | }) |
16 | export class CarritoComponent implements OnInit, OnDestroy { | 18 | export class CarritoComponent implements OnInit, OnDestroy { |
17 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 19 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
18 | maxCantidad = 50; | 20 | maxCantidad = 50; |
19 | modalRef: BsModalRef; | 21 | modalRef: BsModalRef; |
20 | 22 | ||
21 | constructor( | 23 | constructor( |
22 | public articuloService: ArticuloService, | 24 | public articuloService: ArticuloService, |
23 | private location: Location, | 25 | private location: Location, |
24 | private router: Router, | 26 | private router: Router, |
25 | private inactiveScreen: InactiveScreenService, | 27 | private inactiveScreen: InactiveScreenService, |
28 | private modalService: BsModalService | ||
26 | ) { } | 29 | ) { } |
27 | 30 | ||
28 | ngOnInit() { | 31 | ngOnInit() { |
29 | if (!this.articuloService.carrito.length) { | 32 | if (!this.articuloService.carrito.length) { |
30 | this.router.navigate(['']); | 33 | this.router.navigate(['']); |
31 | return; | 34 | return; |
32 | } | 35 | } |
33 | this.mediaPantalla(); | 36 | this.mediaPantalla(); |
34 | } | 37 | } |
35 | 38 | ||
36 | ngOnDestroy() { | 39 | ngOnDestroy() { |
37 | if (this.modalRef) this.modalRef.hide(); | 40 | if (this.modalRef) this.modalRef.hide(); |
38 | } | 41 | } |
39 | 42 | ||
40 | deleteArticulo(index: number) { | 43 | deleteArticulo(index: number) { |
41 | this.articuloService.deleteArticulo(index); | 44 | this.articuloService.deleteArticulo(index); |
42 | } | 45 | } |
43 | 46 | ||
47 | validateCarrito() { | ||
48 | const res = this.articuloService.validateCarrito() | ||
49 | if (res.valid) { | ||
50 | this.router.navigate(['forma-pago']); | ||
51 | } else { | ||
52 | this.modalService.show( | ||
53 | ErrorStockComponent, | ||
54 | { | ||
55 | initialState: { articulo: res.articulo }, | ||
56 | class: 'modal-dialog-centered' | ||
57 | }); | ||
58 | } | ||
59 | } | ||
60 | |||
44 | goBack() { | 61 | goBack() { |
45 | this.location.back(); | 62 | this.location.back(); |
46 | } | 63 | } |
47 | 64 | ||
48 | @HostListener('document:click', ['$event']) | 65 | @HostListener('document:click', ['$event']) |
49 | eventListener(event: Event) { | 66 | eventListener(event: Event) { |
50 | clearTimeout(this.inactiveScreen.timerReposo); | 67 | clearTimeout(this.inactiveScreen.timerReposo); |
51 | this.inactiveScreen.startTimeOutInactividad(); | 68 | this.inactiveScreen.startTimeOutInactividad(); |
52 | } | 69 | } |
53 | 70 | ||
54 | @HostListener('scroll', ['$event']) | 71 | @HostListener('scroll', ['$event']) |
55 | scrollEvent(event: Event) { | 72 | scrollEvent(event: Event) { |
56 | clearTimeout(this.inactiveScreen.timerReposo); | 73 | clearTimeout(this.inactiveScreen.timerReposo); |
57 | this.inactiveScreen.startTimeOutInactividad(); | 74 | this.inactiveScreen.startTimeOutInactividad(); |
58 | } | 75 | } |
59 | 76 | ||
60 | mediaPantalla() { | 77 | mediaPantalla() { |
61 | if ($('body').hasClass('media-pantalla')) { | 78 | if ($('body').hasClass('media-pantalla')) { |
62 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); | 79 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); |
63 | } | 80 | } |
64 | } | 81 | } |
65 | } | 82 | } |
66 | 83 |
src/app/modules/carrito/carrito.module.ts
1 | import { NgModule } from '@angular/core'; | 1 | import { NgModule } from '@angular/core'; |
2 | import { CommonModule } from '@angular/common'; | 2 | import { CommonModule } from '@angular/common'; |
3 | 3 | ||
4 | import { CarritoRoutingModule } from './carrito-routing.module'; | 4 | import { CarritoRoutingModule } from './carrito-routing.module'; |
5 | import { CarritoComponent } from './carrito.component'; | 5 | import { CarritoComponent } from './carrito.component'; |
6 | import { SeleccionArticulosModule } from '../seleccion-articulos/seleccion-articulos.module'; | 6 | import { SeleccionArticulosModule } from '../seleccion-articulos/seleccion-articulos.module'; |
7 | import { SharedModule } from '../shared/shared.module'; | 7 | import { SharedModule } from '../shared/shared.module'; |
8 | import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; | ||
8 | 9 | ||
9 | @NgModule({ | 10 | @NgModule({ |
10 | declarations: [CarritoComponent], | 11 | declarations: [ |
12 | CarritoComponent, | ||
13 | ErrorStockComponent | ||
14 | ], | ||
11 | imports: [ | 15 | imports: [ |
12 | CommonModule, | 16 | CommonModule, |
13 | CarritoRoutingModule, | 17 | CarritoRoutingModule, |
14 | SeleccionArticulosModule, | 18 | SeleccionArticulosModule, |
15 | SharedModule, | 19 | SharedModule, |
16 | ] | 20 | ], |
21 | entryComponents: [ErrorStockComponent] | ||
17 | }) | 22 | }) |
18 | export class CarritoModule { } | 23 | export class CarritoModule { } |
19 | 24 |
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 | import { NoStockComponent } from './no-stock/no-stock.component'; | 15 | import { NoStockComponent } from './no-stock/no-stock.component'; |
16 | import { DateExtension } from 'src/app/utils/dateExtension'; | 16 | import { DateExtension } from 'src/app/utils/dateExtension'; |
17 | 17 | ||
18 | @Component({ | 18 | @Component({ |
19 | selector: 'app-seleccion-articulos', | 19 | selector: 'app-seleccion-articulos', |
20 | templateUrl: './seleccion-articulos.component.html', | 20 | templateUrl: './seleccion-articulos.component.html', |
21 | styleUrls: ['./seleccion-articulos.component.scss'], | 21 | styleUrls: ['./seleccion-articulos.component.scss'], |
22 | animations: [ANIMATIONS.EnterLeaveY] | 22 | animations: [ANIMATIONS.EnterLeaveY] |
23 | }) | 23 | }) |
24 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { | 24 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { |
25 | loading = true; | 25 | loading = true; |
26 | timeoutHandler: any; | 26 | timeoutHandler: any; |
27 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 27 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
28 | articulos: IArticulo[] = []; | 28 | articulos: IArticulo[] = []; |
29 | auxArticulos: IArticulo[] = []; | 29 | auxArticulos: IArticulo[] = []; |
30 | showQuantity = 100; | 30 | showQuantity = 100; |
31 | searchTerm = ''; | 31 | searchTerm = ''; |
32 | ordenandoByVendidos = true; | 32 | ordenandoByVendidos = true; |
33 | modalRef: BsModalRef; | 33 | modalRef: BsModalRef; |
34 | total = 0; | 34 | total = 0; |
35 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; | 35 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; |
36 | 36 | ||
37 | constructor( | 37 | constructor( |
38 | public articuloService: ArticuloService, | 38 | public articuloService: ArticuloService, |
39 | private sinonimoService: SinonimoService, | 39 | private sinonimoService: SinonimoService, |
40 | private modalService: BsModalService, | 40 | private modalService: BsModalService, |
41 | private inactiveScreen: InactiveScreenService, | 41 | private inactiveScreen: InactiveScreenService, |
42 | ) { } | 42 | ) { } |
43 | 43 | ||
44 | ngOnInit() { } | 44 | ngOnInit() { } |
45 | 45 | ||
46 | ngAfterViewInit(): void { | 46 | ngAfterViewInit(): void { |
47 | this.filtroCategorias.getCategorias(); | 47 | this.filtroCategorias.getCategorias(); |
48 | this.mediaPantalla(); | 48 | this.mediaPantalla(); |
49 | } | 49 | } |
50 | 50 | ||
51 | ngOnDestroy() { | 51 | ngOnDestroy() { |
52 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 52 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { |
53 | this.modalService.hide(i); | 53 | this.modalService.hide(i); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | getProductos() { | 57 | getProductos() { |
58 | this.articuloService.getAll() | 58 | this.articuloService.getAll() |
59 | .subscribe((result: IArticulo[]) => { | 59 | .subscribe((result: IArticulo[]) => { |
60 | this.articuloService.setArticulosSinImagen(result); | 60 | this.articuloService.setArticulosSinImagen(result); |
61 | if (this.filtroCategorias.queMostrar === 'ordenar') { | 61 | if (this.filtroCategorias.queMostrar === 'ordenar') { |
62 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { | 62 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { |
63 | const tempArticulos = result.filter((articulo: IArticulo) => { | 63 | const tempArticulos = result.filter((articulo: IArticulo) => { |
64 | return articulo.categoria_selfservice === categoria.id; | 64 | return articulo.categoria_selfservice === categoria.id; |
65 | }); | 65 | }); |
66 | result = tempArticulos; | 66 | result = tempArticulos; |
67 | }); | 67 | }); |
68 | } | 68 | } |
69 | localStorage.setItem('articulos', JSON.stringify(result)); | 69 | localStorage.setItem('articulos', JSON.stringify(result)); |
70 | this.setProductos(); | 70 | this.setProductos(); |
71 | }, (error) => { | 71 | }, (error) => { |
72 | console.error(error); | 72 | console.error(error); |
73 | }); | 73 | }); |
74 | } | 74 | } |
75 | 75 | ||
76 | setProductos() { | 76 | setProductos() { |
77 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 77 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
78 | this.filterItems(); | 78 | this.filterItems(); |
79 | this.loading = false; | 79 | this.loading = false; |
80 | } | 80 | } |
81 | 81 | ||
82 | filterItems() { | 82 | filterItems() { |
83 | if (this.filtroCategorias.categoriaActive === 0) { | 83 | if (this.filtroCategorias.categoriaActive === 0) { |
84 | this.auxArticulos = this.articulos; | 84 | this.auxArticulos = this.articulos; |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | this.auxArticulos = this.articulos.filter(x => { | 87 | this.auxArticulos = this.articulos.filter(x => { |
88 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; | 88 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; |
89 | }); | 89 | }); |
90 | this.ordenar(); | 90 | this.ordenar(); |
91 | } | 91 | } |
92 | 92 | ||
93 | ordenar() { | 93 | ordenar() { |
94 | if (this.ordenandoByVendidos) { | 94 | if (this.ordenandoByVendidos) { |
95 | this.auxArticulos.sort((a, b) => { | 95 | this.auxArticulos.sort((a, b) => { |
96 | return b.cantidadVendida - a.cantidadVendida; | 96 | return b.cantidadVendida - a.cantidadVendida; |
97 | }); | 97 | }); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | selectArticulo(articulo: IArticulo) { | 101 | selectArticulo(articulo: IArticulo) { |
102 | if (articulo.ExiVta < 1) { | 102 | if (articulo.ExiVta < 1) { |
103 | if (this.modalRef) return; | 103 | if (this.modalRef) return; |
104 | this.modalRef = this.modalService.show(NoStockComponent, { | 104 | this.modalRef = this.modalService.show(NoStockComponent, { |
105 | class: 'modal-dialog-centered', | 105 | class: 'modal-dialog-centered', |
106 | backdrop: false, | 106 | backdrop: false, |
107 | ignoreBackdropClick: true, | 107 | ignoreBackdropClick: true, |
108 | }); | 108 | }); |
109 | this.modalRef.content.onClose | 109 | this.modalRef.content.onClose |
110 | .subscribe(() => this.modalRef = null); | 110 | .subscribe(() => this.modalRef = null); |
111 | } else { | 111 | } else { |
112 | this.getByID(articulo.id); | 112 | this.getByID(articulo.id); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | getByID(id: number) { | 116 | getByID(id: number) { |
117 | this.articuloService.getById(id) | 117 | this.articuloService.getById(id) |
118 | .subscribe((res: IArticulo) => { | 118 | .subscribe((res: IArticulo) => { |
119 | if (res.FPP) { | 119 | if (res.FPP) { |
120 | this.openModalPromos(res); | 120 | this.openModalPromos(res); |
121 | } else { | 121 | } else { |
122 | this.getSinonimos(res); | 122 | this.getSinonimos(res); |
123 | } | 123 | } |
124 | }, err => console.error(err)); | 124 | }, err => console.error(err)); |
125 | } | 125 | } |
126 | 126 | ||
127 | getSinonimos(articulo: IArticulo) { | 127 | getSinonimos(articulo: IArticulo) { |
128 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 128 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
129 | .subscribe((res: any[]) => { | 129 | .subscribe((res: any[]) => { |
130 | if (res.length) { | 130 | if (res.length) { |
131 | const sinonimos = []; | 131 | const sinonimos = []; |
132 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); | 132 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); |
133 | Object.keys(gruposArticulos).forEach(key => { | 133 | Object.keys(gruposArticulos).forEach(key => { |
134 | sinonimos.push({ productos: gruposArticulos[key], }); | 134 | sinonimos.push({ productos: gruposArticulos[key], }); |
135 | }); | 135 | }); |
136 | for (let j = 0; j < articulo.productos.length; j++) { | 136 | for (const a of articulo.productos) { |
137 | Object.keys(gruposArticulos).forEach((key, i) => { | 137 | Object.keys(gruposArticulos).forEach((key, i) => { |
138 | if (gruposArticulos[key][i].ID_SIN.toString() === articulo.productos[j].idSinonimo.toString()) { | 138 | if (gruposArticulos[key][i].ID_SIN.toString() === a.idSinonimo.toString()) { |
139 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = articulo.productos[j].cantidad; | 139 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; |
140 | } | 140 | } |
141 | }); | 141 | }); |
142 | } | 142 | } |
143 | res = sinonimos; | 143 | res = sinonimos; |
144 | this.openModalSinonimos(res, articulo); | 144 | this.openModalSinonimos(res, articulo); |
145 | } else { | 145 | } else { |
146 | this.articuloService.setArticulo(articulo); | 146 | this.articuloService.setArticulo(articulo); |
147 | } | 147 | } |
148 | }); | 148 | }); |
149 | } | 149 | } |
150 | 150 | ||
151 | openModalPromos(articulo: IArticulo) { | 151 | openModalPromos(articulo: IArticulo) { |
152 | if (this.modalRef) return; | 152 | if (this.modalRef) return; |
153 | this.articuloService.setArticulosSinImagen([articulo]); | 153 | this.articuloService.setArticulosSinImagen([articulo]); |
154 | this.modalRef = this.modalService.show(PromocionComponent, { | 154 | this.modalRef = this.modalService.show(PromocionComponent, { |
155 | initialState: { articulosPromo: [articulo] }, | 155 | initialState: { articulosPromo: [articulo] }, |
156 | class: 'modal-dialog-centered', | 156 | class: 'modal-dialog-centered', |
157 | ignoreBackdropClick: true, | 157 | ignoreBackdropClick: true, |
158 | }); | 158 | }); |
159 | this.modalRef.content.onClose | 159 | this.modalRef.content.onClose |
160 | .subscribe(() => this.modalRef = null); | 160 | .subscribe(() => this.modalRef = null); |
161 | this.mediaPantalla(); | 161 | this.mediaPantalla(); |
162 | } | 162 | } |
163 | 163 | ||
164 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 164 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
165 | if (this.modalRef) return; | 165 | if (this.modalRef) return; |
166 | this.modalRef = this.modalService.show(SinonimoComponent, { | 166 | this.modalRef = this.modalService.show(SinonimoComponent, { |
167 | initialState: { | 167 | initialState: { |
168 | sinonimos: sinonimosData, | 168 | sinonimos: sinonimosData, |
169 | articulo | 169 | articulo |
170 | }, | 170 | }, |
171 | class: 'modal-dialog-centered', | 171 | class: 'modal-dialog-centered', |
172 | ignoreBackdropClick: true, | 172 | ignoreBackdropClick: true, |
173 | }); | 173 | }); |
174 | 174 | ||
175 | this.modalRef.content.onClose | 175 | this.modalRef.content.onClose |
176 | .subscribe((res: any) => { | 176 | .subscribe((res: any) => { |
177 | this.modalRef = null; | 177 | this.modalRef = null; |
178 | if (!res) return; | 178 | if (!res) return; |
179 | articulo.productos = res.articulos; | 179 | articulo.productos = res.articulos; |
180 | this.articuloService.setArticulo(articulo); | 180 | this.articuloService.setArticulo(articulo); |
181 | }); | 181 | }); |
182 | this.mediaPantalla(); | 182 | this.mediaPantalla(); |
183 | } | 183 | } |
184 | 184 | ||
185 | deleteArticulo(index: number) { | 185 | deleteArticulo(index: number) { |
186 | this.articuloService.deleteArticulo(index); | 186 | this.articuloService.deleteArticulo(index); |
187 | } | 187 | } |
188 | 188 | ||
189 | increaseShow() { | 189 | increaseShow() { |
190 | this.showQuantity += 100; | 190 | this.showQuantity += 100; |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | validarFecha(fechaInicio: string, fechaFin: string) { | 194 | validarFecha(fechaInicio: string, fechaFin: string) { |
195 | return DateExtension.ValidateDateRange(fechaInicio, fechaFin); | 195 | return DateExtension.ValidateDateRange(fechaInicio, fechaFin); |
196 | } | 196 | } |
197 | 197 | ||
198 | @HostListener('scroll', ['$event']) | 198 | @HostListener('scroll', ['$event']) |
199 | scrollEvent(event: Event) { | 199 | scrollEvent(event: Event) { |
200 | clearTimeout(this.inactiveScreen.timerReposo); | 200 | clearTimeout(this.inactiveScreen.timerReposo); |
201 | this.inactiveScreen.startTimeOutInactividad(); | 201 | this.inactiveScreen.startTimeOutInactividad(); |
202 | } | 202 | } |
203 | 203 | ||
204 | mouseup() { | 204 | mouseup() { |
205 | if (!this.timeoutHandler) return; | 205 | if (!this.timeoutHandler) return; |
206 | clearInterval(this.timeoutHandler); | 206 | clearInterval(this.timeoutHandler); |
207 | } | 207 | } |
208 | 208 | ||
209 | scrollY(el: HTMLElement, value) { | 209 | scrollY(el: HTMLElement, value) { |
210 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 210 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
211 | this.timeoutHandler = setInterval(() => { | 211 | this.timeoutHandler = setInterval(() => { |
212 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 212 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
213 | }, 500); | 213 | }, 500); |
214 | } | 214 | } |
215 | 215 | ||
216 | scrollX(el: HTMLElement, value) { | 216 | scrollX(el: HTMLElement, value) { |
217 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 217 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
218 | this.timeoutHandler = setInterval(() => { | 218 | this.timeoutHandler = setInterval(() => { |
219 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 219 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
220 | }, 500); | 220 | }, 500); |
221 | } | 221 | } |
222 | 222 | ||
223 | mediaPantalla() { | 223 | mediaPantalla() { |
224 | if ($('body').hasClass('media-pantalla')) { | 224 | if ($('body').hasClass('media-pantalla')) { |
225 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 225 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
226 | .cat-box,.img-categoria, .modal-content`) | 226 | .cat-box,.img-categoria, .modal-content`) |
227 | .addClass('media-pantalla') | 227 | .addClass('media-pantalla') |
228 | .addBack('media-pantalla'); | 228 | .addBack('media-pantalla'); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 |
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 | 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 | substractCant(articulo: IArticulo) { | 37 | substractCant(articulo: IArticulo) { |
38 | if (articulo.cantidad === 1) return; | 38 | if (articulo.cantidad === 1) return; |
39 | articulo.cantidad--; | 39 | articulo.cantidad--; |
40 | this.calcularTotal(); | 40 | this.calcularTotal(); |
41 | } | 41 | } |
42 | 42 | ||
43 | addCant(articulo: IArticulo) { | 43 | addCant(articulo: IArticulo) { |
44 | if (articulo.cantidad >= articulo.ExiVta) return; | ||
45 | articulo.cantidad++; | 44 | articulo.cantidad++; |
46 | this.calcularTotal(); | 45 | this.calcularTotal(); |
47 | } | 46 | } |
48 | 47 | ||
49 | calcularTotal() { | 48 | calcularTotal() { |
50 | this.total = 0; | 49 | this.total = 0; |
51 | this.carrito.forEach(articulo => { | 50 | this.carrito.forEach(articulo => { |
52 | this.total += (articulo.PreVen * articulo.cantidad); | 51 | this.total += (articulo.PreVen * articulo.cantidad); |
53 | }); | 52 | }); |
54 | } | 53 | } |
55 | 54 | ||
56 | setArticulo(articulo: IArticulo) { | 55 | setArticulo(articulo: IArticulo) { |
57 | articulo.cantidad = 1; | 56 | articulo.cantidad = 1; |
58 | for (const articuloCarrito of this.carrito) { | 57 | for (const articuloCarrito of this.carrito) { |
59 | if (articuloCarrito.id === articulo.id && !articulo.productos) { | 58 | if (articuloCarrito.id === articulo.id) { |
60 | articuloCarrito.cantidad++; | 59 | if (!articuloCarrito.productos) break; |
61 | this.calcularTotal(); | 60 | let samePromo = false; |
61 | articuloCarrito.productos.forEach((a, i) => { | ||
62 | samePromo = (a.id === articulo.productos[i].id); | ||
63 | }); | ||
64 | if (!samePromo) break; | ||
65 | this.addCant(articuloCarrito); | ||
62 | return; | 66 | return; |
63 | } | 67 | } |
64 | } | 68 | } |
65 | this.setArticulosSinImagen([articulo]); | 69 | this.setArticulosSinImagen([articulo]); |
66 | this.carrito.unshift(articulo); | 70 | this.carrito.unshift(articulo); |
67 | this.calcularTotal(); | 71 | this.calcularTotal(); |
68 | } | 72 | } |
69 | 73 | ||
70 | deleteArticulo(index: number) { | 74 | deleteArticulo(index: number) { |
71 | this.carrito.splice(index, 1); | 75 | this.carrito.splice(index, 1); |
72 | this.calcularTotal(); | 76 | this.calcularTotal(); |
73 | } | 77 | } |
74 | 78 | ||
75 | pay(dataPago: any) { | 79 | pay(dataPago: any) { |
76 | return new Observable((observer) => { | 80 | return new Observable((observer) => { |
77 | this.clienteService.getById(-1) | 81 | this.clienteService.getById(-1) |
78 | .subscribe(cliente => { | 82 | .subscribe(cliente => { |
79 | this.markArticuloInPromoAsRemoved(); | 83 | this.markArticuloInPromoAsRemoved(); |
80 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { | 84 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { |
81 | productos: this.carrito, | 85 | productos: this.carrito, |
82 | cliente, | 86 | cliente, |
83 | origen: 'autoservicio', | 87 | origen: 'autoservicio', |
84 | codigoVendedor: 5, | 88 | codigoVendedor: 5, |
85 | puntoVenta: APP_SETTINGS.puntoVenta, | 89 | puntoVenta: APP_SETTINGS.puntoVenta, |
86 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 90 | pedidoAnombreDe: dataPago.pedidoAnombreDe, |
87 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, | 91 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, |
88 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), | 92 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), |
89 | terminal: APP_SETTINGS.terminal, | 93 | terminal: APP_SETTINGS.terminal, |
90 | contactLess: dataPago.contactLess === 'true' ? true : false, | 94 | contactLess: dataPago.contactLess === 'true' ? true : false, |
91 | }) | 95 | }) |
92 | .subscribe((data) => { | 96 | .subscribe((data) => { |
93 | observer.next(data); | 97 | observer.next(data); |
94 | observer.complete(); | 98 | observer.complete(); |
95 | }, err => { | 99 | }, err => { |
96 | observer.error(err); | 100 | observer.error(err); |
97 | observer.complete(); | 101 | observer.complete(); |
98 | }); | 102 | }); |
99 | }); | 103 | }); |
100 | }); | 104 | }); |
101 | } | 105 | } |
102 | 106 | ||
107 | validateCarrito() { | ||
108 | for (const articulo of this.carrito) { | ||
109 | if (articulo.productos) { | ||
110 | for (const a of articulo.productos) { | ||
111 | if (a.ExiVta - (a.cantidad * articulo.cantidad) < 0) return { valid: false, articulo }; | ||
112 | } | ||
113 | } else if (articulo.ExiVta - articulo.cantidad < 0) return { valid: false, articulo }; | ||
114 | } | ||
115 | return { valid: true }; | ||
116 | } | ||
117 | |||
103 | cleanShoppingCar() { | 118 | cleanShoppingCar() { |
104 | this.articuloAcargar = undefined; | 119 | this.articuloAcargar = undefined; |
105 | this.promoAcargar = undefined; | 120 | this.promoAcargar = undefined; |
106 | this.carrito = []; | 121 | this.carrito = []; |
107 | this.calcularTotal(); | 122 | this.calcularTotal(); |
108 | } | 123 | } |
109 | 124 | ||
110 | setArticulosSinImagen(articulos: IArticulo[]) { | 125 | setArticulosSinImagen(articulos: IArticulo[]) { |
111 | articulos.forEach((articulo: IArticulo) => { | 126 | articulos.forEach((articulo: IArticulo) => { |
112 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 127 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : |
113 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 128 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; |
114 | }); | 129 | }); |
115 | } | 130 | } |
116 | 131 | ||
117 | markArticuloInPromoAsRemoved() { | 132 | markArticuloInPromoAsRemoved() { |
118 | this.carrito.forEach((articuloCarrito: IArticulo) => { | 133 | this.carrito.forEach((articuloCarrito: IArticulo) => { |
119 | if (articuloCarrito.PRO) { | 134 | if (articuloCarrito.PRO) { |
120 | articuloCarrito.productos.forEach((articulo: IArticulo) => { | 135 | articuloCarrito.productos.forEach((articulo: IArticulo) => { |
121 | if (articulo.cantidadAdicionada === 0) { | 136 | if (articulo.cantidadAdicionada === 0) { |
122 | articulo.cantidad = 0; | 137 | articulo.cantidad = 0; |
123 | articulo.importeValorExtra = 0; | 138 | articulo.importeValorExtra = 0; |
124 | } | 139 | } |
125 | }); | 140 | }); |
126 | } | 141 | } |
127 | }); | 142 | }); |
128 | } | 143 | } |
129 | 144 | ||
130 | changeArticulo(articuloToChange: IArticulo, articuloData: any) { | 145 | changeArticulo(articuloToChange: IArticulo, articuloData: any) { |
131 | articuloToChange.CODA = articuloData.CodArt; | 146 | articuloToChange.CODA = articuloData.CodArt; |
132 | articuloToChange.CodArt = articuloData.CodArt; | 147 | articuloToChange.CodArt = articuloData.CodArt; |
133 | articuloToChange.SECA = articuloData.CodSec; | 148 | articuloToChange.SECA = articuloData.CodSec; |
134 | articuloToChange.CodSec = articuloData.CodSec; | 149 | articuloToChange.CodSec = articuloData.CodSec; |
135 | articuloToChange.PreVen = articuloData.PreVen; | 150 | articuloToChange.PreVen = articuloData.PreVen; |
136 | articuloToChange.id = articuloData.id; | 151 | articuloToChange.id = articuloData.id; |
137 | articuloToChange.DET_LAR = articuloData.DET_LAR; | 152 | articuloToChange.DET_LAR = articuloData.DET_LAR; |
138 | articuloToChange.DetArt = articuloData.DetArt; | 153 | articuloToChange.DetArt = articuloData.DetArt; |
139 | articuloToChange.MKT_DESC = articuloData.MKT_DESC; | 154 | articuloToChange.MKT_DESC = articuloData.MKT_DESC; |
140 | } | 155 | } |
141 | } | 156 | } |
src/app/shared/error-stock/error-stock.component.html
File was created | 1 | <div class="bg-primary text-center rounded"> | |
2 | <div class="modal-body"> | ||
3 | <p class="h4 text-white text-center mx-3 mb-3">El articulo {{articulo.MKT_DESC}} no tiene stock</p> | ||
4 | <div | ||
5 | class="m-0 h4 d-inline-block py-2 btn-effect bg-white badge-pill" | ||
6 | (click)="modalRef.hide()"> | ||
7 | Aceptar | ||
8 | </div> | ||
9 | </div> | ||
10 | </div> | ||
11 |
src/app/shared/error-stock/error-stock.component.scss
src/app/shared/error-stock/error-stock.component.spec.ts
File was created | 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
2 | |||
3 | import { ErrorStockComponent } from './error-stock.component'; | ||
4 | |||
5 | describe('ErrorStockComponent', () => { | ||
6 | let component: ErrorStockComponent; | ||
7 | let fixture: ComponentFixture<ErrorStockComponent>; | ||
8 | |||
9 | beforeEach(async(() => { | ||
10 | TestBed.configureTestingModule({ | ||
11 | declarations: [ ErrorStockComponent ] | ||
12 | }) | ||
13 | .compileComponents(); | ||
14 | })); | ||
15 | |||
16 | beforeEach(() => { | ||
17 | fixture = TestBed.createComponent(ErrorStockComponent); | ||
18 | component = fixture.componentInstance; | ||
19 | fixture.detectChanges(); | ||
20 | }); | ||
21 | |||
22 | it('should create', () => { | ||
23 | expect(component).toBeTruthy(); | ||
24 | }); | ||
25 | }); | ||
26 |
src/app/shared/error-stock/error-stock.component.ts
File was created | 1 | import { Component, OnInit } from '@angular/core'; | |
2 | import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'app-error-stock', | ||
7 | templateUrl: './error-stock.component.html', | ||
8 | styleUrls: ['./error-stock.component.scss'] | ||
9 | }) | ||
10 | export class ErrorStockComponent implements OnInit { | ||
11 | articulo: IArticulo; | ||
12 | |||
13 | constructor( | ||
14 | private modalRef: BsModalRef, | ||
15 | ) { } | ||
16 | |||
17 | ngOnInit() { } | ||
18 | |||
19 | } | ||
20 |
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 | import { NoStockComponent } from 'src/app/modules/seleccion-articulos/no-stock/no-stock.component'; | 14 | import { NoStockComponent } from 'src/app/modules/seleccion-articulos/no-stock/no-stock.component'; |
15 | 15 | ||
16 | @Component({ | 16 | @Component({ |
17 | selector: 'app-header-publicidad', | 17 | selector: 'app-header-publicidad', |
18 | templateUrl: './header-publicidad.component.html', | 18 | templateUrl: './header-publicidad.component.html', |
19 | styleUrls: ['./header-publicidad.component.scss'] | 19 | styleUrls: ['./header-publicidad.component.scss'] |
20 | }) | 20 | }) |
21 | export class HeaderPublicidadComponent implements OnInit { | 21 | export class HeaderPublicidadComponent implements OnInit { |
22 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 22 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
23 | publicidades: IPublicidad[] = []; | 23 | publicidades: IPublicidad[] = []; |
24 | modalRef: BsModalRef; | 24 | modalRef: BsModalRef; |
25 | modalSinonimo: BsModalRef; | 25 | modalSinonimo: BsModalRef; |
26 | 26 | ||
27 | constructor( | 27 | constructor( |
28 | private publicidadService: PublicidadService, | 28 | private publicidadService: PublicidadService, |
29 | private articuloService: ArticuloService, | 29 | private articuloService: ArticuloService, |
30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
31 | private sinonimoService: SinonimoService | 31 | private sinonimoService: SinonimoService |
32 | ) { } | 32 | ) { } |
33 | 33 | ||
34 | ngOnInit() { | 34 | ngOnInit() { |
35 | this.getPublicidades(); | 35 | this.getPublicidades(); |
36 | this.mediaPantalla(); | 36 | this.mediaPantalla(); |
37 | } | 37 | } |
38 | 38 | ||
39 | getPublicidades() { | 39 | getPublicidades() { |
40 | this.publicidadService.getAll() | 40 | this.publicidadService.getAll() |
41 | .subscribe((res: IPublicidad[]) => { | 41 | .subscribe((res: IPublicidad[]) => { |
42 | this.publicidades = res; | 42 | this.publicidades = res; |
43 | }, err => console.error(err)); | 43 | }, err => console.error(err)); |
44 | } | 44 | } |
45 | 45 | ||
46 | elegirArticulo(publicidad: IPublicidad) { | 46 | elegirArticulo(publicidad: IPublicidad) { |
47 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 47 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); |
48 | } | 48 | } |
49 | 49 | ||
50 | getByID(id: number) { | 50 | getByID(id: number) { |
51 | this.articuloService.getById(id) | 51 | this.articuloService.getById(id) |
52 | .subscribe((res: IArticulo) => { | 52 | .subscribe((res: IArticulo) => { |
53 | if (res.ExiVta < 1) { | 53 | if (res.ExiVta < 1) { |
54 | if (this.modalRef) return; | 54 | if (this.modalRef) return; |
55 | this.modalRef = this.modalService.show(NoStockComponent, { | 55 | this.modalRef = this.modalService.show(NoStockComponent, { |
56 | class: 'modal-dialog-centered', | 56 | class: 'modal-dialog-centered', |
57 | backdrop: false, | 57 | backdrop: false, |
58 | ignoreBackdropClick: true, | 58 | ignoreBackdropClick: true, |
59 | }); | 59 | }); |
60 | this.modalRef.content.onClose | 60 | this.modalRef.content.onClose |
61 | .subscribe(() => this.modalRef = null); | 61 | .subscribe(() => this.modalRef = null); |
62 | } else { | 62 | } else { |
63 | if (res.FPP) { | 63 | if (res.FPP) { |
64 | this.openModalPromos(res); | 64 | this.openModalPromos(res); |
65 | return; | 65 | return; |
66 | } else { | 66 | } else { |
67 | this.openModalConfirmacion(res); | 67 | this.openModalConfirmacion(res); |
68 | return; | 68 | return; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
72 | } | 72 | } |
73 | 73 | ||
74 | openModalPromos(articulo: IArticulo) { | 74 | openModalPromos(articulo: IArticulo) { |
75 | if (this.modalRef) return; | 75 | if (this.modalRef) return; |
76 | this.modalRef = this.modalService.show(PromocionComponent, | 76 | this.modalRef = this.modalService.show(PromocionComponent, |
77 | { | 77 | { |
78 | initialState: { | 78 | initialState: { |
79 | idArticulo: articulo.id | 79 | idArticulo: articulo.id |
80 | }, | 80 | }, |
81 | class: 'modal-dialog-centered' | 81 | class: 'modal-dialog-centered' |
82 | }); | 82 | }); |
83 | } | 83 | } |
84 | 84 | ||
85 | openModalConfirmacion(articulo: IArticulo) { | 85 | openModalConfirmacion(articulo: IArticulo) { |
86 | if (this.modalRef) return; | 86 | if (this.modalRef) return; |
87 | this.articuloService.setArticulosSinImagen([articulo]); | 87 | this.articuloService.setArticulosSinImagen([articulo]); |
88 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 88 | this.modalRef = this.modalService.show(ConfirmacionComponent, |
89 | { | 89 | { |
90 | initialState: { | 90 | initialState: { |
91 | titleMessage: articulo.DET_LAR, | 91 | titleMessage: articulo.DET_LAR, |
92 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 92 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', |
93 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, | 93 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, |
94 | footerMessageSecond: `a tu carrito?`, | 94 | footerMessageSecond: `a tu carrito?`, |
95 | footerConfirmation: articulo.PreVen | 95 | footerConfirmation: articulo.PreVen |
96 | }, | 96 | }, |
97 | ignoreBackdropClick: true, | 97 | ignoreBackdropClick: true, |
98 | class: 'modal-dialog-centered' | 98 | class: 'modal-dialog-centered' |
99 | }); | 99 | }); |
100 | this.modalRef.content.onClose.subscribe((resClose) => { | 100 | this.modalRef.content.onClose.subscribe((resClose) => { |
101 | this.modalRef = null; | 101 | this.modalRef = null; |
102 | if (!resClose) return; | 102 | if (!resClose) return; |
103 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 103 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
104 | .subscribe((res: ISinonimo[]) => { | 104 | .subscribe((res: ISinonimo[]) => { |
105 | if (res.length) { | 105 | if (res.length) { |
106 | const sinonimos = []; | 106 | const sinonimos = []; |
107 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); | 107 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); |
108 | Object.keys(gruposArticulos).forEach(key => { | 108 | Object.keys(gruposArticulos).forEach(key => { |
109 | sinonimos.push({ productos: gruposArticulos[key], }); | 109 | sinonimos.push({ productos: gruposArticulos[key], }); |
110 | }); | 110 | }); |
111 | for (let j = 0; j < articulo.productos.length; j++) { | 111 | for (const a of articulo.productos) { |
112 | Object.keys(gruposArticulos).forEach((key, i) => { | 112 | Object.keys(gruposArticulos).forEach((key, i) => { |
113 | if (gruposArticulos[key][i].ID_SIN.toString() === articulo.productos[j].idSinonimo.toString()) { | 113 | if (gruposArticulos[key][i].ID_SIN.toString() === a.idSinonimo.toString()) { |
114 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = articulo.productos[j].cantidad; | 114 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; |
115 | } | 115 | } |
116 | }); | 116 | }); |
117 | } | 117 | } |
118 | res = sinonimos; | 118 | res = sinonimos; |
119 | this.openModalSinonimos(res, articulo); | 119 | this.openModalSinonimos(res, articulo); |
120 | } else { | 120 | } else { |
121 | articulo.cantidad = 1; | 121 | articulo.cantidad = 1; |
122 | this.articuloService.setArticulo(articulo); | 122 | this.articuloService.setArticulo(articulo); |
123 | } | 123 | } |
124 | }, err => console.error(err)); | 124 | }, err => console.error(err)); |
125 | }); | 125 | }); |
126 | this.mediaPantalla(); | 126 | this.mediaPantalla(); |
127 | } | 127 | } |
128 | 128 | ||
129 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 129 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
130 | if (this.modalSinonimo) return; | 130 | if (this.modalSinonimo) return; |
131 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 131 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
132 | initialState: { | 132 | initialState: { |
133 | sinonimos: sinonimosData, | 133 | sinonimos: sinonimosData, |
134 | articulo | 134 | articulo |
135 | }, | 135 | }, |
136 | class: 'modal-dialog-centered' | 136 | class: 'modal-dialog-centered' |
137 | }); | 137 | }); |
138 | this.modalSinonimo.content.onClose | 138 | this.modalSinonimo.content.onClose |
139 | .subscribe((res: any) => { | 139 | .subscribe((res: any) => { |
140 | this.modalSinonimo = null; | 140 | this.modalSinonimo = null; |
141 | if (!res) return; | 141 | if (!res) return; |
142 | articulo.productos = res.articulos; | 142 | articulo.productos = res.articulos; |
143 | this.articuloService.setArticulo(articulo); | 143 | this.articuloService.setArticulo(articulo); |
144 | }); | 144 | }); |
145 | } | 145 | } |
146 | 146 | ||
147 | mediaPantalla() { | 147 | mediaPantalla() { |
148 | if ($('body').hasClass('media-pantalla')) { | 148 | if ($('body').hasClass('media-pantalla')) { |
149 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 149 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 |
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.articuloService.getById(promo.id) | 46 | this.articuloService.getById(promo.id) |
47 | .subscribe((resPromo: IArticulo) => { | 47 | .subscribe((resPromo: IArticulo) => { |
48 | promo = resPromo; | 48 | promo = resPromo; |
49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
50 | .subscribe((res: ISinonimo[]) => { | 50 | .subscribe((res: ISinonimo[]) => { |
51 | if (res.length) { | 51 | if (res.length) { |
52 | const sinonimos = []; | 52 | const sinonimos = []; |
53 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); | 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ORDEN_P'); |
54 | Object.keys(gruposArticulos).forEach(key => { | 54 | Object.keys(gruposArticulos).forEach(key => { |
55 | sinonimos.push({ productos: gruposArticulos[key], }); | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
56 | }); | 56 | }); |
57 | for (let j = 0; j < promo.productos.length; j++) { | 57 | for (const promoProducto of promo.productos) { |
58 | Object.keys(gruposArticulos).forEach((key, i) => { | 58 | Object.keys(gruposArticulos).forEach((key, i) => { |
59 | if (gruposArticulos[key][i].ID_SIN.toString() === promo.productos[j].idSinonimo.toString()) { | 59 | if (gruposArticulos[key][i].ID_SIN.toString() === promoProducto.idSinonimo.toString()) { |
60 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = promo.productos[j].cantidad; | 60 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = promoProducto.cantidad; |
61 | } | 61 | } |
62 | }); | 62 | }); |
63 | } | 63 | } |
64 | res = sinonimos; | ||
65 | this.openModalSinonimos(res, promo); | 64 | this.openModalSinonimos(res, promo); |
66 | } else { | 65 | } else { |
67 | promo.cantidad = 1; | 66 | promo.cantidad = 1; |
68 | this.articuloService.setArticulo(promo); | 67 | this.articuloService.setArticulo(promo); |
69 | this.onClose.next(); | 68 | this.onClose.next(); |
70 | this.modalPromocion.hide(); | 69 | this.modalPromocion.hide(); |
71 | } | 70 | } |
72 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
73 | }, err => console.error(err)); | 72 | }, err => console.error(err)); |
74 | this.mediaPantalla(); | 73 | this.mediaPantalla(); |
75 | } | 74 | } |
76 | 75 | ||
77 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
78 | if (this.modalSinonimo) return; | 77 | if (this.modalSinonimo) return; |
79 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
80 | initialState: { | 79 | initialState: { |
81 | sinonimos: sinonimosData, | 80 | sinonimos: sinonimosData, |
82 | articulo | 81 | articulo |
83 | }, | 82 | }, |
84 | class: 'modal-dialog-centered', | 83 | class: 'modal-dialog-centered', |
85 | ignoreBackdropClick: true, | 84 | ignoreBackdropClick: true, |
86 | }); | 85 | }); |
87 | 86 | ||
88 | this.modalSinonimo.content.onClose | 87 | this.modalSinonimo.content.onClose |
89 | .subscribe((res: any) => { | 88 | .subscribe((res: any) => { |
90 | this.modalSinonimo = null; | 89 | this.modalSinonimo = null; |
91 | if (!res) { | 90 | if (!res) { |
92 | this.onClose.next(); | 91 | this.onClose.next(); |
93 | this.modalPromocion.hide(); | 92 | this.modalPromocion.hide(); |
94 | return; | 93 | return; |
95 | } | 94 | } |
96 | articulo.productos = res.articulos; | 95 | articulo.productos = res.articulos; |
97 | this.articuloService.setArticulo(articulo); | 96 | this.articuloService.setArticulo(articulo); |
98 | this.onClose.next(); | 97 | this.onClose.next(); |
99 | this.modalPromocion.hide(); | 98 | this.modalPromocion.hide(); |
100 | }); | 99 | }); |
101 | } | 100 | } |
102 | 101 | ||
103 | getPromociones() { | 102 | getPromociones() { |
104 | const sector = this.articulosPromo[0].CodSec; | 103 | const sector = this.articulosPromo[0].CodSec; |
105 | const codigo = this.articulosPromo[0].CodArt; | 104 | const codigo = this.articulosPromo[0].CodArt; |
106 | this.promocionService.getPromociones(sector, codigo) | 105 | this.promocionService.getPromociones(sector, codigo) |
107 | .subscribe((res: IArticulo[]) => { | 106 | .subscribe((res: IArticulo[]) => { |
108 | res = res.filter(a => a.ExiVta > 0); | 107 | res = res.filter(a => a.ExiVta > 0); |
109 | this.loading = false; | 108 | this.loading = false; |
110 | this.promociones = res; | 109 | this.promociones = res; |
111 | }, error => { console.error(error); }); | 110 | }, error => { console.error(error); }); |
112 | } | 111 | } |
113 | 112 | ||
114 | @HostListener('document:click', ['$event']) | 113 | @HostListener('document:click', ['$event']) |
115 | eventListener(event: Event) { | 114 | eventListener(event: Event) { |
116 | clearTimeout(this.inactiveScreen.timerReposo); | 115 | clearTimeout(this.inactiveScreen.timerReposo); |
117 | this.inactiveScreen.startTimeOutInactividad(); | 116 | this.inactiveScreen.startTimeOutInactividad(); |
118 | } | 117 | } |
119 | 118 | ||
120 | @HostListener('scroll', ['$event']) | 119 | @HostListener('scroll', ['$event']) |
121 | scrollEvent(event: Event) { | 120 | scrollEvent(event: Event) { |
122 | clearTimeout(this.inactiveScreen.timerReposo); | 121 | clearTimeout(this.inactiveScreen.timerReposo); |
123 | this.inactiveScreen.startTimeOutInactividad(); | 122 | this.inactiveScreen.startTimeOutInactividad(); |
124 | } | 123 | } |
125 | 124 | ||
126 | mediaPantalla() { | 125 | mediaPantalla() { |
127 | if ($('body').hasClass('media-pantalla')) { | 126 | if ($('body').hasClass('media-pantalla')) { |
128 | $('.modal-content').addClass('media-pantalla'); | 127 | $('.modal-content').addClass('media-pantalla'); |
129 | } | 128 | } |
130 | } | 129 | } |
131 | } | 130 | } |
132 | 131 |