From: konrad Date: Sat, 29 Mar 2008 08:22:32 +0000 (+0000) Subject: print bills X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=3b0598369897708ed59120c7628eb22dd5079faa;p=web%2Fkonrad%2Fsmoke.git print bills git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@145 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/doc/prog_odttemplate.html b/doc/prog_odttemplate.html index 95c59c1..79903cc 100644 --- a/doc/prog_odttemplate.html +++ b/doc/prog_odttemplate.html @@ -56,7 +56,7 @@ Loops cannot be nested. File name: eventsummary.odtt

-Loop: TICKETS - this loop iterated over the ticket price categories.

+Loop: TICKETS - this loop iterates over the ticket price categories.

Variables: @@ -71,6 +71,7 @@ Variables: + @@ -78,4 +79,42 @@ Variables:
@UNUSED@tickets that are still unused
@CANCELLED@tickets that were cancelled
@TOTALMONEY@the total amount of income for this event
@TICKETS@the amount of ticket lines in the overview
@TICKETS:PRICE@the price of this category
@TICKETS:BOUGHT@used+unused
@TICKETS:UNUSED@tickets from this category that were not used
+

Order Bills

+ +File name: bill.odtt

+ +Loop: TICKETS - this loop iterates over each ticket in the order.

+ +(TODO: loop for vouchers)

+ +Variables: + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableDescription
@ORDERDATE@the date when this order has been generated
@ORDERDATETIME@the date and time when this order has been generated
@SENTDATE@the date when this order has been shipped
@SENTDATETIME@the date and time when this order has been shipped
@CUSTOMERID@the ID of the customer
@ORDERID@the ID of the order
@ADDRESS@the address of the customer
@DELIVERYADDRESS@the address it is shipped to, if different from the customers address
@TOTALPRICE@the total price of the order
@AMOUNTPAID@the amount that has already been paid
@SELLER@the login ID of the seller (it is not recommended to use this)
@COMMENT@the comment in the order (it is not recommended to use this)
@AMOUNTTOPAY@the amount that still needs to be paid
@AMOUNTTOREFUND@the amount that has to be refunded
@TICKETS@the amount of tickets in the order
@TICKETS:PRICE@the price of this ticket
@TICKETS:ID@the ID of this ticket (barcode-string)
@TICKETS:TITLE@the title of the event for this ticket
@TICKETS:ARTIST@the artist of the event for this ticket
@TICKETS:DATE@the date of the event for this ticket
@TICKETS:STARTTIME@the date and start time of the event for this ticket
@TICKETS:ENDTIME@the end date and time of the event for this ticket
@TICKETS:ROOM@the room/place of the event for this ticket
+ + \ No newline at end of file diff --git a/examples/bill.odtt b/examples/bill.odtt new file mode 100644 index 0000000..280dcb8 Binary files /dev/null and b/examples/bill.odtt differ diff --git a/src/event.cpp b/src/event.cpp index 05abff0..fbbadcd 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -256,6 +256,11 @@ QString MEvent::startTimeString()const return QDateTime::fromTime_t(m_starttime).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); } +QString MEvent::startDateString()const +{ + return QDateTime::fromTime_t(m_starttime).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd","date format")); +} + QString MEvent::endTimeString()const { return QDateTime::fromTime_t(m_endtime).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); diff --git a/src/event.h b/src/event.h index 2d3dea6..9d96c3f 100644 --- a/src/event.h +++ b/src/event.h @@ -57,6 +57,8 @@ class MEvent int endTime()const{return m_endtime;} /**returns the start time of the event as localized string*/ QString startTimeString()const; + /**returns the start date as localized string*/ + QString startDateString()const; /**returns the end time of the event as localized string*/ QString endTimeString()const; /**returns the room of the event, the room must be one out of the list of valid rooms*/ @@ -88,7 +90,7 @@ class MEvent /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ bool isValid()const{return m_valid;} - /**returns whether the event is complete - this depends on the amount of data sent by the server*/ + /**returns whether the data stored in this event object is complete - this depends on the amount of data sent by the server*/ bool isComplete()const{return m_complete;} /**forces the event to believe it is valid and complete; used for saving new events*/ void makeValid(){m_valid=true;m_complete=true;} diff --git a/src/eventsummary.cpp b/src/eventsummary.cpp index b1fe305..d362240 100644 --- a/src/eventsummary.cpp +++ b/src/eventsummary.cpp @@ -154,6 +154,11 @@ void MEventSummary::print() void MEventSummary::saveas() { + QString tf=req->getTemplate("eventsummary.odtt"); + if(tf==""){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary.odtt). Giving up.")); + return; + } QFileDialog fd(this); fd.setAcceptMode(QFileDialog::AcceptSave); fd.setFileMode(QFileDialog::AnyFile); @@ -166,7 +171,7 @@ void MEventSummary::saveas() if(fn.size()<1)return; fname=fn[0]; } - MOdtSignalRenderer rend("../examples/eventsummary.odtt"); + MOdtSignalRenderer rend(tf); connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&))); connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&))); connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,QString&)),this,SLOT(getLoopVariable(QString,int,QString,QString&))); @@ -210,6 +215,9 @@ void MEventSummary::getVariable(QString varname,QString&value) value=QString::number(ntotalmoney/100) +tr(".","decimal dot") +QString().sprintf("%02d",ntotalmoney%100); + else + if(varname=="TICKETS") + value=QString::number(tickets.size()); } void MEventSummary::getLoopIterations(QString loopname,int&iterations) diff --git a/src/order.cpp b/src/order.cpp index 5b9005c..fbdebf2 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -159,6 +159,16 @@ int MOrder::amountToRefund()const return 0; } +QString MOrder::amountToPayStr()const +{ + return cent2string(amountToPay()); +} + +QString MOrder::amountToRefundStr()const +{ + return cent2string(amountToRefund()); +} + bool MOrder::isSent()const { //only in placed mode there is a need for action, hence in all other modes we assume sent diff --git a/src/order.h b/src/order.h index 9a1e3ba..186fd9a 100644 --- a/src/order.h +++ b/src/order.h @@ -194,9 +194,15 @@ class MOrder /**returns how much there is to be paid, in cents*/ int amountToPay()const; + /**returns how much there is to be paid, as localized string*/ + QString amountToPayStr()const; + /**returns how much there is to be refunded, in cents*/ int amountToRefund()const; + /**returns how much there is to be refunded, as localized string*/ + QString amountToRefundStr()const; + /**returns whether the tickets of this order have already been shipped*/ bool isSent()const; diff --git a/src/orderwin.cpp b/src/orderwin.cpp index df1a164..c93c804 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -15,9 +15,11 @@ #include "webrequest.h" #include "ticketrender.h" #include "labeldlg.h" +#include "odtrender.h" #include #include +#include #include #include #include @@ -49,10 +51,10 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o) m->addAction(tr("Receive &Payment...")); m->addAction(tr("&Refund...")); m=mb->addMenu(tr("P&rinting")); - m->addAction(tr("Print &Bill...")); - m->addAction(tr("Save Bill &as file...")); + m->addAction(tr("Print &Bill..."),this,SLOT(printBill())); + m->addAction(tr("Save Bill &as file..."),this,SLOT(saveBill())); m->addSeparator(); - m->addAction(tr("Print &Tickets...")); + m->addAction(tr("Print &Tickets..."),this,SLOT(printTickets())); m->addAction(tr("Print &Current Ticket..."),this,SLOT(printCurrentTicket())); m->addAction(tr("&View Tickets..."),this,SLOT(ticketView())); @@ -183,6 +185,86 @@ void MOrderWindow::printTickets(QList tickets) } +void MOrderWindow::printBill() +{ + QString tf=req->getTemplate("bill.odtt"); + if(tf==""){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (bill.odtt). Giving up.")); + return; + } + MOdtSignalRenderer rend(tf); + connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&))); + connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&))); + connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,QString&)),this,SLOT(getLoopVariable(QString,int,QString,QString&))); + rend.renderToPrinter(); +} + +void MOrderWindow::saveBill() +{ + QString tf=req->getTemplate("eventsummary.odtt"); + if(tf==""){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary.odtt). Giving up.")); + return; + } + QFileDialog fd(this); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + fd.setConfirmOverwrite(true); + fd.setFilter("Open Document Text (*.odt)"); + fd.setDefaultSuffix("odt"); + QString fname; + if(fd.exec()){ + QStringList fn=fd.selectedFiles(); + if(fn.size()<1)return; + fname=fn[0]; + } + MOdtSignalRenderer rend(tf); + connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&))); + connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&))); + connect(&rend,SIGNAL(getLoopVariable(QString,int,QString,QString&)),this,SLOT(getLoopVariable(QString,int,QString,QString&))); + rend.renderToFile(fname); +} + +void MOrderWindow::getVariable(QString vn,QString&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=="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=="DELIVERYADDRESS")value=m_order.deliveryAddress();else + if(vn=="TOTALPRICE")value=m_order.totalPriceString();else + if(vn=="AMOUNTPAID")value=m_order.amountPaidString();else + if(vn=="SELLER")value=m_order.seller();else + if(vn=="COMMENT")value=m_order.comment();else + if(vn=="AMOUNTTOPAY")value=m_order.amountToPayStr();else + if(vn=="AMOUNTTOREFUND")value=m_order.amountToRefundStr();else + if(vn=="TICKETS")value=QString::number(m_ticketmodel->rowCount()); +} + +void MOrderWindow::getLoopIterations(QString loopname,int&iterations) +{ + if(loopname=="TICKETS")iterations=m_ticketmodel->rowCount(); +} +void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,QString&value) +{ + if(loopname!="TICKETS")return; + if(it<0 || it>=m_ticketmodel->rowCount())return; + + QListtickets=m_order.tickets(); + + if(vn=="PRICE")value=tickets[it].priceString();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=="ROOM")value=tickets[it].event().room(); +} + /*************************************************************************************/ diff --git a/src/orderwin.h b/src/orderwin.h index 3eb8e16..6711807 100644 --- a/src/orderwin.h +++ b/src/orderwin.h @@ -47,6 +47,18 @@ class MOrderWindow:public QMainWindow void printTickets(); /**internal helper: print list of tickets*/ void printTickets(QList); + + /**print a bill*/ + void printBill(); + /**save the bill as file*/ + void saveBill(); + /**callback for bill generator: variables; see MOdtSignalRenderer for details*/ + void getVariable(QString varname,QString&value); + /**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,QString&value); + private: MWebRequest*req;