<!DOCTYPE openRPTDef>
<report>
 <title>Time Phased Usage Statistics By Item</title>
 <name>TimePhasedUsageStatisticsByItem</name>
 <description/>
 <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,
       CASE WHEN (%2=-1) THEN 'All Warehouses'
                  ELSE ( SELECT warehous_code
                                 FROM warehous
                              WHERE (warehous_id=%2) )
       END AS warehouse
FROM item
WHERE (item_id=%1);</sql>
 </querysource>
 <querysource>
  <name>detail</name>
  <sql>SELECT findPeriodStart(rcalitem_id) AS pstart,
       findPeriodEnd(rcalitem_id) AS pend,
       (formatDate(findPeriodStart(rcalitem_id)) || '-' || formatDate(findPeriodEnd(rcalitem_id))) AS period,
       warehous_code,
       formatQty(summTransR(itemsite_id, rcalitem_id)) AS received,
       formatQty(summTransI(itemsite_id, rcalitem_id)) AS issued,
       formatQty(summTransS(itemsite_id, rcalitem_id)) AS sold,
       formatQty(summTransC(itemsite_id, rcalitem_id)) AS scrap,
       formatQty(summTransA(itemsite_id, rcalitem_id)) AS adjustments
  FROM rcalitem, itemsite, warehous
 WHERE ((rcalitem_id in (%4))
   AND (itemsite_warehous_id=warehous_id)
   AND (itemsite_item_id=%1)
   AND ((%2=-1) OR (itemsite_warehous_id=%2)) )
 UNION
SELECT findPeriodStart(acalitem_id) AS pstart,
       findPeriodEnd(acalitem_id) AS pend,
       (formatDate(findPeriodStart(acalitem_id)) || '-' || formatDate(findPeriodEnd(acalitem_id))) AS period,
       warehous_code,
       formatQty(summTransR(itemsite_id, acalitem_id)) AS received,
       formatQty(summTransI(itemsite_id, acalitem_id)) AS issued,
       formatQty(summTransS(itemsite_id, acalitem_id)) AS sold,
       formatQty(summTransC(itemsite_id, acalitem_id)) AS scrap,
       formatQty(summTransA(itemsite_id, acalitem_id)) AS adjustments
  FROM acalitem, itemsite, warehous
 WHERE ((acalitem_id IN (%4))
   AND (itemsite_warehous_id=warehous_id)
   AND (itemsite_item_id=%1)
   AND ((%2=-1) OR (itemsite_warehous_id=%2)) )
ORDER BY pstart, warehous_code;</sql>
 </querysource>
 <rpthead>
  <height>221</height>
  <label>
   <rect>
    <x>575</x>
    <y>200</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Scrap</string>
  </label>
  <label>
   <rect>
    <x>660</x>
    <y>200</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Adjusted</string>
  </label>
  <label>
   <rect>
    <x>270</x>
    <y>200</y>
    <width>35</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Whs.</string>
  </label>
  <label>
   <rect>
    <x>30</x>
    <y>80</y>
    <width>105</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Item Number:</string>
  </label>
  <field>
   <rect>
    <x>140</x>
    <y>140</y>
    <width>200</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>warehouse</column>
   </data>
  </field>
  <field>
   <rect>
    <x>140</x>
    <y>120</y>
    <width>385</width>
    <height>20</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>
  <line>
   <xstart>5</xstart>
   <ystart>215</ystart>
   <xend>740</xend>
   <yend>215</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>405</x>
    <y>200</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Issued</string>
  </label>
  <label>
   <rect>
    <x>30</x>
    <y>140</y>
    <width>105</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Warehouse:</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>200</y>
    <width>250</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Period</string>
  </label>
  <field>
   <rect>
    <x>140</x>
    <y>100</y>
    <width>385</width>
    <height>20</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>490</x>
    <y>200</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Sold</string>
  </label>
  <label>
   <rect>
    <x>240</x>
    <y>10</y>
    <width>485</width>
    <height>38</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>18</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Time Phased Usage Statistics By Item</string>
  </label>
  <label>
   <rect>
    <x>320</x>
    <y>200</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Received</string>
  </label>
  <field>
   <rect>
    <x>140</x>
    <y>80</y>
    <width>200</width>
    <height>20</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>
 </rpthead>
 <pghead>
  <firstpage/>
  <height>6</height>
 </pghead>
 <pghead>
  <height>21</height>
  <label>
   <rect>
    <x>490</x>
    <y>0</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Sold</string>
  </label>
  <label>
   <rect>
    <x>10</x>
    <y>0</y>
    <width>250</width>
    <height>15</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>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Issued</string>
  </label>
  <label>
   <rect>
    <x>270</x>
    <y>0</y>
    <width>35</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Whs.</string>
  </label>
  <label>
   <rect>
    <x>575</x>
    <y>0</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Scrap</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>15</ystart>
   <xend>740</xend>
   <yend>15</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>320</x>
    <y>0</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Received</string>
  </label>
  <label>
   <rect>
    <x>660</x>
    <y>0</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Adjusted</string>
  </label>
 </pghead>
 <section>
  <name>detail</name>
  <group>
   <name>detail</name>
   <column>pstart</column>
   <head>
    <height>6</height>
    <field>
     <rect>
      <x>10</x>
      <y>5</y>
      <width>250</width>
      <height>15</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>16</height>
   <field>
    <rect>
     <x>490</x>
     <y>0</y>
     <width>80</width>
     <height>15</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>575</x>
     <y>0</y>
     <width>80</width>
     <height>15</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>405</x>
     <y>0</y>
     <width>80</width>
     <height>15</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>270</x>
     <y>0</y>
     <width>35</width>
     <height>15</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>660</x>
     <y>0</y>
     <width>80</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>adjustments</column>
    </data>
   </field>
   <field>
    <rect>
     <x>320</x>
     <y>0</y>
     <width>80</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <right/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>received</column>
    </data>
   </field>
  </detail>
 </section>
 <pgfoot>
  <height>16</height>
  <label>
   <rect>
    <x>600</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>95</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>
  <field>
   <rect>
    <x>690</x>
    <y>0</y>
    <width>51</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>
  <label>
   <rect>
    <x>5</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>
</report>
