Skip to content

Commit

Permalink
Merge pull request Expensify#39239 from paultsimura/feat/38971-tracki…
Browse files Browse the repository at this point in the history
…ng-expense

feat: Expense Tracking in the Workspace Chat
  • Loading branch information
thienlnam authored Apr 8, 2024
2 parents 7e8c94a + cc3c52d commit 6ec5811
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 84 deletions.
13 changes: 11 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry<ReportActions>
}

// Get all IOU report actions for the report.
const iouRequestTypes: Array<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>> = [CONST.IOU.REPORT_ACTION_TYPE.CREATE, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, CONST.IOU.REPORT_ACTION_TYPE.PAY];
const iouRequestTypes: Array<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>> = [
CONST.IOU.REPORT_ACTION_TYPE.CREATE,
CONST.IOU.REPORT_ACTION_TYPE.SPLIT,
CONST.IOU.REPORT_ACTION_TYPE.PAY,
CONST.IOU.REPORT_ACTION_TYPE.TRACK,
];
const iouRequestActions = reportActionsArray.filter(
(action) =>
action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
Expand Down Expand Up @@ -346,7 +351,11 @@ function getMostRecentIOURequestActionID(reportActions: ReportAction[] | null):
if (!Array.isArray(reportActions)) {
return null;
}
const iouRequestTypes: Array<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>> = [CONST.IOU.REPORT_ACTION_TYPE.CREATE, CONST.IOU.REPORT_ACTION_TYPE.SPLIT];
const iouRequestTypes: Array<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>> = [
CONST.IOU.REPORT_ACTION_TYPE.CREATE,
CONST.IOU.REPORT_ACTION_TYPE.SPLIT,
CONST.IOU.REPORT_ACTION_TYPE.TRACK,
];
const iouRequestActions = reportActions?.filter((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && iouRequestTypes.includes(action.originalMessage.type)) ?? [];

if (iouRequestActions.length === 0) {
Expand Down
23 changes: 14 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type OptimisticExpenseReport = Pick<
| 'stateNum'
| 'statusNum'
| 'total'
| 'nonReimbursableTotal'
| 'notificationPreference'
| 'parentReportID'
| 'lastVisibleActionCreated'
Expand Down Expand Up @@ -3273,8 +3274,9 @@ function populateOptimisticReportFormula(formula: string, report: OptimisticExpe
* @param payeeAccountID - AccountID of the employee (payee)
* @param total - Amount in cents
* @param currency
* @param reimbursable – Whether the expense is reimbursable
*/
function buildOptimisticExpenseReport(chatReportID: string, policyID: string, payeeAccountID: number, total: number, currency: string): OptimisticExpenseReport {
function buildOptimisticExpenseReport(chatReportID: string, policyID: string, payeeAccountID: number, total: number, currency: string, reimbursable = true): OptimisticExpenseReport {
// The amount for Expense reports are stored as negative value in the database
const storedTotal = total * -1;
const policyName = getPolicyName(allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]);
Expand All @@ -3298,6 +3300,7 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa
stateNum,
statusNum,
total: storedTotal,
nonReimbursableTotal: reimbursable ? 0 : storedTotal,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReportID: chatReportID,
lastVisibleActionCreated: DateUtils.getDBTime(),
Expand Down Expand Up @@ -4242,6 +4245,7 @@ function buildOptimisticMoneyRequestEntities(
isSendMoneyFlow = false,
receipt: Receipt = {},
isOwnPolicyExpenseChat = false,
isPersonalTrackingExpense = false,
): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction] {
const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail);

Expand All @@ -4256,7 +4260,7 @@ function buildOptimisticMoneyRequestEntities(
participants,
transactionID,
paymentType,
iouReport.reportID,
isPersonalTrackingExpense ? '0' : iouReport.reportID,
isSettlingUp,
isSendMoneyFlow,
receipt,
Expand Down Expand Up @@ -4809,12 +4813,13 @@ function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, o
* - DMs
* - Split options should show for:
* - DMs
* - chat/ policy rooms with more than 1 participants
* - chat/policy rooms with more than 1 participant
* - groups chats with 3 and more participants
* - corporate workspace chats
* - Track expense option should show for:
* - Self DMs
* - admin rooms
* - own policy expense chats
* - open and processing expense reports tied to own policy expense chat
*
* None of the options should show in chat threads or if there is some special Expensify account
* as a participant of the report.
Expand Down Expand Up @@ -4853,13 +4858,13 @@ function getMoneyRequestOptions(report: OnyxEntry<Report>, policy: OnyxEntry<Pol
options = [CONST.IOU.TYPE.SPLIT];
}

// TODO: Re-enable this when we have a clarity on track expense in policy expense chat
// if (canUseTrackExpense && isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat) {
// options = [...options, CONST.IOU.TYPE.TRACK_EXPENSE];
// }

if (canRequestMoney(report, policy, otherParticipants)) {
options = [...options, CONST.IOU.TYPE.REQUEST];

// If the user can request money from the workspace report, they can also track expenses
if (canUseTrackExpense && (isPolicyExpenseChat(report) || isExpenseReport(report))) {
options = [...options, CONST.IOU.TYPE.TRACK_EXPENSE];
}
}

// Send money option should be visible only in 1:1 DMs
Expand Down
2 changes: 2 additions & 0 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function buildOptimisticTransaction(
tag = '',
billable = false,
pendingFields: Partial<{[K in TransactionPendingFieldsKey]: ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION>}> | undefined = undefined,
reimbursable = true,
): Transaction {
// transactionIDs are random, positive, 64-bit numeric strings.
// Because JS can only handle 53-bit numbers, transactionIDs are strings in the front-end (just like reportActionID)
Expand Down Expand Up @@ -124,6 +125,7 @@ function buildOptimisticTransaction(
category,
tag,
billable,
reimbursable,
};
}

Expand Down
Loading

0 comments on commit 6ec5811

Please sign in to comment.