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);
}
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);
}
$cart->set_status(WOCartOrder::Ok);
//create order
- $ord=$cart->createOrderOnDB($isreserve);
+ $ord=$cart->createOrderOnDB($trans,$isreserve);
//return verified cart and order
$trans->setorder($ord);
}
/**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]--;
{
$ret=true;
$evseats=array();
+ $evprice=array();
$now=time();
if($salestop>0)$now+=$salestop*3600;
foreach($this->prop_tickets as &$tick){
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;
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*/
}
/**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);
}