order audit working
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 27 Dec 2010 22:41:58 +0000 (22:41 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 27 Dec 2010 22:41:58 +0000 (22:41 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@686 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

12 files changed:
Makefile.unix
src/dialogs/dialogfiles.qrc [new file with mode: 0644]
src/dialogs/dialogs.pri
src/dialogs/orderauditdlg.cpp
src/dialogs/orderauditdlg.h
src/dialogs/orderauditdlg.xml [new file with mode: 0644]
src/dialogs/orderauditdlg_p.h [new file with mode: 0644]
src/misc/formula.cpp
src/wext/order.h
src/wext/orderinfo.h
src/wext/ticket.h
src/wext/voucher.h

index 8bc78e6..c5b918f 100644 (file)
@@ -75,6 +75,7 @@ sdoc:
        cd pack/phpbase ; $(DOXYGEN)
        cd pack/qtbase ; $(DOXYGEN)
        cd tzone ; $(DOXYGEN) Doxyfile
+       cd elam/src ; $(DOXYGEN) Doxyfile
 
 install: install-client install-server install-doc
 
diff --git a/src/dialogs/dialogfiles.qrc b/src/dialogs/dialogfiles.qrc
new file mode 100644 (file)
index 0000000..7462539
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC>
+<!-- (c) Konrad Rosenbaum, 2010-2011
+See COPYING.GPL for details. -->
+<RCC version="1.0">
+    <qresource>
+        <file alias="orderaudit.xml">orderauditdlg.xml</file>
+    </qresource>
+</RCC>
index 1b40913..944c269 100644 (file)
@@ -12,7 +12,8 @@ HEADERS += \
        dialogs/aclwin.h \
        dialogs/flagedit.h \
        dialogs/wizard.h \
-       dialogs/orderauditdlg.h
+       dialogs/orderauditdlg.h \
+       dialogs/orderauditdlg_p.h
 
 SOURCES += \
        dialogs/configdialog.cpp \
@@ -30,4 +31,6 @@ SOURCES += \
        dialogs/wizard.cpp \
        dialogs/orderauditdlg.cpp
 
+RESOURCES += dialogs/dialogfiles.qrc
+
 INCLUDEPATH += ./dialogs
\ No newline at end of file
index a055453..a8465a5 100644 (file)
 //
 //
 
-#include "orderauditdlg.h"
+#include "orderauditdlg_p.h"
 
-MOrderAuditDialog::MOrderAuditDialog(const MTGetOrderAudit& audit, QWidget* parent)
+#include "formula.h"
+
+#include <QBoxLayout>
+#include <QDebug>
+#include <QStandardItemModel>
+#include <QTreeView>
+#include <QComboBox>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QFile>
+#include <main.h>
+
+
+class MOAAuditList:public QList<MOAParcel>
+{
+       public:
+               void addOrders(const QList<MOOrderAudit>&o)
+               {for(int i=0;i<o.size();i++)addItem(o[i]);}
+               void addTickets(const QList<MOTicketAudit>&o)
+               {for(int i=0;i<o.size();i++)addItem(o[i]);}
+               void addVouchers(const QList<MOVoucherAudit>&o)
+               {for(int i=0;i<o.size();i++)addItem(o[i]);}
+               
+               void addItem(const MOAItem&it){
+                       for(int i=0;i<size();i++)
+                               if(operator[](i).addItem(it))
+                                       return;
+                       append(MOAParcel(it));
+               }
+};
+
+class MOAFormula:public MElamEngine
+{
+       MOrderAuditDialog*mdialog;
+       MOADynamicObject*mcontext;
+       public:
+               MOAFormula()
+               {mdialog=0;mcontext=0;}
+               MOAFormula(const MOAFormula&f):MElamEngine(){operator=(f);}
+               MOAFormula&operator=(const MOAFormula&f)
+               {mdialog=f.mdialog;mcontext=f.mcontext;return *this;}
+               void setParent(MOrderAuditDialog*p){MElamEngine::setParent(p);mdialog=p;}
+               void setContext(MOADynamicObject*ctx){mcontext=ctx;}
+               bool hasConstant(QString c)const{
+                       if(MElamEngine::hasConstant(c))return true;
+//                     qDebug()<<"looking for const"<<c;
+                       if(mcontext){
+//                             qDebug()<<"have const"<<c<<mcontext->hasValue(c);
+                               return mcontext->hasValue(c);
+                       }
+                       return false;
+               }
+               QVariant getConstant(QString c)const{
+//                     qDebug()<<"getting const"<<c;
+                       if(mcontext){
+                               if(mcontext->hasValue(c))
+                                       return mcontext->getValue(c);
+                       }
+                       return MElamEngine::getConstant(c);
+               }
+};
+
+class DPTR_CLASS_NAME(MOrderAuditDialog)
+{
+protected:
+       friend class MOrderAuditDialog;
+       QTreeView*mdata;
+       QStandardItemModel*mmodel;
+       QComboBox*mprofile;
+       QDomDocument mprofiledoc;
+       MOAAuditList maudit;
+       MOAFormula formula;
+};
+DEFINE_DPTR(MOrderAuditDialog);
+
+MOrderAuditDialog::MOrderAuditDialog(MTGetOrderAudit& audit, QWidget* parent)
        : QDialog(parent)
 {
+       //init
+       QList<MOOrderAudit>orders=audit.getorder();
+       setWindowTitle(tr("Order Audit [%1]").arg(orders.value(0).orderid()));
+       setSizeGripEnabled(true);
+       d->formula.setParent(this);
+       //init list
+       d->maudit.addOrders(orders);
+       d->maudit.addTickets(audit.gettickets());
+       d->maudit.addVouchers(audit.getvouchers());
+       qSort(d->maudit);
+       qDebug()<<"# audit items:"<<d->maudit.size();
+       //accumulate prices
+       calcPrices();
+       //get profiles
+       getProfiles();
+       //display
+       QVBoxLayout*vl;
+       setLayout(vl=new QVBoxLayout);
+       vl->addWidget(d->mprofile=new QComboBox,0);
+       QDomNodeList nl=d->mprofiledoc.elementsByTagName("Report");
+       for(int i=0;i<nl.size();i++){
+               QDomElement el=nl.at(i).toElement();
+               d->mprofile->addItem(el.attribute("name"),i);
+       }
+       vl->addWidget(d->mdata=new QTreeView,1);
+       d->mdata->setModel(d->mmodel=new QStandardItemModel);
+       d->mdata->setEditTriggers(QAbstractItemView::NoEditTriggers);
+       drawdata();
+}
+
+MOrderAuditDialog::~MOrderAuditDialog()
+{
+}
+
+void MOrderAuditDialog::drawdata()
+{
+       //clear
+       d->mmodel->clear();
+       //get profile
+       QDomNodeList nl=d->mprofiledoc.elementsByTagName("Report");
+       if(nl.size()<1)return;
+       int pid=d->mprofile->itemData(d->mprofile->currentIndex()).toInt();
+       if(pid<0||pid>=nl.size())return;
+       QDomElement profile=nl.at(pid).toElement();
+       //set size
+       d->mmodel->insertRows(0,d->maudit.size());
+       int numcols=profile.attribute("columns").toInt();
+       d->mmodel->insertColumns(0,numcols);
+       //set header
+       nl=profile.elementsByTagName("Header");
+       for(int i=0;i<nl.size();i++){
+               QDomElement el=nl.at(i).toElement();
+               d->mmodel->setHeaderData(el.attribute("col").toInt(),Qt::Horizontal,el.text());
+       }
+       //get profile formulae
+       QDomNodeList suml=profile.elementsByTagName("Summary");
+       QDomNodeList ordl=profile.elementsByTagName("Order");
+       QDomNodeList tckl=profile.elementsByTagName("Ticket");
+       QDomNodeList voul=profile.elementsByTagName("Voucher");
+       //set data
+       for(int i=0;i<d->maudit.size();i++){
+               MOAParcel pc=d->maudit.value(i);
+               d->formula.setContext(&pc);
+               for(int k=0;k<suml.size();k++){
+                       QDomElement sum=suml.at(k).toElement();
+                       QModelIndex idx=d->mmodel->index(i,sum.attribute("col").toInt());
+                       QVariant v=d->formula.evaluate(sum.text());
+                       if(v.userType()==ELAM::Exception::metaTypeId())
+                               qDebug()<<"Exception in summary formula. Formula:"<<sum.text() <<"Column:"<<sum.attribute("col").toInt() <<"Exception:"<<v.value<ELAM::Exception>();
+                       d->mmodel->setData(idx,v);
+               }
+               QModelIndex pidx=d->mmodel->index(i,0);
+               d->mmodel->insertRows(0,pc.size(),pidx);
+               d->mmodel->insertColumns(0,numcols,pidx);
+               for(int j=0;j<pc.size();j++){
+                       MOAItem itm=pc[j];
+                       d->formula.setContext(&itm);
+                       switch(itm.itemType()){
+                               case MOAItem::Order:nl=ordl;break;
+                               case MOAItem::Ticket:nl=tckl;break;
+                               case MOAItem::Voucher:nl=voul;break;
+                               default:continue;
+                       }
+                       for(int k=0;k<nl.size();k++){
+                               QDomElement el=nl.at(k).toElement();
+                               QModelIndex idx=d->mmodel->index(j,el.attribute("col").toInt(),pidx);
+                               QVariant v=d->formula.evaluate(el.text());
+                               if(v.userType()==ELAM::Exception::metaTypeId())
+                                       qDebug()<<"Exception in formula. Formula:"<<el.text() <<"ItemType:"<<itm.itemTypeString() <<"Column:"<<el.attribute("col").toInt() <<"Exception:"<<v.value<ELAM::Exception>();
+                               d->mmodel->setData(idx,v);
+                       }
+               }
+               d->formula.setContext(0);
+       }
+       for(int i=0;i<d->mmodel->columnCount();i++)
+               d->mdata->resizeColumnToContents(i);
+}
 
+void MOrderAuditDialog::calcPrices()
+{
+       QMap<QString,qint64>prclist;
+       for(int i=0;i<d->maudit.size();i++){
+               //accumulate items
+               for(int j=0;j<d->maudit[i].size();j++){
+                       MOAItem itm=d->maudit[i][j];
+                       QString id=itm.itemTypeString()+itm.itemID();
+                       switch(itm.itemType()){
+                               case MOAItem::Order:
+                                       prclist.insert(id,itm.order().shippingcosts());
+                                       break;
+                               case MOAItem::Voucher:
+                                       prclist.insert(id,itm.voucher().price());
+                                       break;
+                               case MOAItem::Ticket:
+                                       prclist.insert(id,itm.ticket().amountToPay());
+                                       break;
+                               default:break;
+                       }
+               }
+               //calculate current price
+               qint64 prc=0;
+               QStringList k=prclist.keys();
+               for(int j=0;j<k.size();j++)
+                       prc+=prclist[k[j]];
+               //set price to parcel
+               d->maudit[i].setPrice(prc);
+       }
+}
+
+void MOrderAuditDialog::getProfiles()
+{
+       QFile fd(dataDir+"/orderaudit.xml");
+       if(fd.exists() && fd.open(QIODevice::ReadOnly)){
+               qDebug()<<"loading main config"<<fd.fileName();
+               if(d->mprofiledoc.setContent(&fd))
+                       return;
+       }
+       fd.setFileName(":/orderaudit.xml");
+       if(fd.exists() && fd.open(QIODevice::ReadOnly)){
+               d->mprofiledoc.setContent(&fd);
+               qDebug()<<"loading backup config";
+       }
 }
index 1e4a6d1..3af456e 100644 (file)
 #define MAGICSMOKE_ORDERAUDITDLG_H
 
 #include <QDialog>
+#include <dptr.h>
 
 class MTGetOrderAudit;
-
 class MOrderAuditDialog:public QDialog
 {
        Q_OBJECT
+       DECLARE_DPTR(d);
        public:
-               MOrderAuditDialog(const MTGetOrderAudit&audit,QWidget*parent=0);
+               MOrderAuditDialog(MTGetOrderAudit&audit,QWidget*parent=0);
+               virtual ~MOrderAuditDialog();
+       private slots:
+               void getProfiles();
+               void calcPrices();
+               void drawdata();
 };
 
 #endif
diff --git a/src/dialogs/orderauditdlg.xml b/src/dialogs/orderauditdlg.xml
new file mode 100644 (file)
index 0000000..46be292
--- /dev/null
@@ -0,0 +1,26 @@
+<OrderAudit>
+ <Report name="default" columns="5">
+  <Header col="0">Date, Time&#x0a;ID</Header>
+  <Header col="1">User Name&#x0a;Item Type</Header>
+  <Header col="2">Transaction Type&#x0a;Item Data</Header>
+  <Header col="3">Total Price&#x0a;Item Price</Header>
+  <Header col="4">Amount Paid&#x0a;Info</Header>
+  <Summary col="0">unix2datetime(auditTime)</Summary>
+  <Summary col="1">auditUser</Summary>
+  <Summary col="2">auditTransaction</Summary>
+  <Summary col="3">toMoney(totalPrice)+" (total)"</Summary>
+  <Order col="0">itemID</Order>
+  <Order col="1">itemTypeString</Order>
+  <Order col="2">"Payment: "+paytype+"; "+paydata</Order>
+  <Order col="3">toMoney(shippingcosts)+" (shipping)"</Order>
+  <Order col="4">toMoney(amountpaid)</Order>
+  <Ticket col="0">itemID</Ticket>
+  <Ticket col="1">itemTypeString</Ticket>
+  <Ticket col="3">toMoney(amountToPay)</Ticket>
+  <Voucher col="0">itemID</Voucher>
+  <Voucher col="1">itemTypeString</Voucher>
+  <Voucher col="2">"current value: "+toMoney(value)</Voucher>
+  <Voucher col="3">toMoney(price)</Voucher>
+  <Voucher col="4">comment</Voucher>
+ </Report>
+</OrderAudit>
\ No newline at end of file
diff --git a/src/dialogs/orderauditdlg_p.h b/src/dialogs/orderauditdlg_p.h
new file mode 100644 (file)
index 0000000..1f3c441
--- /dev/null
@@ -0,0 +1,222 @@
+//
+// C++ Interface: orderaudit dialog
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010-2011
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_ORDERAUDITDLG_P_H
+#define MAGICSMOKE_ORDERAUDITDLG_P_H
+
+#include "orderauditdlg.h"
+
+#include <MTGetOrderAudit>
+#include <QMetaMethod>
+#include <TimeStamp>
+
+static bool hasMetaValue(QObject*obj,QString n)
+{
+       const QMetaObject*mobj=obj->metaObject();
+       //look for property
+       int id=mobj->indexOfProperty(n.toAscii().data());
+       if(id>=0)return true;
+       //look for method
+       id=mobj->indexOfMethod(n.toAscii().data());
+       if(id<0)return false;
+       QMetaMethod mm=mobj->method(id);
+       if(mm.parameterNames().size()!=0)return false;
+       if(QString(mm.typeName()).isEmpty())return false;
+       return true;
+}
+
+static QVariant getMetaValue(QObject*obj,QString n)
+{
+       const QMetaObject*mobj=obj->metaObject();
+       //look for property
+       int id=mobj->indexOfProperty(n.toAscii().data());
+       if(id>=0)return mobj->property(id).read(obj);
+       //look for method
+       id=mobj->indexOfMethod(n.toAscii().data());
+       if(id<0)return QVariant();
+       QMetaMethod mm=mobj->method(id);
+       if(mm.parameterNames().size()!=0)return QVariant();
+       if(QString(mm.typeName()).isEmpty())return QVariant();
+       //try to invoke
+       int dataid=QMetaType::type(mm.typeName());
+       void *data=QMetaType::construct(dataid);
+       QVariant ret;
+       if(mm.invoke(obj, Qt::DirectConnection, QGenericReturnArgument(mm.typeName(),data)))
+               ret=QVariant(dataid,data);
+       QMetaType::destroy(dataid,data);
+       return ret;
+}
+
+class MOADynamicObject:public QObject
+{
+       public:
+               virtual bool hasValue(QString n){return hasMetaValue(this,n);}
+               virtual QVariant getValue(QString n){return getMetaValue(this,n);}
+};
+
+class MOAItem:public MOADynamicObject
+{
+       Q_OBJECT
+       Q_PROPERTY(qint64 auditTime READ auditTime)
+       Q_PROPERTY(QString auditUser READ auditUser)
+       Q_PROPERTY(QString auditTransaction READ auditTransaction)
+       Q_PROPERTY(QString itemID READ itemID)
+       Q_PROPERTY(QString itemTypeString READ itemTypeString)
+       public:
+               enum ItemType{None,Order,Ticket,Voucher};
+               ItemType itemType()const{return mtype;}
+               
+               MOAItem(){mtype=None;}
+               MOAItem(const MOOrderAudit&a){morder=a;mtype=Order;}
+               MOAItem(const MOTicketAudit&a){mticket=a;mtype=Ticket;}
+               MOAItem(const MOVoucherAudit&a){mvoucher=a;mtype=Voucher;}
+               MOAItem(const MOAItem&i){operator=(i);}
+               MOAItem&operator=(const MOAItem&i)
+               {
+                       mtype=i.mtype;
+                       morder=i.morder;mticket=i.mticket;mvoucher=i.mvoucher;
+                       return *this;
+               }
+
+               virtual bool hasValue(QString n){
+                       if(hasMetaValue(this,n))return true;
+                       switch(mtype){
+                               case Order:return hasMetaValue(&morder,n);
+                               case Ticket:return hasMetaValue(&mticket,n);
+                               case Voucher:return hasMetaValue(&mvoucher,n);
+                               default: return false;
+                       }
+               }
+               virtual QVariant getValue(QString n){
+                       if(hasMetaValue(this,n))return getMetaValue(this,n);
+                       switch(mtype){
+                               case Order:return getMetaValue(&morder,n);
+                               case Ticket:return getMetaValue(&mticket,n);
+                               case Voucher:return getMetaValue(&mvoucher,n);
+                               default: return false;
+                       }
+               }
+       public slots:
+               MOOrderAudit order()const{return morder;}
+               MOTicketAudit ticket()const{return mticket;}
+               MOVoucherAudit voucher()const{return mvoucher;}
+               
+               qint64 auditTime()const{switch(mtype){
+                       case Order:return (qint64)morder.audittime();
+                       case Ticket:return (qint64)mticket.audittime();
+                       case Voucher:return (qint64)mvoucher.audittime();
+                       default: return 0;
+               }}
+               QString auditUser()const{switch(mtype){
+                       case Order:return morder.audituname();
+                       case Ticket:return mticket.audituname();
+                       case Voucher:return mvoucher.audituname();
+                       default: return QString();
+               }}
+               QString auditTransaction()const{switch(mtype){
+                       case Order:return morder.audittransaction();
+                       case Ticket:return mticket.audittransaction();
+                       case Voucher:return mvoucher.audittransaction();
+                       default: return QString();
+               }}
+               
+               bool isSameTransaction(const MOAItem&i)const{
+                       if(mtype==None || i.mtype==None)return false;
+                       return auditTime() == i.auditTime() &&
+                              auditUser() == i.auditUser() &&
+                              auditTransaction() == i.auditTransaction();
+               }
+               
+               QString itemID()const{switch(mtype){
+                       case Order:return QString::number(morder.orderid());
+                       case Ticket:return mticket.ticketid();
+                       case Voucher:return mvoucher.voucherid();
+                       default:return QString();
+               }}
+               
+               QString itemTypeString()const{switch(mtype){
+                       case Order:return QCoreApplication::translate("MOAItem","Order");
+                       case Ticket:return QCoreApplication::translate("MOAItem","Ticket");
+                       case Voucher:return QCoreApplication::translate("MOAItem","Voucher");
+                       default:return QString();
+               }}
+               
+       private:
+               ItemType mtype;
+               MOOrderAudit morder;
+               MOTicketAudit mticket;
+               MOVoucherAudit mvoucher;
+};
+
+class MOAParcel:public MOADynamicObject
+{
+       Q_OBJECT
+       Q_PROPERTY(qint64 auditTime READ auditTime)
+       Q_PROPERTY(QString auditUser READ auditUser)
+       Q_PROPERTY(QString auditTransaction READ auditTransaction)
+       Q_PROPERTY(qint64 size READ size)
+       Q_PROPERTY(qint64 totalPrice READ totalPrice)
+       public:
+               MOAParcel(){mprice=0;}
+               MOAParcel(const MOAParcel&p){mitems=p.mitems;mprice=p.mprice;}
+               MOAParcel(const MOAItem&i){mitems<<i;mprice=0;}
+               MOAParcel& operator=(const MOAParcel&p){
+                       mitems=p.mitems;mprice=p.mprice;
+                       return *this;}
+               
+       public slots:
+               qint64 auditTime()const{
+                       if(mitems.size()>0)return mitems[0].auditTime();
+                       else return 0;
+               }
+               QString auditUser()const{
+                       if(mitems.size()>0)return mitems[0].auditUser();
+                       else return QString();
+               }
+               QString auditTransaction()const{
+                       if(mitems.size()>0)return mitems[0].auditTransaction();
+                       else return QString();
+               }
+               
+               bool isSameTransaction(const MOAItem&i)const{
+                       if(mitems.size()!=0)
+                               return mitems[0].isSameTransaction(i);
+                       else
+                               return true;
+               }
+               bool addItem(const MOAItem&i){
+                       if(isSameTransaction(i)){
+                               mitems<<i;
+                               return true;
+                       }else return false;
+               }
+               
+               qint64 size()const{return mitems.size();}
+               
+               qint64 totalPrice()const{return mprice;}
+       public:
+               MOAItem item(int i)const{return mitems.value(i);}
+               MOAItem operator[](int i)const{return mitems[i];}
+               MOAItem& operator[](int i){return mitems[i];}
+               MOAItem& item(int i){return mitems[i];}
+               
+               void setPrice(qint64 p){mprice=p;}
+               
+               //used for sorting
+               bool operator<(const MOAParcel&p)const{return auditTime()<p.auditTime();}
+               
+       private:
+               QList<MOAItem>mitems;
+               qint64 mprice;
+};
+
+#endif
index 92bcaf5..188aefe 100644 (file)
@@ -14,6 +14,7 @@
 #include "misc.h"
 
 #include <QDebug>
+#include <Nullable>
 
 using namespace ELAM;
 
@@ -62,6 +63,51 @@ static QVariant unix2DateFunc(const QList<QVariant>&args,Engine&){return unix2DT
 static QVariant unix2TimeFunc(const QList<QVariant>&args,Engine&){return unix2DTFunc(args,1);}
 static QVariant unix2DateTimeFunc(const QList<QVariant>&args,Engine&){return unix2DTFunc(args,2);}
 
+static QVariant nullintCast(const QVariant&orig,const Engine&)
+{
+       if(orig.userType()==qMetaTypeId<Nullable<qint32> >()){
+               Nullable<qint32> ni=orig.value<Nullable<qint32> >();
+               if(ni.isNull())return QVariant();
+               else return (qlonglong)ni.value();
+       }
+       if(orig.userType()==qMetaTypeId<Nullable<quint32> >()){
+               Nullable<quint32> ni=orig.value<Nullable<quint32> >();
+               if(ni.isNull())return QVariant();
+               else return (qlonglong)ni.value();
+       }
+       if(orig.userType()==qMetaTypeId<Nullable<qint64> >()){
+               Nullable<qint64> ni=orig.value<Nullable<qint64> >();
+               if(ni.isNull())return QVariant();
+               else return (qlonglong)ni.value();
+       }
+       if(orig.userType()==qMetaTypeId<Nullable<quint64> >()){
+               Nullable<quint64> ni=orig.value<Nullable<quint64> >();
+               if(ni.isNull())return QVariant();
+               else return (qlonglong)ni.value();
+       }
+       return orig;
+}
+
+static QVariant nullstrCast(const QVariant&orig,const Engine&)
+{
+       if(orig.userType()==qMetaTypeId<Nullable<QString> >()){
+               Nullable<QString> ni=orig.value<Nullable<QString> >();
+               if(ni.isNull())return QVariant();
+               else return ni.value();
+       }
+       return orig;
+}
+
+static QVariant nullboolCast(const QVariant&orig,const Engine&)
+{
+       if(orig.userType()==qMetaTypeId<Nullable<bool> >()){
+               Nullable<bool> ni=orig.value<Nullable<bool> >();
+               if(ni.isNull())return QVariant();
+               else return ni.value();
+       }
+       return orig;
+}
+
 MElamEngine::MElamEngine(QObject* parent): Engine(parent)
 {
        //configure character classes
@@ -88,4 +134,15 @@ MElamEngine::MElamEngine(QObject* parent): Engine(parent)
        setFunction("unix2date",unix2DateFunc);
        setFunction("unix2time",unix2TimeFunc);
        setFunction("unix2datetime",unix2DateTimeFunc);
+       //register casts for nullable
+       setAutoCast(qMetaTypeId<qlonglong>(),
+               QList<int>()
+               <<qMetaTypeId<Nullable<qint32> >()
+               <<qMetaTypeId<Nullable<quint32> >()
+               <<qMetaTypeId<Nullable<qint64> >()
+               <<qMetaTypeId<Nullable<quint64> >(), 
+               nullintCast
+       );
+       setAutoCast(qMetaTypeId<QString>(),QList<int>()<<qMetaTypeId<Nullable<QString> >(), nullstrCast);
+       setAutoCast(qMetaTypeId<bool>(),QList<int>()<<qMetaTypeId<Nullable<bool> >(), nullboolCast);
 }
index 2410d08..d00f36f 100644 (file)
@@ -24,6 +24,25 @@ class MOOrder:public MOOrderAbstract
        Q_OBJECT
        WOBJECT(MOOrder)
        WOSCRIPT(MOOrder)
+       Q_PROPERTY(bool isValid READ isValid)
+       Q_PROPERTY(bool isReservation READ isReservation)
+       Q_PROPERTY(bool isSent READ isSent)
+       Q_PROPERTY(QString orderStatusString READ orderStatusString)
+       Q_PROPERTY(QString totalPriceString READ totalPriceString)
+       Q_PROPERTY(bool needsPayment READ needsPayment)
+       Q_PROPERTY(bool needsRefund READ needsRefund)
+       Q_PROPERTY(int amountToPay READ amountToPay)
+       Q_PROPERTY(QString amountToPayStr READ amountToPayStr)
+       Q_PROPERTY(int amountToRefund READ amountToRefund)
+       Q_PROPERTY(QString amountToRefundStr READ amountToRefundStr)
+       Q_PROPERTY(QString orderDateTimeStr READ orderDateTimeStr)
+       Q_PROPERTY(TimeStamp oderDateTime READ orderDateTime)
+       Q_PROPERTY(TimeStamp sentDateTime READ sentDateTime)
+       Q_PROPERTY(QString sentDateTimeStr READ sentDateTimeStr)
+       Q_PROPERTY(QString orderDateStr READ orderDateStr)
+       Q_PROPERTY(QString sentDateStr READ sentDateStr)
+       Q_PROPERTY(QString fullInvoiceAddress READ fullInvoiceAddress)
+       Q_PROPERTY(QString fullDeliveryAddress READ fullDeliveryAddress)
        public:
                /**create order by id, retrieves it automatically from the database*/
                MOOrder(qint64);
index 7046d21..deaa67a 100644 (file)
@@ -21,6 +21,11 @@ class MOOrderInfo:public MOOrderInfoAbstract
        Q_OBJECT
        WOBJECT(MOOrderInfo)
        WOSCRIPT(MOOrderInfo)
+       Q_PROPERTY(bool isReservation READ isReservation)
+       Q_PROPERTY(bool isSent READ isSent)
+       Q_PROPERTY(bool isCancelled READ isCancelled)
+       Q_PROPERTY(bool needsPayment READ needsPayment)
+       Q_PROPERTY(bool needsRefund READ needsRefund)
        public:
                QString totalPriceString()const{return cent2str(totalprice());}
                QString amountPaidString()const{return cent2str(amountpaid());}
index 9188232..7591786 100644 (file)
@@ -22,6 +22,11 @@ class MOTicket:public MOTicketAbstract
        Q_OBJECT
        WOBJECT(MOTicket)
        WOSCRIPT(MOTicket)
+       Q_PROPERTY(int amountToPay READ amountToPay)
+       Q_PROPERTY(QString priceString READ priceString)
+       Q_PROPERTY(QString statusString READ statusString)
+       Q_PROPERTY(QString priceCategoryName READ priceCategoryName)
+       Q_PROPERTY(QString priceCategoryShort READ priceCategoryShort)
        public:
                /**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;}
index eceacd4..70f6a9d 100644 (file)
@@ -21,6 +21,9 @@ class MOVoucher:public MOVoucherAbstract
        Q_OBJECT
        WOBJECT(MOVoucher)
        WOSCRIPT(MOVoucher)
+       Q_PROPERTY(QString valueString READ valueString)
+       Q_PROPERTY(QString statusString READ statusString)
+       Q_PROPERTY(QString priceString READ priceString)
        public:
                /**returns whether this is a valid voucher object (ie. it has a voucher ID)*/
                bool isValid()const{return !voucherid().isNull();}