From 17e6133c96e025e46aa92cf0d7c207a5d94fde10 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 14 May 2010 12:42:42 +0000 Subject: [PATCH] implemented deduct voucher git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@447 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/mwin/overview.cpp | 24 +++++++++++++----------- wob/order.wolf | 24 +++++++++++++++++++----- www/inc/wext/order.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 74fe30d..31967c5 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -24,6 +24,8 @@ #include "entrancetab.h" #include "aclwin.h" +#include "centbox.h" + #include #include #include @@ -221,7 +223,7 @@ void MOverview::ticketReturn() } void MOverview::deductVoucher() -{/*TODO +{ //get voucher ID and amount QDialog d; d.setWindowTitle(tr("Deduct from Voucher")); @@ -248,20 +250,20 @@ void MOverview::deductVoucher() if(d.exec()!=QDialog::Accepted)return; if(vid->text().trimmed()=="" || cent->value()<=0)return; //query server - QByteArray r=vid->text().trimmed().toAscii()+"\n"+QString::number(cent->value()).toAscii(); - if(!req->request("usevoucheroutside",r)){ - QMessageBox::warning(this,tr("Warning"),tr("Request failed.")); + MTDeductVoucher dv=req->queryDeductVoucher(vid->text(),cent->value()); + if(dv.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to deduct voucher: %1").arg(dv.errorString())); return; } - if(req->responseStatus()!=MSInterface::Ok){ - QMessageBox::warning(this,tr("Warning"),tr("Request failed.")); + if(dv.getamount().value()==0){ + QMessageBox::warning(this,tr("Warning"),tr("Voucher does not contain enough money. Money left: %1").arg(dv.getvoucher().value().value())); return; } - QStringList sl=QString::fromAscii(req->responseBody().trimmed()).split("\n"); - int tak=-1,rem=-1; - if(sl.size()>0)tak=sl[0].trimmed().toInt(); - if(sl.size()>1)rem=sl[1].trimmed().toInt(); - QMessageBox::information(this,tr("Deducted from Voucher"),tr("Value taken from voucher: %1\nValue remaining on voucher: %2").arg(cent2str(tak)).arg(cent2str(rem)));*/ + QMessageBox::information(this,tr("Deducted from Voucher"), + tr("Value taken from voucher: %1\nValue remaining on voucher: %2") + .arg(cent2str(dv.getamount())) + .arg(cent2str(dv.getvoucher().value().value())) + ); } void MOverview::refreshData() diff --git a/wob/order.wolf b/wob/order.wolf index f3eceae..be3ea52 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -491,15 +491,29 @@ + Use a voucher to pay for an order. The system automatically deducts as much as is due for the order or as much as is left on the voucher - whichever is lower. If the voucher is not paid for the transaction will fail. The transaction will never transfer money from an order back to the voucher. - - + ID of the order that is to be paid for + ID of the voucher that is to be used for payment - - - + The full order object after the transaction + The full voucher object after the transaction + The amount that was deducted + + + + + Deducts an amount from a voucher - this can be used for items that are not in the MagicSmoke shop repository. Fails if the voucher is not paid for yet. Will not transfer anything if the voucher does not contain enough money. + + ID of the voucher to be used + Amount to be deducted. Must be positive. + + + + The full voucher object after the transaction + The amount actually transferred. Can only be zero (not enough left on the voucher) or the same as above. diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 0033bd3..050f087 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -565,6 +565,51 @@ class WOOrder extends WOOrderAbstract //return order $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($tick->orderid))); } + + /**called from the DeductVoucher transaction*/ + static public function deductVoucher($trans) + { + //verify amount + $amt=$trans->getamount()+0; + if($amt<0){//negative: error out + $trans->abortWithError(tr("Amount to be paid must be positive.")); + 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->getamountdue()>0){ + $trans->abortWithError(tr("Voucher cannot be used: it has not been paid for.")); + return; + } + //calculate payment + $lft=$vou->value+0; + if($lft<0){//negative: error out + $trans->abortWithError(tr("Internal error: negative voucher.")); + return; + } + if($lft<$amt){ + //not enough left, tell user + $trans->setamount(0); + $trans->setvoucher(WOVoucher::fromTablevoucher($vou)); + return; + } + //make corrections + $vou->value-=$amt; + $vou->isused=true; + $vou->update(); + //return + $trans->setamount($amt); + $trans->setvoucher(WOVoucher::fromTablevoucher($vou)); + } }; ?> \ No newline at end of file -- 1.7.2.5