@@ -2404,6 +2404,14 @@ function isReportFieldOfTypeTitle(reportField: OnyxEntry<PolicyReportField>): bo
2404
2404
return reportField ?. type === 'formula' && reportField ?. fieldID === CONST . REPORT_FIELD_TITLE_FIELD_ID ;
2405
2405
}
2406
2406
2407
+ /**
2408
+ * Check if Report has any held expenses
2409
+ */
2410
+ function isHoldCreator ( transaction : OnyxEntry < Transaction > , reportID : string ) : boolean {
2411
+ const holdReportAction = ReportActionsUtils . getReportAction ( reportID , `${ transaction ?. comment ?. hold ?? '' } ` ) ;
2412
+ return isActionCreator ( holdReportAction ) ;
2413
+ }
2414
+
2407
2415
/**
2408
2416
* Check if report fields are available to use in a report
2409
2417
*/
@@ -2721,6 +2729,71 @@ function canEditReportAction(reportAction: OnyxEntry<ReportAction>): boolean {
2721
2729
) ;
2722
2730
}
2723
2731
2732
+ function canHoldUnholdReportAction ( reportAction : OnyxEntry < ReportAction > ) : { canHoldRequest : boolean ; canUnholdRequest : boolean } {
2733
+ if ( reportAction ?. actionName !== CONST . REPORT . ACTIONS . TYPE . IOU ) {
2734
+ return { canHoldRequest : false , canUnholdRequest : false } ;
2735
+ }
2736
+
2737
+ const moneyRequestReportID = reportAction ?. originalMessage ?. IOUReportID ?? 0 ;
2738
+ const moneyRequestReport = getReport ( String ( moneyRequestReportID ) ) ;
2739
+
2740
+ if ( ! moneyRequestReportID || ! moneyRequestReport ) {
2741
+ return { canHoldRequest : false , canUnholdRequest : false } ;
2742
+ }
2743
+
2744
+ const isRequestSettled = isSettled ( moneyRequestReport ?. reportID ) ;
2745
+ const isApproved = isReportApproved ( moneyRequestReport ) ;
2746
+ const transactionID = moneyRequestReport ? reportAction ?. originalMessage ?. IOUTransactionID : 0 ;
2747
+ const transaction = allTransactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] ?? ( { } as Transaction ) ;
2748
+
2749
+ const parentReport = getReport ( String ( moneyRequestReport . parentReportID ) ) ;
2750
+ const parentReportAction = ReportActionsUtils . getParentReportAction ( moneyRequestReport ) ;
2751
+
2752
+ const isRequestIOU = parentReport ?. type === 'iou' ;
2753
+ const isRequestHoldCreator = isHoldCreator ( transaction , moneyRequestReport ?. reportID ) && isRequestIOU ;
2754
+ const isTrackExpenseMoneyReport = isTrackExpenseReport ( moneyRequestReport ) ;
2755
+ const isActionOwner =
2756
+ typeof parentReportAction ?. actorAccountID === 'number' &&
2757
+ typeof currentUserPersonalDetails ?. accountID === 'number' &&
2758
+ parentReportAction . actorAccountID === currentUserPersonalDetails ?. accountID ;
2759
+ const isApprover = isMoneyRequestReport ( moneyRequestReport ) && moneyRequestReport ?. managerID !== null && currentUserPersonalDetails ?. accountID === moneyRequestReport ?. managerID ;
2760
+ const isOnHold = TransactionUtils . isOnHold ( transaction ) ;
2761
+ const isScanning = TransactionUtils . hasReceipt ( transaction ) && TransactionUtils . isReceiptBeingScanned ( transaction ) ;
2762
+
2763
+ const canModifyStatus = ! isTrackExpenseMoneyReport && ( isPolicyAdmin || isActionOwner || isApprover ) ;
2764
+ const isDeletedParentAction = isEmptyObject ( parentReportAction ) || ReportActionsUtils . isDeletedAction ( parentReportAction ) ;
2765
+
2766
+ const canHoldOrUnholdRequest = ! isRequestSettled && ! isApproved && ! isDeletedParentAction ;
2767
+ const canHoldRequest = canHoldOrUnholdRequest && ! isOnHold && ( isRequestHoldCreator || ( ! isRequestIOU && canModifyStatus ) ) && ! isScanning ;
2768
+ const canUnholdRequest = ! ! ( canHoldOrUnholdRequest && isOnHold && ( isRequestHoldCreator || ( ! isRequestIOU && canModifyStatus ) ) ) ;
2769
+
2770
+ return { canHoldRequest, canUnholdRequest} ;
2771
+ }
2772
+
2773
+ const changeMoneyRequestHoldStatus = ( reportAction : OnyxEntry < ReportAction > ) : void => {
2774
+ if ( reportAction ?. actionName !== CONST . REPORT . ACTIONS . TYPE . IOU ) {
2775
+ return ;
2776
+ }
2777
+ const moneyRequestReportID = reportAction ?. originalMessage ?. IOUReportID ?? 0 ;
2778
+
2779
+ const moneyRequestReport = getReport ( String ( moneyRequestReportID ) ) ;
2780
+ if ( ! moneyRequestReportID || ! moneyRequestReport ) {
2781
+ return ;
2782
+ }
2783
+
2784
+ const transactionID = reportAction ?. originalMessage ?. IOUTransactionID ?? '' ;
2785
+ const transaction = allTransactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] ?? ( { } as Transaction ) ;
2786
+ const isOnHold = TransactionUtils . isOnHold ( transaction ) ;
2787
+ const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ moneyRequestReport . policyID } ` ] ?? null ;
2788
+
2789
+ if ( isOnHold ) {
2790
+ IOU . unholdRequest ( transactionID , reportAction . childReportID ?? '' ) ;
2791
+ } else {
2792
+ const activeRoute = encodeURIComponent ( Navigation . getActiveRouteWithoutParams ( ) ) ;
2793
+ Navigation . navigate ( ROUTES . MONEY_REQUEST_HOLD_REASON . getRoute ( policy ?. type ?? CONST . POLICY . TYPE . PERSONAL , transactionID , reportAction . childReportID ?? '' , activeRoute ) ) ;
2794
+ }
2795
+ } ;
2796
+
2724
2797
/**
2725
2798
* Gets all transactions on an IOU report with a receipt
2726
2799
*/
@@ -6386,14 +6459,6 @@ function navigateToPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Se
6386
6459
Navigation . navigate ( ROUTES . PRIVATE_NOTES_LIST . getRoute ( report . reportID ) ) ;
6387
6460
}
6388
6461
6389
- /**
6390
- * Check if Report has any held expenses
6391
- */
6392
- function isHoldCreator ( transaction : OnyxEntry < Transaction > , reportID : string ) : boolean {
6393
- const holdReportAction = ReportActionsUtils . getReportAction ( reportID , `${ transaction ?. comment ?. hold ?? '' } ` ) ;
6394
- return isActionCreator ( holdReportAction ) ;
6395
- }
6396
-
6397
6462
/**
6398
6463
* Get all held transactions of a iouReport
6399
6464
*/
@@ -6905,6 +6970,7 @@ export {
6905
6970
canCreateTaskInReport ,
6906
6971
canCurrentUserOpenReport ,
6907
6972
canDeleteReportAction ,
6973
+ canHoldUnholdReportAction ,
6908
6974
canEditFieldOfMoneyRequest ,
6909
6975
canEditMoneyRequest ,
6910
6976
canEditPolicyDescription ,
@@ -7132,6 +7198,7 @@ export {
7132
7198
shouldShowMerchantColumn ,
7133
7199
isCurrentUserInvoiceReceiver ,
7134
7200
isDraftReport ,
7201
+ changeMoneyRequestHoldStatus ,
7135
7202
createDraftWorkspaceAndNavigateToConfirmationScreen ,
7136
7203
} ;
7137
7204
0 commit comments