]>
Dogcows Code - chaz/homebank/blob - src/hb-export.c
9ea94c19916920c42141214a91cdad02a0d5a5f6
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 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
];
48 elt
= g_string_sized_new(255);
52 list
= g_list_first(GLOBALS
->ope_list
);
55 Transaction
*txn
= list
->data
;
60 if( txn
->kacc
== acc
->key
)
62 g_date_set_julian (date
, txn
->date
);
64 switch(PREFS
->dtex_datefmt
)
67 g_string_append_printf (elt
, "D%02d/%02d/%04d\n",
68 g_date_get_month(date
),
74 g_string_append_printf (elt
, "D%02d/%02d/%04d\n",
76 g_date_get_month(date
),
81 g_string_append_printf (elt
, "D%04d/%02d/%02d\n",
82 g_date_get_year(date
),
83 g_date_get_month(date
),
89 //g_ascii_dtostr (amountbuf, sizeof (amountbuf), txn->amount);
90 g_ascii_formatd (amountbuf
, sizeof (amountbuf
), "%.2f", txn
->amount
);
91 g_string_append_printf (elt
, "T%s\n", amountbuf
);
93 g_string_append_printf (elt
, "C%s\n", txn
->flags
& OF_VALID
? "R" : "");
95 if( txn
->paymode
== PAYMODE_CHECK
)
96 g_string_append_printf (elt
, "N%s\n", txn
->info
);
99 payee
= da_pay_get(txn
->kpay
);
101 g_string_append_printf (elt
, "P%s\n", payee
->name
);
104 g_string_append_printf (elt
, "M%s\n", txn
->wording
);
106 // LCategory of transaction
107 // L[Transfer account name]
108 // LCategory of transaction/Class of transaction
109 // L[Transfer account]/Class of transaction
110 if( txn
->paymode
== PAYMODE_INTXFER
&& txn
->kacc
== acc
->key
)
113 Account
*dstacc
= da_acc_get(txn
->kxferacc
);
115 g_string_append_printf (elt
, "L[%s]\n", dstacc
->name
);
119 cat
= da_cat_get(txn
->kcat
);
122 txt
= da_cat_get_fullname(cat
);
123 g_string_append_printf (elt
, "L%s\n", txt
);
129 count
= da_transaction_splits_count(txn
);
132 Split
*s
= txn
->splits
[i
];
134 cat
= da_cat_get(s
->kcat
);
137 txt
= da_cat_get_fullname(cat
);
138 g_string_append_printf (elt
, "S%s\n", txt
);
142 g_string_append_printf (elt
, "E%s\n", s
->memo
);
144 g_ascii_formatd (amountbuf
, sizeof (amountbuf
), "%.2f", s
->amount
);
145 g_string_append_printf (elt
, "$%s\n", amountbuf
);
148 g_string_append (elt
, "^\n");
151 list
= g_list_next(list
);
154 g_io_channel_write_chars(io
, elt
->str
, -1, NULL
, NULL
);
156 g_string_free(elt
, TRUE
);
164 static void hb_export_qif_elt_acc(GIOChannel
*io
, Account
*acc
)
169 elt
= g_string_sized_new(255);
172 //#987144 fixed account type
175 case ACC_TYPE_BANK
: type
= "Bank"; break;
176 case ACC_TYPE_CASH
: type
= "Cash"; break;
177 case ACC_TYPE_ASSET
: type
= "Oth A"; break;
178 case ACC_TYPE_CREDITCARD
: type
= "CCard"; break;
179 case ACC_TYPE_LIABILITY
: type
= "Oth L"; break;
180 default : type
= "Bank"; break;
183 g_string_assign(elt
, "!Account\n");
184 g_string_append_printf (elt
, "N%s\n", acc
->name
);
185 g_string_append_printf (elt
, "T%s\n", type
);
186 g_string_append (elt
, "^\n");
187 g_string_append_printf (elt
, "!Type:%s\n", type
);
189 g_io_channel_write_chars(io
, elt
->str
, -1, NULL
, NULL
);
191 g_string_free(elt
, TRUE
);
195 void hb_export_qif_account_single(gchar
*filename
, Account
*acc
)
199 io
= g_io_channel_new_file(filename
, "w", NULL
);
202 g_message("file error on: %s", filename
);
203 //retval = XML_IO_ERROR;
207 hb_export_qif_elt_acc(io
, acc
);
208 hb_export_qif_elt_txn(io
, acc
);
209 g_io_channel_unref (io
);
214 void hb_export_qif_account_all(gchar
*filename
)
219 io
= g_io_channel_new_file(filename
, "w", NULL
);
222 g_message("file error on: %s", filename
);
223 //retval = XML_IO_ERROR;
227 //todo: save accounts in order
228 //todo: save transfer transaction once
230 lacc
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
233 Account
*item
= list
->data
;
235 hb_export_qif_elt_acc(io
, item
);
236 hb_export_qif_elt_txn(io
, item
);
238 list
= g_list_next(list
);
242 g_io_channel_unref (io
);
248 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
This page took 0.044812 seconds and 4 git commands to generate.