From 19a0ddfa659e23e2bf771959843eac8a374751f1 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 30 Mar 2008 16:04:52 +0000 Subject: [PATCH] *implement cancel order *implement ship order git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@151 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- doc/prog_protocol.html | 8 ++++ src/order.cpp | 20 +++++++++++ src/order.h | 6 +++ src/orderwin.cpp | 44 +++++++++++++++++++++++- src/orderwin.h | 2 + www/inc/classes/order.php | 81 +++++++++++++++++++++++++++++++++++++++++++++ www/machine.php | 12 ++++++- 7 files changed, 170 insertions(+), 3 deletions(-) diff --git a/doc/prog_protocol.html b/doc/prog_protocol.html index e5ea315..17232e7 100644 --- a/doc/prog_protocol.html +++ b/doc/prog_protocol.html @@ -554,6 +554,14 @@ The getorderlist transaction can be used to get a list of all currently The orderpay transaction is used to add to the amount paid in an order. The orderrefund 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. +

Set Shipping State of an Order

+ +The ordershipped 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). + +

Cancelling an Order

+ +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. + diff --git a/src/order.cpp b/src/order.cpp index 940a140..901fc08 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -428,6 +428,26 @@ MOrder MOrder::createSale() 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 ******************************************************************************/ diff --git a/src/order.h b/src/order.h index 16902ce..05818c5 100644 --- a/src/order.h +++ b/src/order.h @@ -305,6 +305,12 @@ class MOrder /**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; diff --git a/src/orderwin.cpp b/src/orderwin.cpp index 828f53e..3463d2f 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -50,8 +50,10 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o) 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")); @@ -202,11 +204,20 @@ void MOrderWindow::printTickets(QList tickets) 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&))); @@ -216,11 +227,13 @@ void MOrderWindow::printBill() 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); @@ -233,6 +246,14 @@ void MOrderWindow::saveBill() 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&))); @@ -355,7 +376,17 @@ void MOrderWindow::changeTicket() } 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) { @@ -376,6 +407,15 @@ void MOrderWindow::createSale() 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,QListt) diff --git a/src/orderwin.h b/src/orderwin.h index 549ad7f..8a2c5fe 100644 --- a/src/orderwin.h +++ b/src/orderwin.h @@ -69,6 +69,8 @@ class MOrderWindow:public QMainWindow /**cancel the order*/ void cancelOrder(); + /**mark as shipped*/ + void shipOrder(); /**create a new order*/ void createOrder(bool issale=false); diff --git a/www/inc/classes/order.php b/www/inc/classes/order.php index 12357be..ad17315 100644 --- a/www/inc/classes/order.php +++ b/www/inc/classes/order.php @@ -75,6 +75,12 @@ class Order { 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) @@ -384,6 +390,31 @@ class Order 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) @@ -546,4 +577,54 @@ function orderPayXml($data,$factor) 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 diff --git a/www/machine.php b/www/machine.php index cd8cb2a..b66d17c 100644 --- a/www/machine.php +++ b/www/machine.php @@ -23,7 +23,7 @@ $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"), //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 ); @@ -302,6 +302,16 @@ if($SMOKEREQUEST=="orderrefund"){ 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"){ -- 1.7.2.5