cart, ordering, reserving works again
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 7 Jan 2010 15:44:09 +0000 (15:44 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 7 Jan 2010 15:44:09 +0000 (15:44 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@407 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/carttab.cpp
wob/cart.wolf
www/inc/db/barcodetable.php
www/inc/wext/cart.php
www/inc/wext/order.php

index 5676552..995ff19 100644 (file)
@@ -240,8 +240,8 @@ static const int CART_TICKET=1;
 static const int CART_VOUCHER=2;
 
 static const int CART_IDROLE=Qt::UserRole;//ticket id
-static const int CART_PRICEROLE=Qt::UserRole;//voucher price
-static const int CART_PRICEIDROLE=CART_PRICEROLE;//for tickets: price category id
+static const int CART_PRICEIDROLE=Qt::UserRole+3;//for tickets: price category id
+static const int CART_PRICEROLE=Qt::UserRole+3;//voucher price
 static const int CART_VALUEROLE=Qt::UserRole+1;//voucher value
 static const int CART_TYPEROLE=Qt::UserRole+2;//which is it? ticket or voucher?
 
index 0fd5a81..09a1eb1 100644 (file)
@@ -67,7 +67,7 @@
        <Class name="CartVoucher">
                <Enum name="ValidationState">
                        <Value name="Ok">The voucher can be sold</Value>
-                       <Value name="InvalidValue">The value is not one of the allowed ones and you do not have the privilege to set an arbitrary one, or the value is negative.</Value>
+                       <Value name="InvalidValue">The value is not one of the allowed ones and you do not have the privilege to set an arbitrary one, or the value is negative or zero.</Value>
                        <Value name="InvalidPrice">The price is negative, the price property is ignored if you do not have the privilege to chose a price that differs from the value</Value>
                </Enum>
                <Property name="cartlineid" type="int" optional="1">optional property that can be used by the calling process to distinguish lines in the cart, the server must preserve it unchanged</Property>
index 2f63100..8a4a53e 100644 (file)
 abstract class BarcodeTable extends WobTable
 {
        private static $NumTicketChars=false;
+       private static $NumVoucherChars=false;
        private static function init()
        {
+               global $db;
                if(self::$NumTicketChars===false){
                        self::$NumTicketChars=$db->getConfig("TicketIDChars")+0;
                        if(self::$NumTicketChars<=5)self::$NumTicketChars=10;
                }
+               if(self::$NumVoucherChars===false){
+                       self::$NumVoucherChars=$db->getConfig("VoucherIDChars")+0;
+                       if(self::$NumVoucherChars<=5)self::$NumVoucherChars=10;
+               }
        }
        public static function getNewTicketId()
        {
+               global $db;
                self::init();
                do{
                        $tid=getCode39ID(self::$NumTicketChars,RND_TICKET);
@@ -32,9 +39,10 @@ abstract class BarcodeTable extends WobTable
        }
        public static function getNewVoucherId()
        {
+               global $db;
                self::init();
                do{
-                       $tid=getCode39ID(self::$NumTicketChars,RND_VOUCHER);
+                       $tid=getCode39ID(self::$NumVoucherChars,RND_VOUCHER);
                        $res=$db->select("voucher","voucherid","voucherid=".$db->escapeString($tid));
                        if(count($res)==0)return $tid;
                }while(true);
index d0b4040..e8253c6 100644 (file)
@@ -75,7 +75,7 @@ class WOCartOrder extends WOCartOrderAbstract
                }
                $cart->set_status(WOCartOrder::Ok);
                //create order
-               $ord=$cart->createOrderOnDB($isreserve);
+               $ord=$cart->createOrderOnDB($trans,$isreserve);
                
                //return verified cart and order
                $trans->setorder($ord);
@@ -136,17 +136,19 @@ class WOCartOrder extends WOCartOrderAbstract
        }
        
        /**helper for helper verifyTickets: gets statistics about sold tickets*/
-       private function eventTicketStatistics($evid,$cap)
+       private function eventTicketStatistics($evid,$cap,&$price)
        {
                global $db;
                $ret=array("all"=>$cap);
+               $price[$evid]=array();
                $epcs=WTeventprice::selectFromDB("eventid=".$db->escapeInt($evid));
                foreach($epcs as $pc){
                        $ret[$pc->pricecategoryid]=$pc->maxavailable;
+                       $price[$evid][$pc->pricecategoryid]=$pc->price;
                }
                $ticks=WTticket::selectFromDB("eventid=".$db->escapeInt($evid));
                foreach($ticks as $t){
-                       if(($t & WTticket::MaskBlock)==0)continue;
+                       if(($t->status & WTticket::MaskBlock)==0)continue;
                        $ret["all"]--;
                        if($t->pricecategoryid !== null)
                                $ret[$t->pricecategoryid]--;
@@ -159,6 +161,7 @@ class WOCartOrder extends WOCartOrderAbstract
        {
                $ret=true;
                $evseats=array();
+               $evprice=array();
                $now=time();
                if($salestop>0)$now+=$salestop*3600;
                foreach($this->prop_tickets as &$tick){
@@ -173,27 +176,31 @@ class WOCartOrder extends WOCartOrderAbstract
                                continue;
                        }
                        if(!array_key_exists($evid,$evseats))
-                               $evseats[$evid]=$this->eventTicketStatistics($evid,$ev->capacity);
-                       //verify price category
+                               $evseats[$evid]=$this->eventTicketStatistics($evid,$ev->capacity,$evprice);
+                       //verify price category, set price
                        $pcid=$tick->get_pricecategoryid();
                        if(!array_key_exists($pcid,$evseats[$evid])){
                                $tick->set_status(WOCartTicket::Invalid);
                                $ret=false;
                                continue;
                        }
+                       $tick->set_price($evprice[$evid][$pcid]);
                        //check enough seats for event
+//                     print_r($evseats);print_r($tick);
                        if($tick->get_amount() > $evseats[$evid]["all"]){
                                $tick->set_status(WOCartTicket::Exhausted);
-                               $tick->set_amount($evseats[$evid]["all"]);
+                               $tick->set_maxamount($evseats[$evid]["all"]);
                                $ret=false;
                        }
                        $evseats[$evid]["all"]-=$tick->get_amount();
                        //check enough seats for category
                        if($tick->get_amount() > $evseats[$evid][$pcid]){
                                $tick->set_status(WOCartTicket::Exhausted);
-                               $tick->set_amount($evseats[$evid][$pcid]);
+                               $tick->set_maxamount($evseats[$evid][$pcid]);
                                $ret=false;
                        }
+//                     print("......\n");
+//                     print_r($evseats);print_r($tick);
                        $evseats[$evid][$pcid]-=$tick->get_amount();
                        //check sale time
                        if($salestop==self::AfterSale)continue;
@@ -216,7 +223,40 @@ class WOCartOrder extends WOCartOrderAbstract
        private function verifyVouchers($trans,$vanyval,$vdiffprice)
        {
                //TODO: implement
-               return true;
+               $okvp=array();
+               foreach(explode(' ',$GLOBALS['db']->getConfig('ValidVouchers')) as $vp)
+                       $okvp[]=$vp+0;
+               $ret=true;
+               foreach($this->prop_vouchers as &$vou){
+                       //assume ok
+                       $vou->set_status(WOCartVoucher::Ok);
+                       //check value
+                       $vv=$vou->get_value()+0;
+                       if($vv<=0){
+                               $vou->set_status(WOCartVoucher::InvalidValue);
+                               $ret=false;
+                               continue;
+                       }
+                       if(!$vanyval)
+                               if(!in_array($vv,$okvp)){
+                                       $vou->set_status(WOCartVoucher::InvalidValue);
+                                       $ret=false;
+                                       continue;
+                               }
+                       //check price
+                       if($vdiffprice){
+                               $vp=$vou->get_price()+0;
+                               if($vp<0){
+                                       $vou->set_status(WOCartVoucher::InvalidPrice);
+                                       $ret=false;
+                                       continue;
+                               }
+                       }else{
+                               //price to be ignored, so simply overwrite it
+                               $vou->set_price($vv);
+                       }
+               }
+               return $ret;
        }
        
        /**helper function for createOrder: verifies customer settings*/
@@ -227,14 +267,67 @@ class WOCartOrder extends WOCartOrderAbstract
        }
        
        /**helper function for createOrder: creates the order on the database*/
-       private function createOrderOnDB($trans)
+       private function createOrderOnDB($trans,$isreserve)
        {
+               global $session;
                //create order
                $ord=WTorder::newRow();
+               $ord->customerid=$this->prop_customerid;
+               $ord->invoiceaddress=$this->prop_invoiceaddressid;
+               $ord->deliveryaddress=$this->prop_deliveryaddressid;
+               $ord->soldby=$session->currentUserName();
+               $ord->ordertime=time();
+               $ord->comments=$this->prop_comment;
+               $ord->amountpaid=0;
+               $ord->shippingtype=$this->prop_shippingtypeid;
+               $ship=WTshipping::getFromDB($this->prop_shippingtypeid);
+               if(is_a($ship,"WTshipping"))
+                       $ord->shippingcosts=$ship->cost;
+               if($isreserve)
+                       $ord->status=WTorder::Reserved;
+               else
+                       $ord->status=WTorder::Placed;
+               if(!$ord->insert()){
+                       $trans->abortWithError(tr("DB error while inserting order."));
+                       return;
+               }
                //create tickets
+               if($isreserve)
+                       $tstat=WTticket::Reserved;
+               else
+                       $tstat=WTticket::Ordered;
+               foreach($this->prop_tickets as $tick){
+                       $tck=WTticket::newRow();
+                       $tck->orderid=$ord->orderid;
+                       $tck->eventid=$tick->get_eventid();
+                       $tck->price=$tick->get_price();
+                       $tck->pricecategoryid=$tick->get_pricecategoryid();
+                       $tck->status=$tstat;
+                       for($i=0;$i<$tick->get_amount();$i++)
+                               $tck->insert();
+               }
                //create vouchers
-               //create items
+               foreach($this->prop_vouchers as $vou){
+                       $v=WTvoucher::newRow();
+                       $v->orderid=$ord->orderid;
+                       $v->price=$vou->get_price();
+                       $v->value=$vou->get_value();
+                       $v->isused=false;
+                       for($i=0;$i<$vou->get_amount();$i++)
+                               $v->insert();
+               }
+               //TODO: create items
                //update address use
+               $ad=WTaddress::getFromDB($ord->invoiceaddress);
+               if(is_a($ad,"WTaddress")){
+                       $ad->lastused=time();
+                       $ad->update();
+               }
+               $ad=WTaddress::getFromDB($ord->deliveryaddress);
+               if(is_a($ad,"WTaddress")){
+                       $ad->lastused=time();
+                       $ad->update();
+               }
                //return created order
                return WOOrder::fromTableorder($ord);
        }
index 3c77a78..ff1e1bc 100644 (file)
@@ -384,6 +384,7 @@ class WOOrder extends WOOrderAbstract
        /**called from the ReservationToOrder transaction*/
        public static function reservation2Order($trans)
        {
+               global $db;
                //get order
                $ord=WTorder::getFromDB($trans->getorderid());
                if($ord===false){
@@ -396,8 +397,14 @@ class WOOrder extends WOOrderAbstract
                        return;
                }
                //change state
-               $ord->status = WTorder::Sold;
+               $ord->status = WTorder::Placed;
                $ord->update();
+               //change tickets
+               $ticks=WTticket::selectFromDB("orderid=".$db->escapeInt($ord->orderid));
+               foreach($ticks as $tick){
+                       $tick->status=WTticket::Ordered;
+                       $tick->update();
+               }
                //return
                $trans->setorder(WOOrder::fromTableorder($ord));
        }