Skip to content

Commit

Permalink
fix:ORV2-2977 - Incorrect PermitFee amount in Permit Document and for…
Browse files Browse the repository at this point in the history
…matting (#1661)
  • Loading branch information
praju-aot authored Nov 8, 2024
1 parent c57aedc commit 2a81a25
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
3 changes: 1 addition & 2 deletions vehicles/src/common/constants/api.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export const CRYPTO_ALGORITHM_MD5 = 'md5';
export const CRYPTO_ALGORITHM_SHA256 = 'sha256';
export const TOKEN_EXPIRY_BUFFER = 15;
export const PERMISSIONS_KEY = 'permissions';
export const TIMEZONE_PACIFIC = "America/Vancouver";
export const TIMEZONE_PACIFIC = 'America/Vancouver';
export const GL_PROJ_CODE_PLACEHOLDER = 'PROJECT';

10 changes: 7 additions & 3 deletions vehicles/src/common/helper/format-template-data.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PermitTemplateData,
} from '../interface/permit.template.interface';
import { FullNamesForDgen } from '../interface/full-names-for-dgen.interface';
import { formatAmount } from './payment.helper';

/**
* Formats the permit data so that it can be used in the templated word documents
Expand Down Expand Up @@ -87,9 +88,12 @@ export const formatTemplateData = (
template.companyAlternateName = companyInfo.alternateName;

// Format Fee Summary
template.permitData.feeSummary = permit.permitTransactions
?.at(0)
?.transactionAmount.toString();
const transcation = permit.permitTransactions?.at(0)?.transaction;

template.permitData.feeSummary = formatAmount(
transcation.transactionTypeId,
permit.permitTransactions?.at(0)?.transactionAmount,
).toString();

revisionHistory?.forEach((revision) => {
if (
Expand Down
9 changes: 6 additions & 3 deletions vehicles/src/common/helper/permit-application.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,12 @@ export const isPermitTypeEligibleForQueue = (
return PERMIT_TYPES_FOR_QUEUE.includes(permitType);
};

export const validApplicationDates = (application: Permit, timezone: string): boolean => {
export const validApplicationDates = (
application: Permit,
timezone: string,
): boolean => {
const todayUTC = dayjs(new Date());
const todayPacific = todayUTC.tz(timezone).format("YYYY-MM-DD");
const todayPacific = todayUTC.tz(timezone).format('YYYY-MM-DD');
const { startDate, expiryDate } = application.permitData;
return startDate >= todayPacific && startDate <= expiryDate;
}
};
4 changes: 2 additions & 2 deletions vehicles/src/common/helper/permit-fee.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const validAmount = (
calculatedAmount: number,
receivedAmount: number,
transactionType: TransactionType,
): boolean =>{
): boolean => {
const isAmountValid =
receivedAmount.toFixed(2) === Math.abs(calculatedAmount).toFixed(2);

Expand All @@ -218,4 +218,4 @@ export const validAmount = (
isAmountValid &&
(isRefundValid || transactionType !== TransactionType.REFUND)
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,8 @@ export class ApplicationService {
company: { companyId: permit.company.companyId },
},
});
if(loaDetails.length != loaIdsToInsert.length)
throw new BadRequestException('One or more loa(s) does not exist')
if (loaDetails.length != loaIdsToInsert.length)
throw new BadRequestException('One or more loa(s) does not exist');
// Transform the permit LOA IDs from an array of numbers into individual records.
const singlePermitLoa = loaIdsToInsert.map((loaId) => ({
permitId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ import {
} from 'src/common/helper/permit-fee.helper';
import { CfsTransactionDetail } from './entities/cfs-transaction.entity';
import { CfsFileStatus } from 'src/common/enum/cfs-file-status.enum';
import { isAmendmentApplication, validApplicationDates } from '../../../common/helper/permit-application.helper';
import {
isAmendmentApplication,
validApplicationDates,
} from '../../../common/helper/permit-application.helper';
import { isCfsPaymentMethodType } from 'src/common/helper/payment.helper';
import { PgApprovesStatus } from 'src/common/enum/pg-approved-status-type.enum';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
Expand Down Expand Up @@ -513,8 +516,10 @@ export class PaymentService {
// Calculate and add amount for each requested application, as per the available backend data.
for (const application of applications) {
//Check if each application has a valid start date and valid expiry date.
if (isCVClientUser && !validApplicationDates(application, TIMEZONE_PACIFIC))
{
if (
isCVClientUser &&
!validApplicationDates(application, TIMEZONE_PACIFIC)
) {
throw new UnprocessableEntityException(
`Atleast one of the application has invalid startDate or expiryDate.`,
);
Expand Down

0 comments on commit 2a81a25

Please sign in to comment.