impl redis cloud
This commit is contained in:
@@ -4,6 +4,11 @@ import { InjectDataSource } from "@nestjs/typeorm";
|
||||
import { FindOrdersDto } from "../dto/find-orders.dto";
|
||||
import { OrderItemDto } from "../dto/OrderItemDto";
|
||||
import { CutItemDto } from '../dto/CutItemDto';
|
||||
import { OrderDeliveryDto } from '../dto/OrderDeliveryDto';
|
||||
import { OrderTransferDto } from '../dto/OrderTransferDto';
|
||||
import { OrderStatusDto } from '../dto/OrderStatusDto';
|
||||
import { InvoiceCheckDto } from '../dto/invoice-check.dto';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -365,4 +370,270 @@ export class OrdersRepository {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async getOrderDelivery(orderId: string): Promise<OrderDeliveryDto | null> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
const sql = `
|
||||
SELECT PCPRACA.CODPRACA as "placeId",
|
||||
PCPRACA.PRACA as "placeName",
|
||||
NVL(ENDENT.ENDERENT, PCCLIENT.ENDERENT) as "street",
|
||||
NVL(ENDENT.NUMEROENT, PCCLIENT.NUMEROENT) as "addressNumber",
|
||||
NVL(ENDENT.BAIRROENT, PCCLIENT.BAIRROENT) as "bairro",
|
||||
NVL(ENDENT.MUNICENT, PCCLIENT.MUNICENT) as "city",
|
||||
NVL(ENDENT.ESTENT, PCCLIENT.ESTENT) as "state",
|
||||
NVL(ENDENT.COMPLEMENTOENT, PCCLIENT.COMPLEMENTOENT) as "addressComplement",
|
||||
NVL(ENDENT.CEPENT, PCCLIENT.CEPENT) as "cep",
|
||||
PCPEDC.OBS1 as "commentOrder1",
|
||||
PCPEDC.OBS2 as "commentOrder2",
|
||||
PCPEDC.OBSENTREGA1 as "commentDelivery1",
|
||||
PCPEDC.OBSENTREGA2 as "commentDelivery2",
|
||||
PCPEDC.OBSENTREGA3 as "commentDelivery3",
|
||||
PCPEDC.OBSENTREGA4 as "commentDelivery4",
|
||||
PCPEDC.NUMCAR as "shippimentId",
|
||||
PCCARREG.DTSAIDA as "shippimentDate",
|
||||
PCCARREG.DESTINO as "shippimentComment",
|
||||
PCROTAEXP.DESCRICAO as "place",
|
||||
PCEMPR.MATRICULA||'-'||PCEMPR.NOME as "driver",
|
||||
PCVEICUL.PLACA||' - '||PCVEICUL.DESCRICAO as "car",
|
||||
CASE WHEN PCCARREG.DTFECHA < PCCARREG.DTSAIDA THEN NULL ELSE PCCARREG.DTFECHA END as "closeDate",
|
||||
SEPARADOR.NOME as "separatorName",
|
||||
CONFERENTE.NOME as "confName",
|
||||
PCPEDC.DTLIBERA as "releaseDate"
|
||||
FROM PCPEDC, PCCLIENT, PCPRACA, PCCLIENTENDENT ENDENT, PCCARREG, PCVEICUL, PCEMPR, PCROTAEXP,
|
||||
PCEMPR SEPARADOR, PCEMPR CONFERENTE
|
||||
WHERE NVL(ENDENT.CODPRACAENT, PCPEDC.CODPRACA) = PCPRACA.CODPRACA
|
||||
AND PCPEDC.CODCLI = PCCLIENT.CODCLI
|
||||
AND PCPEDC.CODENDENTCLI = ENDENT.CODENDENTCLI (+)
|
||||
AND PCPEDC.CODCLI = ENDENT.CODCLI (+)
|
||||
AND PCPEDC.NUMCAR = PCCARREG.NUMCAR (+)
|
||||
AND PCCARREG.CODMOTORISTA = PCEMPR.MATRICULA (+)
|
||||
AND PCCARREG.CODVEICULO = PCVEICUL.CODVEICULO (+)
|
||||
AND PCCARREG.CODROTAPRINC = PCROTAEXP.CODROTA (+)
|
||||
AND PCPEDC.CODFUNCSEP = SEPARADOR.MATRICULA (+)
|
||||
AND PCPEDC.CODFUNCCONF = CONFERENTE.MATRICULA (+)
|
||||
AND PCPEDC.NUMPED = ${orderId}
|
||||
`;
|
||||
|
||||
const result = await queryRunner.manager.query(sql);
|
||||
return result.length > 0 ? result[0] : null;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
async getTransfer(orderId: number): Promise<OrderTransferDto[] | null> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
const sql = `
|
||||
SELECT
|
||||
L.NUMPED as "orderId",
|
||||
L.DTTRANSF as "transferDate",
|
||||
L.NUMNOTA as "invoiceId",
|
||||
L.NUMTRANSVENDA as "transactionId",
|
||||
L.NUMCARANTERIOR as "oldShipment",
|
||||
L.NUMCARATUAL as "newShipment",
|
||||
L.MOTIVOTRANSF as "transferText",
|
||||
L.codmotivo || '-' || PCTABDEV.MOTIVO as "cause",
|
||||
L.codfunctransf || '-' || PCEMPR.NOME as "userName",
|
||||
L.rotinatransf as "program"
|
||||
FROM PCLOGTRANSFNFCARREG L
|
||||
LEFT JOIN PCTABDEV ON L.CODMOTIVO = PCTABDEV.coddevol
|
||||
LEFT JOIN PCEMPR ON L.CODFUNCTRANSF = PCEMPR.MATRICULA
|
||||
WHERE L.NUMTRANSVENDA IN (
|
||||
SELECT NUMTRANSVENDA FROM PCPEDC WHERE PCPEDC.NUMPED = ${orderId}
|
||||
)
|
||||
`;
|
||||
|
||||
const result = await queryRunner.manager.query(sql);
|
||||
return result.length > 0 ? result : null;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async getStatusOrder(orderId: number): Promise<OrderStatusDto[] | null> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
try {
|
||||
const sql = `SELECT pcpedc.numped AS "orderId",
|
||||
'Digitação pedido' AS "status",
|
||||
TO_DATE (TO_CHAR(pcpedc.data, 'DD/MM/YYYY') || ' ' || pcpedc.hora || ':' || pcpedc.minuto,
|
||||
'DD/MM/YYYY HH24:MI')
|
||||
AS "statusDate",
|
||||
pcpedc.codemitente || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId} AND pcpedc.codemitente = pcempr.matricula(+)
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Montagem de carga' AS "status",
|
||||
TO_DATE (
|
||||
TO_CHAR(pccarreg.datamon, 'DD/MM/YYYY')
|
||||
|| ' '
|
||||
|| pccarreg.horamon
|
||||
|| ':'
|
||||
|| pccarreg.minutomon,
|
||||
'DD/MM/YYYY HH24:MI')
|
||||
AS "statusDate",
|
||||
pccarreg.codfuncmon || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr, pccarreg
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pccarreg.codfuncmon = pcempr.matricula(+)
|
||||
AND pcpedc.numcar = pccarreg.numcar
|
||||
AND pcpedc.numcar > 0
|
||||
AND pccarreg.datamon is not null
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Emissão do mapa' AS "status",
|
||||
CASE WHEN PCPEDC.DTEMISSAOMAPA IS NOT NULL THEN
|
||||
TO_DATE (
|
||||
TO_CHAR(pcpedc.dtemissaomapa, 'DD/MM/YYYY')
|
||||
|| ' '
|
||||
|| NVL(pcpedc.horaemissaomapa, '00')
|
||||
|| ':'
|
||||
|| nvl(pcpedc.minutoemissaomapa, '01'),
|
||||
'DD/MM/YYYY HH24:MI') ELSE NULL END
|
||||
AS "statusDate",
|
||||
pcpedc.codfuncemissaomapa || '-' || pcempr.nome AS "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.codfuncemissaomapa = pcempr.matricula(+)
|
||||
AND PCPEDC.DTEMISSAOMAPA IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Inicio de Separação' AS "status",
|
||||
pcpedc.dtinicialsep as "statusDate",
|
||||
pcpedc.codfuncsep || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.codfuncsep = pcempr.matricula(+)
|
||||
AND PCPEDC.dtinicialsep IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Fim de Separação' AS "status",
|
||||
pcpedc.dtfinalsep as "statusDate",
|
||||
pcpedc.codfuncsep || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId} AND pcpedc.codfuncsep = pcempr.matricula(+)
|
||||
and pcpedc.dtfinalsep is not null
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Inicio conferência' AS "status",
|
||||
pcpedc.dtinicialcheckout AS "statusDate",
|
||||
pcpedc.codfuncconf || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.codfuncconf = pcempr.matricula(+)
|
||||
AND pcpedc.dtinicialcheckout IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Fim conferência' AS "status",
|
||||
pcpedc.dtfinalcheckout AS "statusDate",
|
||||
pcpedc.codfuncconf || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.codfuncconf = pcempr.matricula(+)
|
||||
AND pcpedc.dtfinalcheckout IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Faturamento' AS "status",
|
||||
TO_DATE (
|
||||
TO_CHAR(pcpedc.dtfat, 'DD/MM/YYYY') || ' ' || pcpedc.horafat || ':' || pcpedc.minutofat,
|
||||
'DD/MM/YYYY HH24:MI')
|
||||
AS "statusDate",
|
||||
pcempr.matricula || '-' || pcempr.nome "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcempr, pccarreg, pcnfsaid
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.numcar = pccarreg.numcar
|
||||
and pcpedc.numtransvenda = pcnfsaid.numtransvenda
|
||||
AND nvl(pcnfsaid.codemitente, decode(pcpedc.numcar,0,-1,pccarreg.codfuncfat)) = pcempr.matricula(+)
|
||||
AND pcpedc.dtfat IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Entrega' AS "status",
|
||||
pcnfsaid.dtcanhoto AS "statusDate",
|
||||
CASE WHEN PCNFSAID.NUMCAR > 0 THEN
|
||||
pcnfsaid.codfunccanhoto || '-' || pcempr.nome
|
||||
ELSE '' END "userName"
|
||||
,NULL as "comments"
|
||||
FROM pcpedc, pcnfsaid, pcempr, pccarreg
|
||||
WHERE pcpedc.numped = ${orderId}
|
||||
AND pcpedc.numtransvenda = pcnfsaid.numtransvenda
|
||||
AND pcnfsaid.numcar = pccarreg.numcar (+)
|
||||
AND pcnfsaid.codfunccanhoto = pcempr.matricula(+)
|
||||
AND pcnfsaid.dtcanhoto IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT pcpedc.numped AS "orderId",
|
||||
'Transf entre carregamento' AS "status",
|
||||
pclogtransfnfcarreg.dttransf AS "statusDate",
|
||||
pclogtransfnfcarreg.codfunctransf || '-' || pcempr.nome "userName",
|
||||
'ORIG: '||pclogtransfnfcarreg.numcaranterior || ' ->
|
||||
DEST.: ' ||pclogtransfnfcarreg.numcaratual as "comments"
|
||||
FROM pclogtransfnfcarreg, pcpedc, pcempr
|
||||
WHERE pclogtransfnfcarreg.numnota = pcpedc.numnota (+)
|
||||
AND pcpedc.numped = ${orderId}
|
||||
AND pclogtransfnfcarreg.codfunctransf = pcempr.matricula(+)
|
||||
ORDER BY 3`;
|
||||
|
||||
const result = await queryRunner.manager.query(sql);
|
||||
return result.length > 0 ? result : null;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
async createInvoiceCheck(invoice: InvoiceCheckDto): Promise<{ message: string }> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
const sequenceSql = 'SELECT ESSCONFERENCIANF.NEXTVAL as "id" FROM DUAL';
|
||||
const result = await queryRunner.manager.query(sequenceSql);
|
||||
const checkId = result[0].id;
|
||||
|
||||
const sqlMain = `
|
||||
INSERT INTO ESTCONFERENCIANF (
|
||||
ID, NUMTRANSVENDA, CODFILIAL, NUMNOTA, DTINICIO, DTFIM, CODFUNCCONF
|
||||
) VALUES (
|
||||
${checkId}, ${invoice.transactionId}, ${invoice.storeId}, ${invoice.invoiceId},
|
||||
TO_DATE(SUBSTR(REPLACE(REPLACE('${invoice.startDate}', 'T', ' '), 'Z', ''),1,18), 'YYYY-MM-DD HH24:MI:SS'),
|
||||
TO_DATE(SUBSTR(REPLACE(REPLACE('${invoice.endDate}', 'T', ' '), 'Z', ''),1,18), 'YYYY-MM-DD HH24:MI:SS'),
|
||||
${invoice.userId}
|
||||
)
|
||||
`;
|
||||
await queryRunner.manager.query(sqlMain);
|
||||
|
||||
for (const item of invoice.itens) {
|
||||
const sqlItem = `
|
||||
INSERT INTO ESTCONFERENCIANFITENS (
|
||||
IDCONF, NUMTRANSVENDA, CODPROD, NUMSEQ, QT, DTCONF
|
||||
) VALUES (
|
||||
${checkId}, ${invoice.transactionId}, ${item.productId}, ${item.seq}, ${item.qt},
|
||||
TO_DATE(SUBSTR(REPLACE(REPLACE('${item.confDate}', 'T', ' '), 'Z', ''),1,18), 'YYYY-MM-DD HH24:MI:SS')
|
||||
)
|
||||
`;
|
||||
await queryRunner.manager.query(sqlItem);
|
||||
}
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return { message: 'Conferência salva com sucesso!' };
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user