<!DOCTYPE openRPTDef>
<report>
 <title>Trial Balances</title>
 <name>TrialBalances</name>
 <description></description>
 <grid>
  <snap/>
  <show/>
  <x>0.05</x>
  <y>0.05</y>
 </grid>
 <size>Letter</size>
 <landscape/>
 <topmargin>50</topmargin>
 <bottommargin>50</bottommargin>
 <rightmargin>50</rightmargin>
 <leftmargin>50</leftmargin>
 <querysource>
  <name>head</name>
  <sql>SELECT &lt;? if exists("accnt_id") ?>
         ( SELECT (accnt_number || '-' || accnt_descrip)
             FROM accnt
            WHERE (accnt_id=&lt;? value("accnt_id") ?>) )
       &lt;? else ?>
         text('All Accounts')
       &lt;? endif ?>
       AS accnt,
       &lt;? if exists("period_id") ?>
         ( SELECT (formatDate(period_start) || '-' || formatDate(period_end))
             FROM period
            WHERE (period_id=&lt;? value("period_id") ?>) )
       &lt;? else ?>
         text('All Periods')
       &lt;? endif ?>
       AS period;
       </sql>
 </querysource>
 <querysource>
  <name>detail</name>
  <sql>SELECT accnt_id,
       period_id,
       formatDate(period_start) AS f_start,
       formatDate(period_end) AS f_end,
       formatGLAccount(accnt_id) AS f_account,
       accnt_descrip,
       formatMoney(abs(trialbal_beginning)) AS f_beginning,
       CASE WHEN(trialbal_beginning>0) THEN text('CR')
            ELSE text('')
       END AS f_beginningcr,
       formatMoney(trialbal_debits) AS f_debits,
       formatMoney(trialbal_credits) AS f_credits,
       formatMoney(abs(trialbal_debits - trialbal_credits)) AS f_diff,
       CASE WHEN((trialbal_debits - trialbal_credits) &lt; 0) THEN text('CR')
            ELSE text('')
       END AS f_diffcr,
       formatMoney(abs(trialbal_ending)) AS f_ending,
       CASE WHEN(trialbal_ending>0) THEN text('CR')
            ELSE text('')
       END AS f_endingcr
  FROM trialbal, accnt, period
 WHERE ((trialbal_accnt_id=accnt_id)
   AND (trialbal_period_id=period_id)
&lt;? if exists("accnt_id") ?>
   AND (trialbal_accnt_id=&lt;? value("accnt_id") ?>)
&lt;? endif ?>
&lt;? if exists("period_id") ?>
   AND (period_id=&lt;? value("period_id") ?>)
&lt;? endif ?>
&lt;? if not exists("showZero") ?>
   AND (abs(trialbal_beginning)+abs(trialbal_ending)+abs(trialbal_debits)+abs(trialbal_credits) > 0) 
&lt;? endif ?>
       )
ORDER BY period_start, formatGLAccount(accnt_id);</sql>
 </querysource>
 <querysource>
  <name>total</name>
  <sql>SELECT formatMoney(abs(beginning)) AS f_beginning,
       CASE WHEN(beginning&lt;0) THEN text('CR')
            ELSE text('')
       END AS f_beginningcr,
       formatMoney(debits) AS f_debits,
       formatMoney(credits) AS f_credits,
       formatMoney(abs(debits - credits)) AS f_diff,
       CASE WHEN((debits - credits) &lt; 0) THEN text('CR')
            ELSE text('')
       END AS f_diffcr,
       formatMoney(abs(ending)) AS f_ending,
       CASE WHEN(ending&lt;0) THEN text('CR')
            ELSE text('')
       END AS f_endingcr
  FROM ( SELECT SUM(trialbal_beginning*-1) AS beginning,
                SUM(trialbal_debits) AS debits,
                SUM(trialbal_credits) AS credits,
                SUM(trialbal_ending*-1) AS ending
           FROM trialbal, accnt, period
          WHERE ((trialbal_accnt_id=accnt_id)
            AND  (trialbal_period_id=period_id)
&lt;? if exists("accnt_id") ?>
            AND  (trialbal_accnt_id=&lt;? value("accnt_id") ?>)
&lt;? endif ?>
&lt;? if exists("period_id") ?>
            AND  (period_id=&lt;? value("period_id") ?>)
&lt;? endif ?>
                )
       ) AS data;</sql>
 </querysource>
 <rpthead>
  <height>191</height>
  <label>
   <rect>
    <x>860</x>
    <y>155</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Ending Bal.</string>
  </label>
  <label>
   <rect>
    <x>370</x>
    <y>155</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Beg. Bal.</string>
  </label>
  <label>
   <rect>
    <x>615</x>
    <y>155</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Credits</string>
  </label>
  <label>
   <rect>
    <x>105</x>
    <y>155</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period End</string>
  </label>
  <label>
   <rect>
    <x>200</x>
    <y>170</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <vcenter/>
   <string>Description</string>
  </label>
  <label>
   <rect>
    <x>510</x>
    <y>155</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Debits</string>
  </label>
  <label>
   <rect>
    <x>200</x>
    <y>155</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <vcenter/>
   <string>Account #</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>155</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period Start</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>185</ystart>
   <xend>990</xend>
   <yend>185</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>720</x>
    <y>155</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Difference</string>
  </label>
  <label>
   <rect>
    <x>635</x>
    <y>10</y>
    <width>350</width>
    <height>38</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>18</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Trial Balances</string>
  </label>
  <text>
   <rect>
    <x>10</x>
    <y>38</y>
    <width>725</width>
    <height>15</height>
   </rect>
   <bottompad>12</bottompad>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <top/>
   <data>
    <query>Parameter Query</query>
    <column>filter</column>
   </data>
  </text>
 </rpthead>
 <pghead>
  <firstpage/>
  <height>6</height>
 </pghead>
 <pghead>
  <height>36</height>
  <label>
   <rect>
    <x>720</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Difference</string>
  </label>
  <label>
   <rect>
    <x>370</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Beg. Bal.</string>
  </label>
  <label>
   <rect>
    <x>200</x>
    <y>15</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <vcenter/>
   <string>Description</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>0</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period Start</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>30</ystart>
   <xend>990</xend>
   <yend>30</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>200</x>
    <y>0</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <vcenter/>
   <string>Account #</string>
  </label>
  <label>
   <rect>
    <x>615</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Credits</string>
  </label>
  <label>
   <rect>
    <x>860</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Ending Bal.</string>
  </label>
  <label>
   <rect>
    <x>105</x>
    <y>0</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period End</string>
  </label>
  <label>
   <rect>
    <x>510</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Debits</string>
  </label>
 </pghead>
 <section>
  <name>detail</name>
  <detail>
   <key>
    <query>detail</query>
   </key>
   <height>31</height>
   <field>
    <rect>
     <x>475</x>
     <y>0</y>
     <width>30</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <left/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_beginningcr</column>
    </data>
   </field>
   <field>
    <rect>
     <x>105</x>
     <y>0</y>
     <width>90</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_end</column>
    </data>
   </field>
   <field>
    <rect>
     <x>965</x>
     <y>0</y>
     <width>30</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <left/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_endingcr</column>
    </data>
   </field>
   <field>
    <rect>
     <x>510</x>
     <y>0</y>
     <width>100</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_debits</column>
    </data>
   </field>
   <field>
    <rect>
     <x>370</x>
     <y>0</y>
     <width>100</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_beginning</column>
    </data>
   </field>
   <field>
    <rect>
     <x>615</x>
     <y>0</y>
     <width>100</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_credits</column>
    </data>
   </field>
   <field>
    <rect>
     <x>200</x>
     <y>15</y>
     <width>140</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <left/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>accnt_descrip</column>
    </data>
   </field>
   <field>
    <rect>
     <x>10</x>
     <y>0</y>
     <width>90</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_start</column>
    </data>
   </field>
   <field>
    <rect>
     <x>860</x>
     <y>0</y>
     <width>100</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_ending</column>
    </data>
   </field>
   <field>
    <rect>
     <x>720</x>
     <y>0</y>
     <width>100</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_diff</column>
    </data>
   </field>
   <field>
    <rect>
     <x>825</x>
     <y>0</y>
     <width>30</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <left/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_diffcr</column>
    </data>
   </field>
   <field>
    <rect>
     <x>200</x>
     <y>0</y>
     <width>150</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <left/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_account</column>
    </data>
   </field>
  </detail>
 </section>
 <pgfoot>
  <height>17</height>
  <label>
   <rect>
    <x>615</x>
    <y>0</y>
    <width>85</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Page:</string>
  </label>
  <field>
   <rect>
    <x>705</x>
    <y>0</y>
    <width>40</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>Context Query</query>
    <column>page_number</column>
   </data>
  </field>
  <field>
   <rect>
    <x>90</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>Context Query</query>
    <column>report_date</column>
   </data>
  </field>
  <label>
   <rect>
    <x>0</x>
    <y>0</y>
    <width>85</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Report Date:</string>
  </label>
 </pgfoot>
 <rptfoot>
  <height>21</height>
  <field>
   <rect>
    <x>370</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_beginning</column>
   </data>
  </field>
  <field>
   <rect>
    <x>720</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_diff</column>
   </data>
  </field>
  <field>
   <rect>
    <x>510</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_debits</column>
   </data>
  </field>
  <field>
   <rect>
    <x>615</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_credits</column>
   </data>
  </field>
  <field>
   <rect>
    <x>860</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_ending</column>
   </data>
  </field>
  <label>
   <rect>
    <x>255</x>
    <y>0</y>
    <width>90</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <vcenter/>
   <string>Total:</string>
  </label>
  <field>
   <rect>
    <x>965</x>
    <y>0</y>
    <width>30</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_endingcr</column>
   </data>
  </field>
  <field>
   <rect>
    <x>475</x>
    <y>0</y>
    <width>30</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_beginningcr</column>
   </data>
  </field>
  <field>
   <rect>
    <x>825</x>
    <y>0</y>
    <width>30</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>total</query>
    <column>f_diffcr</column>
   </data>
  </field>
 </rptfoot>
</report>
