]> Dogcows Code - chaz/homebank/blob - src/hb-import.h
Merge branch 'upstream'
[chaz/homebank] / src / hb-import.h
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 #ifndef __HB_IMPORT_H__
21 #define __HB_IMPORT_H__
22
23 typedef struct _generic_file GenFile;
24
25 typedef struct _generic_acc GenAcc;
26 typedef struct _generic_split GenSplit;
27 typedef struct _generic_txn GenTxn;
28
29
30 //those are guin32 special values
31 #define DST_ACC_GLOBAL 100001
32 #define DST_ACC_NEW 100002
33 #define DST_ACC_SKIP 100010
34
35
36 struct _generic_file
37 {
38 guint32 key;
39 gchar *filepath;
40 gint filetype;
41 const gchar *encoding;
42 gint datefmt;
43 gboolean loaded;
44 gboolean invaliddatefmt;
45 };
46
47
48 struct _generic_acc
49 {
50 guint32 kfile;
51 gint filetype;
52
53 guint32 key;
54 gchar *name;
55 //maybe new user name
56 gchar *number;
57 guint32 kacc; //100001 = NEW, 100002 = SKIP
58 gboolean is_dupcheck; //if target account was checked for duplicate
59 gboolean is_ccard;
60 gboolean is_unamed; //if src account has no name into file
61 gdouble initial;
62 gint n_txnall; //nb of txn total
63 gint n_txnimp; //nb of txn to import
64 gint n_txnbaddate; //nb of txn with bad date
65 gint n_txnduplicate; //nb of txn with duplicate
66 };
67
68
69 struct _generic_split
70 {
71 gchar *category;
72 gdouble amount;
73 gchar *memo;
74 };
75
76
77 struct _generic_txn
78 {
79 guint32 kfile; //todo: remove this
80 guint32 kacc;
81
82 gchar *account;
83
84 gchar *rawinfo; //<n/a> ; check_number
85 gchar *rawpayee; //P ; name
86 gchar *rawmemo; //M ; memo
87
88 gchar *date; //D ; date_posted
89 gchar *info; //N ; <rawinfo>
90 gchar *payee;
91 gchar *memo;
92 gchar *category; //L
93 gchar *tags; //<n/a>
94
95 guint32 julian;
96 gushort paymode; //<n/a> ; transactiontype
97 gdouble amount; //T ; amount
98 gboolean reconciled; //R
99 gboolean cleared; //C
100
101 gboolean to_import;
102 gboolean is_imp_similar;
103 gboolean is_dst_similar;
104
105 gint nb_splits;
106 GenSplit splits[TXN_MAX_SPLIT];
107 GList *lst_existing;
108 };
109
110
111 typedef struct _ImportContext ImportContext;
112 struct _ImportContext
113 {
114 GList *gen_lst_file;
115
116 GList *gen_lst_acc;
117 GList *gen_lst_txn;
118 guint32 gen_next_acckey;
119
120 //to keep track of where we are
121 guint32 curr_kfile;
122 guint32 curr_kacc;
123
124
125 // ofx stuff
126 GenAcc *curr_acc;
127 gboolean curr_acc_isnew;
128
129 gint opt_dateorder;
130 gint opt_daygap;
131
132 gint opt_ofxname;
133 gint opt_ofxmemo;
134
135 gboolean opt_qifmemo;
136 gboolean opt_qifswap;
137 gboolean opt_ucfirst;
138
139 //gboolean is_ccard;
140
141 //GList *trans_list; // trn storage
142 //gint next_acc_key; //max key account when start
143 //gint datefmt;
144 //const gchar *encoding;
145
146 /*gint nb_src_acc, nb_new_acc;
147 gint cnt_new_ope;
148 gint cnt_new_pay;
149 gint cnt_new_cat;
150 gint cnt_err_date;
151 gint nb_duplicate;*/
152 };
153
154
155 enum QIF_Type
156 {
157 QIF_NONE,
158 QIF_HEADER,
159 QIF_ACCOUNT,
160 QIF_CATEGORY,
161 QIF_CLASS,
162 QIF_MEMORIZED,
163 QIF_TRANSACTION,
164 QIF_SECURITY,
165 QIF_PRICES
166 };
167
168
169 void da_import_context_new(ImportContext *ctx);
170 void da_import_context_destroy(ImportContext *ctx);
171
172
173 GenFile *da_gen_file_malloc(void);
174 void da_gen_file_free(GenFile *genfile);
175 GenFile *da_gen_file_get(GList *lst_file, guint32 key);
176 GenFile *da_gen_file_append_from_filename(ImportContext *ictx, gchar *filename);
177
178 GenAcc *da_gen_acc_malloc(void);
179 void da_gen_acc_free(GenAcc *item);
180 GenAcc *da_gen_acc_get_by_key(GList *lst_acc, guint32 key);
181
182 GenTxn *da_gen_txn_malloc(void);
183 void da_gen_txn_free(GenTxn *item);
184 GList *da_gen_txn_sort(GList *list);
185
186 void da_gen_txn_destroy(ImportContext *ctx);
187 void da_gen_txn_new(ImportContext *ctx);
188 void da_gen_txn_move(GenTxn *sitem, GenTxn *ditem);
189 void da_gen_txn_append(ImportContext *ctx, GenTxn *item);
190
191 gchar *hb_import_filetype_char_get(GenAcc *acc);
192
193 GenAcc *hb_import_gen_acc_get_next(ImportContext *ictx, gint filetype, gchar *name, gchar *number);
194 gint hb_import_gen_acc_count_txn(ImportContext *ictx, GenAcc *genacc);
195
196 Transaction *hb_import_convert_txn(GenAcc *genacc, GenTxn *gentxn);
197
198
199 void hb_import_load_all(ImportContext *ictx);
200 gint hb_import_gen_txn_check_target_similar(ImportContext *ictx, GenAcc *genacc);
201 gint hb_import_gen_txn_check_duplicate(ImportContext *ictx, GenAcc *genacc);
202
203 gint hb_import_option_apply(ImportContext *ictx, GenAcc *genacc);
204
205 Account *import_create_account(gchar *name, gchar *number);
206 Account *hb_import_acc_find_existing(gchar *name, gchar *number);
207
208
209 void hb_import_apply(ImportContext *ictx);
210
211 GList *homebank_csv_import(ImportContext *ictx, GenFile *genfile);
212 GList *homebank_ofx_import(ImportContext *ictx, GenFile *genfile);
213 GList *homebank_qif_import(ImportContext *ictx, GenFile *genfile);
214
215 GList *account_import_qif(gchar *filename, ImportContext *ictx);
216 gdouble hb_qif_parser_get_amount(gchar *string);
217
218 gboolean hb_csv_row_valid(gchar **str_array, guint nbcolumns, gint *csvtype);
219 gchar **hb_csv_row_get(gchar *string, gchar *delimiter, gint max_tokens);
220
221 #if MYDEBUG
222 void _import_context_debug_file_list(ImportContext *ctx);
223 void _import_context_debug_acc_list(ImportContext *ctx);
224 void _import_context_debug_txn_list(ImportContext *ctx);
225 #endif
226
227 #endif
228
This page took 0.043403 seconds and 4 git commands to generate.