event summary works again
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 3 Jan 2010 19:25:52 +0000 (19:25 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 3 Jan 2010 19:25:52 +0000 (19:25 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@398 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/eventsummary.cpp
src/dialogs/eventsummary.h
src/mwin/eventstab.cpp
wob/event.wolf
www/inc/wext/event.php

index f600648..756d680 100644 (file)
@@ -28,7 +28,7 @@
 #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
@@ -49,7 +49,7 @@ MEventSummary::MEventSummary(QWidget*par,qint64 eid)
        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);
@@ -108,65 +108,67 @@ MEventSummary::MEventSummary(QWidget*par,qint64 eid)
 
 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;
@@ -175,12 +177,12 @@ void MEventSummary::print()
        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;
@@ -201,7 +203,7 @@ void MEventSummary::saveas()
        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)
@@ -310,8 +312,6 @@ void MEventSummary::getLoopVariable(QString loopname,int iteration,QString varna
        }else
        if(loopname=="ORDERS"){
                if(iteration<0 || iteration>=orderids.size())return;
-               //make sure data is here
-               getOrderData();
                //get order id
                int oid=orderids[iteration];
                
@@ -328,38 +328,40 @@ void MEventSummary::getLoopVariable(QString loopname,int iteration,QString varna
                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;
@@ -375,6 +377,6 @@ void MEventSummary::getLoopVariable(QString loopname,int iteration,QString varna
                                value=prc;
                                av=MOdtRenderer::MoneyVar;
                        }
-               }*/
+               }
        }
 }
index 7913682..394297d 100644 (file)
@@ -46,10 +46,11 @@ class MEventSummary:public QDialog
                void getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&);
                
        private:
-               int eventid;
+               qint64 eventid;
                MOEvent event;
                int nreserved,ncancelled,ntotaltickets,ntotalmoney;
                struct Tickets{
+                       Tickets(int p=0){price=p;bought=used=unused=0;}
                        int price,bought,used,unused;
                };
                QList<Tickets>tickets;
@@ -60,11 +61,10 @@ class MEventSummary:public QDialog
                QList<Comment>comments;
                QList<int>orderids;
                QMap<int,MOOrder>orders;
+               QMap<int,MOCustomerInfo>customers;
                
                //get summary
                void getSummaryData();
-               //helper: get order details
-               void getOrderData();
 };
 
 #endif
index 01f868b..b222119 100644 (file)
@@ -64,7 +64,7 @@ MEventsTab::MEventsTab(QString pk)
        vl->addSpacing(15);
        vl->addWidget(p=new QPushButton(tr("Event Summary...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(eventSummary()));
-       p->setEnabled(req->hasRole("eventsummary"));
+       p->setEnabled(req->hasRight(req->RGetEventSummary));
        vl->addSpacing(15);
        vl->addWidget(p=new QPushButton(tr("Cancel Event...")),0);
        p->setEnabled(req->hasRight(req->RCancelEvent));
index ecc405a..28fb4c2 100644 (file)
                        <Var name="room" type="Room"/>
                </Output>
        </Transaction>
+       
+       <Transaction name="GetEventSummary">
+               <Doc>Returns the event plus all orders concerning it</Doc>
+               <Input>
+                       <Var name="eventid" type="int"/>
+               </Input>
+               <Call lang="php" method="WOEvent::getSummary($this);"/>
+               <Output>
+                       <Var name="event" type="Event"/>
+                       <Var name="orders" type="List:Order"/>
+               </Output>
+       </Transaction>
 </Wolf>
\ No newline at end of file
index 6714c04..afb9747 100644 (file)
@@ -177,6 +177,28 @@ class WOEvent extends WOEventAbstract
                        }
                }
        }
+       
+       /**called by the GetEventSummary transaction: returns the full event summary*/
+       public static function getSummary($trans)
+       {
+               $evt=WOEvent::fromTableevent(WTevent::getFromDB($trans->geteventid()));
+               if(!is_a($evt,"WOEvent")){
+                       $trans->abortWithError(tr("The event ID is not valid."));
+                       return;
+               }
+               //return event
+               $trans->setevent($evt);
+               //find orders
+               //get list of valid orderids
+               global $db;
+               $res=$db->select("ticket","orderid","eventid=".$db->escapeInt($trans->geteventid()),"GROUP BY orderid ORDER BY orderid");
+               $oidl=array();
+               foreach($res as $r)
+                       if(!in_array($r["orderid"],$oidl))$oidl[]=$r["orderid"];
+               //get orders
+               $olst=WOOrder::fromTableArrayorder(WTorder::selectFromDB("orderid in ".$db->escapeIntList($oidl),"ORDER BY orderid"));
+               $trans->setorders($olst);
+       }
 };
 
 ?>
\ No newline at end of file