Skip to content

Commit

Permalink
add orders details report
Browse files Browse the repository at this point in the history
  • Loading branch information
WajdyEssam committed Aug 11, 2012
1 parent 814fb63 commit 91db50e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
53 changes: 35 additions & 18 deletions MangoReports/ordersdetailsreport.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "ordersdetailsreport.h"

#include "../MangoModel/event.h"
#include "../MangoService/event.h"
#include "../MangoModel/orderdetail.h"
#include "../MangoModel/order.h"
#include "../MangoService/orderdetail.h"
#include "../MangoService/order.h"
#include "../MangoService/helper.h"

#include <QDebug>

OrdersDetailsReport::OrdersDetailsReport(const QDateTime& from, const QDateTime& to)
Expand All @@ -26,26 +30,39 @@ QString OrdersDetailsReport::getReportTemplateName()
QString OrdersDetailsReport::getTableData()
{
QString tableBegin = "<table width=\"100%\" cellspacing=\"1\"><tbody>"
"<tr><th>Id</th><th>Username</th><th>Date</th><th>Actions</th></tr>";
"<tr class=\"table_header\"><th>رقم العملية</th><th>رقم الطلب</th><th>اسم الصنف</th><th>الكمية</th>"
"<th>المكونات</th><th>الاضافات</th><th>السكر</th><th>الاجمالي</th></tr>";
QString tableEnd = "</tbody></table>";

QString htmlTableResult = tableBegin;

QList<Model::Event> events = Services::Event::getAll();
foreach(Model::Event event, events) {
Model::Event::EventTypes type = event.eventType();
QString eventType = type == Model::Event::Login ? "Loggin" : " Logout";

QString tableRaw = QString(
"<tr valign=\"top\"> "
"<td align=\"center\"><font size=\"2\">%1</font></td> "
"<td align=\"center\"><font size=\"2\">%2</font></td> "
"<td align=\"center\"><font size=\"2\">%3</font></td> "
"<td align=\"center\"><font size=\"2\">%4</font></td> "
"</tr>"
).arg( QString::number(event.id()), event.user().userName(), event.createdDateTime().toString(), eventType);

htmlTableResult += tableRaw ;
QList<Model::Order> orders = Services::Order::getAll();
foreach(Model::Order order, orders) {
QList<Model::OrderDetail> details = Services::OrderDetail::getByOrderId(order.id());
foreach(Model::OrderDetail detail, details) {
QString tableRaw = QString(
"<tr valign=\"top\"> "
"<td align=\"center\"><font size=\"2\">%1</font></td> "
"<td align=\"center\"><font size=\"2\">%2</font></td> "
"<td align=\"center\"><font size=\"2\">%3</font></td> "
"<td align=\"center\"><font size=\"2\">%4</font></td> "
"<td align=\"center\"><font size=\"2\">%5</font></td> "
"<td align=\"center\"><font size=\"2\">%6</font></td> "
"<td align=\"center\"><font size=\"2\">%7</font></td> "
"<td align=\"center\"><font size=\"2\">%8</font></td> "
"</tr>"
).arg( QString::number(detail.id()),
QString::number(detail.order().id()),
detail.itemDetail().item().arabicName(),
QString::number(detail.qunatity()),
Services::Helper::fromComponentsToText(detail.components()),
Services::Helper::fromAdditionalsToText(detail.additionals()),
QString::number(detail.sugar()),
QString::number(detail.cash())
);

htmlTableResult += tableRaw ;
}
}

htmlTableResult += tableEnd;
Expand Down
30 changes: 30 additions & 0 deletions MangoService/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,34 @@ QString Helper::fromListToText(QStringList ids)
return commaSeparatedId;
}

QString Helper::fromComponentsToText(QList<Model::Component> components)
{
QString commaSeparatedText = "";

for(int i=0; i<components.size(); i++) {
commaSeparatedText += components.at(i).arabicName();

if ( i < components.size() - 1 ) {
commaSeparatedText += ",";
}
}

return commaSeparatedText;
}

QString Helper::fromAdditionalsToText(QList<Model::Additional> additionals)
{
QString commaSeparatedText = "";

for(int i=0; i<additionals.size(); i++) {
commaSeparatedText += additionals.at(i).arabicName();

if ( i < additionals.size() - 1 ) {
commaSeparatedText += ",";
}
}

return commaSeparatedText;
}

}
5 changes: 5 additions & 0 deletions MangoService/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#include <QList>
#include <QStringList>

#include "MangoService_global.h"
#include "../MangoModel/component.h"
#include "../MangoModel/additional.h"

namespace Services {

Expand All @@ -12,6 +15,8 @@ class MANGOSERVICESHARED_EXPORT Helper
public:
static QStringList fromTextToList(QString text);
static QString fromListToText(QStringList ids);
static QString fromComponentsToText(QList<Model::Component> components);
static QString fromAdditionalsToText(QList<Model::Additional> additionals);
};

}
Expand Down

0 comments on commit 91db50e

Please sign in to comment.