DCL 4.0
Loading...
Searching...
No Matches
ViewSalesReport.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#if __DCL_WINDOWS
4#include <windows.h>
5#endif
6
7#include <dcl/DateTime.h>
8
9#include "EShopServlet.h"
10
11#ifdef __DCL_DEBUG
12#undef __THIS_FILE__
13static const wchar_t __THIS_FILE__[] = L"eshop/ViewSalesReport.cpp";
14#endif
15
16__DCL_BEGIN_NAMESPACE
17
18void EShopServlet::onViewSalesReport(
20 const EShopSession& session
21 )
22{
23 Writer& out = ctx.writer();
24 ListedStringToStringArrayMap& params = ctx.__queryMap;
25
26 TextTemplate tpl(readTemplate(L"view_sales_report.html"));
27 TextTemplate& row = tpl[L"ROW"];
28
29 tpl.assign(L"TODAY", DateTime::getCurrentLocalTime().date().toStringF(L"%Y-%m-%d"));
30
31 SQLQuery q(session.SQLConn());
32 q.execute(L""
33 "SELECT D.PRODUCT_ID, P.PRODUCT_NAME,"
34 " SUM(D.QUANTITY) AS QUANTITY, P.PRICE,"
35 " SUM(D.QUANTITY * P.PRICE) AS AMOUNT \n"
36 "FROM (ES_ORDER_DETAIL D \n"
37 " INNER JOIN ES_ORDER_MASTER M ON (D.ORDER_ID = M.ORDER_ID) \n"
38 " ) \n"
39 " INNER JOIN ES_PRODUCT P ON (D.PRODUCT_ID = P.PRODUCT_ID) \n"
40 "WHERE \n"
41 " CURRENT_DATE <= M.ORDER_DATETIME \n"
42 " AND M.ORDER_DATETIME < DATE_ADD(CURRENT_DATE, INTERVAL 1 DAY) \n"
43 "GROUP BY D.PRODUCT_ID "
44 );
45 q.fetch();
46 double fSum = 0.;
47 while(!q.eof())
48 {
49 double fAmount = 0.;
50 SQLField& f = q.fields().byName(L"AMOUNT");
51// out << f.dataTypeName();
52 f.getValue(fAmount);
53 fSum += fAmount;
54 row.assign(q.fields(), L"&nbsp;");
55 tpl.append(L"ROW", row);
56 q.fetch();
57 }
58 tpl.assign(L"TOTAL", String::valueOf(fSum));
59 out << tpl;
60}
61
62__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
static DateTime getCurrentLocalTime()
Definition DateTime.cpp:937
String readTemplate(const wchar_t *filename) const __DCL_THROWS1(IOException *)
SQLConnection * SQLConn() const
StringWriter & writer()