Merge branch 'feat/painel-cliente'
This commit is contained in:
commit
b9525b036e
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"cweijan.dbclient-jdbc"
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -7,12 +7,12 @@ export const typeOrmConfig: TypeOrmModuleOptions = {
|
|||
// username: "LIVIA",
|
||||
// password: "LIVIA",
|
||||
host: "10.1.1.241",
|
||||
username: "teste",
|
||||
password: "teste",
|
||||
username: "SEVEN",
|
||||
password: "USR54SEV",
|
||||
// username: "API",
|
||||
// password: "E05H5KIEQV3YKDJR",
|
||||
port: 1521,
|
||||
sid: "BDTESTE",
|
||||
sid: "WINT",
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
||||
|
|
@ -22,12 +22,11 @@ export const typeOrmConfig: TypeOrmModuleOptions = {
|
|||
export const connectionOptions: ConnectionOptions = {
|
||||
type: "oracle",
|
||||
host: "10.1.1.241",
|
||||
username: "teste",
|
||||
password: "teste",
|
||||
username: "SEVEN",
|
||||
password: "USR54SEV",
|
||||
port: 1521,
|
||||
sid: "BDTESTE",
|
||||
sid: "WINT",
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -60,4 +60,7 @@ export class Shopping {
|
|||
@Column({ name: 'CODTABELAFRETE' })
|
||||
codtabelafrete: number;
|
||||
|
||||
@Column({ name: 'CODPRACA' })
|
||||
codpraca: number;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
export class CartUpdate {
|
||||
constructor(
|
||||
public id: string,
|
||||
public idCustomer: number,
|
||||
public idAddress: number,
|
||||
public saleStore: string,
|
||||
public userId: number,
|
||||
public idSeller: number,
|
||||
public idProfessional: number,
|
||||
public idPaymentPlan: number,
|
||||
public idBilling: string,
|
||||
public shippingValue: number,
|
||||
public scheduleDelivery: boolean,
|
||||
public shippingDate: Date,
|
||||
public shippingPriority: string,
|
||||
public idStorePlace: number,
|
||||
public notation1: string,
|
||||
public notation2: string,
|
||||
public deliveryNote1: string,
|
||||
public deliveryNote2: string,
|
||||
public deliveryNote3: string,
|
||||
public carrierId: number,
|
||||
) { }
|
||||
}
|
||||
|
|
@ -139,10 +139,8 @@ export class CustomerController {
|
|||
return new ResultModel(true, null, result, null);
|
||||
//return new ResultModel(true, null, id, null);
|
||||
} catch(err){
|
||||
throw new HttpException(
|
||||
new ResultModel(false, 'Erro ao cadastrar cliente.', {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
throw new HttpException(new ResultModel(false, 'Erro ao cadastrar cliente.', {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -360,74 +360,44 @@ export class CustomerService {
|
|||
newCustomer.longitude = customer.longitude;
|
||||
newCustomer.tipoendereco = customer.addressType;
|
||||
|
||||
const oldCustomers = await this.findCustomerByCpf(newCustomer.cgcent);
|
||||
if (oldCustomers && oldCustomers.length > 0) {
|
||||
const oldCustomer = oldCustomers[0];
|
||||
const oldCustomer = await this.findCustomerByCpf(newCustomer.cgcent);
|
||||
if (oldCustomer) {
|
||||
console.log('Cliente localizado: ' + oldCustomer.customerId);
|
||||
newCustomer.codcli = oldCustomer.customerId;
|
||||
await this.updateCustomer(newCustomer);
|
||||
return {
|
||||
customerId: oldCustomer.customerId,
|
||||
company: customer.company,
|
||||
name: customer.name,
|
||||
sexo: customer.gender,
|
||||
cpfCnpj: customer.cpfCnpj,
|
||||
numberState: customer.numberState,
|
||||
email: customer.email,
|
||||
zipCode: customer.zipCode,
|
||||
address: customer.address,
|
||||
addressNumber: customer.addressNumber,
|
||||
complement: customer.complement,
|
||||
company: customer.company, name: customer.name, sexo: customer.gender,
|
||||
cpfCnpj: customer.cpfCnpj, numberState: customer.numberState,
|
||||
email: customer.email, zipCode: customer.zipCode, address: customer.address,
|
||||
addressNumber: customer.addressNumber, complement: customer.complement,
|
||||
neighborhood: customer.neighborhood,
|
||||
city: customer.city,
|
||||
state: customer.state,
|
||||
allowMessage: customer.allowMessage,
|
||||
cellPhone: customer.cellPhone,
|
||||
category: customer.category,
|
||||
subCategory: customer.subCategory,
|
||||
place: customer.place,
|
||||
ramo: customer.ramo,
|
||||
meiocomunicacao: customer.communicate,
|
||||
latitude: customer.latitude,
|
||||
longitude: customer.longitude,
|
||||
ibgeCode: customer.ibgeCode,
|
||||
city: customer.city, state: customer.state,
|
||||
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||
category: customer.category, subCategory: customer.subCategory,
|
||||
place: customer.place, ramo: customer.ramo, meiocomunicacao: customer.communicate,
|
||||
latitude: customer.latitude, longitude: customer.longitude, ibgeCode: customer.ibgeCode,
|
||||
addressType: customer.addressType,
|
||||
};
|
||||
} else {
|
||||
const idCustomer = await this.generateIdCustomer();
|
||||
if (idCustomer == -1)
|
||||
return new HttpException(
|
||||
'Erro ao gerar númeração de cliente.',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
return new HttpException("Erro ao gerar númeração de cliente.", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
newCustomer.codcli = idCustomer;
|
||||
await this.insertCustomer(newCustomer);
|
||||
return {
|
||||
customerId: idCustomer,
|
||||
company: customer.company,
|
||||
name: customer.name,
|
||||
cpfCnpj: customer.cpfCnpj,
|
||||
gender: customer.gender,
|
||||
numberState: customer.numberState,
|
||||
email: customer.email,
|
||||
zipCode: customer.zipCode,
|
||||
address: customer.address,
|
||||
addressNumber: customer.addressNumber,
|
||||
complement: customer.complement,
|
||||
company: customer.company, name: customer.name,
|
||||
cpfCnpj: customer.cpfCnpj, gender: customer.gender, numberState: customer.numberState,
|
||||
email: customer.email, zipCode: customer.zipCode, address: customer.address,
|
||||
addressNumber: customer.addressNumber, complement: customer.complement,
|
||||
neighborhood: customer.neighborhood,
|
||||
city: customer.city,
|
||||
state: customer.state,
|
||||
allowMessage: customer.allowMessage,
|
||||
cellPhone: customer.cellPhone,
|
||||
category: customer.category,
|
||||
subCategory: customer.subCategory,
|
||||
place: customer.place,
|
||||
meiocomunicacao: customer.communicate,
|
||||
ramo: customer.ramo,
|
||||
latitude: customer.latitude,
|
||||
longitude: customer.longitude,
|
||||
ibgeCode: customer.ibgeCode,
|
||||
addressType: customer.addressType,
|
||||
city: customer.city, state: customer.state,
|
||||
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||
category: customer.category, subCategory: customer.subCategory,
|
||||
place: customer.place, meiocomunicacao: customer.communicate,
|
||||
ramo: customer.ramo, latitude: customer.latitude, longitude: customer.longitude,
|
||||
ibgeCode: customer.ibgeCode, addressType: customer.addressType,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import { HttpException, HttpStatus, Injectable,Inject } from '@nestjs/common';
|
||||
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { ShoppingItens } from 'src/domain/entity/tables/estprevendai.entity';
|
||||
import { Sale } from 'src/domain/entity/tables/estvenda.entity';
|
||||
import { Pcpedctemp } from 'src/domain/entity/tables/pcpedctemp.entity';
|
||||
import { Connection, QueryRunner } from 'typeorm';
|
||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||
import { Pcpeditemp } from 'src/domain/entity/tables/pcpeditemp.entity';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { Connection, QueryRunner } from 'typeorm';
|
||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||
import { Pcpedc } from '../../domain/entity/tables/pcpedc.entity';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
import { ShoppingService } from '../shopping/shopping.service';
|
||||
import Redis = require('ioredis');
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class OrderService {
|
||||
|
||||
constructor(
|
||||
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
||||
private readonly listsService: ListsService,
|
||||
|
|
@ -30,7 +28,10 @@ export class OrderService {
|
|||
async create(cart: Cart) {
|
||||
const shopping = await this.findShopping(cart.id);
|
||||
if (shopping == null)
|
||||
throw new HttpException("Carrinho de compras não localizado.", HttpStatus.NOT_FOUND);
|
||||
throw new HttpException(
|
||||
'Carrinho de compras não localizado.',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
const order = await this.createOrder(cart);
|
||||
return order;
|
||||
}
|
||||
|
|
@ -42,17 +43,27 @@ export class OrderService {
|
|||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
const orderCancel = await queryRunner.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED', [orderId]);
|
||||
const orderCancel = await queryRunner.query(
|
||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED',
|
||||
[orderId],
|
||||
);
|
||||
|
||||
if (orderCancel !== null && orderCancel.length > 0) {
|
||||
await queryRunner.startTransaction();
|
||||
await queryRunner.query("UPDATE PCPEDC SET VENDAASSISTIDA = 'N', RESERVAESTOQUETV7 = 'N' WHERE NUMPEDENTFUT = :1", [orderId]);
|
||||
await queryRunner.query(
|
||||
"UPDATE PCPEDC SET VENDAASSISTIDA = 'N', RESERVAESTOQUETV7 = 'N' WHERE NUMPEDENTFUT = :1",
|
||||
[orderId],
|
||||
);
|
||||
await queryRunner.commitTransaction();
|
||||
const ordersDelivery = await queryRunner
|
||||
.query("SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPEDENTFUT = :1", [orderId]);
|
||||
const ordersDelivery = await queryRunner.query(
|
||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPEDENTFUT = :1',
|
||||
[orderId],
|
||||
);
|
||||
for (const orderDelivery of ordersDelivery) {
|
||||
await queryRunner
|
||||
.query("BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;", [orderDelivery.numped, userId]);
|
||||
await queryRunner.query(
|
||||
'BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;',
|
||||
[orderDelivery.numped, userId],
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (erro) {
|
||||
|
|
@ -70,7 +81,6 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async createOrder(cart: Cart) {
|
||||
|
||||
const prevenda = await this.shoppingService.getShopping(cart.id);
|
||||
let idPreOrder = 0;
|
||||
cart.idSeller = prevenda.codusur;
|
||||
|
|
@ -86,20 +96,28 @@ export class OrderService {
|
|||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
|
||||
if (prevenda.numped > 0) {
|
||||
// await this.deleteOrdersDelivery(prevenda.numped, cart.userId);
|
||||
const orders = await queryRunner.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED', [prevenda.numped]);
|
||||
const orders = await queryRunner.query(
|
||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED',
|
||||
[prevenda.numped],
|
||||
);
|
||||
if (orders !== null && orders.length > 0) {
|
||||
await queryRunner
|
||||
.query("BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;", [prevenda.numped, cart.userId]);
|
||||
const orderCancel = await queryRunner
|
||||
.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :1', [prevenda.numped]);
|
||||
await queryRunner.query(
|
||||
'BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;',
|
||||
[prevenda.numped, cart.userId],
|
||||
);
|
||||
const orderCancel = await queryRunner.query(
|
||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :1',
|
||||
[prevenda.numped],
|
||||
);
|
||||
if (orderCancel.length > 0) {
|
||||
throw new HttpException('Não foi possível alterar o pedido de venda, verifique se o pedido já não encontra-se FATURADO ou em SEPARAÇÃO.', HttpStatus.BAD_REQUEST);
|
||||
throw new HttpException(
|
||||
'Não foi possível alterar o pedido de venda, verifique se o pedido já não encontra-se FATURADO ou em SEPARAÇÃO.',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if ( prevenda.codcli === null || prevenda.codcli === 1){
|
||||
|
|
@ -108,20 +126,30 @@ export class OrderService {
|
|||
|
||||
const preOrder = await this.createPreOrder(cart, idPreOrder);
|
||||
|
||||
await queryRunner
|
||||
.query("BEGIN IMPORTARVENDAS.IMPORTARPEDIDOWEB(:preOrder, :idSeller); END;", [preOrder.numpedrca, preOrder.codusur]);
|
||||
await queryRunner.query(
|
||||
'BEGIN IMPORTARVENDAS.IMPORTARPEDIDOWEB(:preOrder, :idSeller); END;',
|
||||
[preOrder.numpedrca, preOrder.codusur],
|
||||
);
|
||||
|
||||
const order = await queryRunner.manager
|
||||
.getRepository(Pcpedc)
|
||||
.createQueryBuilder('pcpedc')
|
||||
.where("\"pcpedc\".numpedrca = :idPreOrder AND \"pcpedc\".CONDVENDA IN (1,7)", { idPreOrder: preOrder.numpedrca })
|
||||
.where(
|
||||
'"pcpedc".numpedrca = :idPreOrder AND "pcpedc".CONDVENDA IN (1,7)',
|
||||
{ idPreOrder: preOrder.numpedrca },
|
||||
)
|
||||
.getOne();
|
||||
|
||||
if (!order) {
|
||||
const logPreOrder = await queryRunner.query('SELECT PCPEDCTEMP.NUMPEDRCA, PCPEDCTEMP.observacao_pc as \"resultado\" FROM PCPEDCTEMP WHERE PCPEDCTEMP.NUMPEDRCA = :idPreOrder',
|
||||
[preOrder.numpedrca]);
|
||||
const logPreOrder = await queryRunner.query(
|
||||
'SELECT PCPEDCTEMP.NUMPEDRCA, PCPEDCTEMP.observacao_pc as "resultado" FROM PCPEDCTEMP WHERE PCPEDCTEMP.NUMPEDRCA = :idPreOrder',
|
||||
[preOrder.numpedrca],
|
||||
);
|
||||
console.log(JSON.stringify(logPreOrder));
|
||||
throw new HttpException('Erro ao gerar pedido de venda - ' + logPreOrder[0].resultado, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
throw new HttpException(
|
||||
'Erro ao gerar pedido de venda - ' + logPreOrder[0].resultado,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
|
||||
if (queryRunner.isTransactionActive) {
|
||||
|
|
@ -131,11 +159,13 @@ export class OrderService {
|
|||
await queryRunner.startTransaction();
|
||||
try {
|
||||
// Atualizar numero do pedido na tabela de pre venda para
|
||||
let sql = ` UPDATE ESTPREVENDAC SET NUMPED = ${order.numped} ` +
|
||||
let sql =
|
||||
` UPDATE ESTPREVENDAC SET NUMPED = ${order.numped} ` +
|
||||
` WHERE ESTPREVENDAC.ID = '${cart.id}' `;
|
||||
await queryRunner.query(sql);
|
||||
|
||||
sql = `UPDATE PCORCAVENDAC SET ORCAMENTOUTILIZADO = 'S' ` +
|
||||
sql =
|
||||
`UPDATE PCORCAVENDAC SET ORCAMENTOUTILIZADO = 'S' ` +
|
||||
` ,NUMPED = ${order.numped} ` +
|
||||
` WHERE PCORCAVENDAC.NUMORCA = ( SELECT ESTPREVENDAC.NUMORCA FROM ESTPREVENDAC WHERE ID = '${cart.id}' ) `;
|
||||
await queryRunner.query(sql);
|
||||
|
|
@ -143,8 +173,8 @@ export class OrderService {
|
|||
// await queryRunner
|
||||
// .query("BEGIN ESK_VENDA.RESERVA_PIGMENTO_TINTOMETRICO(:1); END;", [cart.id]);
|
||||
|
||||
|
||||
sql = `UPDATE PCPEDC SET ` +
|
||||
sql =
|
||||
`UPDATE PCPEDC SET ` +
|
||||
` POSICAO = 'L' ` +
|
||||
` , MOTIVOPOSICAO = NULL ` +
|
||||
` , CODMOTIVO = NULL ` +
|
||||
|
|
@ -165,9 +195,9 @@ export class OrderService {
|
|||
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
||||
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
||||
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) `;
|
||||
await queryRunner.manager
|
||||
.query(sql, [order.numped]);
|
||||
sql = `UPDATE PCPEDI SET POSICAO = 'L' WHERE NUMPED = :1 ` +
|
||||
await queryRunner.manager.query(sql, [order.numped]);
|
||||
sql =
|
||||
`UPDATE PCPEDI SET POSICAO = 'L' WHERE NUMPED = :1 ` +
|
||||
` AND EXISTS( SELECT PCPEDC.NUMPED FROM PCPEDC ` +
|
||||
` WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ` +
|
||||
` AND NOT EXISTS(SELECT PCBLOQUEIO.CODMOTBLOQUEIO FROM PCBLOQUEIO WHERE PCBLOQUEIO.CODCOB = PCPEDC.CODCOB) ` +
|
||||
|
|
@ -175,13 +205,12 @@ export class OrderService {
|
|||
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
||||
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
||||
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) )`;
|
||||
await queryRunner.manager
|
||||
.query(sql, [order.numped]);
|
||||
await queryRunner.manager.query(sql, [order.numped]);
|
||||
|
||||
await this.updateStatusItem(queryRunner, order.numped);
|
||||
|
||||
|
||||
sql = ` UPDATE PCPEDC SET ` +
|
||||
sql =
|
||||
` UPDATE PCPEDC SET ` +
|
||||
` POSICAO = 'L' ` +
|
||||
` , MOTIVOPOSICAO = NULL ` +
|
||||
` , CODMOTIVO = NULL ` +
|
||||
|
|
@ -205,7 +234,8 @@ export class OrderService {
|
|||
` AND TV7.POSICAO = 'L' )`;
|
||||
|
||||
await queryRunner.manager.query(sql, [order.numped]);
|
||||
sql = ` UPDATE PCPEDC SET ` +
|
||||
sql =
|
||||
` UPDATE PCPEDC SET ` +
|
||||
` POSICAO = ( SELECT PCPEDI.POSICAO FROM PCPEDI WHERE PCPEDI.NUMPED = PCPEDC.NUMPED AND ROWNUM = 1 ) ` +
|
||||
` , MOTIVOPOSICAO = NULL ` +
|
||||
` , CODMOTIVO = NULL ` +
|
||||
|
|
@ -230,7 +260,8 @@ export class OrderService {
|
|||
await queryRunner.manager.query(sql, [order.numped]);
|
||||
|
||||
// atualizar campos padrão para rotina 4116
|
||||
sql = ` UPDATE PCPEDC SET ` +
|
||||
sql =
|
||||
` UPDATE PCPEDC SET ` +
|
||||
` DTENTREGA = TRUNC(DTENTREGA) ` +
|
||||
` , DATA = TRUNC(DATA) ` +
|
||||
` , DTPREVENTREGA = TRUNC(DTENTREGA) ` +
|
||||
|
|
@ -257,7 +288,8 @@ export class OrderService {
|
|||
`WHERE ( PCPEDC.NUMPED = :1 OR PCPEDC.NUMPEDENTFUT = :2 ) `;
|
||||
await queryRunner.manager.query(sql, [order.numped, order.numped]);
|
||||
|
||||
sql = ` UPDATE PCPEDC SET ` +
|
||||
sql =
|
||||
` UPDATE PCPEDC SET ` +
|
||||
` CODCOB = ( SELECT TV7.CODCOB FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
||||
` , CODPLPAG = ( SELECT TV7.CODPLPAG FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
||||
` , RESERVAESTOQUETV7 = 'N' ` +
|
||||
|
|
@ -265,7 +297,8 @@ export class OrderService {
|
|||
`WHERE (PCPEDC.NUMPEDENTFUT = :1 ) `;
|
||||
await queryRunner.manager.query(sql, [order.numped]);
|
||||
|
||||
sql = ` UPDATE PCPEDI SET CODSUPERVISOR = ( SELECT PCPEDC.CODSUPERVISOR FROM PCPEDC WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ) ` +
|
||||
sql =
|
||||
` UPDATE PCPEDI SET CODSUPERVISOR = ( SELECT PCPEDC.CODSUPERVISOR FROM PCPEDC WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ) ` +
|
||||
` ,DTENTREGA = ( SELECT PCPEDC.DTENTREGA FROM PCPEDC WHERE PCPEDI.NUMPED = PCPEDC.NUMPED ) ` +
|
||||
` ,COMPLEMENTO = NVL(( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP, PCPEDCTEMP ` +
|
||||
` WHERE PCPEDITEMP.NUMPEDRCA = PCPEDCTEMP.NUMPEDRCA ` +
|
||||
|
|
@ -283,10 +316,11 @@ export class OrderService {
|
|||
console.log(err);
|
||||
}
|
||||
|
||||
|
||||
let status = '';
|
||||
const statusOrder = await queryRunner
|
||||
.query('SELECT PCPEDC.POSICAO as "status" FROM PCPEDC WHERE NUMPED = :1', [order.numped]);
|
||||
const statusOrder = await queryRunner.query(
|
||||
'SELECT PCPEDC.POSICAO as "status" FROM PCPEDC WHERE NUMPED = :1',
|
||||
[order.numped],
|
||||
);
|
||||
switch (statusOrder[0].status) {
|
||||
case 'L': {
|
||||
status = 'LIBERADO';
|
||||
|
|
@ -308,7 +342,6 @@ export class OrderService {
|
|||
status = 'CANCELADO';
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Sempre ira retornar status = LIBERADO*/
|
||||
|
|
@ -316,7 +349,7 @@ export class OrderService {
|
|||
|
||||
return {
|
||||
idOrder: order.numped,
|
||||
status: status
|
||||
status: status,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
@ -331,7 +364,8 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async updateStatusItem(queryRunner: QueryRunner, orderId: number) {
|
||||
const sql = ` SELECT PCPEDI.ROWID as "rid", PCPEDI.NUMPED as "numped", PCPEDI.CODPROD as "codprod", PCPEDI.CODFILIALRETIRA as "codfilialretira", ` +
|
||||
const sql =
|
||||
` SELECT PCPEDI.ROWID as "rid", PCPEDI.NUMPED as "numped", PCPEDI.CODPROD as "codprod", PCPEDI.CODFILIALRETIRA as "codfilialretira", ` +
|
||||
` PCPEDI.QT as "qt", PCPEDI.POSICAO as "posicao", ` +
|
||||
` ( NVL(PCEST.QTESTGER,0) - NVL(PCEST.QTRESERV,0) - NVL(PCEST.QTBLOQUEADA,0) - NVL(PCEST.QTPENDENTE,0) + PCPEDI.QT ) as "qtestoque_disponivel" ` +
|
||||
` FROM PCPEDI, PCPEDC, PCEST, PCPEDC TV7 ` +
|
||||
|
|
@ -352,19 +386,23 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async updateStockItem(queryRunner: QueryRunner, item: any) {
|
||||
let sql = "";
|
||||
if (item.posicao === "B") {
|
||||
let sql = '';
|
||||
if (item.posicao === 'B') {
|
||||
if (item.qt > item.qtestoque_disponivel) {
|
||||
sql = `UPDATE PCPEDI SET POSICAO = 'P' ` +
|
||||
` WHERE PCPEDI.ROWID = :1`;
|
||||
sql = `UPDATE PCPEDI SET POSICAO = 'P' ` + ` WHERE PCPEDI.ROWID = :1`;
|
||||
await queryRunner.manager.query(sql, [item.rid]);
|
||||
} else {
|
||||
sql = `UPDATE PCEST SET QTPENDENTE = GREATEST((QTPENDENTE - :1), 0) ` +
|
||||
sql =
|
||||
`UPDATE PCEST SET QTPENDENTE = GREATEST((QTPENDENTE - :1), 0) ` +
|
||||
` ,QTRESERV = QTRESERV + :2 ` +
|
||||
` WHERE PCEST.CODFILIAL = :3 AND PCEST.CODPROD = :4`;
|
||||
await queryRunner.manager.query(sql, [item.qt, item.qt, item.codfilialretira, item.codprod]);
|
||||
sql = `UPDATE PCPEDI SET POSICAO = 'L' ` +
|
||||
` WHERE PCPEDI.ROWID = :1`;
|
||||
await queryRunner.manager.query(sql, [
|
||||
item.qt,
|
||||
item.qt,
|
||||
item.codfilialretira,
|
||||
item.codprod,
|
||||
]);
|
||||
sql = `UPDATE PCPEDI SET POSICAO = 'L' ` + ` WHERE PCPEDI.ROWID = :1`;
|
||||
await queryRunner.manager.query(sql, [item.rid]);
|
||||
}
|
||||
}
|
||||
|
|
@ -389,9 +427,9 @@ export class OrderService {
|
|||
codmotivo: null,
|
||||
motivoposicao: null,
|
||||
vlbonific: 0,
|
||||
vendaassistida: 'S'
|
||||
vendaassistida: 'S',
|
||||
})
|
||||
.where("numped = :numped", { numped: orderDelivery.numped })
|
||||
.where('numped = :numped', { numped: orderDelivery.numped })
|
||||
.execute();
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (err) {
|
||||
|
|
@ -414,14 +452,14 @@ export class OrderService {
|
|||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(Pcpeditemp)
|
||||
.where("\"PCPEDITEMP\".NUMPEDRCA = :numpedrca", { numpedrca: idPreOrder })
|
||||
.where('"PCPEDITEMP".NUMPEDRCA = :numpedrca', { numpedrca: idPreOrder })
|
||||
.execute();
|
||||
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(Pcpedctemp)
|
||||
.where("\"PCPEDCTEMP\".NUMPEDRCA = :numpedrca", { numpedrca: idPreOrder })
|
||||
.where('"PCPEDCTEMP".NUMPEDRCA = :numpedrca', { numpedrca: idPreOrder })
|
||||
.execute();
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (err) {
|
||||
|
|
@ -433,8 +471,11 @@ export class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
async createPreOrder(cart: Cart, idPreOrder: number, idPreOrderTV7: number = null) {
|
||||
|
||||
async createPreOrder(
|
||||
cart: Cart,
|
||||
idPreOrder: number,
|
||||
idPreOrderTV7: number = null,
|
||||
) {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
|
|
@ -446,36 +487,52 @@ export class OrderService {
|
|||
const customer = await this.getCustomer(cart.idCustomer);
|
||||
let idSellerPreorder = cart.idSeller;
|
||||
//Verifica se existe orçamento para a prevenda (CART)
|
||||
const cartPreOrder = await queryRunner.query('SELECT ESTPREVENDAC.NUMORCA, PCORCAVENDAC.CODUSUR as "idSeller" ' +
|
||||
const cartPreOrder = await queryRunner.query(
|
||||
'SELECT ESTPREVENDAC.NUMORCA, PCORCAVENDAC.CODUSUR as "idSeller" ' +
|
||||
' FROM ESTPREVENDAC, PCORCAVENDAC ' +
|
||||
` WHERE ESTPREVENDAC.ID = '${cart.id}' ` +
|
||||
' AND ESTPREVENDAC.NUMORCA = PCORCAVENDAC.NUMORCA ');
|
||||
' AND ESTPREVENDAC.NUMORCA = PCORCAVENDAC.NUMORCA ',
|
||||
);
|
||||
|
||||
if (cartPreOrder != null && cartPreOrder.length > 0) {
|
||||
idSellerPreorder = cartPreOrder[0].idSeller;
|
||||
}
|
||||
|
||||
const supervisor = await queryRunner.manager.query('SELECT PCUSUARI.CODSUPERVISOR FROM PCUSUARI WHERE CODUSUR = :1', [idSellerPreorder]);
|
||||
const supervisor = await queryRunner.manager.query(
|
||||
'SELECT PCUSUARI.CODSUPERVISOR FROM PCUSUARI WHERE CODUSUR = :1',
|
||||
[idSellerPreorder],
|
||||
);
|
||||
console.log(supervisor);
|
||||
|
||||
//Create pre-customers
|
||||
if (cart.idCustomer === 1 && cart.preCustomerDocument !== null) {
|
||||
const preCustomer = await queryRunner.query(`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||
` WHERE IDCART = :1 AND CPF = :2`, [cart.id, cart.preCustomerDocument]);
|
||||
const preCustomer = await queryRunner.query(
|
||||
`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||
` WHERE IDCART = :1 AND CPF = :2`,
|
||||
[cart.id, cart.preCustomerDocument],
|
||||
);
|
||||
if (preCustomer === null || preCustomer.length === 0) {
|
||||
const sqlInsert = ` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR, NUMPEDRCA ) ` +
|
||||
const sqlInsert =
|
||||
` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR, NUMPEDRCA ) ` +
|
||||
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR, :NUMPEDRCA ) `;
|
||||
await queryRunner.query(sqlInsert, [cart.preCustomerDocument,
|
||||
cart.id, cart.preCustomerName, cart.preCustomerPhone, cart.idSeller, idPreOrder]);
|
||||
await queryRunner.query(sqlInsert, [
|
||||
cart.preCustomerDocument,
|
||||
cart.id,
|
||||
cart.preCustomerName,
|
||||
cart.preCustomerPhone,
|
||||
cart.idSeller,
|
||||
idPreOrder,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if (cart.preCustomerDocument !== null) {
|
||||
await queryRunner.query(`DELETE FROM ESTVENDAPRECLIENTE WHERE IDCART = :1 AND REGEXP_REPLACE(:CPF, '[^0-9]', '')`,
|
||||
[cart.id, cart.preCustomerDocument]);
|
||||
await queryRunner.query(
|
||||
`DELETE FROM ESTVENDAPRECLIENTE WHERE IDCART = :1 AND REGEXP_REPLACE(:CPF, '[^0-9]', '')`,
|
||||
[cart.id, cart.preCustomerDocument],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//#region create PCPEDCTEMP
|
||||
console.log('Cart: ' + cart);
|
||||
const dateNow = new Date();
|
||||
|
|
@ -501,18 +558,18 @@ export class OrderService {
|
|||
preOrder.hora = preOrder.data.getHours();
|
||||
preOrder.minuto = preOrder.data.getMinutes();
|
||||
preOrder.dtentrega = dateDelivery;
|
||||
preOrder.codfilial = cart.saleStore,
|
||||
preOrder.codfilialnf = preOrder.codfilial;
|
||||
(preOrder.codfilial = cart.saleStore),
|
||||
(preOrder.codfilialnf = preOrder.codfilial);
|
||||
preOrder.codusur = idSellerPreorder; // cart.idSeller;
|
||||
if (supervisor != null) {
|
||||
preOrder.codsupervisor = supervisor.codsupervisor;
|
||||
}
|
||||
preOrder.codemitente = cart.userId;
|
||||
preOrder.codusur3 = cart.idProfessional;
|
||||
preOrder.tipointegracao = "W";
|
||||
preOrder.validarnivelvenda = "N";
|
||||
preOrder.tipointegracao = 'W';
|
||||
preOrder.validarnivelvenda = 'N';
|
||||
preOrder.dtentrega = cart.shippingDate;
|
||||
preOrder.esc_tipoentrega = (cart.scheduleDelivery === true) ? 'P' : 'N';
|
||||
preOrder.esc_tipoentrega = cart.scheduleDelivery === true ? 'P' : 'N';
|
||||
// preOrder.vlfrete = cart.shippingValue; --Já esta sendo incluido item para o valor de frete
|
||||
preOrder.vldescontocupom = 0;
|
||||
preOrder.vldescontofinanceiro = 0;
|
||||
|
|
@ -520,15 +577,15 @@ export class OrderService {
|
|||
preOrder.vlfretenf = 0;
|
||||
preOrder.vloutrasdesp = 0;
|
||||
preOrder.vltroco = 0;
|
||||
preOrder.origemped = "W";
|
||||
preOrder.origemped = 'W';
|
||||
preOrder.integradora = 10;
|
||||
preOrder.importado = "N";
|
||||
preOrder.importado = 'N';
|
||||
preOrder.codautorizacaotef = 0;
|
||||
preOrder.esc_ajustarfinanceiro = "N";
|
||||
preOrder.esc_obternsu = "N";
|
||||
preOrder.esc_ajustarfinanceiro = 'N';
|
||||
preOrder.esc_obternsu = 'N';
|
||||
preOrder.esc_vloutrasdespweb = 0;
|
||||
preOrder.pedidopagoecommerce = "S";
|
||||
preOrder.numpedmktplace = "";
|
||||
preOrder.pedidopagoecommerce = 'S';
|
||||
preOrder.numpedmktplace = '';
|
||||
preOrder.numitens = cart.itens.length;
|
||||
preOrder.obs1 = cart.notation1;
|
||||
preOrder.obs2 = cart.notation2;
|
||||
|
|
@ -538,7 +595,10 @@ export class OrderService {
|
|||
|
||||
//Dados do cliente
|
||||
preOrder.codcli = cart.idCustomer;
|
||||
preOrder.codpraca = (cart.shippingPriority == "M" && cart.idStorePlace != null ) ? cart.idStorePlace : customer.codpraca;
|
||||
preOrder.codpraca =
|
||||
cart.shippingPriority == 'M' && cart.idStorePlace != null
|
||||
? cart.idStorePlace
|
||||
: customer.codpraca;
|
||||
preOrder.fretedespacho = customer.fretedespacho;
|
||||
preOrder.codfornecfrete = cart.carrierId;
|
||||
|
||||
|
|
@ -552,8 +612,8 @@ export class OrderService {
|
|||
|
||||
let numeroSeq = 1;
|
||||
for (const item of cart.itens) {
|
||||
|
||||
const kit = await queryRunner.query('SELECT PCFORMPROD.CODPRODMP as "idProduct", ' +
|
||||
const kit = await queryRunner.query(
|
||||
'SELECT PCFORMPROD.CODPRODMP as "idProduct", ' +
|
||||
' PCFORMPROD.QTPRODMP as "qtComponent", ' +
|
||||
' PCPRODUT.CODAUXILIAR as "ean" ,' +
|
||||
` case when ESTLISTAPRODUTOS.PRECOPROMOCIONAL > 0 AND '${cart.idBilling}' <> 'CHM' THEN ` +
|
||||
|
|
@ -564,17 +624,19 @@ export class OrderService {
|
|||
' AND PCFORMPROD.CODPRODMP = PCPRODUT.CODPROD ' +
|
||||
' AND PCPRODUT.CODPROD = ESTLISTAPRODUTOS.CODPROD ' +
|
||||
' AND ESTLISTAPRODUTOS.CODFILIAL = :2',
|
||||
[item.idProduct, preOrder.codfilial]);
|
||||
[item.idProduct, preOrder.codfilial],
|
||||
);
|
||||
if (kit.length > 0) {
|
||||
for (const componente of kit) {
|
||||
|
||||
const listPrice = componente.listPrice;
|
||||
|
||||
const salePrice = (componente.listPrice *
|
||||
(item.salePrice / item.listPrice)).toFixed(2);
|
||||
const salePrice = (
|
||||
componente.listPrice *
|
||||
(item.salePrice / item.listPrice)
|
||||
).toFixed(2);
|
||||
|
||||
const itemOrder = new Pcpeditemp();
|
||||
itemOrder.tipointegracao = "W";
|
||||
itemOrder.tipointegracao = 'W';
|
||||
itemOrder.integradora = 10;
|
||||
itemOrder.numpedrca = idPreOrder;
|
||||
itemOrder.numpedweb = idPreOrder;
|
||||
|
|
@ -584,14 +646,15 @@ export class OrderService {
|
|||
itemOrder.codprod = componente.idProduct;
|
||||
itemOrder.codauxiliar = componente.ean;
|
||||
itemOrder.codfilialretira = item.idStock;
|
||||
itemOrder.tipoentrega = (item.deliveryMethod == 'RA') ? "RP" : item.deliveryMethod;
|
||||
itemOrder.rp_imediata = (item.deliveryMethod == 'RA') ? "S" : "N";
|
||||
itemOrder.tipoentrega =
|
||||
item.deliveryMethod == 'RA' ? 'RP' : item.deliveryMethod;
|
||||
itemOrder.rp_imediata = item.deliveryMethod == 'RA' ? 'S' : 'N';
|
||||
if (item.deliveryMethod == 'RA') {
|
||||
preOrder.dtentrega = new Date();
|
||||
}
|
||||
itemOrder.ptabela = Number.parseFloat(listPrice);
|
||||
itemOrder.pvenda = Number.parseFloat(salePrice);
|
||||
itemOrder.qt = (item.quantity * componente.qtComponent);
|
||||
itemOrder.qt = item.quantity * componente.qtComponent;
|
||||
itemOrder.data = new Date();
|
||||
itemOrder.complemento = item.descriptionAux;
|
||||
itemOrder.localizacao = item.environment;
|
||||
|
|
@ -604,10 +667,10 @@ export class OrderService {
|
|||
.execute();
|
||||
|
||||
numeroSeq = numeroSeq + 1;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
const itemOrder = new Pcpeditemp();
|
||||
itemOrder.tipointegracao = "W";
|
||||
itemOrder.tipointegracao = 'W';
|
||||
itemOrder.integradora = 10;
|
||||
itemOrder.numpedrca = idPreOrder;
|
||||
itemOrder.numpedweb = idPreOrder;
|
||||
|
|
@ -617,8 +680,9 @@ export class OrderService {
|
|||
itemOrder.codprod = item.idProduct;
|
||||
itemOrder.codauxiliar = item.ean;
|
||||
itemOrder.codfilialretira = item.idStock;
|
||||
itemOrder.tipoentrega = (item.deliveryMethod == 'RA') ? "RP" : item.deliveryMethod;
|
||||
itemOrder.rp_imediata = (item.deliveryMethod == 'RA') ? "S" : "N";
|
||||
itemOrder.tipoentrega =
|
||||
item.deliveryMethod == 'RA' ? 'RP' : item.deliveryMethod;
|
||||
itemOrder.rp_imediata = item.deliveryMethod == 'RA' ? 'S' : 'N';
|
||||
if (item.deliveryMethod == 'RA') {
|
||||
preOrder.dtentrega = new Date();
|
||||
}
|
||||
|
|
@ -637,7 +701,6 @@ export class OrderService {
|
|||
.execute();
|
||||
|
||||
numeroSeq = numeroSeq + 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -645,7 +708,7 @@ export class OrderService {
|
|||
|
||||
if (cart.shippingValue > 0) {
|
||||
const itemOrder = new Pcpeditemp();
|
||||
itemOrder.tipointegracao = "W";
|
||||
itemOrder.tipointegracao = 'W';
|
||||
itemOrder.integradora = 10;
|
||||
itemOrder.numpedrca = idPreOrder;
|
||||
itemOrder.numpedweb = idPreOrder;
|
||||
|
|
@ -661,7 +724,6 @@ export class OrderService {
|
|||
itemOrder.qt = 1;
|
||||
itemOrder.data = new Date();
|
||||
|
||||
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
|
|
@ -682,7 +744,6 @@ export class OrderService {
|
|||
|
||||
await queryRunner.commitTransaction();
|
||||
return preOrder;
|
||||
|
||||
} catch (err) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw err;
|
||||
|
|
@ -690,8 +751,6 @@ export class OrderService {
|
|||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async findSale(id: string) {
|
||||
|
|
@ -703,7 +762,7 @@ export class OrderService {
|
|||
const sale = await queryRunner.manager
|
||||
.getRepository(Sale)
|
||||
.createQueryBuilder('estvenda')
|
||||
.where("\"estvenda\".id = :id", { id: id })
|
||||
.where('"estvenda".id = :id', { id: id })
|
||||
.getOne();
|
||||
return sale;
|
||||
} catch (error) {
|
||||
|
|
@ -724,7 +783,7 @@ export class OrderService {
|
|||
const shopping = await queryRunner.manager
|
||||
.getRepository(ShoppingItens)
|
||||
.createQueryBuilder('estshopping')
|
||||
.where("\"estshopping\".id = :id", { id: idshopping })
|
||||
.where('"estshopping".id = :id', { id: idshopping })
|
||||
.getMany();
|
||||
return shopping;
|
||||
} catch (error) {
|
||||
|
|
@ -742,7 +801,8 @@ export class OrderService {
|
|||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
console.log('Consultando usuario ' + idSeller);
|
||||
let sql = 'SELECT NVL(PROXNUMPEDWEB,0) as "proxnumpedweb" FROM PCUSUARI ' +
|
||||
let sql =
|
||||
'SELECT NVL(PROXNUMPEDWEB,0) as "proxnumpedweb" FROM PCUSUARI ' +
|
||||
' WHERE PCUSUARI.CODUSUR = :1 FOR UPDATE';
|
||||
const seller = await queryRunner.query(sql, [idSeller]);
|
||||
|
||||
|
|
@ -752,27 +812,21 @@ export class OrderService {
|
|||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
|
||||
sql = 'UPDATE PCUSUARI SET PROXNUMPEDWEB = NVL(PROXNUMPEDWEB,0) + 1 ' +
|
||||
sql =
|
||||
'UPDATE PCUSUARI SET PROXNUMPEDWEB = NVL(PROXNUMPEDWEB,0) + 1 ' +
|
||||
' WHERE PCUSUARI.CODUSUR = :1';
|
||||
await queryRunner.query(sql, [idSeller]);
|
||||
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return idOrder;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
await queryRunner.rollbackTransaction();
|
||||
console.log(err);
|
||||
return -1;
|
||||
|
||||
} finally {
|
||||
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getCustomer(idCustomer: number) {
|
||||
|
|
@ -784,7 +838,7 @@ export class OrderService {
|
|||
const customer = await queryRunner.manager
|
||||
.getRepository(Pcclient)
|
||||
.createQueryBuilder('pcclient')
|
||||
.where("\"pcclient\".codcli = :idCustomer", { idCustomer })
|
||||
.where('"pcclient".codcli = :idCustomer', { idCustomer })
|
||||
.getOne();
|
||||
return customer;
|
||||
} catch (error) {
|
||||
|
|
@ -796,8 +850,15 @@ export class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
async getOrders(store: string, initialDate: Date, finalDate: Date,
|
||||
document: string, name: string, sellerId: number, idOrder: string) {
|
||||
async getOrders(
|
||||
store: string,
|
||||
initialDate: Date,
|
||||
finalDate: Date,
|
||||
document: string,
|
||||
name: string,
|
||||
sellerId: number,
|
||||
idOrder: string,
|
||||
) {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
|
|
@ -806,8 +867,8 @@ export class OrderService {
|
|||
let sql = '';
|
||||
|
||||
try {
|
||||
|
||||
sql = ` SELECT TO_CHAR(PCPEDC.DATA, \'DD/MM/YYYY\') as "createDate" ` +
|
||||
sql =
|
||||
` SELECT TO_CHAR(PCPEDC.DATA, \'DD/MM/YYYY\') as "createDate" ` +
|
||||
` ,PCPEDC.NUMPED as "orderId" ` +
|
||||
` ,PCPEDC.CODFILIAL as "store" ` +
|
||||
` ,CASE WHEN PCPEDC.POSICAO = 'B' THEN 'BLOQUEADO' ` +
|
||||
|
|
@ -833,7 +894,10 @@ export class OrderService {
|
|||
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
||||
}
|
||||
if (name != null && name != '') {
|
||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace('@', '%')}'||'%'`;
|
||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace(
|
||||
'@',
|
||||
'%',
|
||||
)}'||'%'`;
|
||||
}
|
||||
if (sellerId > 0) {
|
||||
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
||||
|
|
@ -845,14 +909,14 @@ export class OrderService {
|
|||
//tratamento de data//
|
||||
const startDate = new Date(initialDate);
|
||||
let day = startDate.getDate();
|
||||
let month = ("00" + (startDate.getMonth() + 1)).slice(-2);
|
||||
let month = ('00' + (startDate.getMonth() + 1)).slice(-2);
|
||||
let year = startDate.getFullYear();
|
||||
const startFormat = day + "/" + month + "/" + year;
|
||||
const startFormat = day + '/' + month + '/' + year;
|
||||
const endDate = new Date(finalDate);
|
||||
day = endDate.getDate();
|
||||
month = ("00" + (endDate.getMonth() + 1)).slice(-2);
|
||||
month = ('00' + (endDate.getMonth() + 1)).slice(-2);
|
||||
year = endDate.getFullYear();
|
||||
const endFormat = day + "/" + month + "/" + year;
|
||||
const endFormat = day + '/' + month + '/' + year;
|
||||
|
||||
sqlWhere += ` AND PCPEDC.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
||||
|
||||
|
|
@ -865,10 +929,8 @@ export class OrderService {
|
|||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async getItensOrder(idOrder: number) {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
|
|
@ -877,8 +939,8 @@ export class OrderService {
|
|||
let sql = '';
|
||||
|
||||
try {
|
||||
|
||||
sql = ` SELECT PCPEDI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ` +
|
||||
sql =
|
||||
` SELECT PCPEDI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ` +
|
||||
` PCPRODUT.EMBALAGEM as "package", ` +
|
||||
` ( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP ` +
|
||||
` WHERE PCPEDC.NUMPEDRCA = PCPEDITEMP.NUMPEDRCA ` +
|
||||
|
|
@ -905,7 +967,6 @@ export class OrderService {
|
|||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getCartId(orderId: number) {
|
||||
|
|
@ -914,7 +975,8 @@ export class OrderService {
|
|||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const order = await queryRunner.query('SELECT PCPEDC.DATA as "createDate" ' +
|
||||
const order = await queryRunner.query(
|
||||
'SELECT PCPEDC.DATA as "createDate" ' +
|
||||
' ,PCPEDC.NUMPED as "orderId" ' +
|
||||
' ,PCPEDC.CODFILIAL as "invoiceStore" ' +
|
||||
' ,PCPEDC.CODCLI as "customerId" ' +
|
||||
|
|
@ -924,7 +986,6 @@ export class OrderService {
|
|||
' ,PCPEDC.CODUSUR3 as "partnerId" ' +
|
||||
' ,ESTPREVENDAC.ID as "cartId" ' +
|
||||
' ,PCPEDC.POSICAO as "status" ' +
|
||||
|
||||
' ,PCPEDC.OBS as "notification" ' +
|
||||
' ,PCPEDC.OBS1 as "notification1" ' +
|
||||
' ,PCPEDC.OBS2 as "notification2" ' +
|
||||
|
|
@ -936,35 +997,64 @@ export class OrderService {
|
|||
` ,NVL(PCPEDC.TIPOPRIORIDADEENTREGA, 'B') as "priorityDelivery" ` +
|
||||
' FROM PCPEDC, ESTPREVENDAC ' +
|
||||
' WHERE PCPEDC.NUMPED = ESTPREVENDAC.NUMPED ' +
|
||||
' AND PCPEDC.NUMPED = :1', [orderId]);
|
||||
' AND PCPEDC.NUMPED = :1',
|
||||
[orderId],
|
||||
);
|
||||
|
||||
if (order.length == 0) {
|
||||
throw new HttpException(`Pedido não foi localizado`, HttpStatus.NOT_FOUND);
|
||||
throw new HttpException(
|
||||
`Pedido não foi localizado`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
if (order.status == 'F') {
|
||||
throw new HttpException(`Pedido já FATURADO, alteração não permitida.`, HttpStatus.NOT_FOUND);
|
||||
throw new HttpException(
|
||||
`Pedido já FATURADO, alteração não permitida.`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const invoiceStores = await this.listsService.GetStoreAll();
|
||||
const invoiceStore = await invoiceStores.find(data => data.id === order[0].invoiceStore);
|
||||
const customer = await this.customerService.findCustomerById(order[0].customerId);
|
||||
const invoiceStore = await invoiceStores.find(
|
||||
data => data.id === order[0].invoiceStore,
|
||||
);
|
||||
const customer = await this.customerService.findCustomerById(
|
||||
order[0].customerId,
|
||||
);
|
||||
const billinds = await this.listsService.GetBilling(order[0].customerId);
|
||||
const partners = await this.listsService.GetPartners();
|
||||
const address = await this.addressCustomerService.getAddress(order[0].customerId, order[0].addressId);
|
||||
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 paymentPlan = paymentPlans.find(data => data.codplpag === order[0].paymentPlanId);
|
||||
const paymentPlans = await this.listsService.GetPaymentPlan(
|
||||
billing.codcob,
|
||||
);
|
||||
const paymentPlan = paymentPlans.find(
|
||||
data => data.codplpag === order[0].paymentPlanId,
|
||||
);
|
||||
const partner = partners.find(data => data.id === order[0].partnerId);
|
||||
|
||||
return {
|
||||
cartId: order[0].cartId, invoiceStore: invoiceStore, customer: customer, partner: partner,
|
||||
paymentPlan: paymentPlan, billing: billing, address: address,
|
||||
notification: order[0].notification, notification1: order[0].notification1, notification2: order[0].notification2,
|
||||
notificationDelivery1: order[0].notificationDelivery1, notificationDelivery2: order[0].notificationDelivery2, notificationDelivery3: order[0].notificationDelivery3,
|
||||
deliveryDate: order[0].deliveryDate, squeduleDelivery: order[0].esc_tipoEntrega == 'P' ? true : false, priorityDelivery: order[0].priorityDelivery
|
||||
}
|
||||
|
||||
cartId: order[0].cartId,
|
||||
invoiceStore: invoiceStore,
|
||||
customer: customer,
|
||||
partner: partner,
|
||||
paymentPlan: paymentPlan,
|
||||
billing: billing,
|
||||
address: address,
|
||||
notification: order[0].notification,
|
||||
notification1: order[0].notification1,
|
||||
notification2: order[0].notification2,
|
||||
notificationDelivery1: order[0].notificationDelivery1,
|
||||
notificationDelivery2: order[0].notificationDelivery2,
|
||||
notificationDelivery3: order[0].notificationDelivery3,
|
||||
deliveryDate: order[0].deliveryDate,
|
||||
squeduleDelivery: order[0].esc_tipoEntrega == 'P' ? true : false,
|
||||
priorityDelivery: order[0].priorityDelivery,
|
||||
};
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connection.close();
|
||||
|
|
@ -972,25 +1062,31 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async createPreCustomer(cart: Cart) {
|
||||
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
try {
|
||||
const preCustomer = await queryRunner.query(`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||
` WHERE IDCART = :1 AND CPF = :2`, [cart.id, cart.preCustomerDocument]);
|
||||
const preCustomer = await queryRunner.query(
|
||||
`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||
` WHERE IDCART = :1 AND CPF = :2`,
|
||||
[cart.id, cart.preCustomerDocument],
|
||||
);
|
||||
if (preCustomer.length === 0) {
|
||||
const sqlInsert = ` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR ) ` +
|
||||
const sqlInsert =
|
||||
` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR ) ` +
|
||||
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR ) `;
|
||||
await queryRunner.query(sqlInsert, [cart.preCustomerDocument,
|
||||
cart.id, cart.preCustomerName, cart.preCustomerPhone, cart.idSeller]);
|
||||
await queryRunner.query(sqlInsert, [
|
||||
cart.preCustomerDocument,
|
||||
cart.id,
|
||||
cart.preCustomerName,
|
||||
cart.preCustomerPhone,
|
||||
cart.idSeller,
|
||||
]);
|
||||
} else {
|
||||
|
||||
}
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
} catch (err) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
console.log(err);
|
||||
|
|
@ -1001,7 +1097,8 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async productsWithoutTax(idCart: string, idCustomer: number) {
|
||||
const sql = ' SELECT ESTPREVENDAI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ' +
|
||||
const sql =
|
||||
' SELECT ESTPREVENDAI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ' +
|
||||
' PCPRODUT.EMBALAGEM as "package", PCCLIENT.ESTENT as "uf" ' +
|
||||
' FROM ESTPREVENDAI, ESTPREVENDAC, PCCLIENT, PCPRODUT ' +
|
||||
' WHERE ESTPREVENDAI.IDCART = ESTPREVENDAC.ID ' +
|
||||
|
|
@ -1028,8 +1125,8 @@ export class OrderService {
|
|||
}
|
||||
|
||||
async OrderRetiraPosterior() {
|
||||
|
||||
const sql = ' SELECT ' +
|
||||
const sql =
|
||||
' SELECT ' +
|
||||
' p.DATA as "data" ' +
|
||||
' ,p.numped as "orderId" ' +
|
||||
` ,TO_CHAR(p.datapedido, 'DD/MM/YYYY HH24:MI') as "orderDate" ` +
|
||||
|
|
@ -1043,6 +1140,7 @@ export class OrderService {
|
|||
' ,round( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) as "timeHour" ' +
|
||||
' ,round(( ( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) - ' +
|
||||
' TRUNC(( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24)) ) * 60,0) as "timeMinute" ' +
|
||||
' ,p.codfilial as "storeId" ' +
|
||||
' FROM esvpedidoretiraposterior p ' +
|
||||
' ORDER BY p.datapedido ';
|
||||
|
||||
|
|
@ -1057,15 +1155,19 @@ export class OrderService {
|
|||
await queryRunner.release();
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getProductsOrder(store: string, initialDate: Date, finalDate: Date,
|
||||
document: string, name: string, sellerId: number, idOrder: string,
|
||||
typeFilterProduct: string, productText: string
|
||||
async getProductsOrder(
|
||||
store: string,
|
||||
initialDate: Date,
|
||||
finalDate: Date,
|
||||
document: string,
|
||||
name: string,
|
||||
sellerId: number,
|
||||
idOrder: string,
|
||||
typeFilterProduct: string,
|
||||
productText: string,
|
||||
) {
|
||||
|
||||
const sql = `SELECT PCPEDC.DATA as "date"
|
||||
,PCPEDC.NUMPED as "orderId"
|
||||
,PCPEDC.NUMNOTA as "invoice"
|
||||
|
|
@ -1109,7 +1211,10 @@ export class OrderService {
|
|||
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
||||
}
|
||||
if (name != null && name != '') {
|
||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace('@', '%')}'||'%'`;
|
||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace(
|
||||
'@',
|
||||
'%',
|
||||
)}'||'%'`;
|
||||
}
|
||||
if (sellerId > 0) {
|
||||
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
||||
|
|
@ -1132,25 +1237,25 @@ export class OrderService {
|
|||
case 'PARTNER':
|
||||
sqlWhere += ` AND PCPRODUT.CODFAB like '${productText}%'`;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//tratamento de data//
|
||||
const startDate = new Date(initialDate);
|
||||
let day = startDate.getDate();
|
||||
let month = ("00" + (startDate.getMonth() + 1)).slice(-2);
|
||||
let month = ('00' + (startDate.getMonth() + 1)).slice(-2);
|
||||
let year = startDate.getFullYear();
|
||||
const startFormat = day + "/" + month + "/" + year;
|
||||
const startFormat = day + '/' + month + '/' + year;
|
||||
const endDate = new Date(finalDate);
|
||||
day = endDate.getDate();
|
||||
month = ("00" + (endDate.getMonth() + 1)).slice(-2);
|
||||
month = ('00' + (endDate.getMonth() + 1)).slice(-2);
|
||||
year = endDate.getFullYear();
|
||||
const endFormat = day + "/" + month + "/" + year;
|
||||
const endFormat = day + '/' + month + '/' + year;
|
||||
|
||||
sqlWhere += ` AND PCPEDI.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
||||
|
||||
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
const queryRunner = connection.createQueryRunner();
|
||||
|
|
@ -1163,5 +1268,4 @@ export class OrderService {
|
|||
await connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
import { Injectable, HttpException, HttpStatus, Inject, CACHE_MANAGER } from '@nestjs/common';
|
||||
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { Connection } from 'typeorm';
|
||||
import { connectionOptions } from '../../configs/typeorm.config';
|
||||
import { Estavisoestoque } from '../../domain/entity/tables/estavisoestoque.entity';
|
||||
import { Estruptura } from '../../domain/entity/tables/estruptura.entity';
|
||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||
import { Esvanalisevendarca } from '../../domain/entity/views/esvanalisevendarca.entity';
|
||||
import { Esvdepartamento } from '../../domain/entity/views/esvdepartamento.entity';
|
||||
import { Esvparcelamentovenda } from '../../domain/entity/views/esvparcelamentovenda.entity';
|
||||
import { SalesProduct } from '../../domain/entity/views/esvprodutosvenda.entity';
|
||||
import { Connection, getConnection } from 'typeorm';
|
||||
import { Esvsecao } from '../../domain/entity/views/esvsecao.entity';
|
||||
import { Esvsituacaopedido } from '../../domain/entity/views/esvsituacaopedido.entity';
|
||||
import { Stock } from '../../domain/entity/views/esvestoquevenda.entity';
|
||||
import { FilterProduct } from '../../domain/models/filter-product.model';
|
||||
import { Notify } from '../../domain/models/notify.model';
|
||||
import { Estavisoestoque } from '../../domain/entity/tables/estavisoestoque.entity';
|
||||
import { Esvparcelamentovenda } from '../../domain/entity/views/esvparcelamentovenda.entity';
|
||||
import { Rupture } from '../../domain/models/rupture.model';
|
||||
import { Estruptura } from '../../domain/entity/tables/estruptura.entity';
|
||||
import { Esvsecao } from '../../domain/entity/views/esvsecao.entity';
|
||||
import { Esvdepartamento } from '../../domain/entity/views/esvdepartamento.entity';
|
||||
import { Esvanalisevendarca } from '../../domain/entity/views/esvanalisevendarca.entity';
|
||||
import { connectionOptions } from '../../configs/typeorm.config';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
import Redis = require('ioredis');
|
||||
|
||||
|
|
@ -954,9 +953,12 @@ export class SalesService {
|
|||
WHERE PCFILIALRETIRA.CODFILIALVENDA = '${storeId}'
|
||||
AND PCFILIALRETIRA.CODFILIALRETIRA = ESVESTOQUEVENDA.CODFILIAL ) > 0 THEN 1
|
||||
ELSE 0 END ) as "allowDelivery"
|
||||
FROM ESVESTOQUEVENDA, PCFILIAL
|
||||
, NVL(PCEST.QTEXPOSICAO,0) as "exhibition"
|
||||
FROM ESVESTOQUEVENDA, PCFILIAL, PCEST
|
||||
WHERE ESVESTOQUEVENDA.CODPROD = ${id}
|
||||
AND ESVESTOQUEVENDA.CODFILIAL = PCFILIAL.CODIGO
|
||||
AND ESVESTOQUEVENDA.CODFILIAL = PCEST.CODFILIAL
|
||||
AND ESVESTOQUEVENDA.CODPROD = PCEST.CODPROD
|
||||
ORDER BY TO_NUMBER(ESVESTOQUEVENDA.CODFILIAL)`;
|
||||
|
||||
const stock = await queryRunner.query(sql);
|
||||
|
|
@ -1468,6 +1470,7 @@ export class SalesService {
|
|||
.query(sql, [cityId, cartId]);
|
||||
return deliveryTaxTable;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
|
|
@ -1502,8 +1505,25 @@ export class SalesService {
|
|||
}
|
||||
|
||||
async calculateDeliveryTaxOrder(dataDeliveryTax: any) {
|
||||
<<<<<<< HEAD
|
||||
let cityId = await this.customerService.findCity(dataDeliveryTax.ibgeCode);
|
||||
|
||||
=======
|
||||
console.log("json dataDeliveryTax", dataDeliveryTax);
|
||||
/*const dataDeliveryTax = {
|
||||
cartId: cartId,
|
||||
cityId: cityId,
|
||||
ibgeCode: ibgeCode,
|
||||
priorityDelivery: priorityDelivery,
|
||||
};*/
|
||||
|
||||
let cityId = 0;
|
||||
if (dataDeliveryTax.ibgeCode) {
|
||||
cityId = await this.customerService.findCity(dataDeliveryTax.ibgeCode);
|
||||
} else {
|
||||
cityId = dataDeliveryTax.cityId;
|
||||
}
|
||||
>>>>>>> feat/painel-cliente
|
||||
await this.updatePriorityDelivery(dataDeliveryTax.cartId, dataDeliveryTax.priorityDelivery);
|
||||
|
||||
if (cityId == 0) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import { OrderDiscount } from 'src/domain/models/order-discount.model';
|
|||
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
||||
import { LogOrder } from 'src/domain/models/log-order.model';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { CartUpdate } from 'src/domain/models/cart-update.model';
|
||||
|
||||
@ApiTags('Shopping')
|
||||
@Controller('api/v1/shopping')
|
||||
|
|
@ -82,6 +84,19 @@ export class ShoppingController {
|
|||
}
|
||||
}
|
||||
|
||||
@Put('cart')
|
||||
async updateCart(@Body() cart: CartUpdate) {
|
||||
try {
|
||||
if (cart.id == null) {
|
||||
throw new HttpException('Cart sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const updateCart = await this.shoppingService.updateShopping(cart);
|
||||
return updateCart;
|
||||
} catch (error) {
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('log')
|
||||
async logOrderShopping(@Body() logOrder: LogOrder) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import { Shopping } from 'src/domain/entity/tables/estprevendac.entity';
|
|||
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { LogOrder } from 'src/domain/models/log-order.model';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { CartUpdate } from 'src/domain/models/cart-update.model';
|
||||
|
||||
@Injectable()
|
||||
export class ShoppingService {
|
||||
|
|
@ -299,6 +301,58 @@ export class ShoppingService {
|
|||
|
||||
}
|
||||
|
||||
async updateShopping(cart: CartUpdate) {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
const sqlUpdate = `UPDATE ESTPREVENDAC SET
|
||||
CODFILIAL = :1,
|
||||
CODUSUR = :2,
|
||||
CODCLI = :3,
|
||||
CODENDENTCLI = :4,
|
||||
VLPEDIDO = :5,
|
||||
VLDESCONTO = :6,
|
||||
VLTAXAENTREGA = :7,
|
||||
TIPOPRIORIDADEENTREGA = :8
|
||||
WHERE ID = :9
|
||||
`;
|
||||
|
||||
const total = await queryRunner.query('SELECT SUM(ESTPREVENDAI.PTABELA * ESTPREVENDAI.QT) as "vltabela" ' +
|
||||
' ,SUM(ESTPREVENDAI.PVENDA * ESTPREVENDAI.QT) as "vlatend" ' +
|
||||
' ,SUM(ESTPREVENDAI.VLDESCONTO * ESTPREVENDAI.QT) as "vldesconto" ' +
|
||||
' ,SUM(PCPRODUT.PESOBRUTO * ESTPREVENDAI.QT) as "totpeso" ' +
|
||||
' FROM ESTPREVENDAI, PCPRODUT ' +
|
||||
' WHERE ESTPREVENDAI.CODPROD = PCPRODUT.CODPROD ' +
|
||||
' AND ESTPREVENDAI.IDCART = :1', [cart.id]);
|
||||
|
||||
await queryRunner.query(sqlUpdate, [
|
||||
cart.saleStore,
|
||||
cart.userId,
|
||||
cart.idCustomer,
|
||||
cart.idAddress,
|
||||
total[0].vlatend,
|
||||
total[0].vldesconto,
|
||||
cart.shippingValue,
|
||||
cart.shippingPriority,
|
||||
cart.id
|
||||
]);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return cart;
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
}
|
||||
}
|
||||
|
||||
async updateTotalShopping(idCart: string) {
|
||||
const connection = new Connection(connectionOptions);
|
||||
await connection.connect();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@
|
|||
"paths": {
|
||||
"src/*": ["./src/*"]
|
||||
},
|
||||
"incremental": true
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": false
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue