diff --git a/doc/examples/simple-book-add-txn.scm b/doc/examples/simple-book-add-txn.scm index 4c34b474451..168d3a6f778 100644 --- a/doc/examples/simple-book-add-txn.scm +++ b/doc/examples/simple-book-add-txn.scm @@ -99,31 +99,37 @@ (action-fn acc-EXP-LEAF) (action-fn acc-EXP-TAX)) -(define txn (xaccMallocTransaction book)) - (define description (get-line "Description")) -(define net-amount (get-amount "Amount, without tax")) -(define tax-amount (* net-amount 1/10)) -(define total-amount (+ tax-amount net-amount)) - -(accounts-action xaccAccountBeginEdit) -(xaccTransBeginEdit txn) -(xaccTransSetCurrency txn (xaccAccountGetCommodity acc-BANK)) -(xaccTransSetDatePostedSecsNormalized txn (current-time)) -(xaccTransSetDescription txn description) -(add-to-transaction book txn acc-BANK (- total-amount) "from bank") -(add-to-transaction book txn acc-EXP-LEAF net-amount "expense net") -(add-to-transaction book txn acc-EXP-TAX tax-amount "tax paid") -(newline) -(gnc:dump-transaction txn) - -(cond - ((get-binary-response "Please confirm transaction [YN]") - (xaccTransCommitEdit txn)) - (else - (xaccTransRollbackEdit txn) - (xaccTransDestroy txn))) -(accounts-action xaccAccountCommitEdit) + +(let lp () + (define txn (xaccMallocTransaction book)) + (define net-amount (get-amount "Amount, without tax")) + (define tax-amount (* net-amount 1/10)) + (define total-amount (+ tax-amount net-amount)) + + (xaccTransBeginEdit txn) + (xaccTransSetCurrency txn (xaccAccountGetCommodity acc-BANK)) + (xaccTransSetDatePostedSecsNormalized txn (current-time)) + (xaccTransSetDescription txn description) + (add-to-transaction book txn acc-BANK (- total-amount) "from bank") + (add-to-transaction book txn acc-EXP-LEAF net-amount "expense net") + (add-to-transaction book txn acc-EXP-TAX tax-amount "tax paid") + (newline) + (gnc:dump-transaction txn) + + (cond + ((not (xaccTransIsBalanced txn)) + (display "WARNING: transaction is not balanced. Try again.\n") + (xaccTransRollbackEdit txn) + (xaccTransDestroy txn) + (lp)) + ((get-binary-response "Please confirm transaction [YN]") + (accounts-action xaccAccountBeginEdit) + (xaccTransCommitEdit txn) + (accounts-action xaccAccountCommitEdit)) + (else + (xaccTransRollbackEdit txn) + (xaccTransDestroy txn)))) ;; (gnc:dump-book) (when (qof-book-session-not-saved book)