From 366d6d1f4d6b4c2cd65197dcce76ecaed45e2adb Mon Sep 17 00:00:00 2001 From: Luis Eduardo Estevao Date: Thu, 19 Feb 2026 10:00:29 -0300 Subject: [PATCH] feat: Add backoffice list controller and service for various data lookups and new sales customer, order, and pre-order services. Add parameter customerId para find payment plans --- src/backoffice/lists/lists.controller.ts | 8 +- src/backoffice/lists/lists.service.ts | 148 ++++++++++++----------- src/sales/customer/customer.service.ts | 8 +- src/sales/order/order.service.ts | 2 +- src/sales/pre-order/pre-order.service.ts | 2 +- 5 files changed, 86 insertions(+), 82 deletions(-) diff --git a/src/backoffice/lists/lists.controller.ts b/src/backoffice/lists/lists.controller.ts index 63637f3..11b6459 100644 --- a/src/backoffice/lists/lists.controller.ts +++ b/src/backoffice/lists/lists.controller.ts @@ -28,7 +28,7 @@ export class ListsController { * Consulta tabela de checkouts da filial informada */ @Get('checkout/:store') - @ApiParam({name: 'Código da filial',}) + @ApiParam({ name: 'Código da filial', }) async getCheckout(@Param('store') idStore: string) { return this.listsServices.GetCheckout(idStore); } @@ -44,9 +44,9 @@ export class ListsController { /** * Consulta tabela de plano de pagamento para pedido de venda */ - @Get('paymentplan/:billindid') - async getPaymentPlan(@Param('billindid') billingId: string) { - return this.listsServices.GetPaymentPlan(billingId); + @Get('paymentplan/:billindid/:customerId') + async getPaymentPlan(@Param('billindid') billingId: string, @Param('customerId') customerId: string) { + return this.listsServices.GetPaymentPlan(billingId, customerId); } /** diff --git a/src/backoffice/lists/lists.service.ts b/src/backoffice/lists/lists.service.ts index ae07182..66bd452 100644 --- a/src/backoffice/lists/lists.service.ts +++ b/src/backoffice/lists/lists.service.ts @@ -15,18 +15,18 @@ export class ListsService { 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 `; + ` 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 queryRunner.release(); await connection.close(); } } @@ -37,22 +37,22 @@ export class ListsService { 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 `; + ` 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')) ) "; - + " ((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]); + 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 queryRunner.release(); await connection.close(); } } @@ -66,7 +66,7 @@ export class ListsService { const checkouts = await queryRunner.manager .getRepository(Checkout) .createQueryBuilder('pccaixa') - .where("\"pccaixa\".CODFILIAL = :idStore", {idStore: idStore}) + .where("\"pccaixa\".CODFILIAL = :idStore", { idStore: idStore }) .orderBy("\"pccaixa\".NUMCAIXA") .getMany(); return checkouts; @@ -74,7 +74,7 @@ export class ListsService { console.log(error); throw error; } finally { - await queryRunner.release(); + await queryRunner.release(); await connection.close(); } } @@ -89,7 +89,7 @@ export class ListsService { .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}) + .where("\"pcempr\".CODFILIAL = :idStore", { idStore: idStore }) .orderBy("\"pcempr\".NOME") .getRawMany(); return checkouts; @@ -97,91 +97,95 @@ export class ListsService { console.log(error); throw error; } finally { - await queryRunner.release(); + await queryRunner.release(); await connection.close(); } } - async GetPaymentPlan(billingId: string){ + async GetPaymentPlan(billingId: string, clientId: 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]); + const sql = `SELECT PCPLPAG.CODPLPAG as "codplpag", PCPLPAG.DESCRICAO as "descricao", + NVL(PCPLPAG.NUMDIAS,0) as "numdias" + FROM PCPLPAG, PCCLIENT, PCPLPAG PLANO_CLI + WHERE PCCLIENT.CODCLI = :CODCLI + AND PCCLIENT.CODPLPAG = PLANO_CLI.CODPLPAG (+) + AND PCPLPAG.NUMDIAS <= NVL(PLANO_CLI.NUMDIAS,9999) + AND EXISTS(SELECT PCCOBPLPAG.CODCOB FROM PCCOBPLPAG + WHERE PCCOBPLPAG.CODPLPAG = PCPLPAG.CODPLPAG + AND PCCOBPLPAG.CODCOB = :CODCOB ) + ORDER BY PCPLPAG.DESCRICAO`; + + const paymentPlans = await queryRunner.query(sql, [clientId, billingId]); return paymentPlans; } catch (error) { throw error; } finally { - await queryRunner.release(); + await queryRunner.release(); await connection.close(); } } - async GetBilling(clienteId: number){ + 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'; + ' 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 queryRunner.release(); await connection.close(); } } - async GetPartners(){ + 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 '; + ' ,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 queryRunner.release(); await connection.close(); } } - async GetPreCustomer(idCart: string){ + 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 '; + 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]); @@ -190,95 +194,95 @@ export class ListsService { } catch (error) { throw error; } finally { - await queryRunner.release(); + await queryRunner.release(); await connection.close(); } } - async GetPlaces(){ + 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'; + ' ,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 queryRunner.release(); await connection.close(); } } - async GetStorePlaces(){ + 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'; + ' ,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 queryRunner.release(); await connection.close(); } } - async GetRamo(){ + 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'; + ' ,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 queryRunner.release(); await connection.close(); } } - async GetStates(state: string){ + 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'; + ' 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 queryRunner.release(); await connection.close(); } } - async getSupervisores(){ + async getSupervisores() { const connection = new Connection(connectionOptions); await connection.connect(); const queryRunner = connection.createQueryRunner(); @@ -294,9 +298,9 @@ export class ListsService { } catch (error) { throw error; } finally { - await queryRunner.release(); + await queryRunner.release(); await connection.close(); } } - } +} diff --git a/src/sales/customer/customer.service.ts b/src/sales/customer/customer.service.ts index 9ffc223..4688a96 100644 --- a/src/sales/customer/customer.service.ts +++ b/src/sales/customer/customer.service.ts @@ -469,9 +469,9 @@ export class CustomerService { async InitializeCustomer() { const cliente = new Pcclient(); cliente.codusur1 = 1; - cliente.codplpag = 10; - cliente.codpraca = 119; - cliente.codcob = "D"; + cliente.codplpag = 18; + cliente.codpraca = 169; + cliente.codcob = "CAR"; cliente.dtcadastro = new Date(); cliente.codcontab = "1"; cliente.aceitavendafracao = "N"; @@ -502,7 +502,7 @@ export class CustomerService { cliente.tv10usacustoproduto = "N"; cliente.inscestadual = "ISENTO"; cliente.codpais = 1058; //Brasil - cliente.observacao = "Importado do E-Commerce"; + cliente.observacao = "Cadastrado Venda Web"; cliente.aceitachterceiros = "S"; cliente.agregarvalorstdescfin = "N"; cliente.anvisa = "N"; diff --git a/src/sales/order/order.service.ts b/src/sales/order/order.service.ts index d5f8ddb..958f402 100644 --- a/src/sales/order/order.service.ts +++ b/src/sales/order/order.service.ts @@ -954,7 +954,7 @@ export class OrderService { const partners = await this.listsService.GetPartners(); const address = await this.addressCustomerService.getAddress(order[0].customerId, order[0].addressId); const billing = billinds.find(data => data.codcob === order[0].billindId); - const paymentPlans = await this.listsService.GetPaymentPlan(billing.codcob); + const paymentPlans = await this.listsService.GetPaymentPlan(billing.codcob, order[0].customerId); const paymentPlan = paymentPlans.find(data => data.codplpag === order[0].paymentPlanId); const partner = partners.find(data => data.id === order[0].partnerId); diff --git a/src/sales/pre-order/pre-order.service.ts b/src/sales/pre-order/pre-order.service.ts index d307f8b..3939293 100644 --- a/src/sales/pre-order/pre-order.service.ts +++ b/src/sales/pre-order/pre-order.service.ts @@ -425,7 +425,7 @@ export class PreOrderService { } // const address = await this.addressCustomerService.getAddress(preOrder[0].customerId, preOrder[0].addressId); const billing = billinds.find(data => data.codcob === preOrder[0].billindId); - const paymentPlans = await this.listsService.GetPaymentPlan((billing !== null && billing !== undefined) ? billing.codcob : '9999'); + const paymentPlans = await this.listsService.GetPaymentPlan((billing !== null && billing !== undefined) ? billing.codcob : '9999', preOrder[0].customerId); const paymentPlan = paymentPlans.find(data => data.codplpag === preOrder[0].paymentPlanId); const partner = partners.find(data => data.id === preOrder[0].partnerId);