<!DOCTYPE openRPTDef>
<report>
 <title>Time Phased Usage Statistics By Item</title>
 <name>TimePhasedStatisticsByItem</name>
 <description>Shows graph</description>
 <grid>
  <snap/>
  <show/>
  <x>0.05</x>
  <y>0.05</y>
 </grid>
 <size>Letter</size>
 <portrait/>
 <topmargin>50</topmargin>
 <bottommargin>50</bottommargin>
 <rightmargin>50</rightmargin>
 <leftmargin>50</leftmargin>
 <querysource>
  <name>head</name>
  <sql>SELECT item_number,
       item_descrip1,
       item_descrip2,
       &lt;? if exists("warehous_id") ?>
         ( SELECT warehous_code
             FROM whsinfo
            WHERE (warehous_id=&lt;? value("warehous_id") ?>) )
       &lt;? else ?>
         text('All Warehouses')
       &lt;? endif ?>
       AS warehouse
  FROM item
 WHERE (item_id=&lt;? value("item_id") ?>);</sql>
 </querysource>
 <querysource>
  <name>detail</name>
  <sql>SELECT calitem_pstart AS pstart,
       calitem_pend AS pend,
       (formatDate(calitem_pstart) || '-' || formatDate(calitem_pend)) AS period,
       warehous_code,
       formatQty(summTransR(itemsite_id, calitem_id)) AS received,
       formatQty(summTransI(itemsite_id, calitem_id)) AS issued,
       formatQty(summTransS(itemsite_id, calitem_id)) AS sold,
       formatQty(summTransC(itemsite_id, calitem_id)) AS scrap,
       formatQty(summTransA(itemsite_id, calitem_id)) AS adjustments,
--
       summTransR(itemsite_id, calitem_id) AS a_received,
       summTransI(itemsite_id, calitem_id) AS a_issued,
       summTransS(itemsite_id, calitem_id) AS a_sold,
       summTransC(itemsite_id, calitem_id) AS a_scrap,
       summTransA(itemsite_id, calitem_id) AS a_adjustments

  FROM itemsite, whsinfo,

       ( SELECT rcalitem_id as calitem_id,
                findPeriodStart(rcalitem_id) as calitem_pstart,
                findPeriodEnd(rcalitem_id) as calitem_pend
           FROM rcalitem
          WHERE (rcalitem_id in (
&lt;? foreach("period_id_list") ?>
  &lt;? if not isfirst("period_id_list") ?>
    ,
  &lt;? endif ?>
  &lt;? value("period_id_list") ?>
&lt;? endforeach ?>
                 ))
          UNION
         SELECT acalitem_id as calitem_id,
                findPeriodStart(acalitem_id) as calitem_pstart,
                findPeriodEnd(acalitem_id) as calitem_pend
           FROM acalitem
          WHERE (acalitem_id in (
&lt;? foreach("period_id_list") ?>
  &lt;? if not isfirst("period_id_list") ?>
    ,
  &lt;? endif ?>
  &lt;? value("period_id_list") ?>
&lt;? endforeach ?>
                 ))
       ORDER BY calitem_pstart, calitem_pend
       ) as calitem

 WHERE ((itemsite_warehous_id=warehous_id)
   AND (itemsite_item_id=&lt;? value("item_id") ?>)
&lt;? if exists("warehous_id") ?>
   AND (itemsite_warehous_id=&lt;? value("warehous_id") ?>)
&lt;? endif ?>
)
ORDER BY calitem_pstart, warehous_code;</sql>
 </querysource>
 <colordef>
  <name>Blue</name>
  <red>0</red>
  <green>0</green>
  <blue>255</blue>
 </colordef>
 <colordef>
  <name>BlueGreen</name>
  <red>0</red>
  <green>255</green>
  <blue>255</blue>
 </colordef>
 <colordef>
  <name>Green</name>
  <red>0</red>
  <green>255</green>
  <blue>0</blue>
 </colordef>
 <colordef>
  <name>Red</name>
  <red>255</red>
  <green>0</green>
  <blue>0</blue>
 </colordef>
 <colordef>
  <name>RedBlue</name>
  <red>255</red>
  <green>0</green>
  <blue>255</blue>
 </colordef>
 <colordef>
  <name>RedGreen</name>
  <red>255</red>
  <green>255</green>
  <blue>0</blue>
 </colordef>
 <rpthead>
  <height>683</height>
  <field>
   <rect>
    <x>130</x>
    <y>63</y>
    <width>385</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>item_descrip1</column>
   </data>
  </field>
  <label>
   <rect>
    <x>60</x>
    <y>613</y>
    <width>300</width>
    <height>12</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <top/>
   <string>Scrapped (RedGreen/Line) Adjusted (RedBlue/Points&amp;Line)</string>
  </label>
  <label>
   <rect>
    <x>434</x>
    <y>43</y>
    <width>104</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Warehouse:</string>
  </label>
  <label>
   <rect>
    <x>575</x>
    <y>655</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Scrap</string>
  </label>
  <field>
   <rect>
    <x>130</x>
    <y>50</y>
    <width>200</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>item_number</column>
   </data>
  </field>
  <line>
   <xstart>0</xstart>
   <ystart>675</ystart>
   <xend>735</xend>
   <yend>675</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>405</x>
    <y>655</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Issued</string>
  </label>
  <label>
   <rect>
    <x>660</x>
    <y>655</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Adjusted</string>
  </label>
  <label>
   <rect>
    <x>18</x>
    <y>605</y>
    <width>360</width>
    <height>12</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <left/>
   <top/>
   <string>Legend: Issued (Green/Bar) Received: (BlueGreen/Line) Sold: (Blue/Bar)</string>
  </label>
  <label>
   <rect>
    <x>268</x>
    <y>655</y>
    <width>35</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Whs.</string>
  </label>
  <label>
   <rect>
    <x>488</x>
    <y>655</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Sold</string>
  </label>
  <graph>
   <rect>
    <x>35</x>
    <y>116</y>
    <width>712</width>
    <height>467</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <data>
    <query>detail</query>
    <column/>
   </data>
   <title>
    <string>Time Phased Activity Graph</string>
   </title>
   <dataaxis>
    <title>
     <string>Date Range</string>
    </title>
    <column>period</column>
   </dataaxis>
   <valueaxis>
    <title>
     <string>Quantity</string>
    </title>
    <min>0</min>
    <max>0</max>
    <autominmax>true</autominmax>
   </valueaxis>
   <series>
    <name>IssuedQuanity</name>
    <column>a_issued</column>
    <color>Green</color>
    <style>
     <bar/>
    </style>
   </series>
   <series>
    <name>Received</name>
    <column>a_received</column>
    <color>BlueGreen</color>
    <style>
     <line/>
    </style>
   </series>
   <series>
    <name>Sold</name>
    <column>a_sold</column>
    <color>Blue</color>
    <style>
     <bar/>
    </style>
   </series>
   <series>
    <name>Scrapped</name>
    <column>a_scrap</column>
    <color>RedGreen</color>
    <style>
     <line/>
    </style>
   </series>
   <series>
    <name>Adjusted</name>
    <column>a_adjustments</column>
    <color>RedBlue</color>
    <style>
     <line/>
     <point/>
    </style>
   </series>
  </graph>
  <label>
   <rect>
    <x>318</x>
    <y>655</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Received</string>
  </label>
  <field>
   <rect>
    <x>543</x>
    <y>43</y>
    <width>200</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>warehouse</column>
   </data>
  </field>
  <label>
   <rect>
    <x>78</x>
    <y>10</y>
    <width>644</width>
    <height>37</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>18</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Time Phased Usage Statistics By Item with Graph</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>50</y>
    <width>104</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Item Number:</string>
  </label>
  <field>
   <rect>
    <x>130</x>
    <y>80</y>
    <width>385</width>
    <height>18</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>item_descrip2</column>
   </data>
  </field>
  <label>
   <rect>
    <x>18</x>
    <y>655</y>
    <width>250</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period</string>
  </label>
 </rpthead>
 <pghead>
  <firstpage/>
  <height>9</height>
 </pghead>
 <pghead>
  <height>23</height>
  <label>
   <rect>
    <x>488</x>
    <y>0</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Sold</string>
  </label>
  <label>
   <rect>
    <x>575</x>
    <y>0</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Scrap</string>
  </label>
  <label>
   <rect>
    <x>318</x>
    <y>0</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Received</string>
  </label>
  <label>
   <rect>
    <x>268</x>
    <y>0</y>
    <width>35</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Whs.</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>13</ystart>
   <xend>738</xend>
   <yend>13</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>660</x>
    <y>0</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Adjusted</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>0</y>
    <width>250</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period</string>
  </label>
  <label>
   <rect>
    <x>405</x>
    <y>0</y>
    <width>80</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Issued</string>
  </label>
 </pghead>
 <section>
  <name>detail</name>
  <group>
   <name>detail</name>
   <column>pstart</column>
   <head>
    <height>15</height>
    <field>
     <rect>
      <x>10</x>
      <y>5</y>
      <width>250</width>
      <height>13</height>
     </rect>
     <font>
      <face>Arial</face>
      <size>8</size>
      <weight>bold</weight>
     </font>
     <hcenter/>
     <vcenter/>
     <data>
      <query>detail</query>
      <column>period</column>
     </data>
    </field>
   </head>
  </group>
  <detail>
   <key>
    <query>detail</query>
   </key>
   <height>18</height>
   <field>
    <rect>
     <x>405</x>
     <y>0</y>
     <width>80</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>issued</column>
    </data>
   </field>
   <field>
    <rect>
     <x>575</x>
     <y>0</y>
     <width>80</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>scrap</column>
    </data>
   </field>
   <field>
    <rect>
     <x>318</x>
     <y>0</y>
     <width>80</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>received</column>
    </data>
   </field>
   <field>
    <rect>
     <x>268</x>
     <y>0</y>
     <width>35</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>warehous_code</column>
    </data>
   </field>
   <field>
    <rect>
     <x>488</x>
     <y>0</y>
     <width>80</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>sold</column>
    </data>
   </field>
   <field>
    <rect>
     <x>660</x>
     <y>0</y>
     <width>80</width>
     <height>13</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>adjustments</column>
    </data>
   </field>
  </detail>
 </section>
 <pgfoot>
  <height>18</height>
  <label>
   <rect>
    <x>5</x>
    <y>0</y>
    <width>85</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Report Date:</string>
  </label>
  <field>
   <rect>
    <x>688</x>
    <y>0</y>
    <width>51</width>
    <height>13</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>
  <label>
   <rect>
    <x>600</x>
    <y>0</y>
    <width>85</width>
    <height>13</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Page:</string>
  </label>
  <field>
   <rect>
    <x>93</x>
    <y>0</y>
    <width>100</width>
    <height>13</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>
 </pgfoot>
</report>
