import { Injectable } from '@nestjs/common'; 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 { BadRequestException } from 'src/exceptions/badRequest.exception'; import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class CarnetApplicationService { constructor(private readonly pgDBService: PgDBService) { } // [ CARNETAPPLICATION_PKG ] // async SaveCarnetApplication(body: SaveCarnetApplicationDTO) { } async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_transmitapplicationtoprocess($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.transmitted, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async CreateApplication(body: CreateApplicationDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_createapplication($1, $2, $3, $4, $5, $6, $7) `; await client.query(callProcQuery, [body.P_SPID, body.P_CLIENTID, body.P_LOCATIONID, body.P_USERID, body.P_APPLICATIONNAME, body.P_ORDERTYPE, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 201, message: ResponseStatus.created, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async UpdateHolder(body: CA_UpdateHolderDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_updateholder($1, $2, $3) `; await client.query(callProcQuery, [body.P_HEADERID, body.P_HOLDERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async UpdateExpGoodsAuthRep(body: UpdateExpGoodsAuthRepDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_updateexpgoodsauthrep($1, $2, $3, $4, $5, $6, $7, $8) `; await client.query(callProcQuery, [body.P_HEADERID, body.P_COMMERCIALSAMPLEFLAG, body.P_PROFEQUIPMENTFLAG, body.P_EXHIBITIONSFAIRFLAG, body.P_AUTOFLAG, body.P_HORSEFLAG, body.P_AUTHREP, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async AddGenerallistItems(body: AddGenerallistItemsDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); function escapePostgresString(str: string): string { if (str == null) return ''; return `"${str.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; } function escapePostgresValue(val: any): string { if (val == null || val === '') return ''; // NULL or empty becomes empty string if (typeof val === 'number') return String(val); // pass numbers as-is return escapePostgresString(String(val)); // quote and escape strings } const contactLiterals = body.P_GLTABLE.map(c => { const fields = [ escapePostgresValue(c.ITEMNO), // integer escapePostgresValue(c.ITEMDESCRIPTION), // varchar escapePostgresValue(c.ITEMVALUE), // numeric escapePostgresValue(c.NOOFPIECES), // integer escapePostgresValue(c.ITEMWEIGHT), // numeric escapePostgresValue(c.ITEMWEIGHTUOM), // varchar escapePostgresValue(c.GOODSORIGINCOUNTRY), // varchar ]; return `(${fields.join(',')})`; // composite literal without outer double quotes }); const pgArrayLiteral = `{${contactLiterals.join(',')}}`; const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_addgenerallistitems($1, $2::"CARNETSYS".gltable[], $3, $4) `; await client.query(callProcQuery, [body.P_HEADERID, pgArrayLiteral, body.P_USERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.added, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async EditGenerallistItems(body: AddGenerallistItemsDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); function escapePostgresString(str: string): string { if (str == null) return ''; return `"${str.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; } function escapePostgresValue(val: any): string { if (val == null || val === '') return ''; // NULL or empty becomes empty string if (typeof val === 'number') return String(val); // pass numbers as-is return escapePostgresString(String(val)); // quote and escape strings } const contactLiterals = body.P_GLTABLE.map(c => { const fields = [ escapePostgresValue(c.ITEMNO), // integer escapePostgresValue(c.ITEMDESCRIPTION), // varchar escapePostgresValue(c.ITEMVALUE), // numeric escapePostgresValue(c.NOOFPIECES), // integer escapePostgresValue(c.ITEMWEIGHT), // numeric escapePostgresValue(c.ITEMWEIGHTUOM), // varchar escapePostgresValue(c.GOODSORIGINCOUNTRY), // varchar ]; return `(${fields.join(',')})`; // composite literal without outer double quotes }); const pgArrayLiteral = `{${contactLiterals.join(',')}}`; const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_editgenerallistitems($1, $2::"CARNETSYS".gltable[], $3, $4) `; await client.query(callProcQuery, [body.P_HEADERID, pgArrayLiteral, body.P_USERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async DeleteGenerallistItems(body: DeleteGenerallistItemsDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_deletegenerallistitems($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_HEADERID, body.P_ITEMNO, body.P_USERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.deleted, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async AddCountries(body: AddCountriesDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); function escapePostgresString(str: string): string { if (str == null) return ''; return `"${str.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; } function escapePostgresValue(val: any): string { if (val == null || val === '') return ''; // NULL or empty becomes empty string if (typeof val === 'number') return String(val); // pass numbers as-is return escapePostgresString(String(val)); // quote and escape strings } const contactLiterals = body.P_COUNTRYTABLE.map(c => { const fields = [ escapePostgresValue(c.P_VISISTTRANSITIND), // integer escapePostgresValue(c.COUNTRYCODE), // varchar escapePostgresValue(c.NOOFTIMESENTLEAVE), // numeric ]; return `(${fields.join(',')})`; // composite literal without outer double quotes }); const pgArrayLiteral = `{${contactLiterals.join(',')}}`; const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_addcountries($1, $2, $3::"CARNETSYS".carnetcountrytable[], $4, $5) `; await client.query(callProcQuery, [body.P_HEADERID, body.P_USSETS, pgArrayLiteral, body.P_USERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.added, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async UpdateShippingDetails(body: UpdateShippingDetailsDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_updateshippingdetails($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29) `; await client.query(callProcQuery, [ body.P_HEADERID, body.P_SHIPTOTYPE, body.P_SHIPCONTACTID, body.P_SHIPNAME, body.P_ADDRESS1, body.P_ADDRESS2, body.P_CITY, body.P_STATE, body.P_ZIP, body.P_COUNTRY, body.P_FIRSTNAME, body.P_LASTNAME, body.P_TITLE, body.P_PHONENO, body.P_MOBILENO, body.P_FAXNO, body.P_EMAILADDRESS, body.P_MIDDLEINITIAL, body.P_FORMOFSECURITY, body.P_INSPROTECTION, body.P_LDIPROTECTION, body.P_DELIVERYTYPE, body.P_DELIVERYMETHOD, body.P_PAYMENTMETHOD, body.P_CUSTCOURIERNO, body.P_REFNO, body.P_NOTES, body.P_USERID, cursorName ]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async EstimatedFees(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetapplication_pkg_estimatedfees($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } // processing [ PROCESSINGCENTER_PKG ] async ProcessCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_processcarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.processed, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_updateprintcarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async VoidCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_voidcarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.voided, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async CopyCarnet(body: CopyCarnetDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_copycarnet($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, body.P_APPLICATIONNAME, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.copied, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async DuplicateCarnet(body: CarnetProcessingCenterDTO2) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_duplicatecarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.duplicated, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async AddlSets(body: CarnetProcessingCenterDTO2) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_addlsets($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.addl_completed, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async ExtendCarnet(body: CarnetProcessingCenterDTO2) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_extendcarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.extended, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async GetExtendedSection(body: GetExtendedSectionDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_getextendedsection($1, $2, $3) `; await client.query(callProcQuery, [body.P_SPID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async SaveExtensionApplication(body: SaveExtensionApplicationDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_saveextensionapplication($1, $2, $3, $4, $5, $6, $7, $8) `; await client.query(callProcQuery, [body.P_USERID, body.P_SPID, body.P_HEADERID, body.P_GOODSPORT, body.P_GOODSCOUNTRY, body.P_REASONCODE, body.P_EXTENSIONPERIOD, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.saved, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async CloseCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_closecarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.closed, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async ResetCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_resetcarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.reset_successfull, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async DeleteCarnet(body: CarnetProcessingCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".processingcenter_pkg_deletecarnet($1, $2, $3) `; await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); checkPgUserDefinedErrors(fetchResult); return { statusCode: 200, message: ResponseStatus.deleted, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } // [ CARNETCONTROLCENTER_PKG ] async GetHolderstoEdit(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetcontrolcenter_pkg_getholderstoedit($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async GetGoodsDetailstoEdit(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetcontrolcenter_pkg_getgoodsdetailstoedit($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async GetCountryDetailstoEdit(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetcontrolcenter_pkg_getcountrydetailstoedit($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async GetShipPaymentDetailstoEdit(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetcontrolcenter_pkg_getshippaymentdetailstoedit($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } async GetGoodsItemstoEdit(body: GetCarnetControlCenterDTO) { let client: PoolClient | null = null; const cursorName = 'p_cursor'; try { client = await this.pgDBService.getConnection(); await client.query('BEGIN'); const callProcQuery = ` CALL "CARNETSYS".carnetcontrolcenter_pkg_getgoodsitemstoedit($1, $2, $3, $4) `; await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); // 🚫 DON'T quote the cursor name in FETCH const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); // 🚫 DON'T quote the cursor name in CLOSE await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); handlePgError(error, CarnetApplicationService.name) } finally { releasePgClient(client) } } // [PRINT_PKG] async getPrintingData(body: PrintCarnetDTO) { } async PrintCarnet(body: PrintCarnetDTO) { } async PrintGL(body: PrintGLDTO) { } // [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) { } async CapturePayment(body: CapturePaymentDTO) { } async OrderDetails(body: GetOrderDetailsDTO) { } async GetPaymentHistory(body: GetPaymentHistoryDTO) { } async SaveHistory(body: SaveHistoryDTO) { } }