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,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 "nsIInterfaceRequestorUtils.h"
26 #include "nsStringAPI.h"
27 #include "nsComponentManagerUtils.h"
28 #include "nsXPCOMCID.h"
29 #include "nsIMutableArray.h"
30 #include "nsISupportsPrimitives.h"
34 /* Project includes */
35 #include "aaITimeFrame.h"
37 #include "aaIChartHandler.h"
38 #include "aaLoadIncome.h"
40 #define AA_LOADINCOME_SELECT_QUERY "SELECT\
46 strftime('%s',income.start),\
47 strftime('%s',income.paid)\
49 LEFT JOIN quote AS takeQ ON\
50 takeQ.day = income.start\
52 LEFT JOIN quote AS giveQ ON\
53 giveQ.day = income.start\
55 WHERE IFNULL(start<=round(julianday(?,'unixepoch')),1)\
56 AND (IFNULL(paid>round(julianday(?,'unixepoch')),0)\
58 GROUP BY income.start"
60 static struct aaLoadRequest::ColumnMap map
[] = {
71 aaLoadIncome::aaLoadIncome()
73 mSql
= AA_LOADINCOME_SELECT_QUERY
;
77 NS_IMPL_ISUPPORTS_INHERITED0(aaLoadIncome
,
82 aaLoadIncome::GetParams(nsIArray
* * aParams
)
85 nsCOMPtr
<aaIFlow
> flow
= do_GetInterface(mFilter
);
86 NS_ENSURE_TRUE(!flow
|| !(flow
->PickId()), NS_ERROR_INVALID_ARG
);
88 nsCOMPtr
<aaITimeFrame
> frame
= do_GetInterface(mFilter
);
89 nsCOMPtr
<nsIMutableArray
> result
90 = do_CreateInstance(NS_ARRAY_CONTRACTID
, &rv
);
91 NS_ENSURE_SUCCESS(rv
, rv
);
93 nsCOMPtr
<nsISupportsPRInt64
> valInt64
;
96 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
97 NS_ENSURE_SUCCESS(rv
, rv
);
98 rv
= valInt64
->SetData(frame
->PickEnd() / 1000000);
99 NS_ENSURE_SUCCESS(rv
, rv
);
100 rv
= result
->InsertElementAt(valInt64
, 0, PR_FALSE
);
101 NS_ENSURE_SUCCESS(rv
, rv
);
103 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
104 NS_ENSURE_SUCCESS(rv
, rv
);
105 rv
= valInt64
->SetData(frame
->PickStart() / 1000000);
106 NS_ENSURE_SUCCESS(rv
, rv
);
107 rv
= result
->InsertElementAt(valInt64
, 1, PR_FALSE
);
108 NS_ENSURE_SUCCESS(rv
, rv
);
111 rv
= result
->InsertElementAt(nsnull
, 0, PR_FALSE
);
112 NS_ENSURE_SUCCESS(rv
, rv
);
114 rv
= result
->InsertElementAt(nsnull
, 1, PR_FALSE
);
115 NS_ENSURE_SUCCESS(rv
, rv
);
126 aaLoadIncome::Accept(aaIHandler
*aQuery
)
129 nsCOMPtr
<aaIChartHandler
> chartQuery
= do_QueryInterface(aQuery
, &rv
);
130 NS_ENSURE_SUCCESS(rv
, rv
);
131 return chartQuery
->HandleIncome(nsnull
);