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) 2007 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 <abstract/aacore.h>
25 #include "nsComponentManagerUtils.h"
27 #include "nsStringAPI.h"
30 #include "unstable/mozIStorageConnection.h"
32 /* Project includes */
33 #include <abstract/base/aaIFlow.h>
34 #include <abstract/base/aaIBalance.h>
35 #include <abstract/storage/aaIFilter.h>
36 #include <abstract/storage/aaIStateFilter.h>
37 #include <abstract/storage/aaBaseLoaders.h>
38 #include <abstract/storage/aaAccountLoaders.h>
39 #include <abstract/report/aaITranscript.h>
40 #include <abstract/storage/aaStorageUtils.h>
41 #include "aaTranscript.h"
43 aaTranscript::aaTranscript(nsISupports
*aOuter
)
45 nsCOMPtr
<mozIStorageConnection
> connection
= do_QueryInterface(aOuter
);
47 mOpening
= do_CreateInstance(AA_LOADBALANCE_CONTRACT_ID
, connection
);
51 mClosing
= do_CreateInstance(AA_LOADBALANCE_CONTRACT_ID
, connection
);
55 mOpeningFilter
= do_CreateInstance(AA_STATEFILTER_CONTRACT_ID
);
59 mClosingFilter
= do_CreateInstance(AA_STATEFILTER_CONTRACT_ID
);
63 mList
= do_CreateInstance(AA_LOADFACTLIST_CONTRACT_ID
, connection
);
67 mConnection
= connection
;
70 aaTranscript::~aaTranscript()
74 NS_IMPL_ISUPPORTS4(aaTranscript
,
85 mOpeningFilter
->SetFlow( mFlow
);
86 mOpeningFilter
->SetDate( mStart
);
87 mOpening
->SetFilter( mOpeningFilter
);
89 mClosingFilter
->SetFlow( mFlow
);
90 mClosingFilter
->SetDate( mEnd
);
91 mClosing
->SetFilter( mClosingFilter
);
93 mList
->SetFilter(this);
95 rv
= mOpening
->Load();
96 NS_ENSURE_SUCCESS(rv
, rv
);
98 rv
= mClosing
->Load();
99 NS_ENSURE_SUCCESS(rv
, rv
);
102 NS_ENSURE_SUCCESS(rv
, rv
);
109 aaTranscript::GetFilter(aaIFilter
* * aFilter
)
111 return NS_ERROR_NOT_IMPLEMENTED
;
114 aaTranscript::SetFilter(aaIFilter
* aFilter
)
116 return NS_ERROR_NOT_IMPLEMENTED
;
119 aaTranscript::PickFilter()
126 aaTranscript::GetFlow(aaIFlow
* *aFlow
)
128 NS_ENSURE_ARG_POINTER(aFlow
);
129 NS_IF_ADDREF(*aFlow
= mFlow
);
133 aaTranscript::SetFlow(aaIFlow
* aFlow
)
139 aaTranscript::PickLoadedFlow()
145 aaTranscript::GetStart(PRTime
*aStart
)
147 NS_ENSURE_ARG_POINTER(aStart
);
152 aaTranscript::SetStart(PRTime aStart
)
159 aaTranscript::GetEnd(PRTime
*aEnd
)
161 NS_ENSURE_ARG_POINTER(aEnd
);
166 aaTranscript::SetEnd(PRTime aEnd
)
173 aaTranscript::GetOpening(aaIBalance
* *aOpen
)
176 NS_ENSURE_ARG_POINTER(aOpen
);
177 NS_ENSURE_TRUE(mOpening
, NS_ERROR_UNEXPECTED
);
180 rv
= mOpening
->GetLength(&count
);
181 NS_ENSURE_SUCCESS(rv
, rv
);
183 return mOpening
->QueryElementAt(0, NS_GET_IID(aaIBalance
), (void **) aOpen
);
191 aaTranscript::GetClosing(aaIBalance
* *aClose
)
194 NS_ENSURE_ARG_POINTER(aClose
);
195 NS_ENSURE_TRUE(mClosing
, NS_ERROR_UNEXPECTED
);
198 rv
= mClosing
->GetLength(&count
);
199 NS_ENSURE_SUCCESS(rv
, rv
);
201 return mClosing
->QueryElementAt(0, NS_GET_IID(aaIBalance
), (void **) aClose
);
210 aaTranscript::GetExpression(nsACString
& aExpression
)
212 aExpression
.Assign(" WHERE txn.day>");
213 aExpression
.AppendInt(aa_julian_day(mOpeningFilter
->PickDate()));
214 aExpression
.Append(" AND txn.day<=");
215 aExpression
.AppendInt(aa_julian_day(mClosingFilter
->PickDate()));
216 aExpression
.Append(" AND (toF.flow_id=");
217 aExpression
.AppendInt(mOpeningFilter
->PickFlow()->PickId());
218 aExpression
.Append(" OR fromF.flow_id=");
219 aExpression
.AppendInt(mOpeningFilter
->PickFlow()->PickId());
220 aExpression
.Append(")");