scanXml(el);
}
+MCustomer::MCustomer(MWebRequest*r,qint64 i)
+{
+ m_req=r;
+ m_iscomplete=false;
+ m_id=i;
+ getUpdate();
+}
+
void MCustomer::scanXml(const QDomElement&el)
{
//get basic information
public:
/**creates an empty/invalid customer*/
MCustomer(MWebRequest*r=0);
+ /**fetches customer from the Database*/
+ MCustomer(MWebRequest*,qint64);
/**creates a customer from XML*/
MCustomer(MWebRequest*,const QDomElement&);
/**copies a customer*/
--- /dev/null
+//
+// C++ Implementation: host
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "order.h"
+#include "webrequest.h"
+
+#include <QDomElement>
+#include <QCoreApplication>
+
+MOrder::MOrder()
+{
+ req=0;
+ m_orderid=m_customer=-1;
+ m_price=m_paid=0;
+ m_status=Invalid;
+}
+
+MOrder::MOrder(MWebRequest*r,qint32 id)
+{
+ req=r;
+ getFromDB(id);
+}
+
+MOrder::MOrder(MWebRequest*r,QDomElement&e)
+{
+ req=r;
+ parseXml(e);
+}
+
+MOrder::MOrder(const MOrder&o)
+{
+ req=o.req;
+ m_orderid=o.m_orderid;
+ m_customer=o.m_customer;
+ m_price=o.m_price;
+ m_paid=o.m_paid;
+ m_status=o.m_status;
+}
+
+int MOrder::orderID()const
+{
+ return m_orderid;
+}
+
+bool MOrder::isValid()const
+{
+ return m_orderid>=0 && m_status!=Invalid;
+}
+
+int MOrder::customerID()const
+{
+ return m_customer;
+}
+
+MCustomer MOrder::customer()const
+{
+ return MCustomer(req,m_customer);
+}
+
+MOrder::OrderStatus MOrder::orderStatus()const
+{
+ return m_status;
+}
+
+QString MOrder::orderStatusString()const
+{
+ switch(m_status){
+ case Placed:return QCoreApplication::translate("MOrder","placed","state");
+ case Sent:return QCoreApplication::translate("MOrder","sent","state");
+ case Cancelled:return QCoreApplication::translate("MOrder","cancelled","state");
+ case Closed:return QCoreApplication::translate("MOrder","closed","state");
+ default:return QCoreApplication::translate("MOrder","invalid","state");
+ }
+}
+
+int MOrder::totalPrice()const
+{
+ return m_price;
+}
+
+QString MOrder::totalPriceString()const
+{
+ return cent2string(m_price);
+}
+
+int MOrder::amountPaid()const
+{
+ return m_paid;
+}
+
+QString MOrder::amountPaidString()const
+{
+ return cent2string(m_paid);
+}
+
+//static
+QString MOrder::cent2string(int c)
+{
+ return QString::number(c/100)+QCoreApplication::translate("MOrder",".","decimal dot")+QString().sprintf("%02d",c%100);
+}
+
+bool MOrder::needsPayment()const
+{
+ if(m_status==Placed || m_status==Sent)
+ if(m_paid<m_price)return true;
+ return false;
+}
+
+bool MOrder::needsRefund()const
+{
+ if(m_status==Cancelled)
+ return m_paid>0;
+ if(m_status==Placed || m_status==Sent)
+ return m_paid>m_price;
+ return false;
+}
+
+int MOrder::amountToPay()const
+{
+ if(m_status==Placed || m_status==Sent)
+ if(m_paid<m_price)return m_price-m_paid;
+ return 0;
+}
+
+int MOrder::amountToRefund()const
+{
+ if(m_status==Cancelled)
+ return m_paid;
+ if(m_status==Placed || m_status==Sent)
+ if(m_paid>m_price)
+ return m_paid-m_price;
+ return 0;
+}
+
+bool MOrder::isSent()const
+{
+ //only in placed mode there is a need for action, hence in all other modes we assum sent
+ return m_status!=Placed;
+}
+
+void MOrder::getFromDB(qint32 i)
+{
+ //TODO
+}
+
+void MOrder::parseXml(const QDomElement&e)
+{
+ //Basics
+ bool b;
+ m_orderid=e.attribute("id","-1").toInt(&b);
+ if(!b){
+ m_orderid=m_customer=-1;
+ m_price=m_paid=0;
+ m_status=Invalid;
+ return;
+ }
+ m_customer=e.attribute("customer","-1").toInt(&b);
+ if(!b)m_customer=-1;
+ m_price=e.attribute("totalprice","0").toInt();
+ m_paid=e.attribute("paid","0").toInt();
+ QString st=e.attribute("status");
+ if(st=="placed")m_status=Placed;else
+ if(st=="sent")m_status=Sent;else
+ if(st=="cancelled")m_status=Cancelled;else
+ if(st=="closed")m_status=Closed;
+ else m_status=Invalid;
+}
--- /dev/null
+//
+// C++ Interface: host
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_ORDER_H
+#define MAGICSMOKE_ORDER_H
+
+#include <QString>
+
+#include "customer.h"
+
+class MWebRequest;
+class QDomElement;
+
+class MOrder
+{
+ public:
+ /**create invalid host*/
+ MOrder();
+ /**create order by id*/
+ MOrder(MWebRequest*,qint32);
+ /**create order from XML element*/
+ MOrder(MWebRequest*,QDomElement&);
+ /**copy order*/
+ MOrder(const MOrder&);
+
+ /**returns the order ID (-1 for invalid orders)*/
+ int orderID()const;
+
+ /**returns whether the order is valid*/
+ bool isValid()const;
+
+ /**returns the customer ID*/
+ int customerID()const;
+
+ /**returns a customer object (calls database!)*/
+ MCustomer customer()const;
+
+ /**status*/
+ enum OrderStatus{
+ /**the order is invalid (not a DB state)*/
+ Invalid,
+ /**the order has been placed, nothing is delivered or paid*/
+ Placed,
+ /**the tickets/vouchers have been shipped*/
+ Sent,
+ /**the order was cancelled*/
+ Cancelled,
+ /**the order is closed (currently unused state)*/
+ Closed
+ };
+
+ /**returns the status of the order*/
+ OrderStatus orderStatus()const;
+
+ /**returns the status of the order as localized string*/
+ QString orderStatusString()const;
+
+ /**returns how much money needs to be paid in total for this order, in cents*/
+ int totalPrice()const;
+
+ /**returns how much money needs to be paid in total for this order, in cents*/
+ QString totalPriceString()const;
+
+ /**returns how much money has already been paid for this order, in cents*/
+ int amountPaid()const;
+
+ /**returns how much money has already been paid for this order, in cents*/
+ QString amountPaidString()const;
+
+ /**returns whether there is anything left to pay*/
+ bool needsPayment()const;
+
+ /**returns whether there is anything left to refund*/
+ bool needsRefund()const;
+
+ /**returns how much there is to be paid, in cents*/
+ int amountToPay()const;
+
+ /**returns how much there is to be refunded, in cents*/
+ int amountToRefund()const;
+
+ /**returns whether the tickets of this order have already been shipped*/
+ bool isSent()const;
+
+ private:
+ MWebRequest*req;
+ int m_orderid,m_customer,m_price,m_paid;
+ OrderStatus m_status;
+
+ /**internal: requests the order from the database*/
+ void getFromDB(qint32);
+
+ /**internal: parse XML*/
+ void parseXml(const QDomElement&);
+
+ /**helper: converts a cent value into a localized string*/
+ static QString cent2string(int);
+};
+
+#endif
#include <QDomElement>
#include <QComboBox>
+#define ORDERNONE 0
+#define ORDERALL 0xff
+#define ORDEROPEN 7
+#define ORDERPAY 1
+#define ORDERREFUND 2
+#define ORDERUNSENT 4
+
MOverview::MOverview(MWebRequest*mw,QString pk)
{
req=mw;
ordertab->setLayout(hl=new QHBoxLayout);
hl->addLayout(vl=new QVBoxLayout,10);
vl->addWidget(ordermode=new QComboBox,0);
- ordermode->addItem(tr("-select mode-"));
- ordermode->addItem(tr("All Orders"));
- ordermode->addItem(tr("Open Orders"));
- ordermode->addItem(tr("Outstanding Payments"));
- ordermode->addItem(tr("Outstanding Refunds"));
- vl->addWidget(new QTableView);
+ ordermode->addItem(tr("-select mode-"),ORDERNONE);
+ ordermode->addItem(tr("All Orders"),ORDERALL);
+ ordermode->addItem(tr("Open Orders"),ORDEROPEN);
+ ordermode->addItem(tr("Outstanding Payments"),ORDERPAY);
+ ordermode->addItem(tr("Outstanding Refunds"),ORDERREFUND);
+ ordermode->addItem(tr("Undelivered Orders"),ORDERUNSENT);
+ connect(ordermode,SIGNAL(currentIndexChanged(int)),this,SLOT(updateOrders()));
+ vl->addWidget(ordertable=new QTableView);
+ ordertable->setModel(ordermodel=new QStandardItemModel(this));
+ ordertable->setSelectionMode(QAbstractItemView::SingleSelection);
+ ordertable->setEditTriggers(QAbstractItemView::NoEditTriggers);
hl->addLayout(vl=new QVBoxLayout,0);
vl->addWidget(new QPushButton(tr("Details...")),0);
vl->addSpacing(10);
}else{
initCart();
}
+ if(req->hasRole("getorders")){
+ updateOrders();
+ }else{
+ ordertab->setEnabled(false);
+ tab->setTabEnabled(tab->indexOf(ordertab),false);
+ }
if(req->hasRole("getusers")){
updateUsers();
}else{
entrancescan->setText("");
}
-
+//helper: finds out whether an order should be printed.
+static inline bool candoUpdateOrders(int omode,const MOrder&ord)
+{
+ if(omode==ORDERALL)return true;
+ if((omode&ORDERPAY)!=0 && ord.needsPayment())return true;
+ if((omode&ORDERREFUND)!=0 && ord.needsRefund())return true;
+ if((omode&ORDERUNSENT)!=0 && !ord.isSent())return true;
+ return false;
+}
+
+void MOverview::updateOrders()
+{
+ ordermodel->clear();
+ ordermodel->setHorizontalHeaderLabels(QStringList()<<tr("Status")<<tr("Total")<<tr("Paid")<<tr("Customer"));
+ int omode=ordermode->itemData(ordermode->currentIndex()).toInt();
+ if(omode==ORDERNONE)return;
+ QList<MOrder> orders=req->getAllOrders();
+ if(orders.size()==0)return;
+ QList<MCustomer> cust=req->getAllCustomers();
+ int cl=0;
+ for(int i=0;i<orders.size();i++){
+ if(!candoUpdateOrders(omode,orders[i]))continue;
+ ordermodel->insertRow(cl);
+ ordermodel->setHeaderData(cl,Qt::Vertical,orders[i].orderID());
+ ordermodel->setData(ordermodel->index(cl,0),orders[i].orderStatusString());
+ ordermodel->setData(ordermodel->index(cl,0),orders[i].orderID(),Qt::UserRole);
+ ordermodel->setData(ordermodel->index(cl,1),orders[i].totalPriceString());
+ ordermodel->setData(ordermodel->index(cl,2),orders[i].amountPaidString());
+ int cid=orders[i].customerID();
+ //TODO: make this more effective:
+ for(int j=0;j<cust.size();j++)
+ if(cust[j].customerID()==cid)
+ ordermodel->setData(ordermodel->index(cl,3),cust[j].name());
+ cl++;
+ }
+}
/**********************************************/
/**open event summary*/
void eventSummary();
+ /**get all orders, update list*/
+ void updateOrders();
+
/**update list of users*/
void updateUsers();
/**create new user*/
//widgets
QTabWidget*tab;
QWidget*eventtab,*carttab,*usertab,*hosttab,*ordertab,*entrancetab;
- QTableView*eventtable,*usertable,*hosttable,*carttable;
- QStandardItemModel*eventmodel,*usermodel,*hostmodel,*cartmodel;
+ QTableView*eventtable,*usertable,*hosttable,*carttable,*ordertable;
+ QStandardItemModel*eventmodel,*usermodel,*hostmodel,*cartmodel,*ordermodel;
QPushButton*thishostbutton;
QLabel*cartcustomer,*entrancelabel;
QTextEdit *cartaddr,*cartcomment;
room.cpp \
user.cpp \
host.cpp \
+ order.cpp \
customer.cpp \
checkdlg.cpp \
eventsummary.cpp \
room.h \
user.h \
host.h \
+ order.h \
customer.h \
checkdlg.h \
eventsummary.h \
return ret;
}
+QList<MOrder> MWebRequest::getAllOrders()
+{
+ errstr="";
+ if(!request("getorderlist",""))return QList<MOrder>();
+ //parse return document
+ QDomDocument doc;
+ QString msg;int ln,cl;
+ if(!doc.setContent(rspdata,&msg,&ln,&cl)){
+ errstr=tr("Error parsing OrderList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg);
+ return QList<MOrder>();
+ }
+ QDomElement root=doc.documentElement();
+ QDomNodeList nl=root.elementsByTagName("Order");
+ QList<MOrder>ret;
+ for(int i=0;i<nl.size();i++){
+ QDomElement el=nl.at(i).toElement();
+ if(el.isNull())continue;
+ MOrder mo(this,el);
+ if(mo.isValid())ret.append(mo);
+ }
+ return ret;
+}
+
QByteArray MWebRequest::responseBody()
{
return rspdata;
#include "user.h"
#include "host.h"
#include "customer.h"
+#include "order.h"
/**abstraction of requests to the web server, handles sessions and all data transfer*/
class MWebRequest:public QObject
/**returns a list of all customers*/
QList<MCustomer>getAllCustomers();
+ /**returns a list of all orders*/
+ QList<MOrder>getAllOrders();
+
/**return current host name of this session*/
QString hostName();