The <tt>orderpay</tt> transaction is used to add to the amount paid in an order. The <tt>orderrefund</tt> transaction is used to subtract from the amount paid of an order. In both cases the request consists of two positive numbers separated by a space: the order-ID and the amount in cent. The response contains the new amount paid after the transaction in the case of success and status error plus an explanation in case of any problem.
+<h3>Set Shipping State of an Order</h3>
+
+The <tt>ordershipped</tt> transaction is used to mark an order as shipped. This transaction is only legal for orders in the "placed" state. The request contains the order ID, the response contains the new shipping time (set automatically during transaction).
+
+<h3>Cancelling an Order</h3>
+
+The <tt>cancelorder</tt> 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.
+
<!-- ************************************************************************************
************************************************************************************
************************************************************************************ -->
return createOrder("createsale");
}
+bool MOrder::cancelOrder()
+{
+ if(!req->request("cancelorder",QByteArray::number(m_orderid)))return false;
+ bool r=req->responseStatus()==MWebRequest::Ok;
+ if(r)m_status=Cancelled;
+ return r;
+}
+
+bool MOrder::shipOrder()
+{
+ if(!req->request("ordershipped",QByteArray::number(m_orderid)))return false;
+ bool r=req->responseStatus()==MWebRequest::Ok;
+ if(r){
+ m_status=Sent;
+ m_stime=req->responseBody().trimmed().toInt();
+ }
+ return r;
+}
+
+
/******************************************************************************
* Ticket
******************************************************************************/
/**create a sale in the DB; returns it*/
MOrder createSale();
+
+ /**cancel the order; queries DB; returns true on success*/
+ bool cancelOrder();
+
+ /**mark the order as shipped; queries DB; returns true on success*/
+ bool shipOrder();
private:
MWebRequest*req;
m->addAction(tr("&Sell..."),this,SLOT(createSale()))
->setEnabled(req->hasRole("createsale")&&o.canSell());
m->addSeparator();
- m->addAction(tr("C&ancel Order..."))
+ m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()))
->setEnabled(req->hasRole("cancelorder")&&o.isStored());
+ m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()))
+ ->setEnabled(req->hasRole("ordershipped"));
m->addSeparator();
m->addAction(tr("Ch&ange Ticket-Price..."),this,SLOT(changeTicket()))
->setEnabled(req->hasRole("changeticketprice"));
void MOrderWindow::printBill()
{
+ //get template
QString tf=req->getTemplate("bill.odtt");
if(tf==""){
QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (bill.odtt). Giving up."));
return;
}
+ //mark order as shipped?
+ if(m_order.orderStatus()==MOrder::Placed)
+ if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+ m_order.shipOrder();
+ m_state->setText(m_order.orderStatusString());
+ m_sentdate->setText(m_order.sentDateTimeStr());
+ }
+ //print bill
MOdtSignalRenderer rend(tf);
connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&)));
connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
void MOrderWindow::saveBill()
{
+ //get template
QString tf=req->getTemplate("eventsummary.odtt");
if(tf==""){
QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary.odtt). Giving up."));
return;
}
+ //get target file name
QFileDialog fd(this);
fd.setAcceptMode(QFileDialog::AcceptSave);
fd.setFileMode(QFileDialog::AnyFile);
if(fn.size()<1)return;
fname=fn[0];
}
+ //mark order as shipped?
+ if(m_order.orderStatus()==MOrder::Placed)
+ if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+ m_order.shipOrder();
+ m_state->setText(m_order.orderStatusString());
+ m_sentdate->setText(m_order.sentDateTimeStr());
+ }
+ //render bill
MOdtSignalRenderer rend(tf);
connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&)));
connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
}
void MOrderWindow::cancelOrder()
-{}
+{
+ if(QMessageBox::question(this,tr("Cancel Order?"),tr("Cancel this order now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)!=QMessageBox::Yes)return;
+ if(m_order.orderStatus()!=MOrder::Placed){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot cancel this order: it is in the wrong state."));
+ return;
+ }
+ if(!m_order.cancelOrder()){
+ QMessageBox::warning(this,tr("Warning"),tr("Failed to cancel this order."));
+ }else
+ m_state->setText(m_order.orderStatusString());
+}
void MOrderWindow::createOrder(bool issale)
{
createOrder(true);
}
+void MOrderWindow::shipOrder()
+{
+ if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+ m_order.shipOrder();
+ m_state->setText(m_order.orderStatusString());
+ m_sentdate->setText(m_order.sentDateTimeStr());
+ }
+}
+
/*************************************************************************************/
MTicketView::MTicketView(QWidget*w,QList<MTicket>t)
/**cancel the order*/
void cancelOrder();
+ /**mark as shipped*/
+ void shipOrder();
/**create a new order*/
void createOrder(bool issale=false);
{
return $this->orderid!==false;
}
+
+ /**returns the sent time as unix timestamp*/
+ public function getSentTime()
+ {
+ return $this->senttime;
+ }
/**removes all items from the given Cart and enters them into itself; returns false if some items cannot be ordered or the order is already closed*/
public function emptyCart($cart)
if($totalprice<$this->amountpaid)return "needrefund";
else return "needpayment";
}
+
+ /**sets the order to being shipped, returns true on success*/
+ public function setShipped()
+ {
+ if(!$this->isValid())return false;
+ if($this->status!=ORDER_PLACED)return false;
+ global $db;
+ $this->senttime=time();
+ $db->update("order",array("status"=>ORDER_SENT,"senttime"=>$this->senttime),"orderid=".$db->escapeInt($this->orderid));
+ return true;
+ }
+
+ /**sets the order to being cancelled, returns true on success*/
+ public function setCancelled()
+ {
+ if(!$this->isValid())return false;
+ if($this->status!=ORDER_PLACED)return false;
+ global $db;
+ $db->update("order",array("status"=>ORDER_CANCELLED,"senttime"=>time()),"orderid=".$db->escapeInt($this->orderid));
+ //propagate to tickets
+ $db->update("ticket",array("status"=>TICKET_CANCELLED),"orderid=".$db->escapeInt($this->orderid));
+ //TODO: propagate to vouchers
+
+ return true;
+ }
};
function createOrderXml($xmldata,$action)
echo $amt2;
}
+//mark order as shipped
+function orderShippedXml($oid)
+{
+ if(!is_numeric($oid)){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID must be numeric."));
+ }
+ $oid=$oid+0;
+ if($oid<0){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID is invalid."));
+ }
+ $ord=new Order($oid);
+ if(!$ord->isValid()){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID is invalid."));
+ }
+ if($ord->setShipped()){
+ header("X-MagicSmoke-Status: Ok");
+ print($ord->getSentTime());
+ }else{
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Wrong state, cannot set order to shipped."));
+ }
+}
+
+//mark order as cancelled
+function orderCancelXml($oid)
+{
+ if(!is_numeric($oid)){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID must be numeric."));
+ }
+ $oid=$oid+0;
+ if($oid<0){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID is invalid."));
+ }
+ $ord=new Order($oid);
+ if(!$ord->isValid()){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Order ID is invalid."));
+ }
+ if($ord->setCancelled()){
+ header("X-MagicSmoke-Status: Ok");
+ }else{
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Wrong state, cannot set order to cancelled."));
+ }
+}
?>
\ No newline at end of file
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"), //sell/order stuff
+ 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("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates
);
orderPayXml($REQUESTDATA,-1);
exit();
}
+//mark order shipped
+if($SMOKEREQUEST=="ordershipped"){
+ orderShippedXml(trim($REQUESTDATA));
+ exit();
+}
+//cancel order
+if($SMOKEREQUEST=="cancelorder"){
+ orderCancelXml(trim($REQUESTDATA));
+ exit();
+}
//get a ticket
if($SMOKEREQUEST=="getticket"){