more flexible reports about events
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 6 Dec 2008 17:15:40 +0000 (17:15 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 6 Dec 2008 17:15:40 +0000 (17:15 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@206 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

14 files changed:
doc/prog_odttemplate.html
doc/prog_protocol.html
src/eventsummary.cpp
src/eventsummary.h
src/misc.cpp
src/misc.h
src/odtrender.cpp
src/odtrender.h
src/order.cpp
src/order.h
src/orderwin.cpp
src/orderwin.h
www/inc/classes/event.php
www/inc/machine/version.inc

index b2069bb..b025cfb 100644 (file)
@@ -7,12 +7,12 @@ This text describes how ODT templates are generated and which ones exist. ODT te
 
 <h2>Creating a Template</h2>
 
-OpenDocumentText (ODT) files are basically zipped XML files. Magic Smoke ODT Templates are ODT files in which the "content.xml" file contains some special markup that is replaced by Magic Smoke before the file is used as a normal ODT file.<p>
+Open Document Files (*.od?, usually *.odt) are basically zipped XML files. Magic Smoke ODF Templates are ODF files in which the "content.xml" file contains some special markup that is replaced by Magic Smoke before the file is used as a normal OD file.<p>
 
 This process needs some knowledge in XML.<p>
 
 <ol>
-<li>Write an ODT file that meets your expectations for what you want to template. It is recommended that you already put all variables (@VAR@, see below) into the file to make it easier to find each location.</li>
+<li>Write an OD file that meets your expectations for what you want to template. It is recommended that you already put all variables (@VAR@, see below) into the file to make it easier to find each location.</li>
 
 <li>Unzip it into a clean directory - make sure the directory structure of the ODT-ZIP-file is kept intact.<br/>Eg. under Linux to extract example.odt: <tt>mkdir example; cd example; unzip ../example.odt</tt></li>
 
@@ -53,7 +53,7 @@ Loops cannot be nested.
 
 <h3>Calculations</h3>
 
-Numeric variables allow some very simple calculations:
+Numeric variables allow some very simple calculations in place:
 
 <pre>
 @VARONE+11@
@@ -62,7 +62,60 @@ Numeric variables allow some very simple calculations:
 
 In the above example the first line will be replaced by the amount of VARONE plus 11 and the second line by the amount of VARTWO minus 77.<p>
 
-For integer variables this works on the plain integer value. For money values it adds/subtracts cents.
+For integer variables this works on the plain integer value. For money values it adds/subtracts cents.<p>
+
+More complex calculations can be done with the #CALC statement:
+
+<pre>
+#CALC:TVAR/MONEY:@VAR1@ * @VAR2@ + 4
+</pre>
+
+The above creates the temporary variable "@#TVAR@" that is the product of @VAR1@ and @VAR2@'s content plus 4. It is marked as a monetary value.<p>
+
+Calculations are restricted to the operators below and are always done from left to right - more complex formulas require several lines. Tokens must be space separated. If no type or a non-existing type is requested INT is assumed. All calculations are done using 64bit signed integers. If the processor comes across an illegal token it sets the variable to "error".<p>
+
+<table frame="1" border="1">
+<tr><td><b>Operator</b></td><td><b>Description</b></td></tr>
+<tr><td>+</td><td>adding</td></tr>
+<tr><td>-</td><td>subtracting</td></tr>
+<tr><td>*</td><td>multiplication</td></tr>
+<tr><td>/</td><td>division</td></tr>
+<tr><td>%</td><td>modulo</td></tr>
+</table>
+
+<table frame="1" border="1">
+<tr><td><b>Type</b></td><td><b>Description</b></td></tr>
+<tr><td>INT</td><td>integer number</td></tr>
+<tr><td>MONEY</td><td>monetary value (the number is interpreted as cents)</td></tr>
+<tr><td>DATE</td><td>a unix timestamp to be shown as date</td></tr>
+<tr><td>TIME</td><td>a unix timestamp to be shown as its time component</td></tr>
+<tr><td>DATETIME</td><td>a unix timestamp to be shown as date plus time</td></tr>
+</table>
+
+<h3>Newline Replacement</h3>
+
+The #SETNEWLINE statement can be used to create a macro that will replace newline in variables:
+
+<pre>
+#SETNEWLINE:&lt;/text:p>&lt;text:p text:style-name="Text_20_body">
+</pre>
+
+The default is a single space character, which can be restored by using "#SETNEWLINE:" without parameters.
+
+<h3>Generic Variables</h3>
+
+There are a few variables that always exist:
+
+<table frame="1" border="1">
+<tr><td><b>Variable</b></td><td><b>Description</b></td></tr>
+<tr><td>@TODAY@</td><td>the current date</td></tr>
+<tr><td>@NOW@</td><td>the current time</td></tr>
+<tr><td>@anyloop:ITERATION@</td><td>for an active loop ("anyloop") the current iteration (0..n)</td></tr>
+</table>
+
+<h3>Localization</h3>
+
+Per default all variables are localized before they get inserted into the document. To suppress localization prefix the variable with a "$"-sign (eg. @$TODAY@ instead of @TODAY@).
 
 <hr/>
 <h2>Event Summary</h2>
@@ -84,12 +137,31 @@ Variables:
 <tr><td>@UNUSED@</td><td>tickets that are still unused</td></tr>
 <tr><td>@CANCELLED@</td><td>tickets that were cancelled</td></tr>
 <tr><td>@TOTALMONEY@</td><td>the total amount of income for this event</td></tr>
-<tr><td>@TICKETS@</td><td>the amount of ticket lines in the overview</td></tr>
 <tr/>
+<tr><td>@TICKETS@</td><td>the amount of ticket lines in the overview</td></tr>
 <tr><td>@TICKETS:PRICE@</td><td>the price of this category</td></tr>
 <tr><td>@TICKETS:BOUGHT@</td><td>used+unused</td></tr>
 <tr><td>@TICKETS:USED@</td><td>tickets from this category that have been used</td></tr>
 <tr><td>@TICKETS:UNUSED@</td><td>tickets from this category that were not used</td></tr>
+<tr/>
+<tr><td>@COMMENTS@</td><td>the amount of (non-empty) comments attached to this event</td></tr>
+<tr><td>@COMMENTS:ORDERID@</td><td>the order-ID of this comment</td></tr>
+<tr><td>@COMMENTS:CUSTOMERID@</td><td>the ID of the customer this comment is attached to</td></tr>
+<tr><td>@COMMENTS:CUSTOMER@</td><td>the name of the customer this comment is attached to</td></tr>
+<tr><td>@COMMENTS:TEXT@</td><td>the text of the comment</td></tr>
+<tr/>
+<tr><td>@ORDERS@</td><td>the amount of orders connected to this event</td></tr>
+<tr><td>@ORDERS:ORDERID@</td><td>the order-ID of this comment</td></tr>
+<tr><td>@ORDERS:CUSTOMERID@</td><td>the ID of the customer this comment is attached to</td></tr>
+<tr><td>@ORDERS:CUSTOMER@</td><td>the name of the customer this comment is attached to</td></tr>
+<tr><td>@ORDERS:NUMTICKETS@</td><td>number of tickets in the order that are for this event</td></tr>
+<tr><td>@ORDERS:TICKETPRICE@</td><td>the accumulated price of all tickets in that order for this event</td></tr>
+<tr><td>@ORDERS:FULLPRICE@</td><td>the full price of this order</td></tr>
+<tr><td>@ORDERS:SHIPPING@</td><td>description of the shipping method of this order</td></tr>
+<tr><td>@ORDERS:SHIPPINGCOST@</td><td>the full shipping costs for this order</td></tr>
+<tr><td>@ORDERS:SHIPPINGCOSTWEIGHTED@</td><td>the weighted shipping costs of this order (costs * ticketsforthisevent / ticketsintotal) - Warning: this may not add up correctly!</td></tr>
+<tr><td>@ORDERS:SHIPPINGCOSTIFFIRST@</td><td>contains the shipping costs if this event is the earliest in the order, zero otherwise</td></tr>
+<tr><td>@ORDERS:SHIPPINGCOSTIFLAST@</td><td>contains the shipping costs if this event is the last in the order, zero otherwise</td></tr>
 </table>
 
 <h2>Order Bills</h2>
@@ -115,14 +187,17 @@ Variables:
 <tr><td>@FULLADDRESS@</td><td>the name and address of the customer</td></tr>
 <tr><td>@NAME@</td><td>the name of the customer</td></tr>
 <tr><td>@DELIVERYADDRESS@</td><td>the address it is shipped to, if different from the customers address</td></tr>
+<tr><td>@FINALADDRESS@</td><td>equals DELIVERYADDRESS if it is non-empty, otherwise FULLADDRESS</td></tr>
 <tr><td>@TOTALPRICE@</td><td>the total price of the order</td></tr>
 <tr><td>@AMOUNTPAID@</td><td>the amount that has already been paid</td></tr>
 <tr><td>@SELLER@</td><td>the login ID of the seller (it is not recommended to use this)</td></tr>
 <tr><td>@COMMENT@</td><td>the comment in the order (it is not recommended to use this)</td></tr>
 <tr><td>@AMOUNTTOPAY@</td><td>the amount that still needs to be paid</td></tr>
 <tr><td>@AMOUNTTOREFUND@</td><td>the amount that has to be refunded</td></tr>
-<tr><td>@TICKETS@</td><td>the amount of tickets in the order</td></tr>
+<tr><td>@SHIPPING@</td><td>description of the shipping method used or empty string</td></tr>
+<tr><td>@SHIPPINGPRICE@</td><td>the costs for shipping</td></tr>
 <tr/>
+<tr><td>@TICKETS@</td><td>the amount of tickets in the order</td></tr>
 <tr><td>@TICKETS:PRICE@</td><td>the price of this ticket</td></tr>
 <tr><td>@TICKETS:ID@</td><td>the ID of this ticket (barcode-string)</td></tr>
 <tr><td>@TICKETS:TITLE@</td><td>the title of the event for this ticket</td></tr>
@@ -131,8 +206,25 @@ Variables:
 <tr><td>@TICKETS:STARTTIME@</td><td>the date and start time of the event for this ticket</td></tr>
 <tr><td>@TICKETS:ENDTIME@</td><td>the end date and time of the event for this ticket</td></tr>
 <tr><td>@TICKETS:ROOM@</td><td>the room/place of the event for this ticket</td></tr>
+<tr/>
+<tr><td>@ACCTICKETS@</td><td>the amount of distinct ticket types in the order</td></tr>
+<tr><td>@ACCTICKETS:PRICE@</td><td>the price of one ticket of this type</td></tr>
+<tr><td>@ACCTICKETS:FULLPRICE@</td><td>the accumulated price of all tickets of this type (PRICE*AMOUNT)</td></tr>
+<tr><td>@ACCTICKETS:AMOUNT@</td><td>the amount of tickets in this type</td></tr>
+<tr><td>@ACCTICKETS:TITLE@</td><td>the title of the event for this ticket type</td></tr>
+<tr><td>@ACCTICKETS:ARTIST@</td><td>the artist of the event for this ticket type</td></tr>
+<tr><td>@ACCTICKETS:DATE@</td><td>the date of the event for this ticket type</td></tr>
+<tr><td>@ACCTICKETS:STARTTIME@</td><td>the date and start time of the event for this ticket type</td></tr>
+<tr><td>@ACCTICKETS:ENDTIME@</td><td>the end date and time of the event for this ticket type</td></tr>
+<tr><td>@ACCTICKETS:ROOM@</td><td>the room/place of the event for this ticket type</td></tr>
+<tr/>
 <tr><td>@ADDRESSLINES@</td><td>amount of lines that the address has</td></tr>
 <tr><td>@ADDRESSLINES:LINE@</td><td>current line in the address loop</td></tr>
+<tr/>
+<tr><td>@VOUCHERS@</td><td>the amount of vouchers in the order</td></tr>
+<tr><td>@VOUCHERS:PRICE@</td><td>the price of this voucher</td></tr>
+<tr><td>@VOUCHERS:VALUE@</td><td>the (remaining) value of this voucher</td></tr>
+<tr><td>@VOUCHERS:ID@</td><td>the ID of this voucher</td></tr>
 </table>
 
 
index f6a949b..33e0663 100644 (file)
@@ -219,6 +219,8 @@ The <tt>eventsummary</tt> transaction returns summary data for an event. The req
     totaltickets="numberOfUsableTickets" totalmoney="totalIncomeOfEventInCent" >
   &lt;Tickets price="priceCategoryInCent" bought="numberOfUsableTicketsInThisCategory"
       used="numberOfUsedTickets" unused="numberOfUnusedTickets" />
+  &lt;Comment customerid="customerID" customer="customers Name" orderid="orderID">comment&lt;/Comment>
+  &lt;Orders>space separated IDs of all orders for this event&lt;/Orders>
 &lt;/EventSummary>
 </pre>
 
index bcc0086..9f524d9 100644 (file)
 #include <QTextBrowser>
 
 MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
-       :QDialog(par)
+       :QDialog(par),event(rq,eid)
 {
        req=rq;
-       eventid=eid;
-       starttime=capacity=nreserved=ncancelled=ntotaltickets=ntotalmoney=0;
+       nreserved=ncancelled=ntotaltickets=ntotalmoney=0;
        //get event data
-       getEventData();
        getSummaryData();
        //layout/tabs
-       setWindowTitle(tr("Summary for Event %1").arg(title));
+       setWindowTitle(tr("Summary for Event %1").arg(event.title()));
        QVBoxLayout*vl;
        setLayout(vl=new QVBoxLayout);
        QTabWidget*tab;
@@ -48,14 +46,13 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        w->setLayout(gl=new QGridLayout);
        int rc=0;
        gl->addWidget(new QLabel(tr("Title:")),rc,0);
-       gl->addWidget(new QLabel(title),rc,1);
+       gl->addWidget(new QLabel(event.title()),rc,1);
        gl->addWidget(new QLabel(tr("Artist:")),++rc,0);
-       gl->addWidget(new QLabel(artist),rc,1);
+       gl->addWidget(new QLabel(event.artist()),rc,1);
        gl->addWidget(new QLabel(tr("Start:")),++rc,0);
-       QString start=QDateTime::fromTime_t(starttime).toString(tr("yyyy-MM-dd hh:mm ap","Date+Time format for displaying event start time"));
-       gl->addWidget(new QLabel(start),rc,1);
+       gl->addWidget(new QLabel(event.startTimeString()),rc,1);
        gl->addWidget(new QLabel(tr("Capacity:")),++rc,0);
-       gl->addWidget(new QLabel(QString::number(capacity)),rc,1);
+       gl->addWidget(new QLabel(QString::number(event.capacity())),rc,1);
        gl->addWidget(new QLabel(tr("Tickets currently reserved:")),++rc,0);
        gl->addWidget(new QLabel(QString::number(nreserved)),rc,1);
        gl->addWidget(new QLabel(tr("Tickets currently cancelled:")),++rc,0);
@@ -63,8 +60,7 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        gl->addWidget(new QLabel(tr("Tickets currently usable:")),++rc,0);
        gl->addWidget(new QLabel(QString::number(ntotaltickets)),rc,1);
        gl->addWidget(new QLabel(tr("Total Income:")),++rc,0);
-       QString tm=QString::number(ntotalmoney/100)+tr(".","decimal dot")+QString().sprintf("%02d",ntotalmoney%100);
-       gl->addWidget(new QLabel(tm),rc,1);
+       gl->addWidget(new QLabel(cent2str(ntotalmoney)),rc,1);
        
        QTableView*table;
        QStandardItemModel*model;
@@ -76,8 +72,7 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        model->setHorizontalHeaderLabels(QStringList()<<tr("Price")<<tr("Bought")<<tr("Used")<<tr("Unused"));
        for(int i=0;i<tickets.size();i++){
                Tickets tc=tickets[i];
-               tm=QString::number(tc.price/100)+tr(".","decimal dot")+QString().sprintf("%02d",tc.price%100);
-               model->setData(model->index(i,0),tm);
+               model->setData(model->index(i,0),cent2str(tc.price));
                model->setData(model->index(i,1),tc.bought);
                model->setData(model->index(i,2),tc.used);
                model->setData(model->index(i,3),tc.unused);
@@ -114,29 +109,17 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
 
 MEventSummary::~MEventSummary(){}
 
-void MEventSummary::getEventData()
+void MEventSummary::getOrderData()
 {
-       if(!req->request("geteventdata",QString::number(eventid).toAscii()))return;
-       if(req->responseStatus()!=MWebRequest::Ok)return;
-       QDomDocument doc;
-       if(!doc.setContent(req->responseBody()))return;
-       QDomNodeList nl=doc.elementsByTagName("Event");
-       for(int i=0;i<nl.size();i++){
-               QDomElement el=nl.at(i).toElement();
-               if(el.isNull())continue;
-               if(el.attribute("id","-1").toInt()!=eventid)continue;
-               starttime=el.attribute("start").toInt();
-               capacity=el.attribute("capacity").toInt();
-               QDomNodeList nl2=el.elementsByTagName("Title");
-               if(nl2.size()>0)title=nl2.at(0).toElement().text();
-               nl2=el.elementsByTagName("Artist");
-               if(nl2.size()>0)artist=nl2.at(0).toElement().text();
+       if(orderids.size()==orders.size())return;
+       for(int i=0;i<orderids.size();i++){
+               orders.insert(orderids[i],MOrder(req,orderids[i]));
        }
 }
 
 void MEventSummary::getSummaryData()
 {
-       if(!req->request("eventsummary",QString::number(eventid).toAscii()))return;
+       if(!req->request("eventsummary",QString::number(event.eventId()).toAscii()))return;
        if(req->responseStatus()!=MWebRequest::Ok)return;
        QDomDocument doc;
        if(!doc.setContent(req->responseBody()))return;
@@ -167,6 +150,19 @@ void MEventSummary::getSummaryData()
                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);
+               }
+       }
+       qSort(orderids);
 }
 
 void MEventSummary::print()
@@ -177,9 +173,9 @@ void MEventSummary::print()
                return;
        }
        MOdtSignalRenderer rend(tf);
-       connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
+       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,int,QString&)),this,SLOT(getLoopVariable(QString,int,QString,int,QString&)));
+       connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
        rend.renderToPrinter();
 }
 
@@ -203,72 +199,176 @@ void MEventSummary::saveas()
                fname=fn[0];
        }
        MOdtSignalRenderer rend(tf);
-       connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
+       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,int,QString&)),this,SLOT(getLoopVariable(QString,int,QString,int,QString&)));
+       connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
        rend.renderToFile(fname);
 }
 
-void MEventSummary::getVariable(QString varname,int av,QString&value)
+void MEventSummary::getVariable(QString varname,MOdtRenderer::VarType&av,QVariant&value)
 {
        if(varname=="TITLE")
-               value=title;
+               value=event.title();
        else
        if(varname=="ARTIST")
-               value=artist;
-       else
-       if(varname=="START")
-               value=QDateTime::fromTime_t(starttime).toString(tr("yyyy-MM-dd hh:mm ap","Date+Time format for displaying event start time"));
-       else
-       if(varname=="CAPACITY")
-               value=QString::number(capacity+av);
-       else
-       if(varname=="RESERVED")
-               value=QString::number(nreserved+av);
-       else
-       if(varname=="BOUGHT")
-               value=QString::number(ntotaltickets+av);
+               value=event.artist();
        else
+       if(varname=="START"){
+               value=event.startTime();
+               av=MOdtRenderer::DateTimeVar;
+       }else
+       if(varname=="CAPACITY"){
+               value=event.capacity();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(varname=="RESERVED"){
+               value=nreserved;
+               av=MOdtRenderer::IntVar;
+       }else
+       if(varname=="BOUGHT"){
+               value=ntotaltickets;
+               av=MOdtRenderer::IntVar;
+       }else
        if(varname=="USED"){
                int nused=0;
                for(int i=0;i<tickets.size();i++)nused+=tickets[i].used;
-               value=QString::number(nused+av);
+               value=nused;
+               av=MOdtRenderer::IntVar;
        }else
        if(varname=="UNUSED"){
                int nunused=0;
                for(int i=0;i<tickets.size();i++)nunused+=tickets[i].unused;
-               value=QString::number(nunused+av);
+               value=nunused;
+               av=MOdtRenderer::IntVar;
+       }else
+       if(varname=="CANCELLED"){
+               value=ncancelled;
+               av=MOdtRenderer::IntVar;
        }else
-       if(varname=="CANCELLED")
-               value=QString::number(ncancelled+av);
-       else
        if(varname=="TOTALMONEY"){
-               int ntm=ntotalmoney+av;
-               value=QString::number(ntm/100)
-                 +tr(".","decimal dot")
-                 +QString().sprintf("%02d",ntm%100);
+               value=ntotalmoney;
+               av=MOdtRenderer::MoneyVar;
        }else
-       if(varname=="TICKETS")
-               value=QString::number(tickets.size()+av);
+       if(varname=="TICKETS"){
+               value=tickets.size();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(varname=="COMMENTS"){
+               value=comments.size();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(varname=="ORDERS"){
+               value=orderids.size();
+               av=MOdtRenderer::IntVar;
+       }
 }
 
 void MEventSummary::getLoopIterations(QString loopname,int&iterations)
 {
-       if(loopname=="TICKETS")iterations=tickets.size();
+       if(loopname=="TICKETS")iterations=tickets.size();else
+       if(loopname=="COMMENTS")iterations=comments.size();else
+       if(loopname=="ORDERS")iterations=orderids.size();
+       else
+               iterations=0;
 }
 
-void MEventSummary::getLoopVariable(QString loopname,int iteration,QString varname,int av,QString&value)
+void MEventSummary::getLoopVariable(QString loopname,int iteration,QString varname,MOdtRenderer::VarType&av,QVariant&value)
 {
-       if(loopname!="TICKETS")return;
-       if(iteration<0 || iteration>=tickets.size())return;
+       if(loopname=="TICKETS"){
+               if(iteration<0 || iteration>=tickets.size())return;
+               
+               if(varname=="PRICE"){
+                       value=tickets[iteration].price;
+                       av=MOdtRenderer::MoneyVar;
+               }else
+               if(varname=="BOUGHT"){
+                       value=tickets[iteration].bought;
+                       av=MOdtRenderer::IntVar;
+               }else
+               if(varname=="USED"){
+                       value=tickets[iteration].used;
+                       av=MOdtRenderer::IntVar;
+               }else
+               if(varname=="UNUSED"){
+                       value=tickets[iteration].unused;
+                       av=MOdtRenderer::IntVar;
+               }
+       }else
+       if(loopname=="COMMENTS"){
+               if(iteration<0 || iteration>=comments.size())return;
        
-       if(varname=="PRICE"){
-               int p=tickets[iteration].price+av;
-               value=QString::number(p/100)
-                 +tr(".","decimal dot")
-                 +QString().sprintf("%02d",p%100);
+               if(varname=="ORDERID")value=QString::number(comments[iteration].orderid);else
+               if(varname=="CUSTOMERID")value=QString::number(comments[iteration].custid);else
+               if(varname=="CUSTOMER")value=comments[iteration].custname;else
+               if(varname=="TEXT")value=comments[iteration].comment;
        }else
-       if(varname=="BOUGHT")value=QString::number(tickets[iteration].bought+av);else
-       if(varname=="USED")value=QString::number(tickets[iteration].used+av);else
-       if(varname=="UNUSED")value=QString::number(tickets[iteration].unused+av);       
+       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=="ORDERID"){
+                       value=QString::number(oid);
+                       return;
+               }
+               
+               //paranoia check
+               if(!orders.contains(oid))return;
+               
+               if(varname=="CUSTOMERID")value=QString::number(orders[oid].customerID());else
+               if(varname=="CUSTOMER")value=orders[oid].customer().name();else
+               if(varname=="FULLPRICE"){
+                       value=orders[oid].totalPrice();
+                       av=MOdtRenderer::MoneyVar;
+               }else
+               if(varname=="SHIPPING")value=orders[oid].shipping().description();else
+               if(varname=="SHIPPINGCOST"){
+                       value=orders[oid].shipping().price();
+                       av=MOdtRenderer::IntVar;
+               }else{
+                       QList<MTicket>ticks=orders[oid].tickets();
+                       QList<MTicket>eticks;
+                       int first,last;
+                       first=last=event.startTime();
+                       int eid=event.eventId();
+                       for(int i=0;i<ticks.size();i++)
+                               if(eid==ticks[i].eventID() && ticks[i].isToBePaid())
+                                       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++;
+                               //calculate weighted amount
+                               value=orders[oid].shipping().price()*eticks.size()/ua;
+                               av=MOdtRenderer::MoneyVar;
+                       }else
+                       if(varname=="SHIPPINGCOSTIFFIRST"){
+                               if(first==event.startTime())
+                                       value=orders[oid].shipping().price();
+                               else
+                                       value=0;
+                               av=MOdtRenderer::MoneyVar;
+                       }else
+                       if(varname=="SHIPPINGCOSTIFLAST"){
+                               if(last==event.startTime())
+                                       value=orders[oid].shipping().price();
+                               else
+                                       value=0;
+                               av=MOdtRenderer::MoneyVar;
+                       }else
+                       if(varname=="NUMTICKETS"){
+                               value=eticks.size();
+                               av=MOdtRenderer::IntVar;
+                       }else
+                       if(varname=="TICKETPRICE"){
+                               int prc=0;
+                               for(int i=0;i<eticks.size();i++)
+                                       prc+=eticks[i].price();
+                               value=prc;
+                               av=MOdtRenderer::MoneyVar;
+                       }
+               }
+       }
 }
index 9efefb2..b5ce8cd 100644 (file)
 #define MAGICSMOKE_EVENTSUMMARY_H
 
 #include <QDialog>
+#include <QMap>
+
+#include "order.h"
+#include "odtrender.h"
 
 class MWebRequest;
 class QTableView;
@@ -37,14 +41,14 @@ class MEventSummary:public QDialog
                void saveas();
                
                //used for ODT rendering:
-               void getVariable(QString varname,int,QString&value);
-               void getLoopIterations(QString loopname,int&iterations);
-               void getLoopVariable(QString loopname,int iteration,QString varname,int,QString&value);
+               void getVariable(QString,MOdtRenderer::VarType&,QVariant&);
+               void getLoopIterations(QString,int&);
+               void getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&);
                
        private:
                MWebRequest*req;
-               int eventid,starttime,capacity;
-               QString title,artist;
+               int eventid;
+               MEvent event;
                int nreserved,ncancelled,ntotaltickets,ntotalmoney;
                struct Tickets{
                        int price,bought,used,unused;
@@ -55,11 +59,13 @@ class MEventSummary:public QDialog
                        QString custname,comment;
                };
                QList<Comment>comments;
+               QList<int>orderids;
+               QMap<int,MOrder>orders;
                
-               //get basic data about event
-               void getEventData();
                //get summary
                void getSummaryData();
+               //helper: get order details
+               void getOrderData();
 };
 
 #endif
index c5c60ce..a055f29 100644 (file)
@@ -13,6 +13,7 @@
 #include "misc.h"
 
 #include <QCoreApplication>
+#include <QDateTime>
 
 QString htmlize(QString str)
 {
@@ -30,7 +31,7 @@ QString htmlize(QString str)
        return out;
 }
 
-QString xmlize(QString str)
+QString xmlize(QString str,QString newline)
 {
        QString out;
        for(int i=0;i<str.size();i++){
@@ -39,25 +40,56 @@ QString xmlize(QString str)
                if(c=='<')out+="&lt;";else
                if(c=='>')out+="&gt;";else
                if(c=='&')out+="&amp;";else
+               if(c=='\n')out+=newline;else
                if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c;
                else out+="&#"+QString::number(ci)+";";
        }
        return out;
 }
-QString cent2str(int c)
+QString cent2str(int c,bool localize)
 {
-       QString ret=QCoreApplication::translate("misc","%1.%2","price with decimal dot");
+       QString ret;
+       if(localize)ret=QCoreApplication::translate("misc","%1.%2","price with decimal dot");
+       else ret="%1.%2";
        return ret.arg(c/100).arg(c%100,2,10,QChar('0'));
 }
 
-int str2cent(QString s)
+int str2cent(QString s,bool localize)
 {
-       QString p=s.replace(QCoreApplication::translate("misc",".","decimal dot in price"),".");
-       double c=s.toDouble()*100;
+       if(localize)s=s.replace(QCoreApplication::translate("misc",".","decimal dot in price"),".");
+       double c=s.toDouble()*100.;
        return int(c);
 }
 
-QRegExp priceRegExp()
+QRegExp priceRegExp(bool localize)
 {
-       return QRegExp(QCoreApplication::translate("misc","[0-9]+\\.[0-9]{2}","regexp for price"));
+       if(localize)
+               return QRegExp(QCoreApplication::translate("misc","[0-9]+\\.[0-9]{2}","regexp for price"));
+       else
+               return QRegExp("[0-9]+\\.[0-9]{2}");
 }
+
+QString unix2date(int tm,bool localize)
+{
+       QString format;
+       if(localize)format=QCoreApplication::translate("misc","yyyy-MM-dd","localized date format");
+       format="yyyy-MM-dd";
+       return QDateTime::fromTime_t(tm).toString(format);
+}
+
+QString unix2time(int tm,bool localize)
+{
+       QString format;
+       if(localize)format=QCoreApplication::translate("misc","hh:mm","localized time format");
+       format="hh:mm";
+       return QDateTime::fromTime_t(tm).toString(format);
+}
+
+QString unix2dateTime(int tm,bool localize)
+{
+       QString format;
+       if(localize)format=QCoreApplication::translate("misc","yyyy-MM-dd hh:mm","localized date + time format");
+       format="yyyy-MM-dd hh:mm";
+       return QDateTime::fromTime_t(tm).toString(format);
+}
+
index a816068..6d9766f 100644 (file)
 QString htmlize(QString str);
 
 /**converts special XML characters into harmless &-codes, so the text can be included*/
-QString xmlize(QString str);
+QString xmlize(QString str,QString newline="\n");
 
-/**converts a cent value into a localized string*/
-QString cent2str(int c);
+/**converts a cent value into a (localized) string*/
+QString cent2str(int cent,bool localize=true);
 
-/**converts a localized string back into a cent value (must not contain spaces or extra dots)*/
-int str2cent(QString s);
+/**converts a (localized) string back into a cent value (must not contain spaces or extra dots)*/
+int str2cent(QString s,bool fromlocal=true);
 
-/**return a localized regular expression that validates prices*/
-QRegExp priceRegExp();
+/**converts a unix timestamp into a date*/
+QString unix2date(int,bool localize=true);
+
+/**converts a unix timestamp into a time (ommitting the date)*/
+QString unix2time(int,bool localize=true);
+
+/**converts a unix timestamp into a date-time-string*/
+QString unix2dateTime(int,bool localize=true);
+
+/**return a (localized) regular expression that validates prices*/
+QRegExp priceRegExp(bool localize=true);
 
 #endif
index 3b09dfa..f10961d 100644 (file)
@@ -49,10 +49,21 @@ class MOdtRendererPrivate
                QString getVariable(QString varname);
                QString getLoopVariable(QString loopname,int iteration,QString varname);
                
+               qint64 intToken(QString,QString,int);
+               void setLocalVar(QString,qint64);
+               void setLocalVarError(QString);
+               
                //data the parent does not access
                MOdtRenderer*parent;
                QUnZip temp;
                QFile tfile;
+               QString newline;
+               
+               struct LocalVar{
+                       MOdtRenderer::VarType type;
+                       QVariant value;
+               };
+               QMap<QString,LocalVar>localvars;
 };
 
 MOdtRenderer::MOdtRenderer(MTemplate file)
@@ -65,6 +76,7 @@ MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p)
        :tfile(file)
 {
        parent=p;
+       newline=" ";
        //open ZIP
        if(tfile.open(QIODevice::ReadOnly))temp.open(&tfile);
        //TODO: make sure this is a valid ZIP file, preferably with some ODT content
@@ -204,7 +216,7 @@ QString MOdtRendererPrivate::render(QString s)
                        if(fbuf[i].trimmed().startsWith("#LOOP:")){
                                lname=fbuf[i].trimmed().mid(6).trimmed();
                                isloop=true;
-                       }else{//not a loop
+                       }else{//not a loop or statement
                                //convert line
                                ret+=renderLine(fbuf[i],"",-1);
                                ret+="\n";
@@ -219,15 +231,58 @@ QString MOdtRendererPrivate::renderLine(QString line,QString loop,int lpos)
 {
        QString ret,vname;
        bool isvar=false;
-       static QString vc="ABCDEFGHIJKLMNOPQRSTUVWXYZ:+-0123456789";
+       static QString vc="ABCDEFGHIJKLMNOPQRSTUVWXYZ:+-0123456789$#";
+       //check for statements
+       if(line.trimmed().startsWith("#SETNEWLINE:")){
+               //set a new newline translation
+               newline=line.trimmed().mid(12).trimmed();
+               if(newline=="")newline=" ";
+               return "";
+       }
+       if(line.trimmed().startsWith("#CALC:")){
+               //do a calculation
+               //get full statement
+               QString stmt=line.trimmed().mid(6).trimmed();
+               qDebug("????????????????Calculation: %s",stmt.toAscii().data());
+               //split out var name
+               int p=stmt.indexOf(':');
+               if(p<1)return "";
+               QString var=stmt.left(p).trimmed();
+               //get list of statement tokens
+               QStringList stl=stmt.mid(p+1).trimmed().split(" ");
+               //go through
+               qint64 res=intToken(stl[0],loop,lpos);
+               qDebug("??????????CalcInit: %lli",res);
+               for(int i=1;i<stl.size();i+=2){
+                       if((i+1)>=stl.size()){
+                               setLocalVarError(var);
+                               qDebug("??????????CalcError: missing operand");
+                               return "";
+                       }
+                       qDebug("??????????Calc: operator '%s' operand '%s' -> '%lli'",stl[i].toAscii().data(),stl[i+1].toAscii().data(),intToken(stl[i+1],loop,lpos));
+                       if(stl[i]=="+")res+=intToken(stl[i+1],loop,lpos);else
+                       if(stl[i]=="-")res-=intToken(stl[i+1],loop,lpos);else
+                       if(stl[i]=="*")res*=intToken(stl[i+1],loop,lpos);else
+                       if(stl[i]=="/")res/=intToken(stl[i+1],loop,lpos);else
+                       if(stl[i]=="%")res%=intToken(stl[i+1],loop,lpos);
+                       else {
+                               setLocalVarError(var);
+                               qDebug("??????????CalcError: unknown operator");
+                               return "";
+                       }
+               }
+               setLocalVar(var,res);
+               return "";
+       }
        //scan characters
        for(int i=0;i<line.size();i++){
                //are we currently inside a variable name?
                if(isvar){
                        //end of var?
                        if(line[i]=='@'){
-                               if(vname=="")ret+="@";
-                               else{
+                               if(vname==""){
+                                       ret+="@";
+                               }else{
                                        QStringList vl=vname.split(":");
                                        if(vl.size()>2){
                                                //this was a mistake, reset
@@ -238,13 +293,13 @@ QString MOdtRendererPrivate::renderLine(QString line,QString loop,int lpos)
                                                //this is a loop variable, 
                                                //check that it is the right loop
                                                //or any loop at all...
-                                               if(loop!="" && loop==vl[0]){
+                                               if(loop!="" && (loop==vl[0] || ("$"+loop)==vl[0])){
                                                        //get value
-                                                       ret+=xmlize(getLoopVariable(loop,lpos,vl[1]));
+                                                       ret+=xmlize(getLoopVariable(vl[0],lpos,vl[1]).trimmed(),newline);
                                                }
                                        }else
                                                //this is a normal variable, get valie
-                                               ret+=xmlize(getVariable(vname));
+                                               ret+=xmlize(getVariable(vname).trimmed(),newline);
                                }
                                //reset mode
                                isvar=false;
@@ -280,28 +335,151 @@ QString MOdtRendererPrivate::renderLine(QString line,QString loop,int lpos)
        return ret;
 }
 
+static inline QString formatVar(QVariant r,MOdtRenderer::VarType tp,bool loc,int offset)
+{
+       switch(tp){
+               case MOdtRenderer::StringVar:
+                       return r.toString();
+               case MOdtRenderer::IntVar:
+                       return QString::number(r.toInt()+offset);
+               case MOdtRenderer::MoneyVar:
+                       return cent2str(r.toInt()+offset,loc);
+               case MOdtRenderer::DateVar:
+                       return unix2date(r.toInt()+offset,loc);
+               case MOdtRenderer::TimeVar:
+                       return unix2time(r.toInt()+offset,loc);
+               case MOdtRenderer::DateTimeVar:
+                       return unix2dateTime(r.toInt()+offset,loc);
+       }
+       return "";
+}
+
 QString MOdtRendererPrivate::getVariable(QString varname)
 {
+       //split out calculation
+       int offset=0;
        int p=varname.indexOf('+');
-       if(p>0)
-               return parent->getVariable(varname.left(p),varname.mid(p+1).toInt());
+       if(p>0){
+               offset=varname.mid(p+1).toInt();
+               varname=varname.left(p);
+       }
        p=varname.indexOf('-');
-       if(p>0)
-               return parent->getVariable(varname.left(p),varname.mid(p).toInt());
-       return parent->getVariable(varname,0);
+       if(p>0){
+               offset=varname.mid(p).toInt();
+               varname=varname.left(p);
+       }
+       //split out $-sign
+       bool localize=true;
+       if(varname[0]=='$'){
+               localize=false;
+               varname=varname.mid(1);
+       }
+       //get variable
+       MOdtRenderer::VarType tp=MOdtRenderer::StringVar;
+       QVariant r;
+       if(varname=="TODAY"){
+               r=QDateTime::currentDateTime().toTime_t();
+               tp=MOdtRenderer::DateVar;
+       }else if(varname=="NOW"){
+               r=QDateTime::currentDateTime().toTime_t();
+               tp=MOdtRenderer::TimeVar;
+       }else if(varname[0]=='#'){
+               if(localvars.contains(varname.mid(1))){
+                       r=localvars[varname.mid(1)].value;
+                       tp=localvars[varname.mid(1)].type;
+               }
+       }else{
+               r=parent->getVariable(varname,tp);
+       }
+       return formatVar(r,tp,localize,offset);
 }
 
 QString MOdtRendererPrivate::getLoopVariable(QString loopname,int iteration,QString varname)
 {
+       //split out calculation
+       int offset=0;
        int p=varname.indexOf('+');
-       if(p>0)
-               return parent->getLoopVariable(loopname,iteration,varname.left(p),varname.mid(p+1).toInt());
+       if(p>0){
+               offset=varname.mid(p+1).toInt();
+               varname=varname.left(p);
+       }
        p=varname.indexOf('-');
-       if(p>0)
-               return parent->getLoopVariable(loopname,iteration,varname.left(p),varname.mid(p).toInt());
-       return parent->getLoopVariable(loopname,iteration,varname,0);
+       if(p>0){
+               offset=varname.mid(p).toInt();
+               varname=varname.left(p);
+       }
+       //split out $-sign
+       bool localize=true;
+       if(loopname[0]=='$'){
+               localize=false;
+               loopname=loopname.mid(1);
+       }
+       qDebug("!!!!!!!!!!getting loop var '%s' : '%s' localized=%s offset=%i",loopname.toAscii().data(),varname.toAscii().data(),(localize?"yes":"no"),offset);
+       //get variable
+       MOdtRenderer::VarType tp=MOdtRenderer::StringVar;
+       QVariant r;
+       if(varname=="ITERATION"){
+               r=iteration;
+               tp=MOdtRenderer::IntVar;
+       }else
+               r=parent->getLoopVariable(loopname,iteration,varname,tp);
+       return formatVar(r,tp,localize,offset);
+}
+
+qint64 MOdtRendererPrivate::intToken(QString vname,QString loop,int lpos)
+{
+       //split the variable
+       QStringList vnl=vname.split(":");
+       if(vnl.size()<2){
+               //local var?
+               if(vnl[0][0]=='#'){
+                       if(localvars.contains(vnl[0].mid(1)))
+                               return localvars[vnl[0].mid(1)].value.toLongLong();
+                       return 0;
+               }
+               //special var?
+               if(vname=="TODAY" || vname=="NOW")
+                       return QDateTime::currentDateTime().toTime_t();
+               //get from parent
+               MOdtRenderer::VarType tp;
+               return parent->getVariable(vnl[0],tp).toLongLong();
+       }else{
+               //correct loop?
+               if(vnl[0]!=loop)return 0;
+               //iteration?
+               if(vnl[1]=="ITERATION")return lpos;
+               //get from parent
+               MOdtRenderer::VarType tp;
+               return parent->getLoopVariable(loop,lpos,vnl[1],tp).toLongLong();
+       }
 }
 
+void MOdtRendererPrivate::setLocalVar(QString vn,qint64 va)
+{
+       //split vname/type
+       QStringList vnl=vn.split("/");
+       MOdtRenderer::VarType tp=MOdtRenderer::IntVar;
+       if(vnl.size()>1){
+               if(vnl[1]=="MONEY")tp=MOdtRenderer::MoneyVar;else
+               if(vnl[1]=="DATE")tp=MOdtRenderer::DateVar;else
+               if(vnl[1]=="TIME")tp=MOdtRenderer::TimeVar;else
+               if(vnl[1]=="DATETIME")tp=MOdtRenderer::DateTimeVar;
+       }
+       //store
+       LocalVar lv;
+       lv.type=tp;
+       lv.value=va;
+       localvars.insert(vnl[0],lv);
+}
+
+void MOdtRendererPrivate::setLocalVarError(QString vn)
+{
+       QStringList vnl=vn.split("/");
+       LocalVar lv;
+       lv.type=MOdtRenderer::StringVar;
+       lv.value="error";
+       localvars.insert(vnl[0],lv);
+}
 
 /********************************************************************/
 
@@ -312,9 +490,10 @@ MOdtSignalRenderer::MOdtSignalRenderer(MTemplate file)
 
 MOdtSignalRenderer::~MOdtSignalRenderer(){}
 
-QString MOdtSignalRenderer::getVariable(QString varname,int av)
+QVariant MOdtSignalRenderer::getVariable(QString varname,MOdtRenderer::VarType&av)
 {
-       QString ret;
+       QVariant ret;
+       av=MOdtRenderer::StringVar;
        emit getVariable(varname,av,ret);
        return ret;
 }
@@ -326,9 +505,10 @@ int MOdtSignalRenderer::getLoopIterations(QString loopname)
        return ret;
 }
 
-QString MOdtSignalRenderer::getLoopVariable(QString loopname,int iteration,QString varname,int av)
+QVariant MOdtSignalRenderer::getLoopVariable(QString loopname,int iteration,QString varname,MOdtRenderer::VarType&av)
 {
-       QString ret;
+       QVariant ret="notfound";
+       av=MOdtRenderer::StringVar;
        emit getLoopVariable(loopname,iteration,varname,av,ret);
        return ret;
 }
index ce7313f..bae9fef 100644 (file)
@@ -39,16 +39,32 @@ class MOdtRenderer
                /**starts the internal rendering routine and outputs to printer (calls OpenOffice to print)*/
                virtual void renderToPrinter();
                
+               /**variable type*/
+               enum VarType{
+                       /**default: uninterpreted string*/
+                       StringVar,
+                       /**simple integer value*/
+                       IntVar,
+                       /**money value*/
+                       MoneyVar,
+                       /**unix timestamp: format as date*/
+                       DateVar,
+                       /**unix timestamp: format as time*/
+                       TimeVar,
+                       /**unix timestamp: format as date+time*/
+                       DateTimeVar
+               };
+               
        protected:
                friend class MOdtRendererPrivate;
                /**implement this to return the value of a variable during rendering; should return empty string if the variable does not exist*/
-               virtual QString getVariable(QString varname,int addval)=0;
+               virtual QVariant getVariable(QString varname,VarType&)=0;
                
                /**implement this to return the amount of iterations for a defined loop; should return 0 if the loop does not exist*/
                virtual int getLoopIterations(QString loopname)=0;
                
                /**implement this to return a specific instance of a loop internal variable; should return empty string if the request is not valid*/
-               virtual QString getLoopVariable(QString loopname,int iteration,QString varname,int addval)=0;
+               virtual QVariant getLoopVariable(QString loopname,int iteration,QString varname,VarType&)=0;
        private:
                MOdtRendererPrivate*d;
 };
@@ -65,18 +81,18 @@ class MOdtSignalRenderer:public QObject,public MOdtRenderer
        
        signals:
                /**connect this to return the value of a variable during rendering; should return empty string if the variable does not exist*/
-               void getVariable(QString varname,int addval,QString&value);
+               void getVariable(QString varname,MOdtRenderer::VarType&,QVariant&value);
                
                /**connect this to return the amount of iterations for a defined loop; should return 0 if the loop does not exist*/
                void getLoopIterations(QString loopname,int&iterations);
                
                /**connect this to return a specific instance of a loop internal variable; should return empty string if the request is not valid*/
-               void getLoopVariable(QString loopname,int iteration,QString varname,int addval,QString&value);
+               void getLoopVariable(QString loopname,int iteration,QString varname,MOdtRenderer::VarType&,QVariant&value);
        
        protected:
-               QString getVariable(QString varname,int addval);
+               QVariant getVariable(QString varname,MOdtRenderer::VarType&);
                int getLoopIterations(QString loopname);
-               QString getLoopVariable(QString loopname,int iteration,QString varname,int addval);
+               QVariant getLoopVariable(QString loopname,int iteration,QString varname,MOdtRenderer::VarType&);
 };
 
 #endif
index 852ac67..3713b93 100644 (file)
@@ -826,6 +826,12 @@ int MTicket::amountToPay()const
        else return 0;
 }
 
+bool MTicket::isToBePaid()const
+{
+       if(m_status==Bought || m_status==Used)return true;
+       else return false;
+}
+
 
 /******************************************************************************
  * Voucher
index cf02525..be58101 100644 (file)
@@ -59,6 +59,9 @@ class MTicket
                /**returns the amount that is to be paid for this ticket; this is identical to the price if the ticket is bought or used, it is zero otherwise*/
                int amountToPay()const;
                
+               /**returns whether the ticket is to be paid (ie. it is bought or already used)*/
+               bool isToBePaid()const;
+               
                /**returns the ID of the event the ticket belongs to*/
                qint32 eventID()const;
                
index 0b8bc4e..fd27ac8 100644 (file)
@@ -341,9 +341,9 @@ void MOrderWindow::printBill()
        //print bill
        initPrintBuffer();
        MOdtSignalRenderer rend(tf);
-       connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
+       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,int,QString&)),this,SLOT(getLoopVariable(QString,int,QString,int,QString&)));
+       connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
        rend.renderToPrinter();
        donePrintBuffer();
 }
@@ -379,37 +379,81 @@ void MOrderWindow::saveBill()
        //render bill
        initPrintBuffer();
        MOdtSignalRenderer rend(tf);
-       connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
+       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,int,QString&)),this,SLOT(getLoopVariable(QString,int,QString,int,QString&)));
+       connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)),this,SLOT(getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&)));
        rend.renderToFile(fname);
        donePrintBuffer();
 }
 
-void MOrderWindow::getVariable(QString vn,int av,QString&value)
+void MOrderWindow::getVariable(QString vn,MOdtRenderer::VarType& av,QVariant&value)
 {
-       if(vn=="ORDERDATE")value=m_order.orderDateStr();else
-       if(vn=="ORDERDATETIME")value=m_order.orderDateTimeStr();else
-       if(vn=="SENTDATE")value=m_order.sentDateStr();else
-       if(vn=="SENTDATETIME")value=m_order.sentDateTimeStr();else
+       if(vn=="ORDERDATE"){
+               value=m_order.orderDateTime().toTime_t();
+               av=MOdtRenderer::DateVar;
+       }else
+       if(vn=="ORDERDATETIME"){
+               value=m_order.orderDateTime().toTime_t();
+               av=MOdtRenderer::DateTimeVar;
+       }else
+       if(vn=="SENTDATE"){
+               value=m_order.sentDateTime().toTime_t();
+               av=MOdtRenderer::DateVar;
+       }else
+       if(vn=="SENTDATETIME"){
+               value=m_order.sentDateTime().toTime_t();
+               av=MOdtRenderer::DateTimeVar;
+       }else
        if(vn=="CUSTOMERID")value=QString::number(m_order.customerID());else
        if(vn=="ORDERID")value=QString::number(m_order.orderID());else
        if(vn=="ADDRESS")value=m_order.customer().address();else
        if(vn=="FULLADDRESS")value=m_order.customer().getNameAddress();else
        if(vn=="NAME")value=m_order.customer().name();else
        if(vn=="DELIVERYADDRESS")value=m_order.deliveryAddress();else
-       if(vn=="TOTALPRICE")value=m_order.totalPriceString(av);else
-       if(vn=="AMOUNTPAID")value=m_order.amountPaidString(av);else
+       if(vn=="FINALADDRESS"){
+               QString v=m_order.deliveryAddress();
+               if(v.trimmed()=="")v=m_order.customer().getNameAddress();
+               value=v;
+       }else
+       if(vn=="TOTALPRICE"){
+               value=m_order.totalPrice();
+               av=MOdtRenderer::MoneyVar;
+       }else
+       if(vn=="AMOUNTPAID"){
+               value=m_order.amountPaid();
+               av=MOdtRenderer::MoneyVar;
+       }else
        if(vn=="SELLER")value=m_order.seller();else
        if(vn=="COMMENT")value=m_order.comment();else
-       if(vn=="AMOUNTTOPAY")value=m_order.amountToPayStr(av);else
-       if(vn=="AMOUNTTOREFUND")value=m_order.amountToRefundStr(av);else
-       if(vn=="TICKETS")value=QString::number(printBuffer.tickets.size()+av);else
-       if(vn=="ACCTICKETS")value=QString::number(printBuffer.tickinfo.size()+av);else
-       if(vn=="VOUCHERS")value=QString::number(printBuffer.vouchers.size()+av);else
-       if(vn=="ADDRESSLINES")value=QString::number(m_order.customer().address().split("\n").size()+av);else
+       if(vn=="AMOUNTTOPAY"){
+               value=m_order.amountToPay();
+               av=MOdtRenderer::MoneyVar;
+       }else
+       if(vn=="AMOUNTTOREFUND"){
+               value=m_order.amountToRefund();
+               av=MOdtRenderer::MoneyVar;
+       }else
+       if(vn=="TICKETS"){
+               value=printBuffer.tickets.size();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(vn=="ACCTICKETS"){
+               value=printBuffer.tickinfo.size();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(vn=="VOUCHERS"){
+               value=printBuffer.vouchers.size();
+               av=MOdtRenderer::IntVar;
+       }else
+       if(vn=="ADDRESSLINES"){
+               value=m_order.customer().address().split("\n").size();
+               av=MOdtRenderer::IntVar;
+       }else
        if(vn=="SHIPPING")value=m_order.shipping().description();else
-       if(vn=="SHIPPINGPRICE")value=m_order.shipping().priceString(av);
+       if(vn=="SHIPPINGPRICE"){
+               value=m_order.shipping().price();
+               av=MOdtRenderer::MoneyVar;
+       }
 }
 
 void MOrderWindow::getLoopIterations(QString loopname,int&iterations)
@@ -419,38 +463,74 @@ void MOrderWindow::getLoopIterations(QString loopname,int&iterations)
        if(loopname=="VOUCHERS")iterations=printBuffer.vouchers.size();
        if(loopname=="ADDRESSLINES")iterations=m_order.customer().address().split("\n").size();
 }
-void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,int av,QString&value)
+void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,MOdtRenderer::VarType& av,QVariant&value)
 {
        if(loopname=="TICKETS"){
                QList<MTicket> &tickets=printBuffer.tickets;
                if(it<0 || it>=tickets.size())return;
                
-               if(vn=="PRICE")value=tickets[it].priceString(av);else
+               if(vn=="PRICE"){
+                       value=tickets[it].price();
+                       av=MOdtRenderer::MoneyVar;
+               }else
                if(vn=="ID")value=tickets[it].ticketID();else
                if(vn=="TITLE")value=tickets[it].event().title();else
                if(vn=="ARTIST")value=tickets[it].event().artist();else
-               if(vn=="DATE")value=tickets[it].event().startDateString();else
-               if(vn=="STARTTIME")value=tickets[it].event().startTimeString();else
-               if(vn=="ENDTIME")value=tickets[it].event().endTimeString();else
+               if(vn=="DATE"){
+                       value=tickets[it].event().startTime();
+                       av=MOdtRenderer::DateVar;
+               }else
+               if(vn=="STARTTIME"){
+                       value=tickets[it].event().startTime();
+                       av=MOdtRenderer::DateTimeVar;
+               }else
+               if(vn=="ENDTIME"){
+                       value=tickets[it].event().endTime();
+                       av=MOdtRenderer::DateTimeVar;
+               }else
                if(vn=="ROOM")value=tickets[it].event().room();
        }else if(loopname=="ACCTICKETS"){
                QList<TickInfo> &tickets=printBuffer.tickinfo;
                if(it<0 || it>=tickets.size())return;
                
-               if(vn=="PRICE")value=tickets[it].proto.priceString(av);else
-               if(vn=="FULLPRICE")value=cent2str(tickets[it].proto.price()*tickets[it].amount+av);else
+               if(vn=="PRICE"){
+                       value=tickets[it].proto.price();
+                       av=MOdtRenderer::MoneyVar;
+               }else
+               if(vn=="FULLPRICE"){
+                       value=tickets[it].proto.price()*tickets[it].amount;
+                       av=MOdtRenderer::MoneyVar;
+               }else
                if(vn=="TITLE")value=tickets[it].proto.event().title();else
                if(vn=="ARTIST")value=tickets[it].proto.event().artist();else
-               if(vn=="DATE")value=tickets[it].proto.event().startDateString();else
-               if(vn=="STARTTIME")value=tickets[it].proto.event().startTimeString();else
-               if(vn=="ENDTIME")value=tickets[it].proto.event().endTimeString();else
+               if(vn=="DATE"){
+                       value=tickets[it].proto.event().startTime();
+                       av=MOdtRenderer::DateVar;
+               }else
+               if(vn=="STARTTIME"){
+                       value=tickets[it].proto.event().startTime();
+                       av=MOdtRenderer::DateTimeVar;
+               }else
+               if(vn=="ENDTIME"){
+                       value=tickets[it].proto.event().endTime();
+                       av=MOdtRenderer::DateTimeVar;
+               }else
                if(vn=="ROOM")value=tickets[it].proto.event().room();else
-               if(vn=="AMOUNT")value=QString::number(tickets[it].amount+av);
+               if(vn=="AMOUNT"){
+                       value=tickets[it].amount;
+                       av=MOdtRenderer::IntVar;
+               }
        }else if(loopname=="VOUCHERS"){
                if(it<0 || it>=printBuffer.vouchers.size())return;
                
-               if(vn=="PRICE")value=printBuffer.vouchers[it].priceString(av);else
-               if(vn=="VALUE")value=printBuffer.vouchers[it].valueString(av);else
+               if(vn=="PRICE"){
+                       value=printBuffer.vouchers[it].price();
+                       av=MOdtRenderer::MoneyVar;
+               }else
+               if(vn=="VALUE"){
+                       value=printBuffer.vouchers[it].value();
+                       av=MOdtRenderer::MoneyVar;
+               }else
                if(vn=="ID")value=printBuffer.vouchers[it].voucherID();
        }else if(loopname=="ADDRESSLINES"){
                QStringList lst=m_order.customer().address().split("\n");
index 3a1467c..8574f98 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <QMainWindow>
 #include "order.h"
+#include "odtrender.h"
 
 class QLabel;
 class QTableView;
@@ -61,11 +62,11 @@ class MOrderWindow:public QMainWindow
                /**save the bill as file*/
                void saveBill();
                /**callback for bill generator: variables; see MOdtSignalRenderer for details*/
-               void getVariable(QString varname,int,QString&value);
+               void getVariable(QString,MOdtRenderer::VarType&,QVariant&);
                /**callback for bill generator: loops; see MOdtSignalRenderer for details*/
                void getLoopIterations(QString loopname,int&iterations);
                /**callback for bill generator: loop variables; see MOdtSignalRenderer for details*/
-               void getLoopVariable(QString loopname,int iteration,QString varname,int,QString&value);
+               void getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&);
 
                /**received payment*/
                void payment();
index d441ed0..8f66e20 100644 (file)
@@ -327,6 +327,7 @@ function getEventSummaryXml($evid)
        $tcused=array();
        $tcall=array();
        $oids=array();
+       $soids="";
        foreach($res as $tc){
                switch($tc["status"]){
                        case TICKET_RESERVED:$tcreserve++;break;
@@ -356,8 +357,10 @@ function getEventSummaryXml($evid)
                                $total++;
                                break;
                }
-               if($tc["orderid"]!==false && !in_array($tc["orderid"],$oids))
+               if($tc["orderid"]!==false && !in_array($tc["orderid"],$oids)){
                        $oids[]=$tc["orderid"];
+                       $soids.=" ".$tc["orderid"];
+               }
        }
        //get comments
        sort($oids);
@@ -402,6 +405,7 @@ function getEventSummaryXml($evid)
                $p->appendChild($xml->createTextNode($comment["cm"]));
                $doc->appendChild($p);
        }
+       $doc->appendChild($xml->createElement("Orders",trim($soids)));
        $xml->appendChild($doc);
        header("X-MagicSmoke-Status: Ok");
        print($xml->saveXml());
index 25dd38f..6589908 100644 (file)
@@ -13,7 +13,7 @@
 //minimum version that the server understands (4 hex digits)
 defversion(MINSERVER,0000)
 //current version of the server
-defversion(CURSERVER,0003)
+defversion(CURSERVER,0004)
 
 //current human readable version of the server
 defversion(HRSERVER,0.2 beta)
@@ -21,7 +21,7 @@ defversion(HRSERVER,0.2 beta)
 //minimum version that the client requires
 defversion(MINCLIENT,0000)
 //current version of the client
-defversion(CURCLIENT,0003)
+defversion(CURCLIENT,0004)
 
 //current human readable version of the client
 defversion(HRCLIENT,0.2 beta)