From: tfheen Date: Tue, 5 Jun 2012 15:27:22 +0000 (+0000) Subject: Add initial invoice rounding function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c779297074065f6b03284135fa83591333fa069;p=dotfiles Add initial invoice rounding function git-svn-id: file:///svn/tfheen/trunk/dotfiles@1545 8da78d58-1cd3-0310-bee5-d77bd1b3e8bf --- diff --git a/emacs b/emacs index b664939..e2ad908 100644 --- a/emacs +++ b/emacs @@ -456,6 +456,53 @@ (format " %f %f\n" hours sum)))) (setq tbl (cdr tbl))))) +(defun org-dblock-write:invoicerounding (params) + "Grab hours in a format suitable for an invoice, rounding all times to a full hour" + (let* ((ts (plist-get params :tstart)) + (te (plist-get params :tend)) + (ins (make-marker)) + (start (time-to-seconds + (apply 'encode-time (org-parse-time-string ts)))) + (end (time-to-seconds + (apply 'encode-time (org-parse-time-string te)))) + tbl sum) + + (setq params (plist-put params :tstart nil)) + (setq params (plist-put params :end nil)) + (move-marker ins (point)) + (while (<= start end) + (save-excursion + (let ((sum 0)) + (org-clock-sum start (+ start 86400)) + (goto-char (point-min)) + (setq st t) + (while (or (and (bobp) (prog1 st (setq st nil)) + (get-text-property (point) :org-clock-minutes) + (setq p (point-min))) + (setq p (next-single-property-change (point) :org-clock-minutes))) + (goto-char p) + (message (format "pre: %s %d %d %s" (format-time-string "%Y-%m-%d" (seconds-to-time start)) sum start (point))) + (if (= 1 (car (org-heading-components))) + (setq sum (+ sum (or (get-text-property p :org-clock-minutes) 0))))) + (push (list start sum) tbl))) + (setq start (+ 86400 start))) + (setq tbl (nreverse tbl)) + (goto-char ins) + (setq sum 0) + (while tbl + (let* ((line (car tbl)) + (ts (seconds-to-time (first line))) + (minutes (second line)) + (hours (minutes-to-hours minutes))) + (setq sum (+ sum hours)) + (if (not (weekend-p ts)) + (setq sum (- sum 7.5))) + (if (> minutes 0) + (insert-before-markers + (format-time-string "%Y-%m-%d" ts) + (format " %f %f\n" hours sum)))) + (setq tbl (cdr tbl))))) + (defun org-dblock-write:gtimelog (params) "Display day-by-day time reports in gtimelog format." (let* ((ts (plist-get params :tstart))