mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bill Gribble's qif patch.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2459 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
7cb10bab16
commit
93c3b8e226
@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
(define (default-equity-account) "Retained Earnings")
|
(define (default-equity-account) "Retained Earnings")
|
||||||
|
|
||||||
|
(define (default-commission-acct brokerage)
|
||||||
|
(string-append "Commissions:" brokerage))
|
||||||
|
|
||||||
|
|
||||||
;; the account-display is a 3-columned list of accounts in the QIF
|
;; the account-display is a 3-columned list of accounts in the QIF
|
||||||
;; import dialog (the "Account" page of the notebook). Column 1 is
|
;; import dialog (the "Account" page of the notebook). Column 1 is
|
||||||
;; the account name in the QIF file, column 2 is the number of QIF
|
;; the account name in the QIF file, column 2 is the number of QIF
|
||||||
@ -203,6 +207,25 @@
|
|||||||
(append (qif-import:guess-acct
|
(append (qif-import:guess-acct
|
||||||
qif-account qif-account-types
|
qif-account qif-account-types
|
||||||
gnc-acct-info)
|
gnc-acct-info)
|
||||||
|
(list 1 xtn))))))
|
||||||
|
|
||||||
|
;; if there's a commission, reference the
|
||||||
|
;; commission account
|
||||||
|
(if (qif-xtn:commission xtn)
|
||||||
|
(begin
|
||||||
|
(set! qif-account
|
||||||
|
(default-commission-acct from-acct))
|
||||||
|
(set! entry
|
||||||
|
(hash-ref acct-hash qif-account))
|
||||||
|
(if entry
|
||||||
|
(list-set! entry 4
|
||||||
|
(+ 1 (list-ref entry 4)))
|
||||||
|
(hash-set! acct-hash
|
||||||
|
qif-account
|
||||||
|
(append (qif-import:guess-acct
|
||||||
|
qif-account
|
||||||
|
(list GNC-EXPENSE-TYPE)
|
||||||
|
gnc-acct-info)
|
||||||
(list 1 xtn)))))))
|
(list 1 xtn)))))))
|
||||||
|
|
||||||
;; non-stock transactions. these are a bit easier.
|
;; non-stock transactions. these are a bit easier.
|
||||||
|
@ -401,12 +401,14 @@
|
|||||||
qif-cat:tax-class qif-cat:set-tax-class!
|
qif-cat:tax-class qif-cat:set-tax-class!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:cats self)
|
qif-parse:parse-number/format (qif-file:cats self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(check-and-parse-field
|
(check-and-parse-field
|
||||||
qif-cat:budget-amt qif-cat:set-budget-amt!
|
qif-cat:budget-amt qif-cat:set-budget-amt!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:cats self)
|
qif-parse:parse-number/format (qif-file:cats self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
;; fields of accounts
|
;; fields of accounts
|
||||||
@ -414,12 +416,14 @@
|
|||||||
qif-acct:limit qif-acct:set-limit!
|
qif-acct:limit qif-acct:set-limit!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:accounts self)
|
qif-parse:parse-number/format (qif-file:accounts self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(check-and-parse-field
|
(check-and-parse-field
|
||||||
qif-acct:budget qif-acct:set-budget!
|
qif-acct:budget qif-acct:set-budget!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:accounts self)
|
qif-parse:parse-number/format (qif-file:accounts self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(parse-field
|
(parse-field
|
||||||
@ -433,6 +437,7 @@
|
|||||||
qif-parse:check-date-format '(m-d-y d-m-y y-m-d y-d-m)
|
qif-parse:check-date-format '(m-d-y d-m-y y-m-d y-d-m)
|
||||||
qif-parse:parse-date/format
|
qif-parse:parse-date/format
|
||||||
(qif-file:xtns self)
|
(qif-file:xtns self)
|
||||||
|
qif-parse:print-date
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(parse-field
|
(parse-field
|
||||||
@ -447,18 +452,21 @@
|
|||||||
qif-xtn:share-price qif-xtn:set-share-price!
|
qif-xtn:share-price qif-xtn:set-share-price!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:xtns self)
|
qif-parse:parse-number/format (qif-file:xtns self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(check-and-parse-field
|
(check-and-parse-field
|
||||||
qif-xtn:num-shares qif-xtn:set-num-shares!
|
qif-xtn:num-shares qif-xtn:set-num-shares!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:xtns self)
|
qif-parse:parse-number/format (qif-file:xtns self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(check-and-parse-field
|
(check-and-parse-field
|
||||||
qif-xtn:commission qif-xtn:set-commission!
|
qif-xtn:commission qif-xtn:set-commission!
|
||||||
qif-parse:check-number-format '(decimal comma)
|
qif-parse:check-number-format '(decimal comma)
|
||||||
qif-parse:parse-number/format (qif-file:xtns self)
|
qif-parse:parse-number/format (qif-file:xtns self)
|
||||||
|
qif-parse:print-number
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
;; this one's a little tricky... it checks and sets all the
|
;; this one's a little tricky... it checks and sets all the
|
||||||
@ -467,6 +475,7 @@
|
|||||||
qif-xtn:split-amounts qif-xtn:set-split-amounts!
|
qif-xtn:split-amounts qif-xtn:set-split-amounts!
|
||||||
qif-parse:check-number-formats '(decimal comma)
|
qif-parse:check-number-formats '(decimal comma)
|
||||||
qif-parse:parse-numbers/format (qif-file:xtns self)
|
qif-parse:parse-numbers/format (qif-file:xtns self)
|
||||||
|
qif-parse:print-numbers
|
||||||
set-error)
|
set-error)
|
||||||
|
|
||||||
(begin
|
(begin
|
||||||
@ -508,7 +517,7 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(define (check-and-parse-field getter setter checker
|
(define (check-and-parse-field getter setter checker
|
||||||
formats parser objects errormsg)
|
formats parser objects printer errormsg)
|
||||||
;; first find the right format for the field
|
;; first find the right format for the field
|
||||||
(let ((do-parsing #f)
|
(let ((do-parsing #f)
|
||||||
(retval #t)
|
(retval #t)
|
||||||
@ -544,7 +553,8 @@
|
|||||||
;; just ignore the format ambiguity. Otherwise, it's really an
|
;; just ignore the format ambiguity. Otherwise, it's really an
|
||||||
;; error. ATM since there's no way to correct the error let's
|
;; error. ATM since there's no way to correct the error let's
|
||||||
;; just leave it be.
|
;; just leave it be.
|
||||||
(all-formats-equivalent? getter parser formats objects errormsg)
|
(all-formats-equivalent? getter parser formats objects printer
|
||||||
|
errormsg)
|
||||||
(set! format (car formats)))
|
(set! format (car formats)))
|
||||||
(#t
|
(#t
|
||||||
(set! format (car formats))))
|
(set! format (car formats))))
|
||||||
@ -569,7 +579,8 @@
|
|||||||
objects))
|
objects))
|
||||||
retval))
|
retval))
|
||||||
|
|
||||||
(define (all-formats-equivalent? getter parser formats objects errormsg)
|
(define (all-formats-equivalent? getter parser formats objects
|
||||||
|
printer errormsg)
|
||||||
(let ((all-ok #t))
|
(let ((all-ok #t))
|
||||||
(let obj-loop ((objlist objects))
|
(let obj-loop ((objlist objects))
|
||||||
(let* ((unparsed (getter (car objlist)))
|
(let* ((unparsed (getter (car objlist)))
|
||||||
@ -586,9 +597,10 @@
|
|||||||
(errormsg
|
(errormsg
|
||||||
(list "Parse ambiguity : between formats "
|
(list "Parse ambiguity : between formats "
|
||||||
formats "\nValue " unparsed " could be "
|
formats "\nValue " unparsed " could be "
|
||||||
parsed " or " this-parsed
|
(printer parsed) " or "
|
||||||
|
(printer this-parsed)
|
||||||
"\nand no evidence exists to distinguish."
|
"\nand no evidence exists to distinguish."
|
||||||
"\nUsing " parsed ". "
|
"\nUsing " (printer parsed) ". "
|
||||||
"\nSee help for more info."))))))
|
"\nSee help for more info."))))))
|
||||||
(cdr formats))))
|
(cdr formats))))
|
||||||
(if (and all-ok (not (null? (cdr objlist))))
|
(if (and all-ok (not (null? (cdr objlist))))
|
||||||
|
@ -504,3 +504,22 @@
|
|||||||
amt-strings)))
|
amt-strings)))
|
||||||
(if all-ok parsed #f)))
|
(if all-ok parsed #f)))
|
||||||
|
|
||||||
|
(define (qif-parse:print-date date-list)
|
||||||
|
(let ((tm (localtime (current-time))))
|
||||||
|
(set-tm:mday tm (car date-list))
|
||||||
|
(set-tm:mon tm (- (cadr date-list) 1))
|
||||||
|
(set-tm:year tm (- (caddr date-list) 1900))
|
||||||
|
(strftime "%a %B %d %Y" tm)))
|
||||||
|
|
||||||
|
(define (qif-parse:print-number num)
|
||||||
|
(with-output-to-string
|
||||||
|
(lambda ()
|
||||||
|
(write num))))
|
||||||
|
|
||||||
|
(define (qif-parse:print-numbers num)
|
||||||
|
(with-output-to-string
|
||||||
|
(lambda ()
|
||||||
|
(write num))))
|
||||||
|
|
||||||
|
(define (qif-parse:print-acct-type t)
|
||||||
|
(symbol->string (gnc:account-type->symbol t)))
|
@ -128,40 +128,6 @@
|
|||||||
(gnc:insert-subaccount parent-acct new-acct)
|
(gnc:insert-subaccount parent-acct new-acct)
|
||||||
(gnc:group-insert-account acct-group new-acct))
|
(gnc:group-insert-account acct-group new-acct))
|
||||||
|
|
||||||
|
|
||||||
; (begin
|
|
||||||
; (if make-new-acct
|
|
||||||
; (begin
|
|
||||||
; (gnc:account-set-name new-acct gnc-name)
|
|
||||||
; (if (and gnc-type
|
|
||||||
; (eq? GNC-EQUITY-TYPE gnc-type)
|
|
||||||
; (qif-xtn? qif-info)
|
|
||||||
; (qif-xtn:qif-security-name qif-info))
|
|
||||||
; ;; this is the special case of the
|
|
||||||
; ;; "retained holdings" equity account
|
|
||||||
; (begin
|
|
||||||
; (gnc:account-set-currency
|
|
||||||
; new-acct (qif-xtn:security-name qif-info))
|
|
||||||
; (set! set-security #f))
|
|
||||||
; (begin
|
|
||||||
; (gnc:account-set-currency new-acct
|
|
||||||
; default-currency)
|
|
||||||
; (set! set-security #t)))
|
|
||||||
|
|
||||||
; (cond ((and (qif-acct? qif-info)
|
|
||||||
; (qif-acct:description qif-info))
|
|
||||||
; (gnc:account-set-description
|
|
||||||
; new-acct (qif-acct:description qif-info)))
|
|
||||||
; ((and (qif-cat? qif-info)
|
|
||||||
; (qif-cat:description qif-info))
|
|
||||||
; (gnc:account-set-description
|
|
||||||
; new-acct (qif-cat:description qif-info)))
|
|
||||||
; ((string? qif-info)
|
|
||||||
; (gnc:account-set-description
|
|
||||||
; new-acct qif-info)))
|
|
||||||
; (if gnc-type (gnc:account-set-type new-acct gnc-type))))
|
|
||||||
|
|
||||||
; (gnc:account-commit-edit new-acct)
|
|
||||||
(hash-set! gnc-acct-hash gnc-name new-acct)
|
(hash-set! gnc-acct-hash gnc-name new-acct)
|
||||||
new-acct))))
|
new-acct))))
|
||||||
|
|
||||||
@ -418,9 +384,13 @@
|
|||||||
(qif-accts #f)
|
(qif-accts #f)
|
||||||
(qif-near-acct #f)
|
(qif-near-acct #f)
|
||||||
(qif-far-acct #f)
|
(qif-far-acct #f)
|
||||||
|
(qif-commission-acct #f)
|
||||||
(far-acct-info #f)
|
(far-acct-info #f)
|
||||||
(far-acct-name #f)
|
(far-acct-name #f)
|
||||||
(far-acct #f)
|
(far-acct #f)
|
||||||
|
(commission-acct #f)
|
||||||
|
(commission-amt (qif-xtn:commission qif-xtn))
|
||||||
|
(commission-split #f)
|
||||||
(defer-share-price #f)
|
(defer-share-price #f)
|
||||||
(gnc-far-split (gnc:split-create)))
|
(gnc-far-split (gnc:split-create)))
|
||||||
|
|
||||||
@ -435,12 +405,13 @@
|
|||||||
(display "splits in stock transaction!") (newline)))
|
(display "splits in stock transaction!") (newline)))
|
||||||
|
|
||||||
(set! qif-accts
|
(set! qif-accts
|
||||||
(qif-split:accounts-affected (qif-xtn:splits qif-xtn)
|
(qif-split:accounts-affected (car (qif-xtn:splits qif-xtn))
|
||||||
qif-xtn))
|
qif-xtn))
|
||||||
|
|
||||||
(set! qif-near-acct (car qif-accts))
|
(set! qif-near-acct (car qif-accts))
|
||||||
(set! qif-far-acct (cadr qif-accts))
|
(set! qif-far-acct (cadr qif-accts))
|
||||||
|
(set! qif-commission-acct (caddr qif-accts))
|
||||||
|
|
||||||
;; translate the QIF account names into Gnucash accounts
|
;; translate the QIF account names into Gnucash accounts
|
||||||
(if (and qif-near-acct qif-far-acct)
|
(if (and qif-near-acct qif-far-acct)
|
||||||
(begin
|
(begin
|
||||||
@ -526,6 +497,21 @@
|
|||||||
(if (or (eq? 'cleared cleared)
|
(if (or (eq? 'cleared cleared)
|
||||||
(eq? 'reconciled cleared))
|
(eq? 'reconciled cleared))
|
||||||
(gnc:split-set-reconcile gnc-far-split #\c)))
|
(gnc:split-set-reconcile gnc-far-split #\c)))
|
||||||
|
|
||||||
|
(if qif-commission-acct
|
||||||
|
(let* ((commission-acct-info
|
||||||
|
(or (hash-ref qif-acct-map qif-commission-acct)
|
||||||
|
(hash-ref qif-cat-map qif-commission-acct)))
|
||||||
|
(commission-acct-name
|
||||||
|
(list-ref commission-acct-info 1)))
|
||||||
|
(set! commission-acct
|
||||||
|
(hash-ref gnc-acct-hash commission-acct-name))))
|
||||||
|
|
||||||
|
(if (and commission-amt commission-acct)
|
||||||
|
(begin
|
||||||
|
(set! commission-split (gnc:split-create))
|
||||||
|
(gnc:split-set-base-value commission-split commission-amt
|
||||||
|
currency)))
|
||||||
|
|
||||||
(if (and qif-near-acct qif-far-acct)
|
(if (and qif-near-acct qif-far-acct)
|
||||||
(begin
|
(begin
|
||||||
@ -535,6 +521,12 @@
|
|||||||
(gnc:transaction-append-split gnc-xtn gnc-far-split)
|
(gnc:transaction-append-split gnc-xtn gnc-far-split)
|
||||||
(gnc:account-insert-split far-acct gnc-far-split)
|
(gnc:account-insert-split far-acct gnc-far-split)
|
||||||
|
|
||||||
|
(if commission-split
|
||||||
|
(begin
|
||||||
|
(gnc:transaction-append-split gnc-xtn commission-split)
|
||||||
|
(gnc:account-insert-split commission-acct
|
||||||
|
commission-split)))
|
||||||
|
|
||||||
;; now find the share price if we need to
|
;; now find the share price if we need to
|
||||||
;; (shrsin and shrsout xtns)
|
;; (shrsin and shrsout xtns)
|
||||||
(if defer-share-price
|
(if defer-share-price
|
||||||
@ -542,6 +534,7 @@
|
|||||||
;; return the modified transaction (though it's ignored).
|
;; return the modified transaction (though it's ignored).
|
||||||
gnc-xtn))
|
gnc-xtn))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; qif-import:mark-matching-xtns
|
;; qif-import:mark-matching-xtns
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -677,6 +670,7 @@
|
|||||||
(define (qif-split:accounts-affected split xtn)
|
(define (qif-split:accounts-affected split xtn)
|
||||||
(let ((near-acct-name #f)
|
(let ((near-acct-name #f)
|
||||||
(far-acct-name #f)
|
(far-acct-name #f)
|
||||||
|
(commission-acct-name #f)
|
||||||
(security (qif-xtn:security-name xtn))
|
(security (qif-xtn:security-name xtn))
|
||||||
(action (qif-xtn:action xtn))
|
(action (qif-xtn:action xtn))
|
||||||
(from-acct (qif-xtn:from-acct xtn)))
|
(from-acct (qif-xtn:from-acct xtn)))
|
||||||
@ -729,9 +723,14 @@
|
|||||||
(default-dividend-acct from-acct security)))
|
(default-dividend-acct from-acct security)))
|
||||||
((shrsin shrsout)
|
((shrsin shrsout)
|
||||||
(set! far-acct-name
|
(set! far-acct-name
|
||||||
(default-equity-holding security))))))
|
(default-equity-holding security))))
|
||||||
|
|
||||||
|
;; the commission account, if it exists
|
||||||
|
(if (qif-xtn:commission xtn)
|
||||||
|
(set! commission-acct-name
|
||||||
|
(default-commission-acct from-acct)))))
|
||||||
|
|
||||||
(list near-acct-name far-acct-name)))
|
(list near-acct-name far-acct-name commission-acct-name)))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -782,10 +781,7 @@
|
|||||||
(qif-split:set-category-is-account?!
|
(qif-split:set-category-is-account?!
|
||||||
split (qif-split:category-is-account? other-split))
|
split (qif-split:category-is-account? other-split))
|
||||||
(qif-split:set-category-private!
|
(qif-split:set-category-private!
|
||||||
split (qif-split:category other-split)))))))
|
split (qif-split:category other-split))))))))
|
||||||
;; merge split fields
|
|
||||||
(write xtn) (newline)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
Loading…
Reference in New Issue
Block a user