Skip to content

Commit

Permalink
[Release] Version 0.3.1 (#354)
Browse files Browse the repository at this point in the history
* Fix second payment method reports (#352)

* [Feature] Update permit holders report (#353)

* Combine address lines 1 and 2 into one line

* Add applicant age to permit holders report

* Add recent app expiry date to permit holders report
  • Loading branch information
leogjhuang authored Feb 25, 2024
1 parent 35571cf commit b94f013
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 45 deletions.
5 changes: 5 additions & 0 deletions lib/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export type ApplicationsReportColumn =
| 'PAYMENT_METHOD'
| 'FEE_AMOUNT'
| 'DONATION_AMOUNT'
| 'SECOND_PAYMENT_METHOD'
| 'SECOND_FEE_AMOUNT'
| 'SECOND_DONATION_AMOUNT'
| 'TOTAL_AMOUNT';

export type ApplicationsResult = {
Expand Down Expand Up @@ -944,6 +947,7 @@ export type PermitHoldersReportColumn =
| 'USER_ID'
| 'APPLICANT_NAME'
| 'APPLICANT_DATE_OF_BIRTH'
| 'APPLICANT_AGE'
| 'HOME_ADDRESS'
| 'EMAIL'
| 'PHONE_NUMBER'
Expand All @@ -952,6 +956,7 @@ export type PermitHoldersReportColumn =
| 'GUARDIAN_POA_ADDRESS'
| 'RECENT_APP_NUMBER'
| 'RECENT_APP_TYPE'
| 'RECENT_APP_EXPIRY_DATE'
| 'USER_STATUS';

export type PermitStatus =
Expand Down
52 changes: 28 additions & 24 deletions lib/reports/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PaymentType,
} from '@lib/graphql/types';
import { SortOrder } from '@tools/types';
import { formatFullName, formatPhoneNumber, formatPostalCode } from '@lib/utils/format'; // Formatting utils
import { formatAddress, formatFullName, formatPhoneNumber } from '@lib/utils/format'; // Formatting utils
import {
formatDateTimeYYYYMMDDHHMMSS,
formatDateYYYYMMDD,
Expand Down Expand Up @@ -91,6 +91,7 @@ export const generatePermitHoldersReport: Resolver<
select: {
rcdPermitId: true,
type: true,
expiryDate: true,
},
},
},
Expand All @@ -103,8 +104,12 @@ export const generatePermitHoldersReport: Resolver<
firstName,
middleName,
lastName,
postalCode,
dateOfBirth,
addressLine1,
addressLine2,
city,
province,
postalCode,
guardian,
permits,
phone,
Expand All @@ -113,36 +118,33 @@ export const generatePermitHoldersReport: Resolver<
return {
...applicant,
id,
phone: formatPhoneNumber(phone),
dateOfBirth: formatDateYYYYMMDD(dateOfBirth),
applicantName: formatFullName(firstName, middleName, lastName),
postalCode: formatPostalCode(postalCode),
dateOfBirth: formatDateYYYYMMDD(dateOfBirth),
age: moment().diff(dateOfBirth, 'years'),
homeAddress: formatAddress(addressLine1, addressLine2, city, postalCode, province),
phone: formatPhoneNumber(phone),
rcdPermitId: `#${permits[0].rcdPermitId}`,
permitType: permits[0].type,
permitExpiryDate: formatDateYYYYMMDD(permits[0].expiryDate),
guardianRelationship: guardian?.relationship,
guardianPOAName:
guardian && formatFullName(guardian.firstName, guardian.middleName, guardian.lastName),
guardianAddressLine1: guardian && guardian.addressLine1,
guardianAddressLine2: guardian && guardian.addressLine2,
guardianCity: guardian && guardian.city,
guardianPostalCode:
guardian && guardian.postalCode && formatPostalCode(guardian.postalCode),
guardianProvince: guardian && guardian.province,
guardianAddress:
guardian &&
formatAddress(
guardian.addressLine1,
guardian.addressLine2,
guardian.city,
guardian.postalCode,
guardian.province
),
};
}
);

const filteredColumns = PERMIT_HOLDERS_COLUMNS.filter(({ value }) => columnsSet.has(value));
const csvHeaders: Array<{ id: string; title: string }> = [];
for (const { name, reportColumnId } of filteredColumns) {
if (typeof reportColumnId === 'string') {
csvHeaders.push({ id: reportColumnId, title: name });
} else {
for (const [columnLabel, columnId] of reportColumnId) {
csvHeaders.push({ id: columnId, title: columnLabel });
}
}
}
const csvHeaders = PERMIT_HOLDERS_COLUMNS.filter(({ value }) => columnsSet.has(value)).map(
({ name, reportColumnId }) => ({ id: reportColumnId, title: name })
);

// Generate CSV string from csv object.
const csvStringifier = createObjectCsvStringifier({
Expand Down Expand Up @@ -275,8 +277,10 @@ export const generateApplicationsReport: Resolver<
dateOfBirth: dateOfBirth && formatDateYYYYMMDD(dateOfBirth),
applicationDate: createdAt ? formatDateYYYYMMDDLocal(createdAt, true) : null,
applicantName: formatFullName(firstName, middleName, lastName),
processingFee: `$${Prisma.Decimal.add(processingFee, secondProcessingFee || 0)}`,
donationAmount: `$${Prisma.Decimal.add(donationAmount, secondDonationAmount || 0)}`,
processingFee: `$${processingFee}`,
donationAmount: `$${donationAmount}`,
secondProcessingFee: `$${secondProcessingFee || 0}`,
secondDonationAmount: `$${secondDonationAmount || 0}`,
totalAmount: `$${Prisma.Decimal.add(
Prisma.Decimal.add(processingFee, donationAmount),
Prisma.Decimal.add(secondProcessingFee || 0, secondDonationAmount || 0)
Expand Down
5 changes: 5 additions & 0 deletions lib/reports/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default gql`
PAYMENT_METHOD
FEE_AMOUNT
DONATION_AMOUNT
SECOND_PAYMENT_METHOD
SECOND_FEE_AMOUNT
SECOND_DONATION_AMOUNT
TOTAL_AMOUNT
}
Expand All @@ -50,6 +53,7 @@ export default gql`
USER_ID
APPLICANT_NAME
APPLICANT_DATE_OF_BIRTH
APPLICANT_AGE
HOME_ADDRESS
EMAIL
PHONE_NUMBER
Expand All @@ -58,6 +62,7 @@ export default gql`
GUARDIAN_POA_ADDRESS
RECENT_APP_NUMBER
RECENT_APP_TYPE
RECENT_APP_EXPIRY_DATE
USER_STATUS
}
Expand Down
12 changes: 6 additions & 6 deletions lib/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const formatStreetAddress = (addressLine1: string, addressLine2: string |
* @param postalCode Postal code
* @param province Province (optional)
* @param country Country (optional)
* @returns Formatted Canadian address
* @returns Formatted Canadian address in one line
*/
export const formatAddress = (
addressLine1: string,
Expand All @@ -85,9 +85,9 @@ export const formatAddress = (
province?: Province,
country?: string
): string => {
return `${addressLine2 ? `${addressLine2} - ${addressLine1}` : addressLine1}
${province ? `${city} ${province}` : city}
${country || ''}
${postalCode}
`;
const streetAddress = formatStreetAddress(addressLine1, addressLine2);
const postalCodeFormatted = formatPostalCode(postalCode);
const provinceFormatted = province ? `, ${province}` : '';
const countryFormatted = country ? `, ${country}` : '';
return `${streetAddress}, ${city}${provinceFormatted} ${postalCodeFormatted}${countryFormatted}`;
};
43 changes: 28 additions & 15 deletions tools/admin/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ export const APPLICATIONS_COLUMNS: Array<{
value: 'DONATION_AMOUNT',
reportColumnId: 'donationAmount',
},
{
name: 'Second Payment Method',
value: 'SECOND_PAYMENT_METHOD',
reportColumnId: 'secondPaymentMethod',
},
{
name: 'Second Fee Amount',
value: 'SECOND_FEE_AMOUNT',
reportColumnId: 'secondProcessingFee',
},
{
name: 'Second Donation Amount',
value: 'SECOND_DONATION_AMOUNT',
reportColumnId: 'secondDonationAmount',
},
{
name: 'Total Amount',
value: 'TOTAL_AMOUNT',
Expand All @@ -65,7 +80,7 @@ export const APPLICATIONS_COLUMNS: Array<{
export const PERMIT_HOLDERS_COLUMNS: Array<{
name: string;
value: PermitHoldersReportColumn;
reportColumnId: string | Array<[string, string]>;
reportColumnId: string;
}> = [
{
name: 'User ID',
Expand All @@ -82,16 +97,15 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{
value: 'APPLICANT_DATE_OF_BIRTH',
reportColumnId: 'dateOfBirth',
},
{
name: 'Applicant Age',
value: 'APPLICANT_AGE',
reportColumnId: 'age',
},
{
name: 'Home Address',
value: 'HOME_ADDRESS',
reportColumnId: [
['Address Line 1', 'addressLine1'],
['Address Line 2', 'addressLine2'],
['City', 'city'],
['Province', 'province'],
['Postal Code', 'postalCode'],
],
reportColumnId: 'homeAddress',
},
{
name: 'Email',
Expand All @@ -116,13 +130,7 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{
{
name: 'Guardian/POA Address',
value: 'GUARDIAN_POA_ADDRESS',
reportColumnId: [
['Guardian/POA Address Line 1', 'guardianAddressLine1'],
['Guardian/POA Address Line 2', 'guardianAddressLine2'],
['Guardian/POA City', 'guardianCity'],
['Guardian/POA Province', 'guardianProvince'],
['Guardian/POA Postal Code', 'guardianPostalCode'],
],
reportColumnId: 'guardianAddress',
},
{
name: 'Recent APP Number',
Expand All @@ -134,6 +142,11 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{
value: 'RECENT_APP_TYPE',
reportColumnId: 'permitType',
},
{
name: 'Recent APP Expiry Date',
value: 'RECENT_APP_EXPIRY_DATE',
reportColumnId: 'permitExpiryDate',
},
{
name: 'User Status',
value: 'USER_STATUS',
Expand Down

0 comments on commit b94f013

Please sign in to comment.