From 35cbdba3df8dccb3b70b0db2429e86a2ccf20ca3 Mon Sep 17 00:00:00 2001 From: konrad Date: Thu, 31 Dec 2009 16:39:10 +0000 Subject: [PATCH] order window: enable add comments, implement payment and refund git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@383 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/orderwin.cpp | 116 ++++++++++++++++++--------------------- src/dialogs/orderwin.h | 2 + wob/order.wolf | 70 ++++++++++++++++++++---- www/inc/wext/order.php | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 252 insertions(+), 74 deletions(-) diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index 30b03ba..69e94c5 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -55,19 +55,16 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) QMenuBar*mb=menuBar(); QMenu *m=mb->addMenu(tr("&Order")); - m->addAction(tr("&Order..."),this,SLOT(createOrder())) - ->setEnabled(req->hasRight(req->RReservationToOrder)&&o.isReservation()); - m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder())) - ->setEnabled(req->hasRight(req->RCancelOrder)); - m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder())) - ->setEnabled(req->hasRight(req->ROrderMarkShipped)); + m_res2order=m->addAction(tr("&Order..."),this,SLOT(createOrder())); + m_cancel=m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder())); + m_ship=m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder())); m->addSeparator(); m->addAction(tr("Ch&ange Item-Price..."),this,SLOT(changeItem())) ->setEnabled(req->hasRole("changeticketprice")); m->addAction(tr("&Return Item..."),this,SLOT(itemReturn())) ->setEnabled(req->hasRole("ticketreturn")); - m->addAction(tr("Change Commen&t..."),this,SLOT(changeComment())) - ->setEnabled(req->hasRole("setordercomment")); + m->addAction(tr("Add Commen&t..."),this,SLOT(changeComment())) + ->setEnabled(req->hasRight(req->ROrderAddComment)); m->addAction(tr("Change Sh&ipping Method..."),this,SLOT(changeShipping())) ->setEnabled(req->hasRight(req->ROrderChangeShipping)); m->addSeparator(); @@ -79,13 +76,10 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) m->addAction(tr("&Close"),this,SLOT(close())); m=mb->addMenu(tr("&Payment")); - m->addAction(tr("Receive &Payment..."),this,SLOT(payment())) - ->setEnabled(req->hasRight(req->ROrderPay)); - m->addAction(tr("&Refund..."),this,SLOT(refund())) - ->setEnabled(req->hasRight(req->ROrderRefund)); - m->addAction(tr("Pay with &Voucher..."),this,SLOT(payvoucher())) - ->setEnabled(req->hasRight(req->RUseVoucher)); - + m_pay=m->addAction(tr("Receive &Payment..."),this,SLOT(payment())); + m_refund=m->addAction(tr("&Refund..."),this,SLOT(refund())); + m_payv=m->addAction(tr("Pay with &Voucher..."),this,SLOT(payvoucher())); + m=mb->addMenu(tr("P&rinting")); m->addAction(tr("Print &Bill..."),this,SLOT(printBill())); m->addAction(tr("Save Bill &as file..."),this,SLOT(saveBill())); @@ -227,6 +221,12 @@ void MOrderWindow::updateData() } //refresh m_table->resizeColumnsToContents(); + m_res2order->setEnabled(req->hasRight(req->RReservationToOrder)&&m_order.isReservation()); + m_cancel->setEnabled(req->hasRight(req->RCancelOrder)); + m_ship->setEnabled(req->hasRight(req->ROrderMarkShipped)&&m_order.status()==m_order.Placed); + m_pay->setEnabled(req->hasRight(req->ROrderPay)&&m_order.needsPayment()); + m_payv->setEnabled(req->hasRight(req->RUseVoucher)&&m_order.needsPayment()); + m_refund->setEnabled(req->hasRight(req->ROrderRefund)&&m_order.needsRefund()); } void MOrderWindow::itemView() @@ -663,62 +663,49 @@ void MOrderWindow::initPrintBuffer() } void MOrderWindow::payment() -{/*TODO - if(!m_order.isValid())return; +{ //get value bool ok; int pay=MCentDialog::getCents(this,tr("Enter Payment"),tr("Please enter the amount that has been paid:"),m_order.amountToPay(),m_order.amountToPay(),&ok); if(!ok)return; if(pay<=0)return; //submit - QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay); - if(!req->request("orderpay",rq)){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to submit payment request.")); + MTOrderPay op=req->queryOrderPay(m_order.orderid(),pay); + if(op.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(op.errorString())); return; } - if(req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(qApp->translate("php::",req->responseBody()))); - return; - } - m_order.setAmountPaid(req->responseBody().trimmed().toInt()); - m_paid->setText(m_order.amountPaidString());*/ + m_order=op.getorder(); + updateData(); } void MOrderWindow::payvoucher() -{/*TODO +{ if(!m_order.isValid())return; //get voucher bool ok; QString vid=QInputDialog::getText(this,tr("Enter Voucher"),tr("Please enter the ID of the voucher you want to use:"),QLineEdit::Normal,"",&ok); if(!ok)return; if(vid=="")return; - MVoucher vou(req,vid); - if(!vou.isValid()){ - QMessageBox::warning(this,tr("Warning"),tr("This voucher is not valid.")); - return; - } //submit - QByteArray rq=vid.toAscii()+"\n"+QByteArray::number(m_order.orderID()); - if(!req->request("usevoucher",rq)){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to submit payment request.")); + MTUseVoucher uv=req->queryUseVoucher(m_order.orderid(),vid); + if(uv.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay with voucher '%1': %2").arg(vid).arg(uv.errorString())); return; } - if(req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(qApp->translate("php::",req->responseBody()))); - return; - } - QStringList sl=QString::fromAscii(req->responseBody().trimmed()).split("\n"); - if(sl.size()>1){ - m_order.setAmountPaid(sl[1].toInt()); - m_paid->setText(m_order.amountPaidString()); - } - if(sl.size()>0){ - QMessageBox::information(this,tr("Voucher Info"),tr("Remaining value of this voucher: %1").arg(cent2str(sl[0].toInt()))); - }*/ + m_order=uv.getorder(); + QMessageBox::information(this,tr("Voucher Info"), + tr("Successfully paid order %1 with voucher '%2'.\nAmount deducted: %3\nRemaining value of this voucher: %4") + .arg(m_order.orderid()) + .arg(vid) + .arg(cent2str(uv.getamount())) + .arg(cent2str(uv.getvoucher().value().value())) + ); + updateData(); } void MOrderWindow::refund() -{/*TODO +{ if(!m_order.isValid())return; //get value bool ok; @@ -726,17 +713,13 @@ void MOrderWindow::refund() if(!ok)return; if(pay<=0)return; //submit - QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay); - if(!req->request("orderrefund",rq)){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to submit refund request.")); + MTOrderRefund op=req->queryOrderRefund(m_order.orderid(),pay); + if(op.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while trying to refund: %1").arg(op.errorString())); return; } - if(req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Warning"),tr("Error whily trying to refund: %1").arg(qApp->translate("php::",req->responseBody()))); - return; - } - m_order.setAmountPaid(req->responseBody().trimmed().toInt()); - m_paid->setText(m_order.amountPaidString());*/ + m_order=op.getorder(); + updateData(); } void MOrderWindow::changeItem() @@ -905,16 +888,18 @@ void MOrderWindow::shipOrder() } void MOrderWindow::changeComment() -{/*TODO +{ //create editor dialog - QString cmt=m_order.comment(); + QString cmt=m_order.comments(); QDialog d; - d.setWindowTitle(tr("Set comment: order %1").arg(m_order.orderID())); + d.setWindowTitle(tr("Add comment: order %1").arg(m_order.orderid())); QVBoxLayout*vl; d.setLayout(vl=new QVBoxLayout); QTextEdit*te; + QLabel*lab; + vl->addWidget(lab=new QLabel("Current comment:\n"+cmt)); + lab->setWordWrap(true); vl->addWidget(te=new QTextEdit,1); - te->setPlainText(cmt); vl->addSpacing(15); QHBoxLayout*hl; vl->addLayout(hl=new QHBoxLayout,0); @@ -927,9 +912,14 @@ void MOrderWindow::changeComment() //get status if(d.exec()!=QDialog::Accepted)return; //send to server - m_order.sendComment(cmt=te->toPlainText()); + MTOrderAddComment ac=req->queryOrderAddComment(m_order.orderid(),te->toPlainText()); + if(ac.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("There was a problem uploading the new comment: %1").arg(ac.errorString())); + return; + } + m_order=ac.getorder(); //reset display - m_comment->setText(cmt);*/ + updateData(); } void MOrderWindow::changeShipping() diff --git a/src/dialogs/orderwin.h b/src/dialogs/orderwin.h index a82d9ba..bdff567 100644 --- a/src/dialogs/orderwin.h +++ b/src/dialogs/orderwin.h @@ -20,6 +20,7 @@ #include "MOOrder.h" #include "MOShipping.h" +class QAction; class QLabel; class QTableView; class QStandardItemModel; @@ -102,6 +103,7 @@ class MOrderWindow:public QMainWindow *m_shipmeth,*m_shipprice,*m_daddr,*m_iaddr,*m_soldby,*m_custname; QTableView *m_table; QStandardItemModel *m_model; + QAction*m_res2order,*m_cancel,*m_ship,*m_pay,*m_payv,*m_refund; //printing buffer struct TickInfo{ diff --git a/wob/order.wolf b/wob/order.wolf index 70cd756..80af929 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -181,6 +181,7 @@ + @@ -206,6 +207,7 @@ + @@ -215,6 +217,7 @@ + @@ -258,12 +261,12 @@ - - - - + amount that has been paid for this order + amount that needs to be paid, negative if too much has been paid + total price for this order (including shipping and all items) + costs for shipping @@ -325,10 +328,10 @@ - - - - + amount that has been paid for this order + amount that needs to be paid, negative if too much has been paid + total price for this order (including shipping and all items) + costs for shipping @@ -409,9 +412,43 @@ - - - + + + The order to be paid + amount offered, it must be positive + + + + fresh copy of the order + the amount actually taken, it is between 0 and at maximum the amount due for the order, it is never above the offered amount + + + + + + + + + + + + + + + + + + + + + + + + + + + + Changes the shipping option and/or price of an order @@ -439,6 +476,17 @@ + + + the order to be commented upon + the comment + + + + a fresh copy of the changed order + + + diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 8a60598..54c584c 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -222,6 +222,144 @@ class WOOrder extends WOOrderAbstract //return $trans->setorder(WOOrder::fromTableorder($ord)); } + + /**called from the OrderAddComment transaction*/ + public static function addComment($trans) + { + global $session; + //get order + $ord=WTorder::getFromDB($trans->getorderid()); + if($ord===false){ + $trans->abortWithError(tr("Order ID is not valid.")); + return; + } + //modify comment + $cmt=trim($ord->comments); + $nc=trim($trans->getcomment().""); + if($nc!=""){ + if($cmt!="")$cmt.="\n"; + $cmt.="[".$session->currentUserName()." ".date("Y-m-d G:i")."] ".$nc; + $ord->comments=$cmt; + $ord->update(); + } + //return + $trans->setorder(WOOrder::fromTableorder($ord)); + } + + /**called from the OrderPay transaction*/ + public static function payForOrder($trans) + { + //get order + $ord=WTorder::getFromDB($trans->getorderid()); + if($ord===false){ + $trans->abortWithError(tr("Order ID is not valid.")); + return; + } + //calculate payment + $pay=$trans->getamount()+0; + if($pay<0){//negative: error out + $trans->abortWithError(tr("Amount to be paid must be positive.")); + return; + } + $order=WOOrder::fromTableorder($ord); + $max=$order->prop_amountdue; + if($max<=0)$pay=0;else + if($max<$pay)$pay=$max; + if($pay==0){//zero: ignore it + $trans->setorder($order); + $trans->setamount(0); + return; + } + //make corrections + $ord->amountpaid+=$pay; + $ord->update(); + //return (redo object conversion: calculated data has changed!) + $trans->setorder(WOOrder::fromTableorder($ord)); + $trans->setamount($pay); + } + + /**called from the UseVoucher transaction*/ + public static function payForOrderVoucher($trans) + { + //get order + $ord=WTorder::getFromDB($trans->getorderid()); + if($ord===false){ + $trans->abortWithError(tr("Order ID is not valid.")); + return; + } + //get and verify voucher + $vou=WTvoucher::getFromDB($trans->getvoucherid()); + if($vou===false){ + $trans->abortWithError(tr("Voucher is not valid!")); + return; + } + $vord=WOOrder::fromTableorder(WTorder::getFromDB($vou->orderid)); + if($vord===false){ + $trans->abortWithError(tr("Voucher is not valid!")); + return; + } + if($vord->get_amountdue()>0){ + $trans->abortWithError(tr("Voucher cannot be used: it has not been paid for.")); + return; + } + //calculate payment + $pay=$vou->value+0; + if($pay<0){//negative: error out + $trans->abortWithError(tr("Amount to be paid must be positive.")); + return; + } + $order=WOOrder::fromTableorder($ord); + $max=$order->prop_amountdue; + if($max<=0)$pay=0;else + if($max<$pay)$pay=$max; + if($pay==0){//zero: ignore it + $trans->setorder($order); + $trans->setamount(0); + return; + } + //make corrections + $ord->amountpaid+=$pay; + $ord->update(); + $vou->value-=$pay; + $vou->isused=true; + $vou->update(); + //return (redo object conversion: calculated data has changed!) + $trans->setorder(WOOrder::fromTableorder($ord)); + $trans->setvoucher(WOVoucher::fromTablevoucher($vou)); + $trans->setamount($pay); + } + + /**called from the OrderRefund transaction*/ + public static function refundOrder($trans) + { + //get order + $ord=WTorder::getFromDB($trans->getorderid()); + if($ord===false){ + $trans->abortWithError(tr("Order ID is not valid.")); + return; + } + //calculate payment + $pay=$trans->getamount()+0; + if($pay<0){//negative: error out + $trans->abortWithError(tr("Amount to be refunded must be positive.")); + return; + } + $order=WOOrder::fromTableorder($ord); + $max=0-$order->prop_amountdue; //refund is negative due + if($max<=0)$pay=0;else + if($max<$pay)$pay=$max; + if($pay==0){//zero: ignore it + $trans->setorder($order); + $trans->setamount(0); + return; + } + //make corrections + $ord->amountpaid-=$pay; + $ord->update(); + //return (redo object conversion: calculated data has changed!) + $trans->setorder(WOOrder::fromTableorder($ord)); + $trans->setamount($pay); + } }; ?> \ No newline at end of file -- 1.7.2.5