27 #include <glib/gi18n.h>
32 #include "gnc-component-manager.h"
37 #include "business-helpers.h"
40 #include "gncEntryLedger.h"
41 #include "gncEntryLedgerP.h"
42 #include "quickfillcell.h"
43 #include "app-utils/gnc-entry-quickfill.h"
45 #define GNC_PREF_TAX_INCL "tax-included"
47 static const QofLogModule log_module =
"Business Entry Ledger";
50 const char * gnc_entry_ledger_type_string_getter (
char flag)
64 const char * gnc_entry_ledger_how_string_getter (
char flag)
87 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISTYPE_CELL);
91 gnc_recn_cell_set_valid_flags (cell,
"12",
'2');
92 gnc_recn_cell_set_flag_order (cell,
"21");
93 gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
103 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISHOW_CELL);
107 gnc_recn_cell_set_valid_flags (cell,
"123",
'1');
108 gnc_recn_cell_set_flag_order (cell,
"123");
109 gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_how_string_getter);
118 cell = (
ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
122 if (!ledger->invoice)
return;
129 g_return_if_fail (employee);
131 gnc_combo_cell_clear_menu (cell);
134 if (gncEmployeeGetCCard (employee))
142 skip_expense_acct_cb (
Account *account, gpointer user_data)
165 skip_income_acct_cb (
Account *account, gpointer user_data)
190 #define EKEY "Expense Business entry quickfill"
191 #define IKEY "Income Business entry quickfill"
199 GtkListStore *store = NULL;
201 root = gnc_book_get_root_account (ledger->book);
202 if (root == NULL)
return;
208 switch (ledger->type)
210 case GNCENTRY_ORDER_ENTRY:
211 case GNCENTRY_ORDER_VIEWER:
212 case GNCENTRY_INVOICE_ENTRY:
213 case GNCENTRY_INVOICE_VIEWER:
214 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
215 case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
217 skip_expense_acct_cb, NULL);
218 store = gnc_get_shared_account_name_list_store (root, IKEY,
219 skip_expense_acct_cb, NULL);
222 case GNCENTRY_BILL_ENTRY:
223 case GNCENTRY_BILL_VIEWER:
224 case GNCENTRY_EXPVOUCHER_ENTRY:
225 case GNCENTRY_EXPVOUCHER_VIEWER:
226 case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
227 case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
228 case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
229 case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
230 case GNCENTRY_NUM_REGISTER_TYPES:
232 skip_income_acct_cb, NULL);
233 store = gnc_get_shared_account_name_list_store (root, EKEY,
234 skip_income_acct_cb, NULL);
237 PWARN (
"Bad GncEntryLedgerType");
242 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
244 gnc_combo_cell_use_list_store_cache (cell, store);
247 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
249 gnc_combo_cell_use_list_store_cache (cell, store);
260 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXTABLE_CELL);
261 gnc_combo_cell_clear_menu (cell);
263 list = gncTaxTableGetTables (ledger->book);
264 for ( ; list ; list = list->next )
267 const char *name = gncTaxTableGetName (table);
281 v_row = end_loc.virt_row + 1;
282 end_loc.virt_row = MIN (v_row, ledger->table->num_virt_rows - 1);
284 gnc_table_show_range (ledger->table, start_loc, end_loc);
287 #define DESC_QF_KEY_INVOICES "ENTRY_DESC_CELL_QF_INVOICES"
288 #define DESC_QF_KEY_BILLS "ENTRY_DESC_CELL_QF_BILLS"
296 switch (ledger->type)
298 case GNCENTRY_INVOICE_ENTRY:
299 case GNCENTRY_INVOICE_VIEWER:
300 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
301 case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
310 gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DESC_CELL);
311 gnc_quickfill_cell_use_quickfill_cache (cell, shared_quickfill);
316 load_xfer_type_cells (ledger);
317 load_taxtable_type_cells (ledger);
318 load_payment_type_cells (ledger);
319 load_description_cell (ledger);
328 void gnc_entry_ledger_load (
GncEntryLedger *ledger, GList *entry_list)
338 gboolean start_primary_color = TRUE;
340 int new_entry_row = -1;
345 load_discount_type_cells (ledger);
346 load_discount_how_cells (ledger);
347 gnc_entry_ledger_load_xfer_cells (ledger);
349 blank_entry = gnc_entry_ledger_get_blank_entry (ledger);
351 if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL)
354 if (blank_entry == NULL && ledger->invoice)
356 switch (ledger->type)
358 case GNCENTRY_ORDER_ENTRY:
359 case GNCENTRY_INVOICE_ENTRY:
360 case GNCENTRY_BILL_ENTRY:
361 case GNCENTRY_EXPVOUCHER_ENTRY:
362 case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
363 case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
364 case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
366 gnc_suspend_gui_refresh ();
368 blank_entry = gncEntryCreate (ledger->book);
370 ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
372 gnc_resume_gui_refresh ();
375 if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
380 gboolean taxincluded = FALSE;
388 price = gncJobGetRate(
gncOwnerGetJob (gncInvoiceGetOwner (ledger->invoice)));
397 case GNC_OWNER_CUSTOMER:
398 taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);
399 discount = gncCustomerGetDiscount (owner->owner.customer);
401 case GNC_OWNER_VENDOR:
402 taxincluded_p = gncVendorGetTaxIncluded (owner->owner.vendor);
409 switch (taxincluded_p)
418 if (ledger->prefs_group)
432 case GNC_OWNER_CUSTOMER:
433 table = gnc_business_get_default_tax_table (ledger->book,
436 if (gncCustomerGetTaxTableOverride (owner->owner.customer))
437 table = gncCustomerGetTaxTable (owner->owner.customer);
440 case GNC_OWNER_VENDOR:
441 table = gnc_business_get_default_tax_table (ledger->book,
444 if (gncVendorGetTaxTableOverride (owner->owner.vendor))
445 table = gncVendorGetTaxTable (owner->owner.vendor);
452 if (ledger->is_cust_doc)
454 gncEntrySetInvTaxTable (blank_entry, table);
455 gncEntrySetInvTaxIncluded (blank_entry, taxincluded);
456 gncEntrySetInvDiscount (blank_entry, discount);
457 gncEntrySetInvPrice (blank_entry, price);
461 gncEntrySetBillTaxTable (blank_entry, table);
462 gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
463 gncEntrySetBillPrice (blank_entry, price);
469 ledger->blank_entry_guid = *
guid_null ();
472 ledger->blank_entry_edited = FALSE;
475 table = ledger->table;
477 gnc_table_leave_update (table, table->current_cursor_loc);
478 save_loc = table->current_cursor_loc;
481 if (ledger->traverse_to_new)
483 find_entry = blank_entry;
485 else if (ledger->hint_entry)
487 find_entry = ledger->hint_entry;
491 find_entry = gnc_entry_ledger_get_current_entry(ledger);
497 if (gnc_table_current_cursor_changed (table, TRUE) &&
498 (find_entry == gnc_entry_ledger_get_current_entry (ledger)))
500 cursor_buffer = gnc_cursor_buffer_new ();
501 gnc_table_save_current_cursor (table, cursor_buffer);
504 cursor_buffer = NULL;
508 gnc_table_control_allow_move (table->control, FALSE);
514 virt_loc.vcell_loc.virt_row = -1;
515 virt_loc.vcell_loc.virt_col = -1;
516 virt_loc.phys_row_offset = -1;
517 virt_loc.phys_col_offset = -1;
519 gnc_table_move_cursor_gui (table, virt_loc);
523 vcell_loc.virt_row = 0;
524 vcell_loc.virt_col = 0;
525 cursor_header = gnc_table_layout_get_cursor (table->layout, CURSOR_HEADER);
526 gnc_table_set_vcell (table, cursor_header, NULL, TRUE, TRUE, vcell_loc);
527 vcell_loc.virt_row++;
530 table->model->dividing_row_upper = -1;
531 table->model->dividing_row = -1;
532 table->model->dividing_row_lower = -1;
533 cursor = gnc_table_layout_get_cursor (table->layout,
"cursor");
536 for (node = entry_list; node; node = node->next)
541 if (entry == blank_entry)
549 if (entry == find_entry)
550 new_entry_row = vcell_loc.virt_row;
552 gnc_table_set_vcell (table, cursor, gncEntryGetGUID (entry),
553 TRUE, start_primary_color, vcell_loc);
554 vcell_loc.virt_row++;
557 start_primary_color = !start_primary_color;
563 gnc_table_set_vcell (table, cursor, gncEntryGetGUID (blank_entry),
564 TRUE, start_primary_color, vcell_loc);
566 if (find_entry == blank_entry)
567 new_entry_row = vcell_loc.virt_row;
569 vcell_loc.virt_row++;
573 gnc_table_set_size (table, vcell_loc.virt_row, 1);
576 if (new_entry_row > 0)
577 save_loc.vcell_loc.virt_row = new_entry_row;
579 if (gnc_table_find_close_valid_cell (table, &save_loc, FALSE))
581 gnc_table_move_cursor_gui (table, save_loc);
583 if (find_entry == gnc_entry_ledger_get_current_entry (ledger))
584 gnc_table_restore_current_cursor (table, cursor_buffer);
587 gnc_cursor_buffer_destroy (cursor_buffer);
588 cursor_buffer = NULL;
591 ledger->traverse_to_new = FALSE;
592 ledger->hint_entry = NULL;
597 gnc_table_refresh_gui (table, TRUE);
598 gnc_entry_ledger_show_entry (ledger, table->current_cursor_loc.vcell_loc);
603 gnc_table_layout_get_cell (table->layout, ENTRY_IACCT_CELL),
604 gnc_get_account_separator ());
608 gnc_table_layout_get_cell (table->layout, ENTRY_BACCT_CELL),
609 gnc_get_account_separator ());
612 gnc_table_control_allow_move (table->control, TRUE);
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
Create an account-name quick-fill.
void gnc_combo_cell_use_quickfill_cache(ComboCell *cell, QuickFill *shared_qf)
QuickFill * gnc_get_shared_account_name_quickfill(Account *root, const char *key, AccountBoolCB cb, gpointer cb_data)
#define PWARN(format, args...)
Account handling public routines.
void gnc_combo_cell_set_complete_char(ComboCell *cell, gunichar complete_char)
void gnc_combo_cell_add_menu_item(ComboCell *cell, const char *menustr)
The ComboCell object implements a cell handler with a "combination-box" pull-down menu in it...
void gncEntrySetDateGDate(GncEntry *entry, const GDate *date)
Generic api to store and retrieve preferences.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
GncJob * gncOwnerGetJob(const GncOwner *owner)
const GncGUID * guid_null(void)
gboolean xaccAccountGetPlaceholder(const Account *acc)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
QuickFill * gnc_get_shared_entry_desc_quickfill(QofBook *book, const char *key, gboolean use_invoices)
Business Entry Interface.
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
const gchar * QofLogModule