GnuCash  5.6-133-gc519490283+
Files | Data Structures | Macros | Enumerations | Functions

A specialized register for Accounts Payable and Accounts Receivable. More...

Files

file  gncEntryLedger.h
 
file  gncEntryLedgerControl.h
 
file  gncEntryLedgerLayout.h
 
file  gncEntryLedgerModel.h
 
file  gncEntryLedgerP.h
 

Data Structures

struct  GncEntryLedger
 

Macros

#define ENTRY_IACCT_CELL   "inv-account"
 
#define ENTRY_BACCT_CELL   "bill-account"
 
#define ENTRY_ACTN_CELL   "action"
 
#define ENTRY_DATE_CELL   "date"
 
#define ENTRY_DESC_CELL   "description"
 
#define ENTRY_DISC_CELL   "discount"
 
#define ENTRY_DISTYPE_CELL   "discount-type"
 
#define ENTRY_DISHOW_CELL   "discount-how"
 
#define ENTRY_PRIC_CELL   "price"
 
#define ENTRY_QTY_CELL   "quantity"
 
#define ENTRY_TAXABLE_CELL   "istaxable"
 
#define ENTRY_TAXTABLE_CELL   "taxtable"
 
#define ENTRY_TAXINCLUDED_CELL   "taxincluded"
 
#define ENTRY_BILLABLE_CELL   "isbillable"
 
#define ENTRY_INV_CELL   "isinvoiced"
 
#define ENTRY_VALUE_CELL   "line-value"
 
#define ENTRY_TAXVAL_CELL   "line-tax-val"
 
#define ENTRY_PAYMENT_CELL   "payment"
 

Enumerations

enum  GncEntryLedgerType {
  GNC_ENTRY_ORDER_NONE = -1, GNCENTRY_ORDER_ENTRY, GNCENTRY_ORDER_VIEWER, GNCENTRY_INVOICE_ENTRY,
  GNCENTRY_INVOICE_VIEWER, GNCENTRY_CUST_CREDIT_NOTE_ENTRY, GNCENTRY_CUST_CREDIT_NOTE_VIEWER, GNCENTRY_BILL_ENTRY,
  GNCENTRY_BILL_VIEWER, GNCENTRY_VEND_CREDIT_NOTE_ENTRY, GNCENTRY_VEND_CREDIT_NOTE_VIEWER, GNCENTRY_EXPVOUCHER_ENTRY,
  GNCENTRY_EXPVOUCHER_VIEWER, GNCENTRY_EMPL_CREDIT_NOTE_ENTRY, GNCENTRY_EMPL_CREDIT_NOTE_VIEWER, GNCENTRY_NUM_REGISTER_TYPES
}
 

Functions

GncEntryLedger * gnc_entry_ledger_new (QofBook *book, GncEntryLedgerType type)
 Create and return a new GncEntry Ledger.
 
void gnc_entry_ledger_set_default_order (GncEntryLedger *ledger, GncOrder *order)
 Set the default order for this ledger.
 
void gnc_entry_ledger_set_default_invoice (GncEntryLedger *ledger, GncInvoice *invoice)
 Set the default invoice for this ledger.
 
void gnc_entry_ledger_destroy (GncEntryLedger *ledger)
 Destroy the GncEntry Ledger.
 
GncEntry * gnc_entry_ledger_get_current_entry (GncEntryLedger *ledger)
 Returns the Entry where the cursor is currently located. More...
 
void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
 Copy GncEntry information from the list to the rows of the Ledger. More...
 
void gnc_entry_ledger_display_refresh (GncEntryLedger *ledger)
 
Table * gnc_entry_ledger_get_table (GncEntryLedger *ledger)
 Get the Table.
 
void gnc_entry_ledger_set_parent (GncEntryLedger *ledger, GtkWidget *parent)
 
void gnc_entry_ledger_set_readonly (GncEntryLedger *ledger, gboolean readonly)
 
gboolean gnc_entry_ledger_changed (GncEntryLedger *ledger)
 
void gnc_entry_ledger_cancel_cursor_changes (GncEntryLedger *ledger)
 
gboolean gnc_entry_ledger_commit_entry (GncEntryLedger *ledger)
 This will act just like hitting 'return' to record an entry.
 
gboolean gnc_entry_ledger_check_close (GtkWidget *parent, GncEntryLedger *ledger)
 This will ask the user if they really want to make a change.
 
void gnc_entry_ledger_reset_query (GncEntryLedger *ledger)
 
GncEntry * gnc_entry_ledger_get_entry (GncEntryLedger *ledger, VirtualCellLocation vcell_loc)
 Returns the GncEntry at the given location, or NULL if the location is not valid. More...
 
GncEntry * gnc_entry_ledger_get_blank_entry (GncEntryLedger *ledger)
 Returns the GncEntry that represents the blank new line at the bottom of the ledger. More...
 
gboolean gnc_entry_ledger_get_entry_virt_loc (GncEntryLedger *ledger, const GncEntry *entry, VirtualCellLocation *vcell_loc)
 Looks up the cell location of the given "entry" and writes the location into the variable pointed to by vcell_loc (which must be non-NULL). More...
 
void gnc_entry_ledger_delete_current_entry (GncEntryLedger *ledger)
 
void gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger)
 
void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger, gboolean move_up)
 This implements the command of moving the current entry (where the cursor is currently located) one row upwards or downwards, effectively swapping this row and the other row. More...
 
QofQuerygnc_entry_ledger_get_query (GncEntryLedger *ledger)
 
void gnc_entry_ledger_set_prefs_group (GncEntryLedger *ledger, const gchar *string)
 
TableControlgnc_entry_ledger_control_new (void)
 
TableLayout * gnc_entry_ledger_layout_new (GncEntryLedger *ledger)
 
TableModelgnc_entry_ledger_model_new (GncEntryLedgerType type)
 Public Interface.
 
Accountgnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell *bcell, const char *name, gboolean *isnew)
 
Accountgnc_entry_ledger_get_account (GncEntryLedger *ledger, const char *cell_name)
 
GncTaxTablegnc_entry_ledger_get_taxtable (GncEntryLedger *ledger, const char *cell_name)
 
gint gnc_entry_ledger_get_type (GncEntryLedger *ledger, const char *cell_name)
 
gboolean gnc_entry_ledger_get_checkmark (GncEntryLedger *ledger, const char *cell_name)
 
gboolean gnc_entry_ledger_get_numeric (GncEntryLedger *ledger, const char *cell_name, gnc_numeric *value)
 
const char * gnc_entry_ledger_type_string_getter (char flag)
 
const char * gnc_entry_ledger_how_string_getter (char flag)
 
gboolean gnc_entry_ledger_find_entry (GncEntryLedger *ledger, GncEntry *entry, VirtualCellLocation *vcell_loc)
 
void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
 
void gnc_entry_ledger_display_init (GncEntryLedger *ledger)
 
void gnc_entry_ledger_display_fini (GncEntryLedger *ledger)
 
void gnc_entry_ledger_compute_value (GncEntryLedger *ledger, gnc_numeric *value, gnc_numeric *tax_value)
 

Detailed Description

A specialized register for Accounts Payable and Accounts Receivable.

Function Documentation

◆ gnc_entry_ledger_get_blank_entry()

GncEntry* gnc_entry_ledger_get_blank_entry ( GncEntryLedger *  ledger)

Returns the GncEntry that represents the blank new line at the bottom of the ledger.

Returns the GncEntry that represents the blank new line at the bottom of the ledger.

Definition at line 75 of file gncEntryLedger.c.

76 {
77  if (!ledger) return NULL;
78  return gncEntryLookup (ledger->book, &(ledger->blank_entry_guid));
79 }

◆ gnc_entry_ledger_get_current_entry()

GncEntry* gnc_entry_ledger_get_current_entry ( GncEntryLedger *  ledger)

Returns the Entry where the cursor is currently located.

Definition at line 232 of file gncEntryLedger.c.

233 {
234  if (!ledger) return NULL;
235 
236  return
238  ledger->table->current_cursor_loc.vcell_loc);
239 }
GncEntry * gnc_entry_ledger_get_entry(GncEntryLedger *ledger, VirtualCellLocation vcell_loc)
Returns the GncEntry at the given location, or NULL if the location is not valid. ...

◆ gnc_entry_ledger_get_entry()

GncEntry* gnc_entry_ledger_get_entry ( GncEntryLedger *  ledger,
VirtualCellLocation  vcell_loc 
)

Returns the GncEntry at the given location, or NULL if the location is not valid.

Definition at line 218 of file gncEntryLedger.c.

220 {
221  GncGUID *guid;
222 
223  if (!ledger) return NULL;
224 
225  guid = gnc_table_get_vcell_data (ledger->table, vcell_loc);
226  if (!guid) return NULL;
227 
228  return gncEntryLookup (ledger->book, guid);
229 }
gpointer gnc_table_get_vcell_data(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell data associated with a cursor located at the given virtual coords...
Definition: table-allgui.c:932
The type used to store guids in C.
Definition: guid.h:75

◆ gnc_entry_ledger_get_entry_virt_loc()

gboolean gnc_entry_ledger_get_entry_virt_loc ( GncEntryLedger *  ledger,
const GncEntry *  entry,
VirtualCellLocation *  vcell_loc 
)

Looks up the cell location of the given "entry" and writes the location into the variable pointed to by vcell_loc (which must be non-NULL).

Returns TRUE if the entry was found, otherwise FALSE.

Definition at line 788 of file gncEntryLedger.c.

790 {
791  Table *table;
792  int v_row;
793  int v_col;
794 
795  if ((ledger == NULL) || (entry == NULL))
796  return FALSE;
797  g_assert(vcell_loc);
798 
799  table = ledger->table;
800 
801  /* go backwards because typically you search for entries at the end */
802 
803  for (v_row = table->num_virt_rows - 1; v_row > 0; v_row--)
804  for (v_col = 0; v_col < table->num_virt_cols; v_col++)
805  {
806  VirtualCellLocation vc_loc = { v_row, v_col };
807  VirtualCell *vcell;
808  GncEntry *e;
809 
810  vcell = gnc_table_get_virtual_cell (table, vc_loc);
811  if (vcell == NULL)
812  continue;
813 
814  if (!vcell->visible)
815  continue;
816 
817  e = gncEntryLookup (ledger->book, vcell->vcell_data);
818 
819  if (e == entry)
820  {
821  if (vcell_loc)
822  *vcell_loc = vc_loc;
823 
824  return TRUE;
825  }
826  }
827 
828  return FALSE;
829 }
gpointer vcell_data
Array of physical cells.
Definition: table-allgui.h:135
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227
unsigned int visible
Used by higher-level code.
Definition: table-allgui.h:138

◆ gnc_entry_ledger_load()

void gnc_entry_ledger_load ( GncEntryLedger *  ledger,
GList *  entry_list 
)

Copy GncEntry information from the list to the rows of the Ledger.

Definition at line 329 of file gncEntryLedgerLoad.c.

330 {
331  GncEntry* blank_entry, *find_entry;
332  CursorBuffer* cursor_buffer;
333  Table* table;
334 
335  GList* node;
336  CellBlock* cursor_header, *cursor;
337  VirtualCellLocation vcell_loc;
338  VirtualLocation save_loc;
339  gboolean start_primary_color = TRUE;
340 
341  int new_entry_row = -1;
342 
343  if (!ledger) return;
344 
345  /* Load up cells */
346  load_discount_type_cells (ledger);
347  load_discount_how_cells (ledger);
348  gnc_entry_ledger_load_xfer_cells (ledger);
349 
350  blank_entry = gnc_entry_ledger_get_blank_entry (ledger);
351 
352  if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL)
353  return;
354 
355  if (blank_entry == NULL && ledger->invoice)
356  {
357  switch (ledger->type)
358  {
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:
366 
367  gnc_suspend_gui_refresh();
368 
369  blank_entry = gncEntryCreate (ledger->book);
370  gncEntrySetDateGDate (blank_entry, &ledger->last_date_entered);
371  ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
372 
373  gnc_resume_gui_refresh();
374 
375  /* The rest of this does not apply to expense vouchers */
376  if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
377  {
378  const GncOwner* owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (
379  ledger->invoice));
380  GncTaxTable* table = NULL;
382  gboolean taxincluded = FALSE;
383  gnc_numeric discount = gnc_numeric_zero();
384  gnc_numeric price = gnc_numeric_zero();
385 
386  /* Determine the Price from Customer's or Vendor's Job */
387  switch (gncOwnerGetType (gncInvoiceGetOwner (ledger->invoice)))
388  {
389  case GNC_OWNER_JOB:
390  price = gncJobGetRate (gncOwnerGetJob (gncInvoiceGetOwner (ledger->invoice)));
391  break;
392  default:
393  break;
394  }
395 
396  /* Determine the TaxIncluded and Discount values */
397  switch (gncOwnerGetType (owner))
398  {
399  case GNC_OWNER_CUSTOMER:
400  taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);
401  discount = gncCustomerGetDiscount (owner->owner.customer);
402  break;
403  case GNC_OWNER_VENDOR:
404  taxincluded_p = gncVendorGetTaxIncluded (owner->owner.vendor);
405  break;
406  default:
407  break;
408  }
409 
410  /* Compute the default taxincluded */
411  switch (taxincluded_p)
412  {
413  case GNC_TAXINCLUDED_YES:
414  taxincluded = TRUE;
415  break;
416  case GNC_TAXINCLUDED_NO:
417  taxincluded = FALSE;
418  break;
420  if (ledger->prefs_group)
421  {
422  taxincluded = gnc_prefs_get_bool (ledger->prefs_group, GNC_PREF_TAX_INCL);
423  }
424  else
425  {
426  taxincluded = FALSE;
427  }
428  break;
429  }
430 
431  /* Compute the proper taxtable */
432  switch (gncOwnerGetType (owner))
433  {
434  case GNC_OWNER_CUSTOMER:
435  table = gncTaxTableGetDefault (ledger->book,
436  GNC_OWNER_CUSTOMER);
437 
438  if (gncCustomerGetTaxTableOverride (owner->owner.customer))
439  table = gncCustomerGetTaxTable (owner->owner.customer);
440  break;
441 
442  case GNC_OWNER_VENDOR:
443  table = gncTaxTableGetDefault (ledger->book,
444  GNC_OWNER_VENDOR);
445 
446  if (gncVendorGetTaxTableOverride (owner->owner.vendor))
447  table = gncVendorGetTaxTable (owner->owner.vendor);
448  break;
449 
450  default:
451  break;
452  }
453 
454  if (ledger->is_cust_doc)
455  {
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);
461  }
462  else
463  {
464  gncEntrySetBillTaxable (blank_entry, table != NULL);
465  gncEntrySetBillTaxTable (blank_entry, table);
466  gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
467  gncEntrySetBillPrice (blank_entry, price);
468  }
469  }
470 
471  break;
472  default:
473  ledger->blank_entry_guid = *guid_null();
474  break;
475  }
476  ledger->blank_entry_edited = FALSE;
477  }
478 
479  table = ledger->table;
480 
481  gnc_table_leave_update (table, table->current_cursor_loc);
482  save_loc = table->current_cursor_loc;
483 
484  /* Figure out where we are going to */
485  if (ledger->traverse_to_new)
486  {
487  find_entry = blank_entry;
488  }
489  else if (ledger->hint_entry)
490  {
491  find_entry = ledger->hint_entry;
492  }
493  else
494  {
495  find_entry = gnc_entry_ledger_get_current_entry (ledger);
496  /* XXX: get current entry (cursor_hint_xxx) */
497  }
498 
499  /* If the current cursor has changed we save the values for later
500  * possible restoration. */
501  if (gnc_table_current_cursor_changed (table, TRUE) &&
502  (find_entry == gnc_entry_ledger_get_current_entry (ledger)))
503  {
504  cursor_buffer = gnc_cursor_buffer_new();
505  gnc_table_save_current_cursor (table, cursor_buffer);
506  }
507  else
508  cursor_buffer = NULL;
509 
510  /* disable move callback -- we don't want the cascade of
511  * callbacks while we are fiddling with loading the register */
512  gnc_table_control_allow_move (table->control, FALSE);
513 
514  /* invalidate the cursor */
515  {
516  VirtualLocation virt_loc;
517 
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;
522 
523  gnc_table_move_cursor_gui (table, virt_loc);
524  }
525 
526  /* make sure that the header is loaded */
527  vcell_loc.virt_row = 0;
528  vcell_loc.virt_col = 0;
529  cursor_header = gnc_table_layout_get_cursor (table->layout, CURSOR_HEADER);
530  gnc_table_set_vcell (table, cursor_header, NULL, TRUE, TRUE, vcell_loc);
531  vcell_loc.virt_row++;
532 
533  /* get the current time and reset the dividing 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");
538 
539  /* Populate the table */
540  for (node = entry_list; node; node = node->next)
541  {
542  GncEntry* entry = node->data;
543 
544  /* Don't load the blank entry */
545  if (entry == blank_entry)
546  continue;
547 
548  /* If this is the first load of the ledger, fill the quickfill cells */
549  {
550  /* XXX */
551  }
552 
553  if (entry == find_entry)
554  new_entry_row = vcell_loc.virt_row;
555 
556  gnc_table_set_vcell (table, cursor, gncEntryGetGUID (entry),
557  TRUE, start_primary_color, vcell_loc);
558  vcell_loc.virt_row++;
559 
560  /* Flip color for the next guy */
561  start_primary_color = !start_primary_color;
562  }
563 
564  /* Add the blank entry at the end. */
565  if (blank_entry)
566  {
567  gnc_table_set_vcell (table, cursor, gncEntryGetGUID (blank_entry),
568  TRUE, start_primary_color, vcell_loc);
569 
570  if (find_entry == blank_entry)
571  new_entry_row = vcell_loc.virt_row;
572 
573  vcell_loc.virt_row++;
574  }
575 
576  /* Resize the table */
577  gnc_table_set_size (table, vcell_loc.virt_row, 1);
578 
579  /* Restore the cursor to its rightful position */
580  if (new_entry_row > 0)
581  save_loc.vcell_loc.virt_row = new_entry_row;
582 
583  if (gnc_table_find_close_valid_cell (table, &save_loc, FALSE))
584  {
585  gnc_table_move_cursor_gui (table, save_loc);
586 
587  if (find_entry == gnc_entry_ledger_get_current_entry (ledger))
588  gnc_table_restore_current_cursor (table, cursor_buffer);
589  }
590 
591  gnc_cursor_buffer_destroy (cursor_buffer);
592  cursor_buffer = NULL;
593 
594  /* Reset the ledger */
595  ledger->traverse_to_new = FALSE;
596  ledger->hint_entry = NULL;
597 
598  /* Set the cell fractions */
599 
600 
602  gnc_entry_ledger_show_entry (ledger, table->current_cursor_loc.vcell_loc);
603 
604  /* Set completion character */
606  ((ComboCell*)
607  gnc_table_layout_get_cell (table->layout, ENTRY_IACCT_CELL),
608  gnc_get_account_separator());
609 
611  ((ComboCell*)
612  gnc_table_layout_get_cell (table->layout, ENTRY_BACCT_CELL),
613  gnc_get_account_separator());
614 
615  /* enable callback for cursor user-driven moves */
616  gnc_table_control_allow_move (table->control, TRUE);
617 }
tax is not included
Definition: gncTaxTable.h:81
GncTaxIncluded
How to interpret the TaxIncluded.
Definition: gncTaxTable.h:78
void gnc_table_move_cursor_gui(Table *table, VirtualLocation new_virt_loc)
will move the cursor and its GUI to the indicated location.
Definition: table-allgui.c:887
gboolean gnc_table_find_close_valid_cell(Table *table, VirtualLocation *virt_loc, gboolean exact_pointer)
Find a close valid cell.
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.
Definition: table-allgui.c:587
tax is included
Definition: gncTaxTable.h:80
use the global setting
Definition: gncTaxTable.h:82
void gnc_combo_cell_set_complete_char(ComboCell *cell, gunichar complete_char)
Sets a character used for special completion processing.
void gnc_table_refresh_gui(Table *table, gboolean do_scroll)
Refresh the whole GUI from the table.
Definition: table-gnome.c:165
The ComboCell object implements a cell handler with a "combination-box" pull-down menu in it...
Definition: combocell.h:52
GncEntry * gnc_entry_ledger_get_current_entry(GncEntryLedger *ledger)
Returns the Entry where the cursor is currently located.
#define CURSOR_HEADER
Standard Cursor Names.
Definition: table-layout.h:36
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.
Definition: table-allgui.c:664
void gncEntrySetDateGDate(GncEntry *entry, const GDate *date)
Set the date of this entry.
Definition: gncEntry.c:504
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
Definition: gncOwner.c:200
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
Definition: gncOwner.c:572
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
Definition: gncOwner.c:376
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
Definition: guid.cpp:130
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
GncEntry * gnc_entry_ledger_get_blank_entry(GncEntryLedger *ledger)
Exported Functions.
modtime is the internal date of the last modtime See src/doc/business.txt for an explanation of the f...

◆ gnc_entry_ledger_move_current_entry_updown()

void gnc_entry_ledger_move_current_entry_updown ( GncEntryLedger *  ledger,
gboolean  move_up 
)

This implements the command of moving the current entry (where the cursor is currently located) one row upwards or downwards, effectively swapping this row and the other row.

If the other row is empty (or it is the blank entry), nothing will happen.

Parameters
move_upIf TRUE, the current entry is moved upwards, otherwise downwards.

Definition at line 978 of file gncEntryLedger.c.

980 {
981  GncEntry *blank, *current, *target;
982  VirtualCellLocation vcell_loc;
983 
984  g_assert(ledger);
985 
986  blank = gnc_entry_ledger_get_blank_entry(ledger);
987  if (!blank)
988  return;
989 
990  /* Ensure we have a valid current GncEntry and it isn't the blank
991  * entry */
992  current = gnc_entry_ledger_get_current_entry(ledger);
993  if (!current || current == blank)
994  return;
995 
996  /* Obtain the GncEntry at the up or down virtual table location */
997  vcell_loc = ledger->table->current_cursor_loc.vcell_loc;
998  if (move_up)
999  {
1000  if (vcell_loc.virt_row == 0)
1001  return;
1002  vcell_loc.virt_row--;
1003  }
1004  else
1005  {
1006  vcell_loc.virt_row++;
1007  }
1008 
1009  /* Ensure we have a valid other GncEntry and it isn't the blank
1010  * entry */
1011  target = gnc_entry_ledger_get_entry(ledger, vcell_loc);
1012  if (!target || target == blank)
1013  return;
1014 
1015  /* Also, only continue if both have the same date, because the
1016  * "standard ordering" is tied to the date anyway. Note: This
1017  * unfortunately prevents the user from changing the ordering if
1018  * he has chosen a different sort order and the sort key happens
1019  * to be equal among the two entries. But I don't know how to look
1020  * up the current sort ordering from here, so I cowardly refuse to
1021  * tweak the EntryDate in this case. */
1022  {
1023  time64 t1, t2;
1024  GDate d1 = gncEntryGetDateGDate(current),
1025  d2 = gncEntryGetDateGDate(target);
1026  if (g_date_compare(&d1, &d2) != 0)
1027  return;
1028 
1029  /* Special treatment if the equality doesn't hold if we access the
1030  dates as time64. See the comment in gncEntrySetDateGDate() for the
1031  reason: Some code used the time64 at noon for the EntryDate, other
1032  code used the time64 at the start of day. */
1033  t1 = gncEntryGetDate(current);
1034  t2 = gncEntryGetDate(target);
1035  if (t1 != t2)
1036  {
1037  /* times are not equal, even though the GDates were equal? Then
1038  we set the GDates again. This will force the times to be equal
1039  as well. */
1040  gncEntrySetDateGDate(current, &d1);
1041  gncEntrySetDateGDate(target, &d2);
1042  }
1043  }
1044 
1045  /*g_warning("Ok, current desc='%s' target desc='%s'",
1046  gncEntryGetDescription(current),
1047  gncEntryGetDescription(target));*/
1048 
1049  gnc_suspend_gui_refresh ();
1050 
1051  /* Swap the date-entered of both entries. That's already
1052  * sufficient! */
1053  {
1054  time64 time_current = gncEntryGetDateEntered(current);
1055  time64 time_target = gncEntryGetDateEntered(target);
1056 
1057  /* Special treatment for identical times (potentially caused
1058  * by the "duplicate entry" command) */
1059  if (time_current == time_target)
1060  {
1061  /*g_warning("Surprise - both DateEntered are equal.");*/
1062  /* We just increment the DateEntered of the previously
1063  * lower of the two by one second. This might still cause
1064  * issues if multiple entries had this problem, but
1065  * whatever. */
1066  if (move_up)
1067  ++time_current;
1068  else
1069  ++time_target;
1070  }
1071 
1072  /* Write the new DateEntered. */
1073  gncEntrySetDateEntered(current, time_target);
1074  gncEntrySetDateEntered(target, time_current);
1075 
1076  /* And finally let the GncInvoice sort its entries
1077  * accordingly, so that the invoice reports will give the same
1078  * ordering as the register window. */
1079  gncInvoiceSortEntries(ledger->invoice);
1080  }
1081 
1082  gnc_resume_gui_refresh ();
1083 }
GncEntry * gnc_entry_ledger_get_entry(GncEntryLedger *ledger, VirtualCellLocation vcell_loc)
Returns the GncEntry at the given location, or NULL if the location is not valid. ...
void gncInvoiceSortEntries(GncInvoice *invoice)
Call this function when an Entry is changed and you want to re-sort the list of entries.
Definition: gncInvoice.c:751
time64 gncEntryGetDate(const GncEntry *entry)
DEPRECATED - use gncEntryGetDateGDate() instead! (Because the time-of-day is a misleading extra infor...
Definition: gncEntry.c:913
GncEntry * gnc_entry_ledger_get_current_entry(GncEntryLedger *ledger)
Returns the Entry where the cursor is currently located.
GDate gncEntryGetDateGDate(const GncEntry *entry)
Returns the day of this entry.
Definition: gncEntry.c:918
void gncEntrySetDateGDate(GncEntry *entry, const GDate *date)
Set the date of this entry.
Definition: gncEntry.c:504
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
GncEntry * gnc_entry_ledger_get_blank_entry(GncEntryLedger *ledger)
Exported Functions.