new apis
This commit is contained in:
parent
f3cbadebd7
commit
c670266256
@ -52,6 +52,40 @@ export class APPLICATIONNAME_DTO {
|
||||
P_APPLICATIONNAME: string;
|
||||
}
|
||||
|
||||
export class GOODS_PORT_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString({ message: 'Property P_GOODSPORT must be a string' })
|
||||
@IsDefined({ message: 'Property P_GOODSPORT is required' })
|
||||
P_GOODSPORT: string;
|
||||
}
|
||||
|
||||
export class GOODS_COUNTRY_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString({ message: 'Property P_GOODSCOUNTRY must be a string' })
|
||||
@IsDefined({ message: 'Property P_GOODSCOUNTRY is required' })
|
||||
P_GOODSCOUNTRY: string;
|
||||
}
|
||||
|
||||
export class REASON_CODE_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString({ message: 'Property P_REASONCODE must be a string' })
|
||||
@IsDefined({ message: 'Property P_REASONCODE is required' })
|
||||
P_REASONCODE: string;
|
||||
}
|
||||
|
||||
export class EXTENSION_PERIOD_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@Max(999999999, {
|
||||
message: 'Property P_EXTENSIONPERIOD must not exceed 999999999',
|
||||
})
|
||||
@Min(0, { message: 'Property P_EXTENSIONPERIOD must be at least 0 or more' })
|
||||
@IsInt({ message: 'Property P_EXTENSIONPERIOD allows only whole numbers' })
|
||||
@IsNumber({}, { message: 'Property P_EXTENSIONPERIOD must be a number' })
|
||||
@Transform(({ value }) => Number(value))
|
||||
@IsDefined({ message: 'Property P_EXTENSIONPERIOD is required' })
|
||||
P_EXTENSIONPERIOD: number;
|
||||
}
|
||||
|
||||
export class ORDERTYPE_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString({ message: 'Property P_ORDERTYPE must be a string' })
|
||||
@ -170,6 +204,63 @@ export class GLTABLE_ROW_DTO {
|
||||
GOODSORIGINCOUNTRY: string;
|
||||
}
|
||||
|
||||
export class GLTABLE_ROW_ADD_DTO {
|
||||
@ApiProperty({ required: false })
|
||||
@Max(99999, { message: 'Property ITEMNO must not exceed 99999' })
|
||||
@Min(0, { message: 'Property ITEMNO must be at least 0 or more' })
|
||||
@IsInt({ message: 'Property ITEMNO allows only whole numbers' })
|
||||
@Transform(({ value }) => {
|
||||
if (value === undefined || value === null || value === '') return 0;
|
||||
return Number(value);
|
||||
})
|
||||
@IsNumber({}, { message: 'Property ITEMNO must be a number' })
|
||||
@IsOptional()
|
||||
ITEMNO: number = 0
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@MaxLength(200, { message: 'Property ITEMDESCRIPTION must not exceed 200 characters' })
|
||||
@IsString({ message: 'Property ITEMDESCRIPTION must be a string' })
|
||||
@IsDefined({ message: 'Property ITEMDESCRIPTION is required' })
|
||||
ITEMDESCRIPTION: string;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@Max(999999999.99, { message: 'Property ITEMVALUE must not exceed 999999999.99' })
|
||||
@Min(0, { message: 'Property ITEMVALUE must be at least 0 or more' })
|
||||
@Transform(({ value }) => Number(value))
|
||||
@IsNumber({ maxDecimalPlaces: 2 }, { message: 'Property ITEMVALUE must be a number' })
|
||||
@IsDefined({ message: 'Property ITEMVALUE is required' })
|
||||
ITEMVALUE: number;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@Max(99999, { message: 'Property NOOFPIECES must not exceed 99999' })
|
||||
@Min(0, { message: 'Property NOOFPIECES must be at least 0 or more' })
|
||||
@IsInt({ message: 'Property NOOFPIECES allows only whole numbers' })
|
||||
@Transform(({ value }) => Number(value))
|
||||
@IsNumber({}, { message: 'Property NOOFPIECES must be a number' })
|
||||
@IsDefined({ message: 'Property NOOFPIECES is required' })
|
||||
NOOFPIECES: number;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@Max(99999.9999, { message: 'Property ITEMVALUE must not exceed 999999999.99' })
|
||||
@Min(0, { message: 'Property ITEMVALUE must be at least 0 or more' })
|
||||
@Transform(({ value }) => Number(value))
|
||||
@IsNumber({ maxDecimalPlaces: 2 }, { message: 'Property ITEMVALUE must be a number' })
|
||||
@IsDefined({ message: 'Property ITEMVALUE is required' })
|
||||
ITEMWEIGHT: number;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@MaxLength(10, { message: 'Property ITEMWEIGHTUOM must not exceed 10 characters' })
|
||||
@IsString({ message: 'Property ITEMWEIGHTUOM must be a string' })
|
||||
@IsDefined({ message: 'Property ITEMWEIGHTUOM is required' })
|
||||
ITEMWEIGHTUOM: string;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@MaxLength(2, { message: 'Property GOODSORIGINCOUNTRY must not exceed 2 characters' })
|
||||
@IsString({ message: 'Property GOODSORIGINCOUNTRY must be a string' })
|
||||
@IsDefined({ message: 'Property GOODSORIGINCOUNTRY is required' })
|
||||
GOODSORIGINCOUNTRY: string;
|
||||
}
|
||||
|
||||
export class GLTABLE_DTO {
|
||||
@ApiProperty({ required: true, type: () => [GLTABLE_ROW_DTO] })
|
||||
@Type(() => GLTABLE_ROW_DTO)
|
||||
@ -179,7 +270,16 @@ export class GLTABLE_DTO {
|
||||
P_GLTABLE: GLTABLE_ROW_DTO[];
|
||||
}
|
||||
|
||||
export class ITEMNO_DTO{
|
||||
export class GLTABLE_ITEMNO_OPTIONAL_DTO {
|
||||
@ApiProperty({ required: true, type: () => [GLTABLE_ROW_ADD_DTO] })
|
||||
@Type(() => GLTABLE_ROW_ADD_DTO)
|
||||
@ValidateNested({ each: true })
|
||||
@IsArray({ message: 'Property P_GLTABLE allows only array type' })
|
||||
@IsDefined({ message: 'Property P_GLTABLE is required' })
|
||||
P_GLTABLE: GLTABLE_ROW_ADD_DTO[];
|
||||
}
|
||||
|
||||
export class ITEMNO_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@Max(99999, { message: 'Property ITEMNO must not exceed 99999' })
|
||||
@Min(0, { message: 'Property ITEMNO must be at least 0 or more' })
|
||||
@ -190,7 +290,7 @@ export class ITEMNO_DTO{
|
||||
P_ITEMNO: number;
|
||||
}
|
||||
|
||||
export class SHIPCONTACTID_DTO{
|
||||
export class SHIPCONTACTID_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@Max(99999, { message: 'Property P_SHIPCONTACTID must not exceed 99999' })
|
||||
@Min(0, { message: 'Property P_SHIPCONTACTID must be at least 0 or more' })
|
||||
|
||||
@ -3,10 +3,10 @@ import { IntersectionType, PartialType } from "@nestjs/swagger";
|
||||
import {
|
||||
APPLICATIONNAME_DTO, AUTHREP_DTO, AUTO_FLAG_DTO, COMMERCIAL_SAMPLE_FLAG_DTO,
|
||||
COUNTRYTABLE_DTO, CUSTCOURIERNO_DTO, DELIVERYMETHOD_DTO, DELIVERYTYPE_DTO,
|
||||
EXIBITIONS_FAIR_FLAG_DTO, FORMOFSECURITY_DTO, GLTABLE_DTO, HEADERID_DTO,
|
||||
EXIBITIONS_FAIR_FLAG_DTO, EXTENSION_PERIOD_DTO, FORMOFSECURITY_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GOODS_COUNTRY_DTO, GOODS_PORT_DTO, HEADERID_DTO,
|
||||
HORSE_FLAG_DTO, INSPROTECTION_DTO, ITEMNO_DTO, LDIPROTECTION_DTO, ORDERTYPE_DTO, PAYMENTMETHOD_DTO,
|
||||
PRINTGL_DTO,
|
||||
PROF_EQUIPMENT_FLAG_DTO, REFNO_DTO, SHIPADDRID_DTO, SHIPCONTACTID_DTO, SHIPNAME_DTO, SHIPTOTYPE_DTO, USSETS_DTO
|
||||
PROF_EQUIPMENT_FLAG_DTO, REASON_CODE_DTO, REFNO_DTO, SHIPADDRID_DTO, SHIPCONTACTID_DTO, SHIPNAME_DTO, SHIPTOTYPE_DTO, USSETS_DTO
|
||||
} from "./carnet-application-property.dto";
|
||||
|
||||
import { ADDRESS1_DTO, ADDRESS2_DTO, CITY_DTO, COUNTRY_DTO, NOTES_DTO, SPID_DTO, STATE_DTO, USERID_DTO, ZIP_DTO } from "../uscib-managed-sp/sp/sp-property.dto";
|
||||
@ -52,8 +52,18 @@ export class TransmitApplicationtoProcessDTO extends IntersectionType(
|
||||
) { }
|
||||
|
||||
// processing [ PROCESSINGCENTER_PKG ]
|
||||
|
||||
export class CopyCarnetDTO extends (IntersectionType(USERID_DTO, HEADERID_DTO, APPLICATIONNAME_DTO)) { }
|
||||
export class CarnetProcessingCenterDTO extends (IntersectionType(USERID_DTO, HEADERID_DTO)) { }
|
||||
export class GetExtendedSectionDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO)){}
|
||||
export class SaveExtensionApplicationDTO extends(IntersectionType(
|
||||
USERID_DTO,
|
||||
SPID_DTO,
|
||||
HEADERID_DTO,
|
||||
GOODS_PORT_DTO,
|
||||
GOODS_COUNTRY_DTO,
|
||||
REASON_CODE_DTO,
|
||||
EXTENSION_PERIOD_DTO
|
||||
)){}
|
||||
|
||||
export class PrintCarnetDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO, PRINTGL_DTO)) { }
|
||||
export class PrintGLDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO)) { }
|
||||
@ -74,6 +84,10 @@ export class UpdateExpGoodsAuthRepDTO extends IntersectionType(
|
||||
) { }
|
||||
|
||||
export class AddGenerallistItemsDTO extends IntersectionType(
|
||||
HEADERID_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, USERID_DTO
|
||||
) { }
|
||||
|
||||
export class EditGenerallistItemsDTO extends IntersectionType(
|
||||
HEADERID_DTO, GLTABLE_DTO, USERID_DTO
|
||||
) { }
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Body, Controller, Delete, Get, Param, Patch, Post, Put, Res, StreamableFile, UseGuards } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Delete, Get, HttpCode, Param, Patch, Post, Put, Res, StreamableFile, UseGuards } from '@nestjs/common';
|
||||
import { CarnetApplicationService } from './carnet-application.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
AddCountriesDTO,
|
||||
AddGenerallistItemsDTO,
|
||||
CA_UpdateHolderDTO,
|
||||
CarnetProcessingCenterDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, GetCarnetControlCenterDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO,
|
||||
CarnetProcessingCenterDTO, CopyCarnetDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, EditGenerallistItemsDTO, GetCarnetControlCenterDTO, GetExtendedSectionDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, SaveExtensionApplicationDTO, TransmitApplicationtoProcessDTO,
|
||||
UpdateExpGoodsAuthRepDTO,
|
||||
UpdateShippingDetailsDTO
|
||||
} from 'src/dto/property.dto';
|
||||
@ -70,7 +70,7 @@ export class CarnetApplicationController {
|
||||
}
|
||||
|
||||
@Put('EditGenerallistItems')
|
||||
EditGenerallistItems(@Body() body: AddGenerallistItemsDTO) {
|
||||
EditGenerallistItems(@Body() body: EditGenerallistItemsDTO) {
|
||||
return this.carnetApplicationService.EditGenerallistItems(body);
|
||||
}
|
||||
|
||||
@ -107,12 +107,38 @@ export class CarnetApplicationController {
|
||||
return this.carnetApplicationService.VoidCarnet(body);
|
||||
}
|
||||
|
||||
|
||||
@Patch('CopyCarnet')
|
||||
CopyCarnet(@Body() body: CopyCarnetDTO) {
|
||||
return this.carnetApplicationService.CopyCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('DuplicateCarnet')
|
||||
@Roles('ca')
|
||||
DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.DuplicateCarnet(body);
|
||||
}
|
||||
|
||||
@Patch('AddlSets')
|
||||
AddlSets(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.AddlSets(body);
|
||||
}
|
||||
|
||||
@Patch('ExtendCarnet')
|
||||
ExtendCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
return this.carnetApplicationService.ExtendCarnet(body);
|
||||
}
|
||||
|
||||
@Get('GetExtendedSection/:P_SPID/:P_HEADERID')
|
||||
GetExtendedSection(@Param() body: GetExtendedSectionDTO) {
|
||||
return this.carnetApplicationService.GetExtendedSection(body);
|
||||
}
|
||||
|
||||
@Post('SaveExtensionApplication')
|
||||
@HttpCode(200)
|
||||
SaveExtensionApplication(@Body() body: SaveExtensionApplicationDTO) {
|
||||
return this.carnetApplicationService.SaveExtensionApplication(body);
|
||||
}
|
||||
|
||||
@Patch('CloseCarnet')
|
||||
@Roles('sa')
|
||||
CloseCarnet(@Body() body: CarnetProcessingCenterDTO) {
|
||||
@ -158,7 +184,7 @@ export class CarnetApplicationController {
|
||||
|
||||
// [PRINT_PKG]
|
||||
@Post('PrintCarnet')
|
||||
@Roles('ca', 'sa', 'ua')
|
||||
@HttpCode(200)
|
||||
async PrintCarnet(@Body() body: PrintCarnetDTO, @Res({ passthrough: true }) res: Response) {
|
||||
|
||||
try {
|
||||
@ -203,16 +229,16 @@ export class CarnetApplicationController {
|
||||
}
|
||||
|
||||
@Post('PrintGL')
|
||||
@Roles('ca', 'sa', 'ua')
|
||||
@HttpCode(200)
|
||||
async PrintGL(@Body() body: PrintGLDTO, @Res({ passthrough: true }) res: Response) {
|
||||
try {
|
||||
const { finalArray, carnetData }: any = await this.carnetApplicationService.PrintGL(body);
|
||||
|
||||
let filesArray = [`${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`];
|
||||
let filesArray = [`${body.P_HEADERID}p2.pdf`];
|
||||
// await generateFinalPDF([...filesArray, '2GeneralList.pdf', ...carnetData], 'carnet.pdf');
|
||||
await generateFinalPDF([...filesArray, ...finalArray], `${replaceSlashWithDash(carnetData.carnetNo)}-GL.pdf`);
|
||||
await generateFinalPDF([...filesArray, ...finalArray], `${body.P_HEADERID}-GL.pdf`);
|
||||
|
||||
const fileName = `${replaceSlashWithDash(carnetData.carnetNo)}-GL.pdf`;
|
||||
const fileName = `${body.P_HEADERID}-GL.pdf`;
|
||||
|
||||
res.set({
|
||||
'Content-Type': 'application/pdf',
|
||||
@ -236,7 +262,12 @@ export class CarnetApplicationController {
|
||||
|
||||
return new StreamableFile(stream);
|
||||
} catch (error) {
|
||||
return error.message;
|
||||
if (error instanceof BadRequestException || error instanceof BR) {
|
||||
throw new BadRequestException("Download failed please check the details")
|
||||
}
|
||||
else {
|
||||
throw new InternalServerException("Error while downloading");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,10 @@ import {
|
||||
DeleteGenerallistItemsDTO,
|
||||
PrintCarnetDTO,
|
||||
PrintGLDTO,
|
||||
YON
|
||||
YON,
|
||||
CopyCarnetDTO,
|
||||
GetExtendedSectionDTO,
|
||||
SaveExtensionApplicationDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { OracleService } from '../oracle.service';
|
||||
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||
@ -327,7 +330,7 @@ export class CarnetApplicationService {
|
||||
try {
|
||||
connection = await this.oracleDBService.getConnection();
|
||||
|
||||
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body);
|
||||
const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(body);
|
||||
|
||||
const result = await connection.execute(
|
||||
`BEGIN
|
||||
@ -750,6 +753,50 @@ export class CarnetApplicationService {
|
||||
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: CarnetProcessingCenterDTO) {
|
||||
let connection;
|
||||
try {
|
||||
@ -792,6 +839,181 @@ export class CarnetApplicationService {
|
||||
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
||||
}
|
||||
}
|
||||
async AddlSets(body: CarnetProcessingCenterDTO) {
|
||||
let connection;
|
||||
try {
|
||||
connection = await this.oracleDBService.getConnection();
|
||||
|
||||
const result = await connection.execute(
|
||||
`BEGIN
|
||||
PROCESSINGCENTER_PKG.AddlSets(
|
||||
: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: "Additional sets completed", ...fres[0] };
|
||||
} catch (error) {
|
||||
handleError(error, CarnetApplicationService.name)
|
||||
} finally {
|
||||
await closeOracleDbConnection(connection, CarnetApplicationService.name)
|
||||
}
|
||||
}
|
||||
async ExtendCarnet(body: CarnetProcessingCenterDTO) {
|
||||
let connection;
|
||||
try {
|
||||
connection = await this.oracleDBService.getConnection();
|
||||
|
||||
const result = await connection.execute(
|
||||
`BEGIN
|
||||
PROCESSINGCENTER_PKG.ExtendCarnet(
|
||||
: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: "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;
|
||||
} 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 {
|
||||
@ -1159,6 +1381,8 @@ export class CarnetApplicationService {
|
||||
throw new BadRequestException(fres[0].ERRORMESG)
|
||||
}
|
||||
|
||||
// console.log(fres, "\n", "--------------------", fres1.length > 0 ? fres[0] : []);
|
||||
|
||||
return { fres: fres, fres1: fres1 }
|
||||
|
||||
} catch (error) {
|
||||
@ -1173,9 +1397,16 @@ export class CarnetApplicationService {
|
||||
try {
|
||||
const { fres, fres1 }: any = await this.getPrintingData(body);
|
||||
|
||||
if (fres.length === 0 || fres1.length === 0) {
|
||||
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);
|
||||
@ -1183,7 +1414,7 @@ export class CarnetApplicationService {
|
||||
}
|
||||
|
||||
try {
|
||||
const glData: pdfGLData[] = fres1.map(x => {
|
||||
const glData: pdfGLData[] = fres1.map((x: any) => {
|
||||
return {
|
||||
itemNo: x.ITEMNO,
|
||||
description: x.ITEMDESCRIPTION,
|
||||
@ -1195,20 +1426,20 @@ export class CarnetApplicationService {
|
||||
});
|
||||
|
||||
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,
|
||||
NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS,
|
||||
NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS,
|
||||
PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED,
|
||||
HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT,
|
||||
CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS,
|
||||
NEXTUSCFNO: fres[0].NEXTUSCFNO,
|
||||
NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO,
|
||||
NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO,
|
||||
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
|
||||
}
|
||||
|
||||
@ -1217,7 +1448,7 @@ export class CarnetApplicationService {
|
||||
let p2Status: any = "";
|
||||
|
||||
if (body.P_PRINTGL === 'Y') {
|
||||
p2Status = await generateGL(glData, carnetData);
|
||||
p2Status = await generateGL(glData, carnetData, body);
|
||||
// console.log("-------- p2 --------", p2Status);
|
||||
// console.log(typeof p2Status.batch, p2Status.batch);
|
||||
|
||||
@ -1291,20 +1522,20 @@ export class CarnetApplicationService {
|
||||
});
|
||||
|
||||
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,
|
||||
NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS,
|
||||
NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS,
|
||||
PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED,
|
||||
HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT,
|
||||
CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS,
|
||||
NEXTUSCFNO: fres[0].NEXTUSCFNO,
|
||||
NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO,
|
||||
NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO,
|
||||
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
|
||||
}
|
||||
|
||||
@ -1312,16 +1543,16 @@ export class CarnetApplicationService {
|
||||
|
||||
let p2Status: any = "";
|
||||
|
||||
p2Status = await generateGL(glData, carnetData);
|
||||
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 generateFinalPDF([...p2Status.fileArray, '2GeneralListVOID.pdf'], `${body.P_HEADERID}p2.pdf`)
|
||||
await deleteFilesAsync([...p2Status.fileArray])
|
||||
}
|
||||
else {
|
||||
await generateFinalPDF([...p2Status.fileArray], `${replaceSlashWithDash(carnetData.carnetNo)}p2.pdf`)
|
||||
await generateFinalPDF([...p2Status.fileArray], `${body.P_HEADERID}p2.pdf`)
|
||||
await deleteFilesAsync([...p2Status.fileArray])
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { OracleDBService } from "src/db/db.service";
|
||||
import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto";
|
||||
import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GLTABLE_ROW_ADD_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto";
|
||||
import { InternalServerException } from "src/exceptions/internalServerError.exception";
|
||||
import { closeOracleDbConnection, handleError } from "src/utils/helper";
|
||||
|
||||
@ -10,6 +10,62 @@ export class OracleService {
|
||||
|
||||
constructor(private readonly oracleDBService: OracleDBService) { }
|
||||
|
||||
async get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(finalBody: any) {
|
||||
|
||||
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }
|
||||
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
||||
|
||||
let connection;
|
||||
|
||||
try {
|
||||
connection = await this.oracleDBService.getConnection();
|
||||
|
||||
const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE');
|
||||
|
||||
if (typeof GLTABLE !== 'function') {
|
||||
throw new InternalServerException('GLTABLE is not a constructor');
|
||||
}
|
||||
|
||||
async function createGLArrayInstance(
|
||||
ITEMNO, ITEMDESCRIPTION, ITEMVALUE, NOOFPIECES,
|
||||
ITEMWEIGHT, ITEMWEIGHTUOM, GOODSORIGINCOUNTRY,
|
||||
) {
|
||||
const result = await connection.execute(
|
||||
`SELECT CARNETSYS.GLARRAY(
|
||||
:ITEMNO, :ITEMDESCRIPTION, :ITEMVALUE, :NOOFPIECES,
|
||||
:ITEMWEIGHT, :ITEMWEIGHTUOM, :GOODSORIGINCOUNTRY
|
||||
) FROM dual`,
|
||||
{
|
||||
ITEMNO, ITEMDESCRIPTION, ITEMVALUE, NOOFPIECES,
|
||||
ITEMWEIGHT, ITEMWEIGHTUOM, GOODSORIGINCOUNTRY,
|
||||
}
|
||||
);
|
||||
return result.rows[0][0];
|
||||
}
|
||||
|
||||
const GLTABLE_ARRAY: GLTABLE_ITEMNO_OPTIONAL_DTO = {
|
||||
P_GLTABLE: await Promise.all(
|
||||
(finalBody.P_GLTABLE ?? []).map(async (x: GLTABLE_ROW_ADD_DTO) => {
|
||||
return await createGLArrayInstance(
|
||||
x.ITEMNO, x.ITEMDESCRIPTION, x.ITEMVALUE, x.NOOFPIECES,
|
||||
x.ITEMWEIGHT, x.ITEMWEIGHTUOM, x.GOODSORIGINCOUNTRY,
|
||||
);
|
||||
})
|
||||
)
|
||||
};
|
||||
|
||||
const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY.P_GLTABLE ?? []);
|
||||
|
||||
return GLTABLE_INSTANCE;
|
||||
|
||||
} catch (error) {
|
||||
console.log("error while creating GL instance : ", error);
|
||||
throw new Error("Error occured completing this process")
|
||||
} finally {
|
||||
await closeOracleDbConnection(connection, OracleService.name)
|
||||
}
|
||||
}
|
||||
|
||||
async get_GL_TABLE_INSTANCE(finalBody: any) {
|
||||
|
||||
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }
|
||||
|
||||
@ -13,7 +13,7 @@ import * as fsPromises from 'fs/promises';
|
||||
import { BadRequestException as BR } from 'src/exceptions/badRequest.exception';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { PDFDocument as pdfl, TextAlignment, PDFTextField, PDFCheckBox, PDFRadioGroup, PDFDropdown, PDFOptionList } from 'pdf-lib';
|
||||
import { PrintCarnetDTO } from 'src/dto/property.dto';
|
||||
import { PrintCarnetDTO, PrintGLDTO } from 'src/dto/property.dto';
|
||||
|
||||
const logger = new Logger('Helper');
|
||||
|
||||
@ -1114,6 +1114,7 @@ export async function processGlDataInBatches(
|
||||
glDataArray: pdfGLData[],
|
||||
batchSize: number,
|
||||
carnetData: pdfCarnetData, // carnetData is a parameter here
|
||||
body: PrintGLDTO,
|
||||
batchCallback: (batch: pdfGLData[], batchNumber: number, startIndex: number, endIndex: number) => Promise<void>
|
||||
): Promise<number> {
|
||||
if (!Array.isArray(glDataArray)) {
|
||||
@ -1258,7 +1259,7 @@ export async function processGlDataInBatches(
|
||||
form.flatten();
|
||||
const filledPdfBytes = await pdfDoc.save();
|
||||
|
||||
const outputPath = path.join(__dirname, PDF_URL, `${replaceSlashWithDash(carnetData.carnetNo)}p2gl${batchNumber}.pdf`);
|
||||
const outputPath = path.join(__dirname, PDF_URL, `${body.P_HEADERID}p2gl${batchNumber}.pdf`);
|
||||
const writeStream = fs.createWriteStream(outputPath);
|
||||
|
||||
writeStream.write(filledPdfBytes);
|
||||
@ -1295,7 +1296,7 @@ export async function processGlDataInBatches(
|
||||
return batchNumber
|
||||
}
|
||||
|
||||
export async function generateGL(glData: pdfGLData[], carnetData: pdfCarnetData): Promise<any> {
|
||||
export async function generateGL(glData: pdfGLData[], carnetData: pdfCarnetData, body: PrintGLDTO): Promise<any> {
|
||||
const BATCH_SIZE = 38;
|
||||
const totalLength = glData.length;
|
||||
|
||||
@ -1311,11 +1312,11 @@ export async function generateGL(glData: pdfGLData[], carnetData: pdfCarnetData)
|
||||
|
||||
// Call the existing processGlDataInBatches function and await its completion
|
||||
try {
|
||||
const loop = await processGlDataInBatches(glData, BATCH_SIZE, carnetData, innerLogFunction);
|
||||
const loop = await processGlDataInBatches(glData, BATCH_SIZE, carnetData, body, innerLogFunction);
|
||||
console.log("--- generateGL function completed ---");
|
||||
let fileArray: string[] = []
|
||||
for (let i = 1; i < loop; i++) {
|
||||
fileArray.push(`${replaceSlashWithDash(carnetData.carnetNo)}p2gl${i}.pdf`)
|
||||
fileArray.push(`${body.P_HEADERID}p2gl${i}.pdf`)
|
||||
}
|
||||
return { fileArray, batch: loop - 1 };
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user