~ubuntu-branches/ubuntu/lucid/skrooge/lucid

« back to all changes in this revision

Viewing changes to skrooge_monthly/skgmonthlypluginwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-07-28 15:38:43 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090728153843-91b74m0vcam50krt
Tags: 0.2.9-0ubuntu1
* New upstream release
* Added kubuntu_01_cmake_fix.patch:
  Fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        ui.kRefresh->setIcon(KIcon("view-refresh"));
48
48
        ui.kPrint->setIcon(KIcon("printer"));
49
49
 
50
 
        connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
 
50
        connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
51
51
 
52
52
        //Refresh
53
 
        connect((const QObject*) getDocument(), SIGNAL(transactionSuccessfullyEnded(int)), this, SLOT(refresh()), Qt::QueuedConnection);
54
 
 
55
 
        refresh();
 
53
        connect((const QObject*) getDocument(), SIGNAL(tableModified(QString, int)), this, SLOT(dataModified(QString, int)), Qt::QueuedConnection );
 
54
        dataModified("", 0);
56
55
}
57
56
 
58
57
SKGMonthlyPluginWidget::~SKGMonthlyPluginWidget()
99
98
        if (dialog.exec() == QDialog::Accepted) {
100
99
                QPainter painter(&printer);
101
100
                ui.kWebView->render(&painter);
 
101
                painter.end();
102
102
        }
103
103
#endif
104
104
}
105
105
 
106
 
void SKGMonthlyPluginWidget::refresh()
 
106
void SKGMonthlyPluginWidget::dataModified(const QString& iTableName, int iIdTransaction)
107
107
{
108
 
        SKGTRACEIN(1, "SKGMonthlyPluginWidget::refresh");
 
108
        SKGTRACEIN(1, "SKGMonthlyPluginWidget::dataModified");
109
109
 
110
110
        QSqlDatabase* db = getDocument()->getDatabase();
111
111
        setEnabled(db!=NULL);
112
 
        if (db!=NULL) {
 
112
        if (db!=NULL &&  (iTableName=="parameters" || iTableName=="operation" || iTableName.isEmpty())) {
113
113
                //Fill combo
114
 
                disconnect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
 
114
                disconnect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
115
115
 
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()));
127
 
 
128
 
                //Display report
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 !"));
133
 
                } else {
134
 
                        //Report generated
135
 
                        //Set style sheet
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))
139
 
                                return;
140
 
 
141
 
                        QString style;
142
 
                        QTextStream in(&file);
143
 
                        while (!in.atEnd()) {
144
 
                                style+=in.readLine();
145
 
                        }
146
 
 
147
 
                        htmlReport.replace("##STYLE##", style);
148
 
 
149
 
                        //Display html report
150
 
                        ui.kWebView->setHtml(htmlReport);
 
126
                connect(ui.kMonth, SIGNAL(currentIndexChanged(int)), this, SLOT(onMonthChanged()));
 
127
 
 
128
                onMonthChanged();
 
129
        }
 
130
}
 
131
 
 
132
void SKGMonthlyPluginWidget::onMonthChanged()
 
133
{
 
134
        SKGTRACEIN(1, "SKGMonthlyPluginWidget::onMonthChanged");
 
135
        QString month=ui.kMonth->text();
 
136
 
 
137
        //Display report
 
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."));
 
142
        } else {
 
143
                //Report generated
 
144
                //Set style sheet
 
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))
 
148
                        return;
 
149
 
 
150
                QString style;
 
151
                QTextStream in(&file);
 
152
                while (!in.atEnd()) {
 
153
                        style+=in.readLine();
151
154
                }
 
155
 
 
156
                htmlReport.replace("##STYLE##", style);
 
157
 
 
158
                //Display html report
 
159
                ui.kWebView->setHtml(htmlReport);
152
160
        }
153
161
}
154
162
 
155
163
void SKGMonthlyPluginWidget::onReportRefresh()
156
 
 
157
164
{
158
165
        SKGError err;
159
166
        SKGTRACEINRC(10, "SKGMonthlyPluginWidget::onReportRefresh",err);
187
194
                //Main title
188
195
                html+="<h1>"+i18n("Report for %1", month)+"</h1>";
189
196
 
190
 
                //Income & Expense
 
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",
195
202
                                        listTmp);
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>"
201
208
                                      "</tr>";
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;
 
213
 
 
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;
 
222
                                }
 
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;
215
 
                                }
 
225
 
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>"
219
229
                                      "</tr>";
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>"
223
233
                                      "</tr>";
231
241
                                            SKGServices::doubleToString(abs(expense_month))+','+
232
242
                                            SKGServices::doubleToString(abs(income_month))+
233
243
                                            "&chds="+range+
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+"\" />";
237
247
                        }
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>"
379
389
 
380
390
        //status bar
381
391
        if (err.isSucceeded())  err=SKGError(0, i18n("Report computed."));
382
 
        else err.addError(ERR_FAIL, i18n("Report computation failed"));
 
392
        else err.addError(ERR_FAIL, i18n("Report computation failed."));
383
393
 
384
394
        //Display error
385
395
        getMainPanel()->displayErrorMessage(err);