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 "nsStringAPI.h"
26 #include "nsEmbedString.h"
28 /* Project includes */
29 #include <abstract/base/aaIFlow.h>
30 #include <abstract/storage/aaIStateFilter.h>
31 #include <abstract/storage/aaStorageUtils.h>
32 #include "aaStateFilter.h"
34 aaStateFilter::aaStateFilter()
38 aaStateFilter::~aaStateFilter()
42 NS_IMPL_ISUPPORTS2(aaStateFilter
,
47 aaStateFilter::GetExpression(nsACString
& aExpression
)
50 balanceSheetExpression(aExpression
);
51 else if (mFlow
->PickId())
52 balanceExpression(aExpression
);
54 incomeExpression(aExpression
);
61 aaStateFilter::GetFlow(aaIFlow
* *aFlow
)
63 NS_ENSURE_ARG_POINTER(aFlow
);
64 NS_IF_ADDREF( *aFlow
= mFlow
);
68 aaStateFilter::SetFlow(aaIFlow
* aFlow
)
74 aaStateFilter::PickFlow()
80 aaStateFilter::GetDate(PRTime
*aDate
)
82 NS_ENSURE_ARG_POINTER(aDate
);
87 aaStateFilter::SetDate(PRTime aDate
)
93 aaStateFilter::PickDate()
100 aaStateFilter::balanceSheetExpression(nsACString
& aExpression
)
102 aExpression
.Assign(" WHERE balance.start<=");
103 aExpression
.AppendInt(aa_julian_day(mDate
));
104 aExpression
.Append(" AND (balance.paid>");
105 aExpression
.AppendInt(aa_julian_day(mDate
));
106 aExpression
.Append(" OR balance.paid IS NULL)");
110 aaStateFilter::balanceExpression(nsACString
& aExpression
)
112 aExpression
.Assign(" WHERE balance.flow_id=");
113 aExpression
.AppendInt(mFlow
->PickId());
114 aExpression
.Append(" AND balance.start=(SELECT MAX(start) FROM balance\
116 aExpression
.AppendInt(mFlow
->PickId());
117 aExpression
.Append(" AND start<=");
118 aExpression
.AppendInt(aa_julian_day(mDate
));
119 aExpression
.Append(") AND (balance.paid>");
120 aExpression
.AppendInt(aa_julian_day(mDate
));
121 aExpression
.Append(" OR balance.paid IS NULL)");
125 aaStateFilter::incomeExpression(nsACString
& aExpression
)
127 aExpression
.Assign(" WHERE income.start<=");
128 aExpression
.AppendInt(aa_julian_day(mDate
));
129 aExpression
.Append(" AND (income.paid>");
130 aExpression
.AppendInt(aa_julian_day(mDate
));
131 aExpression
.Append(" OR income.paid IS NULL)");