vl2->addWidget(p=new QPushButton(tr("Customer:")),0);
connect(p,SIGNAL(clicked()),this,SLOT(setCustomer()));
vl2->addWidget(cartcustomer=new QLabel("..."));
+ cartcustomer->setAutoFillBackground(true);
vl2->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::HLine);
vl2->addWidget(p=new QPushButton(tr("Invoice Address:")),0);
connect(p,SIGNAL(clicked()),this,SLOT(setInvoiceAddr()));
vl2->addWidget(invoiceaddr=new QLabel("..."));
+ invoiceaddr->setAutoFillBackground(true);
vl2->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::HLine);
vl2->addWidget(p=new QPushButton(tr("Delivery Address:")),0);
connect(p,SIGNAL(clicked()),this,SLOT(setDeliveryAddr()));
vl2->addWidget(deliveryaddr=new QLabel("..."));
+ deliveryaddr->setAutoFillBackground(true);
vl2->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::HLine);
vl2->addSpacing(10);
connect(p,SIGNAL(clicked()),this,SLOT(cartOrder()));
hl->addWidget(p=new QPushButton(tr("Reserve")));
p->setEnabled(req->hasRight(req->RCreateReservation));
- connect(p,SIGNAL(clicked()),this,SLOT(cartOrder()));
+ connect(p,SIGNAL(clicked()),this,SLOT(cartReserve()));
hl->addWidget(p=new QPushButton(tr("Clear")));
connect(p,SIGNAL(clicked()),this,SLOT(initCart()));
QMenu*m=new QMenu(tr("C&art"));
m->addAction(tr("Add &Ticket"),this,SLOT(cartAddTicket()));
m->addAction(tr("Add &Voucher"),this,SLOT(cartAddVoucher()));
- m->addAction(tr("&Remove Item"),this,SLOT(cartRemoveItem()));
+ m->addAction(tr("Add &Shop-Item"),this,SLOT(cartAddItem()));
+ m->addAction(tr("&Remove Line"),this,SLOT(cartRemoveItem()));
m->addAction(tr("&Abort Shopping"),this,SLOT(initCart()));
m->addSeparator();
m->addAction(tr("&Update Shipping Options"),this,SLOT(updateShipping()));
QList<MOShipping>ship=sh.getshipping();
for(int i=0;i<ship.size();i++)
cartship->addItem(ship[i].description(),(int)ship[i].shipid());
+ QPalette pal2=QComboBox().palette();
+ cartship->setPalette(pal2);
+ cartship->setToolTip(QString());
}
void MCartTab::initCart()
{
//clear cart
cartmodel->clear();
- cartmodel->setHorizontalHeaderLabels(QStringList()<<tr("Amount")<<tr("Title")<<tr("Start Time"));
+ cartmodel->setHorizontalHeaderLabels(QStringList()<<tr("Amount")<<tr("Title")<<tr("Start Time")<<tr("Price"));
//clear customer
customer=MOCustomer();
cartcustomer->setText("");
cartcomment->setPlainText("");
//clear shipping
cartship->setCurrentIndex(0);
+ //reset colors
+ resetColor();
+}
+
+void MCartTab::resetColor(bool addronly)
+{
+ QPalette pal=QLabel().palette();
+ cartcustomer->setPalette(pal);
+ cartcustomer->setToolTip(QString());
+ invoiceaddr->setPalette(pal);
+ invoiceaddr->setToolTip(QString());
+ deliveryaddr->setPalette(pal);
+ deliveryaddr->setToolTip(QString());
+ if(!addronly){
+ for(int i=0;i<cartmodel->rowCount();i++)
+ for(int j=0;j<cartmodel->columnCount();j++){
+ QModelIndex idx=cartmodel->index(i,j);
+ cartmodel->setData(idx,QVariant(),Qt::ToolTipRole);
+ cartmodel->setData(idx,QVariant(),Qt::BackgroundRole);
+ }
+ QPalette pal2=QComboBox().palette();
+ cartship->setPalette(pal2);
+ cartship->setToolTip(QString());
+ }
}
void MCartTab::setCustomer()
deliveryaddr->setText("");
invoiceaddr->setText("");
deliveryaddrid=invoiceaddrid=-1;
+ resetColor(true);
//follow up with address dialog
if(!customer.customerid().isNull())
setInvoiceAddr();
customer=d.customer();
deliveryaddr->setText(d.address().fullAddress(customer.fullName()));
deliveryaddrid=d.addressId();
+ deliveryaddr->setPalette(QLabel().palette());
+ deliveryaddr->setToolTip(QString());
}
void MCartTab::setInvoiceAddr()
customer=d.customer();
invoiceaddr->setText(d.address().fullAddress(customer.fullName()));
invoiceaddrid=d.addressId();
+ invoiceaddr->setPalette(QLabel().palette());
+ invoiceaddr->setToolTip(QString());
}
static const int CART_TICKET=1;
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_VALUEROLE=Qt::UserRole+1;//voucher value
static const int CART_TYPEROLE=Qt::UserRole+2;//which is it? ticket or voucher?
hl->addWidget(p=new QPushButton(tr("Cancel")),0);
connect(p,SIGNAL(clicked()),&dlg,SLOT(reject()));
//wait for it
- if(dlg.exec()==QDialog::Accepted){
- //get selection
- QModelIndex idx=tv->currentIndex();
- if(!idx.isValid())return;
- int id=eventmodel->data(eventmodel->index(idx.row(),0),Qt::UserRole).toInt();
- if(id<0)return;
- //copy to cart
- int cr=cartmodel->rowCount();
- cartmodel->insertRows(cr,1);
- cartmodel->setData(cartmodel->index(cr,0),1);
- cartmodel->setData(cartmodel->index(cr,0),id,CART_IDROLE);
- cartmodel->setData(cartmodel->index(cr,0),CART_TICKET,CART_TYPEROLE);
- cartmodel->setData(cartmodel->index(cr,1),eventmodel->data(eventmodel->index(idx.row(),1)));
- cartmodel->setData(cartmodel->index(cr,2),eventmodel->data(eventmodel->index(idx.row(),0)));
- carttable->resizeColumnsToContents();
+ if(dlg.exec()!=QDialog::Accepted)return;
+ //get selection
+ QModelIndex idx=tv->currentIndex();
+ if(!idx.isValid())return;
+ int id=eventmodel->data(eventmodel->index(idx.row(),0),Qt::UserRole).toInt();
+ if(id<0)return;
+ addTicketForEvent(id);
+}
+
+void MCartTab::addTicketForEvent(qint64 id)
+{
+ //get event
+ MTGetEvent ge=MTGetEvent::query(id);
+ if(ge.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error getting event, please try again."));
+ return;
}
+ MOEvent ev=ge.getevent();
+ //get Price Category
+ QList<MOEventPrice> ep=ev.price();
+ if(ep.size()==0){
+ QMessageBox::warning(this,tr("Warning"),tr("This event has no prices associated. Cannot sell tickets."));
+ return;
+ }
+ int pcidx=0;
+ if(ep.size()>1){
+ QDialog d(this);
+ d.setWindowTitle(tr("Select Price Category"));
+ QVBoxLayout*vl;
+ QHBoxLayout*hl;
+ QComboBox*box;
+ QPushButton*p;
+ d.setLayout(vl=new QVBoxLayout);
+ vl->addWidget(new QLabel(tr("Please chose a price category:")));
+ vl->addWidget(box=new QComboBox);
+ for(int i=0;i<ep.size();i++)
+ box->addItem(ep[i].pricecategory().value().name().value()+": "+cent2str(ep[i].price()));
+ box->setEditable(false);
+ vl->addSpacing(10);
+ vl->addStretch(10);
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(10);
+ hl->addWidget(p=new QPushButton(tr("Ok")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ if(d.exec()!=QDialog::Accepted)return;
+ pcidx=box->currentIndex();
+ }
+ //copy to cart
+ int cr=cartmodel->rowCount();
+ cartmodel->insertRows(cr,1);
+ cartmodel->setData(cartmodel->index(cr,0),1);
+ cartmodel->setData(cartmodel->index(cr,0),id,CART_IDROLE);
+ cartmodel->setData(cartmodel->index(cr,0),CART_TICKET,CART_TYPEROLE);
+ cartmodel->setData(cartmodel->index(cr,0),ep[pcidx].pricecategoryid().value(),CART_PRICEIDROLE);
+ cartmodel->setData(cartmodel->index(cr,1),ev.title().value());
+ cartmodel->setData(cartmodel->index(cr,2),ev.startTimeString());
+ QString pcn=cent2str(ep[pcidx].price())+" ("+ep[pcidx].pricecategory().value().name().value()+")";
+ cartmodel->setData(cartmodel->index(cr,3),pcn);
+ carttable->resizeColumnsToContents();
}
void MCartTab::eventOrderTicket()
//activate order tab
emit requestFocus();
//insert event into table
- int cr=cartmodel->rowCount();
- cartmodel->insertRows(cr,1);
- cartmodel->setData(cartmodel->index(cr,0),1);
- cartmodel->setData(cartmodel->index(cr,0),id,CART_IDROLE);
- cartmodel->setData(cartmodel->index(cr,0),CART_TICKET,CART_TYPEROLE);
- cartmodel->setData(cartmodel->index(cr,1),emit currentEventTitle());
- cartmodel->setData(cartmodel->index(cr,2),emit currentEventStart());
- carttable->resizeColumnsToContents();
+ addTicketForEvent(id);
}
void MCartTab::cartAddVoucher()
cartmodel->setData(cartmodel->index(cr,0),price,CART_PRICEROLE);
cartmodel->setData(cartmodel->index(cr,0),value,CART_VALUEROLE);
cartmodel->setData(cartmodel->index(cr,0),CART_VOUCHER,CART_TYPEROLE);
- cartmodel->setData(cartmodel->index(cr,1),tr("Voucher (price: %1, value %2)").arg(cent2str(price)).arg(cent2str(value)));
+ cartmodel->setData(cartmodel->index(cr,1),tr("Voucher (value %1)").arg(cent2str(value)));
+ cartmodel->setData(cartmodel->index(cr,3),cent2str(price));
carttable->resizeColumnsToContents();
}
}
cartmodel->removeRow(idx.row());
}
-void MCartTab::cartOrder()
+void MCartTab::cartOrder(bool isreserve)
{
//sanity checks
- if(cartmodel->rowCount()<1){
- QMessageBox::warning(this,tr("Error"),tr("There is nothing in the order. Ignoring it."));
- return;
- }
- if(!customer.isValid()){
- QMessageBox::warning(this,tr("Error"),tr("Please chose a customer first!"));
- return;
- }
- if(cartship->currentIndex()>0 && deliveryaddrid<0 && invoiceaddrid<0){
- if(QMessageBox::question(this,tr("Shipping"),tr("You have chosen a shipping method, but no address. Are you sure you want to continue?"),QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes)return;
- }
+ if(!canorder(isreserve))return;
+ resetColor(false);
///////////////
//create order
MOCartOrder cord;
QString s=cartcomment->toPlainText().trimmed();
if(s!="")cord.setcomment(s);
//scan tickets & scan vouchers
+ cartTableToOrder(cord);
+ //set shipping info
+ if(cartship->currentIndex()>0)
+ cord.setshippingtypeid(cartship->itemData(cartship->currentIndex()).toInt());
+ /////
+ //send
+ MOOrder ord;
+ if(!orderExecute(cord,ord,isreserve))return;
+ /////
+ //everything ok, move on
+ if(!ord.orderid().isNull()){
+ initCart();
+ MOrderWindow *ow=new MOrderWindow(window(),ord);
+ ow->show();
+ return;
+ }
+ /////
+ //something went wrong: verify cart
+ QMessageBox::warning(this,tr("Warning"),tr("There are problems with the contents of the cart, please check and then try again."));
+ //verify customer
+ verifyOrderCustomer(cord);
+ //verify tickets
+ verifyOrderTickets(cord.tickets());
+ verifyOrderVouchers(cord.vouchers());
+ verifyOrderItems(cord.items());
+}
+
+void MCartTab::cartReserve()
+{
+ cartOrder(true);
+}
+
+bool MCartTab::canorder(bool isreserve)
+{
+ //basics
+ if(cartmodel->rowCount()<1){
+ QMessageBox::warning(this,tr("Error"),tr("There is nothing in the order. Ignoring it."));
+ return false;
+ }
+ if(!customer.isValid()){
+ QMessageBox::warning(this,tr("Error"),tr("Please chose a customer first!"));
+ return false;
+ }
+ if(cartship->currentIndex()>0 && deliveryaddrid<0 && invoiceaddrid<0){
+ if(QMessageBox::question(this,tr("Shipping"),tr("You have chosen a shipping method, but no address. Are you sure you want to continue?"),QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes)return false;
+ }
+ //if for a reservation: tickets only please
+ if(isreserve)
+ for(int i=0;i<cartmodel->rowCount();i++){
+ int tp=cartmodel->data(cartmodel->index(i,0),CART_TYPEROLE).toInt();
+ if(tp!=CART_TICKET){
+ QMessageBox::warning(this,tr("Warning"),tr("Reservations can only contain tickets."));
+ return false;
+ }
+ }
+ //all clear
+ return true;
+}
+
+void MCartTab::cartTableToOrder(MOCartOrder&cord)
+{
for(int i=0;i<cartmodel->rowCount();i++){
QModelIndex idx=cartmodel->index(i,0);
int tp=cartmodel->data(idx,CART_TYPEROLE).toInt();
MOCartTicket ct;
ct.setamount(cartmodel->data(idx).toInt());
ct.seteventid(cartmodel->data(idx,CART_IDROLE).toInt());
+ ct.setpricecategoryid(cartmodel->data(idx,CART_PRICEIDROLE).toInt());
+ ct.setcartlineid(i);
cord.addtickets(ct);
}else
if(tp==CART_VOUCHER){
cv.setamount(cartmodel->data(idx).toInt());
cv.setprice(cartmodel->data(idx,CART_PRICEROLE).toInt());
cv.setvalue(cartmodel->data(idx,CART_VALUEROLE).toInt());
+ cv.setcartlineid(i);
cord.addvouchers(cv);
}
//TODO: product/items
}
- //set shipping info
- cord.setshippingtypeid(cartship->itemData(cartship->currentIndex()).toInt());
- //send
- MTCreateOrder co=req->queryCreateOrder(cord);
- if(co.hasError()){
- QMessageBox::warning(this,tr("Warning"),tr("Error while creating order: %1").arg(co.errorString()));
- return;
+}
+
+bool MCartTab::orderExecute(MOCartOrder&cord,MOOrder&ord,bool isreserve)
+{
+ if(isreserve){
+ MTCreateReservation co=req->queryCreateReservation(cord);
+ if(co.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while creating reservation: %1").arg(co.errorString()));
+ return false;
+ }
+ ord=co.getorder();
+ cord=co.getcart();
+ }else{
+ MTCreateOrder co=req->queryCreateOrder(cord);
+ if(co.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while creating order: %1").arg(co.errorString()));
+ return false;
+ }
+ ord=co.getorder();
+ cord=co.getcart();
+ }
+ return true;
+}
+
+void MCartTab::verifyOrderCustomer(MOCartOrder&cord)
+{
+ QPalette red=QLabel().palette();red.setColor(QPalette::Window,Qt::red);
+ if(cord.customerid() != customer.customerid()){
+ customer=MOCustomer();
+ cartcustomer->setPalette(red);
+ cartcustomer->setToolTip(tr("The customer is not valid, please chose another one."));
+ }
+ if(deliveryaddrid>=0 && cord.deliveryaddressid() != deliveryaddrid){
+ deliveryaddrid=-1;
+ deliveryaddr->setPalette(red);
+ deliveryaddr->setToolTip(tr("The delivery address is not valid, please chose another one."));
+ }
+ if(invoiceaddrid>=0 && cord.invoiceaddressid() != invoiceaddrid){
+ invoiceaddrid=-1;
+ invoiceaddr->setPalette(red);
+ invoiceaddr->setToolTip(tr("The invoice address is not valid, please chose another one."));
+ }
+ if(cartship->currentIndex()>0 && cord.shippingtypeid().isNull()){
+ QPalette red2=QComboBox().palette();red2.setColor(QPalette::Window,Qt::red);
+ cartship->setPalette(red2);
+ cartship->setToolTip(tr("Shipping Type does not exist or you do not have permission to use it."));
+ }
+}
+
+void MCartTab::verifyOrderTickets(const QList<MOCartTicket>&ticks)
+{
+ for(int i=0;i<ticks.size();i++){
+ if(ticks[i].status()!=MOCartTicket::Ok){
+ //find it
+ int j=ticks[i].cartlineid();
+ if(j<0 || j>=cartmodel->rowCount())continue;
+ QModelIndex idx0=cartmodel->index(j,0);
+ if(cartmodel->data(idx0,CART_TYPEROLE).toInt() != CART_TICKET)continue;
+ QModelIndex idx1=cartmodel->index(j,1);
+ cartmodel->setData(idx1,Qt::red,Qt::BackgroundRole);
+ //check state, color it
+ switch(ticks[i].status().value()){
+ case MOCartTicket::EventOver:
+ cartmodel->setData(idx1,tr("The event is already over, please remove this entry."),Qt::ToolTipRole);
+ break;
+ case MOCartTicket::TooLate:
+ cartmodel->setData(idx1,tr("You cannot order tickets for this event anymore, ask a more privileged user."),Qt::ToolTipRole);
+ break;
+ case MOCartTicket::Exhausted:{
+ cartmodel->setData(idx0,Qt::red,Qt::BackgroundRole);
+ QString tt=tr("The event is (almost) sold out, there are %1 tickets left.").arg(ticks[i].maxamount());
+ cartmodel->setData(idx0,tt,Qt::ToolTipRole);
+ cartmodel->setData(idx1,tt,Qt::ToolTipRole);
+ break;}
+ case MOCartTicket::Invalid:
+ cartmodel->setData(idx1,tr("The event does not exist or there is another serious problem, please remove this entry."),Qt::ToolTipRole);
+ break;
+ default:break;//ignore all others
+ }
+ }
+ }
+}
+
+void MCartTab::verifyOrderVouchers(const QList<MOCartVoucher>&voucs)
+{
+ for(int i=0;i<voucs.size();i++){
+ if(voucs[i].status()!=MOCartVoucher::Ok){
+ //find it
+ int j=voucs[i].cartlineid();
+ if(j<0 || j>=cartmodel->rowCount())continue;
+ QModelIndex idx0=cartmodel->index(j,0);
+ if(cartmodel->data(idx0,CART_TYPEROLE).toInt() != CART_VOUCHER)continue;
+ QModelIndex idx1=cartmodel->index(j,1);
+ cartmodel->setData(idx1,Qt::red,Qt::BackgroundRole);
+ //check state, color it
+ switch(voucs[i].status().value()){
+ case MOCartVoucher::InvalidValue:
+ cartmodel->setData(idx1,tr("You do not have permission to create vouchers with this value, please remove it."),Qt::ToolTipRole);
+ break;
+ case MOCartVoucher::InvalidPrice:
+ cartmodel->setData(idx1,tr("The price tag of this voucher is not valid, please remove and recreate it."),Qt::ToolTipRole);
+ break;
+ default:break;//ignore all others
+ }
+ }
}
- initCart();
- MOrderWindow *ow=new MOrderWindow(window(),co.getorder());
- ow->show();
+}
+
+void MCartTab::verifyOrderItems(const QList<MOCartItem>&)
+{
+ //TODO: implement items
}
/********************************************************************************/
--- /dev/null
+<?
+//
+// PHP Implementation: cart
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class WOCartOrder extends WOCartOrderAbstract
+{
+ const LateSale=-1;
+ const AfterSale=-2;
+
+ /**called by the CreateOrder and CreateReservation transactions*/
+ public static function createOrder($trans)
+ {
+ //get cart object
+ $cart=$trans->getcart();
+ if(!is_a($cart,"WOCartOrder")){
+ $trans->abortWithError(tr("Not a valid cart object."));
+ return;
+ }
+ //get permissions
+ global $db;
+ $isreserve=false;
+ $vanyval=false;
+ $vdiffprice=false;
+ $tsalestop=0;
+ if(is_a($trans,"WTrCreateOrder")){
+ $vanyval=$trans->havePrivilege(WTrCreateOrder::Priv_AnyVoucherValue);
+ $vdiffprice=$trans->havePrivilege(WTrCreateOrder::Priv_DiffVoucherValuePrice);
+ $tsalestop=$db->getConfig("OrderStop")+0;
+ if($tsalestop<0)$tsalestop=0;
+ if($trans->havePrivilege(WTrCreateOrder::Priv_LateSale))
+ $tsalestop=self::LateSale;
+ if($trans->havePrivilege(WTrCreateOrder::Priv_AfterTheFactSale))
+ $tsalestop=self::AfterSale;
+ }else
+ if(is_a($trans,"WTrCreateReservation")){
+ $isreserve=true;
+ $tsalestop=$db->getConfig("ReserveStop")+0;
+ if($tsalestop<0)$tsalestop=0;
+ if($trans->havePrivilege(WTrCreateReservation::Priv_LateReserve))
+ $tsalestop=0;
+ }else{
+ $trans->abortWithError(tr("CreateSale called from an unknown transaction."));
+ return;
+ }
+ //verify necessary elements and content
+ $very=true;
+ $very&=$cart->verifyCustomer($trans);
+ $very&=$cart->verifyShipping($trans);
+
+ $very&=$cart->verifyTickets($trans,$tsalestop);
+ if($isreserve){
+ if(count($cart->get_vouchers())>0 || count($cart->get_items())>0){
+ $trans->abortWithError(tr("Reservations must not contain anything but tickets."));
+ return;
+ }
+ }else{
+ $very&=$cart->verifyVouchers($trans,$vanyval,$vdiffprice);
+ $very&=$cart->verifyItems($trans);
+ }
+ //verification successful?
+ if(!$very){
+ //no: set verified cart and return to caller
+ $cart->set_status(WOCartOrder::Invalid);
+ $trans->setcart($cart);
+ return;
+ }
+ $cart->set_status(WOCartOrder::Ok);
+ //create order
+ $ord=$cart->createOrderOnDB($isreserve);
+
+ //return verified cart and order
+ $trans->setorder($ord);
+ $trans->setcart($cart);
+ }
+
+ /**helper function for createOrder: verifies customer settings*/
+ private function verifyCustomer($trans)
+ {
+ //check customer exists
+ $cust=WTcustomer::getFromDB($this->prop_customerid);
+ if(!is_a($cust,"WTcustomer")){
+ $this->prop_customerid=null;
+ $this->prop_deliveryaddressid=null;
+ $this->prop_invoiceaddressid=null;
+ return false;
+ }
+ //check addresses belong to customer
+ $ret=true;
+ if($this->prop_invoiceaddressid!==null){
+ $addr=WTaddress::getFromDB($this->prop_invoiceaddressid);
+ if(!is_a($addr,"WTaddress")){
+ $this->prop_invoiceaddressid=null;
+ $ret=false;
+ }else{
+ if($addr->customerid != $this->prop_customerid){
+ $this->prop_invoiceaddressid=null;
+ $ret=false;
+ }
+ }
+ }
+ if($this->prop_deliveryaddressid!==null){
+ $addr=WTaddress::getFromDB($this->prop_deliveryaddressid);
+ if(!is_a($addr,"WTaddress")){
+ $this->prop_deliveryaddressid=null;
+ $ret=false;
+ }else{
+ if($addr->customerid != $this->prop_customerid){
+ $this->prop_deliveryaddressid=null;
+ $ret=false;
+ }
+ }
+ }
+ return $ret;
+ }
+
+ /**helper function for createOrder: verifies customer settings*/
+ private function verifyShipping($trans)
+ {
+ if($this->prop_shippingtypeid !== null){
+ $ship=WTshipping::getFromDB($this->prop_shippingtypeid);
+ if(!is_a($ship,"WTshipping")){
+ $this->prop_shippingtypeid=null;
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**helper for helper verifyTickets: gets statistics about sold tickets*/
+ private function eventTicketStatistics($evid,$cap)
+ {
+ global $db;
+ $ret=array("all"=>$cap);
+ $epcs=WTeventprice::selectFromDB("eventid=".$db->escapeInt($evid));
+ foreach($epcs as $pc){
+ $ret[$pc->pricecategoryid]=$pc->maxavailable;
+ }
+ $ticks=WTticket::selectFromDB("eventid=".$db->escapeInt($evid));
+ foreach($ticks as $t){
+ if(($t & WTticket::MaskBlock)==0)continue;
+ $ret["all"]--;
+ if($t->pricecategoryid !== null)
+ $ret[$t->pricecategoryid]--;
+ }
+ return $ret;
+ }
+
+ /**helper function for createOrder: verifies customer settings*/
+ private function verifyTickets($trans,$salestop)
+ {
+ $ret=true;
+ $evseats=array();
+ $now=time();
+ if($salestop>0)$now+=$salestop*3600;
+ foreach($this->prop_tickets as &$tick){
+ //assume ok
+ $tick->set_status(WOCartTicket::Ok);
+ //check event exists
+ $evid=$tick->get_eventid();
+ $ev=WTevent::getFromDB($evid);
+ if(!is_a($ev,"WTevent")){
+ $tick->set_status(WOCartTicket::Invalid);
+ $ret=false;
+ continue;
+ }
+ if(!array_key_exists($evid,$evseats))
+ $evseats[$evid]=$this->eventTicketStatistics($evid,$ev->capacity);
+ //verify price category
+ $pcid=$tick->get_pricecategoryid();
+ if(!array_key_exists($pcid,$evseats[$evid])){
+ $tick->set_status(WOCartTicket::Invalid);
+ $ret=false;
+ continue;
+ }
+ //check enough seats for event
+ if($tick->get_amount() > $evseats[$evid]["all"]){
+ $tick->set_status(WOCartTicket::Exhausted);
+ $tick->set_amount($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]);
+ $ret=false;
+ }
+ $evseats[$evid][$pcid]-=$tick->get_amount();
+ //check sale time
+ if($salestop==self::AfterSale)continue;
+ if($salestop==self::LateSale){
+ if($now>$ev->endtime){
+ $tick->set_status(WOCartTicket::TooLate);
+ $ret=false;
+ }
+ }else{
+ if($now>$ev->starttime){
+ $tick->set_status(WOCartTicket::TooLate);
+ $ret=false;
+ }
+ }
+ }
+ return $ret;
+ }
+
+ /**helper function for createOrder: verifies customer settings*/
+ private function verifyVouchers($trans,$vanyval,$vdiffprice)
+ {
+ //TODO: implement
+ return true;
+ }
+
+ /**helper function for createOrder: verifies customer settings*/
+ private function verifyItems($trans)
+ {
+ //TODO: implement items
+ return true;
+ }
+
+ /**helper function for createOrder: creates the order on the database*/
+ private function createOrderOnDB($trans)
+ {
+ //create order
+ $ord=WTorder::newRow();
+ //create tickets
+ //create vouchers
+ //create items
+ //update address use
+ //return created order
+ return WOOrder::fromTableorder($ord);
+ }
+};
+
+?>
\ No newline at end of file