#  n3
#
#  Categorized stuff by date for a sungle account, "1"!os:argv
#
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix s: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix os: <http://www.w3.org/2000/10/swap/os#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix q:  <http://www.w3.org/2000/10/swap/pim/qif#>.
@prefix acc: <accounts.n3#> .   # for URIs Generated by qif2qu.n3

@prefix os: <http://www.w3.org/2000/10/swap/os#>.
@prefix tax:  <http://www.w3.org/2000/10/swap/pim/tax.n3#>.

#
@prefix : <#>.
@prefix foo: <#>.

@forAll :a, :c, :d, :k, :l, :m, :n, :p, :s, :t, :x, :y, :z.


# {?x log:uri "1"!os:argv!os:baseAbsolute} => {?x a :target}.

# Select subclasses of TaxCategories.
#  Must be at least one entry, and must have a label

{ [] a :c. :c a q:Cat; s:label [] } log:implies { :c a :toBeDisplayed }.
 
#q:Unclassified a :toBeDisplayed; s:label "Unclassified transactions".
q:UnclassifiedIncome a :toBeDisplayed; s:label "Unclassified Income".
q:UnclassifiedOutgoing a :toBeDisplayed; s:label "Unclassified Outgoings".


{  "1" os:argv :a.
   ( """<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>""" :a """ account by date</title>
  <link type="text/css" rel="stylesheet" href="report.css" />
</head>

<body>
<h1>""" :a """ account by date</h1>
""" 
    ) string:concatenation :s.

}=>{ "00" log:outputString :s }.



"01" :monthName "January".
"02" :monthName "February".
"03" :monthName "March".
"04" :monthName "April".
"05" :monthName "May".
"06" :monthName "June".
"07" :monthName "July".
"08" :monthName "August".
"09" :monthName "September".
"10" :monthName "October".
"11" :monthName "November".
"12" :monthName "December".

{  :m :monthName :n.
    ( "2002-" :m "-00" ) string:concatenation :k.
    ( "<h2><a name='m" :m "'>  " :n """</a></h2>
<table>
  <tbody>
    <tr><th>Date</th><th>Details ("payee")</th>
     <th>Category</th><th>Account</th><th>Amount</th></tr>
""" ) string:concatenation :s
    } log:implies {
    :k log:outputString :s
}.


{ "1" os:argv :a } =>  { :a a :LabelOfThisAccount }.
# Each line:

{  
    [] a :y; q:payee :p; q:amount :x; q:date :d; q:toAccount [s:label :a].
    :p log:notEqualTo "Check".
    :p log:notEqualTo "Check - Ecp".
     :d string:startsWith "2002".
     :a a :LabelOfThisAccount.
    :y a :toBeDisplayed; s:label :l.
    ( :d :a ) string:concatenation :k.
    (  	"<tr class='"  :a "'><td class='date'>" (:d "^([^T]*)")!string:scrape
       	"</td><td class='payee'>" :p
        "</td><td class='cat'>" :l
       "</td><td class='to'>" :a
        "</td><td class='amount'>" :x
	"</td></tr>\n") string:concatenation :s
} log:implies {
   :k log:outputString :s
}.

acc:Default s:label "DEFAULT".

# end section:

{  :m :monthName :n.
    ( "2002-" :m  "ZZZZZ" ) string:concatenation :k.
} log:implies {
    :k log:outputString "</tbody></table>\n"
}.




"zz" log:outputString """</body>
</html>
""".

#ends

