Commit 5fe97dc032fa23ba4013473a3f5db49883dd8517

Authored by Marcelo Puebla
Exists in develop

Merge branch 'develop' into 'develop'

Develop

See merge request !162
src/app/modules/seleccion-articulos/filtro-categorias/filtro-categorias.component.html
1 <!-- FILTRO CATEGORIAS --> 1 <!-- FILTRO CATEGORIAS -->
2 <p class="h6 h-6 m-0 text-center"><small>CATEGORÍAS</small></p> 2 <p class="h6 h-6 m-0 text-center"><small>CATEGORÍAS</small></p>
3 <div class="row mx-0 h-94 justify-content-center align-items-center"> 3 <div class="row mx-0 h-94 justify-content-center align-items-center">
4 <div class="col-auto btn-effect h-5 cat-btn"> 4 <div class="col-auto btn-effect h-5 cat-btn">
5 <img
6 draggable="false"
7 ondragstart="return false;"
8 (contextmenu)="false"
9 class="h-100 d-block mx-auto rotate-90-neg"
10 src="assets/img/ir-color.svg"
11 (mousedown)="scrollY(templateCategorias, -100)"
12 (mouseup)="mouseup()"
13 (mouseleave)="mouseup()">
14 </div>
15 <!-- CATEGORIAS -->
16 <div
17 #templateCategorias
18 class="col-12 px-0 mx-0 box-categorias border border-primary py-1
19 border-left-0 rounded-right scroll-y cat-box"
20 (scroll)="scrollEvent($event)">
21 <div
22 class="row mx-2 mb-2 h-25 h-lg-30 justify-content-center tab cat-content"
23 [ngClass]="{ 'active rounded shadow px-2': allActive, 'border-bottom-effect': !allActive }"
24 (click)="selectCategoria(-1, 0)">
5 <img 25 <img
6 draggable="false" 26 draggable="false"
7 ondragstart="return false;" 27 ondragstart="return false;"
8 (contextmenu)="false" 28 (contextmenu)="false"
9 class="h-100 d-block mx-auto rotate-90-neg" 29 class="img-fluid align-self-end d-none d-sm-block rounded-circle h-100 h-md-70"
10 src="assets/img/ir-color.svg" 30 src="assets/img/logo-spot.svg">
11 (mousedown)="scrollY(templateCategorias, -100)" 31 <small class="col-12 px-0 my-1 h-100 h-md-20 align-self-end text-center text-truncate">Todos</small>
12 (mouseup)="mouseup()"
13 (mouseleave)="mouseup()">
14 </div> 32 </div>
15 <!-- CATEGORIAS -->
16 <div 33 <div
17 #templateCategorias 34 class="row mx-2 mb-2 h-25 h-lg-30 justify-content-center tab cat-content"
18 class="col-12 px-0 mx-0 box-categorias border border-primary py-1 35 [ngClass]="{
19 border-left-0 rounded-right scroll-y cat-box" 36 'active rounded shadow px-2': categoria.selected,
20 (scroll)="scrollEvent($event)"> 37 'border-bottom-effect': !categoria.selected,
21 <div 38 'media-pantalla': templateCategorias.classList.contains('media-pantalla')
22 class="row mx-2 mb-2 h-25 h-lg-30 justify-content-center tab cat-content" 39 }"
23 [ngClass]="{ 'active rounded shadow px-2': allActive, 'border-bottom-effect': !allActive }" 40 (click)="selectCategoria(i, categoria.id)"
24 (click)="selectCategoria(-1, 0)"> 41 id="cat-content"
25 <img 42 *ngFor="let categoria of categorias; let i = index;"
26 draggable="false" 43 [hidden]="categoria.articulos <= 0
27 ondragstart="return false;" 44 || validarFecha(categoria.vigencia_desde, categoria.vigencia_hasta)">
28 (contextmenu)="false"
29 class="img-fluid align-self-end d-none d-sm-block rounded-circle h-100 h-md-70"
30 src="assets/img/logo-spot.svg">
31 <small class="col-12 px-0 my-1 h-100 h-md-20 align-self-end text-center text-truncate">Todos</small>
32 </div>
33 <div
34 class="row mx-2 mb-2 h-25 h-lg-30 justify-content-center tab cat-content"
35 [ngClass]="{
36 'active rounded shadow px-2': categoria.selected,
37 'border-bottom-effect': !categoria.selected,
38 'media-pantalla': templateCategorias.classList.contains('media-pantalla')
39 }"
40 (click)="selectCategoria(i, categoria.id)"
41 id="cat-content"
42 *ngFor="let categoria of categorias; let i = index;"
43 [hidden]="categoria.articulos <= 0
44 || validarFecha(categoria.vigencia_desde, categoria.vigencia_hasta)">
45 <img
46 draggable="false"
47 ondragstart="return false;"
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 articulo.cantidad++; 44 articulo.cantidad++;
45 this.calcularTotal(); 45 this.calcularTotal();
46 } 46 }
47 47
48 calcularTotal() { 48 calcularTotal() {
49 this.total = 0; 49 this.total = 0;
50 this.carrito.forEach(articulo => { 50 this.carrito.forEach(articulo => {
51 this.total += (articulo.PreVen * articulo.cantidad); 51 this.total += (articulo.PreVen * articulo.cantidad);
52 }); 52 });
53 } 53 }
54 54
55 setArticulo(articulo: IArticulo) { 55 setArticulo(articulo: IArticulo) {
56 articulo.cantidad = 1; 56 articulo.cantidad = 1;
57 for (const articuloCarrito of this.carrito) { 57 for (const articuloCarrito of this.carrito) {
58 if (articuloCarrito.id === articulo.id) { 58 if (articuloCarrito.id === articulo.id) {
59 if (!articuloCarrito.productos) break; 59 if (!articuloCarrito.productos) break;
60 let samePromo = false; 60 let samePromo = true;
61 articuloCarrito.productos.forEach((a, i) => { 61 articuloCarrito.productos.forEach((a, i) => {
62 samePromo = (a.id === articulo.productos[i].id); 62 if (samePromo) samePromo = (a.id === articulo.productos[i].id);
63 }); 63 });
64 if (!samePromo) break; 64 if (!samePromo) break;
65 this.addCant(articuloCarrito); 65 this.addCant(articuloCarrito);
66 return; 66 return;
67 } 67 }
68 } 68 }
69 this.setArticulosSinImagen([articulo]); 69 this.setArticulosSinImagen([articulo]);
70 this.carrito.unshift(articulo); 70 this.carrito.unshift(articulo);
71 this.calcularTotal(); 71 this.calcularTotal();
72 } 72 }
73 73
74 deleteArticulo(index: number) { 74 deleteArticulo(index: number) {
75 this.carrito.splice(index, 1); 75 this.carrito.splice(index, 1);
76 this.calcularTotal(); 76 this.calcularTotal();
77 } 77 }
78 78
79 pay(dataPago: any) { 79 pay(dataPago: any) {
80 return new Observable((observer) => { 80 return new Observable((observer) => {
81 this.clienteService.getById(-1) 81 this.clienteService.getById(-1)
82 .subscribe(cliente => { 82 .subscribe(cliente => {
83 this.markArticuloInPromoAsRemoved(); 83 this.markArticuloInPromoAsRemoved();
84 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { 84 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, {
85 productos: this.carrito, 85 productos: this.carrito,
86 cliente, 86 cliente,
87 origen: 'autoservicio', 87 origen: 'autoservicio',
88 codigoVendedor: 5, 88 codigoVendedor: 5,
89 puntoVenta: APP_SETTINGS.puntoVenta, 89 puntoVenta: APP_SETTINGS.puntoVenta,
90 pedidoAnombreDe: dataPago.pedidoAnombreDe, 90 pedidoAnombreDe: dataPago.pedidoAnombreDe,
91 numeroPlanilla: APP_SETTINGS.numeroPlanilla, 91 numeroPlanilla: APP_SETTINGS.numeroPlanilla,
92 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), 92 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'),
93 terminal: APP_SETTINGS.terminal, 93 terminal: APP_SETTINGS.terminal,
94 contactLess: dataPago.contactLess === 'true' ? true : false, 94 contactLess: dataPago.contactLess === 'true' ? true : false,
95 }) 95 })
96 .subscribe((data) => { 96 .subscribe((data) => {
97 observer.next(data); 97 observer.next(data);
98 observer.complete(); 98 observer.complete();
99 }, err => { 99 }, err => {
100 observer.error(err); 100 observer.error(err);
101 observer.complete(); 101 observer.complete();
102 }); 102 });
103 }); 103 });
104 }); 104 });
105 } 105 }
106 106
107 validateCarrito() { 107 validateCarrito() {
108 for (const articulo of this.carrito) { 108 for (const articulo of this.carrito) {
109 if (articulo.productos) { 109 if (articulo.productos) {
110 for (const a of articulo.productos) { 110 for (const a of articulo.productos) {
111 if (a.ExiVta - (a.cantidad * articulo.cantidad) < 0) return { valid: false, articulo }; 111 if (a.ExiVta - (a.cantidad * articulo.cantidad) < 0) return { valid: false, articulo };
112 } 112 }
113 } else if (articulo.ExiVta - articulo.cantidad < 0) return { valid: false, articulo }; 113 } else if (articulo.ExiVta - articulo.cantidad < 0) return { valid: false, articulo };
114 } 114 }
115 return { valid: true }; 115 return { valid: true };
116 } 116 }
117 117
118 cleanShoppingCar() { 118 cleanShoppingCar() {
119 this.articuloAcargar = undefined; 119 this.articuloAcargar = undefined;
120 this.promoAcargar = undefined; 120 this.promoAcargar = undefined;
121 this.carrito = []; 121 this.carrito = [];
122 this.calcularTotal(); 122 this.calcularTotal();
123 } 123 }
124 124
125 setArticulosSinImagen(articulos: IArticulo[]) { 125 setArticulosSinImagen(articulos: IArticulo[]) {
126 articulos.forEach((articulo: IArticulo) => { 126 articulos.forEach((articulo: IArticulo) => {
127 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : 127 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] :
128 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; 128 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes;
129 }); 129 });
130 } 130 }
131 131
132 markArticuloInPromoAsRemoved() { 132 markArticuloInPromoAsRemoved() {
133 this.carrito.forEach((articuloCarrito: IArticulo) => { 133 this.carrito.forEach((articuloCarrito: IArticulo) => {
134 if (articuloCarrito.PRO) { 134 if (articuloCarrito.PRO) {
135 articuloCarrito.productos.forEach((articulo: IArticulo) => { 135 articuloCarrito.productos.forEach((articulo: IArticulo) => {
136 if (articulo.cantidadAdicionada === 0) { 136 if (articulo.cantidadAdicionada === 0) {
137 articulo.cantidad = 0; 137 articulo.cantidad = 0;
138 articulo.importeValorExtra = 0; 138 articulo.importeValorExtra = 0;
139 } 139 }
140 }); 140 });
141 } 141 }
142 }); 142 });
143 } 143 }
144 144
145 changeArticulo(articuloToChange: IArticulo, articuloData: any) { 145 changeArticulo(articuloToChange: IArticulo, articuloData: any) {
146 articuloToChange.CODA = articuloData.CodArt; 146 articuloToChange.CODA = articuloData.CodArt;
147 articuloToChange.CodArt = articuloData.CodArt; 147 articuloToChange.CodArt = articuloData.CodArt;
148 articuloToChange.SECA = articuloData.CodSec; 148 articuloToChange.SECA = articuloData.CodSec;
149 articuloToChange.CodSec = articuloData.CodSec; 149 articuloToChange.CodSec = articuloData.CodSec;
150 articuloToChange.PreVen = articuloData.PreVen; 150 articuloToChange.PreVen = articuloData.PreVen;
151 articuloToChange.id = articuloData.id; 151 articuloToChange.id = articuloData.id;
152 articuloToChange.DET_LAR = articuloData.DET_LAR; 152 articuloToChange.DET_LAR = articuloData.DET_LAR;
153 articuloToChange.DetArt = articuloData.DetArt; 153 articuloToChange.DetArt = articuloData.DetArt;
154 articuloToChange.MKT_DESC = articuloData.MKT_DESC; 154 articuloToChange.MKT_DESC = articuloData.MKT_DESC;
155 } 155 }
156 } 156 }
157 157