@@ -24,6 +24,7 @@ import variables from '@styles/variables';
24
24
import CONST from '@src/CONST' ;
25
25
import ONYXKEYS from '@src/ONYXKEYS' ;
26
26
import ROUTES from '@src/ROUTES' ;
27
+ import { SearchReport , SearchTransaction } from '@src/types/onyx/SearchResults' ;
27
28
import type DeepValueOf from '@src/types/utils/DeepValueOf' ;
28
29
import { useSearchContext } from './SearchContext' ;
29
30
import SearchPageHeaderInput from './SearchPageHeaderInput' ;
@@ -57,7 +58,7 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
57
58
const [ isDownloadErrorModalVisible , setIsDownloadErrorModalVisible ] = useState ( false ) ;
58
59
59
60
const { status, hash} = queryJSON ;
60
-
61
+ const [ allSnapshots ] = useOnyx ( ` ${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ hash } ` ) ;
61
62
const selectedTransactionsKeys = Object . keys ( selectedTransactions ?? { } ) ;
62
63
63
64
const handleDeleteExpenses = ( ) => {
@@ -136,7 +137,9 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
136
137
const transactionIDList = selectedReports . length ? undefined : Object . keys ( selectedTransactions ) ;
137
138
const items = selectedReports . length ? selectedReports : Object . values ( selectedTransactions ) ;
138
139
139
- for ( const item of items ) {
140
+ let updatedSelectedTransactions : SearchTransaction [ ] = [ ] ;
141
+ let updatedSelectedReports : SearchReport [ ] = [ ] ;
142
+ items . forEach ( ( item , index ) => {
140
143
const policyID = item . policyID ;
141
144
const lastPolicyPaymentMethod = policyID ? lastPaymentMethods ?. [ policyID ] : null ;
142
145
@@ -146,23 +149,30 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
146
149
}
147
150
148
151
const hasVBBA = PolicyUtils . hasVBBA ( policyID ) ;
149
-
150
152
if ( lastPolicyPaymentMethod !== CONST . IOU . PAYMENT_TYPE . ELSEWHERE && ! hasVBBA ) {
151
153
Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : item . reportID , backTo : activeRoute } ) ) ;
152
154
return ;
153
155
}
154
- }
156
+
157
+ // We need to compute the amount for the report or the transaction, by getting the snapshot data
158
+ if ( selectedReports . length === 0 ) {
159
+ const itemSnapshotData = ( allSnapshots ?. data ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionIDList ! [ index ] } ` ] ?? { } ) as SearchTransaction ;
160
+ updatedSelectedTransactions . push ( itemSnapshotData ) ;
161
+ } else {
162
+ const itemSnapshotData = ( allSnapshots ?. data ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ item . reportID } ` ] ?? { } ) as SearchReport ;
163
+ updatedSelectedReports . push ( itemSnapshotData ) ;
164
+ }
165
+ } ) ;
155
166
156
167
const paymentData = (
157
168
selectedReports . length
158
- ? selectedReports . map ( ( report ) => ( { reportID : report . reportID , amount : report . total , paymentType : lastPaymentMethods [ report . policyID ] } ) )
159
- : Object . values ( selectedTransactions ) . map ( ( transaction ) => ( {
169
+ ? updatedSelectedReports . map ( ( report ) => ( { reportID : report . reportID , amount : report . total , paymentType : lastPaymentMethods [ report . policyID ] } ) )
170
+ : updatedSelectedTransactions . map ( ( transaction ) => ( {
160
171
reportID : transaction . reportID ,
161
- amount : transaction . amount ,
172
+ amount : Math . abs ( transaction . amount ) ,
162
173
paymentType : lastPaymentMethods [ transaction . policyID ] ,
163
174
} ) )
164
175
) as PaymentData [ ] ;
165
-
166
176
SearchActions . payMoneyRequestOnSearch ( hash , paymentData , transactionIDList ) ;
167
177
} ,
168
178
} ) ;
0 commit comments