GnuCash  4.8a-132-gcdaeb421d+
Files | Data Structures | Macros | Enumerations | Functions
Scheduled/Periodic/Recurring Transactions


Scheduled Transactions provide a framework for remembering information about a transactions that are set to occur in the future, either once or periodically. More...

Files

file  FreqSpec.h
 Period / Date Frequency Specification.
 
file  SchedXaction.h
 Scheduled Transactions public handling routines.
 
file  SX-book.h
 Anchor Scheduled Transaction info in a book.
 

Data Structures

struct  SchedXaction
 A single scheduled transaction. More...
 
struct  SchedXactionClass
 
struct  SXTmpStateData
 Just the variable temporal bits from the SX structure. More...
 
struct  SchedXactions
 
struct  SchedXactionsClass
 

Macros

#define ENUM_LIST_TYPE(_)
 
#define ENUM_LIST_UI(_)
 
#define GNC_TYPE_SCHEDXACTION   (gnc_schedxaction_get_type ())
 
#define GNC_SCHEDXACTION(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SCHEDXACTION, SchedXaction))
 
#define GNC_SCHEDXACTION_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SCHEDXACTION, SchedXactionClass))
 
#define GNC_IS_SCHEDXACTION(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SCHEDXACTION))
 
#define GNC_IS_SCHEDXACTION_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SCHEDXACTION))
 
#define GNC_SCHEDXACTION_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SCHEDXACTION, SchedXactionClass))
 
#define GNC_IS_SX(obj)   GNC_IS_SCHEDXACTION(obj)
 
#define GNC_SX(obj)   GNC_SCHEDXACTION(obj)
 
#define xaccSchedXactionSetGUID(X, G)   qof_instance_set_guid(QOF_INSTANCE(X),(G))
 
#define GNC_SX_SHARES   "shares"
 
#define GNC_SX_FREQ_SPEC   "scheduled-frequency"
 
#define GNC_SX_NAME   "sched-xname"
 
#define GNC_SX_START_DATE   "sched-start-date"
 
#define GNC_SX_LAST_DATE   "sched-last-date"
 
#define GNC_SX_NUM_OCCUR   "sx-total-number"
 
#define GNC_SX_REM_OCCUR   "sx-remaining-num"
 
#define xaccSchedXactionIsDirty(X)   qof_instance_is_dirty (QOF_INSTANCE(X))
 
#define xaccSchedXactionGetGUID(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 
#define GNC_TYPE_SCHEDXACTIONS   (gnc_schedxactions_get_type ())
 
#define GNC_SCHEDXACTIONS(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SCHEDXACTIONS, SchedXactions))
 
#define GNC_SCHEDXACTIONS_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SCHEDXACTIONS, SchedXactionsClass))
 
#define GNC_IS_SCHEDXACTIONS(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SCHEDXACTIONS))
 
#define GNC_IS_SCHEDXACTIONS_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SCHEDXACTIONS))
 
#define GNC_SCHEDXACTIONS_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SCHEDXACTIONS, SchedXactionsClass))
 
#define GNC_IS_SXES(obj)   GNC_IS_SCHEDXACTIONS(obj)
 
#define GNC_SXES(obj)   GNC_SCHEDXACTIONS(obj)
 

Enumerations

enum  FreqType {
  INVALID, ONCE, DAILY, WEEKLY,
  MONTHLY, MONTH_RELATIVE, COMPOSITE
}
 Frequency specification. More...
 
enum  UIFreqType {
  UIFREQ_NONE, UIFREQ_ONCE, UIFREQ_DAILY, UIFREQ_DAILY_MF,
  UIFREQ_WEEKLY, UIFREQ_BI_WEEKLY, UIFREQ_SEMI_MONTHLY, UIFREQ_MONTHLY,
  UIFREQ_QUARTERLY, UIFREQ_TRI_ANUALLY, UIFREQ_SEMI_YEARLY, UIFREQ_YEARLY,
  UIFREQ_NUM_UI_FREQSPECS
}
 The user's conception of the frequency. More...
 

Functions

GType gnc_schedxaction_get_type (void)
 
SchedXaction * xaccSchedXactionMalloc (QofBook *book)
 Creates and initializes a scheduled transaction.
 
void sx_set_template_account (SchedXaction *sx, Account *account)
 
void xaccSchedXactionDestroy (SchedXaction *sx)
 Cleans up and frees a SchedXaction and its associated data.
 
void gnc_sx_begin_edit (SchedXaction *sx)
 
void gnc_sx_commit_edit (SchedXaction *sx)
 
GList * gnc_sx_get_schedule (const SchedXaction *sx)
 
void gnc_sx_set_schedule (SchedXaction *sx, GList *schedule)
 
gchar * xaccSchedXactionGetName (const SchedXaction *sx)
 
void xaccSchedXactionSetName (SchedXaction *sx, const gchar *newName)
 A copy of the name is made.
 
const GDate * xaccSchedXactionGetStartDate (const SchedXaction *sx)
 
time64 xaccSchedXactionGetStartDateTT (const SchedXaction *sx)
 
void xaccSchedXactionSetStartDate (SchedXaction *sx, const GDate *newStart)
 
void xaccSchedXactionSetStartDateTT (SchedXaction *sx, const time64 newStart)
 
int xaccSchedXactionHasEndDate (const SchedXaction *sx)
 
const GDate * xaccSchedXactionGetEndDate (const SchedXaction *sx)
 Returns invalid date when there is no end-date specified.
 
void xaccSchedXactionSetEndDate (SchedXaction *sx, const GDate *newEnd)
 Set to an invalid GDate to turn off 'end-date' definition.
 
const GDate * xaccSchedXactionGetLastOccurDate (const SchedXaction *sx)
 
time64 xaccSchedXactionGetLastOccurDateTT (const SchedXaction *sx)
 
void xaccSchedXactionSetLastOccurDate (SchedXaction *sx, const GDate *newLastOccur)
 
void xaccSchedXactionSetLastOccurDateTT (SchedXaction *sx, const time64 newLastOccur)
 
gboolean xaccSchedXactionHasOccurDef (const SchedXaction *sx)
 Returns true if the scheduled transaction has a defined number of occurrences, false if not.
 
gint xaccSchedXactionGetNumOccur (const SchedXaction *sx)
 
void xaccSchedXactionSetNumOccur (SchedXaction *sx, gint numNum)
 Set to '0' to turn off number-of-occurrences definition.
 
gint xaccSchedXactionGetRemOccur (const SchedXaction *sx)
 
void xaccSchedXactionSetRemOccur (SchedXaction *sx, gint numRemain)
 
gint gnc_sx_get_num_occur_daterange (const SchedXaction *sx, const GDate *start_date, const GDate *end_date)
 Calculates and returns the number of occurrences of the given SX in the given date range (inclusive). More...
 
gint gnc_sx_get_instance_count (const SchedXaction *sx, SXTmpStateData *stateData)
 Get the instance count. More...
 
void gnc_sx_set_instance_count (SchedXaction *sx, gint instanceNum)
 Sets the instance count to something other than the default. More...
 
GList * xaccSchedXactionGetSplits (const SchedXaction *sx)
 
void xaccSchedXactionSetSplits (SchedXaction *sx, GList *newSplits)
 
gboolean xaccSchedXactionGetEnabled (const SchedXaction *sx)
 
void xaccSchedXactionSetEnabled (SchedXaction *sx, gboolean newEnabled)
 
void xaccSchedXactionGetAutoCreate (const SchedXaction *sx, gboolean *outAutoCreate, gboolean *outNotify)
 
void xaccSchedXactionSetAutoCreate (SchedXaction *sx, gboolean newAutoCreate, gboolean newNotify)
 
gint xaccSchedXactionGetAdvanceCreation (const SchedXaction *sx)
 
void xaccSchedXactionSetAdvanceCreation (SchedXaction *sx, gint createDays)
 
gint xaccSchedXactionGetAdvanceReminder (const SchedXaction *sx)
 
void xaccSchedXactionSetAdvanceReminder (SchedXaction *sx, gint reminderDays)
 
GDate xaccSchedXactionGetNextInstance (const SchedXaction *sx, SXTmpStateData *stateData)
 Returns the next occurrence of a scheduled transaction. More...
 
void xaccSchedXactionSetTemplateTrans (SchedXaction *sx, GList *t_t_list, QofBook *book)
 Set the schedxaction's template transaction. More...
 
void gnc_sx_add_defer_instance (SchedXaction *sx, void *deferStateData)
 Adds an instance to the deferred list of the SX. More...
 
void gnc_sx_remove_defer_instance (SchedXaction *sx, void *deferStateData)
 Removes an instance from the deferred list. More...
 
GList * gnc_sx_get_defer_instances (SchedXaction *sx)
 Returns the defer list from the SX. More...
 
gboolean SXRegister (void)
 QOF registration. More...
 
GType gnc_schedxactions_get_type (void)
 
SchedXactions * gnc_book_get_schedxactions (QofBook *book)
 
void gnc_sxes_add_sx (SchedXactions *sxes, SchedXaction *sx)
 
void gnc_sxes_del_sx (SchedXactions *sxes, SchedXaction *sx)
 
Accountgnc_book_get_template_root (const QofBook *book)
 Returns the template group from the book. More...
 
GList * gnc_sx_get_sxes_referencing_account (QofBook *book, Account *acct)
 

Temporal state data.


These functions allow us to opaquely save the entire temporal state of ScheduledTransactions.

This is used by the "since-last-run" dialog to store the initial state of SXes before modification ... if it later becomes necessary to revert an entire set of changes, we can 'revert' the SX without having to rollback all the individual state changes.

SXTmpStateDatagnc_sx_create_temporal_state (const SchedXaction *sx)
 Allocates a new SXTmpStateData object and fills it with the current state of the given sx.
 
void gnc_sx_incr_temporal_state (const SchedXaction *sx, SXTmpStateData *stateData)
 Calculates the next occurrence of the given SX and stores that occurrence in the remporalStateDate. More...
 
void gnc_sx_destroy_temporal_state (SXTmpStateData *stateData)
 Frees the given stateDate object. More...
 
SXTmpStateDatagnc_sx_clone_temporal_state (SXTmpStateData *stateData)
 Allocates and returns a one-by-one copy of the given temporal state. More...
 

Detailed Description


Scheduled Transactions provide a framework for remembering information about a transactions that are set to occur in the future, either once or periodically.

Macro Definition Documentation

◆ ENUM_LIST_TYPE

#define ENUM_LIST_TYPE (   _)
Value:
_(INVALID,) \
_(ONCE,) \
_(DAILY,) \
_(WEEKLY,) \
_(MONTHLY,) \
_(MONTH_RELATIVE,) \
_(COMPOSITE,)
Hmmm...
Definition: FreqSpec.h:43

Definition at line 34 of file FreqSpec.h.

◆ ENUM_LIST_UI

#define ENUM_LIST_UI (   _)
Value:
_(UIFREQ_NUM_UI_FREQSPECS,)
Repeat twice a year.
Definition: FreqSpec.h:68
no frequency
Definition: FreqSpec.h:68
Repeat once each week.
Definition: FreqSpec.h:68
Repeat every day.
Definition: FreqSpec.h:68
Repeat three times a year.
Definition: FreqSpec.h:68
Repeat twice a month.
Definition: FreqSpec.h:68
Repeat twice a week.
Definition: FreqSpec.h:68
Just occurs once.
Definition: FreqSpec.h:68
Repeat every quarter.
Definition: FreqSpec.h:68
Repeat Monday to Friday, skip weekend.
Definition: FreqSpec.h:68
Repeat once a year.
Definition: FreqSpec.h:68
Repeat once a month.
Definition: FreqSpec.h:68

Definition at line 53 of file FreqSpec.h.

◆ xaccSchedXactionGetGUID

#define xaccSchedXactionGetGUID (   X)    qof_entity_get_guid(QOF_INSTANCE(X))
Deprecated:

Definition at line 323 of file SchedXaction.h.

◆ xaccSchedXactionIsDirty

#define xaccSchedXactionIsDirty (   X)    qof_instance_is_dirty (QOF_INSTANCE(X))
Deprecated:

Definition at line 321 of file SchedXaction.h.

Enumeration Type Documentation

◆ FreqType

enum FreqType

Frequency specification.

For BI_WEEKLY, use weekly[2] SEMI_MONTHLY, use composite YEARLY, monthly[12]

Enumerator
WEEKLY 

Hmmm...

This is sort of DAILY[7]...

Definition at line 43 of file FreqSpec.h.

◆ UIFreqType

enum UIFreqType

The user's conception of the frequency.

It is expected that this list will grow, while the former FreqType will not.

Enumerator
UIFREQ_NONE 

no frequency

UIFREQ_ONCE 

Just occurs once.

UIFREQ_DAILY 

Repeat every day.

UIFREQ_DAILY_MF 

Repeat Monday to Friday, skip weekend.

UIFREQ_WEEKLY 

Repeat once each week.

UIFREQ_BI_WEEKLY 

Repeat twice a week.

UIFREQ_SEMI_MONTHLY 

Repeat twice a month.

UIFREQ_MONTHLY 

Repeat once a month.

UIFREQ_QUARTERLY 

Repeat every quarter.

UIFREQ_TRI_ANUALLY 

Repeat three times a year.

UIFREQ_SEMI_YEARLY 

Repeat twice a year.

UIFREQ_YEARLY 

Repeat once a year.

Definition at line 68 of file FreqSpec.h.

Function Documentation

◆ gnc_book_get_template_root()

Account* gnc_book_get_template_root ( const QofBook *  book)

Returns the template group from the book.

Definition at line 65 of file SX-book.c.

66 {
67  QofCollection *col;
68  if (!book) return NULL;
69  col = qof_book_get_collection (book, GNC_ID_SXTG);
70  return gnc_collection_get_template_root (col);
71 }
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:604

◆ gnc_sx_add_defer_instance()

void gnc_sx_add_defer_instance ( SchedXaction *  sx,
void *  deferStateData 
)

Adds an instance to the deferred list of the SX.

Added instances are added in date-sorted order.

Added instances are added in (date-)sorted order.

Definition at line 1156 of file SchedXaction.c.

1157 {
1158  sx->deferredList = g_list_insert_sorted( sx->deferredList,
1159  deferStateData,
1160  _temporal_state_data_cmp );
1161 }

◆ gnc_sx_clone_temporal_state()

SXTmpStateData* gnc_sx_clone_temporal_state ( SXTmpStateData stateData)

Allocates and returns a one-by-one copy of the given temporal state.

The caller must destroy the returned object with gnc_sx_destroy_temporal_state() after usage.

Definition at line 1120 of file SchedXaction.c.

1121 {
1122  SXTmpStateData *toRet = NULL;
1123 
1124  if(tsd)
1125  {
1126  toRet = g_malloc(sizeof(SXTmpStateData));
1127  toRet = memcpy (toRet, tsd, sizeof (SXTmpStateData));
1128  }
1129 
1130  return toRet;
1131 }
Just the variable temporal bits from the SX structure.
Definition: SchedXaction.h:127

◆ gnc_sx_destroy_temporal_state()

void gnc_sx_destroy_temporal_state ( SXTmpStateData stateData)

Frees the given stateDate object.

Definition at line 1114 of file SchedXaction.c.

1115 {
1116  g_free(tsd);
1117 }

◆ gnc_sx_get_defer_instances()

GList* gnc_sx_get_defer_instances ( SchedXaction *  sx)

Returns the defer list from the SX.

This is a date-sorted state-data instance list. The list should not be modified by the caller; use the gnc_sx_{add,remove}_defer_instance() functions to modify the list.

Returns the defer list from the SX.

The list should not be modified by the caller; use the gnc_sx_{add,remove}_defer_instance() functions to modify the list.

Parameters
sxScheduled transaction
Returns
Defer list which must not be modified by the caller

Definition at line 1194 of file SchedXaction.c.

1195 {
1196  return sx->deferredList;
1197 }

◆ gnc_sx_get_instance_count()

gint gnc_sx_get_instance_count ( const SchedXaction *  sx,
SXTmpStateData stateData 
)

Get the instance count.

This is incremented by one for every created instance of the SX. Returns the instance num of the SX unless stateData is non-null, in which case it returns the instance num from the state data.

Parameters
sxThe instance whose state should be retrieved.
stateDatamay be NULL.

Definition at line 966 of file SchedXaction.c.

967 {
968  gint toRet = -1;
969  SXTmpStateData *tsd;
970 
971  if ( stateData )
972  {
973  tsd = (SXTmpStateData*)stateData;
974  toRet = tsd->num_inst;
975  }
976  else
977  {
978  toRet = sx->instance_num;
979  }
980 
981  return toRet;
982 }
Just the variable temporal bits from the SX structure.
Definition: SchedXaction.h:127

◆ gnc_sx_get_num_occur_daterange()

gint gnc_sx_get_num_occur_daterange ( const SchedXaction *  sx,
const GDate *  start_date,
const GDate *  end_date 
)

Calculates and returns the number of occurrences of the given SX in the given date range (inclusive).

Definition at line 776 of file SchedXaction.c.

777 {
778  gint result = 0;
779  SXTmpStateData *tmpState;
780  gboolean countFirstDate;
781 
782  /* SX still active? If not, return now. */
784  && xaccSchedXactionGetRemOccur(sx) <= 0)
785  || (xaccSchedXactionHasEndDate(sx)
786  && g_date_compare(xaccSchedXactionGetEndDate(sx), start_date) < 0))
787  {
788  return result;
789  }
790 
791  tmpState = gnc_sx_create_temporal_state (sx);
792 
793  /* Should we count the first valid date we encounter? Only if the
794  * SX has not yet occurred so far, or if its last valid date was
795  * before the start date. */
796  countFirstDate = !g_date_valid(&tmpState->last_date)
797  || (g_date_compare(&tmpState->last_date, start_date) < 0);
798 
799  /* No valid date? SX has never occurred so far. */
800  if (!g_date_valid(&tmpState->last_date))
801  {
802  /* SX has never occurred so far */
803  gnc_sx_incr_temporal_state (sx, tmpState);
804  if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
805  {
807  return result;
808  }
809  }
810 
811  /* Increase the tmpState until we are in our interval of
812  * interest. Only calculate anything if the sx hasn't already
813  * ended. */
814  while (g_date_compare(&tmpState->last_date, start_date) < 0)
815  {
816  gnc_sx_incr_temporal_state (sx, tmpState);
817  if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
818  {
820  return result;
821  }
822  }
823 
824  /* Now we are in our interval of interest. Increment the
825  * occurrence date until we are beyond the end of our
826  * interval. Make sure to check for invalid dates here: It means
827  * the SX has ended. */
828  while (g_date_valid(&tmpState->last_date)
829  && (g_date_compare(&tmpState->last_date, end_date) <= 0)
830  && (!xaccSchedXactionHasEndDate(sx)
831  || g_date_compare(&tmpState->last_date, xaccSchedXactionGetEndDate(sx)) <= 0)
833  /* The >=0 (i.e. the ==) is important here, otherwise
834  * we miss the last valid occurrence of a SX which is
835  * limited by num_occur */
836  || tmpState->num_occur_rem >= 0))
837  {
838  ++result;
839  gnc_sx_incr_temporal_state (sx, tmpState);
840  }
841 
842  /* If the first valid date shouldn't be counted, decrease the
843  * result number by one. */
844  if (!countFirstDate && result > 0)
845  --result;
846 
848  return result;
849 }
const GDate * xaccSchedXactionGetEndDate(const SchedXaction *sx)
Returns invalid date when there is no end-date specified.
Definition: SchedXaction.c:656
void gnc_sx_destroy_temporal_state(SXTmpStateData *tsd)
Frees the given stateDate object.
SXTmpStateData * gnc_sx_create_temporal_state(const SchedXaction *sx)
Allocates a new SXTmpStateData object and fills it with the current state of the given sx...
Just the variable temporal bits from the SX structure.
Definition: SchedXaction.h:127
void gnc_sx_incr_temporal_state(const SchedXaction *sx, SXTmpStateData *tsd)
Calculates the next occurrence of the given SX and stores that occurrence in the remporalStateDate.
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Returns true if the scheduled transaction has a defined number of occurrences, false if not...
Definition: SchedXaction.c:728

◆ gnc_sx_get_schedule()

GList* gnc_sx_get_schedule ( const SchedXaction *  sx)
Returns
GList<Recurrence*>

Definition at line 561 of file SchedXaction.c.

562 {
563  return sx->schedule;
564 }

◆ gnc_sx_get_sxes_referencing_account()

GList* gnc_sx_get_sxes_referencing_account ( QofBook *  book,
Account acct 
)
Returns
The list of SXes which reference the given Account. Caller should free this list.

Definition at line 366 of file SX-book.c.

367 {
368  GList *rtn = NULL;
369  const GncGUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
370  GList *sx_list;
371  SchedXactions *sxactions = gnc_book_get_schedxactions(book);
372  g_return_val_if_fail( sxactions != NULL, rtn);
373  for (sx_list = sxactions->sx_list; sx_list != NULL; sx_list = sx_list->next)
374  {
375  SchedXaction *sx = (SchedXaction*)sx_list->data;
376  GList *splits = xaccSchedXactionGetSplits(sx);
377  for (; splits != NULL; splits = splits->next)
378  {
379  Split *s = (Split*)splits->data;
380  GncGUID *guid = NULL;
381  qof_instance_get (QOF_INSTANCE (s), "sx-account", &guid, NULL);
382  if (guid_equal(acct_guid, guid))
383  rtn = g_list_prepend (rtn, sx);
384 
385  guid_free (guid);
386  }
387  }
388  return g_list_reverse (rtn);
389 }
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
Definition: guid.cpp:204
const GncGUID * qof_entity_get_guid(gconstpointer ent)
The type used to store guids in C.
Definition: guid.h:75

◆ gnc_sx_incr_temporal_state()

void gnc_sx_incr_temporal_state ( const SchedXaction *  sx,
SXTmpStateData stateData 
)

Calculates the next occurrence of the given SX and stores that occurrence in the remporalStateDate.

The SX is unchanged.

Definition at line 1102 of file SchedXaction.c.

1103 {
1104  g_return_if_fail(tsd != NULL);
1105  tsd->last_date = xaccSchedXactionGetNextInstance (sx, tsd);
1106  if (xaccSchedXactionHasOccurDef (sx))
1107  {
1108  --tsd->num_occur_rem;
1109  }
1110  ++tsd->num_inst;
1111 }
GDate xaccSchedXactionGetNextInstance(const SchedXaction *sx, SXTmpStateData *tsd)
Returns the next occurrence of a scheduled transaction.
Definition: SchedXaction.c:923
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Returns true if the scheduled transaction has a defined number of occurrences, false if not...
Definition: SchedXaction.c:728

◆ gnc_sx_remove_defer_instance()

void gnc_sx_remove_defer_instance ( SchedXaction *  sx,
void *  deferStateData 
)

Removes an instance from the deferred list.

If the instance is no longer useful; gnc_sx_destroy_temporal_state() it.

The saved SXTmpStateData existed for comparison only, so destroy it.

Definition at line 1168 of file SchedXaction.c.

1169 {
1170  GList *found_by_value;
1171 
1172  found_by_value = g_list_find_custom(
1173  sx->deferredList, deferStateData, _temporal_state_data_cmp);
1174  if (found_by_value == NULL)
1175  {
1176  g_warning("unable to find deferred instance");
1177  return;
1178  }
1179 
1180  gnc_sx_destroy_temporal_state(found_by_value->data);
1181  sx->deferredList = g_list_delete_link(sx->deferredList, found_by_value);
1182 }
void gnc_sx_destroy_temporal_state(SXTmpStateData *tsd)
Frees the given stateDate object.

◆ gnc_sx_set_instance_count()

void gnc_sx_set_instance_count ( SchedXaction *  sx,
gint  instanceNum 
)

Sets the instance count to something other than the default.

As the default is the incorrect value '0', callers should DTRT here.

Definition at line 985 of file SchedXaction.c.

986 {
987  g_return_if_fail(sx);
988  if (sx->instance_num == instance_num)
989  return;
990  gnc_sx_begin_edit(sx);
991  sx->instance_num = instance_num;
992  qof_instance_set_dirty(&sx->inst);
993  gnc_sx_commit_edit(sx);
994 }

◆ gnc_sx_set_schedule()

void gnc_sx_set_schedule ( SchedXaction *  sx,
GList *  schedule 
)
Parameters
[in]scheduleA GList<Recurrence*>

Definition at line 567 of file SchedXaction.c.

568 {
569  g_return_if_fail(sx);
570  gnc_sx_begin_edit(sx);
571  sx->schedule = schedule;
572  qof_instance_set_dirty(&sx->inst);
573  gnc_sx_commit_edit(sx);
574 }

◆ SXRegister()

gboolean SXRegister ( void  )

QOF registration.

Definition at line 1245 of file SchedXaction.c.

1246 {
1247  static QofParam params[] =
1248  {
1249  {
1250  GNC_SX_NAME, QOF_TYPE_STRING, (QofAccessFunc)xaccSchedXactionGetName,
1252  },
1253  {
1254  GNC_SX_START_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetStartDateTT,
1255  (QofSetterFunc)xaccSchedXactionSetStartDateTT
1256  },
1257  {
1258  GNC_SX_LAST_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetLastOccurDateTT,
1259  (QofSetterFunc)xaccSchedXactionSetLastOccurDateTT
1260  },
1261  {
1262  GNC_SX_NUM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetNumOccur,
1264  },
1265  {
1266  GNC_SX_REM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetRemOccur,
1267  (QofSetterFunc)xaccSchedXactionSetRemOccur
1268  },
1269  { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
1270  { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
1271  { NULL },
1272  };
1273  qof_class_register(GNC_SX_ID, NULL, params);
1274  return qof_object_register(&SXDesc);
1275 }
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
void xaccSchedXactionSetNumOccur(SchedXaction *sx, gint new_num)
Set to &#39;0&#39; to turn off number-of-occurrences definition.
Definition: SchedXaction.c:740
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
Definition: qofclass.cpp:86
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
Definition: qofquery.h:109
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
Definition: qofclass.h:184
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition: qofclass.h:177
void xaccSchedXactionSetName(SchedXaction *sx, const gchar *newName)
A copy of the name is made.
Definition: SchedXaction.c:583
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
Definition: qofobject.cpp:317

◆ xaccSchedXactionGetNextInstance()

GDate xaccSchedXactionGetNextInstance ( const SchedXaction *  sx,
SXTmpStateData stateData 
)

Returns the next occurrence of a scheduled transaction.

If the transaction hasn't occurred, then it's based off the start date. Otherwise, it's based off the last-occurrence date.

If state data is NULL, the current value of the SX is used for computation. Otherwise, the values in the state data are used. This allows the caller to correctly create a set of instances into the future for possible action without modifying the SX state until action is actually taken.

Definition at line 923 of file SchedXaction.c.

924 {
925  GDate prev_occur, next_occur;
926 
927  g_date_clear( &prev_occur, 1 );
928  if ( tsd != NULL )
929  prev_occur = tsd->last_date;
930 
931  /* If prev_occur is in the "cleared" state and sx->start_date isn't, then
932  * we're at the beginning. We want to pretend prev_occur is the day before
933  * the start_date in case the start_date is today so that the SX will fire
934  * today. If start_date isn't valid either then the SX will fire anyway, no
935  * harm done. prev_occur cannot be before start_date either.
936  */
937  if (g_date_valid (&sx->start_date) && (!g_date_valid ( &prev_occur ) || g_date_compare (&prev_occur, &sx->start_date)<0))
938  {
939  /* We must be at the beginning. */
940  prev_occur = sx->start_date;
941  g_date_subtract_days (&prev_occur, 1 );
942  }
943 
944  recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);
945 
946  if ( xaccSchedXactionHasEndDate( sx ) )
947  {
948  const GDate *end_date = xaccSchedXactionGetEndDate( sx );
949  if ( g_date_compare( &next_occur, end_date ) > 0 )
950  {
951  g_date_clear( &next_occur, 1 );
952  }
953  }
954  else if ( xaccSchedXactionHasOccurDef( sx ) )
955  {
956  if ((tsd && tsd->num_occur_rem == 0) ||
957  (!tsd && sx->num_occurances_remain == 0 ))
958  {
959  g_date_clear( &next_occur, 1 );
960  }
961  }
962  return next_occur;
963 }
const GDate * xaccSchedXactionGetEndDate(const SchedXaction *sx)
Returns invalid date when there is no end-date specified.
Definition: SchedXaction.c:656
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Returns true if the scheduled transaction has a defined number of occurrences, false if not...
Definition: SchedXaction.c:728

◆ xaccSchedXactionSetTemplateTrans()

void xaccSchedXactionSetTemplateTrans ( SchedXaction *  sx,
GList *  t_t_list,
QofBook *  book 
)

Set the schedxaction's template transaction.

t_t_list is a glist of TTInfo's as defined in SX-ttinfo.h. The edit dialog doesn't use this mechanism; maybe it should.

Definition at line 1039 of file SchedXaction.c.

1041 {
1042  Transaction *new_trans;
1043  TTInfo *tti;
1044  TTSplitInfo *s_info;
1045  Split *new_split;
1046  GList *split_list;
1047 
1048  g_return_if_fail (book);
1049 
1050  /* delete any old transactions, if there are any */
1051  delete_template_trans( sx );
1052 
1053  for (; t_t_list != NULL; t_t_list = t_t_list->next)
1054  {
1055  tti = t_t_list->data;
1056 
1057  new_trans = xaccMallocTransaction(book);
1058 
1059  xaccTransBeginEdit(new_trans);
1060 
1061  xaccTransSetDescription(new_trans,
1062  gnc_ttinfo_get_description(tti));
1063 
1065 
1066  /* Set tran-num with gnc_set_num_action which is the same as
1067  * xaccTransSetNum with these arguments */
1068  gnc_set_num_action(new_trans, NULL,
1069  gnc_ttinfo_get_num(tti), NULL);
1070  xaccTransSetNotes (new_trans, gnc_ttinfo_get_notes (tti));
1071  xaccTransSetCurrency( new_trans,
1072  gnc_ttinfo_get_currency(tti) );
1073 
1074  for (split_list = gnc_ttinfo_get_template_splits(tti);
1075  split_list;
1076  split_list = split_list->next)
1077  {
1078  s_info = split_list->data;
1079  new_split = pack_split_info(s_info, sx->template_acct,
1080  new_trans, book);
1081  xaccTransAppendSplit(new_trans, new_split);
1082  }
1083  xaccTransCommitEdit(new_trans);
1084  }
1085 }
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Definition: Transaction.h:362
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
Definition: Transaction.c:510
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
void xaccTransSetNotes(Transaction *trans, const char *notes)
Sets the transaction Notes.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
Definition: Transaction.c:1425
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.cpp:273