print bills
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 29 Mar 2008 08:22:32 +0000 (08:22 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 29 Mar 2008 08:22:32 +0000 (08:22 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@145 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

doc/prog_odttemplate.html
examples/bill.odtt [new file with mode: 0644]
src/event.cpp
src/event.h
src/eventsummary.cpp
src/order.cpp
src/order.h
src/orderwin.cpp
src/orderwin.h

index 95c59c1..79903cc 100644 (file)
@@ -56,7 +56,7 @@ Loops cannot be nested.
 
 File name: <tt>eventsummary.odtt</tt><p>
 
-Loop: <tt>TICKETS</tt> - this loop iterated over the ticket price categories.<p>
+Loop: <tt>TICKETS</tt> - this loop iterates over the ticket price categories.<p>
 
 Variables:
 <table frame="1" border="1">
@@ -71,6 +71,7 @@ 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:PRICE@</td><td>the price of this category</td></tr>
 <tr><td>@TICKETS:BOUGHT@</td><td>used+unused</td></tr>
@@ -78,4 +79,42 @@ Variables:
 <tr><td>@TICKETS:UNUSED@</td><td>tickets from this category that were not used</td></tr>
 </table>
 
+<h2>Order Bills</h2>
+
+File name: <tt>bill.odtt</tt><p>
+
+Loop: <tt>TICKETS</tt> - this loop iterates over each ticket in the order.<p>
+
+(TODO: loop for vouchers)<p>
+
+Variables:
+<table frame="1" border="1">
+<tr><td><b>Variable</b></td><td><b>Description</b></td></tr>
+<tr><td>@ORDERDATE@</td><td>the date when this order has been generated</td></tr>
+<tr><td>@ORDERDATETIME@</td><td>the date and time when this order has been generated</td></tr>
+<tr><td>@SENTDATE@</td><td>the date when this order has been shipped</td></tr>
+<tr><td>@SENTDATETIME@</td><td>the date and time when this order has been shipped</td></tr>
+<tr><td>@CUSTOMERID@</td><td>the ID of the customer</td></tr>
+<tr><td>@ORDERID@</td><td>the ID of the order</td></tr>
+<tr><td>@ADDRESS@</td><td>the address 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>@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/>
+<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>
+<tr><td>@TICKETS:ARTIST@</td><td>the artist of the event for this ticket</td></tr>
+<tr><td>@TICKETS:DATE@</td><td>the date of the event for this ticket</td></tr>
+<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>
+</table>
+
+
 </html>
\ No newline at end of file
diff --git a/examples/bill.odtt b/examples/bill.odtt
new file mode 100644 (file)
index 0000000..280dcb8
Binary files /dev/null and b/examples/bill.odtt differ
index 05abff0..fbbadcd 100644 (file)
@@ -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"));
index 2d3dea6..9d96c3f 100644 (file)
@@ -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;}
index b1fe305..d362240 100644 (file)
@@ -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)
index 5b9005c..fbdebf2 100644 (file)
@@ -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
index 9a1e3ba..186fd9a 100644 (file)
@@ -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;
                
index df1a164..c93c804 100644 (file)
 #include "webrequest.h"
 #include "ticketrender.h"
 #include "labeldlg.h"
+#include "odtrender.h"
 
 #include <QBoxLayout>
 #include <QComboBox>
+#include <QFileDialog>
 #include <QGridLayout>
 #include <QLabel>
 #include <QMenu>
@@ -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<MTicket> 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;
+       
+       QList<MTicket>tickets=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();
+}
+
 
 /*************************************************************************************/
 
index 3eb8e16..6711807 100644 (file)
@@ -47,6 +47,18 @@ class MOrderWindow:public QMainWindow
                void printTickets();
                /**internal helper: print list of tickets*/
                void printTickets(QList<MTicket>);
+               
+               /**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;