From 2d7bd40089ea64d288aa5718baea71fa804975b9 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 30 Dec 2009 17:38:48 +0000 Subject: [PATCH] significantly more on order window got rid of old event.* git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@379 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/eventedit.h | 4 +- src/dialogs/orderwin.cpp | 172 ++++++++++++++++++++++--------------------- src/dialogs/orderwin.h | 11 +--- src/iface/event.cpp | 66 ---------------- src/iface/event.h | 69 ----------------- src/iface/iface.pri | 2 - src/iface/msinterface.cpp | 4 + src/iface/msinterface.h | 5 + src/templates/templates.h | 2 +- src/wbase/WObject.h | 12 +++ src/wext/MOAddress.cpp | 40 ++++++++++ src/wext/MOAddress.h | 30 ++++++++ src/wext/MOCustomerInfo.cpp | 14 ++++ src/wext/MOCustomerInfo.h | 5 +- src/wext/MOEvent.cpp | 67 +++++++++++++++++ src/wext/MOEvent.h | 50 +++++++++++++ src/wext/MOOrder.cpp | 23 ++++++ src/wext/MOOrder.h | 4 + src/wext/MOTicket.h | 14 +++- src/wext/MOVoucher.h | 33 ++++++++ src/wext/wext.pri | 9 ++- wob/customer.wolf | 1 + wob/event.wolf | 11 +++ wob/order.wolf | 16 ++++ woc/phpout.cpp | 42 ++++++++++- woc/phpout.h | 2 + woc/processor.cpp | 18 +++++ woc/processor.h | 8 ++ woc/qtout.cpp | 12 +++ www/inc/classes/event.php | 8 ++ www/inc/wbase/table.php | 19 ++++- www/inc/wext/order.php | 38 +++++++++- 32 files changed, 558 insertions(+), 253 deletions(-) delete mode 100644 src/iface/event.cpp delete mode 100644 src/iface/event.h create mode 100644 src/wext/MOAddress.cpp create mode 100644 src/wext/MOAddress.h create mode 100644 src/wext/MOCustomerInfo.cpp create mode 100644 src/wext/MOEvent.cpp create mode 100644 src/wext/MOEvent.h create mode 100644 src/wext/MOVoucher.h diff --git a/src/dialogs/eventedit.h b/src/dialogs/eventedit.h index bd183a7..96f5046 100644 --- a/src/dialogs/eventedit.h +++ b/src/dialogs/eventedit.h @@ -15,7 +15,7 @@ #include -#include "event.h" +#include "MOEvent.h" class QCheckBox; class QDateTime; @@ -38,7 +38,7 @@ class MEventEditor:public QDialog void startTimeChanged(const QDateTime&); void endTimeChanged(const QDateTime&); private: - MEvent event; + MOEvent event; QDateTimeEdit*starttime,*endtime; QLineEdit*title,*artist,*room,*price,*cancelreason; QTextEdit*description; diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index 8b60a08..4a6f118 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -11,7 +11,6 @@ // #include "centbox.h" -#include "event.h" #include "labeldlg.h" #include "misc.h" #include "moneylog.h" @@ -19,6 +18,9 @@ #include "orderwin.h" #include "ticketrender.h" #include "msinterface.h" +#include "templates.h" + +#include "MOEvent.h" #include #include @@ -67,7 +69,7 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) m->addAction(tr("Change Commen&t..."),this,SLOT(changeComment())) ->setEnabled(req->hasRole("setordercomment")); m->addAction(tr("Change Sh&ipping Method..."),this,SLOT(changeShipping())) - ->setEnabled(req->hasRole("changeordershipping")); + ->setEnabled(req->hasRight(req->ROrderChangeShipping)); m->addSeparator(); m->addAction(tr("MoneyLog for Order..."),this,SLOT(moneyLogOrder())) ->setEnabled(req->hasRole("moneylog")); @@ -110,9 +112,14 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) gl->addWidget(m_sentdate=new QLabel(m_order.sentDateTimeStr()),rw,1); gl->addWidget(new QLabel(tr("Customer:")),++rw,0); gl->addWidget(new QLabel(m_order.customer().value().fullName()),rw,1); - gl->addWidget(new QLabel(tr("Delivery Address:")),++rw,0); - //FIXME:gl->addWidget(lab=new QLabel(m_order.deliveryAddress()),rw,1); - //lab->setWordWrap(true); + gl->addWidget(lab=new QLabel(tr("Delivery Address:")),++rw,0); + lab->setAlignment(Qt::AlignTop); + gl->addWidget(lab=new QLabel(m_order.fullDeliveryAddress(false)),rw,1); + lab->setWordWrap(true);lab->setFrameShape(lab->Box);lab->setFrameShadow(lab->Raised); + gl->addWidget(lab=new QLabel(tr("Invoice Address:")),++rw,0); + lab->setAlignment(Qt::AlignTop); + gl->addWidget(lab=new QLabel(m_order.fullInvoiceAddress(false)),rw,1); + lab->setWordWrap(true);lab->setFrameShape(lab->Box);lab->setFrameShadow(lab->Raised); gl->addWidget(new QLabel(tr("Sold by:")),++rw,0); gl->addWidget(new QLabel(m_order.soldby()),rw,1); gl->addWidget(new QLabel(tr("Total Price:")),++rw,0); @@ -122,14 +129,13 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) gl->addWidget(new QLabel(tr("Order State:")),++rw,0); gl->addWidget(m_state=new QLabel(m_order.orderStatusString()),rw,1); gl->addWidget(new QLabel(tr("Shipping Method:")),++rw,0); - //FIXME: - gl->addWidget(m_shipmeth=new QLabel(/*m_order.shipping().description()*/"ship?"),rw,1); + gl->addWidget(m_shipmeth=new QLabel(m_order.shippingtype().value().description()),rw,1); gl->addWidget(new QLabel(tr("Shipping Costs:")),++rw,0); - gl->addWidget(m_shipprice=new QLabel(/*m_order.shipping().priceString()*/),rw,1); - gl->addWidget(new QLabel(tr("Order Comment:")),++rw,0); - //FIXME: - gl->addWidget(m_comment=lab=new QLabel(/*m_order.comment()*/"comment?"),rw,1); - lab->setWordWrap(true); + gl->addWidget(m_shipprice=new QLabel(cent2str(m_order.shippingcosts())),rw,1); + gl->addWidget(lab=new QLabel(tr("Order Comment:")),++rw,0); + lab->setAlignment(Qt::AlignTop); + gl->addWidget(m_comment=lab=new QLabel(m_order.comments()),rw,1); + lab->setWordWrap(true);lab->setFrameShape(lab->Box);lab->setFrameShadow(lab->Raised); gl->setColumnStretch(0,0); gl->setColumnStretch(1,10); @@ -147,46 +153,66 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) sz.setHeight(sz.height()+vsz.height()+40); //TODO: limit this to the screen size; find a better measure than viewport resize(sz); - - req->dataDir(); } static const int ITEM_TICKET=1; static const int ITEM_VOUCHER=2; +static const int ITEM_ITEM=3; void MOrderWindow::updateTable() -{/*TODO: +{ + //get detail data QList tickets=m_order.tickets(); - QList events; - if(tickets.size()>0) - events=req->getAllEvents(); - QList vouchers=m_order.vouchers(); + QList events; + if(tickets.size()>0){ + QListevid; + for(int i=0;iqueryGetEventList(evid); + events=gel.getevents(); + } + QList vouchers=m_order.vouchers(); + QList items=m_order.items(); + //set up model m_model->clear(); m_model->setHorizontalHeaderLabels(QStringList()<insertRows(0,tickets.size()+vouchers.size()); + m_model->insertRows(0,tickets.size()+vouchers.size()+items.size()); + //insert tickets for(int i=0;isetData(m_model->index(i,0),tickets[i].ticketID()); + m_model->setData(m_model->index(i,0),tickets[i].ticketid().value()); m_model->setData(m_model->index(i,0),ITEM_TICKET,Qt::UserRole); m_model->setData(m_model->index(i,3),tickets[i].statusString()); m_model->setData(m_model->index(i,4),tickets[i].priceString()); //find event - MEvent ev;int eid=tickets[i].eventID(); + MOEvent ev;int eid=tickets[i].eventid(); for(int j=0;jsetData(m_model->index(i,1),ev.title()); + m_model->setData(m_model->index(i,1),ev.title().value()); m_model->setData(m_model->index(i,2),ev.startTimeString()); } + //insert vouchers int off=tickets.size(); for(int i=0;isetData(m_model->index(i+off,0),ITEM_VOUCHER,Qt::UserRole); - m_model->setData(m_model->index(i+off,0),vouchers[i].voucherID()); + m_model->setData(m_model->index(i+off,0),vouchers[i].voucherid().value()); m_model->setData(m_model->index(i+off,1),tr("Voucher (current value: %1)").arg(vouchers[i].valueString())); m_model->setData(m_model->index(i+off,3),vouchers[i].statusString()); m_model->setData(m_model->index(i+off,4),vouchers[i].priceString()); } - m_table->resizeColumnsToContents();*/ + //TODO: insert items + off+=vouchers.size(); + for(int i=0;isetData(m_model->index(i+off,0),ITEM_ITEM,Qt::UserRole); + m_model->setData(m_model->index(i+off,0),items[i].itemid().value()); + m_model->setData(m_model->index(i+off,1),tr("%1x %2").arg(items[i].amount().value()).arg(items[i].productname().value())); + m_model->setData(m_model->index(i+off,3),""); + m_model->setData(m_model->index(i+off,4),cent2str(items[i].totalprice())); + } + //refresh + m_table->resizeColumnsToContents(); } void MOrderWindow::setChanged() @@ -239,22 +265,20 @@ void MOrderWindow::printCurrentItem() void MOrderWindow::printTickets() { - //FIXME: - //printTickets(m_order.tickets()); + printTickets(m_order.tickets()); } void MOrderWindow::printVouchers() { - //FIXME - //printVouchers(m_order.vouchers()); + printVouchers(m_order.vouchers()); } void MOrderWindow::printTickets(QList ticketsin) -{/*TODO +{ //reduce ticket list to usable ones - QList tickets; + QList tickets; for(int i=0;i ticketsin) return; } //get template - MTemplate tf=req->getTemplate("ticket"); + MTemplate tf=req->templateStore()->getTemplate("ticket"); if(!tf.isValid()){ QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (ticket.xtt). Giving up.")); return; @@ -287,15 +311,15 @@ void MOrderWindow::printTickets(QList ticketsin) printer.newPage(); } render.render(tickets[i],printer,&painter,p); - }*/ + } } void MOrderWindow::printVouchers(QList vouchersin) -{/*TODO +{ //reduce voucher list to usable ones - QListvouchers; + QListvouchers; for(int i=0;i0 && vouchersin[i].xmlState()=="") + if(vouchersin[i].isValid() && vouchersin[i].value()>0) vouchers.append(vouchersin[i]); } //sanity check @@ -304,7 +328,7 @@ void MOrderWindow::printVouchers(QList vouchersin) return; } //get template - MTemplate tf=req->getTemplate("voucher"); + MTemplate tf=req->templateStore()->getTemplate("voucher"); if(!tf.isValid()){ QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (voucher.xtt). Giving up.")); return; @@ -328,7 +352,7 @@ void MOrderWindow::printVouchers(QList vouchersin) printer.newPage(); } render.render(vouchers[i],printer,&painter,p); - }*/ + } } void MOrderWindow::restorePrinter(QPrinter&prn,QString key) @@ -841,31 +865,6 @@ void MOrderWindow::createOrder(Create mode) close();*/ } -void MOrderWindow::createSale() -{ - createOrder(CreateSale); -} - -void MOrderWindow::createReservation() -{ - createOrder(CreateReservation); -} - -void MOrderWindow::recheckOrder() -{/*TODO - //prune - m_order.pruneInvalid(); - //now check - MOrder ord; - ord=m_order.createOrder("checkorder"); - if(!ord.isValid())return; - //display final order - MOrderWindow *ow=new MOrderWindow(parentWidget(),req,ord); - ow->show(); - //undisplay self - close();*/ -} - void MOrderWindow::shipOrder() {/*TODO if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){ @@ -926,17 +925,24 @@ void MOrderWindow::changeComment() } void MOrderWindow::changeShipping() -{/*TODO +{ //create editor dialog - MShippingChange d(this,req,m_order.shipping()); + MShippingChange d(this,m_order.shippingtype(),m_order.shippingcosts()); //get status if(d.exec()!=QDialog::Accepted)return; //send to server - m_order.sendShipping(d.selection()); + int shipid=-1; + if(!d.selection().shipid().isNull())shipid=d.selection().shipid(); + MTOrderChangeShipping ocs=req->queryOrderChangeShipping(m_order.orderid(),shipid,d.price()); + if(ocs.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while changing shipping: %1").arg(ocs.errorString())); + return; + } + m_order=ocs.getorder(); //reset display - m_shipmeth->setText(m_order.shipping().description()); - m_shipprice->setText(m_order.shipping().priceString()); - m_total->setText(m_order.totalPriceString());*/ + m_shipmeth->setText(m_order.shippingtype().value().description()); + m_shipprice->setText(cent2str(m_order.shippingcosts())); + m_total->setText(m_order.totalPriceString()); } void MOrderWindow::moneyLogOrder() @@ -984,23 +990,20 @@ MOrderItemView::MOrderItemView(QWidget*w,QListt,QListv) cb->addItem(tr("Voucher: ")+vouchers[i].voucherid()); vl->addWidget(disp=new QLabel,10); //get the templates - /*TODO - trender=new MTicketRenderer(req->getTemplate("ticket")); - vrender=new MVoucherRenderer(req->getTemplate("voucher")); - */ + trender=new MTicketRenderer(req->templateStore()->getTemplate("ticket")); + vrender=new MVoucherRenderer(req->templateStore()->getTemplate("voucher")); changeItem(0); connect(cb,SIGNAL(currentIndexChanged(int)),this,SLOT(changeItem(int))); } MOrderItemView::~MOrderItemView() { - //FIXME - //delete trender; - //delete vrender; + delete trender; + delete vrender; } void MOrderItemView::changeItem(int idx) -{/*TODO +{ //ticket or voucher? if(idxlabelSize(*disp); @@ -1016,21 +1019,20 @@ void MOrderItemView::changeItem(int idx) if(!vrender->render(vouchers[idx-tickets.size()],tick)) qDebug("unable to render"); disp->setPixmap(tick); - }*/ + } } /*************************************************************************************/ -MShippingChange::MShippingChange(QWidget*pa,MOShipping s) +MShippingChange::MShippingChange(QWidget*pa,MOShipping s,int costs) :QDialog(pa) { all=req->queryGetAllShipping().getshipping(); setWindowTitle(tr("Change Shipping Method")); int cid=-1; - //FIXME: - //if(s.isValid())cid=s.id(); + if(!s.shipid().isNull())cid=s.shipid(); QGridLayout*gl; setLayout(gl=new QGridLayout); @@ -1050,8 +1052,8 @@ MShippingChange::MShippingChange(QWidget*pa,MOShipping s) connect(p,SIGNAL(clicked()),this,SLOT(reject())); prc->setRange(0,1000000000);//hmm, even in Yen this should be big enough - prc->setValue(s.cost()); - prc->setEnabled(req->hasRole("orderchangeshipping")); + prc->setValue(costs); + prc->setEnabled(req->hasRight(req->POrderChangeShipping_ChangePrice)); opt->addItem(tr("(None)","shipping method")); int scid=0; diff --git a/src/dialogs/orderwin.h b/src/dialogs/orderwin.h index b4175ac..d08819c 100644 --- a/src/dialogs/orderwin.h +++ b/src/dialogs/orderwin.h @@ -96,15 +96,6 @@ class MOrderWindow:public QMainWindow /**create a new order*/ void createOrder(Create mode=CreateOrder); - /**create a sale*/ - void createSale(); - - /**create a new reservation*/ - void createReservation(); - - /**prune and recheck the order*/ - void recheckOrder(); - /**money log for the order*/ void moneyLogOrder(); /**money log for a voucher*/ @@ -170,7 +161,7 @@ class MShippingChange:public QDialog Q_OBJECT public: /**creates the dialog*/ - MShippingChange(QWidget*,MOShipping); + MShippingChange(QWidget*,MOShipping,int); /**returns the selected shipping option, including corrected price*/ MOShipping selection()const; diff --git a/src/iface/event.cpp b/src/iface/event.cpp deleted file mode 100644 index e81f4a6..0000000 --- a/src/iface/event.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// C++ Implementation: event -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "event.h" - -#include -#include -#include -#include - -#include "msinterface.h" - -MEvent::MEvent(qint64 i) -{ - MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); - if(ge.stage()==ge.Success) - operator=(ge.getevent().value()); -} - -QRegExp MEvent::priceRegExp()const -{ - return QRegExp(QCoreApplication::translate("MEvent","[0-9]+\\.[0-9]{2}","price validator regexp")); -} - -QString MEvent::priceString()const -{ - qint64 dp=/*defaultprice()*/0; - QString ret=QString::number(dp/100); - ret+=QCoreApplication::translate("MEvent",".","price decimal dot"); - ret+=QString::number((dp/10)%10); - ret+=QString::number(dp%10); - return ret; -} - -QString MEvent::startTimeString()const -{ - return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); -} - -QString MEvent::startDateString()const -{ - return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd","date format")); -} - -QString MEvent::endTimeString()const -{ - return QDateTime::fromTime_t(end()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); -} - -void MEvent::setdefaultprice(QString str) -{ - QStringList ps=str.split(QCoreApplication::translate("MEvent",".","price decimal dot")); - qint64 prc=0; - if(ps.size()>=1)prc=ps[0].toInt()*100; - if(ps.size()>=2)prc+=ps[1].toInt(); - setdefaultprice(prc); -} diff --git a/src/iface/event.h b/src/iface/event.h deleted file mode 100644 index e5b9f7b..0000000 --- a/src/iface/event.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// C++ Interface: event -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef EVENT_H -#define EVENT_H - -#include -#include - -/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ -class MEvent:public MOEvent -{ - public: - /**creates an invalid event*/ - MEvent():MOEvent(){} - /**copies an event*/ - MEvent(const MEvent&e):MOEvent(e){} - /**copies an event*/ - MEvent(const MOEvent&e):MOEvent(e){} - /**get event directly from server*/ - MEvent(qint64); - /**destructs an event*/ - ~MEvent(){} - - /**copies the event*/ - MEvent& operator=(const MEvent&e){MOEvent::operator=(e);return *this;} - - /**updates data from the database, can be used to upgrade an incomplete event to a complete one*/ - //void refresh(); - - /**saves all data back to the database, it returns an empty string on success, it does not do anything if the event is invalid or incomplete*/ - //QString save(); - - /**returns the start time of the event as localized string*/ - QString startTimeString()const; - /**returns the start date as localized string*/ - QString startDateString()const; - /**returns the end time of the event as localized string*/ - QString endTimeString()const; - /**returns the room of the event, the room must be one out of the list of valid rooms*/ - - /**returns the price as a localized string*/ - QString priceString()const; - /**returns the local regular expression for prices*/ - QRegExp priceRegExp()const; - - /**set the price as string*/ - void setdefaultprice(QString); - - //inherit alternative definition - inline void setdefaultprice(qint64 p){/*MOEvent::setdefaultprice(p);*/} - - /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ - //bool isValid()const{return m_valid;} - - /**requests to cancel the event from the DB; expects reason as argument; returns true on success*/ - //bool cancelEvent(QString); -}; - -#endif diff --git a/src/iface/iface.pri b/src/iface/iface.pri index 2836044..c9dc8e7 100644 --- a/src/iface/iface.pri +++ b/src/iface/iface.pri @@ -1,13 +1,11 @@ HEADERS += \ iface/msinterface.h \ - iface/event.h \ iface/sslexception.h \ iface/customer.h SOURCES += \ iface/msinterface.cpp \ - iface/event.cpp \ iface/sslexception.cpp \ iface/customer.cpp diff --git a/src/iface/msinterface.cpp b/src/iface/msinterface.cpp index 74f4ba0..374efee 100644 --- a/src/iface/msinterface.cpp +++ b/src/iface/msinterface.cpp @@ -13,6 +13,7 @@ #include "msinterface.h" #include "main.h" #include "sslexception.h" +#include "templates.h" #include #include @@ -41,6 +42,7 @@ MSInterface::MSInterface(QString pid) setLogLevel((LogLevel)set.value("webloglevel",LogOnError).toInt()); setWebTimeout(set.value("webtimeout",30).toInt()*1000); sslexcept=new MSslExceptions(dataDir()+"/sslexceptions.xml"); + temp=new MTemplateStore(pid); } MSInterface::~MSInterface() @@ -48,6 +50,8 @@ MSInterface::~MSInterface() logout(); if(sslexcept)delete sslexcept; sslexcept=0; + if(temp)delete temp; + temp=0; } bool MSInterface::login(QString username,QString passwd) diff --git a/src/iface/msinterface.h b/src/iface/msinterface.h index 937d8c7..bc4b07f 100644 --- a/src/iface/msinterface.h +++ b/src/iface/msinterface.h @@ -19,6 +19,7 @@ class MSslExceptions; +class MTemplateStore; /**the MagicSmoke specific interface class - enhances the basic interface by some functionality needed in the MagicSmoke context*/ class MSInterface:public MInterface @@ -64,6 +65,9 @@ class MSInterface:public MInterface /**initializes the interface, ie. retrieves language and scripts*/ void initialize(); + + /**returns a pointer to the template storage engine*/ + MTemplateStore* templateStore(){return temp;} public slots: /**logs into the server, returns true on success*/ @@ -84,6 +88,7 @@ class MSInterface:public MInterface QByteArray servertranslation; MSslExceptions*sslexcept; bool didsslerror; + MTemplateStore *temp; }; diff --git a/src/templates/templates.h b/src/templates/templates.h index 08e5aa4..6fe0d96 100644 --- a/src/templates/templates.h +++ b/src/templates/templates.h @@ -105,7 +105,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(MTemplate::Types) class MTemplateStore { protected: - //FIXME friend class MWebRequest; + friend class MSInterface; friend class MTemplateEditor; /**instantiates the template subsystem*/ MTemplateStore(QString); diff --git a/src/wbase/WObject.h b/src/wbase/WObject.h index d10cbc6..afce3bd 100644 --- a/src/wbase/WObject.h +++ b/src/wbase/WObject.h @@ -22,16 +22,28 @@ class QDomElement; class QDomDocument; +/**base class of all web based objects*/ class WObject:public QObject { protected: WObject(){} }; +/**this exception is thrown if the deserialization of an object fails on the XML parser level*/ class WDeserializerException:public WException { public: WDeserializerException(QString e):WException(e,"Deserializer"){} }; +/**the WOBJECT macro defines the necessary constructors if you just want to extend an abstract class without overwriting the constructors yourself*/ +#define WOBJECT(wob) public: \ + wob():wob ## Abstract(){} \ + wob(const wob&w):wob ## Abstract(w){} \ + wob(const wob ## Abstract&w):wob ## Abstract(w){} \ + wob(const QDomElement&w):wob ## Abstract(w){} \ + wob& operator=(const wob&w){wob ## Abstract::operator=(w);return *this;} \ + wob& operator=(const wob ## Abstract&w){wob ## Abstract::operator=(w);return *this;} \ + private: + #endif diff --git a/src/wext/MOAddress.cpp b/src/wext/MOAddress.cpp new file mode 100644 index 0000000..2f18aea --- /dev/null +++ b/src/wext/MOAddress.cpp @@ -0,0 +1,40 @@ +// +// C++ Implementation: MOAddress +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "MOAddress.h" + +#include + +QString MOAddress::fullAddress(QString nm)const +{ + //if not valid: return nothing + if(!isValid())return ""; + //collect lines + QStringList rl; + if(name().isNull()){ + if(nm!="")rl<, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MADDRESS_H +#define MAGICSMOKE_MADDRESS_H + +#include "MOAddressAbstract.h" + +class MOAddress:public MOAddressAbstract +{ + WOBJECT(MOAddress); + public: + /**returns the full address, if name is given and the address does not have its own name, it is included as top line*/ + QString fullAddress(QString name=QString())const; + + /**returns true if this is a valid address (ie. it has an address ID)*/ + bool isValid()const{return !addressid().isNull() && addressid().value()>=0;} +}; + + +#endif diff --git a/src/wext/MOCustomerInfo.cpp b/src/wext/MOCustomerInfo.cpp new file mode 100644 index 0000000..52bf13c --- /dev/null +++ b/src/wext/MOCustomerInfo.cpp @@ -0,0 +1,14 @@ +// +// C++ Implementation: MOCustomerInfo +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "MOCustomerInfo.h" + diff --git a/src/wext/MOCustomerInfo.h b/src/wext/MOCustomerInfo.h index 998befe..34c1bcc 100644 --- a/src/wext/MOCustomerInfo.h +++ b/src/wext/MOCustomerInfo.h @@ -16,11 +16,8 @@ #include "MOCustomerInfoAbstract.h" class MOCustomerInfo:public MOCustomerInfoAbstract { + WOBJECT(MOCustomerInfo); public: - MOCustomerInfo():MOCustomerInfoAbstract(){} - MOCustomerInfo(const MOCustomerInfo&o):MOCustomerInfoAbstract(o){} - MOCustomerInfo(const QDomElement&e):MOCustomerInfoAbstract(e){} - QString fullName()const{return title()+" "+name()+", "+firstname();} }; diff --git a/src/wext/MOEvent.cpp b/src/wext/MOEvent.cpp new file mode 100644 index 0000000..d8413eb --- /dev/null +++ b/src/wext/MOEvent.cpp @@ -0,0 +1,67 @@ +// +// C++ Implementation: event +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "MOEvent.h" + +#include +#include +#include +#include + +#include "msinterface.h" + +MOEvent::MOEvent(qint64 i) +{ + MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); + if(ge.stage()==ge.Success) + operator=(ge.getevent().value()); +} + +QRegExp MOEvent::priceRegExp()const +{ + return QRegExp(QCoreApplication::translate("MOEvent","[0-9]+\\.[0-9]{2}","price validator regexp")); +} + +QString MOEvent::priceString()const +{ + qint64 dp=/*defaultprice()*/0; + QString ret=QString::number(dp/100); + ret+=QCoreApplication::translate("MOEvent",".","price decimal dot"); + ret+=QString::number((dp/10)%10); + ret+=QString::number(dp%10); + return ret; +} + +QString MOEvent::startTimeString()const +{ + return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MOEvent","yyyy-MM-dd hh:mm ap","date/time format")); +} + +QString MOEvent::startDateString()const +{ + return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MOEvent","yyyy-MM-dd","date format")); +} + +QString MOEvent::endTimeString()const +{ + return QDateTime::fromTime_t(end()).toString(QCoreApplication::translate("MOEvent","yyyy-MM-dd hh:mm ap","date/time format")); +} + +void MOEvent::setdefaultprice(QString str) +{ + /*TODO: we have multiple prices now! + QStringList ps=str.split(QCoreApplication::translate("MOEvent",".","price decimal dot")); + qint64 prc=0; + if(ps.size()>=1)prc=ps[0].toInt()*100; + if(ps.size()>=2)prc+=ps[1].toInt(); + setdefaultprice(prc);*/ +} diff --git a/src/wext/MOEvent.h b/src/wext/MOEvent.h new file mode 100644 index 0000000..7f981a8 --- /dev/null +++ b/src/wext/MOEvent.h @@ -0,0 +1,50 @@ +// +// C++ Interface: event +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef EVENT_H +#define EVENT_H + +#include +#include + +/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ +class MOEvent:public MOEventAbstract +{ + WOBJECT(MOEvent); + public: + /**get event directly from server*/ + MOEvent(qint64); + + /**alias for id()*/ + inline Nullable eventid()const{return id();} + + /**returns the start time of the event as localized string*/ + QString startTimeString()const; + /**returns the start date as localized string*/ + QString startDateString()const; + /**returns the end time of the event as localized string*/ + QString endTimeString()const; + /**returns the room of the event, the room must be one out of the list of valid rooms*/ + + /**returns the price as a localized string*/ + QString priceString()const; + /**returns the local regular expression for prices*/ + QRegExp priceRegExp()const; + + /**set the price as string*/ + void setdefaultprice(QString); + + /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ + bool isValid()const{return !eventid().isNull() && eventid().value()>0;} +}; + +#endif diff --git a/src/wext/MOOrder.cpp b/src/wext/MOOrder.cpp index 27387b9..9f103a8 100644 --- a/src/wext/MOOrder.cpp +++ b/src/wext/MOOrder.cpp @@ -100,3 +100,26 @@ QString MOOrder::sentDateStr() return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd","date format")); } +QString MOOrder::fullInvoiceAddress(bool allowfallback)const +{ + if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) + return invoiceaddress().value().fullAddress(customer().value().fullName()); + //fall back + if(!allowfallback)return ""; + if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) + return deliveryaddress().value().fullAddress(customer().value().fullName()); + //give up + return ""; +} + +QString MOOrder::fullDeliveryAddress(bool allowfallback)const +{ + if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) + return deliveryaddress().value().fullAddress(customer().value().fullName()); + //fall back + if(!allowfallback)return ""; + if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) + return invoiceaddress().value().fullAddress(customer().value().fullName()); + //give up + return ""; +} diff --git a/src/wext/MOOrder.h b/src/wext/MOOrder.h index 465c5a9..f7d1b07 100644 --- a/src/wext/MOOrder.h +++ b/src/wext/MOOrder.h @@ -89,6 +89,10 @@ class MOOrder:public MOOrderAbstract /**returns the shipping date only as string*/ QString sentDateStr(); + /**returns the full invoice address, or delivery address if no explicit invoice address was given and allowfallback==true*/ + QString fullInvoiceAddress(bool allowfallback=true)const; + /**returns the full delivery address, or invoice address if no explicit delivery address was given and allowfallback==true*/ + QString fullDeliveryAddress(bool allowfallback=true)const; }; #endif diff --git a/src/wext/MOTicket.h b/src/wext/MOTicket.h index 5b38f97..175ad2d 100644 --- a/src/wext/MOTicket.h +++ b/src/wext/MOTicket.h @@ -14,14 +14,20 @@ #define MAGICSMOKE_MOTICKET_H #include "MOTicketAbstract.h" +#include "misc.h" + class MOTicket:public MOTicketAbstract { + WOBJECT(MOTicket); public: - MOTicket():MOTicketAbstract(){} - MOTicket(const MOTicket&m):MOTicketAbstract(m){} - MOTicket(const QDomElement&e):MOTicketAbstract(e){} - + /**returns the amount to be paid for this ticket; this may be 0 even if there is a price attached*/ int amountToPay()const{if(status()&MaskPay)return price();else return 0;} + + /**returns the price as string*/ + QString priceString()const{return cent2str(price());} + + /**returns the ticket status as localized string*/ + QString statusString()const{return TicketState2locstr(status());} }; #endif diff --git a/src/wext/MOVoucher.h b/src/wext/MOVoucher.h new file mode 100644 index 0000000..4971f1f --- /dev/null +++ b/src/wext/MOVoucher.h @@ -0,0 +1,33 @@ +// +// C++ Interface: MOVoucher +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOVOUCHER_H +#define MAGICSMOKE_MOVOUCHER_H + +#include "MOVoucherAbstract.h" +#include "misc.h" + +class MOVoucher:public MOVoucherAbstract +{ + WOBJECT(MOVoucher); + public: + /**returns whether this is a valid voucher object (ie. it has a voucher ID)*/ + bool isValid()const{return !voucherid().isNull();} + /**returns the current value as string*/ + QString valueString()const{return cent2str(value());} + /**returns the status of the voucher as string*/ + QString statusString()const{return VoucherState2locstr(status());} + /**returns the price as string*/ + QString priceString()const{return cent2str(price());} +}; + +#endif diff --git a/src/wext/wext.pri b/src/wext/wext.pri index 15cc4a3..6ab44cb 100644 --- a/src/wext/wext.pri +++ b/src/wext/wext.pri @@ -5,7 +5,12 @@ HEADERS += \ wext/MOOrder.h \ wext/MOOrderInfo.h \ wext/MORole.h \ - wext/MOTicket.h + wext/MOTicket.h \ + wext/MOAddress.h \ + wext/MOEvent.h SOURCES += \ - wext/MOOrder.cpp \ No newline at end of file + wext/MOCustomerInfo.cpp \ + wext/MOOrder.cpp \ + wext/MOAddress.cpp \ + wext/MOEvent.cpp \ No newline at end of file diff --git a/wob/customer.wolf b/wob/customer.wolf index 6b8e23f..c8aad6c 100644 --- a/wob/customer.wolf +++ b/wob/customer.wolf @@ -61,6 +61,7 @@ + diff --git a/wob/event.wolf b/wob/event.wolf index b7db45c..26d513e 100644 --- a/wob/event.wolf +++ b/wob/event.wolf @@ -92,6 +92,7 @@ + @@ -158,6 +159,16 @@ + + + + + + + + + + diff --git a/wob/order.wolf b/wob/order.wolf index 16d8a2e..e706bae 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -187,6 +187,7 @@ + @@ -412,8 +413,23 @@ + + Changes the shipping option and/or price of an order + + + The order to be changed + the new shipping option or -1 if shipping is to be deleted + if the user has the privilege ChangePrice this field overrides the shipping costs, otherwise the default from the shipping table is used + + + + a fresh copy of the changed order + + + + diff --git a/woc/phpout.cpp b/woc/phpout.cpp index 83679f4..d265edf 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -99,6 +99,7 @@ void WocPHPServerOut::transInfo() void WocPHPServerOut::transInfo2() { WocProcessor*woc=WocProcessor::instance(); + //transaction names QString code=" static public function transactionNames(){\n\treturn array("; QStringList tns=woc->transactionNames(); for(int i=0;iprivilegeNames(); + for(int i=0;iens=tbl.columnEnums(cols[i]); QListenvs; for(int j=0;jdata,false,\""+tbl.name()+"_audit\");\n"; + code+="protected function createAudit(){$ad=WT"+tbl.name()+"_audit::newRow($this->data);\n"; code+="\treturn $ad->insert();\n}\n"; } @@ -826,6 +836,9 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn) //direct execution tf.write(trnExecute(trn).toAscii()); + //privileges + tf.write(trnPrivileges(trn).toAscii()); + //end code="\n//end of class\n}\n"; tf.write(code.toAscii()); @@ -1043,3 +1056,26 @@ QString WocPHPServerOut::trnExecute(const WocTransaction&trn) code+="private function do_execute(){"+trn.callFunction("php")+"}\n"; return code; } + +QString WocPHPServerOut::trnPrivileges(const WocTransaction&trn) +{ + //privilege inventory + QString code; + code+="static public function privileges(){\n\treturn array("; + QString cn=trnClassName(trn); + QStringList priv=trn.privileges(); + for(int i=0;i m_call; QList >m_input,m_output; + QStringList m_privileges; //docu QStringList m_docstrings; QMapm_indoc,m_outdoc; @@ -419,7 +423,11 @@ class WocProcessor:public QObject /**returns a list of table names*/ QStringList tableNames()const; + /**returns global docu*/ QStringList docStrings()const{return m_docstrings;} + + /**returns the qualified names of all privileges*/ + QStringList privilegeNames()const; signals: void sfinalize(); void newClass(const WocClass&); diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 396c629..53a336b 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -725,8 +725,12 @@ void WocQtClientOut::trnList() //header code+=" enum Right {\n NoRight"; QStringList r=WocProcessor::instance()->transactionNames(); + QStringList p=WocProcessor::instance()->privilegeNames(); + QStringList pp=p; for(int i=0;i "+m_prefix+"Interface::allKnownRights()\n{\n"; code+="\tQList ret;ret"; for(int i=0;isetevents($evlst); } + + /**XML iface: get list of events*/ + public static function getEventList($trans) + { + global $db; + $evlst=WOEvent::fromTableArrayevent(WTevent::selectFromDB("eventid in ".$db->escapeIntList($trans->geteventids()))); + $trans->setevents($evlst); + } }; /**machine-function: get the requested events as XML data*/ diff --git a/www/inc/wbase/table.php b/www/inc/wbase/table.php index a7e575a..b706631 100644 --- a/www/inc/wbase/table.php +++ b/www/inc/wbase/table.php @@ -23,15 +23,28 @@ class ValueOutOfRange extends Exception /**parent class of all tables*/ abstract class WobTable { - private $data; - private $cdata; + protected $data; + protected $cdata; private $isfromdb; private $table; /**constructs a basic table*/ protected function __construct(array $data,$isfromdb,$table) { - $this->data=$data; + $this->data=array(); + if($isfromdb)$this->data=$data; + else + foreach($data as $k=>$d){ + //silently ignore garbage + if(!$this->hasProperty($k))continue; + //verify non-garbage + $vm="verifyValue".$k; + if(method_exists($this,$vm)) + if(!$this->$vm($d)) + throw ValueOutOfRange($this->table,$k,$d); + //set + $this->data[$k]=$d; + } $this->isfromdb=$isfromdb; $this->table=$table; $this->cdata=array(); diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 69e88f7..8e03f00 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -135,10 +135,10 @@ class WOOrder extends WOOrderAbstract $prc+=$it->amountToPay(); //add vouchers foreach($this->prop_vouchers as $it) - $prc+=$it->getprice(); + $prc+=$it->get_price(); //add items foreach($this->prop_items as $it) - $prc+=$it->gettotalprice(); + $prc+=$it->get_totalprice(); //return return $prc; } @@ -156,6 +156,40 @@ class WOOrder extends WOOrderAbstract if(count($res)>=0) $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($res[0]["orderid"]))); } + + /**called by OrderChangeShipping transaction*/ + static public function changeShipping($trans) + { + //get shipping + $shipid=$trans->getshippingid(); +// print_r($shipid); + if($shipid===false)$shipid=-1;else $shipid=$shipid+0; + if($shipid>=0){ + $ship=WTshipping::getFromDB($shipid); + if($ship===false){ + $trans->abortWithError(tr("Invalid shipping ID.")); + return; + } + } + //get order + $ord=WTorder::getFromDB($trans->getorderid()); + //get shipping costs + $cost=0; + if($shipid>=0)$cost=$ship->cost; + if($trans->havePrivilege(WtrOrderChangeShipping::Priv_ChangePrice)){ + if($trans->getshippingcosts()!==false) + $cost=$trans->getshippingcosts(); + } + //set order + $ord->shippingcosts=$cost; + if($shipid>=0) + $ord->shippingtype=$shipid; + else + $ord->shippingtype=null; + $ord->update(); + //return order + $trans->setorder(WOOrder::fromTableorder($ord)); + } }; ?> \ No newline at end of file -- 1.7.2.5