Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into icbc2
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan-aot committed Nov 8, 2024
2 parents 06e33f0 + b6a7322 commit a7b73cd
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 42 deletions.
38 changes: 38 additions & 0 deletions database/mssql/scripts/versions/revert/v_47_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

UPDATE [permit].[ORBC_PERMIT_TYPE] SET NAME='Motive Fuel User',[DB_LAST_UPDATE_TIMESTAMP] =getutcdate() WHERE PERMIT_TYPE='MFP';

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting permit name update for MFP'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (46, @VersionDescription, getutcdate())
IF @@ERROR <> 0 SET NOEXEC ON
GO

COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO
42 changes: 42 additions & 0 deletions database/mssql/scripts/versions/v_47_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

UPDATE [permit].[ORBC_PERMIT_TYPE] SET NAME='Motive Fuel User Permit',[DB_LAST_UPDATE_TIMESTAMP] =getutcdate() WHERE PERMIT_TYPE='MFP';

IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Update permit name of permit type MFP'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (47, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate())
IF @@ERROR <> 0 SET NOEXEC ON
GO

COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO

5 changes: 5 additions & 0 deletions database/mssql/test/versions/v_47_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Test that the permit name has been configured correctly
SET NOCOUNT ON

SELECT COUNT(*) FROM $(DB_NAME).[permit].[ORBC_PERMIT_TYPE]
WHERE NAME='Motive Fuel User Permit'
16 changes: 16 additions & 0 deletions database/mssql/test/versions/v_47_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Retrieve arguments
source ${SCRIPT_DIR}/utility/getopt.sh
USAGE="-u USER -p PASS -s SERVER -d DATABASE"
parse_options "${USAGE}" ${@}

# All database tests for database version 47 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_47_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_47_1_test.sql | xargs)
if [[ $TEST_47_1_RESULT -eq 1 ]]; then
echo "Test 47.1 passed: MFP Permit name update successful."
else
echo "******** Test 47.1 failed: MFP Permit name update failed."
fi
28 changes: 17 additions & 11 deletions frontend/src/common/helpers/formatDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ export const now = () => dayjs();
export const nowUtc = () => dayjs.utc();

/**
* Get local datetime string in a specified format for a given DayJS object.
* @param dayjsObj DayJS object that could be in any timezone
* Get local datetime string in a specified format for a given local DayJS object.
* @param localDayjs Local DayJS object
* @param formatStr datetime format to display the datetime in (default ISO-8601)
* @returns datetime string representing local datetime in the format specified
*/
export const dayjsToLocalStr = (dayjsObj: Dayjs, formatStr?: string) =>
dayjs(dayjsObj).local().format(formatStr);
export const dayjsToLocalStr = (localDayjs: Dayjs, formatStr?: string) =>
dayjs(localDayjs).format(formatStr);

/**
* Get UTC datetime string in a specified format for a given DayJS object.
* @param dayjsObj DayJS object that could be in any timezone
* Get UTC datetime string in a specified format for a given local DayJS object.
* @param localDayjs Local DayJS object
* @param formatStr datetime format to display the datetime in (default ISO-8601)
* @returns datetime string representing UTC datetime in the format specified
*/
export const dayjsToUtcStr = (dayjsObj: Dayjs, formatStr?: string) =>
dayjs(dayjsObj).utc().format(formatStr);
export const dayjsToUtcStr = (localDayjs: Dayjs, formatStr?: string) =>
dayjs(localDayjs).utc().format(formatStr);

/**
* Get UTC datetime string in a specified format for a given datetime string
Expand All @@ -65,10 +65,16 @@ export const toUtc = (dateTimeStr: string, formatStr?: string) =>
* Get local datetime string in a specified format for a given datetime string
* @param dateTimeStr datetime string that could be in any timezone
* @param formatStr datetime format to display in (default ISO-8601)
* @param isDateTimeStrLocal Whether or not the provided datetime string is already local
* @returns datetime string representing local datetime in the format specified
*/
export const toLocal = (dateTimeStr: string, formatStr?: string) =>
dayjs(dateTimeStr).local().format(formatStr);
export const toLocal = (
dateTimeStr: string,
formatStr?: string,
isDateTimeStrLocal?: boolean,
) => isDateTimeStrLocal
? dayjs(dateTimeStr).format(formatStr)
: dayjs(dateTimeStr).local().format(formatStr);

/**
* Get local DayJS object for a given UTC datetime string
Expand Down Expand Up @@ -106,7 +112,7 @@ export const toTimeZone = (
) =>
ianaId
? dayjs(datetimeStr).tz(ianaId).format(formatStr)
: toLocal(datetimeStr, formatStr);
: toLocal(datetimeStr, formatStr, true);

/**
* Gets the number of days between two datetimes (should both be in the same timezone).
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/common/helpers/tableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import { PermitListItem } from "../../features/permits/types/permit";
import { Nullable } from "../types/common";

/**
* Format a given datetime string to a format that we can display
* @param rawDateTime
* Format a datetime string in a table cell to a given display format.
* @param rawDateTime Provided datetime string, if any
* @param isDateTimeLocal Whether or not the provided datetime is local
* @returns datetime string for display or "NA" if invalid date given
*/
export const formatCellValuetoDatetime = (rawDateTime: Nullable<string>) => {
export const formatCellValuetoDatetime = (
rawDateTime: Nullable<string>,
isDateTimeLocal?: boolean,
) => {
return applyWhenNotNullable(
(dt) => toLocal(dt, DATE_FORMATS.DATEONLY_ABBR_MONTH),
(dt) => toLocal(dt, DATE_FORMATS.DATEONLY_ABBR_MONTH, isDateTimeLocal),
rawDateTime,
"NA",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const PermitSearchResultColumnDef = (
enableSorting: true,
sortingFn: dateTimeStringSortingFn,
Cell: (props: { cell: any }) => {
const formattedDate = formatCellValuetoDatetime(props.cell.getValue());
const formattedDate = formatCellValuetoDatetime(props.cell.getValue(), true);
return formattedDate;
},
},
Expand All @@ -115,7 +115,7 @@ export const PermitSearchResultColumnDef = (
enableSorting: true,
sortingFn: dateTimeStringSortingFn,
Cell: (props: { cell: any }) => {
const formattedDate = formatCellValuetoDatetime(props.cell.getValue());
const formattedDate = formatCellValuetoDatetime(props.cell.getValue(), true);
return formattedDate;
},
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/features/permits/apiManager/permitsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const getApplications = async (
startDate: toLocal(
application?.startDate,
DATE_FORMATS.DATEONLY_SHORT_NAME,
true,
),
} as ApplicationListItem;
});
Expand Down Expand Up @@ -494,10 +495,12 @@ export const getPermits = async (
startDate: toLocal(
permit.startDate,
DATE_FORMATS.DATEONLY_SHORT_NAME,
true,
),
expiryDate: toLocal(
permit.expiryDate,
DATE_FORMATS.DATEONLY_SHORT_NAME,
true,
),
} as PermitListItem;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const PermitsColumnDefinition = (
header: "Permit Start Date",
enableSorting: true,
Cell: (props: { cell: any }) => {
const formattedDate = formatCellValuetoDatetime(props.cell.getValue());
const formattedDate = formatCellValuetoDatetime(props.cell.getValue(), true);
return formattedDate;
},
},
Expand All @@ -81,7 +81,7 @@ export const PermitsColumnDefinition = (
id: "expiryDate",
enableSorting: true,
Cell: (props: { cell: any }) => {
const formattedDate = formatCellValuetoDatetime(props.cell.getValue());
const formattedDate = formatCellValuetoDatetime(props.cell.getValue(), true);
return formattedDate;
},
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/permits/helpers/equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { PermitVehicleDetails } from "../types/PermitVehicleDetails";
import { PermitData } from "../types/PermitData";
import { PermitCondition } from "../types/PermitCondition";
import { arePermitLOADetailsEqual, PermitLOA } from "../types/PermitLOA";
import { doUniqueArraysHaveSameObjects } from "../../../common/helpers/equality";
import {
DATE_FORMATS,
dayjsToLocalStr,
} from "../../../common/helpers/formatDate";
import { doUniqueArraysHaveSameObjects } from "../../../common/helpers/equality";

/**
* Compare whether or not two mailing addresses are equal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useFetchSpecialAuthorizations } from "../../../../settings/hooks/specia
import { filterLOAsForPermitType, filterNonExpiredLOAs } from "../../../helpers/permitLOA";
import {
dayjsToUtcStr,
nowUtc,
now,
} from "../../../../../common/helpers/formatDate";

import {
Expand Down Expand Up @@ -213,7 +213,7 @@ export const AmendPermitForm = () => {
comment: getDefaultRequiredVal("", history.comment),
name: history.commentUsername,
revisionDateTime: getDefaultRequiredVal(
dayjsToUtcStr(nowUtc()),
dayjsToUtcStr(now()),
history.transactionSubmitDate,
),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const LOATable = ({
scope="row"
>
{applyWhenNotNullable(
expiryDate => toLocal(expiryDate, DATE_FORMATS.DATEONLY_SLASH),
expiryDate => toLocal(expiryDate, DATE_FORMATS.DATEONLY_SLASH, true),
selectableLOA.loa.expiryDate,
"Never expires",
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const ShoppingCartItem = ({
<span
className="shopping-cart-item__info shopping-cart-item__info--start-date"
>
{toLocal(cartItemData.startDate, DATE_FORMATS.DATEONLY_ABBR_MONTH)}
{toLocal(cartItemData.startDate, DATE_FORMATS.DATEONLY_ABBR_MONTH, true)}
</span>
</div>
</div>
Expand Down Expand Up @@ -113,7 +113,7 @@ export const ShoppingCartItem = ({
<span
className="shopping-cart-item__info shopping-cart-item__info--end-date"
>
{toLocal(cartItemData.expiryDate, DATE_FORMATS.DATEONLY_ABBR_MONTH)}
{toLocal(cartItemData.expiryDate, DATE_FORMATS.DATEONLY_ABBR_MONTH, true)}
</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const VoidPermitHeader = ({ permit }: { permit: Nullable<Permit> }) => {
{toLocal(
permit.permitData.startDate,
DATE_FORMATS.DATEONLY_ABBR_MONTH,
true,
)}
</Box>
</Box>
Expand All @@ -62,6 +63,7 @@ export const VoidPermitHeader = ({ permit }: { permit: Nullable<Permit> }) => {
{toLocal(
permit.permitData.expiryDate,
DATE_FORMATS.DATEONLY_ABBR_MONTH,
true,
)}
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const LOAListColumnDef = (
},
{
accessorFn: (originalRow) => {
return toLocal(originalRow.startDate, DATE_FORMATS.DATEONLY_SLASH);
return toLocal(originalRow.startDate, DATE_FORMATS.DATEONLY_SLASH, true);
},
id: "startDate",
header: "Start Date",
Expand All @@ -54,7 +54,7 @@ export const LOAListColumnDef = (
{
accessorFn: (originalRow) =>
applyWhenNotNullable(
(expiryDate) => toLocal(expiryDate, DATE_FORMATS.DATEONLY_SLASH),
(expiryDate) => toLocal(expiryDate, DATE_FORMATS.DATEONLY_SLASH, true),
originalRow.expiryDate,
"Never expires",
) as string,
Expand Down
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)
);
}
};
Loading

0 comments on commit a7b73cd

Please sign in to comment.