]>
Dogcows Code - chaz/homebank/blob - src/hb-report.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "hb-report.h"
23 /****************************************************************************/
25 /****************************************************************************/
34 /* our global datas */
35 extern struct HomeBank
*GLOBALS
;
36 extern struct Preferences
*PREFS
;
39 extern gchar
*CYA_ABMONTHS
[];
41 /* = = = = = = = = = = = = = = = = = = = = */
44 void da_vehiclecost_free(CarCost
*item
)
53 CarCost
*da_vehiclecost_malloc(void)
55 return g_malloc0(sizeof(CarCost
));
58 void da_vehiclecost_destroy(GList
*list
)
60 GList
*tmplist
= g_list_first(list
);
62 while (tmplist
!= NULL
)
64 CarCost
*item
= tmplist
->data
;
65 da_vehiclecost_free(item
);
66 tmplist
= g_list_next(tmplist
);
72 /* = = = = = = = = = = = = = = = = = = = = */
76 ** return the month list position correponding to the passed date
78 static guint
DateInMonth(guint32 from
, guint32 opedate
)
84 // this return sometimes -1, -2 which is wrong
86 date1
= g_date_new_julian(from
);
87 date2
= g_date_new_julian(opedate
);
89 pos
= ((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
);
91 //g_print(" from=%d-%d ope=%d-%d => %d\n", g_date_get_month(date1), g_date_get_year(date1), g_date_get_month(date2), g_date_get_year(date2), pos);
101 //for fiscal sub gap between 1st fiscal and 1/1/year
103 //int quarterNumber = (date.Month-1)/3+1;
104 //DateTime firstDayOfQuarter = new DateTime(date.Year, (quarterNumber-1)*3+1,1);
105 //DateTime lastDayOfQuarter = firstDayOfQuarter.AddMonths(3).AddDays(-1);
107 static guint
DateInQuarter(guint32 from
, guint32 opedate
)
109 GDate
*date1
, *date2
;
112 date1
= g_date_new_julian(from
);
113 date2
= g_date_new_julian(opedate
);
115 //#1758532 shift to first quarter day of 'from date'
116 quarter
= ((g_date_get_month(date1
)-1)/3)+1;
117 DB( g_print("-- from=%02d/%d :: Q%d\n", g_date_get_month(date1
), g_date_get_year(date1
), quarter
) );
118 g_date_set_day(date1
, 1);
119 g_date_set_month(date1
, ((quarter
-1)*3)+1);
121 pos
= (((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
))/3;
123 DB( g_print("-- from=%02d/%d ope=%02d/%d => pos=%d\n", g_date_get_month(date1
), g_date_get_year(date1
), g_date_get_month(date2
), g_date_get_year(date2
), pos
) );
132 static guint
DateInHalfYear(guint32 from
, guint32 opedate
)
134 GDate
*date1
, *date2
;
137 date1
= g_date_new_julian(from
);
138 date2
= g_date_new_julian(opedate
);
140 // shift to first half year of 'from date'
141 hyear
= ((g_date_get_month(date1
)-1)/6)+1;
142 DB( g_print("-- from=%02d/%d :: Q%d\n", g_date_get_month(date1
), g_date_get_year(date1
), hyear
) );
143 g_date_set_day(date1
, 1);
144 g_date_set_month(date1
, ((hyear
-1)*6)+1);
146 pos
= (((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
))/6;
148 DB( g_print(" from=%d-%d ope=%d-%d => %d\n", g_date_get_month(date1
), g_date_get_year(date1
), g_date_get_month(date2
), g_date_get_year(date2
), pos
) );
158 ** return the year list position correponding to the passed date
160 static guint
DateInYear(guint32 from
, guint32 opedate
)
163 guint year_from
, year_ope
, pos
;
165 date
= g_date_new_julian(from
);
166 year_from
= g_date_get_year(date
);
168 g_date_set_julian(date
, opedate
);
169 year_ope
= g_date_get_year(date
);
172 pos
= year_ope
- year_from
;
174 //g_print(" from=%d ope=%d => %d\n", year_from, year_ope, pos);
180 gint
report_items_count(gint src
, guint32 jfrom
, guint32 jto
)
182 GDate
*date1
, *date2
;
187 case REPORT_SRC_CATEGORY
:
188 case REPORT_SRC_SUBCATEGORY
:
189 nbsrc
= da_cat_get_max_key() + 1;
191 case REPORT_SRC_PAYEE
:
192 nbsrc
= da_pay_get_max_key() + 1;
194 case REPORT_SRC_ACCOUNT
:
195 nbsrc
= da_acc_get_max_key() + 1;
198 nbsrc
= da_tag_length();
200 case REPORT_SRC_MONTH
:
201 date1
= g_date_new_julian(jfrom
);
202 date2
= g_date_new_julian(jto
);
203 nbsrc
= ((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
) + 1;
207 case REPORT_SRC_YEAR
:
208 date1
= g_date_new_julian(jfrom
);
209 date2
= g_date_new_julian(jto
);
210 nbsrc
= g_date_get_year(date2
) - g_date_get_year(date1
) + 1;
221 gint
report_items_get_pos(gint tmpsrc
, guint jfrom
, Transaction
*ope
)
227 case REPORT_SRC_CATEGORY
:
228 pos
= category_report_id(ope
->kcat
, FALSE
);
230 case REPORT_SRC_SUBCATEGORY
:
233 case REPORT_SRC_PAYEE
:
236 case REPORT_SRC_ACCOUNT
:
239 case REPORT_SRC_MONTH
:
240 pos
= DateInMonth(jfrom
, ope
->date
);
242 case REPORT_SRC_YEAR
:
243 pos
= DateInYear(jfrom
, ope
->date
);
250 gint
report_interval_get_pos(gint intvl
, guint jfrom
, Transaction
*ope
)
256 case REPORT_INTVL_DAY
:
257 pos
= ope
->date
- jfrom
;
259 case REPORT_INTVL_WEEK
:
260 pos
= (ope
->date
- jfrom
)/7;
262 case REPORT_INTVL_MONTH
:
263 pos
= DateInMonth(jfrom
, ope
->date
);
265 case REPORT_INTVL_QUARTER
:
266 pos
= DateInQuarter(jfrom
, ope
->date
);
268 case REPORT_INTVL_HALFYEAR
:
269 pos
= DateInHalfYear(jfrom
, ope
->date
);
271 case REPORT_INTVL_YEAR
:
272 pos
= DateInYear(jfrom
, ope
->date
);
281 gint
report_interval_count(gint intvl
, guint32 jfrom
, guint32 jto
)
283 GDate
*date1
, *date2
;
286 date1
= g_date_new_julian(jfrom
);
287 date2
= g_date_new_julian(jto
);
291 case REPORT_INTVL_DAY
:
292 nbintvl
= 1 + (jto
- jfrom
);
294 case REPORT_INTVL_WEEK
:
295 nbintvl
= 1 + ((jto
- jfrom
) / 7);
297 case REPORT_INTVL_MONTH
:
298 nbintvl
= 1 + ((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
);
300 case REPORT_INTVL_QUARTER
:
301 nbintvl
= 1 + (((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
))/3;
303 case REPORT_INTVL_HALFYEAR
:
304 nbintvl
= 1 + (((g_date_get_year(date2
) - g_date_get_year(date1
)) * 12) + g_date_get_month(date2
) - g_date_get_month(date1
))/6;
306 case REPORT_INTVL_YEAR
:
307 nbintvl
= 1 + g_date_get_year(date2
) - g_date_get_year(date1
);
318 void report_interval_snprint_name(gchar
*s
, gint slen
, gint intvl
, guint32 jfrom
, gint idx
)
320 GDate
*date
= g_date_new_julian(jfrom
);
324 case REPORT_INTVL_DAY
:
325 g_date_add_days(date
, idx
);
326 g_date_strftime (s
, slen
, PREFS
->date_format
, date
);
329 case REPORT_INTVL_WEEK
:
330 g_date_add_days(date
, idx
*7);
331 //g_snprintf(buffer, 63, "%d-%02d", g_date_get_year(date), g_date_get_month(date));
332 //TRANSLATORS: printf string for year of week W, ex. 2019-W52 for week 52 of 2019
333 g_snprintf(s
, slen
, _("%d-w%d"), g_date_get_year(date
), g_date_get_monday_week_of_year(date
));
336 case REPORT_INTVL_MONTH
:
337 g_date_add_months(date
, idx
);
338 //g_snprintf(buffer, 63, "%d-%02d", g_date_get_year(date), g_date_get_month(date));
339 g_snprintf(s
, slen
, "%d-%s", g_date_get_year(date
), _(CYA_ABMONTHS
[g_date_get_month(date
)]));
342 case REPORT_INTVL_QUARTER
:
343 g_date_add_months(date
, idx
*3);
344 //g_snprintf(buffer, 63, "%d-%02d", g_date_get_year(date), g_date_get_month(date));
345 //todo: will be innacurrate here if fiscal year start not 1/jan
346 //TRANSLATORS: printf string for year of quarter Q, ex. 2019-Q4 for quarter 4 of 2019
347 g_snprintf(s
, slen
, _("%d-q%d"), g_date_get_year(date
), ((g_date_get_month(date
)-1)/3)+1);
350 case REPORT_INTVL_HALFYEAR
:
351 g_date_add_months(date
, idx
*6);
352 g_snprintf(s
, slen
, "%d-%s", g_date_get_year(date
), g_date_get_month(date
) < 7 ? "h1" : "h2");
355 case REPORT_INTVL_YEAR
:
356 g_date_add_years(date
, idx
);
357 g_snprintf(s
, slen
, "%d", g_date_get_year(date
));
368 //TODO: maybe migrate this to filter as well
369 //#1562372 in case of a split we need to take amount for filter categories only
370 gdouble
report_txn_amount_get(Filter
*flt
, Transaction
*txn
)
374 amount
= txn
->amount
;
376 if( flt
->option
[FILTER_CATEGORY
] > 0 ) //not inactive
378 if( txn
->flags
& OF_SPLIT
)
380 guint i
, nbsplit
= da_splits_length(txn
->splits
);
387 for(i
=0;i
<nbsplit
;i
++)
389 split
= da_splits_get(txn
->splits
, i
);
390 catentry
= da_cat_get(split
->kcat
);
391 if(catentry
== NULL
) continue;
392 sinsert
= ( catentry
->flt_select
== TRUE
) ? 1 : 0;
393 if(flt
->option
[FILTER_CATEGORY
] == 2) sinsert
^= 1;
395 DB( g_print(" split '%s' insert=%d\n",catentry
->name
, sinsert
) );
397 if( (flt
->option
[FILTER_CATEGORY
] == 0) || sinsert
)
399 amount
+= split
->amount
;
This page took 0.050549 seconds and 5 git commands to generate.