<Value name="Reserved" value="4">The order is just a reservation for a limited time, application logic must determine the timeout.</Value>
<Value name="Closed" value="0x80">The order is closed out of the system - the payment status is ignored from now on. Currently not used.</Value>
</Column>
- <Column name="ordertime" type="int32" notnull="yes">When the order was created</Column>
- <Column name="senttime" type="int32">When the order was sent to the customer</Column>
+ <Column name="ordertime" type="int64" notnull="yes">When the order was created</Column>
+ <Column name="senttime" type="int64">When the order was sent to the customer</Column>
<Column name="comments" type="text">comments made on web form (eg. "urgently needed for dads birthday")</Column>
<Column name="amountpaid" type="int32">
how much has been paid already (including used vouchers);
<Table name="product" backup="yes">
<Doc>A saleable product other than tickets or vouchers (eg. merchandizing).</Doc>
+ <Doc>This table represents stock. When a product is sold an entry is created in the table item.</Doc>
<Column name="productid" type="seq32" primarykey="yes"/>
<Column name="name" type="string" notnull="yes"/>
<Column name="description" type="text"/>
- <!-- amount that is in the inventory, or -1 if it is unlimited -->
- <Column name="inventory" type="int32" notnull="yes"/>
+
+ <Column name="inventory" type="int32" notnull="yes">
+ amount that remains in the inventory, or -1 if it is unlimited
+ </Column>
<Column name="price" type="int32" notnull="yes"/>
<Column name="barcode" type="string" null="yes">usually the EAN code</Column>
<Column name="flags" type="string"/>
</Table>
-
- <Class name="Ticket">
+ <!-- both sides implement some additional logic, hence abstract -->
+ <Class name="Ticket" abstract="yes">
<Doc>This class represents the data of a ticket as stored in the database.</Doc>
<Enum name="TicketState" refColumn="ticket:status"/>
<Property name="ticketid" type="astring" id="yes">uniquely identifies the ticket, this ID is automatically generated when the ticket is created by the server</Property>
<Property name="price" type="int" optional="1"/>
<Property name="status" type="VoucherState" optional="1"/>
<Property name="isused" type="bool"/>
+ <Property name="orderid" type="int"/>
+ <Mapping table="voucher">
+ <Map column="voucherid"/>
+ <Map column="value"/>
+ <Map column="price"/>
+ <Map column="orderid"/>
+ <Map column="isused"/>
+ <Map property="status">
+ <Call lang="php" method="self::Ok"/>
+ </Map>
+ </Mapping>
</Class>
<Transaction name="GetVoucher">
</Output>
</Transaction>
- <!-- this class used to be abstract="yes" - dunno why.-->
- <Class name="Order">
+ <Class name="ItemInfo">
+ <Doc>used for basic info about items</Doc>
+ <Property name="itemid" type="int"/>
+ <Property name="productid" type="int"/>
+ <!-- etc. -->
+ </Class>
+
+ <Class name="Order" abstract="yes">
+ <Doc>This class represents an order in its entirety, including any items sold in it.</Doc>
<Enum name="OrderState" refColumn="order:status" />
<Property name="orderid" type="int"/>
- <Property name="customerid" type="int"/>
- <Property name="seller" type="astring"/>
+ <Property name="customerid" type="int"/><!-- should be a full customer object -->
+ <!--invoice/delivery addresses missing -->
+ <Property name="soldby" type="astring"/>
<Property name="tickets" type="List:Ticket"/>
<Property name="vouchers" type="List:Voucher"/>
+ <!-- products/items missing -->
<Property name="amountpaid" type="int"/>
- <Property name="state" type="OrderState"/>
+ <Property name="status" type="OrderState"/>
<Property name="amountdue" type="int"/><!-- abstract="yes"? -->
</Output>
</Transaction>
+ <Class name="OrderInfo" abstract="yes">
+ <Doc>This class represents the main information about an order as shown in lists.</Doc>
+ <Enum name="OrderState" refColumn="order:status" />
+
+ <Property name="orderid" type="int"/>
+ <Property name="customerid" type="int"/>
+ <Property name="soldby" type="astring"/>
+
+ <Property name="amounttickets" type="int"/>
+ <Property name="amountvouchers" type="int"/>
+ <Property name="amountitems" type="int"/>
+
+ <Property name="status" type="OrderState"/>
+
+ <Property name="amountpaid" type="int"/>
+ <Property name="amountdue" type="int"/>
+ <Property name="totalprice" type="int"/>
+ <Property name="shippingcosts" type="int"/>
+
+ <Property name="ordertime" type="int64"/>
+ <Property name="senttime" type="int64"/>
+ <!-- etc.pp. -->
+ <Mapping table="order">
+ <Map column="orderid"/>
+ <Map column="customerid"/>
+ <Map column="soldby"/>
+ <Map column="status"/>
+ <Map column="ordertime"/>
+ <Map column="senttime"/>
+ <Map column="amountpaid"/>
+ <Map column="shippingcosts"/>
+
+ <Map property="totalprice">
+ <Call lang="php" method="$data->getTotalPriceFromDB()"/>
+ </Map>
+ <Map property="amountdue">
+ <Call lang="php" method="$data->prop_amountdue=$data->prop_totalprice - $data->propamountpaid"/>
+ </Map>
+ <Map property="amounttickets">
+ <Call lang="php" method="$data->getAmountTicketsFromDB()"/>
+ </Map>
+ <Map property="amountvouchers">
+ <Call lang="php" method="$data->getAmountVouchersFromDB()"/>
+ </Map>
+ <Map property="amountitems">
+ <Call lang="php" method="$data->getAmountItemsFromDB()"/>
+ </Map>
+ </Mapping>
+ </Class>
+
+ <Transaction name="GetOrderList">
+ <Input>
+ <Var name="oldest" type="int64">unix timestamp for the oldest order to be returned (compared with ordertime)</Var>
+ </Input>
+ <Call lang="php" method="WOOrderInfo::getAllOrders($this);"/>
+ <Output>
+ <Var name="orders" type="List:OrderInfo"/>
+ <Var name="customers" type="List:CustomerInfo"/>
+ </Output>
+ </Transaction>
+
+ <Transaction name="GetOrdersByEvents">
+ <Input>
+ <Var name="events" type="List:int32">list of event ids to select</Var>
+ <Var name="oldest" type="int64">unix timestamp for the oldest order to be returned (compared with ordertime)</Var>
+ </Input>
+ <Call lang="php" method="WOOrderInfo::getOrdersByEvents($this);"/>
+ <Output>
+ <Var name="orders" type="List:OrderInfo"/>
+ <Var name="customers" type="List:CustomerInfo"/>
+ </Output>
+ </Transaction>
+
+ <Transaction name="GetOrdersByCustomer">
+ <Input>
+ <Var name="customerid" type="int32">customer to select</Var>
+ <Var name="oldest" type="int64">unix timestamp for the oldest order to be returned (compared with ordertime)</Var>
+ </Input>
+ <Call lang="php" method="WOOrderInfo::getOrdersByCustomer($this);"/>
+ <Output>
+ <Var name="orders" type="List:OrderInfo"/>
+ </Output>
+ </Transaction>
+
+ <Transaction name="CreateOrder"/>
+ <Transaction name="CreateSale"/>
+
<Class name="Shipping">
<Property name="id" type="int32" id="yes"/>
<Property name="cost" type="int32"/> <!--default cost of this shipping type-->
--- /dev/null
+<?
+//
+// PHP Implementation: order
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+/**shortened info about orders*/
+class WOOrderInfo extends WOOrderInfoAbstract
+{
+ /**mapping helper*/
+ protected function getTotalPriceFromDB()
+ {
+ global $db;
+ //if order is closed, return 0
+ if($this->prop_status==self::Closed)
+ return 0;
+ //get shipping price
+ $prc=$this->prop_shippingcosts;
+ //if this order is cancelled the items are not counted
+ if($this->prop_status==self::Cancelled)
+ return $prc;
+ //get tickets
+ $itms=WOTicket::fromTableArrayticket(WTticket::selectFromDB("orderid=".$db->escapeInt($this->prop_orderid)));
+ foreach($itms as $it)
+ $prc+=$it->amountToPay();
+ //get vouchers
+ $itms=WOVoucher::fromTableArrayvoucher(WTvoucher::selectFromDB("orderid=".$db->escapeInt($this->prop_orderid)));
+ foreach($itms as $it)
+ $prc+=$it->get_price();
+ //get others
+ $itms=WTitem::selectFromDB("orderid=".$db->escapeInt($this->prop_orderid));
+ foreach($itms as $it)
+ $prc+=$it->totalprice;
+
+ //return result
+ return $prc;
+ }
+ /**mapping helper*/
+ protected function getAmountTicketsFromDB()
+ {
+ global $db;
+ $res=$db->select("ticket","count(*)as count","orderid=".$db->escapeInt($this->prop_orderid));
+ return $res[0]["count"];
+ }
+ /**mapping helper*/
+ protected function getAmountVouchersFromDB()
+ {
+ global $db;
+ $res=$db->select("voucher","count(*)as count","orderid=".$db->escapeInt($this->prop_orderid));
+ return $res[0]["count"];
+ }
+ /**mapping helper*/
+ protected function getAmountItemsFromDB()
+ {
+ global $db;
+ $res=$db->select("item","count(*)as count","orderid=".$db->escapeInt($this->prop_orderid));
+ return $res[0]["count"];
+ }
+
+ /**called from GetOrderList transaction*/
+ static public function getAllOrders($trans)
+ {
+ global $db;
+ $old=$trans->getoldest();
+ if($old===false)$old=0;
+ $olst=self::fromTableArrayorder(WTorder::selectFromDB("ordertime>=".$db->escapeInt($old),"ORDER BY orderid"));
+ $trans->setorders($olst);
+ $trans->setcustomers(self::getCustomerListByOrders($olst));
+ }
+
+ /**called from GetOrdersByEvents transaction*/
+ static public function getOrdersByEvents($trans)
+ {
+ global $db;
+ $old=$trans->getoldest();
+ if($old===false)$old=0;
+ //get list of valid orderids
+ $res=$db->select("ticket","orderid","eventid in ".$db->escapeIntList($trans->getevents()),"GROUP BY orderid ORDER BY orderid");
+ $oidl=array();
+ foreach($res as $r)
+ if(!in_array($r["orderid"],$oidl))$oidl[]=$r["orderid"];
+ //get orders
+ $olst=self::fromTableArrayorder(WTorder::selectFromDB("ordertime>=".$db->escapeInt($old)." AND orderid in ".$db->escapeIntList($oidl),"ORDER BY orderid"));
+ $trans->setorders($olst);
+ $trans->setcustomers(self::getCustomerListByOrders($olst));
+ }
+
+ /**helper function for several transactions: selects customers by their IDs references by the given order info objects*/
+ static protected function getCustomerListByOrders(array $olist)
+ {
+ global $db;
+ //filter olist
+ $cl=array();
+ foreach($olist as $o){
+ $id=$o->prop_customerid;
+ if(!in_array($id,$cl))
+ $cl[]=$id;
+ }
+ //request data
+ return WOCustomerInfo::fromTableArraycustomer(WTcustomer::selectFromDB("customerid in ".$db->escapeIntList($cl)));
+ }
+};
+
+class WOOrder extends WOOrderAbstract
+{
+};
+
+?>
\ No newline at end of file