server side of now usable order tab
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 15:02:44 +0000 (15:02 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 15:02:44 +0000 (15:02 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@367 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

wob/customer.wolf
wob/order.wolf
www/inc/db/barcodetable.php
www/inc/db/db.php
www/inc/wext/autoload.php
www/inc/wext/customer.php [new file with mode: 0644]
www/inc/wext/order.php [new file with mode: 0644]
www/inc/wext/ticket.php [new file with mode: 0644]

index 9f16c2b..edac499 100644 (file)
                <Property name="addresses" type="List:Address"/>
                <Property name="contacts" type="List:Contact"/>
        </Class>
-       <Class name="CustomerShort">
-               <Property name="id" type="int"/>
+       <Class name="CustomerInfo" abstract="yes">
+               <!-- abstract is needed on C++ side -->
+               <Doc>This class encapsulates the most basic information about a customer.</Doc>
+               <Doc>For more complex tasks the Customer class is used.</Doc>
+               <Property name="customerid" type="int"/>
+               <Property name="title" type="string"/>
+               <Property name="firstname" type="string"/>
                <Property name="name" type="string"/>
+               <Mapping table="customer">
+                       <Map column="customerid"/>
+                       <Map column="title"/>
+                       <Map column="firstname"/>
+                       <Map column="name"/>
+               </Mapping>
        </Class>
        
+       
        <Transaction name="GetCustomer">
                <Input>
                        <Var name="customerid" type="int"/>
        <Transaction name="GetAllCustomerNames">
                <Input/>
                <Output>
-                       <Var name="customers" type="List:CustomerShort"/>
+                       <Var name="customers" type="List:CustomerInfo"/>
                </Output>
        </Transaction>
 </Wolf>
\ No newline at end of file
index 6c9a02a..9036fe4 100644 (file)
@@ -49,8 +49,8 @@
                        <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-->
index 57527be..2f63100 100644 (file)
@@ -11,7 +11,7 @@
 //
 //
 
-class BarcodeTable extends WobTable
+abstract class BarcodeTable extends WobTable
 {
        private static $NumTicketChars=false;
        private static function init()
index 5131687..137317c 100644 (file)
@@ -283,6 +283,20 @@ abstract class DbEngine
                return round($i + 0);
        }
        
+       /**escapes a list of integers; uses escapeInt for each element; automatically adds parentheses*/
+       public function escapeIntList(array $il)
+       {
+               $r="(";
+               $b=false;
+               foreach($il as $i){
+                       if($b)$r.=",";
+                       else $b=true;
+                       $r.=$this->escapeInt($i);
+               }
+               $r.=")";
+               return $r;
+       }
+       
        /**escapes strings; the default uses addslashes and encloses the value in ''; it is recommended to overwrite this with the proper escaping procedure for the target DB (false and null are translated to NULL)*/
        public function escapeString($s)
        {
index bc716bf..c446bc5 100644 (file)
@@ -12,4 +12,8 @@
 //
 
 $AUTOCLASS["WORole"]="inc/wext/role.php";
+$AUTOCLASS["WOOrderInfo"]="inc/wext/order.php";
+$AUTOCLASS["WOOrder"]="inc/wext/order.php";
+$AUTOCLASS["WOCustomerInfo"]="inc/wext/customer.php";
+$AUTOCLASS["WOTicket"]="inc/wext/ticket.php";
 ?>
\ No newline at end of file
diff --git a/www/inc/wext/customer.php b/www/inc/wext/customer.php
new file mode 100644 (file)
index 0000000..9c2fa50
--- /dev/null
@@ -0,0 +1,15 @@
+<?
+//
+// PHP Implementation: customer
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class WOCustomerInfo extends WOCustomerInfoAbstract {};
+?>
\ No newline at end of file
diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php
new file mode 100644 (file)
index 0000000..14bd2af
--- /dev/null
@@ -0,0 +1,115 @@
+<?
+//
+// 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
diff --git a/www/inc/wext/ticket.php b/www/inc/wext/ticket.php
new file mode 100644 (file)
index 0000000..f56de70
--- /dev/null
@@ -0,0 +1,25 @@
+<?
+//
+// PHP Implementation: ticket
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class WOTicket extends WOTicketAbstract
+{
+       public function amountToPay()
+       {
+               if($this->prop_status & self::MaskPay)
+                       return $this->prop_price;
+               else
+                       return 0;
+       }
+};
+
+?>
\ No newline at end of file