From ac3a8348159ffda35621639b36e7c615425e6715 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 29 Dec 2009 15:02:44 +0000 Subject: [PATCH] server side of now usable order tab git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@367 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- wob/customer.wolf | 18 +++++- wob/order.wolf | 132 +++++++++++++++++++++++++++++++++++++++---- www/inc/db/barcodetable.php | 2 +- www/inc/db/db.php | 14 +++++ www/inc/wext/autoload.php | 4 + www/inc/wext/customer.php | 15 +++++ www/inc/wext/order.php | 115 +++++++++++++++++++++++++++++++++++++ www/inc/wext/ticket.php | 25 ++++++++ 8 files changed, 310 insertions(+), 15 deletions(-) create mode 100644 www/inc/wext/customer.php create mode 100644 www/inc/wext/order.php create mode 100644 www/inc/wext/ticket.php diff --git a/wob/customer.wolf b/wob/customer.wolf index 9f16c2b..edac499 100644 --- a/wob/customer.wolf +++ b/wob/customer.wolf @@ -96,11 +96,23 @@ - - + + + This class encapsulates the most basic information about a customer. + For more complex tasks the Customer class is used. + + + + + + + + + + @@ -113,7 +125,7 @@ - + \ No newline at end of file diff --git a/wob/order.wolf b/wob/order.wolf index 6c9a02a..9036fe4 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -49,8 +49,8 @@ The order is just a reservation for a limited time, application logic must determine the timeout. The order is closed out of the system - the payment status is ignored from now on. Currently not used. - When the order was created - When the order was sent to the customer + When the order was created + When the order was sent to the customer comments made on web form (eg. "urgently needed for dads birthday") how much has been paid already (including used vouchers); @@ -121,11 +121,14 @@ A saleable product other than tickets or vouchers (eg. merchandizing). + This table represents stock. When a product is sold an entry is created in the table item. - - + + + amount that remains in the inventory, or -1 if it is unlimited + usually the EAN code @@ -141,8 +144,8 @@
- - + + This class represents the data of a ticket as stored in the database. uniquely identifies the ticket, this ID is automatically generated when the ticket is created by the server @@ -180,6 +183,17 @@ + + + + + + + + + + + @@ -191,17 +205,26 @@ - - + + used for basic info about items + + + + + + + This class represents an order in its entirety, including any items sold in it. - - + + + + - + @@ -220,6 +243,93 @@
+ + This class represents the main information about an order as shown in lists. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + unix timestamp for the oldest order to be returned (compared with ordertime) + + + + + + + + + + + list of event ids to select + unix timestamp for the oldest order to be returned (compared with ordertime) + + + + + + + + + + + customer to select + unix timestamp for the oldest order to be returned (compared with ordertime) + + + + + + + + + + diff --git a/www/inc/db/barcodetable.php b/www/inc/db/barcodetable.php index 57527be..2f63100 100644 --- a/www/inc/db/barcodetable.php +++ b/www/inc/db/barcodetable.php @@ -11,7 +11,7 @@ // // -class BarcodeTable extends WobTable +abstract class BarcodeTable extends WobTable { private static $NumTicketChars=false; private static function init() diff --git a/www/inc/db/db.php b/www/inc/db/db.php index 5131687..137317c 100644 --- a/www/inc/db/db.php +++ b/www/inc/db/db.php @@ -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) { diff --git a/www/inc/wext/autoload.php b/www/inc/wext/autoload.php index bc716bf..c446bc5 100644 --- a/www/inc/wext/autoload.php +++ b/www/inc/wext/autoload.php @@ -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 index 0000000..9c2fa50 --- /dev/null +++ b/www/inc/wext/customer.php @@ -0,0 +1,15 @@ +, (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 index 0000000..14bd2af --- /dev/null +++ b/www/inc/wext/order.php @@ -0,0 +1,115 @@ +, (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 index 0000000..f56de70 --- /dev/null +++ b/www/inc/wext/ticket.php @@ -0,0 +1,25 @@ +, (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 -- 1.7.2.5