* src/app-utils/hooks.scm -- create a new 'post-ui-startup' hook

* src/app-utils/app-utils.scm -- export the 'post-ui-startup' hook
	* src/scm/main.scm -- run the post-ui-startup hook after the UI
	  is up but before we run the ui-event-loop
	* src/business/business-utils/business-prefs.scm -- create two
	  new global preferences: "Notify Bills Due?" and "Bills Due Days"
	* src/business/business-gnome/business-gnome.scm -- create a dialog
	  are runtime (and via a new menu item) that displays all the bills
	  that are due withing "Bills Due Days" days from now.  It's ugly,
	  but it's functional.  Fixes #102439.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7856 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2003-01-20 04:18:39 +00:00
parent be187cdecb
commit d953f96d13
6 changed files with 150 additions and 0 deletions

View File

@@ -26,6 +26,17 @@
* src/gnome-utils/gnc-gui-query.c -- fix gnc_info_dialog() to deal
properly in the case that it's called before the UI is up.
* src/app-utils/hooks.scm -- create a new 'post-ui-startup' hook
* src/app-utils/app-utils.scm -- export the 'post-ui-startup' hook
* src/scm/main.scm -- run the post-ui-startup hook after the UI
is up but before we run the ui-event-loop
* src/business/business-utils/business-prefs.scm -- create two
new global preferences: "Notify Bills Due?" and "Bills Due Days"
* src/business/business-gnome/business-gnome.scm -- create a dialog
are runtime (and via a new menu item) that displays all the bills
that are due withing "Bills Due Days" days from now. It's ugly,
but it's functional. Fixes #102439.
2003-01-18 Derek Atkins <derek@ihtfp.com>

View File

@@ -235,6 +235,7 @@
(export gnc:*startup-hook*)
(export gnc:*shutdown-hook*)
(export gnc:*ui-startup-hook*)
(export gnc:*ui-post-startup-hook*)
(export gnc:*ui-shutdown-hook*)
(export gnc:*book-opened-hook*)
(export gnc:*new-book-hook*)

View File

@@ -88,6 +88,11 @@
'ui-startup-hook
"Functions to run when the ui comes up. Hook args: ()"))
(define gnc:*ui-post-startup-hook*
(gnc:hook-define
'ui-post-startup-hook
"Functions to run after the ui comes up. Hook args: ()"))
(define gnc:*ui-shutdown-hook*
(gnc:hook-define
'ui-shutdown-hook

View File

@@ -19,6 +19,104 @@
(define new-label (N_ "New"))
(define find-label (N_ "Find"))
(define ui-started #f)
(define (remind-bills-due session)
(define (option-value name)
(gnc:option-value (gnc:lookup-global-option gnc:*business-label* name)))
(define (get-payables book)
(let* ((group (gnc:book-get-group book))
(acct-list (gnc:group-get-subaccounts group))
(accts '()))
(for-each
(lambda (acct)
(let ((account-type (gw:enum-<gnc:AccountType>-val->sym
(gnc:account-get-type acct) #f)))
(if (eq? account-type 'payable)
(set! accts (cons acct accts)))))
acct-list)
accts))
(define (make-query book accts)
(let ((q (gnc:malloc-query)))
(gnc:query-add-account-match q accts 'guid-match-any 'query-and)
(gnc:query-set-book q book)
q))
(define (get-open-lots query)
(let ((all-lots (gnc:query-get-lots query 'query-txn-match-any))
(open-lots '()))
(for-each
(lambda (lot)
(if (not (gnc:lot-closed? lot))
(set! open-lots (cons lot open-lots))))
all-lots)
open-lots))
(define (compute-date today days)
(if (= days 0)
today
(compute-date (incdate today DayDelta) (1- days))))
(let ((check-bills? (option-value "Notify Bills Due?")))
(if (and ui-started session check-bills?)
(let* ((book (gnc:session-get-book session))
(payables-accounts (get-payables book))
(query (make-query book payables-accounts))
(open-lots (get-open-lots query))
(days (option-value "Bills Due Days"))
(compare-date (compute-date (gnc:get-today) days))
(bills '()))
;; free up the space we don't need right now...
(gnc:free-query query)
;; compute the bills that are soon to be (or over-) due
(for-each
(lambda (lot)
(let* ((invoice (gnc:invoice-get-invoice-from-lot lot))
(due-date (gnc:invoice-get-date-due invoice)))
;; true if compare-date is later than due-date
(if (and invoice (gnc:timepair-later due-date compare-date))
(set! bills (cons invoice bills)))))
open-lots)
;; If we've got bills, then compute the message to display
(if (not (null? bills))
(let ((message
(string-append
(if (> (length bills) 1)
(_ "The following bills are due:")
(_ "The following bill is due:"))
"\n\n"
(_ "Due Date") " "
(_ "Company") " "
(_ "Amount") "\n")))
(for-each
(lambda (bill)
(let* ((due-date (gnc:invoice-get-date-due bill))
(owner (gnc:invoice-get-owner bill))
(lot (gnc:invoice-get-posted-lot bill))
(print-info (gnc:default-print-info #t)))
(set! message
(string-append
message
(gnc:print-date due-date)
" "
(gnc:owner-get-name owner)
" "
(gnc:amount->string
(gnc:numeric-abs (gnc:lot-get-balance lot))
print-info)
"\n"))))
bills)
(gnc:info-dialog message)))))))
(define (add-customer-items)
(let ((last-cust (gnc:owner-create))
(cust (N_ "Customers")))
@@ -184,6 +282,13 @@
;;(gnc:add-extension find)
;;(gnc:add-extension new)
(gnc:add-extension
(gnc:make-menu-item (N_ "Bills Due Reminder")
(N_ "View the quick report of bills coming due soon.")
(list main-window top-level "")
(lambda ()
(remind-bills-due (gnc:get-current-session)))))
(gnc:add-extension
(gnc:make-menu-item (N_ "Billing Terms")
(N_ "View and Edit the available Billing Terms")
@@ -382,6 +487,15 @@
(add-employee-extensions)
)
(define (business-book-opened session)
(remind-bills-due session))
(define (business-ui-started)
(set! ui-started #t)
(remind-bills-due (gnc:get-current-session)))
(gnc:hook-add-dangler gnc:*report-hook* business-report-function)
(gnc:hook-add-dangler gnc:*ui-startup-hook* add-business-items)
(gnc:hook-add-dangler gnc:*ui-post-startup-hook* business-ui-started)
;(gnc:hook-add-dangler gnc:*book-opened-hook* business-book-opened)
(gnc:hook-add-dangler gnc:*add-extension-hook* add-business-test)

View File

@@ -54,6 +54,24 @@
"This setting is inherited by new customers and vendors"))
#f))
(gnc:register-configuration-option
(gnc:make-simple-boolean-option
gnc:*business-label* (N_ "Notify Bills Due?")
"g" (N_ "Whether to display the list of Bills Due at startup.")
#t))
(gnc:register-configuration-option
(gnc:make-number-range-option
gnc:*business-label* (N_ "Bills Due Days")
"h" (N_ "How many days in the future to warn about Bills coming due.")
7.0 ;; default
1.0 ;; lower bound
180.0 ;; upper bound
0.0 ;; number of decimals
1.0 ;; step size
))
(define (book-options-generator options)
(define (reg-option new-option)
(gnc:register-option options new-option))

View File

@@ -623,6 +623,7 @@ string and 'directories' must be a list of strings."
(begin
(gnc:load-account-file)
(gnc:destroy-splash-screen)))
(gnc:hook-run-danglers gnc:*ui-post-startup-hook*)
(gnc:start-ui-event-loop)
(gnc:hook-remove-dangler gnc:*ui-shutdown-hook* gnc:gui-finish))