feat(splits): save split as rule from split modal

- Checkbox in split modal: 'Also save as rule for <merchant>'
- Creates a rule with apply_split action storing the participant shares
- Rules engine now handles apply_split: deletes existing splits and re-applies
- Bulk split mode hides the checkbox (rule wouldn't make sense for ad-hoc bulk)
This commit is contained in:
2026-03-11 12:40:03 +11:00
parent a8743ba7df
commit af4c64bba7
4 changed files with 58 additions and 6 deletions
+18
View File
@@ -9,10 +9,16 @@ interface Condition {
value: string;
}
interface SplitEntry {
participant_id: number;
share_percent: number;
}
interface Actions {
set_category?: string;
add_tag_ids?: number[];
set_merchant?: string;
apply_split?: SplitEntry[];
}
interface TxFields {
@@ -108,6 +114,18 @@ export async function POST(req: NextRequest) {
);
}
}
if (actions.apply_split?.length) {
// Delete existing splits then insert new ones
await queryRaw(`DELETE FROM transaction_splits WHERE transaction_id = $1`, [tx.id]);
for (const s of actions.apply_split) {
await queryRaw(
`INSERT INTO transaction_splits (transaction_id, participant_id, share_percent)
VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`,
[tx.id, s.participant_id, s.share_percent]
);
}
}
}
}