1888 lines
81 KiB
TypeScript
1888 lines
81 KiB
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
import { OracleDBService } from 'src/db/db.service';
|
|
import * as oracledb from 'oracledb'
|
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
|
import { closeOracleDbConnection, deleteFilesAsync, fetchCursor, fnCounterFoil, fnVochers, generateFinalPDF, generateGL, generateGL1, generateGreenCoverPDF, handleError, pdfCarnetData, pdfGLData, replaceSlashWithDash, setEmptyStringsToNull, tnVochers, tsCounterFoil, usCounterFoil } from 'src/utils/helper';
|
|
|
|
import {
|
|
CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO,
|
|
CreateApplicationDTO,
|
|
UpdateExpGoodsAuthRepDTO,
|
|
AddGenerallistItemsDTO,
|
|
AddCountriesDTO,
|
|
UpdateShippingDetailsDTO,
|
|
CA_UpdateHolderDTO,
|
|
GetCarnetControlCenterDTO,
|
|
DeleteGenerallistItemsDTO,
|
|
PrintCarnetDTO,
|
|
PrintGLDTO,
|
|
YON,
|
|
CopyCarnetDTO,
|
|
GetExtendedSectionDTO,
|
|
SaveExtensionApplicationDTO,
|
|
CarnetProcessingCenterDTO2,
|
|
CapturePaymentDTO,
|
|
InitiatePaymentDTO,
|
|
GetOrderDetailsDTO,
|
|
GetPaymentHistoryDTO,
|
|
SaveHistoryDTO
|
|
} from 'src/dto/property.dto';
|
|
import { OracleService } from '../oracle.service';
|
|
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
|
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
|
|
import { PaypalService } from 'src/paypal/paypal.service';
|
|
import { NotFoundException } from 'src/exceptions/notFound.exception';
|
|
|
|
@Injectable()
|
|
export class CarnetApplicationService {
|
|
|
|
private readonly logger = new Logger(CarnetApplicationService.name);
|
|
|
|
constructor(
|
|
private readonly oracleDBService: OracleDBService,
|
|
private readonly oracleService: OracleService,
|
|
private readonly payPalService: PaypalService
|
|
) { }
|
|
|
|
// [ CARNETAPPLICATION_PKG ]
|
|
|
|
async SaveCarnetApplication(body: SaveCarnetApplicationDTO) {
|
|
|
|
const newBody = {
|
|
P_SPID: null, //
|
|
P_CLIENTID: null,
|
|
P_LOCATIONID: null,
|
|
P_USERID: null, //
|
|
P_HEADERID: null,
|
|
P_APPLICATIONNAME: null,
|
|
P_HOLDERID: null,
|
|
P_COMMERCIALSAMPLEFLAG: null,
|
|
P_PROFEQUIPMENTFLAG: null,
|
|
P_EXHIBITIONSFAIRFLAG: null,
|
|
P_AUTOFLAG: null,
|
|
P_HORSEFLAG: null,
|
|
P_AUTHREP: null,
|
|
P_GLTABLE: null,
|
|
P_USSETS: null,
|
|
P_COUNTRYTABLE: null,
|
|
P_SHIPTOTYPE: null,
|
|
P_SHIPADDRID: null,
|
|
P_FORMOFSECURITY: null,
|
|
P_INSPROTECTION: null,
|
|
P_LDIPROTECTION: null,
|
|
P_DELIVERYTYPE: null,
|
|
P_DELIVERYMETHOD: null,
|
|
P_PAYMENTMETHOD: null,
|
|
P_CUSTCOURIERNO: null,
|
|
P_REFNO: null,
|
|
P_NOTES: null,
|
|
};
|
|
|
|
const reqBody = JSON.parse(JSON.stringify(body));
|
|
|
|
|
|
setEmptyStringsToNull(reqBody);
|
|
|
|
const finalBody = { ...newBody, ...reqBody };
|
|
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(finalBody);
|
|
|
|
const COUNTRYTABLE_INSTANCE = await this.oracleService.get_COUNTRY_TABLE_INSTANCE(finalBody);
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.SaveCarnetApplication(
|
|
:P_SPID, :P_CLIENTID, :P_LOCATIONID, :P_USERID, :P_HEADERID, :P_APPLICATIONNAME, :P_HOLDERID, :P_COMMERCIALSAMPLEFLAG, :P_PROFEQUIPMENTFLAG, :P_EXHIBITIONSFAIRFLAG, :P_AUTOFLAG, :P_HORSEFLAG, :P_AUTHREP, :P_GLTABLE, :P_USSETS, :P_COUNTRYTABLE, :P_SHIPTOTYPE, :P_SHIPADDRID, :P_FORMOFSECURITY, :P_INSPROTECTION, :P_LDIPROTECTION, :P_DELIVERYTYPE, :P_DELIVERYMETHOD, :P_PAYMENTMETHOD, :P_CUSTCOURIERNO, :P_REFNO, :P_NOTES, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_LOCATIONID: { val: body.P_LOCATIONID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_COMMERCIALSAMPLEFLAG: { val: body.P_COMMERCIALSAMPLEFLAG, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_PROFEQUIPMENTFLAG: { val: body.P_PROFEQUIPMENTFLAG, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_EXHIBITIONSFAIRFLAG: { val: body.P_EXHIBITIONSFAIRFLAG, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_AUTOFLAG: { val: body.P_AUTOFLAG, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_HORSEFLAG: { val: body.P_HORSEFLAG, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER },
|
|
P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_SHIPTOTYPE: { val: body.P_SHIPTOTYPE, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_SHIPADDRID: { val: body.P_SHIPADDRID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_FORMOFSECURITY: { val: body.P_FORMOFSECURITY, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_INSPROTECTION: { val: body.P_INSPROTECTION, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_LDIPROTECTION: { val: body.P_LDIPROTECTION, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_DELIVERYTYPE: { val: body.P_DELIVERYTYPE, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_DELIVERYMETHOD: { val: body.P_DELIVERYMETHOD, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_PAYMENTMETHOD: { val: body.P_PAYMENTMETHOD, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_CUSTCOURIERNO: { val: body.P_CUSTCOURIERNO, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_VARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Saved Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.TransmitApplicationtoProcess(
|
|
:P_SPID, :P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Transmitted Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async CreateApplication(body: CreateApplicationDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.CreateApplication(
|
|
:P_SPID, :P_CLIENTID, :P_LOCATIONID, :P_USERID,
|
|
:P_APPLICATIONNAME, :P_ORDERTYPE, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_LOCATIONID: { val: body.P_LOCATIONID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ORDERTYPE: { val: body.P_ORDERTYPE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
// P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Application created successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async UpdateHolder(body: CA_UpdateHolderDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.UpdateHolder(
|
|
:P_HEADERID, :P_HOLDERID, :P_ERRORMESG
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_ERRORMESG) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
// return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name);
|
|
const fres: any = await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async UpdateExpGoodsAuthRep(body: UpdateExpGoodsAuthRepDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.UpdateExpGoodsAuthRep(
|
|
:P_HEADERID, :P_COMMERCIALSAMPLEFLAG, :P_PROFEQUIPMENTFLAG,
|
|
:P_EXHIBITIONSFAIRFLAG, :P_AUTOFLAG, :P_HORSEFLAG, :P_AUTHREP,
|
|
:P_ERRORMESG
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_COMMERCIALSAMPLEFLAG: { val: body.P_COMMERCIALSAMPLEFLAG, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_PROFEQUIPMENTFLAG: { val: body.P_PROFEQUIPMENTFLAG, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_EXHIBITIONSFAIRFLAG: { val: body.P_EXHIBITIONSFAIRFLAG, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_AUTOFLAG: { val: body.P_AUTOFLAG, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HORSEFLAG: { val: body.P_HORSEFLAG, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_ERRORMESG) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async AddGenerallistItems(body: AddGenerallistItemsDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(body);
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.AddGenerallistItems(
|
|
:P_HEADERID, :P_GLTABLE, :P_USERID, :P_ERRORMESG
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' },
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_ERRORMESG) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
// return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name);
|
|
const fres: any = await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Added Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async EditGenerallistItems(body: AddGenerallistItemsDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body);
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.EditGenerallistItems(
|
|
:P_HEADERID, :P_GLTABLE, :P_USERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' },
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
// P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async DeleteGenerallistItems(body: DeleteGenerallistItemsDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body);
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.DeleteGenerallistItems(
|
|
:P_HEADERID, :P_ITEMNO, :P_USERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_ITEMNO: { val: body.P_ITEMNO, type: oracledb.DB_TYPE_NUMBER },
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' },
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
// P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Deleted Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async AddCountries(body: AddCountriesDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const COUNTRYTABLE_INSTANCE = await this.oracleService.get_COUNTRY_TABLE_INSTANCE(body);
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.AddCountries(
|
|
:P_HEADERID, :P_USSETS, :P_COUNTRYTABLE, :P_USERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER },
|
|
P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT, typeName: 'CARNETCOUNTRYTABLE' },
|
|
// P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' },
|
|
// P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
// P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Added Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async UpdateShippingDetails(body: UpdateShippingDetailsDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.UpdateShippingDetails(
|
|
:P_HEADERID,
|
|
:P_SHIPTOTYPE,:P_SHIPCONTACTID,:P_SHIPNAME,
|
|
:P_ADDRESS1,:P_ADDRESS2,:P_CITY,:P_STATE,:P_ZIP,:P_COUNTRY,
|
|
:P_FIRSTNAME,:P_LASTNAME,:P_TITLE,:P_PHONENO,:P_MOBILENO,:P_FAXNO,:P_EMAILADDRESS,:P_MIDDLEINITIAL,
|
|
:P_FORMOFSECURITY,:P_INSPROTECTION,:P_LDIPROTECTION,
|
|
:P_DELIVERYTYPE,:P_DELIVERYMETHOD,:P_PAYMENTMETHOD,
|
|
:P_CUSTCOURIERNO,:P_REFNO,:P_NOTES,:P_USERID,
|
|
:P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_SHIPTOTYPE: { val: body.P_SHIPTOTYPE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_SHIPCONTACTID: { val: body.P_SHIPCONTACTID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_SHIPNAME: { val: body.P_SHIPNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ADDRESS1: { val: body.P_ADDRESS1, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ADDRESS2: { val: body.P_ADDRESS2, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CITY: { val: body.P_CITY, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_STATE: { val: body.P_STATE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ZIP: { val: body.P_ZIP, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_COUNTRY: { val: body.P_COUNTRY, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_FIRSTNAME: { val: body.P_FIRSTNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_LASTNAME: { val: body.P_LASTNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_TITLE: { val: body.P_TITLE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_PHONENO: { val: body.P_PHONENO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_MOBILENO: { val: body.P_MOBILENO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_FAXNO: { val: body.P_FAXNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_EMAILADDRESS: { val: body.P_EMAILADDRESS, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_MIDDLEINITIAL: { val: body.P_MIDDLEINITIAL, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_FORMOFSECURITY: { val: body.P_FORMOFSECURITY, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_INSPROTECTION: { val: body.P_INSPROTECTION, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_LDIPROTECTION: { val: body.P_LDIPROTECTION, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_DELIVERYTYPE: { val: body.P_DELIVERYTYPE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_DELIVERYMETHOD: { val: body.P_DELIVERYMETHOD, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_PAYMENTMETHOD: { val: body.P_PAYMENTMETHOD, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CUSTCOURIERNO: { val: body.P_CUSTCOURIERNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async EstimatedFees(body: GetCarnetControlCenterDTO) {
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETAPPLICATION_PKG.EstimatedFees(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
return fres.length > 0 ? fres[0] : [];
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name);
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name);
|
|
}
|
|
}
|
|
|
|
// processing [ PROCESSINGCENTER_PKG ]
|
|
|
|
async ProcessCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.ProcessCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Processed Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.UpdatePrintCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async VoidCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.VoidCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Voided Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
async CopyCarnet(body: CopyCarnetDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.CopyCarnet(
|
|
:P_USERID, :P_HEADERID, :P_APPLICATIONNAME, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Copied Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async DuplicateCarnet(body: CarnetProcessingCenterDTO2) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.DuplicateCarnet(
|
|
:P_USERID, :P_CARNETNO, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CARNETNO: { val: body.P_CARNETNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Duplicated Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async AddlSets(body: CarnetProcessingCenterDTO2) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.AddlSets(
|
|
:P_USERID, :P_CARNETNO, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CARNETNO: { val: body.P_CARNETNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Additional sets completed", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async ExtendCarnet(body: CarnetProcessingCenterDTO2) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.ExtendCarnet(
|
|
:P_USERID, :P_CARNETNO, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CARNETNO: { val: body.P_CARNETNO, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Extended successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async GetExtendedSection(body: GetExtendedSectionDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.GetExtendedSection(
|
|
:P_SPID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
// return { statusCode: 200, message: "Extended successfully", ...fres[0] };
|
|
return fres.length > 0 ? fres[0] : [];
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async SaveExtensionApplication(body: SaveExtensionApplicationDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.SaveExtensionApplication(
|
|
:P_USERID, :P_SPID, :P_HEADERID, :P_GOODSPORT, :P_GOODSCOUNTRY, :P_REASONCODE, :P_EXTENSIONPERIOD, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_GOODSPORT: { val: body.P_GOODSPORT, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_GOODSCOUNTRY: { val: body.P_GOODSCOUNTRY, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_REASONCODE: { val: body.P_REASONCODE, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_EXTENSIONPERIOD: { val: body.P_EXTENSIONPERIOD, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Saved successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
async CloseCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.CloseCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Closed Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async ResetCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.ResetCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Reset Successfull", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async DeleteCarnet(body: CarnetProcessingCenterDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PROCESSINGCENTER_PKG.DeleteCarnet(
|
|
:P_USERID, :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Deleted Successfully", ...fres[0] };
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
// [ CARNETCONTROLCENTER_PKG ]
|
|
|
|
async GetHolderstoEdit(body: GetCarnetControlCenterDTO) {
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETCONTROLCENTER_PKG.GetHolderstoEdit(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
return fres.length > 0 ? fres[0] : [];
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
|
|
}
|
|
async GetGoodsDetailstoEdit(body: GetCarnetControlCenterDTO) {
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETCONTROLCENTER_PKG.GetGoodsDetailstoEdit(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
// if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
// this.logger.warn(fres[0].ERRORMESG);
|
|
// throw new BadRequestException(fres[0].ERRORMESG)
|
|
// }
|
|
|
|
return fres.length > 0 ? fres[0] : [];
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async GetCountryDetailstoEdit(body: GetCarnetControlCenterDTO) {
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETCONTROLCENTER_PKG.GetCountryDetailstoEdit(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
|
|
|
|
return fres.length > 0 ?
|
|
{
|
|
NOOFUSSETS: fres[0].NOOFUSSETS,
|
|
P_COUNTRYTABLE: fres.map(({ NOOFUSSETS, ...rest }) => rest)
|
|
}
|
|
: {};
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async GetShipPaymentDetailstoEdit(body: GetCarnetControlCenterDTO) {
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETCONTROLCENTER_PKG.GetShipPaymentDetailstoEdit(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
return fres.length > 0 ? fres[0] : [];
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async GetGoodsItemstoEdit(body: GetCarnetControlCenterDTO) {
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
CARNETCONTROLCENTER_PKG.GetGoodsItemstoEdit(
|
|
:P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
// [PRINT_PKG]
|
|
|
|
async getPrintingData(body: PrintCarnetDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
PRINT_PKG.PrintCarnet(
|
|
:P_SPID, :P_HEADERID, :P_PRINTGL, :P_CARNETDATACURSOR, :P_GLDATACURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER },
|
|
P_PRINTGL: { val: body.P_PRINTGL === 'Y' ? 'YES' : 'NO', type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CARNETDATACURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
P_GLDATACURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CARNETDATACURSOR || !outBinds?.P_GLDATACURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CARNETDATACURSOR, CarnetApplicationService.name);
|
|
const fres1: any = await fetchCursor(outBinds.P_GLDATACURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length === 0 || fres1.length === 0) {
|
|
throw new BadRequestException("Print failed please check the submitted details");
|
|
}
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
// console.log(fres, "\n", "--------------------", fres1.length > 0 ? fres[0] : []);
|
|
|
|
return { fres: fres, fres1: fres1 }
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
async PrintCarnet(body: PrintCarnetDTO) {
|
|
|
|
try {
|
|
const { fres, fres1 }: any = await this.getPrintingData(body);
|
|
|
|
if (body.P_PRINTGL === 'Y') {
|
|
if (fres.length === 0 || !fres[0].CARNETNO || fres1.length === 0) {
|
|
throw new BadRequestException("Print failed please check the submitted details");
|
|
}
|
|
}
|
|
else {
|
|
if (fres.length === 0 || !fres[0].CARNETNO) {
|
|
throw new BadRequestException("Print failed please check the submitted details");
|
|
}
|
|
}
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
try {
|
|
const glData: pdfGLData[] = fres1.map((x: any) => {
|
|
return {
|
|
itemNo: x.ITEMNO,
|
|
description: x.ITEMDESCRIPTION,
|
|
noOfPieces: x.NOOFPIECES,
|
|
weight: x.WEIGHT,
|
|
itemValue: x.ITEMVALUE,
|
|
countryOfOrigin: x.GOODSORIGINCOUNTRY
|
|
};
|
|
});
|
|
|
|
const carnetData: pdfCarnetData = {
|
|
carnetNo: fres[0].CARNETNO ?? "",
|
|
ISSUEDBY: fres[0].ISSUEDBY ?? "",
|
|
ISSUEDATE: fres[0].ISSUEDATE ?? "",
|
|
EXPDATE: fres[0].EXPDATE ?? "",
|
|
AUTHREP: fres[0].AUTHREP ?? "",
|
|
NOOFUSSETS: fres[0].NOOFUSSETS ?? 0,
|
|
NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS ?? 0,
|
|
NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS ?? 0,
|
|
PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED ?? "",
|
|
HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT ?? "",
|
|
CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS ?? 0,
|
|
NEXTUSCFNO: fres[0].NEXTUSCFNO ?? 0,
|
|
NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO ?? 0,
|
|
NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO ?? 0,
|
|
contPageNo: 0
|
|
}
|
|
|
|
const p1Status = await generateGreenCoverPDF(carnetData);
|
|
|
|
let p2Status: any = "";
|
|
|
|
if (body.P_PRINTGL === 'Y') {
|
|
p2Status = await generateGL(glData, carnetData, body);
|
|
// console.log("-------- p2 --------", p2Status);
|
|
// console.log(typeof p2Status.batch, p2Status.batch);
|
|
|
|
if (p2Status.batch % 2 === 0) {
|
|
await generateFinalPDF([...p2Status.fileArray, '2GeneralListVOID.pdf'], `${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`)
|
|
await deleteFilesAsync([...p2Status.fileArray])
|
|
}
|
|
else {
|
|
await generateFinalPDF([...p2Status.fileArray], `${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`)
|
|
await deleteFilesAsync([...p2Status.fileArray])
|
|
}
|
|
|
|
} else {
|
|
p2Status = await generateGL1(carnetData);
|
|
if (p2Status === 'p2 done') {
|
|
await generateFinalPDF([`${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`, '2GeneralListVOID.pdf'], `${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`)
|
|
}
|
|
}
|
|
|
|
const p3Status = await usCounterFoil(carnetData);
|
|
const p4Status = await fnCounterFoil(carnetData);
|
|
const p5Status = await tsCounterFoil(carnetData);
|
|
const p6Status = await fnVochers(carnetData, body);
|
|
const p7Status = await tnVochers(carnetData, body);
|
|
|
|
const finalArray = [
|
|
...p3Status,
|
|
...p4Status,
|
|
...p5Status,
|
|
...p6Status,
|
|
...p7Status
|
|
]
|
|
|
|
return { finalArray, carnetData }
|
|
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message)
|
|
}
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
async PrintGL(body: PrintGLDTO) {
|
|
|
|
let newBody: PrintCarnetDTO = { ...body, P_PRINTGL: YON.YES }
|
|
|
|
try {
|
|
const { fres, fres1 }: any = await this.getPrintingData(newBody);
|
|
|
|
if (fres.length === 0 || fres1.length === 0) {
|
|
throw new BadRequestException("Print failed please check the submitted details");
|
|
}
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
try {
|
|
const glData: pdfGLData[] = fres1.map(x => {
|
|
return {
|
|
itemNo: x.ITEMNO,
|
|
description: x.ITEMDESCRIPTION,
|
|
noOfPieces: x.NOOFPIECES,
|
|
weight: x.WEIGHT,
|
|
itemValue: x.ITEMVALUE,
|
|
countryOfOrigin: x.GOODSORIGINCOUNTRY
|
|
};
|
|
});
|
|
|
|
const carnetData: pdfCarnetData = {
|
|
carnetNo: fres[0].CARNETNO ?? "",
|
|
ISSUEDBY: fres[0].ISSUEDBY ?? "",
|
|
ISSUEDATE: fres[0].ISSUEDATE ?? "",
|
|
EXPDATE: fres[0].EXPDATE ?? "",
|
|
AUTHREP: fres[0].AUTHREP ?? "",
|
|
NOOFUSSETS: fres[0].NOOFUSSETS ?? 0,
|
|
NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS ?? 0,
|
|
NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS ?? 0,
|
|
PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED ?? "",
|
|
HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT ?? "",
|
|
CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS ?? 0,
|
|
NEXTUSCFNO: fres[0].NEXTUSCFNO ?? 0,
|
|
NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO ?? 0,
|
|
NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO ?? 0,
|
|
contPageNo: 0
|
|
}
|
|
|
|
// const p1Status = await generateGreenCoverPDF(carnetData);
|
|
|
|
let p2Status: any = "";
|
|
|
|
p2Status = await generateGL(glData, carnetData, body);
|
|
// console.log("-------- p2 --------", p2Status);
|
|
// console.log(typeof p2Status.batch, p2Status.batch);
|
|
|
|
if (p2Status.batch % 2 === 0) {
|
|
await generateFinalPDF([...p2Status.fileArray, '2GeneralListVOID.pdf'], `${body.P_HEADERID}p2.pdf`)
|
|
await deleteFilesAsync([...p2Status.fileArray])
|
|
}
|
|
else {
|
|
await generateFinalPDF([...p2Status.fileArray], `${body.P_HEADERID}p2.pdf`)
|
|
await deleteFilesAsync([...p2Status.fileArray])
|
|
}
|
|
|
|
// const p3Status = await usCounterFoil(carnetData);
|
|
// const p4Status = await fnCounterFoil(carnetData);
|
|
// const p5Status = await tsCounterFoil(carnetData);
|
|
// const p6Status = await fnVochers(carnetData);
|
|
// const p7Status = await tnVochers(carnetData);
|
|
|
|
const finalArray = [
|
|
// ...p3Status,
|
|
// ...p4Status,
|
|
// ...p5Status,
|
|
// ...p6Status,
|
|
// ...p7Status
|
|
]
|
|
|
|
return { finalArray, carnetData }
|
|
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message)
|
|
}
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
|
|
// [payment]
|
|
|
|
async formatAmount(amount) {
|
|
if (typeof amount !== 'number' || isNaN(amount)) {
|
|
throw new Error('Amount must be a valid number');
|
|
}
|
|
|
|
if (amount < 0) {
|
|
throw new BadRequestException('Amount must be non-negative');
|
|
}
|
|
|
|
return amount.toFixed(2); // Always returns a string with 2 decimal places
|
|
}
|
|
|
|
|
|
|
|
async InitiatePayment(body: InitiatePaymentDTO) {
|
|
// console.log(body);
|
|
|
|
const quantity = 1;
|
|
|
|
const formattedAmount = await this.formatAmount(body.P_PRICE * quantity);
|
|
|
|
try {
|
|
const accessToken = await this.payPalService.generateAccessToken();
|
|
|
|
// return {
|
|
// id: "6CU709471L678832M",
|
|
// href: "https://www.sandbox.paypal.com/checkoutnow?token=6CU709471L678832M"
|
|
// }
|
|
|
|
const response = await axios({
|
|
url: process.env.PAYPAL_BASE_URL + '/v2/checkout/orders',
|
|
method: 'post',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + accessToken
|
|
},
|
|
data: JSON.stringify({
|
|
intent: 'CAPTURE',
|
|
purchase_units: [
|
|
{
|
|
items: [
|
|
{
|
|
name: 'Carnet',
|
|
description: body.P_DESCRIPTION,
|
|
quantity: quantity,
|
|
unit_amount: {
|
|
currency_code: 'USD',
|
|
value: formattedAmount
|
|
}
|
|
}
|
|
],
|
|
amount: {
|
|
currency_code: 'USD',
|
|
value: formattedAmount,
|
|
breakdown: {
|
|
item_total: {
|
|
currency_code: 'USD',
|
|
value: formattedAmount
|
|
}
|
|
}
|
|
}
|
|
}
|
|
],
|
|
application_context: {
|
|
return_url: process.env.BASE_URL + '/complete-order',
|
|
cancel_url: process.env.BASE_URL + '/cancel-order',
|
|
shipping_preference: 'NO_SHIPPING',
|
|
user_action: 'PAY_NOW',
|
|
brand_name: 'test sample',
|
|
disable_funding: "card"
|
|
}
|
|
})
|
|
});
|
|
|
|
// console.log('PayPal create order response headers:', response.headers);
|
|
// console.log('PayPal create order response data:', response.data);
|
|
|
|
return {
|
|
id: response.data.id, href: response?.data?.links?.find(obj => obj.rel === 'approve')?.href
|
|
};
|
|
|
|
// return { id: response.data.id };
|
|
|
|
} catch (error) {
|
|
console.error('Error creating PayPal order:', error.response?.data || error.message || error);
|
|
|
|
// Return a structured error object or throw to be handled by caller
|
|
|
|
throw new InternalServerException();
|
|
// return {
|
|
// error: true,
|
|
// message: 'Failed to create PayPal order',
|
|
// details: error.response?.data || error.message || error
|
|
// };
|
|
}
|
|
}
|
|
|
|
async CapturePayment(body: CapturePaymentDTO) {
|
|
try {
|
|
const accessToken = await this.payPalService.generateAccessToken();
|
|
|
|
const response = await axios({
|
|
url: `${process.env.PAYPAL_BASE_URL}/v2/checkout/orders/${body.P_ORDERID}/capture`,
|
|
method: 'post',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${accessToken}`,
|
|
},
|
|
});
|
|
|
|
const capture = response?.data?.purchase_units?.[0]?.payments?.captures?.[0];
|
|
// console.log(JSON.stringify(response?.data));
|
|
|
|
return {
|
|
statusCode: 200,
|
|
message: "Payment successful",
|
|
amount: `${capture?.amount?.value} ${capture?.amount?.currency_code}`,
|
|
};
|
|
|
|
} catch (error: any) {
|
|
const status = error.response?.status || 500;
|
|
const message = error.response?.data?.message || "Payment failed due to an unexpected error.";
|
|
|
|
// Optional: log full error for debugging
|
|
console.error("PayPal Capture Error:", {
|
|
status,
|
|
message,
|
|
details: error.response?.data,
|
|
});
|
|
|
|
if (status === 404) {
|
|
throw new NotFoundException(error.response?.data?.message || error?.message || "Resource Not Found")
|
|
}
|
|
|
|
throw new InternalServerException();
|
|
}
|
|
}
|
|
|
|
async OrderDetails(body: GetOrderDetailsDTO) {
|
|
try {
|
|
|
|
// Max length of Order ID: 36 characters (UUID)
|
|
if (!body.P_ORDERID || body.P_ORDERID.length > 36) {
|
|
throw new BadRequestException("Invalid Order ID");
|
|
}
|
|
|
|
const accessToken = await this.payPalService.generateAccessToken();
|
|
|
|
const response = await axios({
|
|
url: `${process.env.PAYPAL_BASE_URL}/v2/checkout/orders/${body.P_ORDERID}`,
|
|
method: 'get',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${accessToken}`,
|
|
},
|
|
});
|
|
|
|
// console.log("PayPal Order Details:", JSON.stringify(response.data));
|
|
|
|
return {
|
|
statusCode: 200,
|
|
message: "Order details retrieved successfully",
|
|
data: response.data,
|
|
};
|
|
|
|
} catch (error: any) {
|
|
const isAxiosError = error.isAxiosError;
|
|
|
|
if (isAxiosError) {
|
|
const axiosErrorCode = error.code;
|
|
|
|
switch (axiosErrorCode) {
|
|
case 'ECONNABORTED':
|
|
case 'ETIMEDOUT':
|
|
console.error("PayPal request timed out. Please try again later.")
|
|
throw new InternalServerException("Service is currently unreachable. Please try again later.");
|
|
case 'ENOTFOUND':
|
|
case 'ECONNREFUSED':
|
|
console.error("PayPal service is currently unavailable. Please try again later.")
|
|
throw new InternalServerException("Service is currently unreachable. Please try again later.");
|
|
}
|
|
}
|
|
|
|
const status = error.response?.status || 500;
|
|
const message = error.response?.data?.message || "Failed to fetch order details.";
|
|
|
|
|
|
console.error("PayPal OrderDetails Error:", {
|
|
status,
|
|
message,
|
|
details: error.response?.data,
|
|
});
|
|
|
|
if (status === 404) {
|
|
throw new NotFoundException(message);
|
|
}
|
|
|
|
throw new InternalServerException("A Error Occured while Processing your Request");
|
|
}
|
|
}
|
|
|
|
async GetPaymentHistory(body: GetPaymentHistoryDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
Pay_GetPaymentHistory(
|
|
:P_APPLICATIONNAME, :P_USERID, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return fres.length > 0 ? fres[0] : {}
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
async SaveHistory(body: SaveHistoryDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
Pay_SaveHistory(
|
|
:P_APPLICATIONNAME, :P_ORDERID, :P_PAYMENTAMOUNT, :P_STATUS, :P_USERID, :P_PAYMENTERROR, :P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_ORDERID: { val: body.P_ORDERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_PAYMENTAMOUNT: { val: body.P_PAYMENTAMOUNT, type: oracledb.DB_TYPE_NUMBER },
|
|
P_STATUS: { val: body.P_STATUS, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_PAYMENTERROR: { val: body.P_PAYMENTERROR, type: oracledb.DB_TYPE_NVARCHAR },
|
|
P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
|
|
// P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
|
|
},
|
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
|
);
|
|
|
|
await connection.commit();
|
|
|
|
const outBinds = result.outBinds;
|
|
if (!outBinds?.P_CURSOR) {
|
|
this.logger.error('One or more expected cursors are missing from stored procedure output.');
|
|
throw new InternalServerException("Incomplete data received from the database.");
|
|
}
|
|
|
|
const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name);
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Saved Successfully", ...fres[0] };
|
|
|
|
} catch (error) {
|
|
handleError(error, CarnetApplicationService.name)
|
|
} finally {
|
|
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
|
}
|
|
}
|
|
}
|