From 2e7ad356d56a1a569cc9797d5eeaa0029a53d7ed Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 14 May 2010 13:30:11 +0000 Subject: [PATCH] allow sale git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@448 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/mwin/carttab.cpp | 18 +++++++++++++----- src/mwin/carttab.h | 6 ++++-- wob/order.wolf | 7 +++++-- www/inc/wext/cart.php | 26 +++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/mwin/carttab.cpp b/src/mwin/carttab.cpp index 5311d6c..93cab93 100644 --- a/src/mwin/carttab.cpp +++ b/src/mwin/carttab.cpp @@ -99,8 +99,11 @@ MCartTab::MCartTab(QString pk) vl->addLayout(hl=new QHBoxLayout,0); hl->addStretch(10); hl->addWidget(p=new QPushButton(tr("Order"))); - p->setEnabled(req->hasRight(req->RCreateOrder)); + p->setEnabled(req->hasRight(req->RCreateOrder)&&req->hasRight(req->PCreateOrder_CanOrder)); connect(p,SIGNAL(clicked()),this,SLOT(cartOrder())); + hl->addWidget(p=new QPushButton(tr("Sell"))); + p->setEnabled(req->hasRight(req->RCreateOrder)&&req->hasRight(req->PCreateOrder_CanSell)); + connect(p,SIGNAL(clicked()),this,SLOT(cartSell())); hl->addWidget(p=new QPushButton(tr("Reserve"))); p->setEnabled(req->hasRight(req->RCreateReservation)); connect(p,SIGNAL(clicked()),this,SLOT(cartReserve())); @@ -418,7 +421,7 @@ void MCartTab::cartRemoveItem() cartmodel->removeRow(idx.row()); } -void MCartTab::cartOrder(bool isreserve) +void MCartTab::cartOrder(bool isreserve,bool issale) { //sanity checks if(!canorder(isreserve))return; @@ -441,7 +444,7 @@ void MCartTab::cartOrder(bool isreserve) ///// //send MOOrder ord; - if(!orderExecute(cord,ord,isreserve))return; + if(!orderExecute(cord,ord,isreserve,issale))return; ///// //everything ok, move on if(!ord.orderid().isNull()){ @@ -466,6 +469,11 @@ void MCartTab::cartReserve() cartOrder(true); } +void MCartTab::cartSell() +{ + cartOrder(false,true); +} + bool MCartTab::canorder(bool isreserve) { //basics @@ -518,7 +526,7 @@ void MCartTab::cartTableToOrder(MOCartOrder&cord) } } -bool MCartTab::orderExecute(MOCartOrder&cord,MOOrder&ord,bool isreserve) +bool MCartTab::orderExecute(MOCartOrder&cord,MOOrder&ord,bool isreserve,bool issale) { if(isreserve){ MTCreateReservation co=req->queryCreateReservation(cord); @@ -529,7 +537,7 @@ bool MCartTab::orderExecute(MOCartOrder&cord,MOOrder&ord,bool isreserve) ord=co.getorder(); cord=co.getcart(); }else{ - MTCreateOrder co=req->queryCreateOrder(cord); + MTCreateOrder co=req->queryCreateOrder(cord,issale); if(co.hasError()){ QMessageBox::warning(this,tr("Warning"),tr("Error while creating order: %1").arg(co.errorString())); return false; diff --git a/src/mwin/carttab.h b/src/mwin/carttab.h index 0435247..2e9b35d 100644 --- a/src/mwin/carttab.h +++ b/src/mwin/carttab.h @@ -94,9 +94,11 @@ class MCartTab:public QWidget /**remove item from the cart*/ void cartRemoveItem(); /**create the order on the server*/ - void cartOrder(bool isreserve=false); + void cartOrder(bool isreserve=false,bool issale=false); /**create a reservation on the server*/ void cartReserve(); + /**create a sale on the server*/ + void cartSell(); /**reset the colors of the tab*/ void resetColor(bool addronly=false); @@ -118,7 +120,7 @@ class MCartTab:public QWidget /**helper for order: turns the cart table into order items*/ void cartTableToOrder(MOCartOrder&); /**helper for order: makes the actual order or reserve; returns the result in the first two parameters; returns false if the transaction was aborted and processing should stop here*/ - bool orderExecute(MOCartOrder&cart,MOOrder&order,bool isreserve); + bool orderExecute(MOCartOrder&cart,MOOrder&order,bool isreserve,bool issale); /**helper for order: verifies customer properties*/ void verifyOrderCustomer(MOCartOrder&); /**helper for order: verifies tickets*/ diff --git a/wob/order.wolf b/wob/order.wolf index be3ea52..2c6710d 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -417,13 +417,16 @@ - CreateOrder creates orders that are queued to be executed immediately, they may contain tickets, vouchers, or shopping items + CreateOrder creates orders that are queued to be executed immediately or sales that are marked executed and paid for immediately; they may contain tickets, vouchers, or shopping items users with this privilege can create vouchers with arbitrary value users with this privilege can create vouchers with a price (what the customer pays) different from its value (what the customer can buy with it) - users with this privilege can sell tickets until the event is over, otherwise a configurable limit applies + users with this privilege can sell/order tickets until the event is over, otherwise a configurable limit applies users with this privilege can sell tickets for past events - be careful to give this privilege only to very few special users, it is an invitation to mistakes! + users with this privilege may use this transaction to create orders + users with this privilege may use this transaction to create sales The cart contents + true if this is a sale, false if this is an order diff --git a/www/inc/wext/cart.php b/www/inc/wext/cart.php index c7ffe7a..834a29d 100644 --- a/www/inc/wext/cart.php +++ b/www/inc/wext/cart.php @@ -28,6 +28,7 @@ class WOCartOrder extends WOCartOrderAbstract //get permissions global $db; $isreserve=false; + $issale=false; $vanyval=false; $vdiffprice=false; $tsalestop=0; @@ -40,6 +41,18 @@ class WOCartOrder extends WOCartOrderAbstract $tsalestop=self::LateSale; if($trans->havePrivilege(WTrCreateOrder::Priv_AfterTheFactSale)) $tsalestop=self::AfterSale; + $issale=$trans->getissale(); + if($issale){ + if(!$trans->havePrivilege(WTrCreateOrder::Priv_CanSell)){ + $trans->abortWithError(tr("Lacking privileges to create a sale.")); + return; + } + }else{ + if(!$trans->havePrivilege(WTrCreateOrder::Priv_CanOrder)){ + $trans->abortWithError(tr("Lacking privileges to create an order.")); + return; + } + } }else if(is_a($trans,"WTrCreateReservation")){ $isreserve=true; @@ -48,7 +61,7 @@ class WOCartOrder extends WOCartOrderAbstract if($trans->havePrivilege(WTrCreateReservation::Priv_LateReserve)) $tsalestop=0; }else{ - $trans->abortWithError(tr("CreateSale called from an unknown transaction.")); + $trans->abortWithError(tr("CreateOrder called from an unknown transaction.")); return; } //verify necessary elements and content @@ -75,7 +88,7 @@ class WOCartOrder extends WOCartOrderAbstract } $cart->setstatus(WOCartOrder::Ok); //create order - $ord=$cart->createOrderOnDB($trans,$isreserve); + $ord=$cart->createOrderOnDB($trans,$isreserve,$issale); //return verified cart and order $trans->setorder($ord); @@ -267,7 +280,7 @@ class WOCartOrder extends WOCartOrderAbstract } /**helper function for createOrder: creates the order on the database*/ - private function createOrderOnDB($trans,$isreserve) + private function createOrderOnDB($trans,$isreserve,$issale) { global $session; //create order @@ -317,6 +330,13 @@ class WOCartOrder extends WOCartOrderAbstract $v->insert(); } //TODO: create items + //for sales: update amountpaid and mark shipped + if($issale){ + $oo=WOOrder::fromTableorder($ord); + $ord->amountpaid=$oo->getTotalPrice(); + $ord->senttime=$ord->ordertime; + $ord->update(); + } //update address use $ad=WTaddress::getFromDB($ord->invoiceaddress); if(is_a($ad,"WTaddress")){ -- 1.7.2.5