]> Dogcows Code - chaz/homebank/blobdiff - src/hb-import.h
import homebank-5.2.4
[chaz/homebank] / src / hb-import.h
index c7fcdf893346af058fe53696f86ec5bfe28470a7..95e00986671042c04a517e8986859716154a37a1 100644 (file)
@@ -1,5 +1,5 @@
 /*  HomeBank -- Free, easy, personal accounting for everyone.
- *  Copyright (C) 1995-2018 Maxime DOYEN
+ *  Copyright (C) 1995-2019 Maxime DOYEN
  *
  *  This file is part of HomeBank.
  *
 #ifndef __HB_IMPORT_H__
 #define __HB_IMPORT_H__
 
+typedef struct _generic_file   GenFile;
 
-typedef struct _ImportContext ImportContext;
-struct _ImportContext
-{
-       GList                   *trans_list;    // trn storage
-       gint                    next_acc_key;   //max key account when start
+typedef struct _generic_acc            GenAcc;
+typedef struct _generic_split  GenSplit;
+typedef struct _generic_txn            GenTxn;
 
-       gint                    datefmt;
-       const gchar             *encoding;
 
-       gint                    nb_src_acc, nb_new_acc; 
-       gint                    cnt_new_ope;
-       gint                    cnt_new_pay;
-       gint                    cnt_new_cat;
-       gint                    cnt_err_date;
-       gint                    nb_duplicate;
-};
+//those are guin32 special values
+#define DST_ACC_GLOBAL 100001
+#define DST_ACC_NEW            100002
+#define DST_ACC_SKIP           100010
 
 
-typedef struct _OfxContext OfxContext;
-struct _OfxContext
+struct _generic_file
 {
-       GList           *trans_list;
-       Account         *curr_acc;
-       gboolean        curr_acc_isnew;
-       ImportContext *ictx;
+       guint32      key;
+       gchar        *filepath;
+       gint             filetype;
+       const gchar      *encoding;
+       gint             datefmt;
+       gboolean        loaded;
+       gboolean    invaliddatefmt;
 };
 
 
-typedef struct _QifContext QifContext;
-typedef struct _qif_split      QIFSplit;
-typedef struct _qif_tran       QIF_Tran;
-
-#define QIF_UNKNOW_ACCOUNT_NAME "(unknown)"
-
-struct _QifContext
+struct _generic_acc
 {
-       GList   *q_acc;
-       GList   *q_cat;
-       GList   *q_pay;
-       GList   *q_tra;
-
+       guint32         kfile;
+       gint            filetype;
+
+       guint32         key;
+       gchar      *name;
+       //maybe new user name
+       gchar      *number;
+       guint32         kacc;                   //100001 = NEW, 100002 = SKIP
+       gboolean        is_dupcheck;    //if target account was checked for duplicate
        gboolean        is_ccard;
+       gboolean        is_unamed;              //if src account has no name into file
+       gdouble         initial;
+       gint            n_txnall;               //nb of txn total
+       gint            n_txnimp;               //nb of txn to import
+       gint            n_txnbaddate;   //nb of txn with bad date
+       gint            n_txnduplicate; //nb of txn with duplicate
 };
 
-struct _qif_split
+
+struct _generic_split
 {
        gchar           *category;
        gdouble         amount;
        gchar           *memo;
 };
 
-struct _qif_tran
+
+struct _generic_txn
 {
+       guint32         kfile;          //todo: remove this
+       guint32         kacc;
+
        gchar           *account;
-       gchar           *date;
-       gdouble         amount;
-       gboolean        reconciled;
-       gboolean        cleared;
-       gchar           *info;
+
+       gchar           *rawinfo;       //<n/a> ; check_number
+       gchar       *rawpayee;  //P ; name
+       gchar       *rawmemo;   //M ; memo
+       
+       gchar           *date;          //D ; date_posted
+       gchar           *info;          //N ; <rawinfo> 
        gchar           *payee;
        gchar           *memo;
-       gchar           *category;
+       gchar           *category;  //L
+       gchar           *tags;          //<n/a>
+       
+       guint32         julian;
+       gushort         paymode;        //<n/a> ; transactiontype
+       gdouble         amount;         //T ; amount
+       gboolean        reconciled; //R
+       gboolean        cleared;        //C
+
+       gboolean        to_import;
+       gboolean        is_imp_similar;
+       gboolean        is_dst_similar;
 
        gint            nb_splits;
-       QIFSplit        splits[TXN_MAX_SPLIT];
+       GenSplit        splits[TXN_MAX_SPLIT];
+       GList           *lst_existing;
+};
+
+
+typedef struct _ImportContext ImportContext;
+struct _ImportContext
+{
+       GList      *gen_lst_file;
+
+       GList      *gen_lst_acc;
+       GList      *gen_lst_txn;
+       guint32         gen_next_acckey;
+
+       //to keep track of where we are
+       guint32         curr_kfile;
+       guint32         curr_kacc;
+
+
+       // ofx stuff
+       GenAcc          *curr_acc;
+       gboolean        curr_acc_isnew;
+
+       gint            opt_dateorder;
+       gint            opt_daygap;
+       
+       gint            opt_ofxname;
+       gint            opt_ofxmemo;
+
+       gboolean        opt_qifmemo;
+       gboolean        opt_qifswap;
+       gboolean        opt_ucfirst;
+
+       //gboolean      is_ccard;
+
+       //GList                 *trans_list;    // trn storage
+       //gint                  next_acc_key;   //max key account when start
+       //gint                  datefmt;
+       //const gchar           *encoding;
+
+       /*gint                  nb_src_acc, nb_new_acc; 
+       gint                    cnt_new_ope;
+       gint                    cnt_new_pay;
+       gint                    cnt_new_cat;
+       gint                    cnt_err_date;
+       gint                    nb_duplicate;*/
 };
 
 
@@ -103,18 +166,63 @@ enum QIF_Type
 };
 
 
-GList *account_import_qif(gchar *filename, ImportContext *ictx);
-gdouble hb_qif_parser_get_amount(gchar *string);
+void da_import_context_new(ImportContext *ctx);
+void da_import_context_destroy(ImportContext *ctx);
+
+
+GenFile *da_gen_file_malloc(void);
+void da_gen_file_free(GenFile *genfile);
+GenFile *da_gen_file_get(GList *lst_file, guint32 key);
+GenFile *da_gen_file_append_from_filename(ImportContext *ictx, gchar *filename);
 
+GenAcc *da_gen_acc_malloc(void);
+void da_gen_acc_free(GenAcc *item);
+GenAcc *da_gen_acc_get_by_key(GList *lst_acc, guint32 key);
 
+GenTxn *da_gen_txn_malloc(void);
+void da_gen_txn_free(GenTxn *item);
+GList *da_gen_txn_sort(GList *list);
+
+void da_gen_txn_destroy(ImportContext *ctx);
+void da_gen_txn_new(ImportContext *ctx);
+void da_gen_txn_move(GenTxn *sitem, GenTxn *ditem);
+void da_gen_txn_append(ImportContext *ctx, GenTxn *item);
+
+gchar *hb_import_filetype_char_get(GenAcc *acc);
+
+GenAcc *hb_import_gen_acc_get_next(ImportContext *ictx, gint filetype, gchar *name, gchar *number);
+gint hb_import_gen_acc_count_txn(ImportContext *ictx, GenAcc *genacc);
+
+Transaction *hb_import_convert_txn(GenAcc *genacc, GenTxn *gentxn);
+
+
+void hb_import_load_all(ImportContext *ictx);
+gint hb_import_gen_txn_check_target_similar(ImportContext *ictx, GenAcc *genacc);
+gint hb_import_gen_txn_check_duplicate(ImportContext *ictx, GenAcc *genacc);
+
+gint hb_import_option_apply(ImportContext *ictx, GenAcc *genacc);
 
 Account *import_create_account(gchar *name, gchar *number);
-GList *homebank_ofx_import(gchar *filename, ImportContext *ictx);
+Account *hb_import_acc_find_existing(gchar *name, gchar *number);
+
+
+void hb_import_apply(ImportContext *ictx);
+
+GList *homebank_csv_import(ImportContext *ictx, GenFile *genfile);
+GList *homebank_ofx_import(ImportContext *ictx, GenFile *genfile);
+GList *homebank_qif_import(ImportContext *ictx, GenFile *genfile);
+
+GList *account_import_qif(gchar *filename, ImportContext *ictx);
+gdouble hb_qif_parser_get_amount(gchar *string);
 
 gboolean hb_csv_row_valid(gchar **str_array, guint nbcolumns, gint *csvtype);
 gchar **hb_csv_row_get(gchar *string, gchar *delimiter, gint max_tokens);
 
-GList *homebank_csv_import(gchar *filename, ImportContext *ictx);
+#if MYDEBUG
+void _import_context_debug_file_list(ImportContext *ctx);
+void _import_context_debug_acc_list(ImportContext *ctx);
+void _import_context_debug_txn_list(ImportContext *ctx);
+#endif
 
 #endif
 
This page took 0.021637 seconds and 4 git commands to generate.