mirror of https://github.com/Gnucash/gnucash
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2104 57a11ea4-9604-0410-9ed3-97b8803252fdzzzoldreleases/1.4
parent
3d6fc24d2b
commit
e6a025cd57
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,112 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; number-to-words.scm
|
||||
;;; convert a number into a sentence for check printing
|
||||
;;;
|
||||
;;; Copyright 2000 Bill Gribble <grib@billgribble.com>
|
||||
;;; $Id$
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(gnc:support "number-to-words.scm")
|
||||
|
||||
(define (integer-to-words val)
|
||||
(let ((current-string "")
|
||||
(small-numbers
|
||||
#("zero" "one" "two" "three" "four" "five"
|
||||
"six" "seven" "eight" "nine" "ten"
|
||||
"eleven" "twelve" "thirteen" "fourteen" "fifteen"
|
||||
"sixteen" "seventeen" "eighteen" "nineteen" "twenty"))
|
||||
(medium-numbers
|
||||
#("zero" "ten" "twenty" "thirty" "forty" "fifty"
|
||||
"sixty" "seventy" "eighty" "ninety"))
|
||||
(big-numbers
|
||||
#("hundred" "thousand" "million" "billion" "trillion"
|
||||
"quadrillion" "quintillion")))
|
||||
(cond
|
||||
((< val 20)
|
||||
(vector-ref small-numbers val))
|
||||
|
||||
((< val 100)
|
||||
(let ((this-part (quotient val 10))
|
||||
(that-part (remainder val 10)))
|
||||
(set! current-string (vector-ref medium-numbers this-part))
|
||||
(if (> that-part 0)
|
||||
(set! current-string
|
||||
(string-append current-string "-"
|
||||
(vector-ref small-numbers that-part))))
|
||||
current-string))
|
||||
((< val 1000)
|
||||
(let ((this-part (quotient val 100))
|
||||
(that-part (remainder val 100)))
|
||||
(set! current-string
|
||||
(string-append current-string
|
||||
(vector-ref small-numbers this-part) " "
|
||||
(vector-ref big-numbers 0)))
|
||||
(if (> that-part 0)
|
||||
(set! current-string
|
||||
(string-append current-string
|
||||
" " (integer-to-words that-part))))
|
||||
current-string))
|
||||
(#t
|
||||
(let* ((log-val (inexact->exact
|
||||
(truncate (+ .00001 (/ (log10 val) 3)))))
|
||||
(this-part (quotient val
|
||||
(inexact->exact
|
||||
(truncate
|
||||
(+ .00001 (expt 10 (* 3 log-val)))))))
|
||||
(that-part (remainder val
|
||||
(inexact->exact
|
||||
(+ .00001
|
||||
(truncate
|
||||
(expt 10 (* 3 log-val))))))))
|
||||
(if (> this-part 0)
|
||||
(set! current-string
|
||||
(string-append (integer-to-words this-part)
|
||||
" " (vector-ref big-numbers log-val))))
|
||||
(if (> that-part 0)
|
||||
(set! current-string
|
||||
(string-append current-string
|
||||
" " (integer-to-words that-part))))
|
||||
current-string)))))
|
||||
|
||||
;; return a string with the number properly truncated and zero padded
|
||||
;; for check printing
|
||||
(define (printable-value val frac-denom)
|
||||
(let* ((int-part (inexact->exact (truncate val)))
|
||||
(frac-part (inexact->exact
|
||||
(truncate
|
||||
(+ (/ .5 frac-denom) (* frac-denom
|
||||
(- val int-part)))))))
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(write int-part) (display ".")
|
||||
(if (< frac-part 10) (display "0"))
|
||||
(write frac-part)))))
|
||||
|
||||
|
||||
(define (number-to-words val frac-denom)
|
||||
(let* ((negative?
|
||||
(if (< val 0)
|
||||
(begin (set! val (- val))
|
||||
#t)
|
||||
#f))
|
||||
(int-part (inexact->exact (truncate val)))
|
||||
(frac-part (inexact->exact
|
||||
(truncate
|
||||
(+ (/ .5 frac-denom) (* frac-denom (- val int-part))))))
|
||||
(result-string ""))
|
||||
(set! result-string
|
||||
(string-append (integer-to-words int-part) " and "
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(write frac-part)
|
||||
(display "/")
|
||||
(write frac-denom)))))
|
||||
(string-set! result-string 0
|
||||
(char-upcase (string-ref result-string 0)))
|
||||
result-string))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; print-check.scm
|
||||
;;; print a check from a transaction.
|
||||
;;;
|
||||
;;; Copyright 2000 Bill Gribble <grib@billgribble.com>
|
||||
;;; $Id$
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(gnc:support "print-check.scm")
|
||||
(gnc:depend "number-to-words.scm")
|
||||
|
||||
;; format notes (I found a GIF of the check form and am measuring from
|
||||
;; that, so this is definitely not perfect) positions are lower-left
|
||||
;; text origin, (0,0) at lower left of page, in inches, for
|
||||
;; US-Letter format paper.
|
||||
(define quicken-check-3up-at-top-us-letter
|
||||
'((payee . (1.0625 9.625))
|
||||
(amount-words . (1.0625 9.325))
|
||||
(amount-number . (6.5 9.625))
|
||||
(date . (6.5 10.1))
|
||||
(memo . (1.0625 8.15))))
|
||||
|
||||
(define (gnc:print-check payee amount date memo)
|
||||
(let* ((int-part (inexact->exact (truncate amount)))
|
||||
(frac-part (inexact->exact
|
||||
(truncate
|
||||
(+ (/ .5 100) (* 100 (- amount int-part))))))
|
||||
(ps (gnc:print-session-create))
|
||||
(format quicken-check-3up-at-top-us-letter)
|
||||
(inches-to-points
|
||||
(lambda (inches)
|
||||
(* inches 72))))
|
||||
|
||||
(let ((date-pos (assq 'date format)))
|
||||
(gnc:print-session-moveto ps
|
||||
(inches-to-points (cadr date-pos))
|
||||
(inches-to-points (caddr date-pos)))
|
||||
(gnc:print-session-text ps date))
|
||||
|
||||
(let ((payee-pos (assq 'payee format)))
|
||||
(gnc:print-session-moveto ps
|
||||
(inches-to-points (cadr payee-pos))
|
||||
(inches-to-points (caddr payee-pos)))
|
||||
(gnc:print-session-text ps payee))
|
||||
|
||||
(let ((number-pos (assq 'amount-number format)))
|
||||
(gnc:print-session-moveto ps
|
||||
(inches-to-points (cadr number-pos))
|
||||
(inches-to-points (caddr number-pos)))
|
||||
(gnc:print-session-text ps (printable-value amount 100)))
|
||||
|
||||
(let ((words-pos (assq 'amount-words format)))
|
||||
(gnc:print-session-moveto ps
|
||||
(inches-to-points (cadr words-pos))
|
||||
(inches-to-points (caddr words-pos)))
|
||||
(gnc:print-session-text ps (number-to-words amount 100)))
|
||||
|
||||
(gnc:print-session-done ps)
|
||||
(gnc:print-dialog-create ps)))
|
||||
Loading…
Reference in new issue