GnuCash  2.6.18
Files | Data Structures | Macros | Functions
Scheduled/Periodic/Recurring Transactions

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. See src/doc/books.txt for design overview.
 

Data Structures

struct  SchedXaction
 
struct  SchedXactionClass
 
struct  SXTmpStateData
 
struct  SchedXactions
 
struct  SchedXactionsClass
 

Macros

#define ENUM_LIST_TYPE(_)
 
#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_ID   "sched-xaction"
 
#define GNC_SX_ACCOUNT   "account"
 
#define GNC_SX_CREDIT_FORMULA   "credit-formula"
 
#define GNC_SX_DEBIT_FORMULA   "debit-formula"
 
#define GNC_SX_CREDIT_NUMERIC   "credit-numeric"
 
#define GNC_SX_DEBIT_NUMERIC   "debit-numeric"
 
#define GNC_SX_SHARES   "shares"
 
#define GNC_SX_AMOUNT   "amnt"
 
#define GNC_SX_FROM_SCHED_XACTION   "from-sched-xaction"
 
#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 xaccSchedXactionGetSlots(X)   qof_instance_get_slots(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)
 

Functions

GType gnc_schedxaction_get_type (void)
 
SchedXaction * xaccSchedXactionMalloc (QofBook *book)
 
void sx_set_template_account (SchedXaction *sx, Account *account)
 
void xaccSchedXactionDestroy (SchedXaction *sx)
 
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)
 
const GDate * xaccSchedXactionGetStartDate (const SchedXaction *sx)
 
void xaccSchedXactionSetStartDate (SchedXaction *sx, const GDate *newStart)
 
int xaccSchedXactionHasEndDate (const SchedXaction *sx)
 
const GDate * xaccSchedXactionGetEndDate (const SchedXaction *sx)
 
void xaccSchedXactionSetEndDate (SchedXaction *sx, const GDate *newEnd)
 
const GDate * xaccSchedXactionGetLastOccurDate (const SchedXaction *sx)
 
void xaccSchedXactionSetLastOccurDate (SchedXaction *sx, const GDate *newLastOccur)
 
gboolean xaccSchedXactionHasOccurDef (const SchedXaction *sx)
 
gint xaccSchedXactionGetNumOccur (const SchedXaction *sx)
 
void xaccSchedXactionSetNumOccur (SchedXaction *sx, gint numNum)
 
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)
 
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)
 
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.
 
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)
 
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)
 
void gnc_sx_incr_temporal_state (const SchedXaction *sx, SXTmpStateData *stateData)
 
void gnc_sx_destroy_temporal_state (SXTmpStateData *stateData)
 
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,)

Definition at line 34 of file FreqSpec.h.

◆ xaccSchedXactionGetGUID

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

Definition at line 327 of file SchedXaction.h.

◆ xaccSchedXactionGetSlots

#define xaccSchedXactionGetSlots (   X)    qof_instance_get_slots(QOF_INSTANCE(X))
Deprecated:

Definition at line 329 of file SchedXaction.h.

◆ xaccSchedXactionIsDirty

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

Definition at line 325 of file SchedXaction.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 64 of file SX-book.c.

65 {
66  QofCollection *col;
67  if (!book) return NULL;
68  col = qof_book_get_collection (book, GNC_ID_SXTG);
69  return gnc_collection_get_template_root (col);
70 }
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306

◆ 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.

Adds an instance to the deferred list of the SX. Added instances are added in (date-)sorted order.

Definition at line 1122 of file SchedXaction.c.

1123 {
1124  sx->deferredList = g_list_insert_sorted( sx->deferredList,
1125  deferStateData,
1126  _temporal_state_data_cmp );
1127 }

◆ 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 1092 of file SchedXaction.c.

1093 {
1094  SXTmpStateData *toRet;
1095  toRet = g_memdup (tsd, sizeof (SXTmpStateData));
1096  return toRet;
1097 }

◆ gnc_sx_create_temporal_state()

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.

Definition at line 1060 of file SchedXaction.c.

1061 {
1062  SXTmpStateData *toRet =
1063  g_new0( SXTmpStateData, 1 );
1064  if (g_date_valid (&(sx->last_date)))
1065  toRet->last_date = sx->last_date;
1066  else
1067  g_date_set_dmy (&(toRet->last_date), 1, 1, 1970);
1068  toRet->num_occur_rem = sx->num_occurances_remain;
1069  toRet->num_inst = sx->instance_num;
1070  return toRet;
1071 }

◆ gnc_sx_destroy_temporal_state()

void gnc_sx_destroy_temporal_state ( SXTmpStateData stateData)

Frees the given stateDate object.

Definition at line 1086 of file SchedXaction.c.

1087 {
1088  g_free(tsd);
1089 }

◆ 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; this is a (date-)sorted temporal-state-data instance list. The list should not be modified by the caller; use the gnc_sx_{add,remove}_defer_instance() functions to modifiy the list.

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

Definition at line 1160 of file SchedXaction.c.

1161 {
1162  return sx->deferredList;
1163 }

◆ 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 912 of file SchedXaction.c.

913 {
914  gint toRet = -1;
915  SXTmpStateData *tsd;
916 
917  if ( stateData )
918  {
919  tsd = (SXTmpStateData*)stateData;
920  toRet = tsd->num_inst;
921  }
922  else
923  {
924  toRet = sx->instance_num;
925  }
926 
927  return toRet;
928 }

◆ 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 722 of file SchedXaction.c.

723 {
724  gint result = 0;
725  SXTmpStateData *tmpState;
726  gboolean countFirstDate;
727 
728  /* SX still active? If not, return now. */
730  && xaccSchedXactionGetRemOccur(sx) <= 0)
731  || (xaccSchedXactionHasEndDate(sx)
732  && g_date_compare(xaccSchedXactionGetEndDate(sx), start_date) < 0))
733  {
734  return result;
735  }
736 
737  tmpState = gnc_sx_create_temporal_state (sx);
738 
739  /* Should we count the first valid date we encounter? Only if the
740  * SX has not yet occurred so far, or if its last valid date was
741  * before the start date. */
742  countFirstDate = !g_date_valid(&tmpState->last_date)
743  || (g_date_compare(&tmpState->last_date, start_date) < 0);
744 
745  /* No valid date? SX has never occurred so far. */
746  if (!g_date_valid(&tmpState->last_date))
747  {
748  /* SX has never occurred so far */
749  gnc_sx_incr_temporal_state (sx, tmpState);
750  if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
751  {
753  return result;
754  }
755  }
756 
757  /* Increase the tmpState until we are in our interval of
758  * interest. Only calculate anything if the sx hasn't already
759  * ended. */
760  while (g_date_compare(&tmpState->last_date, start_date) < 0)
761  {
762  gnc_sx_incr_temporal_state (sx, tmpState);
763  if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
764  {
766  return result;
767  }
768  }
769 
770  /* Now we are in our interval of interest. Increment the
771  * occurrence date until we are beyond the end of our
772  * interval. Make sure to check for invalid dates here: It means
773  * the SX has ended. */
774  while (g_date_valid(&tmpState->last_date)
775  && (g_date_compare(&tmpState->last_date, end_date) <= 0)
776  && (!xaccSchedXactionHasEndDate(sx)
777  || g_date_compare(&tmpState->last_date, xaccSchedXactionGetEndDate(sx)) <= 0)
779  /* The >=0 (i.e. the ==) is important here, otherwise
780  * we miss the last valid occurrence of a SX which is
781  * limited by num_occur */
782  || tmpState->num_occur_rem >= 0))
783  {
784  ++result;
785  gnc_sx_incr_temporal_state (sx, tmpState);
786  }
787 
788  /* If the first valid date shouldn't be counted, decrease the
789  * result number by one. */
790  if (!countFirstDate && result > 0)
791  --result;
792 
794  return result;
795 }
const GDate * xaccSchedXactionGetEndDate(const SchedXaction *sx)
Definition: SchedXaction.c:623
void gnc_sx_destroy_temporal_state(SXTmpStateData *tsd)
SXTmpStateData * gnc_sx_create_temporal_state(const SchedXaction *sx)
void gnc_sx_incr_temporal_state(const SchedXaction *sx, SXTmpStateData *tsd)
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Definition: SchedXaction.c:674

◆ gnc_sx_get_schedule()

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

Definition at line 554 of file SchedXaction.c.

555 {
556  return sx->schedule;
557 }

◆ 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 362 of file SX-book.c.

363 {
364  GList *rtn = NULL;
365  const GncGUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
366  GList *sx_list;
367  SchedXactions *sxactions = gnc_book_get_schedxactions(book);
368  g_return_val_if_fail( sxactions != NULL, rtn);
369  for (sx_list = sxactions->sx_list; sx_list != NULL; sx_list = sx_list->next)
370  {
371  SchedXaction *sx = (SchedXaction*)sx_list->data;
372  GList *splits = xaccSchedXactionGetSplits(sx);
373  for (; splits != NULL; splits = splits->next)
374  {
375  Split *s = (Split*)splits->data;
376  KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
377  GncGUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
378  if (guid_equal(acct_guid, sx_split_acct_guid))
379  {
380  rtn = g_list_append(rtn, sx);
381  }
382  }
383  }
384  return rtn;
385 }
Definition: guid.h:54
KvpFrame * xaccSplitGetSlots(const Split *s)
Definition: Split.c:961
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Definition: guid.c:708
const GncGUID * qof_entity_get_guid(gconstpointer ent)
Definition: qofinstance.c:484
KvpFrame * kvp_frame_get_frame(const KvpFrame *frame, const gchar *path)

◆ 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 occurence in the remporalStateDate. The SX is unchanged.

Definition at line 1074 of file SchedXaction.c.

1075 {
1076  g_return_if_fail(tsd != NULL);
1077  tsd->last_date = xaccSchedXactionGetNextInstance (sx, tsd);
1078  if (xaccSchedXactionHasOccurDef (sx))
1079  {
1080  --tsd->num_occur_rem;
1081  }
1082  ++tsd->num_inst;
1083 }
GDate xaccSchedXactionGetNextInstance(const SchedXaction *sx, SXTmpStateData *tsd)
Returns the next occurrence of a scheduled transaction.
Definition: SchedXaction.c:869
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Definition: SchedXaction.c:674

◆ 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.

Removes an instance from the deferred list. The saved SXTmpStateData existed for comparison only, so destroy it.

Definition at line 1134 of file SchedXaction.c.

1135 {
1136  GList *found_by_value;
1137 
1138  found_by_value = g_list_find_custom(
1139  sx->deferredList, deferStateData, _temporal_state_data_cmp);
1140  if (found_by_value == NULL)
1141  {
1142  g_warning("unable to find deferred instance");
1143  return;
1144  }
1145 
1146  gnc_sx_destroy_temporal_state(found_by_value->data);
1147  sx->deferredList = g_list_delete_link(sx->deferredList, found_by_value);
1148 }
void gnc_sx_destroy_temporal_state(SXTmpStateData *tsd)

◆ 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 931 of file SchedXaction.c.

932 {
933  g_return_if_fail(sx);
934  if (sx->instance_num == instance_num)
935  return;
936  gnc_sx_begin_edit(sx);
937  sx->instance_num = instance_num;
938  qof_instance_set_dirty(&sx->inst);
939  gnc_sx_commit_edit(sx);
940 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723

◆ gnc_sx_set_schedule()

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

Definition at line 560 of file SchedXaction.c.

561 {
562  g_return_if_fail(sx);
563  gnc_sx_begin_edit(sx);
564  sx->schedule = schedule;
565  qof_instance_set_dirty(&sx->inst);
566  gnc_sx_commit_edit(sx);
567 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723

◆ xaccSchedXactionDestroy()

void xaccSchedXactionDestroy ( SchedXaction *  sx)

Cleans up and frees a SchedXaction and its associated data.

Definition at line 468 of file SchedXaction.c.

469 {
470  qof_instance_set_destroying( QOF_INSTANCE(sx), TRUE );
471  gnc_sx_commit_edit( sx );
472 }
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667

◆ xaccSchedXactionGetEndDate()

const GDate* xaccSchedXactionGetEndDate ( const SchedXaction *  sx)

Returns invalid date when there is no end-date specified.

Definition at line 623 of file SchedXaction.c.

624 {
625  g_assert (sx);
626  return &sx->end_date;
627 }

◆ 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 869 of file SchedXaction.c.

870 {
871  GDate prev_occur, next_occur;
872 
873  g_date_clear( &prev_occur, 1 );
874  if ( tsd != NULL )
875  prev_occur = tsd->last_date;
876 
877  /* If prev_occur is in the "cleared" state and sx->start_date isn't, then
878  * we're at the beginning. We want to pretend prev_occur is the day before
879  * the start_date in case the start_date is today so that the SX will fire
880  * today. If start_date isn't valid either then the SX will fire anyway, no
881  * harm done.
882  */
883  if (! g_date_valid( &prev_occur ) && g_date_valid(&sx->start_date))
884  {
885  /* We must be at the beginning. */
886  prev_occur = sx->start_date;
887  g_date_subtract_days( &prev_occur, 1 );
888  }
889 
890  recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);
891 
892  if ( xaccSchedXactionHasEndDate( sx ) )
893  {
894  const GDate *end_date = xaccSchedXactionGetEndDate( sx );
895  if ( g_date_compare( &next_occur, end_date ) > 0 )
896  {
897  g_date_clear( &next_occur, 1 );
898  }
899  }
900  else if ( xaccSchedXactionHasOccurDef( sx ) )
901  {
902  if ((tsd && tsd->num_occur_rem == 0) ||
903  (!tsd && sx->num_occurances_remain == 0 ))
904  {
905  g_date_clear( &next_occur, 1 );
906  }
907  }
908  return next_occur;
909 }
const GDate * xaccSchedXactionGetEndDate(const SchedXaction *sx)
Definition: SchedXaction.c:623
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Definition: SchedXaction.c:674

◆ xaccSchedXactionHasOccurDef()

gboolean xaccSchedXactionHasOccurDef ( const SchedXaction *  sx)

Returns true if the scheduled transaction has a defined number of occurrences, false if not.

Definition at line 674 of file SchedXaction.c.

675 {
676  return ( xaccSchedXactionGetNumOccur( sx ) != 0 );
677 }

◆ xaccSchedXactionMalloc()

SchedXaction* xaccSchedXactionMalloc ( QofBook *  book)

Creates and initializes a scheduled transaction.

Definition at line 399 of file SchedXaction.c.

400 {
401  SchedXaction *sx;
402 
403  g_return_val_if_fail (book, NULL);
404 
405  sx = g_object_new(GNC_TYPE_SCHEDXACTION, NULL);
406  xaccSchedXactionInit( sx, book );
407  qof_event_gen( &sx->inst, QOF_EVENT_CREATE , NULL);
408 
409  return sx;
410 }
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ xaccSchedXactionSetEndDate()

void xaccSchedXactionSetEndDate ( SchedXaction *  sx,
const GDate *  newEnd 
)

Set to an invalid GDate to turn off 'end-date' definition.

Definition at line 630 of file SchedXaction.c.

631 {
632 /* Note that an invalid GDate IS a permissable value: It means that
633  * the SX is to run "forever". See gnc_sxed_save_sx() and
634  * schedXact_editor_populate() in dialog-sx-editor.c.
635  */
636  if (newEnd == NULL ||
637  (g_date_valid(newEnd) && g_date_compare( newEnd, &sx->start_date ) < 0 ))
638  {
639  /* XXX: I reject the bad data - is this the right
640  * thing to do <rgmerk>.
641  * This warning is only human readable - the caller
642  * doesn't know the call failed. This is bad
643  */
644  g_critical("Bad End Date: Invalid or before Start Date");
645  return;
646  }
647 
648  gnc_sx_begin_edit(sx);
649  sx->end_date = *newEnd;
650  qof_instance_set_dirty(&sx->inst);
651  gnc_sx_commit_edit(sx);
652 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723

◆ xaccSchedXactionSetName()

void xaccSchedXactionSetName ( SchedXaction *  sx,
const gchar *  newName 
)

A copy of the name is made.

Definition at line 576 of file SchedXaction.c.

577 {
578  g_return_if_fail( newName != NULL );
579  gnc_sx_begin_edit(sx);
580  if ( sx->name != NULL )
581  {
582  g_free( sx->name );
583  sx->name = NULL;
584  }
585  sx->name = g_strdup( newName );
586  qof_instance_set_dirty(&sx->inst);
587  gnc_sx_commit_edit(sx);
588 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723

◆ xaccSchedXactionSetNumOccur()

void xaccSchedXactionSetNumOccur ( SchedXaction *  sx,
gint  numNum 
)

Set to '0' to turn off number-of-occurrences definition.

Definition at line 686 of file SchedXaction.c.

687 {
688  if (sx->num_occurances_total == new_num)
689  return;
690  gnc_sx_begin_edit(sx);
691  sx->num_occurances_remain = sx->num_occurances_total = new_num;
692  qof_instance_set_dirty(&sx->inst);
693  gnc_sx_commit_edit(sx);
694 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723

◆ 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 1011 of file SchedXaction.c.

1013 {
1014  Transaction *new_trans;
1015  TTInfo *tti;
1016  TTSplitInfo *s_info;
1017  Split *new_split;
1018  GList *split_list;
1019 
1020  g_return_if_fail (book);
1021 
1022  /* delete any old transactions, if there are any */
1023  delete_template_trans( sx );
1024 
1025  for (; t_t_list != NULL; t_t_list = t_t_list->next)
1026  {
1027  tti = t_t_list->data;
1028 
1029  new_trans = xaccMallocTransaction(book);
1030 
1031  xaccTransBeginEdit(new_trans);
1032 
1033  xaccTransSetDescription(new_trans,
1034  gnc_ttinfo_get_description(tti));
1035 
1037 
1038  /* Set tran-num with gnc_set_num_action which is the same as
1039  * xaccTransSetNum with these arguments */
1040  gnc_set_num_action(new_trans, NULL,
1041  gnc_ttinfo_get_num(tti), NULL);
1042  xaccTransSetNotes (new_trans, gnc_ttinfo_get_notes (tti));
1043  xaccTransSetCurrency( new_trans,
1044  gnc_ttinfo_get_currency(tti) );
1045 
1046  for (split_list = gnc_ttinfo_get_template_splits(tti);
1047  split_list;
1048  split_list = split_list->next)
1049  {
1050  s_info = split_list->data;
1051  new_split = pack_split_info(s_info, sx->template_acct,
1052  new_trans, book);
1053  xaccTransAppendSplit(new_trans, new_split);
1054  }
1055  xaccTransCommitEdit(new_trans);
1056  }
1057 }
#define xaccTransAppendSplit(t, s)
Definition: Transaction.h:351
Transaction * xaccMallocTransaction(QofBook *book)
Definition: Transaction.c:449
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
Definition: Transaction.c:1896
void xaccTransSetNotes(Transaction *trans, const char *notes)
Definition: Transaction.c:2097
void xaccTransSetDescription(Transaction *trans, const char *desc)
Definition: Transaction.c:2067
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Definition: Transaction.c:1327
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.c:410