From: konrad Date: Sat, 29 Nov 2008 17:26:00 +0000 (+0000) Subject: render orders according to new capabilities (added voucher + shipping) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a4447bd998f82fed8615c8ecfa42fda8e02cd7ae;p=web%2Fkonrad%2Fsmoke.git render orders according to new capabilities (added voucher + shipping) git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@204 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/misc.cpp b/src/misc.cpp index 7f23964..c5c60ce 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -30,6 +30,20 @@ QString htmlize(QString str) return out; } +QString xmlize(QString str) +{ + QString out; + for(int i=0;i')out+=">";else + if(c=='&')out+="&";else + if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c; + else out+="&#"+QString::number(ci)+";"; + } + return out; +} QString cent2str(int c) { QString ret=QCoreApplication::translate("misc","%1.%2","price with decimal dot"); diff --git a/src/misc.h b/src/misc.h index 8062066..a816068 100644 --- a/src/misc.h +++ b/src/misc.h @@ -19,6 +19,9 @@ /**converts special HTML characters into harmless &-codes, so the text can be included*/ QString htmlize(QString str); +/**converts special XML characters into harmless &-codes, so the text can be included*/ +QString xmlize(QString str); + /**converts a cent value into a localized string*/ QString cent2str(int c); diff --git a/src/odtrender.cpp b/src/odtrender.cpp index 85972ba..15da178 100644 --- a/src/odtrender.cpp +++ b/src/odtrender.cpp @@ -11,6 +11,7 @@ // #include "odtrender.h" +#include "misc.h" #include #include @@ -31,18 +32,25 @@ class MOdtRendererPrivate 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; @@ -51,6 +59,7 @@ class MOdtRendererPrivate MOdtRenderer::MOdtRenderer(MTemplate file) { d=new MOdtRendererPrivate(file.cacheFileName(),this); + d->extension=file.targetExtension(); } MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p) @@ -97,7 +106,7 @@ void MOdtRenderer::renderToPrinter() //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 @@ -228,11 +237,11 @@ QString MOdtRendererPrivate::renderLine(QString line,QString loop,int lpos) //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; diff --git a/src/order.cpp b/src/order.cpp index 57b7f30..852ac67 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -889,9 +889,9 @@ MVoucher& MVoucher::operator=(const MVoucher&v) QString MVoucher::voucherID()const{return m_id;} int MVoucher::price()const{return m_price;} -QString MVoucher::priceString()const{return cent2str(m_price);} +QString MVoucher::priceString(int off)const{return cent2str(m_price+off);} int MVoucher::value()const{return m_value;} -QString MVoucher::valueString()const{return cent2str(m_value);} +QString MVoucher::valueString(int off)const{return cent2str(m_value+off);} bool MVoucher::isValid()const{return req!=0 && m_id!="";} diff --git a/src/order.h b/src/order.h index 1c8a4bd..cf02525 100644 --- a/src/order.h +++ b/src/order.h @@ -180,11 +180,11 @@ class MVoucher /**returns the price in cent of the voucher (what it costs)*/ int price()const; /**returns the price of the voucher as string*/ - QString priceString()const; + QString priceString(int off=0)const; /**returns the remaining value in cent of the voucher (what it is worth)*/ int value()const; /**returns the remaining value of the voucher as string*/ - QString valueString()const; + QString valueString(int off=0)const; /**returns whether this is a valid voucher object*/ bool isValid()const; diff --git a/src/orderwin.cpp b/src/orderwin.cpp index c6b3ee2..0b8bc4e 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -10,12 +10,13 @@ // // -#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 #include @@ -338,11 +339,13 @@ void MOrderWindow::printBill() 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() @@ -350,7 +353,7 @@ 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 @@ -374,11 +377,13 @@ void MOrderWindow::saveBill() 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) @@ -399,21 +404,26 @@ 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; - - QListtickets=m_order.tickets(); + QList &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 @@ -423,6 +433,25 @@ void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,int av,QSt 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 &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; @@ -431,6 +460,49 @@ void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,int av,QSt 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) + QListtlst=m_order.tickets(); + for(int i=0;ivlst=m_order.vouchers(); + for(int i=0;i tickets; + QList vouchers; + QList tickinfo; + }printBuffer; + void initPrintBuffer(); + void donePrintBuffer(); }; class MTicketRenderer; diff --git a/src/shipping.cpp b/src/shipping.cpp index 22e7521..1476a45 100644 --- a/src/shipping.cpp +++ b/src/shipping.cpp @@ -10,6 +10,7 @@ // // +#include "misc.h" #include "shipping.h" #include "webrequest.h" @@ -70,9 +71,9 @@ bool MShipping::isValid()const int MShipping::id()const{return m_id;} int MShipping::price()const{return m_price;} -QString MShipping::priceString()const +QString MShipping::priceString(int off)const { - return QString::number(m_price/100)+QCoreApplication::translate("MShipping",".","decimal dot")+QString().sprintf("%02d",m_price%100); + return cent2str(m_price+off); } bool MShipping::webUsable()const{return m_web;} diff --git a/src/shipping.h b/src/shipping.h index 2587dcc..f0be5b4 100644 --- a/src/shipping.h +++ b/src/shipping.h @@ -42,7 +42,7 @@ class MShipping int price()const; /**returns the price as string*/ - QString priceString()const; + QString priceString(int off=0)const; /**returns whether the type is usable via web interface*/ bool webUsable()const; diff --git a/src/templates.cpp b/src/templates.cpp index 6da43bd..f0bd492 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -89,6 +89,8 @@ void MTemplateStore::updateTemplates(bool force) QString dname=req->dataDir()+"/templates/"; QSettings set; set.beginGroup("templates/"+profileid); + //make sure directory exists + QDir(req->dataDir()).mkpath("templates"); //do we need an update yet? QDateTime last=QDateTime::fromTime_t(set.value("lastupdate",0).toInt()+300); if(last>=QDateTime::currentDateTime() && !force)return;