Commit 36f686b8f8e2fa6e0507e3559161f704d8eda733
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !154
Showing
4 changed files
Show diff stats
src/app/services/articulo/articulo.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; | 3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; |
4 | import { IArticulo } from '../../interfaces/IArticulo'; | 4 | import { IArticulo } from '../../interfaces/IArticulo'; |
5 | import { ClienteService } from '../cliente/cliente.service'; | 5 | import { ClienteService } from '../cliente/cliente.service'; |
6 | import { Observable } from 'rxjs'; | 6 | import { Observable } from 'rxjs'; |
7 | 7 | ||
8 | @Injectable() | 8 | @Injectable() |
9 | export class ArticuloService { | 9 | export class ArticuloService { |
10 | carrito: IArticulo[] = []; | 10 | carrito: IArticulo[] = []; |
11 | articuloAcargar: IArticulo; | 11 | articuloAcargar: IArticulo; |
12 | promoAcargar: IArticulo; | 12 | promoAcargar: IArticulo; |
13 | mostrar: string; | 13 | mostrar: string; |
14 | esPromoPersonalizada = false; | 14 | esPromoPersonalizada = false; |
15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; |
16 | medioPago: number; | 16 | medioPago: number; |
17 | idComanda: number; | 17 | idComanda: number; |
18 | total = 0; | 18 | total = 0; |
19 | maxCantidad = 50; | ||
20 | 19 | ||
21 | constructor( | 20 | constructor( |
22 | private http: HttpClient, | 21 | private http: HttpClient, |
23 | private clienteService: ClienteService, | 22 | private clienteService: ClienteService, |
24 | ) { } | 23 | ) { } |
25 | 24 | ||
26 | getById(id) { | 25 | getById(id) { |
27 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); | 26 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); |
28 | } | 27 | } |
29 | 28 | ||
30 | getAll() { | 29 | getAll() { |
31 | return this.http.get(`${this.urlDeboSuite}/articulos/`); | 30 | return this.http.get(`${this.urlDeboSuite}/articulos/`); |
32 | } | 31 | } |
33 | 32 | ||
34 | getAllWithPaginator(page: number = 1) { | 33 | getAllWithPaginator(page: number = 1) { |
35 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); | 34 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); |
36 | } | 35 | } |
37 | 36 | ||
38 | substractCant(articulo: IArticulo) { | 37 | substractCant(articulo: IArticulo) { |
39 | if (articulo.cantidad === 1) return; | 38 | if (articulo.cantidad === 1) return; |
40 | articulo.cantidad--; | 39 | articulo.cantidad--; |
41 | this.calcularTotal(); | 40 | this.calcularTotal(); |
42 | } | 41 | } |
43 | 42 | ||
44 | addCant(articulo: IArticulo) { | 43 | addCant(articulo: IArticulo) { |
45 | if (articulo.cantidad >= this.maxCantidad) return; | 44 | if (articulo.cantidad >= articulo.ExiVta) return; |
46 | articulo.cantidad++; | 45 | articulo.cantidad++; |
47 | this.calcularTotal(); | 46 | this.calcularTotal(); |
48 | } | 47 | } |
49 | 48 | ||
50 | calcularTotal() { | 49 | calcularTotal() { |
51 | this.total = 0; | 50 | this.total = 0; |
52 | this.carrito.forEach(articulo => { | 51 | this.carrito.forEach(articulo => { |
53 | this.total += (articulo.PreVen * articulo.cantidad); | 52 | this.total += (articulo.PreVen * articulo.cantidad); |
54 | }); | 53 | }); |
55 | } | 54 | } |
56 | 55 | ||
57 | setArticulo(articulo: IArticulo) { | 56 | setArticulo(articulo: IArticulo) { |
58 | articulo.cantidad = 1; | 57 | articulo.cantidad = 1; |
59 | for (const articuloCarrito of this.carrito) { | 58 | for (const articuloCarrito of this.carrito) { |
60 | if (articuloCarrito.id === articulo.id && !articulo.productos) { | 59 | if (articuloCarrito.id === articulo.id && !articulo.productos) { |
61 | articuloCarrito.cantidad++; | 60 | articuloCarrito.cantidad++; |
62 | this.calcularTotal(); | 61 | this.calcularTotal(); |
63 | return; | 62 | return; |
64 | } | 63 | } |
65 | } | 64 | } |
66 | this.setArticulosSinImagen([articulo]); | 65 | this.setArticulosSinImagen([articulo]); |
67 | this.carrito.unshift(articulo); | 66 | this.carrito.unshift(articulo); |
68 | this.calcularTotal(); | 67 | this.calcularTotal(); |
69 | } | 68 | } |
70 | 69 | ||
71 | deleteArticulo(index: number) { | 70 | deleteArticulo(index: number) { |
72 | this.carrito.splice(index, 1); | 71 | this.carrito.splice(index, 1); |
73 | this.calcularTotal(); | 72 | this.calcularTotal(); |
74 | } | 73 | } |
75 | 74 | ||
76 | pay(dataPago: any) { | 75 | pay(dataPago: any) { |
77 | return new Observable((observer) => { | 76 | return new Observable((observer) => { |
78 | this.clienteService.getById(-1) | 77 | this.clienteService.getById(-1) |
79 | .subscribe(cliente => { | 78 | .subscribe(cliente => { |
80 | this.markArticuloInPromoAsRemoved(); | 79 | this.markArticuloInPromoAsRemoved(); |
81 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { | 80 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { |
82 | productos: this.carrito, | 81 | productos: this.carrito, |
83 | cliente, | 82 | cliente, |
84 | origen: 'autoservicio', | 83 | origen: 'autoservicio', |
85 | codigoVendedor: 5, | 84 | codigoVendedor: 5, |
86 | puntoVenta: APP_SETTINGS.puntoVenta, | 85 | puntoVenta: APP_SETTINGS.puntoVenta, |
87 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 86 | pedidoAnombreDe: dataPago.pedidoAnombreDe, |
88 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, | 87 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, |
89 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), | 88 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), |
90 | terminal: APP_SETTINGS.terminal, | 89 | terminal: APP_SETTINGS.terminal, |
91 | contactLess: true, | 90 | contactLess: true, |
92 | }) | 91 | }) |
93 | .subscribe((data) => { | 92 | .subscribe((data) => { |
94 | observer.next(data); | 93 | observer.next(data); |
95 | observer.complete(); | 94 | observer.complete(); |
96 | }, err => { | 95 | }, err => { |
97 | observer.error(err); | 96 | observer.error(err); |
98 | observer.complete(); | 97 | observer.complete(); |
99 | }); | 98 | }); |
100 | }); | 99 | }); |
101 | }); | 100 | }); |
102 | } | 101 | } |
103 | 102 | ||
104 | cleanShoppingCar() { | 103 | cleanShoppingCar() { |
105 | this.articuloAcargar = undefined; | 104 | this.articuloAcargar = undefined; |
106 | this.promoAcargar = undefined; | 105 | this.promoAcargar = undefined; |
107 | this.carrito = []; | 106 | this.carrito = []; |
108 | this.calcularTotal(); | 107 | this.calcularTotal(); |
109 | } | 108 | } |
110 | 109 | ||
111 | setArticulosSinImagen(articulos: IArticulo[]) { | 110 | setArticulosSinImagen(articulos: IArticulo[]) { |
112 | articulos.forEach((articulo: IArticulo) => { | 111 | articulos.forEach((articulo: IArticulo) => { |
113 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 112 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : |
114 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 113 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; |
115 | }); | 114 | }); |
116 | } | 115 | } |
117 | 116 | ||
118 | markArticuloInPromoAsRemoved() { | 117 | markArticuloInPromoAsRemoved() { |
119 | this.carrito.forEach((articuloCarrito: IArticulo) => { | 118 | this.carrito.forEach((articuloCarrito: IArticulo) => { |
120 | if (articuloCarrito.PRO) { | 119 | if (articuloCarrito.PRO) { |
121 | articuloCarrito.productos.forEach((articulo: IArticulo) => { | 120 | articuloCarrito.productos.forEach((articulo: IArticulo) => { |
122 | if (articulo.cantidadAdicionada === 0) { | 121 | if (articulo.cantidadAdicionada === 0) { |
123 | articulo.cantidad = 0; | 122 | articulo.cantidad = 0; |
124 | articulo.importeValorExtra = 0; | 123 | articulo.importeValorExtra = 0; |
125 | } | 124 | } |
126 | }); | 125 | }); |
127 | } | 126 | } |
128 | }); | 127 | }); |
129 | } | 128 | } |
130 | 129 | ||
131 | changeArticulo(articuloToChange: IArticulo, articuloData: any) { | 130 | changeArticulo(articuloToChange: IArticulo, articuloData: any) { |
132 | articuloToChange.CODA = articuloData.CodArt; | 131 | articuloToChange.CODA = articuloData.CodArt; |
133 | articuloToChange.CodArt = articuloData.CodArt; | 132 | articuloToChange.CodArt = articuloData.CodArt; |
134 | articuloToChange.SECA = articuloData.CodSec; | 133 | articuloToChange.SECA = articuloData.CodSec; |
135 | articuloToChange.CodSec = articuloData.CodSec; | 134 | articuloToChange.CodSec = articuloData.CodSec; |
136 | articuloToChange.PreVen = articuloData.PreVen; | 135 | articuloToChange.PreVen = articuloData.PreVen; |
137 | articuloToChange.id = articuloData.id; | 136 | articuloToChange.id = articuloData.id; |
138 | articuloToChange.DET_LAR = articuloData.DET_LAR; | 137 | articuloToChange.DET_LAR = articuloData.DET_LAR; |
139 | articuloToChange.DetArt = articuloData.DetArt; | 138 | articuloToChange.DetArt = articuloData.DetArt; |
140 | articuloToChange.MKT_DESC = articuloData.MKT_DESC; | 139 | articuloToChange.MKT_DESC = articuloData.MKT_DESC; |
141 | } | 140 | } |
142 | } | 141 | } |
143 | 142 |
src/app/shared/promocion/promocion.component.html
1 | <div class="bg-primary rounded"> | 1 | <div class="bg-primary rounded"> |
2 | <div class="modal-header" *ngIf="articulosPromo.length"> | 2 | <div class="modal-header" *ngIf="articulosPromo.length"> |
3 | <img | 3 | <img |
4 | draggable="false" | 4 | draggable="false" |
5 | ondragstart="return false;" | 5 | ondragstart="return false;" |
6 | (contextmenu)="false" | 6 | (contextmenu)="false" |
7 | (click)="selectPromo(articulosPromo[0])" | 7 | (click)="selectPromo(articulosPromo[0])" |
8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" | 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" |
9 | src="assets/img/icono-cancelar-blanco.svg"> | 9 | src="assets/img/icono-cancelar-blanco.svg"> |
10 | <div class="row w-100 no-gutters justify-content-between"> | 10 | <div class="row w-100 no-gutters justify-content-between"> |
11 | <div class="col align-self-center"> | 11 | <div class="col align-self-center"> |
12 | <p class="h3 text-white">{{articulosPromo[0].MKT_DESC ? articulosPromo[0].MKT_DESC.toUpperCase() : articulosPromo[0].DetArt.toUpperCase()}}</p> | 12 | <p class="h3 text-white">{{articulosPromo[0].MKT_DESC ? articulosPromo[0].MKT_DESC.toUpperCase() : articulosPromo[0].DetArt.toUpperCase()}}</p> |
13 | </div> | 13 | </div> |
14 | <div class="col-auto align-self-center mt-4 pl-2"> | 14 | <div class="col-auto align-self-center mt-4 pl-2"> |
15 | <div | 15 | <div |
16 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" | 16 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" |
17 | (click)="selectPromo(articulosPromo[0])"> | 17 | (click)="selectPromo(articulosPromo[0])"> |
18 | <div class="col-auto align-self-center text-primary"> | 18 | <div class="col-auto align-self-center text-primary"> |
19 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> | 19 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> |
20 | </div> | 20 | </div> |
21 | <div class="col-auto px-0"> | 21 | <div class="col-auto px-0"> |
22 | <img | 22 | <img |
23 | draggable="false" | 23 | draggable="false" |
24 | ondragstart="return false;" | 24 | ondragstart="return false;" |
25 | (contextmenu)="false" | 25 | (contextmenu)="false" |
26 | class="d-block ml-auto my-1 icon-20" | 26 | class="d-block ml-auto my-1 icon-20" |
27 | src="assets/img/ir-color.svg"> | 27 | src="assets/img/ir-color.svg"> |
28 | </div> | 28 | </div> |
29 | </div> | 29 | </div> |
30 | </div> | 30 | </div> |
31 | </div> | 31 | </div> |
32 | </div> | 32 | </div> |
33 | <div class="modal-body" *ngIf="articulosPromo.length"> | 33 | <div class="modal-body" *ngIf="articulosPromo.length"> |
34 | <div class="row no-gutters w-100"> | 34 | <div |
35 | class="row no-gutters w-100" | ||
36 | *ngIf="promociones.length && !loading"> | ||
35 | <div class="col-9 col-9 align-self-center"> | 37 | <div class="col-9 col-9 align-self-center"> |
36 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> | 38 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> |
37 | <p class="h1 text-white">en un combo?</p> | 39 | <p class="h1 text-white">en un combo?</p> |
38 | </div> | 40 | </div> |
39 | <div class="col-3"> | 41 | <div class="col-3"> |
40 | <img | 42 | <img |
41 | draggable="false" | 43 | draggable="false" |
42 | ondragstart="return false;" | 44 | ondragstart="return false;" |
43 | (contextmenu)="false" | 45 | (contextmenu)="false" |
44 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" | 46 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" |
45 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" | 47 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" |
46 | class="card-img-top img-fluid rounded-circle"> | 48 | class="card-img-top img-fluid rounded-circle"> |
47 | </div> | 49 | </div> |
48 | </div> | 50 | </div> |
51 | <div> | ||
52 | <div | ||
53 | class="row no-gutters w-100" | ||
54 | *ngIf="!promociones.length && !loading"> | ||
55 | <div class="col-12 text-center"> | ||
56 | <p class="text-white"><small>NO HAY PROMOS CON STOCK</small></p> | ||
57 | </div> | ||
58 | </div> | ||
49 | <div | 59 | <div |
50 | class="d-flex justify-content-center mt-2" | 60 | class="d-flex justify-content-center mt-2" |
51 | *ngIf="loading"> | 61 | *ngIf="loading"> |
52 | <div class="spinner-border text-white" role="status"> | 62 | <div class="spinner-border text-white" role="status"> |
53 | <span class="sr-only">Loading...</span> | 63 | <span class="sr-only">Loading...</span> |
54 | </div> | 64 | </div> |
55 | </div> | 65 | </div> |
56 | <div | 66 | <div |
57 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" | 67 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" |
58 | (scroll)="scrollEvent($event)"> | 68 | (scroll)="scrollEvent($event)"> |
59 | <div class="col-12"> | 69 | <div class="col-12"> |
60 | <div *ngFor="let promo of promociones; let i = index"> | 70 | <div *ngFor="let promo of promociones; let i = index"> |
61 | <div | 71 | <div |
62 | [ngClass]="{ 'mt-2': i !== 0 }" | 72 | [ngClass]="{ 'mt-2': i !== 0 }" |
63 | class="btn-effect bg-white badge-pill text-primary" | 73 | class="btn-effect bg-white badge-pill text-primary" |
64 | (click)="selectPromo(promo)"> | 74 | (click)="selectPromo(promo)"> |
65 | <div class="d-flex"> | 75 | <div class="d-flex"> |
66 | <p class="text-truncate mr-auto my-auto"><small>{{promo.MKT_DESC ? promo.MKT_DESC.toUpperCase() : promo.DetArt.toUpperCase()}}</small></p> | 76 | <p class="text-truncate mr-auto my-auto"><small>{{promo.MKT_DESC ? promo.MKT_DESC.toUpperCase() : promo.DetArt.toUpperCase()}}</small></p> |
67 | <p class="font-weight-bold ml-auto my-auto pr-2"> | 77 | <p class="font-weight-bold ml-auto my-auto pr-2"> |
68 | <span>{{promo.PreVen | currency}}</span> | 78 | <span>{{promo.PreVen | currency}}</span> |
69 | </p> | 79 | </p> |
70 | <img | 80 | <img |
71 | draggable="false" | 81 | draggable="false" |
72 | ondragstart="return false;" | 82 | ondragstart="return false;" |
73 | (contextmenu)="false" | 83 | (contextmenu)="false" |
74 | class="d-block py-1 icon-30" | 84 | class="d-block py-1 icon-30" |
75 | src="assets/img/ir-color.svg"> | 85 | src="assets/img/ir-color.svg"> |
76 | </div> | 86 | </div> |
77 | </div> | 87 | </div> |
78 | </div> | 88 | </div> |
79 | </div> | 89 | </div> |
80 | </div> | 90 | </div> |
81 | </div> | 91 | </div> |
82 | </div> | 92 | </div> |
83 | 93 |
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, 'ID_SIN'); | 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
54 | Object.keys(gruposArticulos).forEach((key, i) => { | 54 | Object.keys(gruposArticulos).forEach((key, i) => { |
55 | sinonimos.push({ productos: gruposArticulos[key], }); | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
56 | for (const a of promo.productos) { | 56 | for (const a of promo.productos) { |
57 | if (key === a.idSinonimo.toString()) { | 57 | if (key === a.idSinonimo.toString()) { |
58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | 58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; |
59 | continue; | 59 | continue; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | }); | 62 | }); |
63 | res = sinonimos; | 63 | res = sinonimos; |
64 | this.openModalSinonimos(res, promo); | 64 | this.openModalSinonimos(res, promo); |
65 | } else { | 65 | } else { |
66 | promo.cantidad = 1; | 66 | promo.cantidad = 1; |
67 | this.articuloService.setArticulo(promo); | 67 | this.articuloService.setArticulo(promo); |
68 | this.onClose.next(); | 68 | this.onClose.next(); |
69 | this.modalPromocion.hide(); | 69 | this.modalPromocion.hide(); |
70 | } | 70 | } |
71 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
72 | }, err => console.error(err)); | 72 | }, err => console.error(err)); |
73 | this.mediaPantalla(); | 73 | this.mediaPantalla(); |
74 | } | 74 | } |
75 | 75 | ||
76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
77 | if (this.modalSinonimo) return; | 77 | if (this.modalSinonimo) return; |
78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
79 | initialState: { | 79 | initialState: { |
80 | sinonimos: sinonimosData, | 80 | sinonimos: sinonimosData, |
81 | articulo | 81 | articulo |
82 | }, | 82 | }, |
83 | class: 'modal-dialog-centered', | 83 | class: 'modal-dialog-centered', |
84 | ignoreBackdropClick: true, | 84 | ignoreBackdropClick: true, |
85 | }); | 85 | }); |
86 | 86 | ||
87 | this.modalSinonimo.content.onClose | 87 | this.modalSinonimo.content.onClose |
88 | .subscribe((res: any) => { | 88 | .subscribe((res: any) => { |
89 | this.modalSinonimo = null; | 89 | this.modalSinonimo = null; |
90 | if (!res) { | 90 | if (!res) { |
91 | this.onClose.next(); | 91 | this.onClose.next(); |
92 | this.modalPromocion.hide(); | 92 | this.modalPromocion.hide(); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | articulo.productos = res.articulos; | 95 | articulo.productos = res.articulos; |
96 | this.articuloService.setArticulo(articulo); | 96 | this.articuloService.setArticulo(articulo); |
97 | this.onClose.next(); | 97 | this.onClose.next(); |
98 | this.modalPromocion.hide(); | 98 | this.modalPromocion.hide(); |
99 | }); | 99 | }); |
100 | } | 100 | } |
101 | 101 | ||
102 | getPromociones() { | 102 | getPromociones() { |
103 | const sector = this.articulosPromo[0].CodSec; | 103 | const sector = this.articulosPromo[0].CodSec; |
104 | const codigo = this.articulosPromo[0].CodArt; | 104 | const codigo = this.articulosPromo[0].CodArt; |
105 | this.promocionService.getPromociones(sector, codigo) | 105 | this.promocionService.getPromociones(sector, codigo) |
106 | .subscribe((res: IArticulo[]) => { | 106 | .subscribe((res: IArticulo[]) => { |
107 | this.promociones = res; | 107 | res = res.filter(a => a.ExiVta > 0); |
108 | this.loading = false; | 108 | this.loading = false; |
109 | this.promociones = res; | ||
109 | }, error => { console.error(error); }); | 110 | }, error => { console.error(error); }); |
110 | } | 111 | } |
111 | 112 | ||
112 | @HostListener('document:click', ['$event']) | 113 | @HostListener('document:click', ['$event']) |
113 | eventListener(event: Event) { | 114 | eventListener(event: Event) { |
114 | clearTimeout(this.inactiveScreen.timerReposo); | 115 | clearTimeout(this.inactiveScreen.timerReposo); |
115 | this.inactiveScreen.startTimeOutInactividad(); | 116 | this.inactiveScreen.startTimeOutInactividad(); |
116 | } | 117 | } |
117 | 118 | ||
118 | @HostListener('scroll', ['$event']) | 119 | @HostListener('scroll', ['$event']) |
119 | scrollEvent(event: Event) { | 120 | scrollEvent(event: Event) { |
120 | clearTimeout(this.inactiveScreen.timerReposo); | 121 | clearTimeout(this.inactiveScreen.timerReposo); |
121 | this.inactiveScreen.startTimeOutInactividad(); | 122 | this.inactiveScreen.startTimeOutInactividad(); |
122 | } | 123 | } |
123 | 124 | ||
124 | mediaPantalla() { | 125 | mediaPantalla() { |
125 | if ($('body').hasClass('media-pantalla')) { | 126 | if ($('body').hasClass('media-pantalla')) { |
126 | $('.modal-content').addClass('media-pantalla'); | 127 | $('.modal-content').addClass('media-pantalla'); |
127 | } | 128 | } |
128 | } | 129 | } |
129 | } | 130 | } |
130 | 131 |
src/app/shared/sinonimo/sinonimo.component.html
1 | <div class="bg-primary rounded text-white"> | 1 | <div class="bg-primary rounded text-white"> |
2 | <div class="modal-header"> | 2 | <div class="modal-header"> |
3 | <img | 3 | <img |
4 | draggable="false" | 4 | draggable="false" |
5 | ondragstart="return false;" | 5 | ondragstart="return false;" |
6 | (contextmenu)="false" | 6 | (contextmenu)="false" |
7 | (click)="close()" | 7 | (click)="close()" |
8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute right-0 top-0 z-index" | 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute right-0 top-0 z-index" |
9 | src="assets/img/icono-cancelar-blanco.svg"> | 9 | src="assets/img/icono-cancelar-blanco.svg"> |
10 | <p class="col-12 h4 px-0 align-self-center">{{ articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase() }}</p> | 10 | <p class="col-12 h4 px-0 align-self-center">{{ articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase() }}</p> |
11 | </div> | 11 | </div> |
12 | 12 | ||
13 | <div class="modal-body my-2"> | 13 | <div class="modal-body my-2"> |
14 | <p class="mb-2 h4">Opcion {{currentIndex+1}}</p> | 14 | <p class="mb-2 h4">Opcion {{currentIndex+1}}</p> |
15 | <p class="mb-2 h5">Cantidad restante {{sinonimos[currentIndex].cantidadRestante}}</p> | 15 | <p class="mb-2 h5">Cantidad restante {{sinonimos[currentIndex].cantidadRestante}}</p> |
16 | <div class="lista-sinonimos scroll-y-visible"> | 16 | <div class="lista-sinonimos scroll-y-visible"> |
17 | <div | 17 | <div |
18 | class="row mx-0 mb-2 fade-in-left" | 18 | class="row mx-0 mb-2 fade-in-left" |
19 | *ngFor="let articulo of sinonimos[currentIndex].productos"> | 19 | *ngFor="let articulo of sinonimos[currentIndex].productos" |
20 | [hidden]="articulo.ExiVta <= 0"> | ||
20 | <div class="col-8 p-0 my-auto h6 text-right"> | 21 | <div class="col-8 p-0 my-auto h6 text-right"> |
21 | <p class="m-0 font-weight-normal"> | 22 | <p class="m-0 font-weight-normal"> |
22 | {{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}} | 23 | {{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}} |
23 | </p> | 24 | </p> |
24 | </div> | 25 | </div> |
25 | <div class="col-4"> | 26 | <div class="col-4"> |
26 | <div class="row mx-0 justify-content-between border border-white badge-pill"> | 27 | <div class="row mx-0 justify-content-between border border-white badge-pill"> |
27 | <!-- BOTON MENOS --> | 28 | <!-- BOTON MENOS --> |
28 | <div class="col-auto px-0 my-auto"> | 29 | <div class="col-auto px-0 my-auto"> |
29 | <img | 30 | <img |
30 | draggable="false" | 31 | draggable="false" |
31 | ondragstart="return false;" | 32 | ondragstart="return false;" |
32 | (contextmenu)="false" | 33 | (contextmenu)="false" |
33 | class="d-block ml-auto py-2 icon-30 btn-effect" | 34 | class="d-block ml-auto py-2 icon-30 btn-effect" |
34 | src="assets/img/menos-blanco.svg" | 35 | src="assets/img/menos-blanco.svg" |
35 | (click)="restarCantidadSinonimo(articulo, currentIndex)"> | 36 | (click)="restarCantidadSinonimo(articulo, currentIndex)"> |
36 | </div> | 37 | </div> |
37 | <!-- CANTIDAD --> | 38 | <!-- CANTIDAD --> |
38 | <div class="col px-0 my-auto text-white text-center"> | 39 | <div class="col px-0 my-auto text-white text-center"> |
39 | <p>{{articulo.cantidad}}</p> | 40 | <p>{{articulo.cantidad}}</p> |
40 | </div> | 41 | </div> |
41 | <!-- BOTON MAS --> | 42 | <!-- BOTON MAS --> |
42 | <div class="col-auto px-0 my-auto"> | 43 | <div class="col-auto px-0 my-auto"> |
43 | <img | 44 | <img |
44 | draggable="false" | 45 | draggable="false" |
45 | ondragstart="return false;" | 46 | ondragstart="return false;" |
46 | (contextmenu)="false" | 47 | (contextmenu)="false" |
47 | class="d-block ml-auto py-2 icon-30 btn-effect" | 48 | class="d-block ml-auto py-2 icon-30 btn-effect" |
48 | src="assets/img/mas-blanco.svg" | 49 | src="assets/img/mas-blanco.svg" |
49 | (click)="sumarCantidadSinonimo(articulo, currentIndex)"> | 50 | (click)="sumarCantidadSinonimo(articulo, currentIndex)"> |
50 | </div> | 51 | </div> |
51 | </div> | 52 | </div> |
52 | </div> | 53 | </div> |
53 | </div> | 54 | </div> |
54 | </div> | 55 | </div> |
55 | 56 | ||
56 | </div> | 57 | </div> |
57 | 58 | ||
58 | <div class="modal-footer"> | 59 | <div class="modal-footer"> |
59 | <div | 60 | <div |
60 | *ngIf="currentIndex != 0 && sinonimos.length > 1" | 61 | *ngIf="currentIndex != 0 && sinonimos.length > 1" |
61 | class="d-inline-block py-1 bg-white badge-pill text-primary btn-effect mr-auto fade-in-right" | 62 | class="d-inline-block py-1 bg-white badge-pill text-primary btn-effect mr-auto fade-in-right" |
62 | (click)="currentIndex = currentIndex-1"> | 63 | (click)="currentIndex = currentIndex-1"> |
63 | <img | 64 | <img |
64 | draggable="false" | 65 | draggable="false" |
65 | ondragstart="return false;" | 66 | ondragstart="return false;" |
66 | (contextmenu)="false" | 67 | (contextmenu)="false" |
67 | class="icon-30 flip" | 68 | class="icon-30 flip" |
68 | src="assets/img/ir-color.svg"> | 69 | src="assets/img/ir-color.svg"> |
69 | VOLVER | 70 | VOLVER |
70 | </div> | 71 | </div> |
71 | <div | 72 | <div |
72 | [ngClass]="validateNext()" | 73 | [ngClass]="validateNext()" |
73 | *ngIf="currentIndex != sinonimos.length-1" | 74 | *ngIf="currentIndex != sinonimos.length-1" |
74 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" | 75 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" |
75 | (click)="goNext()"> | 76 | (click)="goNext()"> |
76 | SIGUIENTE | 77 | SIGUIENTE |
77 | <img | 78 | <img |
78 | draggable="false" | 79 | draggable="false" |
79 | ondragstart="return false;" | 80 | ondragstart="return false;" |
80 | (contextmenu)="false" | 81 | (contextmenu)="false" |
81 | class="icon-30" | 82 | class="icon-30" |
82 | src="assets/img/ir-color.svg"> | 83 | src="assets/img/ir-color.svg"> |
83 | </div> | 84 | </div> |
84 | <div | 85 | <div |
85 | [ngClass]="validate()" | 86 | [ngClass]="validate()" |
86 | *ngIf="currentIndex == sinonimos.length-1" | 87 | *ngIf="currentIndex == sinonimos.length-1" |
87 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" | 88 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" |
88 | (click)="continue()"> | 89 | (click)="continue()"> |
89 | CONTINUAR | 90 | CONTINUAR |
90 | <img | 91 | <img |
91 | draggable="false" | 92 | draggable="false" |
92 | ondragstart="return false;" | 93 | ondragstart="return false;" |
93 | (contextmenu)="false" | 94 | (contextmenu)="false" |
94 | class="icon-30" | 95 | class="icon-30" |
95 | src="assets/img/ir-color.svg"> | 96 | src="assets/img/ir-color.svg"> |
96 | </div> | 97 | </div> |
97 | </div> | 98 | </div> |
98 | </div> | 99 | </div> |
99 | 100 |