27#include <glib/gi18n.h>
32#include "gnc-component-manager.h"
41#include "gnc-entry-quickfill.h"
43#define GNC_PREF_TAX_INCL "tax-included"
45static const QofLogModule log_module =
"Business Entry Ledger";
48const char* gnc_entry_ledger_type_string_getter (
char flag)
62const char* gnc_entry_ledger_how_string_getter (
char flag)
78static void load_discount_type_cells (GncEntryLedger* ledger)
85 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISTYPE_CELL);
90 gnc_recn_cell_set_flag_order (cell,
"21");
91 gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
94static void load_discount_how_cells (GncEntryLedger* ledger)
101 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISHOW_CELL);
106 gnc_recn_cell_set_flag_order (cell,
"123");
107 gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_how_string_getter);
110static void load_payment_type_cells (GncEntryLedger* ledger)
114 GncEmployee* employee;
116 cell = (
ComboCell*) gnc_table_layout_get_cell (ledger->table->layout,
120 if (!ledger->invoice)
return;
127 g_return_if_fail (employee);
129 gnc_combo_cell_clear_menu (cell);
132 if (gncEmployeeGetCCard (employee))
140skip_expense_acct_cb (
Account* account, gpointer user_data)
146 if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
147 type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
148 type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
154 if (type == ACCT_TYPE_EXPENSE)
return TRUE;
163skip_income_acct_cb (
Account* account, gpointer user_data)
169 if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
170 type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
171 type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
177 if (type == ACCT_TYPE_INCOME)
return TRUE;
188#define EKEY "Expense Business entry quickfill"
189#define IKEY "Income Business entry quickfill"
192load_xfer_type_cells (GncEntryLedger* ledger)
196 QuickFill* qf = NULL;
197 GtkListStore* store = NULL;
199 root = gnc_book_get_root_account (ledger->book);
200 if (root == NULL)
return;
206 switch (ledger->type)
208 case GNCENTRY_ORDER_ENTRY:
209 case GNCENTRY_ORDER_VIEWER:
210 case GNCENTRY_INVOICE_ENTRY:
211 case GNCENTRY_INVOICE_VIEWER:
212 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
213 case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
215 skip_expense_acct_cb, NULL);
216 store = gnc_get_shared_account_name_list_store (root, IKEY,
217 skip_expense_acct_cb, NULL);
220 case GNCENTRY_BILL_ENTRY:
221 case GNCENTRY_BILL_VIEWER:
222 case GNCENTRY_EXPVOUCHER_ENTRY:
223 case GNCENTRY_EXPVOUCHER_VIEWER:
224 case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
225 case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
226 case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
227 case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
228 case GNCENTRY_NUM_REGISTER_TYPES:
230 skip_income_acct_cb, NULL);
231 store = gnc_get_shared_account_name_list_store (root, EKEY,
236 PWARN (
"Bad GncEntryLedgerType");
241 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
243 gnc_combo_cell_use_list_store_cache (cell, store);
246 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
248 gnc_combo_cell_use_list_store_cache (cell, store);
253static void load_taxtable_type_cells (GncEntryLedger* ledger)
259 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXTABLE_CELL);
260 gnc_combo_cell_clear_menu (cell);
262 list = gncTaxTableGetTables (ledger->book);
263 for (; list ; list = list->next)
266 const char* name = gncTaxTableGetName (
table);
273gnc_entry_ledger_show_entry (GncEntryLedger* ledger,
274 VirtualCellLocation start_loc)
276 VirtualCellLocation end_loc;
280 v_row = end_loc.virt_row + 1;
281 end_loc.virt_row = MIN (v_row, ledger->table->num_virt_rows - 1);
286#define DESC_QF_KEY_INVOICES "ENTRY_DESC_CELL_QF_INVOICES"
287#define DESC_QF_KEY_BILLS "ENTRY_DESC_CELL_QF_BILLS"
290load_description_cell (GncEntryLedger* ledger)
292 QuickFill* shared_quickfill;
295 switch (ledger->type)
297 case GNCENTRY_INVOICE_ENTRY:
298 case GNCENTRY_INVOICE_VIEWER:
299 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
300 case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
302 DESC_QF_KEY_INVOICES, TRUE);
306 DESC_QF_KEY_BILLS, FALSE);
311 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DESC_CELL);
315void gnc_entry_ledger_load_xfer_cells (GncEntryLedger* ledger)
317 load_xfer_type_cells (ledger);
318 load_taxtable_type_cells (ledger);
319 load_payment_type_cells (ledger);
320 load_description_cell (ledger);
331 GncEntry* blank_entry, *find_entry;
332 CursorBuffer* cursor_buffer;
337 VirtualCellLocation vcell_loc;
338 VirtualLocation save_loc;
339 gboolean start_primary_color = TRUE;
341 int new_entry_row = -1;
346 load_discount_type_cells (ledger);
347 load_discount_how_cells (ledger);
348 gnc_entry_ledger_load_xfer_cells (ledger);
352 if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL)
355 if (blank_entry == NULL && ledger->invoice)
357 switch (ledger->type)
359 case GNCENTRY_ORDER_ENTRY:
360 case GNCENTRY_INVOICE_ENTRY:
361 case GNCENTRY_BILL_ENTRY:
362 case GNCENTRY_EXPVOUCHER_ENTRY:
363 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
364 case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
365 case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
367 gnc_suspend_gui_refresh();
369 blank_entry = gncEntryCreate (ledger->book);
371 ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
373 gnc_resume_gui_refresh();
376 if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
382 gboolean taxincluded = FALSE;
383 gnc_numeric discount = gnc_numeric_zero();
384 gnc_numeric price = gnc_numeric_zero();
390 price = gncJobGetRate (
gncOwnerGetJob (gncInvoiceGetOwner (ledger->invoice)));
399 case GNC_OWNER_CUSTOMER:
400 taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);
401 discount = gncCustomerGetDiscount (owner->owner.customer);
403 case GNC_OWNER_VENDOR:
404 taxincluded_p = gncVendorGetTaxIncluded (owner->owner.vendor);
411 switch (taxincluded_p)
420 if (ledger->prefs_group)
434 case GNC_OWNER_CUSTOMER:
435 table = gncTaxTableGetDefault (ledger->book,
438 if (gncCustomerGetTaxTableOverride (owner->owner.customer))
439 table = gncCustomerGetTaxTable (owner->owner.customer);
442 case GNC_OWNER_VENDOR:
443 table = gncTaxTableGetDefault (ledger->book,
446 if (gncVendorGetTaxTableOverride (owner->owner.vendor))
447 table = gncVendorGetTaxTable (owner->owner.vendor);
454 if (ledger->is_cust_doc)
456 gncEntrySetInvTaxable (blank_entry,
table != NULL);
457 gncEntrySetInvTaxTable (blank_entry,
table);
458 gncEntrySetInvTaxIncluded (blank_entry, taxincluded);
459 gncEntrySetInvDiscount (blank_entry, discount);
460 gncEntrySetInvPrice (blank_entry, price);
464 gncEntrySetBillTaxable (blank_entry,
table != NULL);
465 gncEntrySetBillTaxTable (blank_entry,
table);
466 gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
467 gncEntrySetBillPrice (blank_entry, price);
476 ledger->blank_entry_edited = FALSE;
479 table = ledger->table;
481 gnc_table_leave_update (
table,
table->current_cursor_loc);
482 save_loc =
table->current_cursor_loc;
485 if (ledger->traverse_to_new)
487 find_entry = blank_entry;
489 else if (ledger->hint_entry)
491 find_entry = ledger->hint_entry;
501 if (gnc_table_current_cursor_changed (
table, TRUE) &&
504 cursor_buffer = gnc_cursor_buffer_new();
505 gnc_table_save_current_cursor (
table, cursor_buffer);
508 cursor_buffer = NULL;
512 gnc_table_control_allow_move (
table->control, FALSE);
516 VirtualLocation virt_loc;
518 virt_loc.vcell_loc.virt_row = -1;
519 virt_loc.vcell_loc.virt_col = -1;
520 virt_loc.phys_row_offset = -1;
521 virt_loc.phys_col_offset = -1;
527 vcell_loc.virt_row = 0;
528 vcell_loc.virt_col = 0;
531 vcell_loc.virt_row++;
534 table->model->dividing_row_upper = -1;
535 table->model->dividing_row = -1;
536 table->model->dividing_row_lower = -1;
537 cursor = gnc_table_layout_get_cursor (
table->layout,
"cursor");
540 for (node = entry_list; node; node = node->next)
542 GncEntry* entry = node->data;
545 if (entry == blank_entry)
553 if (entry == find_entry)
554 new_entry_row = vcell_loc.virt_row;
557 TRUE, start_primary_color, vcell_loc);
558 vcell_loc.virt_row++;
561 start_primary_color = !start_primary_color;
568 TRUE, start_primary_color, vcell_loc);
570 if (find_entry == blank_entry)
571 new_entry_row = vcell_loc.virt_row;
573 vcell_loc.virt_row++;
580 if (new_entry_row > 0)
581 save_loc.vcell_loc.virt_row = new_entry_row;
588 gnc_table_restore_current_cursor (
table, cursor_buffer);
591 gnc_cursor_buffer_destroy (cursor_buffer);
592 cursor_buffer = NULL;
595 ledger->traverse_to_new = FALSE;
596 ledger->hint_entry = NULL;
602 gnc_entry_ledger_show_entry (ledger,
table->current_cursor_loc.vcell_loc);
607 gnc_table_layout_get_cell (
table->layout, ENTRY_IACCT_CELL),
608 gnc_get_account_separator());
612 gnc_table_layout_get_cell (
table->layout, ENTRY_BACCT_CELL),
613 gnc_get_account_separator());
616 gnc_table_control_allow_move (
table->control, TRUE);
Account handling public routines.
Create an account-name quick-fill.
Generic api to store and retrieve preferences.
utility functions for the GnuCash UI
Business Entry Interface.
QuickFill * gnc_get_shared_account_name_quickfill(Account *root, const char *key, AccountBoolCB cb, gpointer cb_data)
Create/fetch a quickfill of account names.
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
GncEntry * gnc_entry_ledger_get_current_entry(GncEntryLedger *ledger)
Returns the Entry where the cursor is currently located.
GncEntry * gnc_entry_ledger_get_blank_entry(GncEntryLedger *ledger)
Exported Functions.
void gnc_entry_ledger_load(GncEntryLedger *ledger, GList *entry_list)
Copy GncEntry information from the list to the rows of the Ledger.
void gnc_quickfill_cell_use_quickfill_cache(QuickFillCell *cell, QuickFill *shared_qf)
Lets the cell use the given shared quickfill object instead of the one it owns internally.
void gnc_combo_cell_set_complete_char(ComboCell *cell, gunichar complete_char)
Sets a character used for special completion processing.
void gnc_combo_cell_use_quickfill_cache(ComboCell *cell, QuickFill *shared_qf)
Tell the combocell to use a shared QuickFill object.
void gnc_recn_cell_set_valid_flags(RecnCell *cell, const char *flags, char default_flag)
note that chars is copied into the RecnCell directly, but remains the "property" of the caller.
void gnc_combo_cell_add_menu_item(ComboCell *cell, const char *menustr)
Add a menu item to the list.
gboolean xaccAccountGetPlaceholder(const Account *acc)
Get the "placeholder" flag for an account.
void gncEntrySetDateGDate(GncEntry *entry, const GDate *date)
Set the date of this entry.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
#define PWARN(format, args...)
Log a warning.
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object.
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
QuickFill * gnc_get_shared_entry_desc_quickfill(QofBook *book, const char *key, gboolean use_invoices)
Similar to the Account Names account name quickfill, we create a cached quickfill with the descriptio...
void gnc_table_refresh_gui(Table *table, gboolean do_scroll)
Refresh the whole GUI from the table.
void gnc_table_move_cursor_gui(Table *table, VirtualLocation new_virt_loc)
will move the cursor and its GUI to the indicated location.
void gnc_table_set_size(Table *table, int virt_rows, int virt_cols)
The gnc_table_set_size() method will resize the table to the indicated dimensions.
gboolean gnc_table_find_close_valid_cell(Table *table, VirtualLocation *virt_loc, gboolean exact_pointer)
Find a close valid cell.
void gnc_table_show_range(Table *table, VirtualCellLocation start_loc, VirtualCellLocation end_loc)
Try to show the whole range in the register.
#define CURSOR_HEADER
Standard Cursor Names.
void gnc_table_set_vcell(Table *table, CellBlock *cursor, gconstpointer vcell_data, gboolean visible, gboolean start_primary_color, VirtualCellLocation vcell_loc)
Indicate what handler should be used for a given virtual block.
GncTaxIncluded
How to interpret the TaxIncluded.
@ GNC_TAXINCLUDED_NO
tax is not included
@ GNC_TAXINCLUDED_YES
tax is included
@ GNC_TAXINCLUDED_USEGLOBAL
use the global setting
The ComboCell object implements a cell handler with a "combination-box" pull-down menu in it.
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability....
The QuickFillCell implements a text cell with quick-fill capabilities.
The RecnCell object implements a cell handler that will cycle through a series of single-character va...