allow sale
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 May 2010 13:30:11 +0000 (13:30 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 May 2010 13:30:11 +0000 (13:30 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@448 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

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

index 5311d6c..93cab93 100644 (file)
@@ -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;
index 0435247..2e9b35d 100644 (file)
@@ -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*/
index be3ea52..2c6710d 100644 (file)
        </Transaction>
        
        <Transaction name="CreateOrder">
-               <Doc>CreateOrder creates orders that are queued to be executed immediately, they may contain tickets, vouchers, or shopping items</Doc>
+               <Doc>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</Doc>
                <Privilege name="AnyVoucherValue">users with this privilege can create vouchers with arbitrary value</Privilege>
                <Privilege name="DiffVoucherValuePrice">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)</Privilege>
-               <Privilege name="LateSale">users with this privilege can sell tickets until the event is over, otherwise a configurable limit applies</Privilege>
+               <Privilege name="LateSale">users with this privilege can sell/order tickets until the event is over, otherwise a configurable limit applies</Privilege>
                <Privilege name="AfterTheFactSale">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!</Privilege>
+               <Privilege name="CanOrder">users with this privilege may use this transaction to create orders</Privilege>
+               <Privilege name="CanSell">users with this privilege may use this transaction to create sales</Privilege>
                <Input>
                        <Var name="cart" type="CartOrder">The cart contents</Var>
+                       <Var name="issale" type="bool">true if this is a sale, false if this is an order</Var>
                </Input>
                <Call lang="php" method="WOCartOrder::createOrder($this);"/>
                <Output>
index c7ffe7a..834a29d 100644 (file)
@@ -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")){