]>
Dogcows Code - chaz/homebank/blob - src/hb-export.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 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-export.h"
23 /****************************************************************************/
25 /****************************************************************************/
34 /* our global datas */
35 extern struct HomeBank
*GLOBALS
;
36 extern struct Preferences
*PREFS
;
38 /* = = = = = = = = = = = = = = = = = = = = */
40 static void hb_export_qif_elt_txn(GIOChannel
*io
, Account
*acc
)
45 char amountbuf
[G_ASCII_DTOSTR_BUF_SIZE
];
49 elt
= g_string_sized_new(255);
53 list
= g_queue_peek_head_link(acc
->txn_queue
);
56 Transaction
*txn
= list
->data
;
61 g_date_set_julian (date
, txn
->date
);
63 switch(PREFS
->dtex_datefmt
)
66 g_string_append_printf (elt
, "D%02d/%02d/%04d\n",
67 g_date_get_month(date
),
73 g_string_append_printf (elt
, "D%02d/%02d/%04d\n",
75 g_date_get_month(date
),
80 g_string_append_printf (elt
, "D%04d/%02d/%02d\n",
81 g_date_get_year(date
),
82 g_date_get_month(date
),
88 //g_ascii_dtostr (amountbuf, sizeof (amountbuf), txn->amount);
89 g_ascii_formatd (amountbuf
, sizeof (amountbuf
), "%.2f", txn
->amount
);
90 g_string_append_printf (elt
, "T%s\n", amountbuf
);
93 if(txn
->status
== TXN_STATUS_CLEARED
)
96 if(txn
->status
== TXN_STATUS_RECONCILED
)
99 g_string_append_printf (elt
, "C%s\n", sbuf
);
101 if( txn
->paymode
== PAYMODE_CHECK
)
102 g_string_append_printf (elt
, "N%s\n", txn
->info
);
105 payee
= da_pay_get(txn
->kpay
);
107 g_string_append_printf (elt
, "P%s\n", payee
->name
);
110 g_string_append_printf (elt
, "M%s\n", txn
->wording
);
112 // LCategory of transaction
113 // L[Transfer account name]
114 // LCategory of transaction/Class of transaction
115 // L[Transfer account]/Class of transaction
116 if( txn
->paymode
== PAYMODE_INTXFER
&& txn
->kacc
== acc
->key
)
119 Account
*dstacc
= da_acc_get(txn
->kxferacc
);
121 g_string_append_printf (elt
, "L[%s]\n", dstacc
->name
);
125 cat
= da_cat_get(txn
->kcat
);
128 txt
= da_cat_get_fullname(cat
);
129 g_string_append_printf (elt
, "L%s\n", txt
);
135 count
= da_splits_count(txn
->splits
);
138 Split
*s
= txn
->splits
[i
];
140 cat
= da_cat_get(s
->kcat
);
143 txt
= da_cat_get_fullname(cat
);
144 g_string_append_printf (elt
, "S%s\n", txt
);
148 g_string_append_printf (elt
, "E%s\n", s
->memo
);
150 g_ascii_formatd (amountbuf
, sizeof (amountbuf
), "%.2f", s
->amount
);
151 g_string_append_printf (elt
, "$%s\n", amountbuf
);
154 g_string_append (elt
, "^\n");
157 list
= g_list_next(list
);
160 g_io_channel_write_chars(io
, elt
->str
, -1, NULL
, NULL
);
162 g_string_free(elt
, TRUE
);
170 static void hb_export_qif_elt_acc(GIOChannel
*io
, Account
*acc
)
175 elt
= g_string_sized_new(255);
178 //#987144 fixed account type
181 case ACC_TYPE_BANK
: type
= "Bank"; break;
182 case ACC_TYPE_CASH
: type
= "Cash"; break;
183 case ACC_TYPE_ASSET
: type
= "Oth A"; break;
184 case ACC_TYPE_CREDITCARD
: type
= "CCard"; break;
185 case ACC_TYPE_LIABILITY
: type
= "Oth L"; break;
186 default : type
= "Bank"; break;
189 g_string_assign(elt
, "!Account\n");
190 g_string_append_printf (elt
, "N%s\n", acc
->name
);
191 g_string_append_printf (elt
, "T%s\n", type
);
192 g_string_append (elt
, "^\n");
193 g_string_append_printf (elt
, "!Type:%s\n", type
);
195 g_io_channel_write_chars(io
, elt
->str
, -1, NULL
, NULL
);
197 g_string_free(elt
, TRUE
);
201 void hb_export_qif_account_single(gchar
*filename
, Account
*acc
)
205 io
= g_io_channel_new_file(filename
, "w", NULL
);
208 g_message("file error on: %s", filename
);
209 //retval = XML_IO_ERROR;
213 hb_export_qif_elt_acc(io
, acc
);
214 hb_export_qif_elt_txn(io
, acc
);
215 g_io_channel_unref (io
);
220 void hb_export_qif_account_all(gchar
*filename
)
225 io
= g_io_channel_new_file(filename
, "w", NULL
);
228 g_message("file error on: %s", filename
);
229 //retval = XML_IO_ERROR;
233 //todo: save accounts in order
234 //todo: save transfer transaction once
236 lacc
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
239 Account
*item
= list
->data
;
241 hb_export_qif_elt_acc(io
, item
);
242 hb_export_qif_elt_txn(io
, item
);
244 list
= g_list_next(list
);
248 g_io_channel_unref (io
);
This page took 0.042221 seconds and 4 git commands to generate.