@@ -126,7 +126,7 @@ import {
126
126
isOptimisticPersonalDetail ,
127
127
isPayAtEndExpenseReport as isPayAtEndExpenseReportReportUtils ,
128
128
isPayer as isPayerReportUtils ,
129
- isPolicyExpenseChat as isPolicyExpenseChatReportUtils ,
129
+ isPolicyExpenseChat as isPolicyExpenseChatReportUtil ,
130
130
isReportApproved ,
131
131
isSelfDM ,
132
132
isSettled ,
@@ -325,6 +325,8 @@ type RequestMoneyTransactionParams = {
325
325
actionableWhisperReportActionID ?: string ;
326
326
linkedTrackedExpenseReportAction ?: OnyxTypes . ReportAction ;
327
327
linkedTrackedExpenseReportID ?: string ;
328
+ waypoints ?: WaypointCollection ;
329
+ customUnitRateID ?: string ;
328
330
} ;
329
331
330
332
type PerDiemExpenseTransactionParams = {
@@ -4131,6 +4133,38 @@ const getConvertTrackedExpenseInformation = (
4131
4133
return { optimisticData, successData, failureData, modifiedExpenseReportActionID : modifiedExpenseReportAction . reportActionID } ;
4132
4134
} ;
4133
4135
4136
+ type ConvertTrackedWorkspaceParams = {
4137
+ category : string | undefined ;
4138
+ tag : string | undefined ;
4139
+ taxCode : string ;
4140
+ taxAmount : number ;
4141
+ billable : boolean | undefined ;
4142
+ policyID : string ;
4143
+ receipt : Receipt | undefined ;
4144
+ waypoints ?: string ;
4145
+ customUnitRateID ?: string ;
4146
+ } ;
4147
+
4148
+ type AddTrackedExpenseToPolicyParam = {
4149
+ amount : number ;
4150
+ currency : string ;
4151
+ comment : string ;
4152
+ created : string ;
4153
+ merchant : string ;
4154
+ transactionID : string ;
4155
+ reimbursable : boolean ;
4156
+ actionableWhisperReportActionID : string ;
4157
+ moneyRequestReportID : string ;
4158
+ reportPreviewReportActionID : string ;
4159
+ modifiedExpenseReportActionID : string ;
4160
+ moneyRequestCreatedReportActionID : string | undefined ;
4161
+ moneyRequestPreviewReportActionID : string ;
4162
+ } & ConvertTrackedWorkspaceParams ;
4163
+
4164
+ function addTrackedExpenseToPolicy ( parameters : AddTrackedExpenseToPolicyParam , onyxData : OnyxData ) {
4165
+ API . write ( WRITE_COMMANDS . ADD_TRACKED_EXPENSE_TO_POLICY , parameters , onyxData ) ;
4166
+ }
4167
+
4134
4168
function convertTrackedExpenseToRequest (
4135
4169
payerAccountID : number ,
4136
4170
payerEmail : string ,
@@ -4152,6 +4186,7 @@ function convertTrackedExpenseToRequest(
4152
4186
merchant : string ,
4153
4187
created : string ,
4154
4188
attendees ?: Attendee [ ] ,
4189
+ workspaceParams ?: ConvertTrackedWorkspaceParams ,
4155
4190
) {
4156
4191
const { optimisticData, successData, failureData} = onyxData ;
4157
4192
@@ -4174,6 +4209,28 @@ function convertTrackedExpenseToRequest(
4174
4209
successData ?. push ( ...moveTransactionSuccessData ) ;
4175
4210
failureData ?. push ( ...moveTransactionFailureData ) ;
4176
4211
4212
+ if ( workspaceParams ) {
4213
+ const params = {
4214
+ amount,
4215
+ currency,
4216
+ comment,
4217
+ created,
4218
+ merchant,
4219
+ reimbursable : true ,
4220
+ transactionID,
4221
+ actionableWhisperReportActionID,
4222
+ moneyRequestReportID,
4223
+ moneyRequestCreatedReportActionID,
4224
+ moneyRequestPreviewReportActionID,
4225
+ modifiedExpenseReportActionID,
4226
+ reportPreviewReportActionID,
4227
+ ...workspaceParams ,
4228
+ } ;
4229
+
4230
+ addTrackedExpenseToPolicy ( params , { optimisticData, successData, failureData} ) ;
4231
+ return ;
4232
+ }
4233
+
4177
4234
const parameters = {
4178
4235
attendees,
4179
4236
amount,
@@ -4319,13 +4376,22 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
4319
4376
actionableWhisperReportActionID,
4320
4377
linkedTrackedExpenseReportAction,
4321
4378
linkedTrackedExpenseReportID,
4379
+ waypoints,
4380
+ customUnitRateID,
4322
4381
} = transactionParams ;
4323
4382
4383
+ const sanitizedWaypoints = waypoints ? JSON . stringify ( sanitizeRecentWaypoints ( waypoints ) ) : undefined ;
4384
+
4324
4385
// If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
4325
4386
const isMoneyRequestReport = isMoneyRequestReportReportUtils ( report ) ;
4326
4387
const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport ( report ?. chatReportID ) : report ;
4327
4388
const moneyRequestReportID = isMoneyRequestReport ? report ?. reportID : '' ;
4328
4389
const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseIOUUtils ( action ) ;
4390
+ const existingTransactionID =
4391
+ isMovingTransactionFromTrackExpense && linkedTrackedExpenseReportAction && isMoneyRequestAction ( linkedTrackedExpenseReportAction )
4392
+ ? getOriginalMessage ( linkedTrackedExpenseReportAction ) ?. IOUTransactionID
4393
+ : undefined ;
4394
+ const existingTransaction = allTransactions [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ existingTransactionID } ` ] ;
4329
4395
4330
4396
const {
4331
4397
payerAccountID,
@@ -4346,10 +4412,8 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
4346
4412
policyParams,
4347
4413
transactionParams,
4348
4414
moneyRequestReportID,
4349
- existingTransactionID :
4350
- isMovingTransactionFromTrackExpense && linkedTrackedExpenseReportAction && isMoneyRequestAction ( linkedTrackedExpenseReportAction )
4351
- ? getOriginalMessage ( linkedTrackedExpenseReportAction ) ?. IOUTransactionID
4352
- : undefined ,
4415
+ existingTransactionID,
4416
+ existingTransaction : isDistanceRequestTransactionUtils ( existingTransaction ) ? existingTransaction : undefined ,
4353
4417
} ) ;
4354
4418
const activeReportID = isMoneyRequestReport ? report ?. reportID : chatReport . reportID ;
4355
4419
@@ -4358,7 +4422,20 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
4358
4422
if ( ! linkedTrackedExpenseReportAction || ! actionableWhisperReportActionID || ! linkedTrackedExpenseReportID ) {
4359
4423
return ;
4360
4424
}
4361
-
4425
+ const workspaceParams =
4426
+ isPolicyExpenseChatReportUtil ( chatReport ) && chatReport . policyID
4427
+ ? {
4428
+ receipt : receipt instanceof Blob ? receipt : undefined ,
4429
+ category,
4430
+ tag,
4431
+ taxCode,
4432
+ taxAmount,
4433
+ billable,
4434
+ policyID : chatReport . policyID ,
4435
+ waypoints : sanitizedWaypoints ,
4436
+ customUnitRateID,
4437
+ }
4438
+ : undefined ;
4362
4439
convertTrackedExpenseToRequest (
4363
4440
payerAccountID ,
4364
4441
payerEmail ,
@@ -4380,6 +4457,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
4380
4457
merchant ,
4381
4458
created ,
4382
4459
attendees ,
4460
+ workspaceParams ,
4383
4461
) ;
4384
4462
break ;
4385
4463
}
@@ -5044,7 +5122,7 @@ function createSplitsAndOnyxData(
5044
5122
const hasMultipleParticipants = participants . length > 1 ;
5045
5123
participants . forEach ( ( participant ) => {
5046
5124
// In a case when a participant is a workspace, even when a current user is not an owner of the workspace
5047
- const isPolicyExpenseChat = isPolicyExpenseChatReportUtils ( participant ) ;
5125
+ const isPolicyExpenseChat = isPolicyExpenseChatReportUtil ( participant ) ;
5048
5126
const splitAmount = splitShares ?. [ participant . accountID ?? CONST . DEFAULT_NUMBER_ID ] ?. amount ?? calculateIOUAmount ( participants . length , amount , currency , false ) ;
5049
5127
const splitTaxAmount = calculateIOUAmount ( participants . length , taxAmount , currency , false ) ;
5050
5128
@@ -5670,7 +5748,7 @@ function startSplitBill({
5670
5748
} ) ;
5671
5749
5672
5750
participants . forEach ( ( participant ) => {
5673
- const isPolicyExpenseChat = isPolicyExpenseChatReportUtils ( participant ) ;
5751
+ const isPolicyExpenseChat = isPolicyExpenseChatReportUtil ( participant ) ;
5674
5752
if ( ! isPolicyExpenseChat ) {
5675
5753
return ;
5676
5754
}
@@ -7279,7 +7357,7 @@ function getReportFromHoldRequestsOnyxData(
7279
7357
const newParentReportActionID = rand64 ( ) ;
7280
7358
7281
7359
const coefficient = isExpenseReport ( iouReport ) ? - 1 : 1 ;
7282
- const isPolicyExpenseChat = isPolicyExpenseChatReportUtils ( chatReport ) ;
7360
+ const isPolicyExpenseChat = isPolicyExpenseChatReportUtil ( chatReport ) ;
7283
7361
const holdAmount = ( ( iouReport ?. total ?? 0 ) - ( iouReport ?. unheldTotal ?? 0 ) ) * coefficient ;
7284
7362
const holdNonReimbursableAmount = ( ( iouReport ?. nonReimbursableTotal ?? 0 ) - ( iouReport ?. unheldNonReimbursableTotal ?? 0 ) ) * coefficient ;
7285
7363
const optimisticExpenseReport = isPolicyExpenseChat
@@ -7858,7 +7936,7 @@ function canIOUBePaid(
7858
7936
invoiceReceiverPolicy ?: SearchPolicy ,
7859
7937
shouldCheckApprovedState = true ,
7860
7938
) {
7861
- const isPolicyExpenseChat = isPolicyExpenseChatReportUtils ( chatReport ) ;
7939
+ const isPolicyExpenseChat = isPolicyExpenseChatReportUtil ( chatReport ) ;
7862
7940
const reportNameValuePairs = chatReportRNVP ?? getReportNameValuePairs ( chatReport ?. reportID ) ;
7863
7941
const isChatReportArchived = isArchivedReport ( reportNameValuePairs ) ;
7864
7942
const iouSettled = isSettled ( iouReport ) ;
@@ -8826,8 +8904,8 @@ function setMoneyRequestParticipantsFromReport(transactionID: string, report: On
8826
8904
const shouldAddAsReport = ! isEmptyObject ( chatReport ) && isSelfDM ( chatReport ) ;
8827
8905
let participants : Participant [ ] = [ ] ;
8828
8906
8829
- if ( isPolicyExpenseChatReportUtils ( chatReport ) || shouldAddAsReport ) {
8830
- participants = [ { accountID : 0 , reportID : chatReport ?. reportID , isPolicyExpenseChat : isPolicyExpenseChatReportUtils ( chatReport ) , selected : true } ] ;
8907
+ if ( isPolicyExpenseChatReportUtil ( chatReport ) || shouldAddAsReport ) {
8908
+ participants = [ { accountID : 0 , reportID : chatReport ?. reportID , isPolicyExpenseChat : isPolicyExpenseChatReportUtil ( chatReport ) , selected : true } ] ;
8831
8909
} else if ( isInvoiceRoom ( chatReport ) ) {
8832
8910
participants = [
8833
8911
{ reportID : chatReport ?. reportID , selected : true } ,
0 commit comments