-
Notifications
You must be signed in to change notification settings - Fork 761
/
Ledger.c
159 lines (122 loc) · 3.86 KB
/
Ledger.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* FILE:
* Ledger.c
*
* FUNCTION:
* copy transaction data into ledger
*/
#include "Ledger.h"
#include "register.h"
#include "Transaction.h"
#define BUFSIZE 1024
/* ======================================================== */
static void
LedgerMoveCursor (struct _Table *_table, void * client_data)
{
Table * table = (Table *)_table;
BasicRegister *reg = (BasicRegister *) client_data;
xaccSaveRegEntry (reg);
}
/* ======================================================== */
Split * xaccGetCurrentSplit (BasicRegister *reg)
{
CellBlock *cursor;
Split *split;
/* get the handle to the current split and transaction */
cursor = reg->table->cursor;
split = (Split *) cursor->user_data;
return split;
}
/* ======================================================== */
void
xaccSaveRegEntry (BasicRegister *reg)
{
Split *split;
Transaction *trans;
/* get the handle to the current split and transaction */
split = xaccGetCurrentSplit (reg);
if (!split) return;
trans = (Transaction *) (split->parent);
/* copy the contents from the cursor to the split */
xaccTransSetDate (trans, reg->dateCell->date.tm_mday,
reg->dateCell->date.tm_mon+1,
reg->dateCell->date.tm_year+1900);
xaccTransSetNum (trans, reg->numCell->value);
xaccTransSetDescription (trans, reg->descCell->cell.value);
xaccSplitSetMemo (split, reg->memoCell->value);
xaccSplitSetAction (split, reg->actionCell->cell.value);
xaccSplitSetReconcile (split, reg->recnCell->value[0]);
}
/* ======================================================== */
void
xaccLoadRegEntry (BasicRegister *reg, Split *split)
{
Transaction *trans;
char buff[2];
if (!split) return;
trans = (Transaction *) (split->parent);
xaccSetDateCellValue (reg->dateCell, trans->date.day,
trans->date.month,
trans->date.year);
xaccSetBasicCellValue (reg->numCell, trans->num);
xaccSetBasicCellValue (&(reg->actionCell->cell), split->action);
xaccSetQuickFillCellValue (reg->descCell, trans->description);
xaccSetBasicCellValue (reg->memoCell, split->memo);
buff[0] = split->reconciled;
buff[1] = 0x0;
xaccSetBasicCellValue (reg->recnCell, buff);
xaccSetDebCredCellValue (reg->debitCell,
reg->creditCell, split->damount);
xaccSetAmountCellValue (reg->balanceCell, split->balance);
reg->table->cursor->user_data = (void *) split;
/* copy cursor contents into the table */
xaccCommitCursor (reg->table);
}
/* ======================================================== */
void
xaccLoadRegister (BasicRegister *reg, Split **slist)
{
int i;
Split *split;
Transaction *trans;
char buff[BUFSIZE];
Table *table;
table = reg->table;
/* disable callback */
table->move_cursor = NULL;
/* set table size to number of items in list */
i=0;
while (slist[i]) i++;
xaccSetTableSize (table, i, 1);
/* populate the table */
i=0;
split = slist[0];
while (split) {
xaccMoveCursor (table, i, 0);
xaccLoadRegEntry (reg, split);
i++;
split = slist[i];
}
xaccRefreshTableGUI (table);
/* enable callback for cursor moves */
table->move_cursor = LedgerMoveCursor;
table->client_data = (void *) reg;
}
/* ======================================================== */
void xaccLoadXferCell (ComboCell *cell, AccountGroup *grp)
{
Account * acc;
int n;
if (!grp) return;
/* build the xfer menu out of account names */
/* traverse sub-accounts ecursively */
n = 0;
acc = getAccount (grp, n);
while (acc) {
xaccAddComboCellMenuItem (cell, acc->accountName);
xaccLoadXferCell (cell, acc->children);
n++;
acc = getAccount (grp, n);
}
}
/* ======================= end of file =================== */