BE/src/oracle/carnet-application/carnet-application.service.ts
2025-08-07 20:18:55 +05:30

1223 lines
54 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, generateFinalPDF, generateGeneralistPDF1, generateGeneralistPDF2, handleError, pdfCarnetData, pdfGLData, setEmptyStringsToNull } from 'src/utils/helper';
import {
CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO,
CreateApplicationDTO,
UpdateExpGoodsAuthRepDTO,
AddGenerallistItemsDTO,
AddCountriesDTO,
UpdateShippingDetailsDTO,
CA_UpdateHolderDTO,
GetCarnetControlCenterDTO,
DeleteGenerallistItemsDTO,
PrintCarnetDTO
} from 'src/dto/property.dto';
import { OracleService } from '../oracle.service';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
@Injectable()
export class CarnetApplicationService {
private readonly logger = new Logger(CarnetApplicationService.name);
constructor(
private readonly oracleDBService: OracleDBService,
private readonly oracleService: OracleService
) { }
// [ 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_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 DuplicateCarnet(body: CarnetProcessingCenterDTO) {
let connection;
try {
connection = await this.oracleDBService.getConnection();
const result = await connection.execute(
`BEGIN
PROCESSINGCENTER_PKG.DuplicateCarnet(
: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: "Duplicated 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)
}
return { fres: fres, fres1: fres1 }
} catch (error) {
handleError(error, CarnetApplicationService.name)
} finally {
await closeOracleDbConnection(connection, CarnetApplicationService.name)
}
}
async PrintCarnet(body: PrintCarnetDTO) {
try {
const { fres }: any = await this.getPrintingData(body);
const { fres1 }: any = await this.getPrintingData(body);
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,
contPageNo: 0
}
let p2Status: string = "";
if (body.P_PRINTGL === 'Y') {
p2Status = await generateGeneralistPDF1(glData, carnetData);
} else {
p2Status = await generateGeneralistPDF2(carnetData.carnetNo);
}
if (p2Status === "p2 done") {
await generateFinalPDF(['p2.pdf'], 'carnet.pdf');
}
} catch (error) {
throw new InternalServerException(error.message)
}
} catch (error) {
handleError(error, CarnetApplicationService.name)
}
}
}