# Report for <?scm (gtt-show (gtt-project-title (gtt-linked-project))) ?>

number (gtt-kvp-str "start_day"))) (define one-day (time-difference (make-time time-utc 0 86400) (make-time time-utc 0 0))) (define report-end (time-second (add-duration (make-time time-utc 0 report-start) one-day))) ) (if (equal? (gtt-kvp-str "interval") "monthly") (begin (define report-start (time-second (date->time-utc (string->date (string-append "01 " (gtt-kvp-str "start_month")) "~d ~b ~Y")))) (define report-start-date (time-utc->date (make-time time-utc 0 report-start))) (define str-next-month (string-append "01 " (number->string (+ (date-month report-start-date) 1)) " " (number->string (date-year report-start-date)))) (define report-end (time-second (date->time-utc (string->date str-next-month "~d ~m ~Y")))) ) (if (equal? (gtt-kvp-str "interval") "custom") (begin (define report-start (catch #t (lambda () (time-second (date->time-utc (string->date (gtt-kvp-str "start-date") "~d ~b ~Y")))) (lambda (key . args) 0) )) (define report-end (catch #t (lambda () (time-second (date->time-utc (string->date (gtt-kvp-str "end-date") "~d ~b ~Y")))) (lambda (key . args) 0) )) ))) ) (define total-reported-time 0) ?>
\n") (string-tail str (+ noff 1)) ) ) ) ) (tail-escape-newline "" str) ) (define (seconds->human-readable sec type) (let ( (days (quotient sec 28800)) (hours-remain (quotient (remainder sec 28800) 3600)) (hours-total (quotient sec 3600)) (minutes (quotient (remainder sec 3600) 60)) ) (if (equal? type "day") (string-append (number->string days) "d " (number->string hours-remain) "h " (number->string minutes) "m: ") (string-append (number->string hours-total) "h " (number->string minutes) "m: ") ) ) ) (define (task-reported-time task) (let ( (intervals (filter (lambda (interval) (and (> (gtt-interval-start interval) report-start) (< (gtt-interval-start interval) report-end))) (gtt-intervals task))) ) (apply + (map - (gtt-interval-stop intervals) (gtt-interval-start intervals) ) ) ) ) (define (project-reported-time project) (let ( (current-project-time (apply + (map (lambda (task) (task-reported-time task) ) (gtt-tasks project) ) ) ) ) (begin (set! total-reported-time (+ total-reported-time current-project-time)) current-project-time ) ) ) ; show only tasks with at least 5 minutes of logged time! (define (reported-tasks project) (filter (lambda (task) (> (task-reported-time task) 300)) (gtt-tasks project)) ) ; Returns rows consisting of project's task-notes to be reported (define (show-reported-tasks project) (map (lambda (task) (if (not (or (equal? (gtt-task-notes task) "") (equal? (gtt-task-notes task) "\n") )) (gtt-show (string-append "
\n" "" (gtt-task-memo task) "
\n" (my-html-escape-newline (gtt-task-notes task)) "\n
\n" )) ) ) (reported-tasks project) )) (define (show-reported-projects prjs prefix) (if (null? prjs) '() (map (lambda (proj) (list ; Show only those tasks that racked up 5+ minutes of time... (if (not (null? (reported-tasks proj))) (list (gtt-show (string-append "\n
\n" "" (if (equal? (gtt-kvp-str "show-sum-time") "yes") (if (equal? (gtt-kvp-str "interval") "daily") (seconds->human-readable (project-reported-time proj) "min") (seconds->human-readable (project-reported-time proj) "day") ) " ") " " prefix "/" (gtt-project-title proj) " - " (gtt-project-desc proj) "\n" "

\n" ) ) (show-reported-tasks proj) (gtt-show "

\n") (gtt-show "
\n") ) ) (show-reported-projects (gtt-project-subprojects proj) (string-append prefix "/" (gtt-project-title proj))) ) ) prjs ) ) ) ?>

## string (time-utc->date (make-time time-utc 0 report-start)) "~d ~b ~Y (~A)") ) (if (equal? (gtt-kvp-str "interval") "monthly") (string-append "Monthly report for " (date->string (time-utc->date (make-time time-utc 0 report-start)) "~b ~Y") ) (if (equal? (gtt-kvp-str "interval") "custom") (string-append "Report for " (date->string (time-utc->date (make-time time-utc 0 report-start)) "~d ~b ~Y") " - " (date->string (time-utc->date (make-time time-utc 0 report-end)) "~d ~b ~Y") ) ))) ) ?>

\n" ) ) (if (= report-end 0) (gtt-show (string-append "
\n" "ERROR: You have entered an invalid format for the start date: " (gtt-kvp-str "start-date") ". \n" "Please use format like \"5 Jul 2006\".\n" "
\n" "ERROR: You have entered an invalid format for the end date:" (gtt-kvp-str "end-date") ". \n" "Please use format like \"5 Jul 2006\".\n" "
\n" ) ) ; No, don't show *all* projects; just the selected project and its children ... ; (show-reported-projects (gtt-projects) "") (show-reported-projects (list (gtt-linked-project)) "") )) ?> (if (equal? (gtt-kvp-str "show-sum-time") "yes") (begin (gtt-show "

### ") (gtt-show (seconds->human-readable total-reported-time "day")) (gtt-show "TOTAL

* 1 day is equal to 8 hours
") ) ) ?>