<!DOCTYPE openRPTDef>
<report>
 <title>Buy Card</title>
 <name>BuyCard</name>
 <description></description>
 <size>Letter</size>
 <portrait/>
 <topmargin>50</topmargin>
 <bottommargin>50</bottommargin>
 <rightmargin>50</rightmargin>
 <leftmargin>50</leftmargin>
 <querysource>
  <name>head</name>
  <sql>SELECT vend_number, vend_name,
       itemsrc_vend_item_number,
       itemsrc_vend_item_descrip
  FROM vendinfo, itemsrc
 WHERE ((vend_id=&lt;? value("vend_id") ?>)
   AND  (itemsrc_id=&lt;? value("itemsrc_id") ?>) )</sql>
 </querysource>
 <querysource>
  <name>detail</name>
  <sql>SELECT poitem_id, pohead_number, poitem_linenumber,
       CASE WHEN(poitem_status='C') THEN TEXT('Closed')
            WHEN(poitem_status='U') THEN TEXT('Unposted')
            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered>(poitem_qty_received-poitem_qty_returned))) THEN TEXT('Partial')
            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered=(poitem_qty_received-poitem_qty_returned))) THEN TEXT('Received')
            WHEN(poitem_status='O') THEN TEXT('Open')
            ELSE poitem_status
       END AS poitemstatus,
       formatDate(poitem_duedate) as f_duedate,
       formatQty(poitem_qty_ordered) as f_qtyord,
       formatQty(COALESCE(SUM(recv_qty), 0)) as f_qty,
       formatPrice(poitem_unitprice) as f_unitprice
FROM pohead, poitem LEFT OUTER JOIN recv ON (recv_orderitem_id=poitem_id)
WHERE ( (poitem_pohead_id=pohead_id)
 AND (recv_order_type='PO')
 AND (pohead_vend_id=&lt;? value("vend_id") ?>)
 AND (poitem_vend_item_number=(select itemsrc_vend_item_number from itemsrc where itemsrc_id=&lt;? value("itemsrc_id") ?>)) ) 
GROUP BY poitem_id, pohead_number, poitem_linenumber,
         poitem_status, poitem_qty_received, poitem_qty_returned,
         poitem_duedate, poitem_qty_ordered, poitem_unitprice
ORDER BY pohead_number, poitem_linenumber;</sql>
 </querysource>
 <querysource>
  <name>foot</name>
  <sql>SELECT itemsrc_comments
  FROM itemsrc
 WHERE itemsrc_id=&lt;? value("itensrc_id") ?>;</sql>
 </querysource>
 <rpthead>
  <height>221</height>
  <field>
   <rect>
    <x>135</x>
    <y>114</y>
    <width>300</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>itemsrc_vend_item_number</column>
   </data>
  </field>
  <label>
   <rect>
    <x>270</x>
    <y>200</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Ordered</string>
  </label>
  <label>
   <rect>
    <x>175</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>Due Date</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>215</ystart>
   <xend>745</xend>
   <yend>215</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>60</x>
    <y>200</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>#</string>
  </label>
  <label>
   <rect>
    <x>30</x>
    <y>114</y>
    <width>100</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Vendor Part #:</string>
  </label>
  <label>
   <rect>
    <x>335</x>
    <y>5</y>
    <width>400</width>
    <height>40</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>18</size>
    <weight>bold</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Buy Card</string>
  </label>
  <label>
   <rect>
    <x>114</x>
    <y>200</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Status</string>
  </label>
  <label>
   <rect>
    <x>5</x>
    <y>200</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>P/O #</string>
  </label>
  <field>
   <rect>
    <x>135</x>
    <y>65</y>
    <width>300</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>vend_number</column>
   </data>
  </field>
  <label>
   <rect>
    <x>370</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>
  <label>
   <rect>
    <x>30</x>
    <y>65</y>
    <width>100</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Vendor #:</string>
  </label>
  <field>
   <rect>
    <x>135</x>
    <y>85</y>
    <width>300</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>vend_name</column>
   </data>
  </field>
  <label>
   <rect>
    <x>455</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>Unit Cost</string>
  </label>
  <label>
   <rect>
    <x>5</x>
    <y>135</y>
    <width>125</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Vendor Description:</string>
  </label>
  <field>
   <rect>
    <x>135</x>
    <y>135</y>
    <width>300</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>head</query>
    <column>itemsrc_vend_item_descrip</column>
   </data>
  </field>
 </rpthead>
 <pghead>
  <firstpage/>
  <height>6</height>
 </pghead>
 <pghead>
  <height>26</height>
  <label>
   <rect>
    <x>175</x>
    <y>5</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Due Date</string>
  </label>
  <label>
   <rect>
    <x>60</x>
    <y>5</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>#</string>
  </label>
  <label>
   <rect>
    <x>455</x>
    <y>5</y>
    <width>80</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Unit Cost</string>
  </label>
  <line>
   <xstart>5</xstart>
   <ystart>20</ystart>
   <xend>745</xend>
   <yend>20</yend>
   <weight>2</weight>
  </line>
  <label>
   <rect>
    <x>114</x>
    <y>5</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Status</string>
  </label>
  <label>
   <rect>
    <x>5</x>
    <y>5</y>
    <width>50</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>P/O #</string>
  </label>
  <label>
   <rect>
    <x>270</x>
    <y>5</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <hcenter/>
   <vcenter/>
   <string>Ordered</string>
  </label>
  <label>
   <rect>
    <x>370</x>
    <y>5</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>
 </pghead>
 <section>
  <name>detail</name>
  <detail>
   <key>
    <query>detail</query>
   </key>
   <height>16</height>
   <field>
    <rect>
     <x>260</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_qtyord</column>
    </data>
   </field>
   <field>
    <rect>
     <x>455</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>f_unitprice</column>
    </data>
   </field>
   <field>
    <rect>
     <x>175</x>
     <y>0</y>
     <width>80</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>f_duedate</column>
    </data>
   </field>
   <field>
    <rect>
     <x>5</x>
     <y>0</y>
     <width>50</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>pohead_number</column>
    </data>
   </field>
   <field>
    <rect>
     <x>60</x>
     <y>0</y>
     <width>50</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>poitem_linenumber</column>
    </data>
   </field>
   <field>
    <rect>
     <x>370</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>f_qty</column>
    </data>
   </field>
   <field>
    <rect>
     <x>114</x>
     <y>0</y>
     <width>50</width>
     <height>15</height>
    </rect>
    <font>
     <face>Arial</face>
     <size>8</size>
     <weight>bold</weight>
    </font>
    <hcenter/>
    <vcenter/>
    <data>
     <query>detail</query>
     <column>poitemstatus</column>
    </data>
   </field>
  </detail>
 </section>
 <pgfoot>
  <height>16</height>
  <label>
   <rect>
    <x>0</x>
    <y>0</y>
    <width>100</width>
    <height>15</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>8</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Report Date:</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>
  <label>
   <rect>
    <x>600</x>
    <y>0</y>
    <width>100</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>104</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>
 </pgfoot>
 <rptfoot>
  <height>31</height>
  <label>
   <rect>
    <x>20</x>
    <y>5</y>
    <width>100</width>
    <height>20</height>
   </rect>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>normal</weight>
   </font>
   <right/>
   <vcenter/>
   <string>Comments:</string>
  </label>
  <text>
   <rect>
    <x>125</x>
    <y>5</y>
    <width>615</width>
    <height>20</height>
   </rect>
   <bottompad>5</bottompad>
   <font>
    <face>Arial</face>
    <size>10</size>
    <weight>bold</weight>
   </font>
   <left/>
   <vcenter/>
   <data>
    <query>foot</query>
    <column>itemsrc_comments</column>
   </data>
  </text>
 </rptfoot>
</report>
