@@ -61,13 +61,13 @@ import type {
6161 TransactionViolation ,
6262} from '@src/types/onyx' ;
6363import type { ReportAttributes , ReportAttributesDerivedValue } from '@src/types/onyx/DerivedValues' ;
64- import type { Participant } from '@src/types/onyx/IOU' ;
64+ import type { Accountant , Attendee , Participant } from '@src/types/onyx/IOU' ;
6565import type { CurrentUserPersonalDetails } from '@src/types/onyx/PersonalDetails' ;
6666import type { Unit } from '@src/types/onyx/Policy' ;
6767import type { Comment , Receipt , WaypointCollection } from '@src/types/onyx/Transaction' ;
6868import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
6969import type { GpsPoint , IOURequestType } from './index' ;
70- import { getAllTransactionDrafts , setMoneyRequestMerchant , setMoneyRequestPendingFields } from './index' ;
70+ import { getAllTransactionDrafts } from './index' ;
7171import { createDistanceRequest , resetSplitShares , startSplitBill } from './Split' ;
7272import { submitWithDismissFirst } from './submitWithDismissFirst' ;
7373import type { WriteOverrides } from './submitWithDismissFirst' ;
@@ -1337,6 +1337,87 @@ function setMoneyRequestDistanceRate(currentTransaction: OnyxEntry<Transaction>,
13371337 } ) ;
13381338}
13391339
1340+ function setMoneyRequestReceiptState ( transactionID : string , isDraft : boolean , shouldStopSmartscan = false ) {
1341+ if ( ! isDraft || ! shouldStopSmartscan ) {
1342+ return ;
1343+ }
1344+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { receipt : { state : CONST . IOU . RECEIPT_STATE . OPEN } } ) ;
1345+ }
1346+
1347+ function setMoneyRequestAmount ( transactionID : string , amount : number , currency : string , shouldShowOriginalAmount = false , shouldStopSmartscan = false ) {
1348+ // Mark that the user has explicitly set the amount. This is used by the new manual expense flow to distinguish
1349+ // a default amount of 0 (field empty) from a user-entered 0 (valid $0 expense).
1350+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { amount, currency, shouldShowOriginalAmount, isAmountSet : true } ) ;
1351+ setMoneyRequestReceiptState ( transactionID , true , shouldStopSmartscan ) ;
1352+ }
1353+
1354+ /**
1355+ * Clears the amount field back to an empty/unset state in the new manual expense flow.
1356+ * Called when the user deletes all characters from the amount input so that the field
1357+ * shows as empty and submission is blocked until a value is entered again.
1358+ */
1359+ function clearMoneyRequestAmount ( transactionID : string ) {
1360+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { amount : 0 , isAmountSet : false } ) ;
1361+ }
1362+
1363+ function clearMoneyRequestMerchant ( transactionID : string , isDraft = true ) {
1364+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { merchant : '' , isMerchantSet : false } ) ;
1365+ }
1366+
1367+ function setMoneyRequestCreated ( transactionID : string , created : string , isDraft : boolean , shouldStopSmartscan = false ) {
1368+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { created} ) ;
1369+ setMoneyRequestReceiptState ( transactionID , isDraft , shouldStopSmartscan ) ;
1370+ }
1371+
1372+ function setMoneyRequestDateAttribute ( transactionID : string , start : string , end : string ) {
1373+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { comment : { customUnit : { attributes : { dates : { start, end} } } } } ) ;
1374+ }
1375+
1376+ function setMoneyRequestCurrency ( transactionID : string , currency : string , isEditing = false ) {
1377+ const fieldToUpdate = isEditing ? 'modifiedCurrency' : 'currency' ;
1378+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { [ fieldToUpdate ] : currency } ) ;
1379+ }
1380+
1381+ function setMoneyRequestDescription ( transactionID : string , comment : string , isDraft : boolean , shouldStopSmartscan = false ) {
1382+ // Trim only when persisting to the real transaction (not a draft) to avoid
1383+ // stripping trailing spaces/newlines while the user is still typing.
1384+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { comment : { comment : isDraft ? comment : comment . trim ( ) } } ) ;
1385+ setMoneyRequestReceiptState ( transactionID , isDraft , shouldStopSmartscan ) ;
1386+ }
1387+
1388+ function setMoneyRequestMerchant ( transactionID : string , merchant : string , isDraft : boolean , shouldStopSmartscan = false ) {
1389+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { merchant, isMerchantSet : true } ) ;
1390+ setMoneyRequestReceiptState ( transactionID , isDraft , shouldStopSmartscan ) ;
1391+ }
1392+
1393+ function setMoneyRequestAttendees ( transactionID : string , attendees : Attendee [ ] , isDraft : boolean ) {
1394+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { comment : { attendees} } ) ;
1395+ }
1396+
1397+ function setMoneyRequestAccountant ( transactionID : string , accountant : Accountant , isDraft : boolean ) {
1398+ Onyx . merge ( `${ isDraft ? ONYXKEYS . COLLECTION . TRANSACTION_DRAFT : ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` , { accountant} ) ;
1399+ }
1400+
1401+ function setMoneyRequestPendingFields ( transactionID : string , pendingFields : Transaction [ 'pendingFields' ] ) {
1402+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { pendingFields} ) ;
1403+ }
1404+
1405+ function setMoneyRequestTag ( transactionID : string , tag : string ) {
1406+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { tag} ) ;
1407+ }
1408+
1409+ function setMoneyRequestBillable ( transactionID : string , billable : boolean ) {
1410+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { billable} ) ;
1411+ }
1412+
1413+ function setMoneyRequestReimbursable ( transactionID : string , reimbursable : boolean ) {
1414+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { reimbursable} ) ;
1415+ }
1416+
1417+ function setMoneyRequestReportID ( transactionID : string , reportID : string ) {
1418+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { reportID} ) ;
1419+ }
1420+
13401421export {
13411422 createTransaction ,
13421423 handleMoneyRequestStepScanParticipants ,
@@ -1366,5 +1447,21 @@ export {
13661447 setCustomUnitID ,
13671448 setMoneyRequestDistance ,
13681449 setMoneyRequestDistanceRate ,
1450+ setMoneyRequestReceiptState ,
1451+ setMoneyRequestAmount ,
1452+ clearMoneyRequestAmount ,
1453+ clearMoneyRequestMerchant ,
1454+ setMoneyRequestCreated ,
1455+ setMoneyRequestDateAttribute ,
1456+ setMoneyRequestCurrency ,
1457+ setMoneyRequestDescription ,
1458+ setMoneyRequestMerchant ,
1459+ setMoneyRequestAttendees ,
1460+ setMoneyRequestAccountant ,
1461+ setMoneyRequestPendingFields ,
1462+ setMoneyRequestTag ,
1463+ setMoneyRequestBillable ,
1464+ setMoneyRequestReimbursable ,
1465+ setMoneyRequestReportID ,
13691466} ;
13701467export type { MoneyRequestStepScanParticipantsFlowParams } ;
0 commit comments