//
#include "odtrender.h"
+#include "misc.h"
#include <QDir>
#include <QFile>
protected:
friend class MOdtRenderer;
+ //methods that the parent uses
MOdtRendererPrivate(QString file,MOdtRenderer*p);
~MOdtRendererPrivate();
void render(QIODevice*);
QString render(QString);
+
+ //data the parent uses
+ QString extension;
+
+ private:
+ //methods that the parent does not call
QString renderLine(QString,QString,int);
QString getVariable(QString varname);
QString getLoopVariable(QString loopname,int iteration,QString varname);
- private:
+ //data the parent does not access
MOdtRenderer*parent;
QUnZip temp;
QFile tfile;
MOdtRenderer::MOdtRenderer(MTemplate file)
{
d=new MOdtRendererPrivate(file.cacheFileName(),this);
+ d->extension=file.targetExtension();
}
MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p)
//generate temporary file
QTemporaryFile tfile;
tfile.setAutoRemove(false);
- tfile.setFileTemplate(QDir::tempPath()+"/msmoke_XXXXXX.odt");
+ tfile.setFileTemplate(QDir::tempPath()+"/msmoke_XXXXXX."+d->extension);
tfile.open();
QString tname=tfile.fileName();
//render
//or any loop at all...
if(loop!="" && loop==vl[0]){
//get value
- ret+=getLoopVariable(loop,lpos,vl[1]);
+ ret+=xmlize(getLoopVariable(loop,lpos,vl[1]));
}
}else
//this is a normal variable, get valie
- ret+=getVariable(vname);
+ ret+=xmlize(getVariable(vname));
}
//reset mode
isvar=false;
//
//
-#include "orderwin.h"
#include "event.h"
-#include "webrequest.h"
-#include "ticketrender.h"
#include "labeldlg.h"
+#include "misc.h"
#include "odtrender.h"
+#include "orderwin.h"
+#include "ticketrender.h"
+#include "webrequest.h"
#include <QApplication>
#include <QBoxLayout>
m_sentdate->setText(m_order.sentDateTimeStr());
}
//print bill
+ initPrintBuffer();
MOdtSignalRenderer rend(tf);
connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
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&)));
rend.renderToPrinter();
+ donePrintBuffer();
}
void MOrderWindow::saveBill()
//get template
MTemplate tf=req->getTemplate("bill");
if(!tf.isValid()){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary). Giving up."));
+ QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (bill). Giving up."));
return;
}
//get target file name
m_sentdate->setText(m_order.sentDateTimeStr());
}
//render bill
+ initPrintBuffer();
MOdtSignalRenderer rend(tf);
connect(&rend,SIGNAL(getVariable(QString,int,QString&)),this,SLOT(getVariable(QString,int,QString&)));
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&)));
rend.renderToFile(fname);
+ donePrintBuffer();
}
void MOrderWindow::getVariable(QString vn,int av,QString&value)
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(m_model->rowCount()+av);
- if(vn=="ADDRESSLINES")value=QString::number(m_order.customer().address().split("\n").size()+av);
+ 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=="SHIPPING")value=m_order.shipping().description();else
+ if(vn=="SHIPPINGPRICE")value=m_order.shipping().priceString(av);
}
void MOrderWindow::getLoopIterations(QString loopname,int&iterations)
{
- if(loopname=="TICKETS")iterations=m_model->rowCount();
+ if(loopname=="TICKETS")iterations=printBuffer.tickets.size();
+ if(loopname=="ACCTICKETS")iterations=printBuffer.tickinfo.size();
+ 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)
{
if(loopname=="TICKETS"){
- if(it<0 || it>=m_model->rowCount())return;
-
- QList<MTicket>tickets=m_order.tickets();
+ QList<MTicket> &tickets=printBuffer.tickets;
+ if(it<0 || it>=tickets.size())return;
if(vn=="PRICE")value=tickets[it].priceString(av);else
if(vn=="ID")value=tickets[it].ticketID();else
if(vn=="STARTTIME")value=tickets[it].event().startTimeString();else
if(vn=="ENDTIME")value=tickets[it].event().endTimeString();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=="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=="ROOM")value=tickets[it].proto.event().room();else
+ if(vn=="AMOUNT")value=QString::number(tickets[it].amount+av);
+ }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=="ID")value=printBuffer.vouchers[it].voucherID();
}else if(loopname=="ADDRESSLINES"){
QStringList lst=m_order.customer().address().split("\n");
if(it<0 || it>=lst.size())return;
return /*empty handed*/;
}
+void MOrderWindow::donePrintBuffer()
+{
+ printBuffer.tickets.clear();
+ printBuffer.vouchers.clear();
+ printBuffer.tickinfo.clear();
+}
+
+static inline bool compare(const MTicket&a,const MTicket&b)
+{
+ if(a.eventID()!=b.eventID())return false;
+ if(a.price()!=b.price())return false;
+ return true;
+}
+
+void MOrderWindow::initPrintBuffer()
+{
+ //clear
+ donePrintBuffer();
+ //get tickets (only valid ones)
+ QList<MTicket>tlst=m_order.tickets();
+ for(int i=0;i<tlst.size();i++)
+ if(tlst[i].isValid())
+ printBuffer.tickets.append(tlst[i]);
+ //accumulated view on tickets
+ for(int i=0;i<printBuffer.tickets.size();i++){
+ MTicket t=printBuffer.tickets[i];
+ bool found=false;
+ for(int j=0;j<printBuffer.tickinfo.size();j++){
+ if(compare(printBuffer.tickinfo[j].proto,t)){
+ found=true;
+ printBuffer.tickinfo[j].amount++;
+ break;
+ }
+ }
+ if(!found)printBuffer.tickinfo.append(t);
+ }
+ //get valid vouchers
+ QList<MVoucher>vlst=m_order.vouchers();
+ for(int i=0;i<vlst.size();i++)
+ if(!vlst[i].isCancelled())
+ printBuffer.vouchers.append(vlst[i]);
+}
+
void MOrderWindow::payment()
{
if(!m_order.isValid())return;