1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsStringAPI.h"
28 #include "nsTextFormatter.h"
32 #include "nsArrayUtils.h"
33 #include "nsITreeColumns.h"
35 #include "nsIAtomService.h"
36 #include "nsIStringBundle.h"
38 /* Project includes */
39 #include "aaAmountUtils.h"
40 #include "aaIResource.h"
43 #include "aaITransaction.h"
44 #include "aaISqlTransaction.h"
45 #include "aaReportKeys.h"
46 #include "aaViewUtils.h"
47 #include "aaTreeViewLedger.h"
49 aaTreeViewLedger::aaTreeViewLedger()
51 mComplexLoader
= do_CreateInstance(AA_GENERALLEDGER_CONTRACT
);
54 aaTreeViewLedger::~aaTreeViewLedger()
58 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewLedger
, aaTreeView
)
60 /* Virtual overrides */
62 aaTreeViewLedger::GetRowCount(PRInt32
*aRowCount
)
64 NS_ENSURE_ARG_POINTER(aRowCount
);
70 rv
= mDataSet
->GetLength((PRUint32
*) aRowCount
);
71 NS_ENSURE_SUCCESS(rv
, rv
);
79 aaTreeViewLedger::getColumn0(aaITransaction
*txn
, PRUint32 flags
,
85 assignDate(_retval
, txn
->PickFact()->PickTime());
90 aaTreeViewLedger::getColumn1(aaITransaction
*txn
, PRUint32 flags
,
96 nsCOMPtr
<aaIResource
> resource
;
97 aaIFlow
*flow
= txn
->PickFact()->PickTakeFrom();
98 if (flow
&& flow
->PickId()) {
99 txn
->PickFact()->PickTakeFrom()->GetGiveResource(
100 getter_AddRefs(resource
));
102 txn
->PickFact()->PickGiveTo()->GetTakeResource(
103 getter_AddRefs(resource
));
107 return resource
->GetTag(_retval
);
113 aaTreeViewLedger::getColumn2(aaITransaction
*txn
, PRUint32 flags
,
119 assignDouble(_retval
, txn
->PickFact()->PickAmount());
124 aaTreeViewLedger::getColumn3(aaITransaction
*txn
, PRUint32 flags
,
128 nsCOMPtr
<nsIStringBundleService
> heap
= do_GetService(
129 NS_STRINGBUNDLE_CONTRACTID
, &rv
);
130 NS_ENSURE_SUCCESS(rv
, rv
);
132 nsCOMPtr
<nsIStringBundle
> bundle
;
133 rv
= heap
->CreateBundle("chrome://abstract/locale/abstract.properties",
134 getter_AddRefs( bundle
));
135 NS_ENSURE_SUCCESS(rv
, rv
);
139 rv
= bundle
->GetStringFromName(NS_LITERAL_STRING("terms.debit").get(),
142 rv
= bundle
->GetStringFromName(NS_LITERAL_STRING("terms.credit").get(),
150 aaTreeViewLedger::getColumn4(aaITransaction
*txn
, PRUint32 flags
,
154 if (txn
->PickFact()->PickTakeFrom())
155 txn
->PickFact()->PickTakeFrom()->GetTag(_retval
);
157 if (txn
->PickFact()->PickGiveTo())
158 txn
->PickFact()->PickGiveTo()->GetTag(_retval
);
164 aaTreeViewLedger::getColumn5(aaITransaction
*txn
, PRUint32 flags
,
167 if (isZero(txn
->PickFact()->PickAmount()))
171 assignDouble(_retval
, (txn
->PickValue() + txn
->PickEarnings())
172 / txn
->PickFact()->PickAmount());
174 assignDouble(_retval
, (txn
->PickValue())
175 / txn
->PickFact()->PickAmount());
181 aaTreeViewLedger::getColumn6(aaITransaction
*txn
, PRUint32 flags
,
187 assignDouble(_retval
, txn
->PickValue() + txn
->PickEarnings());
192 aaTreeViewLedger::getColumn7(aaITransaction
*txn
, PRUint32 flags
,
198 assignDouble(_retval
, txn
->PickValue());
203 aaTreeViewLedger::colFuncs
[])(aaITransaction
*, PRUint32 flags
,
205 &aaTreeViewLedger::getColumn0
,
206 &aaTreeViewLedger::getColumn1
,
207 &aaTreeViewLedger::getColumn2
,
208 &aaTreeViewLedger::getColumn3
,
209 &aaTreeViewLedger::getColumn4
,
210 &aaTreeViewLedger::getColumn5
,
211 &aaTreeViewLedger::getColumn6
,
212 &aaTreeViewLedger::getColumn7
215 /* Private functions */
217 aaTreeViewLedger::doGetCellText(PRInt32 row
, nsITreeColumn
*col
,
223 PRInt32 ci
= getColumnIndex(col
, sizeof(colFuncs
));
224 NS_ENSURE_TRUE(ci
>= 0, NS_OK
);
226 nsCOMPtr
<aaITransaction
> transaction(do_QueryElementAt(mDataSet
,
227 getIndexFromRow(row
), &rv
));
228 NS_ENSURE_SUCCESS(rv
, rv
);
229 NS_ENSURE_TRUE(transaction
, NS_OK
);
231 return colFuncs
[ci
](transaction
, getOffsetFromRow(row
), _retval
);