only amount
ST
smntov at gmail.com
Sat Mar 10 14:53:31 EST 2012
actually I get errors everywhere I try to use the new fmtmoneyNoCurrency
instead of the original fmtmoney from taxinvoice.eguile.scm. How should
such a function for gnc-numeric look like?
thank you again, Derek,
ST
> Having said that, you are only getting one error, and the error is that
> you are passing a gnc-numeric into a function that only takes a
> gnc-monetary. Your issue is the line:
>
> (fmtmoneyNoCurrency rval)
>
> But rval is of the wrong type, hense the error:
>
> 77* [fmtmoneyNoCurrency #<num: 1800000 denom: 100>]
> 32: 78 [xaccPrintAmount ...
> 33: 79* [gnc:gnc-monetary-amount #< num: 1800000 denom: 100>]
> ?: 80 (if (eq? # #) (struct-ref obj 1) (%record-type-error # obj)) ...
> ?: 81 [scm-error wrong-type-arg "%record-type-check" ...]
>
> You cannot use your new API for both types. You will have a similar
> problem later, where you try to format the output of gnc-numeric-add
>
> -derek
>
> PS: I would have responded inline and cut most of this message had you
> already sent it to the list.. Please rmemeber to send future messages to
> the list. Thanks.
>
> ST <smntov at gmail.com> writes:
>
> > thank you Derek!
> >
> > I tried this, but I still get errors. Here is a portion of slightly
> > modified version of taxinvoice.eguile.scm (here I try to print only
> > amounts without currency):
> >
> > [see errors below]
> >
> > <tbody> <!-- display invoice entry lines, keeping running totals -->
> > <?scm
> > (let ((tax-total (gnc:make-commodity-collector))
> > (sub-total (gnc:make-commodity-collector))
> > (dsc-total (gnc:make-commodity-collector))
> > (inv-total (gnc:make-commodity-collector)))
> > (for entry in entries do
> > (let ((qty (gncEntryGetQuantity entry))
> > (each (gncEntryGetInvPrice entry))
> > (action (gncEntryGetAction entry))
> > (rval (gncEntryReturnValue entry #t))
> > (rdiscval (gncEntryReturnDiscountValue entry #t))
> > (rtaxval (gncEntryReturnTaxValue entry #t))
> > (disc (gncEntryGetInvDiscount entry))
> > (disctype (gncEntryGetInvDiscountType entry))
> > (acc (gncEntryGetInvAccount entry))
> > (taxable (gncEntryGetInvTaxable entry))
> > (taxtable (gncEntryGetInvTaxTable entry)))
> > (inv-total 'add currency rval)
> > (inv-total 'add currency rtaxval)
> > (tax-total 'add currency rtaxval)
> > (sub-total 'add currency rval)
> > (dsc-total 'add currency rdiscval)
> > ?>
> > <tr valign="top">
> > <td align="center"><?scm:d (gnc-print-date (gncEntryGetDate
> > entry)) ?></td>
> > <td align="right"><?scm:d (gncEntryGetDescription entry) ?></td>
> > <!-- td align="right">< ?scm:d (gncEntryGetNotes entry) ?></td -->
> > <?scm (if units? (begin ?>
> > <td align="right"><?scm:d action ?></td>
> > <?scm )) ?>
> > <?scm (if (or units? qty?) (begin ?>
> > <td align="left"><?scm:d (fmtnumeric qty) ?></td>
> > <?scm )) ?>
> > <?scm (if (or units? qty? discount?) (begin ?>
> > <td align="left"><?scm:d (fmtmoneyNoCurrency each) ?></td>
> > <?scm )) ?>
> > <?scm (if discount? (begin ?>
> > <?scm (if (equal? disctype GNC-AMT-TYPE-VALUE) (begin ?>
> > <td align="left"><?scm:d (gnc:monetary->string
> > (gnc:make-gnc-monetary currency disc)) ?></td>
> > <?scm ) (begin ?>
> > <td align="left"><?scm:d (fmtnumeric disc) ?>%</td>
> > <?scm )) ?>
> > <td align="left"><?scm:d (fmtmoneyNoCurrency rdiscval) ?></td>
> > <?scm )) ?>
> > <?scm (if (and tax? taxtables?) (begin ?>
> > <td align="left"><?scm:d (fmtmoneyNoCurrency rval) ?></td>
> > <td align="left"><?scm (taxrate taxable taxtable
> > currency) ?></td>
> > <td align="left"><?scm:d (fmtmoneyNoCurrency rtaxval) ?></td>
> > <?scm )) ?>
> > <!-- TO DO: need an option about whether to display the
> > tax-inclusive total? -->
> > <td align="left"><?scm:d (fmtmoneyNoCurrency (gnc-numeric-add rval
> > rtaxval GNC-DENOM-AUTO GNC-RND-ROUND)) ?></td>
> > </tr>
> > <?scm )) ?>
> >
> > <!-- display subtotals row -->
> > <?scm (if (or tax? discount? payments?) (begin ?>
> > <tr valign="top">
> > <td align="right" class="subtotal" colspan="<?scm:d
> > spancols2 ?>"><strong><?scm:d opt-subtotal-heading ?></strong></td>
> > <?scm (if discount? (begin ?>
> > <td align="left" class="subtotal"><strong><?scm
> > (display-comm-coll-total dsc-total #f) ?></strong></td>
> > <?scm )) ?>
> > <?scm (if (and tax? taxtables?) (begin ?>
> > <td align="left" class="subtotal"><strong><?scm
> > (display-comm-coll-total sub-total #f) ?></strong></td>
> > <td> </td>
> > <td align="left" class="subtotal"><strong><?scm
> > (display-comm-coll-total tax-total #f) ?></strong></td>
> > <?scm )) ?>
> > <td align="left" class="subtotal"><strong><?scm
> > (display-comm-coll-total inv-total #f) ?></strong></td>
> > </tr>
> > <?scm )) ?>
> >
> > <!-- payments -->
> > <?scm
> > (if payments?
> > (for split in splits do
> > (let ((t (xaccSplitGetParent split)))
> > (if (not (equal? t txn)) ; don't process the entry itself
> > as a split
> > (let ((c (xaccTransGetCurrency t))
> > (a (xaccSplitGetValue split)))
> > (inv-total 'add c a)
> > ?>
> > <tr valign="top">
> > <td align="center"><?scm:d (gnc-print-date
> > (gnc-transaction-get-date-posted t)) ?></td>
> > <td align="right" colspan="<?scm:d (- spancols1 1) ?>"><?scm:d
> > opt-payment-recd-heading ?></td>
> > <td align="left"><?scm:d (fmtmoneyNoCurrency a) ?></td>
> > </tr>
> > <?scm ))))) ?>
> >
> > <!-- total row -->
> > <tr valign="top">
> > <td align="right" class="total" colspan="<?scm:d
> > spancols1 ?>"><strong><?scm:d opt-amount-due-heading ?></strong></td>
> > <td align="left" class="total"><strong><?scm
> > (display-comm-coll-total inv-total #f) ?></strong></td>
> > </tr>
> >
> > </tbody>
> >
> >
> >
> > but I get following 2 errors:
> >
> > n error occurred when processing the template:
> >
> > ERROR: In procedure %record-type-check:
> > ERROR: Wrong type record (want `"<gnc-monetary>"'): #<<gnc-numeric> num:
> > 1800000 denom: 100>
> > In current input:
> > 4: 63* (let* ((x 42)) (letrec (# #) (if # # ...) ...))
> > ?: 64 (letrec (# #) (if # # #) (display "
> >
> >
> >
> > "))
> > 411: 65* (if (null? opt-invoice) (begin (display #) (display #)) ...)
> > 415: 66 (let* ((owner #) (endowner #) (ownertype #)) (if (not #)
> > (begin # #) ...))
> > ...
> > 38: 67 (let* (# # # # ...) (if # #) (for-each # entries) ...)
> > 296: 68* (let (# # # ...) (for-each # entries) ...)
> > 300: 69* (for entry in ...)
> > 300: 70 [for-each # (#)]
> > ?: 71* [# #]
> > ?: 72* (let (# # # # ...) (begin # # # ...))
> > ?: 73 (begin (inv-total # currency ...) (inv-total #
> > currency ...) ...)
> > ?: 74* (if (and tax? taxtables?) (begin # # # ...))
> > ?: 75 (begin (display "
> >
> >
> > and the second error:
> >
> >
> > ") (display #) ...) ?: 76* [display ... ?: 77* [fmtmoneyNoCurrency #<
> > num: 1800000 denom: 100>] 32: 78 [xaccPrintAmount ... 33: 79*
> > [gnc:gnc-monetary-amount #< num: 1800000 denom: 100>] ?: 80 (if (eq? #
> > #) (struct-ref obj 1) (%record-type-error # obj)) ... ?: 81 [scm-error
> > wrong-type-arg "%record-type-check" ...]
> >
> >
> > On Tue, 2012-03-06 at 11:41 -0500, Derek Atkins wrote:
> >> Hi,
> >>
> >> ST <smntov at gmail.com> writes:
> >>
> >> > when I removed "-public" from define it started to work...
> >> >
> >> > I tried:
> >> >
> >> > (define (fmtmoneyNoCurrency curr amt)
> >> > ;; Format a monetary amount in the given currency as HTML
> >> > (nbsp (gnc:monetary->string (gnc:gnc-monetary-amount amt))))
> >> >
> >> > but it also produced errors...
> >> >
> >> > So the questions is - how do I rewrite this function so that it prints
> >> > only amount without currency?
> >>
> >> The gnc:monetary->string API expects a <gnc:monetary>. What you want is
> >> a modification of that API that passes #f instead of #t into
> >> gnc-commodity-print-info. So something like:
> >>
> >> (define (fmtmoneyNoCurrency value)
> >> (xaccPrintAmount
> >> (gnc:gnc-monetary-amount value)
> >> (gnc-commodity-print-info (gnc:gnc-monetary-commodity value) #f)))
> >>
> >> Then you can use this instead of gnc:monetary->string
> >>
> >> > ST
> >>
> >> -derek
> >>
> >
> >
> >
> >
>
More information about the gnucash-devel
mailing list