#include <QTextBrowser>
MEventSummary::MEventSummary(QWidget*par,qint64 eid)
- :QDialog(par)/*,event(eid) TODO: get event somehow*/
+ :QDialog(par),eventid(eid)
{
nreserved=ncancelled=ntotaltickets=ntotalmoney=0;
//get event data
gl->addWidget(new QLabel(tr("Artist:")),++rc,0);
gl->addWidget(new QLabel(event.artist().value().name()),rc,1);
gl->addWidget(new QLabel(tr("Start:")),++rc,0);
-// gl->addWidget(new QLabel(event.startTimeString()),rc,1);
+ gl->addWidget(new QLabel(event.startTimeString()),rc,1);
gl->addWidget(new QLabel(tr("Capacity:")),++rc,0);
gl->addWidget(new QLabel(QString::number(event.capacity())),rc,1);
gl->addWidget(new QLabel(tr("Tickets currently reserved:")),++rc,0);
MEventSummary::~MEventSummary(){}
-void MEventSummary::getOrderData()
+void MEventSummary::getSummaryData()
{
- if(orderids.size()==orders.size())return;
- for(int i=0;i<orderids.size();i++){
- orders.insert(orderids[i],MOOrder(orderids[i]));
+ MTGetEventSummary ges=req->queryGetEventSummary(eventid);
+ if(ges.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while retrieving data: %1").arg(ges.errorString()));
+ return;
}
-}
+ event=ges.getevent();
+ QList<MOOrder>ord=ges.getorders();
+
+ nreserved=ncancelled=ntotaltickets=ntotalmoney=0;
+ QMap<int,Tickets>maptickets;
-void MEventSummary::getSummaryData()
-{/*TODO:
- if(!req->request("eventsummary",QString::number(event.eventId()).toAscii()))return;
- if(req->responseStatus()!=MWebRequest::Ok)return;
- QDomDocument doc;
- if(!doc.setContent(req->responseBody()))return;
- QDomElement sum=doc.documentElement();
- nreserved=sum.attribute("reserved","0").toInt();
- ncancelled=sum.attribute("cancelled","0").toInt();
- ntotaltickets=sum.attribute("totaltickets","0").toInt();
- ntotalmoney=sum.attribute("totalmoney","0").toInt();
- QDomNodeList nl=sum.elementsByTagName("Tickets");
- for(int i=0;i<nl.size();i++){
- QDomElement el=nl.at(i).toElement();
- if(el.isNull())continue;
- Tickets tc;
- tc.price=el.attribute("price","0").toInt();
- tc.bought=el.attribute("bought","0").toInt();
- tc.used=el.attribute("used","0").toInt();
- tc.unused=el.attribute("unused","0").toInt();
- tickets.append(tc);
- }
- nl=sum.elementsByTagName("Comment");
- for(int i=0;i<nl.size();i++){
- QDomElement el=nl.at(i).toElement();
- if(el.isNull())continue;
- Comment c;
- c.custid=el.attribute("customerid","-1").toInt();
- c.custname=el.attribute("customer");
- c.orderid=el.attribute("orderid","-1").toInt();
- c.comment=el.text();
- comments.append(c);
- }
- nl=sum.elementsByTagName("Orders");
- for(int i=0;i<nl.size();i++){
- QDomElement el=nl.at(i).toElement();
- if(el.isNull())continue;
- QStringList oidl=el.text().split(" ");
- int oid;bool b;
- for(int i=0;i<oidl.size();i++){
- oid=oidl[i].toInt(&b);
- if(b && !orderids.contains(oid))
- orderids.append(oid);
+ //parse orders
+ for(int i=0;i<ord.size();i++){
+ //remember the order
+ orders.insert(ord[i].orderid().value(),ord[i]);
+ orderids<<ord[i].orderid();
+ //parse tickets
+ QList<MOTicket>ticks=ord[i].tickets();
+ for(int j=0;j<ticks.size();j++){
+ //ignore foreign tickets
+ if(ticks[j].eventid()!=eventid)
+ continue;
+ //count accumulated prices
+ int p=ticks[j].price();
+ if(!maptickets.contains(p))
+ maptickets.insert(p,Tickets(p));
+ //count up
+ if(ticks[j].status().value()&MOTicket::MaskUsable){
+ ntotaltickets++;
+ ntotalmoney+=ticks[j].price();
+ maptickets[p].bought++;
+ if(ticks[j].status()==MOTicket::Used)
+ maptickets[p].used++;
+ else
+ maptickets[p].unused++;
+ }
+ if(ticks[j].status()==MOTicket::Reserved)
+ nreserved++;
+ if(ticks[j].status()==MOTicket::Cancelled)
+ ncancelled++;
+ }
+ //register comments
+ QString cs=ord[i].comments().value().trimmed();
+ if(cs!=""){
+ Comment c;
+ c.custid=ord[i].customerid();
+ c.custname=ord[i].customer().value().fullName();
+ c.orderid=ord[i].orderid();
+ c.comment=cs;
+ comments.append(c);
}
}
- qSort(orderids);*/
+ tickets=maptickets.values();
+ qSort(orderids);
}
void MEventSummary::print()
-{/*TODO:
- MTemplate tf=req->getTemplate("eventsummary");
+{
+ MTemplate tf=req->templateStore()->getTemplate("eventsummary");
if(!tf.isValid()){
QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary). Giving up."));
return;
connect(&rend,SIGNAL(getVariable(QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getVariable(QString,MOdtRenderer::VarType&,QVariant&)));
connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
- rend.renderToPrinter();*/
+ rend.renderToPrinter();
}
void MEventSummary::saveas()
-{/*TODO:
- MTemplate tf=req->getTemplate("eventsummary");
+{
+ MTemplate tf=req->templateStore()->getTemplate("eventsummary");
if(!tf.isValid()){
QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary). Giving up."));
return;
connect(&rend,SIGNAL(getVariable(QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getVariable(QString,MOdtRenderer::VarType&,QVariant&)));
connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
- rend.renderToFile(fname);*/
+ rend.renderToFile(fname);
}
void MEventSummary::getVariable(QString varname,MOdtRenderer::VarType&av,QVariant&value)
}else
if(loopname=="ORDERS"){
if(iteration<0 || iteration>=orderids.size())return;
- //make sure data is here
- getOrderData();
//get order id
int oid=orderids[iteration];
if(varname=="FULLPRICE"){
value=orders[oid].totalprice().value();
av=MOdtRenderer::MoneyVar;
- }/*TODO: else
- if(varname=="SHIPPING")value=orders[oid].shipping().description();else
+ }else
+ if(varname=="SHIPPING")value=orders[oid].shippingtype().value().description().value();else
if(varname=="SHIPPINGCOST"){
- value=orders[oid].shipping().price();
+ value=orders[oid].shippingcosts().value();
av=MOdtRenderer::MoneyVar;
}else{
- QList<MTicket>ticks=orders[oid].tickets();
- QList<MTicket>eticks;
+ QList<MOTicket>ticks=orders[oid].tickets();
+ QList<MOTicket>eticks;
int first,last;
- first=last=event.startTime();
- int eid=event.eventId();
+ first=last=event.start();
+ int eid=event.eventid();
for(int i=0;i<ticks.size();i++)
- if(eid==ticks[i].eventID() && ticks[i].isToBePaid())
+ if(eid==ticks[i].eventid() && ticks[i].status()&MOTicket::MaskPay)
eticks.append(ticks[i]);
if(varname=="SHIPPINGCOSTWEIGHTED"){
//get amount of usable tickets
int ua=0;
- for(int i=0;i<ticks.size();i++)if(ticks[i].isToBePaid())ua++;
+ for(int i=0;i<ticks.size();i++)
+ if(ticks[i].status()&MOTicket::MaskPay)
+ ua++;
//calculate weighted amount
- value=orders[oid].shipping().price()*eticks.size()/ua;
+ value=orders[oid].shippingcosts()*eticks.size()/ua;
av=MOdtRenderer::MoneyVar;
}else
if(varname=="SHIPPINGCOSTIFFIRST"){
- if(first==event.startTime())
- value=orders[oid].shipping().price();
+ if(first==event.start())
+ value=orders[oid].shippingcosts().value();
else
value=0;
av=MOdtRenderer::MoneyVar;
}else
if(varname=="SHIPPINGCOSTIFLAST"){
- if(last==event.startTime())
- value=orders[oid].shipping().price();
+ if(last==event.start())
+ value=orders[oid].shippingcosts().value();
else
value=0;
av=MOdtRenderer::MoneyVar;
value=prc;
av=MOdtRenderer::MoneyVar;
}
- }*/
+ }
}
}