"big merge" - implemented empty voucher
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 May 2010 18:04:39 +0000 (18:04 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 May 2010 18:04:39 +0000 (18:04 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@451 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/overview.cpp
src/mwin/overview.h
wob/order.wolf
www/inc/wext/order.php

index 31967c5..8404d2a 100644 (file)
@@ -117,6 +117,7 @@ MOverview::MOverview(QString pk)
        m->addAction(tr("Edit &Shipping Options..."),this,SLOT(editShipping()));
        m->addSeparator();
        m->addAction(tr("&Deduct from voucher..."),this,SLOT(deductVoucher()));
+       m->addAction(tr("&Empty voucher..."),this,SLOT(emptyVoucher()));
        
        m=mb->addMenu(tr("C&onfigure"));
        m->addAction(tr("&Auto-Refresh settings..."),this,SLOT(setRefresh()));
@@ -266,6 +267,21 @@ void MOverview::deductVoucher()
        );
 }
 
+void MOverview::emptyVoucher()
+{
+       //get voucher ID
+       QString vid=QInputDialog::getText(this,tr("Invalidate Voucher"),tr("Please enter/scan the barcode of the voucher to invalidate/empty - the voucher will no longer be usable afterwards, but still has to be paid for."));
+       if(vid=="")return;
+       //query server
+       MTEmptyVoucher dv=req->queryEmptyVoucher(vid);
+       if(dv.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to invalidate voucher: %1").arg(dv.errorString()));
+               return;
+       }
+       QMessageBox::information(this,tr("Invalidated Voucher"),
+         tr("The voucher '%1'has been invalidated.").arg(vid));
+}
+
 void MOverview::refreshData()
 {
        QSettings set;
index 8283e1c..63c2c13 100644 (file)
@@ -71,6 +71,8 @@ class MOverview:public QMainWindow
                void ticketReturn();
                /**deduct some money from a voucher (to pay outside the system)*/
                void deductVoucher();
+               /**empty/invalidate voucher*/
+               void emptyVoucher();
                
                /**refresh data that we can refresh*/
                void refreshData();
index 2c6710d..fae345c 100644 (file)
                </Output>
        </Transaction>
        
+       <Transaction name="EmptyVoucher">
+               <Doc>Empties a voucher, makes it invalid for any further use, but also keeps the price tag.</Doc>
+               <Input>
+                       <Var name="voucherid" type="astring">ID of the voucher</Var>
+               </Input>
+               <Call lang="php" method="WOOrder::emptyVoucher($this);"/>
+               <Output>
+                       <Var name="voucher" type="Voucher">The voucher as it is left after emptying</Var>
+               </Output>
+       </Transaction>
+       
        
        <Transaction name="OrderChangeShipping">
                <Doc>Changes the shipping option and/or price of an order</Doc>
index 050f087..4ee24d1 100644 (file)
@@ -610,6 +610,32 @@ class WOOrder extends WOOrderAbstract
                $trans->setamount($amt);
                $trans->setvoucher(WOVoucher::fromTablevoucher($vou));
        }
+       
+       /**called from EmptyVoucher transaction*/
+       static public function emptyVoucher($trans)
+       {
+               //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;
+               }
+               //empty it
+               $vou->value=0;
+               $vou->isused=true;
+               $vou->update();
+               //return
+               $trans->setvoucher(WOVoucher::fromTablevoucher($vou));
+       }       
 };
 
 ?>
\ No newline at end of file