From: konrad Date: Sun, 30 Mar 2008 18:33:21 +0000 (+0000) Subject: *return tickets X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b837fc016544dfe8cd8b1ad96f82de157dbce29d;p=konrad%2Fsmoke.git *return tickets *find orders by ticket ID git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@152 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/doc/prog_protocol.html b/doc/prog_protocol.html index 17232e7..2f5409e 100644 --- a/doc/prog_protocol.html +++ b/doc/prog_protocol.html @@ -562,6 +562,10 @@ The ordershipped transaction is used to mark an order as shipped. This The cancelorder transaction is used to mark an order as cancelled. It also marks all tickets inside the order as cancelled and voids any vouchers in it. This transaction is only legal for orders in the "placed" state. +

Searching for an Order

+ +The orderbyticket transaction can be used to find an order by a ticket ID from that order. The request contains the ticket ID, the response contains the order ID or returns as error if not found. + @@ -593,6 +597,10 @@ Only tickets that have status "bought" and whose order have payment status "ok" The changeticketprice transaction can be used to change the price of a ticket. The request contains the ticket-ID and the new price in cent separated by a newline. The response is empty. +

Returning Tickets

+ +The ticketreturn transaction can be used to return a ticket that has not been used yet. The request contains the ticket-ID, the response is empty. + diff --git a/src/order.cpp b/src/order.cpp index 901fc08..f213060 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -375,14 +375,28 @@ void MOrder::updateTicketPrice(QString tid,int price) { for(int i=0;irequest("ticketreturn",m_id.toUtf8())) + return QT_TRANSLATE_NOOP("MTicket","Failed to execute request"); + if(req->responseStatus()!=MWebRequest::Ok) + return QString::fromUtf8(req->responseBody()); + m_status=Refund; + return ""; +} + +int MTicket::amountToPay()const +{ + if(m_status==Bought || m_status==Used)return m_price; + else return 0; +} diff --git a/src/order.h b/src/order.h index 05818c5..6650abd 100644 --- a/src/order.h +++ b/src/order.h @@ -56,6 +56,9 @@ class MTicket /**returns the price of the ticket as localized string*/ QString priceString()const; + /**returns the amount that is to be paid for this ticket; this is identical to the price if the ticket is bought or used, it is zero otherwise*/ + int amountToPay()const; + /**returns the ID of the event the ticket belongs to*/ qint32 eventID()const; @@ -133,6 +136,9 @@ class MTicket /**updates the price of this ticket, calls DB*/ void updatePrice(int); + /**attempts to return the ticket; returns empty string on success, error message on failure*/ + QString ticketReturn(); + protected: friend class MOrder; /**sets the order-ID of the ticket, used by MOrder*/ @@ -300,6 +306,9 @@ class MOrder /**used to update the price of a ticket, calls DB*/ void updateTicketPrice(QString,int); + /**used to cancel/return a ticket from this order; returns empty string on success, error message on failure*/ + QString ticketReturn(QString); + /**create a new order in the DB; returns it*/ MOrder createOrder(QString type="createorder"); diff --git a/src/orderwin.cpp b/src/orderwin.cpp index 3463d2f..1ab759b 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -57,6 +57,8 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o) m->addSeparator(); m->addAction(tr("Ch&ange Ticket-Price..."),this,SLOT(changeTicket())) ->setEnabled(req->hasRole("changeticketprice")); + m->addAction(tr("&Return Ticket..."),this,SLOT(ticketReturn())) + ->setEnabled(req->hasRole("ticketreturn")); m->addSeparator(); m->addAction(tr("&Close"),this,SLOT(close())); m=mb->addMenu(tr("&Payment")); @@ -375,6 +377,36 @@ void MOrderWindow::changeTicket() updateTable(); } +void MOrderWindow::ticketReturn() +{ + if(!m_order.isValid())return; + //get ticket selection + QModelIndexList lst=m_tickettable->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=m_ticketmodel->index(lst[0].row(),0); + QString id=m_ticketmodel->data(idx).toString(); + if(id=="")return; + //find ticket + QListtickets=m_order.tickets(); + MTicket tick; + for(int i=0;isetText(m_order.totalPriceString()); + updateTable(); + if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8())); +} + void MOrderWindow::cancelOrder() { if(QMessageBox::question(this,tr("Cancel Order?"),tr("Cancel this order now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)!=QMessageBox::Yes)return; diff --git a/src/orderwin.h b/src/orderwin.h index 8a2c5fe..54b3836 100644 --- a/src/orderwin.h +++ b/src/orderwin.h @@ -66,6 +66,8 @@ class MOrderWindow:public QMainWindow /**change a ticket price*/ void changeTicket(); + /**return a ticket*/ + void ticketReturn(); /**cancel the order*/ void cancelOrder(); diff --git a/src/overview.cpp b/src/overview.cpp index c9e63c6..be2931b 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -76,10 +76,9 @@ MOverview::MOverview(MWebRequest*mw,QString pk) m->addAction(tr("Add &Voucher"),this,SLOT(cartAddVoucher()))->setEnabled(false); m->addAction(tr("&Remove Item"),this,SLOT(cartRemoveItem())); m->addAction(tr("&Abort Shopping"),this,SLOT(initCart())); - m->addSeparator(); - m->addAction(tr("&Show all orders")); - m=mb->addMenu(tr("C&onfigure")); + m=mb->addMenu(tr("&Misc")); + m->addAction(tr("&Return ticket..."),this,SLOT(ticketReturn())); //tabs setCentralWidget(tab=new QTabWidget); @@ -185,6 +184,10 @@ MOverview::MOverview(MWebRequest*mw,QString pk) vl->addWidget(p=new QPushButton(tr("Details...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderDetails())); p->setEnabled(req->hasRole("getorder")); + vl->addSpacing(15); + vl->addWidget(p=new QPushButton(tr("Find by Ticket...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(orderByTicket())); + p->setEnabled(req->hasRole("orderbyticket")); vl->addStretch(10); //Entrance Control Tab @@ -947,6 +950,32 @@ void MOverview::orderDetails() om->show(); } +void MOverview::orderByTicket() +{ + //get selected order + bool ok; + QString tid=QInputDialog::getText(this,tr("Enter Ticket"),tr("Please enter the ID of one of the tickets of the order you seek:"),QLineEdit::Normal,"",&ok); + if(!ok || tid=="")return; + //request it + if(!req->request("orderbyticket",tid.toUtf8())){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to query server.")); + return; + } + if(req->responseStatus()!=MWebRequest::Ok){ + QMessageBox::warning(this,tr("Warning"),tr(req->responseBody())); + return; + } + int id=req->responseBody().trimmed().toInt(&ok); + if(!ok || id<0){ + QMessageBox::warning(this,tr("Warning"),tr("Server returned an invalid order ID.")); + return; + } + //open order window + MOrderWindow *om=new MOrderWindow(this,req,MOrder(req,id)); + om->setAttribute(Qt::WA_DeleteOnClose); + om->show(); +} + void MOverview::uploadTemplate() { //get file @@ -969,6 +998,28 @@ void MOverview::uploadTemplate() QMessageBox::warning(this,tr("Warning"),tr("Unable to upload the template.")); } +void MOverview::ticketReturn() +{ + //get ticket + bool ok; + QString tid=QInputDialog::getText(this,tr("Return Ticket"),tr("Please enter the ticket ID to return:"),QLineEdit::Normal,"",&ok); + if(!ok || tid=="")return; + MTicket tick(req,tid); + if(!tick.isValid()){ + QMessageBox::warning(this,tr("Warning"),tr("This is not a valid ticket.")); + return; + } + //check state + if(tick.status()!=MTicket::Bought && tick.status()!=MTicket::Reserved){ + QMessageBox::warning(this,tr("Warning"),tr("This ticket cannot be returned, it has already been used or is in the wrong state.")); + return; + } + //submit + QString r=tick.ticketReturn(); + if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8())); +} + + /**********************************************/ MPasswordChange::MPasswordChange(QWidget*par,QString user) diff --git a/src/overview.h b/src/overview.h index 99b4971..6e5fb98 100644 --- a/src/overview.h +++ b/src/overview.h @@ -120,6 +120,11 @@ class MOverview:public QMainWindow /**upload Templates*/ void uploadTemplate(); + /**return a ticket*/ + void ticketReturn(); + /**find an order by ticket*/ + void orderByTicket(); + private: //my session object QPointerreq; diff --git a/www/inc/classes/order.php b/www/inc/classes/order.php index ad17315..cf4ef41 100644 --- a/www/inc/classes/order.php +++ b/www/inc/classes/order.php @@ -627,4 +627,22 @@ function orderCancelXml($oid) die(tr("Wrong state, cannot set order to cancelled.")); } } + +//find an order +function orderByTicketXml($ticket) +{ + global $db; + $res=$db->select("ticket","orderid","ticketid=".$db->escapeString($ticket)); + if(count($res)<1){ + header("X-MagicSmoke-Status: Error"); + die(tr("Ticket not found.")); + } + if($res[0]["orderid"]===NULL || $res[0]["orderid"]<0){ + header("X-MagicSmoke-Status: Error"); + die(tr("Ticket has no order.")); + } + header("X-MagicSmoke-Status: Ok"); + echo $res[0]["orderid"]; +} + ?> \ No newline at end of file diff --git a/www/inc/classes/ticket.php b/www/inc/classes/ticket.php index 1d5dc45..95c112f 100644 --- a/www/inc/classes/ticket.php +++ b/www/inc/classes/ticket.php @@ -276,4 +276,25 @@ function changeTicketPriceXml($data) header("X-MagicSmoke-Status: Ok"); } +function ticketReturnXml($tid) +{ + //get ticket + global $db; + $db->beginTransaction(); + $res=$db->select("ticket","ticketid,status","ticketid=".$db->escapeString($tid)); + if(count($res)<1){ + $db->rollbackTransaction(); + header("X-MagicSmoke-Status: Error"); + die(tr("Unable to find this ticket.")); + } + if($res[0]["status"]!=TICKET_BOUGHT && $res[0]["status"]!=TICKET_RESERVED){ + $db->rollbackTransaction(); + header("X-MagicSmoke-Status: Error"); + die(tr("Ticket cannot be returned.")); + } + $db->update("ticket",array("status"=>TICKET_CANCELLED),"ticketid=".$db->escapeString($tid)); + $db->commitTransaction(); + header("X-MagicSmoke-Status: Ok"); +} + ?> \ No newline at end of file diff --git a/www/machine.php b/www/machine.php index b66d17c..be9bf78 100644 --- a/www/machine.php +++ b/www/machine.php @@ -23,8 +23,8 @@ $ALLOWEDREQUESTS=array( tr("geteventlist"),tr("geteventdata"),tr("seteventdata"),tr("eventsummary"),tr("cancelevent"),//event infos tr("getroomdata"),tr("setroomdata"),//room infos tr("getcustomerlist"),tr("getcustomer"),tr("setcustomer"), //customer info - tr("checkorder"),tr("createorder"),tr("createsale"),tr("getorderlist"),tr("getorder"),tr("orderpay"),tr("orderrefund"),tr("ordershipped"),tr("cancelorder"), //sell/order stuff - tr("getticket"),tr("useticket"),tr("changeticketprice"),//ticket management + tr("checkorder"),tr("createorder"),tr("createsale"),tr("getorderlist"),tr("getorder"),tr("orderpay"),tr("orderrefund"),tr("ordershipped"),tr("cancelorder"),tr("orderbyticket"), //sell/order stuff + tr("getticket"),tr("useticket"),tr("changeticketprice"),tr("ticketreturn"),//ticket management tr("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates ); /**contains the low-level request name from the client*/ @@ -312,6 +312,11 @@ if($SMOKEREQUEST=="cancelorder"){ orderCancelXml(trim($REQUESTDATA)); exit(); } +//find an order +if($SMOKEREQUEST=="orderbyticket"){ + orderByTicketXml(trim($REQUESTDATA)); + exit(); +} //get a ticket if($SMOKEREQUEST=="getticket"){ @@ -328,6 +333,11 @@ if($SMOKEREQUEST=="changeticketprice"){ changeTicketPriceXml(trim($REQUESTDATA)); exit(); } +//return a ticket: cancels it +if($SMOKEREQUEST=="ticketreturn"){ + ticketReturnXml(trim($REQUESTDATA)); + exit(); +} //EOF header("X-MagicSmoke-Status: Error");