cart tab almost functional, create order in php missing, create reservation missing...
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 5 Jan 2010 16:15:59 +0000 (16:15 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 5 Jan 2010 16:15:59 +0000 (16:15 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@405 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

13 files changed:
src/dialogs/customerdlg.cpp
src/dialogs/customerdlg.h
src/mwin/carttab.cpp
src/mwin/carttab.h
src/wext/MOCustomer.cpp
src/wext/MOCustomer.h
src/wext/MOCustomerInfo.cpp
src/wext/MOCustomerInfo.h
wob/cart.wolf
wob/customer.wolf
wob/magicsmoke.wolf
wob/order.wolf
www/inc/wext/customer.php

index 47621ec..2ef4d9d 100644 (file)
@@ -91,8 +91,11 @@ void MCustomerListDialog::updateList(int nid)
        //check for current selection
        if(nid<0){
                QModelIndex idx=m_listview->currentIndex();
-               if(idx.isValid())
-                       nid=m_proxymodel->data(idx,Qt::UserRole).toInt();
+               if(idx.isValid()){
+                       int i=m_proxymodel->data(idx,Qt::UserRole).toInt();
+                       if(i>=0&&i<m_list.size())
+                               nid=m_list[i].customerid();
+               }
        }
        //go to server
        MTGetAllCustomerNames gac=req->queryGetAllCustomerNames();
@@ -736,3 +739,52 @@ void MAddressDialog::selectCountry()
        m_addr.setcountryid(m_addr.country().value().id());
        m_country->setText(m_addr.country().value().name());
 }
+
+/*****************************************************************************/
+
+MAddressChoiceDialog::MAddressChoiceDialog(QWidget*par,const MOCustomer&c)
+       :QDialog(par),m_cust(c)
+{
+       m_needupdate=false;
+       setWindowTitle(tr("Chose an Address"));
+       QHBoxLayout*hl;
+       QVBoxLayout*vl;
+       setLayout(vl=new QVBoxLayout);
+       vl->addWidget(m_lwidget=new MAddressListWidget(this,m_cust.addresses(),true),10);
+       connect(m_lwidget,SIGNAL(addressChanged(const MOAddress&)),this,SLOT(changed()));
+       connect(m_lwidget,SIGNAL(addressDeleted(const MOAddress&)),this,SLOT(changed()));
+       connect(m_lwidget,SIGNAL(addressCreated(const MOAddress&)),this,SLOT(changed()));
+       connect(m_lwidget,SIGNAL(addressEdited(const MOAddress&)),this,SLOT(changed()));
+       //on selection: first update customer, then close window
+       connect(m_lwidget,SIGNAL(addressSelected(qint64)),this,SLOT(updateCustomer()),Qt::DirectConnection);
+       
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(10);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("Add Address")),0);
+       connect(p,SIGNAL(clicked()),m_lwidget,SLOT(createAddress()));
+       hl->addSpacing(20);
+       hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+}
+
+MOAddress MAddressChoiceDialog::address()const{return m_lwidget->selection();}
+qint64 MAddressChoiceDialog::addressId()const{return m_lwidget->selection().addressid();}
+void MAddressChoiceDialog::changed(){m_needupdate=true;}
+
+void MAddressChoiceDialog::updateCustomer()
+{
+       setEnabled(false);
+       if(m_needupdate){
+               //do update
+               m_cust.setaddresses(m_lwidget->addressList());
+               MTChangeCustomer cc=MTChangeCustomer::query(m_cust);
+               if(cc.hasError()){
+                       QMessageBox::warning(this,tr("Warning"),tr("Unable to save changes made to addresses: %1").arg(cc.errorString()));
+                       return;
+               }
+               m_cust=cc.getcustomer();
+       }
+       //close dialog successfully
+       accept();
+}
index c456f7b..88775a6 100644 (file)
@@ -181,6 +181,33 @@ class MAddressListWidget:public QScrollArea
                QGridLayout*m_layout;
 };
 
+/**wrapper dialog to chose an address; updates the customer is there is a change*/
+class MAddressChoiceDialog:public QDialog
+{
+       Q_OBJECT
+       public:
+               /**creates the dialog*/
+               MAddressChoiceDialog(QWidget*,const MOCustomer&);
+               
+               /**returns the chosen address*/
+               MOAddress address()const;
+               
+               /**returns the ID of the chosen address*/
+               qint64 addressId()const;
+               
+               /**returns the (modified) customer object*/
+               MOCustomer customer()const{return m_cust;}
+       private slots:
+               /**internal: notified if there is a change to the address list*/
+               void changed();
+               /**internal: updates the customer if necessary*/
+               void updateCustomer();
+       private:
+               MOCustomer m_cust;
+               bool m_needupdate;
+               MAddressListWidget*m_lwidget;
+};
+
 /**dialog for editing exactly one address*/
 class MAddressDialog:public QDialog
 {
index 3b1566e..89d29ee 100644 (file)
@@ -36,6 +36,7 @@
 MCartTab::MCartTab(QString pk)
 {
        profilekey=pk;
+       deliveryaddrid=invoiceaddrid=-1;
        
        QVBoxLayout*vl;QHBoxLayout*hl;
        QPushButton*p;
@@ -56,7 +57,12 @@ MCartTab::MCartTab(QString pk)
        connect(p,SIGNAL(clicked()),this,SLOT(cartAddTicket()));
        hl2->addWidget(p=new QPushButton(tr("Add Voucher")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(cartAddVoucher()));
-       hl2->addWidget(p=new QPushButton(tr("Remove Item")),0);
+       hl2->addWidget(p=new QPushButton(tr("Add Shop Item")),0);
+       //TODO: implement items
+       p->setEnabled(false);
+       connect(p,SIGNAL(clicked()),this,SLOT(cartAddItem()));
+       hl2->addSpacing(15);
+       hl2->addWidget(p=new QPushButton(tr("Remove Line")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(cartRemoveItem()));
        QFrame*frm;
        hl->addWidget(frm=new QFrame,0);
@@ -64,15 +70,23 @@ MCartTab::MCartTab(QString pk)
        hl->addLayout(vl2=new QVBoxLayout,1);
        vl2->addWidget(p=new QPushButton(tr("Customer:")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(setCustomer()));
-       vl2->addWidget(cartcustomer=new QLabel("...\n \n \n "));
+       vl2->addWidget(cartcustomer=new QLabel("..."));
+       vl2->addWidget(frm=new QFrame,0);
+       frm->setFrameShape(QFrame::HLine);
+       vl2->addWidget(p=new QPushButton(tr("Invoice Address:")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(setInvoiceAddr()));
+       vl2->addWidget(invoiceaddr=new QLabel("..."));
+       vl2->addWidget(frm=new QFrame,0);
+       frm->setFrameShape(QFrame::HLine);
+       vl2->addWidget(p=new QPushButton(tr("Delivery Address:")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(setDeliveryAddr()));
+       vl2->addWidget(deliveryaddr=new QLabel("..."));
        vl2->addWidget(frm=new QFrame,0);
        frm->setFrameShape(QFrame::HLine);
        vl2->addSpacing(10);
        vl2->addWidget(new QLabel(tr("Shipping Method:")),0);
        vl2->addWidget(cartship=new QComboBox,0);
        cartship->setEditable(false);
-       vl2->addWidget(new QLabel(tr("Delivery Address:")),0);
-       vl2->addWidget(cartaddr=new QTextEdit);
        vl2->addSpacing(10);
        vl2->addWidget(new QLabel(tr("Comments:")),0);
        vl2->addWidget(cartcomment=new QTextEdit);
@@ -133,8 +147,11 @@ void MCartTab::initCart()
        //clear customer
        customer=MOCustomer();
        cartcustomer->setText("");
-       //clear address/comment
-       cartaddr->setPlainText("");
+       //clear address
+       deliveryaddr->setText("");
+       invoiceaddr->setText("");
+       deliveryaddrid=invoiceaddrid=-1;
+       //clear comment
        cartcomment->setPlainText("");
        //clear shipping
        cartship->setCurrentIndex(0);
@@ -145,8 +162,42 @@ void MCartTab::setCustomer()
        MCustomerListDialog mcl(this,true,customer.id());
        if(mcl.exec()!=QDialog::Accepted)return;
        customer=mcl.getCustomer();
-       //TODO: follow up with address dialog
-//     cartcustomer->setText(customer.getNameAddress());
+       cartcustomer->setText(customer.fullName());
+       //clear address
+       deliveryaddr->setText("");
+       invoiceaddr->setText("");
+       deliveryaddrid=invoiceaddrid=-1;
+       //follow up with address dialog
+       if(!customer.customerid().isNull())
+               setInvoiceAddr();
+}
+
+void MCartTab::setDeliveryAddr()
+{
+       if(customer.customerid().isNull()){
+               QMessageBox::warning(this,tr("Warning"),tr("Please set the customer first."));
+               return;
+       }
+       MAddressChoiceDialog d(this,customer);
+       if(d.exec()!=QDialog::Accepted)return;
+       customer=d.customer();
+       deliveryaddr->setText(d.address().fullAddress(customer.fullName()));
+       deliveryaddrid=d.addressId();
+}
+
+void MCartTab::setInvoiceAddr()
+{
+       if(customer.customerid().isNull()){
+               //customer not set yet, chose it
+               setCustomer();
+               //the setCustomer routine will recurse back to here
+               return;
+       }
+       MAddressChoiceDialog d(this,customer);
+       if(d.exec()!=QDialog::Accepted)return;
+       customer=d.customer();
+       invoiceaddr->setText(d.address().fullAddress(customer.fullName()));
+       invoiceaddrid=d.addressId();
 }
 
 static const int CART_TICKET=1;
@@ -218,7 +269,7 @@ void MCartTab::eventOrderTicket()
 }
 
 void MCartTab::cartAddVoucher()
-{/*TODO
+{
        //create voucher selection dialog
        QDialog dlg;
        dlg.setWindowTitle(tr("Select Voucher"));
@@ -227,13 +278,13 @@ void MCartTab::cartAddVoucher()
        QGridLayout*gl;
        QStandardItemModel mdl;
        QRegExpValidator regv(priceRegExp(),this);
-       QList<int>prc=req->getVoucherPrices();
+       QList<qint64>prc=MTGetValidVoucherPrices::query().getprices();
        mdl.insertRows(0,prc.size());
        mdl.insertColumns(0,1);
        for(int i=0;i<prc.size();i++)mdl.setData(mdl.index(i,0),cent2str(prc[i]));
        dlg.setLayout(gl=new QGridLayout);
        gl->addWidget(new QLabel(tr("Select voucher price and value:")),0,0,1,2);
-       if(req->hasRole("_anypricevoucher")){
+       if(req->hasRight(req->PCreateOrder_DiffVoucherValuePrice)){
                gl->addWidget(new QLabel(tr("Price:")),1,0);
                gl->addWidget(cp=new QComboBox,1,1);
                cp->setModel(&mdl);
@@ -243,7 +294,7 @@ void MCartTab::cartAddVoucher()
        gl->addWidget(new QLabel(tr("Value:")),2,0);
        gl->addWidget(cv=new QComboBox,2,1);
        cv->setModel(&mdl);
-       cv->setEditable(req->hasRole("_anyvoucher"));
+       cv->setEditable(req->hasRight(req->PCreateOrder_AnyVoucherValue));
        cv->setValidator(&regv);
        gl->setRowMinimumHeight(3,15);
        gl->setColumnStretch(0,0);
@@ -261,7 +312,7 @@ void MCartTab::cartAddVoucher()
                //get selection
                int price,value;
                value=str2cent(cv->currentText());
-               if(req->hasRole("_anypricevoucher") && cp)
+               if(req->hasRight(req->PCreateOrder_DiffVoucherValuePrice) && cp)
                        price=str2cent(cp->currentText());
                else
                        price=value;
@@ -274,7 +325,12 @@ void MCartTab::cartAddVoucher()
                cartmodel->setData(cartmodel->index(cr,0),CART_VOUCHER,CART_TYPEROLE);
                cartmodel->setData(cartmodel->index(cr,1),tr("Voucher (price: %1, value %2)").arg(cent2str(price)).arg(cent2str(value)));
                carttable->resizeColumnsToContents();
-       }*/
+       }
+}
+
+void MCartTab::cartAddItem()
+{
+       //TODO: implement items
 }
 
 void MCartTab::cartRemoveItem()
@@ -288,7 +344,7 @@ void MCartTab::cartRemoveItem()
 
 void MCartTab::cartOrder()
 {
-/*     //sanity checks
+       //sanity checks
        if(cartmodel->rowCount()<1){
                QMessageBox::warning(this,tr("Error"),tr("There is nothing in the order. Ignoring it."));
                return;
@@ -297,77 +353,49 @@ void MCartTab::cartOrder()
                QMessageBox::warning(this,tr("Error"),tr("Please chose a customer first!"));
                return;
        }
+       if(cartship->currentIndex()>0 && deliveryaddrid<0 && invoiceaddrid<0){
+               if(QMessageBox::question(this,tr("Shipping"),tr("You have chosen a shipping method, but no address. Are you sure you want to continue?"),QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes)return;
+       }
        ///////////////
        //create order
-       QDomDocument doc;
-       QDomElement root=doc.createElement("Order");
-       root.setAttribute("customer",customer.id());
+       MOCartOrder cord;
+       cord.setcustomerid(customer.id());
        //is there a delivery address
-       QString s=cartaddr->toPlainText().trimmed();
-       if(s!=""){
-               QDomElement da=doc.createElement("DeliveryAddress");
-               da.appendChild(doc.createTextNode(s));
-               root.appendChild(da);
-       }
+       if(deliveryaddrid>=0)cord.setdeliveryaddressid(deliveryaddrid);
+       if(invoiceaddrid>=0)cord.setinvoiceaddressid(invoiceaddrid);
        //is there a comment?
-       s=cartcomment->toPlainText().trimmed();
-       if(s!=""){
-               QDomElement cc=doc.createElement("Comment");
-               cc.appendChild(doc.createTextNode(s));
-               root.appendChild(cc);
-       }
+       QString s=cartcomment->toPlainText().trimmed();
+       if(s!="")cord.setcomment(s);
        //scan tickets & scan vouchers
        for(int i=0;i<cartmodel->rowCount();i++){
                QModelIndex idx=cartmodel->index(i,0);
                int tp=cartmodel->data(idx,CART_TYPEROLE).toInt();
                if(tp==CART_TICKET){
-                       int amt=cartmodel->data(idx).toInt();
-                       int evid=cartmodel->data(idx,CART_IDROLE).toInt();
-                       for(int j=0;j<amt;j++){
-                               QDomElement tc=doc.createElement("Ticket");
-                               tc.setAttribute("event",evid);
-                               root.appendChild(tc);
-                       }
+                       MOCartTicket ct;
+                       ct.setamount(cartmodel->data(idx).toInt());
+                       ct.seteventid(cartmodel->data(idx,CART_IDROLE).toInt());
+                       cord.addtickets(ct);
                }else
                if(tp==CART_VOUCHER){
-                       int amt=cartmodel->data(idx).toInt();
-                       int price=cartmodel->data(idx,CART_PRICEROLE).toInt();
-                       int value=cartmodel->data(idx,CART_VALUEROLE).toInt();
-                       for(int j=0;j<amt;j++){
-                               QDomElement tc=doc.createElement("Voucher");
-                               tc.setAttribute("price",price);
-                               tc.setAttribute("value",value);
-                               root.appendChild(tc);
-                       }
-               
+                       MOCartVoucher cv;
+                       cv.setamount(cartmodel->data(idx).toInt());
+                       cv.setprice(cartmodel->data(idx,CART_PRICEROLE).toInt());
+                       cv.setvalue(cartmodel->data(idx,CART_VALUEROLE).toInt());
+                       cord.addvouchers(cv);
                }
+               //TODO: product/items
        }
        //set shipping info
-       if(cartship->currentIndex()>0){
-               QDomElement si=doc.createElement("Shipping");
-               si.setAttribute("type",cartship->itemData(cartship->currentIndex()).toInt());
-               root.appendChild(si);
-       }
-       //finalize
-       doc.appendChild(root);*/
+       cord.setshippingtypeid(cartship->itemData(cartship->currentIndex()).toInt());
        //send
-       /*TODO
-       if(req->request("checkorder",doc.toByteArray())==false){
-               QMessageBox::warning(this,tr("Error"),tr("The request failed."));
-               return;
-       }
-       if(req->responseStatus()!=MSInterface::Ok){
-               QMessageBox::warning(this,tr("Error"),tr("A problem occurred during the order: %1").arg(qApp->translate("php::",req->responseBody())));
+       MTCreateOrder co=req->queryCreateOrder(cord);
+       if(co.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Error while creating order: %1").arg(co.errorString()));
                return;
        }
-       //parse result
-       QDomDocument rdoc;
-       rdoc.setContent(req->responseBody());
-       //display order and give user chance to actually order it
-       MOrderWindow *ow=new MOrderWindow(this,req,MOrder(req,rdoc.documentElement()));
+       initCart();
+       MOrderWindow *ow=new MOrderWindow(window(),co.getorder());
        ow->show();
-       //empty the cart
-       initCart();*/
 }
 
 /********************************************************************************/
index 4200e70..99a2365 100644 (file)
@@ -73,12 +73,18 @@ class MCartTab:public QWidget
        private slots:
                /**decide what customer to use*/
                void setCustomer();
+               /**decide about delivery address*/
+               void setDeliveryAddr();
+               /**decide about invoice address*/
+               void setInvoiceAddr();
                /**initialize cart tab*/
                void initCart();
                /**add a ticket to the cart*/
                void cartAddTicket();
                /**add a voucher to the cart*/
                void cartAddVoucher();
+               /**add a product item to the cart*/
+               void cartAddItem();
                /**remove item from the cart*/
                void cartRemoveItem();
                /**check the order on the server*/
@@ -90,11 +96,12 @@ class MCartTab:public QWidget
                //widgets
                QTableView*carttable;
                QStandardItemModel*cartmodel;
-               QLabel*cartcustomer;
-               QTextEdit *cartaddr,*cartcomment;
+               QLabel*cartcustomer,*deliveryaddr,*invoiceaddr;
+               QTextEdit *cartcomment;
                QComboBox*cartship;
                //cart
                MOCustomer customer;
+               qint64 deliveryaddrid,invoiceaddrid;
 };
 
 /**Helper class for shopping cart: allow editing amount, but nothing else*/
index 587bc76..6d487de 100644 (file)
@@ -21,9 +21,11 @@ MOCustomer::MOCustomer(qint64 i)
                operator=(gc.getcustomer().value());
 }
 
-MOCustomer::MOCustomer(const MOCustomerInfo&i)
+MOCustomer::MOCustomer(const MOCustomerInfo&ci)
 {
-       MOCustomer::MOCustomer(i.id());
+       MTGetCustomer gc=req->queryGetCustomer(ci.id());
+       if(gc.stage()==gc.Success)
+               operator=(gc.getcustomer().value());
 }
 
 QString MOCustomer::address(int i)
@@ -31,16 +33,21 @@ QString MOCustomer::address(int i)
        if(i<0)return "";
        QList<MOAddress>adrs=addresses();
        if(i>=adrs.size())return "";
-       QString ret;
-       MOAddress adr=adrs[i];
-       if(adr.name().isNull())ret=name();
-       else ret=adr.name().value();
-       ret+="\n";
-       if(!adr.addr1().isNull())ret+=adr.addr1().value()+"\n";
-       if(!adr.addr2().isNull())ret+=adr.addr2().value()+"\n";
-       if(!adr.city().isNull())ret+=adr.city().value()+"\n";
-       if(!adr.state().isNull())ret+=adr.state().value()+"\n";
-       if(!adr.zipcode().isNull())ret+=adr.zipcode().value()+"\n";
-       if(!adr.country().isNull())ret+=adr.country().value().name();
+       return adrs[i].fullAddress(fullName());
+}
+
+QString MOCustomer::fullName()const
+{
+       QString ret=title().value().trimmed();
+       QString s=name().value().trimmed();
+       if(s!=""){
+               if(ret!="")ret+=" ";
+               ret+=s;
+       }
+       s=firstname().value().trimmed();
+       if(s!=""){
+               if(ret!="")ret+=", ";
+               ret+=s;
+       }
        return ret;
 }
index 95a61f3..bde3b20 100644 (file)
@@ -35,7 +35,7 @@ class MOCustomer:public MOCustomerAbstract
                QString address(int i=0);
                
                /**returns the full name (incl. title)*/
-               QString fullName()const{return title()+" "+name()+", "+firstname();}
+               QString fullName()const;
 
 };
 
index 52bf13c..336d1a2 100644 (file)
 
 #include "MOCustomerInfo.h"
 
+QString MOCustomerInfo::fullName()const
+{
+       QString ret=title().value().trimmed();
+       QString s=name().value().trimmed();
+       if(s!=""){
+               if(ret!="")ret+=" ";
+               ret+=s;
+       }
+       s=firstname().value().trimmed();
+       if(s!=""){
+               if(ret!="")ret+=", ";
+               ret+=s;
+       }
+       return ret;
+}
index dd6c7e9..76b8900 100644 (file)
@@ -19,7 +19,7 @@ class MOCustomerInfo:public MOCustomerInfoAbstract
        WOBJECT(MOCustomerInfo);
        public:
                /**returns the full name (incl. title)*/
-               QString fullName()const{return title()+" "+name()+", "+firstname();}
+               QString fullName()const;
                
                /**alias for customerid()*/
                Nullable<qint64> id()const{return customerid();}
index 641931c..426c967 100644 (file)
@@ -68,6 +68,7 @@
                        <Value name="InvalidValue"/>
                        <Value name="InvalidPrice"/>
                </Enum>
+               <Property name="amount" type="int"/>
                <Property name="value" type="int"/>
                <Property name="price" type="int" optional="1"/>
                <Property name="status" type="ValidationState" optional="1"/>
                </Enum>
                <Property name="status" type="ValidationState" optional="1"/>
                <Property name="customerid" type="int"/>
+               <Property name="invoiceaddressid" type="int"/>
+               <Property name="deliveryaddressid" type="int"/>
+               <Property name="comment" type="string"/>
+               <Property name="shippingtypeid" type="int"/>
                <Property name="tickets" type="List:CartTicket"/>
                <Property name="vouchers" type="List:CartVoucher"/>
        </Class>
index 6b63bd5..4528a80 100644 (file)
                        <Var name="customerid" type="int"/>
                        <Var name="mergewithid" type="int"/>
                </Input>
+               <Call lang="php" method="WOCustomer::deleteCustomer($this);"/>
+               <Output>
+                       <Var name="customer" type="Customer"/>
+               </Output>
        </Transaction>
        
        <Transaction name="GetAddress">
index d1304fc..ae08b0e 100644 (file)
@@ -2,13 +2,13 @@
 <!-- Main MagicSmoke WOLF
   - makes some basic settings and then includes the real object files.
   -
-  - (c) Konrad Rosenbaum, 2009
+  - (c) Konrad Rosenbaum, 2009-2010
   - this file is protected under the GNU AGPLv3 or at your option any newer
   - see COPYING.AGPL for details
   -->
 <Wolf>
        <Doc>These files describe the database schema and communication protocol of MagicSmoke.</Doc>
-       <Doc>(c) Konrad Rosenbaum, 2009&lt;br/>these files are protected under the GNU AGPLv3 or at your option any newer</Doc>
+       <Doc>(c) Konrad Rosenbaum, 2009-2010&lt;br/>these files are protected under the GNU AGPLv3 or at your option any newer</Doc>
        <!-- generic settings -->
        <Project baseDir=".." wobDir="wob" name="MagicSmoke"/>
        <Version comm="0100" needcomm="0100" humanReadable="1.91 alpha" svnTarget="."/>
index bb36af6..d82b43a 100644 (file)
                </Output>
        </Transaction>
        
-       <Transaction name="CreateOrder"/>
-       <Transaction name="CreateReservation"/>
+       <Transaction name="CreateOrder">
+               <Doc>CreateOrder creates orders that are queued to be executed 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>
+               <Input>
+                       <Var name="cart" type="CartOrder"/>
+               </Input>
+               <Output>
+                       <Var name="order" type="Order"/>
+               </Output>
+       </Transaction>
+       
+       <Transaction name="CreateReservation">
+               <Doc>Reservations are orders that are not executed right away. They may only contain tickets that block some seats for a limited time. They cannot contain any shopping items or vouchers.</Doc>
+               <Input>
+                       <Var name="cart" type="CartOrder"/>
+               </Input>
+               <Output>
+                       <Var name="order" type="Order"/>
+               </Output>
+       </Transaction>
        <Transaction name="ReservationToOrder">
+               <Doc>This transaction turns a reservation into a regular order</Doc>
                <Input>
                        <Var name="orderid" type="int"/>
                </Input>
                        <Var name="shipping" type="List:Shipping"/>
                </Output>
        </Transaction>
+       
+       <Transaction name="GetValidVoucherPrices">
+               <Call lang="php" method="$this->setprices(explode(' ',$GLOBALS['db']->getConfig('ValidVouchers')));"/>
+               <Output>
+                       <Var name="prices" type="List:int"/>
+               </Output>
+       </Transaction>
 </Wolf>
\ No newline at end of file
index 08dc8f5..9835b79 100644 (file)
@@ -136,6 +136,65 @@ class WOCustomer extends WOCustomerAbstract
                //return
                $trans->setcustomer(WOCustomer::fromTablecustomer($ct));
        }
+       
+       /**called from DeleteCustomer transaction*/
+       public static function deleteCustomer($trans)
+       {
+               //get customer table objects
+               $dc=WTcustomer::getFromDB($trans->getcustomerid());
+               $mc=WTcustomer::getFromDB($trans->getmergewithid());
+               if(!is_a($dc,"WTcustomer")){
+                       $trans->abortWithError(tr("Not a valid customer, cannot delete."));
+                       return;
+               }
+               $domerge=is_a($mc,"WTcustomer");
+               //delete any left over sessions
+               global $db;
+               $db->deleteRows("websession","customerid=".$db->escapeInt($dc->customerid));
+               //collect owned objects
+               $addr=WTaddress::selectFromDB("customerid=".$db->escapeInt($dc->customerid));
+               $cont=WTcontact::selectFromDB("customerid=".$db->escapeInt($dc->customerid));
+               $ordr=WTorder::selectFromDB("customerid=".$db->escapeInt($dc->customerid));
+               //if not merge
+               if(!$domerge){
+                       //sanity check
+                       if(count($ordr)>0){
+                               $trans->abortWithError(tr("This customer has orders in the system, cannot delete."));
+                               return;
+                       }
+                       //delete sub-objects
+                       foreach($addr as $ad)
+                               $ad->deleteFromDB();
+                       foreach($cont as $ct)
+                               $ct->deleteFromDB();
+                       //delete
+                       $dc->deleteFromDB();
+               }else{//if merge...
+                       //sanity check
+                       if($dc->customerid == $mc->customerid){
+                               $trans->abortWithError(tr("Cannot merge a customer with itself."));
+                               return;
+                       }
+                       //transfer sub-objects
+                       foreach($ordr as $od){
+                               $od->customerid=$mc->customerid;
+                               $od->update();
+                       }
+                       foreach($cont as $od){
+                               $od->customerid=$mc->customerid;
+                               $od->update();
+                       }
+                       foreach($addr as $od){
+                               $od->customerid=$mc->customerid;
+                               $od->update();
+                       }
+                       //delete
+                       $dc->deleteFromDB();
+                       //return substitute
+                       $trans->setcustomer(WOCustomer::fromTablecustomer($mc));
+               }
+               print($db->lastError());
+       }
 
        /**called from CreateCountry transaction*/
        public static function createCountry($trans)