Skip to content

Commit

Permalink
psp-8871 | Fixed Period totals not being calculated (#4203)
Browse files Browse the repository at this point in the history
* Split lease payment columns into two files. Moved logic about variable payment to a class. Fixed issue with totals not beign calculated.

* Regenerated snaps

* Renamed for better readability

* Fixed initialization of new class

---------

Co-authored-by: Alejandro Sanchez <emailforasr@gmail.com>
  • Loading branch information
FuriousLlama and asanchezr authored Jul 17, 2024
1 parent 65b6796 commit 1caa33d
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,39 @@ export class FormLeasePayment {
}
}

export class FormLeasePeriodWithCategory extends FormLeasePeriod {
category: ApiGen_CodeTypes_LeasePaymentCategoryTypes;
export class LeasePeriodByCategoryProjection {
readonly leasePmtFreqTypeCode: ApiGen_Base_CodeType<string> | null;
readonly paymentAmount: NumberFieldValue;
readonly isGstEligible: boolean | undefined;
readonly gstAmount: NumberFieldValue;
readonly payments: FormLeasePayment[];
readonly isTermExercised: boolean | undefined;
readonly category: ApiGen_CodeTypes_LeasePaymentCategoryTypes;

constructor(
leasePeriod: FormLeasePeriod | undefined,
category: ApiGen_CodeTypes_LeasePaymentCategoryTypes,
) {
this.leasePmtFreqTypeCode = leasePeriod?.leasePmtFreqTypeCode ?? null;
this.paymentAmount = leasePeriod?.paymentAmount ?? 0;
this.isGstEligible = leasePeriod?.isGstEligible;
this.gstAmount = leasePeriod?.gstAmount ?? 0;
this.payments = leasePeriod?.payments ?? [];
this.isTermExercised = leasePeriod?.isTermExercised;
this.category = category ?? ApiGen_CodeTypes_LeasePaymentCategoryTypes.BASE;

if (category === ApiGen_CodeTypes_LeasePaymentCategoryTypes.ADDL) {
this.isGstEligible = leasePeriod?.isAdditionalRentGstEligible;
this.paymentAmount = leasePeriod?.additionalRentPaymentAmount ?? 0;
this.leasePmtFreqTypeCode = leasePeriod?.additionalRentFreqTypeCode ?? null;
this.gstAmount = leasePeriod?.additionalRentGstAmount ?? 0;
} else if (category === ApiGen_CodeTypes_LeasePaymentCategoryTypes.VBL) {
this.isGstEligible = leasePeriod?.isVariableRentGstEligible;
this.paymentAmount = leasePeriod?.variableRentPaymentAmount ?? 0;
this.leasePmtFreqTypeCode = leasePeriod?.variableRentFreqTypeCode ?? null;
this.gstAmount = leasePeriod?.variableRentGstAmount ?? 0;
}
}
}

export const defaultFormLeasePayment: FormLeasePayment = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
defaultFormLeasePayment,
FormLeasePayment,
FormLeasePeriod,
FormLeasePeriodWithCategory,
LeasePeriodByCategoryProjection,
} from '../../models';
import * as PaymentStyles from '../../styles';
import { getLeaseVariablePeriodColumns } from '../periods/columns';
import { getLeaseVariablePeriodColumns } from '../periods/variablePeriodColumns';
import { getActualsColumns } from './paymentsColumns';

export interface IPaymentsViewProps {
Expand All @@ -26,7 +26,7 @@ export interface IPaymentsViewProps {
isGstEligible?: boolean;
isReceivable?: boolean;
periodId?: number;
period: FormLeasePeriod;
period: FormLeasePeriod | undefined;
}

export const PaymentsView: React.FunctionComponent<React.PropsWithChildren<IPaymentsViewProps>> = ({
Expand All @@ -39,24 +39,10 @@ export const PaymentsView: React.FunctionComponent<React.PropsWithChildren<IPaym
period,
}) => {
const variablePaymentColumns = getLeaseVariablePeriodColumns();
const variablePaymentData: FormLeasePeriodWithCategory[] = [
{ category: ApiGen_CodeTypes_LeasePaymentCategoryTypes.BASE, ...period },
{
category: ApiGen_CodeTypes_LeasePaymentCategoryTypes.ADDL,
...period,
isGstEligible: period?.isAdditionalRentGstEligible,
paymentAmount: period?.additionalRentPaymentAmount ?? 0,
leasePmtFreqTypeCode: period?.additionalRentFreqTypeCode,
gstAmount: period?.additionalRentGstAmount,
},
{
category: ApiGen_CodeTypes_LeasePaymentCategoryTypes.VBL,
...period,
isGstEligible: period?.isVariableRentGstEligible,
paymentAmount: period?.variableRentPaymentAmount ?? 0,
leasePmtFreqTypeCode: period?.variableRentFreqTypeCode,
gstAmount: period?.variableRentGstAmount,
},
const variablePaymentData: LeasePeriodByCategoryProjection[] = [
new LeasePeriodByCategoryProjection(period, ApiGen_CodeTypes_LeasePaymentCategoryTypes.BASE),
new LeasePeriodByCategoryProjection(period, ApiGen_CodeTypes_LeasePaymentCategoryTypes.ADDL),
new LeasePeriodByCategoryProjection(period, ApiGen_CodeTypes_LeasePaymentCategoryTypes.VBL),
];
const columns = useMemo(
() =>
Expand All @@ -75,7 +61,7 @@ export const PaymentsView: React.FunctionComponent<React.PropsWithChildren<IPaym
<>
{period?.isVariable === 'true' && (
<Section className="ml-10 p-0">
<PaymentStyles.StyledPaymentTable<React.FC<TableProps<FormLeasePeriodWithCategory>>>
<PaymentStyles.StyledPaymentTable<React.FC<TableProps<LeasePeriodByCategoryProjection>>>
name="variablePeriodTable"
columns={variablePaymentColumns}
data={variablePaymentData ?? []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { createRef } from 'react';
import { ApiGen_CodeTypes_LeaseLicenceTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseLicenceTypes';
import PeriodPaymentsView, { IPeriodPaymentsViewProps } from './PaymentPeriodsView';
import { defaultFormLeasePeriod, FormLeasePayment } from '../../models';
import { LEASE_PAYMENT_CATEGORY_TYPES } from '@/constants/API';
import { ApiGen_CodeTypes_LeasePaymentCategoryTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeasePaymentCategoryTypes';

const history = createMemoryHistory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { prettyFormatDate } from '@/utils';

import { defaultFormLeasePeriod, FormLeasePayment, FormLeasePeriod } from '../../models';
import PaymentsView from '../payments/PaymentsView';
import { getLeasePeriodColumns } from './columns';
import { getLeasePeriodColumns } from './periodColumns';

export interface IPeriodPaymentsViewProps {
onEdit: (values: FormLeasePeriod) => void;
Expand Down
Loading

0 comments on commit 1caa33d

Please sign in to comment.