commit
This commit is contained in:
97
src/backoffice/lists/lists.controller.ts
Normal file
97
src/backoffice/lists/lists.controller.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ListsService } from './lists.service';
|
||||
import { ApiParam, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('api/v1/lists')
|
||||
export class ListsController {
|
||||
|
||||
constructor(private readonly listsServices: ListsService) { }
|
||||
|
||||
/**
|
||||
* Consulta todas filiais cadastradas
|
||||
*/
|
||||
@Get('store')
|
||||
async getAll() {
|
||||
return this.listsServices.GetStoreAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta filiais autorizadas para o usuário
|
||||
*/
|
||||
@Get('store/user/:id')
|
||||
async getByUser(@Param('id') id: number) {
|
||||
return this.listsServices.GetStoreByUser(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de checkouts da filial informada
|
||||
*/
|
||||
@Get('checkout/:store')
|
||||
@ApiParam({name: 'Código da filial',})
|
||||
async getCheckout(@Param('store') idStore: string) {
|
||||
return this.listsServices.GetCheckout(idStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta lista de funcionários para a filial informada nos parâmetros
|
||||
*/
|
||||
@Get('user/:store')
|
||||
async getUser(@Param('store') idStore: string) {
|
||||
return this.listsServices.GetUser(idStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de plano de pagamento para pedido de venda
|
||||
*/
|
||||
@Get('paymentplan/:billindid')
|
||||
async getPaymentPlan(@Param('billindid') billingId: string) {
|
||||
return this.listsServices.GetPaymentPlan(billingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta tabela de cobrança para pedido de venda
|
||||
*/
|
||||
@Get('billing/:customerid')
|
||||
async getBillingByCustomer(@Param('customerid') customerId: number) {
|
||||
return this.listsServices.GetBilling(customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta cadastro de parceiros
|
||||
*/
|
||||
@Get('partners')
|
||||
async getPartners() {
|
||||
return this.listsServices.GetPartners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta praças para o cadastro de cliente / endereços
|
||||
*/
|
||||
@Get('places')
|
||||
async getPlaces() {
|
||||
return this.listsServices.GetPlaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta praças para o cadastro de cliente / endereços para retira em loja (CODPRINCIPAL = 1004)
|
||||
*/
|
||||
@Get('store-places')
|
||||
async getStorePlaces() {
|
||||
return this.listsServices.GetStorePlaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulta ramos de atividade do cliente
|
||||
*/
|
||||
@Get('ramo')
|
||||
async getRamo() {
|
||||
return this.listsServices.GetRamo();
|
||||
}
|
||||
|
||||
@Get('supervisores')
|
||||
async getSupervisores() {
|
||||
return this.listsServices.getSupervisores();
|
||||
}
|
||||
|
||||
}
|
||||
12
src/backoffice/lists/lists.module.ts
Normal file
12
src/backoffice/lists/lists.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ListsService } from './lists.service';
|
||||
import { ListsController } from './lists.controller';
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [
|
||||
ListsController,],
|
||||
providers: [
|
||||
ListsService,],
|
||||
})
|
||||
export class ListsModule { }
|
||||
302
src/backoffice/lists/lists.service.ts
Normal file
302
src/backoffice/lists/lists.service.ts
Normal file
@@ -0,0 +1,302 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Checkout } from 'src/domain/entity/tables/pccaixa.entity';
|
||||
import { Connection } from 'typeorm';
|
||||
import { Store } from '../../domain/entity/tables/pcfilial.entity';
|
||||
import { Pcempr } from '../../domain/entity/tables/pcempr.entity';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
|
||||
@Injectable()
|
||||
export class ListsService {
|
||||
|
||||
async GetStoreAll(): Promise<Store[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT PCFILIAL.CODIGO as "id", ` +
|
||||
` PCFILIAL.RAZAOSOCIAL as "name", ` +
|
||||
` PCFILIAL.CODIGO|| ' - '|| PCFILIAL.FANTASIA as "shortName" ` +
|
||||
` FROM PCFILIAL ` +
|
||||
` WHERE PCFILIAL.CODIGO <> '99' ` +
|
||||
` ORDER BY PCFILIAL.CODIGO `;
|
||||
const stores = await queryRunner.query(sql);
|
||||
return stores as Store[];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStoreByUser(idUser: number): Promise<Store[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
const sql = `SELECT PCFILIAL.CODIGO as "id", ` +
|
||||
` PCFILIAL.RAZAOSOCIAL as "name", ` +
|
||||
` PCFILIAL.CODIGO|| ' - '|| PCFILIAL.FANTASIA as "shortName" ` +
|
||||
` FROM PCFILIAL `;
|
||||
const whereByUser = " WHERE PCFILIAL.CODIGO <> '99' AND " +
|
||||
" ((PCFILIAL.CODIGO IN ( SELECT PCLIB.CODIGOA FROM PCLIB WHERE PCLIB.CODTABELA = 1 AND PCLIB.CODFUNC = :iduser )) OR " +
|
||||
" (EXISTS(SELECT PCLIB.CODIGOA FROM PCLIB WHERE PCLIB.CODTABELA = 1 AND PCLIB.CODFUNC = :iduser AND PCLIB.CODIGOA = '99')) ) ";
|
||||
|
||||
const orderBy = ` ORDER BY PCFILIAL.CODIGO`
|
||||
try {
|
||||
const stores = await queryRunner.query(sql + whereByUser + orderBy, [idUser]);
|
||||
return stores as Store[];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetCheckout(idStore: string): Promise<Checkout[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const checkouts = await queryRunner.manager
|
||||
.getRepository(Checkout)
|
||||
.createQueryBuilder('pccaixa')
|
||||
.where("\"pccaixa\".CODFILIAL = :idStore", {idStore: idStore})
|
||||
.orderBy("\"pccaixa\".NUMCAIXA")
|
||||
.getMany();
|
||||
return checkouts;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetUser(idStore: string): Promise<Pcempr[]> {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const checkouts = await queryRunner.manager
|
||||
.getRepository(Pcempr)
|
||||
.createQueryBuilder('pcempr')
|
||||
.select("\"pcempr\".matricula as \"id\", \"pcempr\".nome as \"name\", \"pcempr\".email as \"email\", \"pcempr\".usuariobd as \"smallName\"")
|
||||
.where("\"pcempr\".CODFILIAL = :idStore", {idStore: idStore})
|
||||
.orderBy("\"pcempr\".NOME")
|
||||
.getRawMany();
|
||||
return checkouts;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPaymentPlan(billingId: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPLPAG.CODPLPAG as "codplpag", PCPLPAG.DESCRICAO as "descricao", ' +
|
||||
' NVL(PCPLPAG.NUMDIAS,0) as "numdias" ' +
|
||||
' FROM PCPLPAG ' +
|
||||
' WHERE EXISTS(SELECT PCCOBPLPAG.CODCOB FROM PCCOBPLPAG ' +
|
||||
' WHERE PCCOBPLPAG.CODPLPAG = PCPLPAG.CODPLPAG ' +
|
||||
' AND PCCOBPLPAG.CODCOB = :CODCOB ) '
|
||||
' ORDER BY PCPAG.DESCRICAO ';
|
||||
const paymentPlans = await queryRunner.query(sql, [billingId]);
|
||||
return paymentPlans;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetBilling(clienteId: number){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCCOB.CODCOB as "codcob", PCCOB.CODCOB ||\' - \'||PCCOB.COBRANCA as "cobranca" ' +
|
||||
' FROM PCCOB ' +
|
||||
' WHERE NVL(PCCOB.enviacobrancafv, \'N\') = \'S\' ' +
|
||||
' AND ( ( NOT EXISTS(SELECT PCCOBCLI.CODCOB FROM PCCOBCLI WHERE PCCOBCLI.CODCLI = :CODCLI ) AND ' +
|
||||
' ( PCCOB.NIVELVENDA <= ( SELECT C.NIVELVENDA FROM PCCLIENT, PCCOB C ' +
|
||||
' WHERE PCCLIENT.CODCLI = :CODCLI AND PCCLIENT.CODCOB = C.CODCOB ) ) ) OR ' +
|
||||
' EXISTS(SELECT PCCOBCLI.CODCOB FROM PCCOBCLI WHERE PCCOBCLI.CODCLI = :CODCLI AND PCCOBCLI.CODCOB = PCCOB.CODCOB ) ) ' +
|
||||
' ORDER BY PCCOB.CODCOB';
|
||||
const billings = await queryRunner.query(sql, [clienteId]);
|
||||
return billings;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPartners(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT ESTPARCEIRO.ID as "id" ' +
|
||||
' ,REGEXP_REPLACE(ESTPARCEIRO.CPF, \'[^0-9]\',\'\') || \' - \' ||ESTPARCEIRO.NOME as "name" ' +
|
||||
' FROM ESTPARCEIRO ' +
|
||||
' WHERE 1 = 1 ';
|
||||
const partners = await queryRunner.manager
|
||||
.query(sql);
|
||||
return partners;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPreCustomer(idCart: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' select CPF as "document" '+
|
||||
' ,NOME as "name" ' +
|
||||
' ,TELEFONE as "phone" ' +
|
||||
' ,IDCART as "idCart" ' +
|
||||
' from estvendaprecliente ' +
|
||||
' where IDCART = :idcart ';
|
||||
console.log(idCart);
|
||||
const preCustomer = await queryRunner
|
||||
.query(sql, [idCart]);
|
||||
console.log(JSON.stringify(preCustomer));
|
||||
return preCustomer[0];
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetPlaces(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPRACA.CODPRACA as "id" ' +
|
||||
' ,PCPRACA.PRACA as "name" ' +
|
||||
' FROM PCPRACA ' +
|
||||
' WHERE 1 = 1';
|
||||
const places = await queryRunner.manager
|
||||
.query(sql);
|
||||
return places;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStorePlaces(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCPRACA.CODPRACA as "id" ' +
|
||||
' ,PCPRACA.PRACA as "name" ' +
|
||||
' FROM PCPRACA ' +
|
||||
' WHERE PCPRACA.CODPRACAPRINCIPAL = 1004';
|
||||
const places = await queryRunner.manager
|
||||
.query(sql);
|
||||
return places;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetRamo(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCATIVI.CODATIV as "id" ' +
|
||||
' ,PCATIVI.RAMO as "name" ' +
|
||||
' FROM PCATIVI ' +
|
||||
' WHERE 1 = 1 ' +
|
||||
' ORDER BY PCATIVI.RAMO';
|
||||
const ramos = await queryRunner.manager
|
||||
.query(sql);
|
||||
return ramos;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async GetStates(state: string){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = ' SELECT PCESTADO.ESTADO as "name" FROM PCESTADO' +
|
||||
' WHERE PCESTADO.UF = :1';
|
||||
const states = await queryRunner.manager
|
||||
.query(sql, [state]);
|
||||
return states[0].name;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
async getSupervisores(){
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT PCSUPERV.CODSUPERVISOR as "supervisorId"
|
||||
,PCSUPERV.NOME as "name"
|
||||
FROM PCSUPERV
|
||||
WHERE PCSUPERV.dtdemissao IS NULL`;
|
||||
const supervisores = await queryRunner.manager
|
||||
.query(sql);
|
||||
return supervisores;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user