2015-09-29 14:08:48 -05:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; This program is free software; you can redistribute it and/or
|
|
|
|
;; modify it under the terms of the GNU General Public License as
|
|
|
|
;; published by the Free Software Foundation; either version 2 of
|
|
|
|
;; the License, or (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program; if not, contact:
|
|
|
|
;;
|
|
|
|
;; Free Software Foundation Voice: +1-617-542-5942
|
|
|
|
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
;; Boston, MA 02110-1301, USA gnu@gnu.org
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
(define-module (gnucash business-core))
|
2002-07-03 21:39:19 -05:00
|
|
|
(use-modules (gnucash gnc-module))
|
|
|
|
(gnc:module-load "gnucash/engine" 0)
|
2002-02-26 00:07:09 -06:00
|
|
|
|
|
|
|
(define (gnc:owner-get-address owner)
|
2006-10-15 14:02:05 -05:00
|
|
|
(let ((type (gncOwnerGetType owner)))
|
|
|
|
(cond
|
|
|
|
((eqv? type GNC-OWNER-CUSTOMER)
|
|
|
|
(let ((c (gncOwnerGetCustomer owner)))
|
|
|
|
(gncCustomerGetAddr c)))
|
|
|
|
((eqv? type GNC-OWNER-VENDOR)
|
|
|
|
(let ((v (gncOwnerGetVendor owner)))
|
|
|
|
(gncVendorGetAddr v)))
|
|
|
|
((eqv? type GNC-OWNER-EMPLOYEE)
|
|
|
|
(let ((e (gncOwnerGetEmployee owner)))
|
|
|
|
(gncEmployeeGetAddr e)))
|
|
|
|
((eqv? type GNC-OWNER-JOB)
|
2007-02-21 12:46:44 -06:00
|
|
|
(gnc:owner-get-address (gncJobGetOwner
|
2006-10-15 14:02:05 -05:00
|
|
|
(gncOwnerGetJob owner))))
|
|
|
|
(else '()))))
|
2002-05-08 15:42:38 -05:00
|
|
|
|
2006-02-12 10:16:20 -06:00
|
|
|
;
|
|
|
|
; The -dep functions return combined strings of the appropriate
|
|
|
|
; content. When multiple "lines" are included, separate them
|
|
|
|
; by newlines.
|
|
|
|
;
|
|
|
|
; e.g.: return a string which is basically:
|
|
|
|
; name \n Attn: contact \n addr1 \n addr2 \n addr3 \n addr4
|
|
|
|
;
|
|
|
|
; But only include the strings that really exist.
|
|
|
|
;
|
|
|
|
|
|
|
|
(define (gnc:owner-get-name-dep owner)
|
|
|
|
(define (just-name name)
|
|
|
|
(if name name ""))
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
(let ((type (gncOwnerGetType owner)))
|
|
|
|
(cond
|
|
|
|
((eqv? type GNC-OWNER-JOB)
|
2007-02-21 12:46:44 -06:00
|
|
|
(gnc:owner-get-name-dep (gncJobGetOwner
|
2006-10-15 14:02:05 -05:00
|
|
|
(gncOwnerGetJob owner))))
|
|
|
|
(else (just-name (gncOwnerGetName owner))))))
|
2006-02-12 10:16:20 -06:00
|
|
|
|
|
|
|
(define (gnc:owner-get-address-dep owner)
|
|
|
|
(define (add-if-exists lst new)
|
|
|
|
(if (and new (> (string-length new) 0))
|
|
|
|
(cons new lst)
|
|
|
|
lst))
|
|
|
|
(define (build-string lst)
|
|
|
|
(cond
|
|
|
|
((null? lst) "")
|
|
|
|
((null? (cdr lst)) (car lst))
|
|
|
|
(else (string-append (build-string (cdr lst)) "\n" (car lst)))))
|
|
|
|
(let ((lst '())
|
|
|
|
(addr (gnc:owner-get-address owner)))
|
2010-02-17 23:27:55 -06:00
|
|
|
; Added gncAddressGetName <mikee@saxicola.co.uk>
|
|
|
|
(set! lst (add-if-exists lst (gncAddressGetName addr)))
|
2006-10-15 14:02:05 -05:00
|
|
|
(set! lst (add-if-exists lst (gncAddressGetAddr1 addr)))
|
|
|
|
(set! lst (add-if-exists lst (gncAddressGetAddr2 addr)))
|
|
|
|
(set! lst (add-if-exists lst (gncAddressGetAddr3 addr)))
|
|
|
|
(set! lst (add-if-exists lst (gncAddressGetAddr4 addr)))
|
2006-02-12 10:16:20 -06:00
|
|
|
(build-string lst)))
|
|
|
|
|
|
|
|
(define (gnc:owner-get-name-and-address-dep owner)
|
|
|
|
(let ((name (gnc:owner-get-name-dep owner))
|
|
|
|
(addr (gnc:owner-get-address-dep owner)))
|
|
|
|
(if (> (string-length name) 0)
|
|
|
|
(string-append name "\n" addr)
|
|
|
|
addr)))
|
2002-02-26 00:07:09 -06:00
|
|
|
|
|
|
|
(define (gnc:owner-get-owner-id owner)
|
2006-10-15 14:02:05 -05:00
|
|
|
(let ((type (gncOwnerGetType owner)))
|
|
|
|
(cond
|
|
|
|
((eqv? type GNC-OWNER-CUSTOMER)
|
|
|
|
(let ((c (gncOwnerGetCustomer owner)))
|
|
|
|
(gncCustomerGetID c)))
|
|
|
|
((eqv? type GNC-OWNER-VENDOR)
|
|
|
|
(let ((v (gncOwnerGetVendor owner)))
|
|
|
|
(gncVendorGetID v)))
|
|
|
|
((eqv? type GNC-OWNER-EMPLOYEE)
|
|
|
|
(let ((e (gncOwnerGetEmployee owner)))
|
|
|
|
(gncEmployeeGetID e)))
|
|
|
|
((eqv? type GNC-OWNER-JOB)
|
|
|
|
(gnc:owner-get-owner-id (gncJobGetOwner (gncOwnerGetJob owner))))
|
2002-02-26 00:07:09 -06:00
|
|
|
(else ""))))
|
|
|
|
|
2002-07-03 21:39:19 -05:00
|
|
|
(define (gnc:entry-type-percent-p type-val)
|
2006-10-15 14:02:05 -05:00
|
|
|
(let ((type type-val))
|
|
|
|
(equal? type GNC-AMT-TYPE-PERCENT)))
|
2002-07-03 21:39:19 -05:00
|
|
|
|
|
|
|
(define (gnc:owner-from-split split result-owner)
|
2006-10-15 14:02:05 -05:00
|
|
|
(let* ((trans (xaccSplitGetParent split))
|
|
|
|
(invoice (gncInvoiceGetInvoiceFromTxn trans))
|
2011-05-11 16:51:17 -05:00
|
|
|
(temp-owner (gncOwnerNew))
|
2006-10-28 22:12:49 -05:00
|
|
|
(owner '()))
|
2002-07-03 21:39:19 -05:00
|
|
|
|
2006-10-28 22:12:49 -05:00
|
|
|
(if (not (null? invoice))
|
2006-10-15 14:02:05 -05:00
|
|
|
(set! owner (gncInvoiceGetOwner invoice))
|
2006-10-18 20:00:17 -05:00
|
|
|
(let ((split-list (xaccTransGetSplitList trans)))
|
2002-07-03 21:39:19 -05:00
|
|
|
(define (check-splits splits)
|
2003-01-07 17:31:35 -06:00
|
|
|
(if (and splits (not (null? splits)))
|
|
|
|
(let* ((split (car splits))
|
2006-10-15 14:02:05 -05:00
|
|
|
(lot (xaccSplitGetLot split)))
|
2006-10-28 22:12:49 -05:00
|
|
|
(if (not (null? lot))
|
2006-10-15 14:02:05 -05:00
|
|
|
(let* ((invoice (gncInvoiceGetInvoiceFromLot lot))
|
2007-03-26 16:28:48 -05:00
|
|
|
(owner? (gncOwnerGetOwnerFromLot
|
2003-01-07 17:31:35 -06:00
|
|
|
lot temp-owner)))
|
2006-10-28 22:12:49 -05:00
|
|
|
(if (not (null? invoice))
|
2006-10-15 14:02:05 -05:00
|
|
|
(set! owner (gncInvoiceGetOwner invoice))
|
2003-01-07 17:31:35 -06:00
|
|
|
(if owner?
|
|
|
|
(set! owner temp-owner)
|
|
|
|
(check-splits (cdr splits)))))
|
|
|
|
(check-splits (cdr splits))))))
|
2002-07-03 21:39:19 -05:00
|
|
|
(check-splits split-list)))
|
|
|
|
|
2006-10-28 22:12:49 -05:00
|
|
|
(if (not (null? owner))
|
2003-01-07 17:31:35 -06:00
|
|
|
(begin
|
2006-10-15 14:02:05 -05:00
|
|
|
(gncOwnerCopy (gncOwnerGetEndOwner owner) result-owner)
|
2011-05-11 16:51:17 -05:00
|
|
|
(gncOwnerFree temp-owner)
|
2003-01-07 17:31:35 -06:00
|
|
|
result-owner)
|
|
|
|
(begin
|
2011-05-11 16:51:17 -05:00
|
|
|
(gncOwnerFree temp-owner)
|
2006-10-28 22:12:49 -05:00
|
|
|
'()))))
|
2002-07-03 21:39:19 -05:00
|
|
|
|
2002-02-26 17:42:11 -06:00
|
|
|
|
2002-02-26 00:07:09 -06:00
|
|
|
(export gnc:owner-get-address)
|
2006-02-12 10:16:20 -06:00
|
|
|
(export gnc:owner-get-name-dep)
|
|
|
|
(export gnc:owner-get-address-dep)
|
2006-02-12 09:28:58 -06:00
|
|
|
(export gnc:owner-get-name-and-address-dep)
|
2002-02-26 00:07:09 -06:00
|
|
|
(export gnc:owner-get-owner-id)
|
2002-02-26 17:42:11 -06:00
|
|
|
(export gnc:entry-type-percent-p)
|
2002-07-03 21:39:19 -05:00
|
|
|
(export gnc:owner-from-split)
|