47
47
ui.kRefresh->setIcon(KIcon("view-refresh"));
48
48
ui.kPrint->setIcon(KIcon("printer"));
50
connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
50
connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
53
connect((const QObject*) getDocument(), SIGNAL(transactionSuccessfullyEnded(int)), this, SLOT(refresh()), Qt::QueuedConnection);
53
connect((const QObject*) getDocument(), SIGNAL(tableModified(QString, int)), this, SLOT(dataModified(QString, int)), Qt::QueuedConnection );
58
57
SKGMonthlyPluginWidget::~SKGMonthlyPluginWidget()
99
98
if (dialog.exec() == QDialog::Accepted) {
100
99
QPainter painter(&printer);
101
100
ui.kWebView->render(&painter);
106
void SKGMonthlyPluginWidget::refresh()
106
void SKGMonthlyPluginWidget::dataModified(const QString& iTableName, int iIdTransaction)
108
SKGTRACEIN(1, "SKGMonthlyPluginWidget::refresh");
108
SKGTRACEIN(1, "SKGMonthlyPluginWidget::dataModified");
110
110
QSqlDatabase* db = getDocument()->getDatabase();
111
111
setEnabled(db!=NULL);
112
if (db!=NULL && (iTableName=="parameters" || iTableName=="operation" || iTableName.isEmpty())) {
114
disconnect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
114
disconnect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
116
116
QStringList list;
117
117
SKGServices::getDistinctValues(getDocument(), "v_operation_display", "d_DATEMONTH", "d_date<=CURRENT_DATE", list);
123
123
ui.kMonth->addItems(list);
124
124
if (!month.isEmpty()) ui.kMonth->setText(month);
125
125
else if (list.count()) month=list.at(0);
126
connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
129
QString htmlReport=getDocument()->getParameter("SKG_MONTHLY_REPORT_"+month);
130
if (htmlReport.isEmpty()) {
131
//Report not yet generated
132
ui.kWebView->setHtml(i18n("This monthly report is not computed yet. Click on refresh to do it !"));
136
QDir dirCss(KStandardDirs::locate("data", QString::fromLatin1("skrooge/css/")));
137
QFile file(dirCss.absoluteFilePath("skrooge_monthly-default.css"));
138
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
142
QTextStream in(&file);
143
while (!in.atEnd()) {
144
style+=in.readLine();
147
htmlReport.replace("##STYLE##", style);
149
//Display html report
150
ui.kWebView->setHtml(htmlReport);
126
connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
132
void SKGMonthlyPluginWidget::onMonthChanged()
134
SKGTRACEIN(1, "SKGMonthlyPluginWidget::onMonthChanged");
135
QString month=ui.kMonth->text();
138
QString htmlReport=getDocument()->getParameter("SKG_MONTHLY_REPORT_"+month);
139
if (htmlReport.isEmpty()) {
140
//Report not yet generated
141
ui.kWebView->setHtml(i18n("The monthly report has not yet been computed: click on refresh to do so."));
145
QDir dirCss(KStandardDirs::locate("data", QString::fromLatin1("skrooge/css/")));
146
QFile file(dirCss.absoluteFilePath("skrooge_monthly-default.css"));
147
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
151
QTextStream in(&file);
152
while (!in.atEnd()) {
153
style+=in.readLine();
156
htmlReport.replace("##STYLE##", style);
158
//Display html report
159
ui.kWebView->setHtml(htmlReport);
155
163
void SKGMonthlyPluginWidget::onReportRefresh()
159
166
SKGTRACEINRC(10, "SKGMonthlyPluginWidget::onReportRefresh",err);
188
195
html+="<h1>"+i18n("Report for %1", month)+"</h1>";
197
//Income & Expenditure
191
198
if (err.isSucceeded()) {
192
199
SKGStringListList listTmp;
193
200
err=SKGServices::executeSelectSqliteOrder(getDocument(),
194
"SELECT TOTAL(f_CURRENTAMOUNT), t_TYPEEXPENSE, d_DATEMONTH from v_operation_display WHERE (d_DATEMONTH='"+month+"' OR d_DATEMONTH='"+previousmonth+"') AND i_group_id=0 group by d_DATEMONTH, t_TYPEEXPENSE",
201
"SELECT TOTAL(f_CURRENTAMOUNT), d_DATEMONTH from v_operation_display WHERE (d_DATEMONTH='"+month+"' OR d_DATEMONTH='"+previousmonth+"') AND i_group_id=0 group by d_DATEMONTH, t_TYPEEXPENSE",
196
if (err.isSucceeded() && listTmp.count()>2) {
197
html+="<h2>"+i18n("Income & Expense")+"</h2><table class=\"table\">";
203
if (err.isSucceeded()) {
204
html+="<h2>"+i18n("Income & Expenditure")+"</h2><table class=\"table\">";
198
205
html+="<tr class=\"tabletitle\"><td align=\"center\"></td>"
199
206
"<td align=\"center\">"+previousmonth+"</td>"
200
207
"<td align=\"center\">"+month+"</td>"
202
209
double income_previous_month=0;
203
210
double expense_previous_month=0;
204
double saving_previous_month=0;
205
double income_month=SKGServices::stringToDouble(listTmp.at(1).at(0));
206
double expense_month=SKGServices::stringToDouble(listTmp.at(2).at(0));
211
double income_month=0;
212
double expense_month=0;
214
int nbval=listTmp.count();
215
for (int i=1; i<nbval; ++i) { //Ignore header
216
QString m=listTmp.at(i).at(1);
217
double v=SKGServices::stringToDouble(listTmp.at(i).at(0));
218
if (v>0 && m==month) income_month=v;
219
else if (v<0 && m==month) expense_month=v;
220
else if (v>0 && m==previousmonth) income_previous_month=v;
221
else if (v<0 && m==previousmonth) expense_previous_month=v;
223
double saving_previous_month=income_previous_month+expense_previous_month;
207
224
double saving_month=income_month+expense_month;
208
if (listTmp.count()>4) {
209
income_previous_month=income_month;
210
expense_previous_month=expense_month;
211
saving_previous_month=saving_month;
212
income_month=SKGServices::stringToDouble(listTmp.at(3).at(0));
213
expense_month=SKGServices::stringToDouble(listTmp.at(4).at(0));
214
saving_month=income_month+expense_month;
216
226
html+=QString("<tr><td>")+i18n("Income")+"</td>"
217
227
"<td align=\"right\">"+locale->formatMoney(income_previous_month, primary,2)+"</td>"
218
228
"<td align=\"right\">"+locale->formatMoney(income_month, primary,2)+"</td>"
220
html+=QString("<tr><td>")+i18n("Expense")+"</td>"
230
html+=QString("<tr><td>")+i18n("Expenditure")+"</td>"
221
231
"<td align=\"right\">"+locale->formatMoney(abs(expense_previous_month), primary,2)+"</td>"
222
232
"<td align=\"right\">"+locale->formatMoney(abs(expense_month), primary,2)+"</td>"
231
241
SKGServices::doubleToString(abs(expense_month))+','+
232
242
SKGServices::doubleToString(abs(income_month))+
234
"&chs=300x200&chl="+i18n("Expense")+'|'+i18n("Income")+"&chtt="+i18n("Expense vs Income")+'|'+month;
244
"&chs=300x200&chl="+i18n("Expenditure")+'|'+i18n("Income")+"&chtt="+i18n("Expenditure vs Income")+'|'+month;
235
245
// SKGTRACE << img << endl;
236
246
html+="<img src=\""+img+"\" />";
244
254
SKGObjectBase::SKGListSKGObjectBase accounts;
245
255
SKGError err=SKGObjectBase::getObjects(getDocument(), "v_account_display", "1=1 ORDER BY t_TYPENLS", accounts);
246
256
if (err.isSucceeded()) {
247
html+="<h2>"+i18n("Amount of accounts")+"</h2><table class=\"table\">";
257
html+="<h2>"+i18n("Amounts in accounts")+"</h2><table class=\"table\">";
248
258
html+="<tr class=\"tabletitle\"><td align=\"center\">"+i18n("Account")+"</td>"
249
259
"<td align=\"center\">"+locale->formatDate (date1, KLocale::ShortDate)+"</td>"
250
260
"<td align=\"center\">"+locale->formatDate (date2, KLocale::ShortDate)+"</td>"
341
351
SKGObjectBase::SKGListSKGObjectBase units;
342
352
SKGError err=SKGObjectBase::getObjects(getDocument(), "v_unit_display", "1=1 ORDER BY t_TYPENLS", units);
343
353
if (err.isSucceeded()) {
344
html+="<h2>"+i18n("Amount of units")+"</h2><table class=\"table\">";
354
html+="<h2>"+i18n("Amounts of units")+"</h2><table class=\"table\">";
345
355
html+="<tr class=\"tabletitle\"><td align=\"center\">"+i18n("Unit")+"</td>"
346
356
"<td align=\"center\">"+locale->formatDate (date1, KLocale::ShortDate)+"</td>"
347
357
"<td align=\"center\">"+locale->formatDate (date2, KLocale::ShortDate)+"</td>"