GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | 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  xaccSchedXactionsDef
 
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_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 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)
 

Typedefs

typedef struct _SchedXactionClass SchedXactionClass
 
typedef struct _SchedXaction SchedXaction
 
typedef struct _SXTmpStateData SXTmpStateData
 
typedef struct xaccSchedXactionsDef SchedXactions
 
typedef struct _SchedXactionsClass SchedXactionsClass
 

Functions

GType gnc_schedxaction_get_type (void)
 
SchedXactionxaccSchedXactionMalloc (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...
 
GDate xaccSchedXactionGetInstanceAfter (const SchedXaction *sx, GDate *date, SXTmpStateData *stateData)
 
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)
 
SchedXactionsgnc_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

#define ENUM_LIST_TYPE (   _)
Value:
_(INVALID,) \
_(ONCE,) \
_(DAILY,) \
_(WEEKLY,) \
_(MONTHLY,) \
_(MONTH_RELATIVE,) \
_(COMPOSITE,)

Definition at line 34 of file FreqSpec.h.

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

Definition at line 321 of file SchedXaction.h.

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

Definition at line 323 of file SchedXaction.h.

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

Definition at line 319 of file SchedXaction.h.

Typedef Documentation

Just the variable temporal bits from the SX structure.

Function Documentation

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 *, QofIdType)
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 1201 of file SchedXaction.c.

1202 {
1203  sx->deferredList = g_list_insert_sorted( sx->deferredList,
1204  deferStateData,
1205  _temporal_state_data_cmp );
1206 }
GList * deferredList
Definition: SchedXaction.h:118
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 1168 of file SchedXaction.c.

1169 {
1170  SXTmpStateData *toRet, *tsd;
1171  tsd = (SXTmpStateData*)stateData;
1172  toRet = g_memdup( tsd, sizeof( SXTmpStateData ) );
1173  return toRet;
1174 }
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 1130 of file SchedXaction.c.

1131 {
1132  SXTmpStateData *toRet =
1133  g_new0( SXTmpStateData, 1 );
1134  if (g_date_valid (&(sx->last_date)))
1135  toRet->last_date = sx->last_date;
1136  else
1137  g_date_set_dmy (&(toRet->last_date), 1, 1, 1970);
1138  toRet->num_occur_rem = sx->num_occurances_remain;
1139  toRet->num_inst = sx->instance_num;
1140  return toRet;
1141 }
void gnc_sx_destroy_temporal_state ( SXTmpStateData stateData)

Frees the given stateDate object.

Definition at line 1162 of file SchedXaction.c.

1163 {
1164  g_free( (SXTmpStateData*)stateData );
1165 }
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 1239 of file SchedXaction.c.

1240 {
1241  return sx->deferredList;
1242 }
GList * deferredList
Definition: SchedXaction.h:118
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 1009 of file SchedXaction.c.

1010 {
1011  gint toRet = -1;
1012  SXTmpStateData *tsd;
1013 
1014  if ( stateData )
1015  {
1016  tsd = (SXTmpStateData*)stateData;
1017  toRet = tsd->num_inst;
1018  }
1019  else
1020  {
1021  toRet = sx->instance_num;
1022  }
1023 
1024  return toRet;
1025 }
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 726 of file SchedXaction.c.

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

Definition at line 559 of file SchedXaction.c.

560 {
561  return sx->schedule;
562 }
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  {
384  rtn = g_list_append(rtn, sx);
385  }
386  }
387  }
388  return rtn;
389 }
void qof_instance_get(const QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_get.
Definition: guid.h:65
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
const GncGUID * qof_entity_get_guid(gconstpointer)
Definition: SplitP.h:71
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 1144 of file SchedXaction.c.

1145 {
1146  GDate unused;
1147  SXTmpStateData *tsd = (SXTmpStateData*)stateData;
1148 
1149  g_date_clear( &unused, 1 );
1150  tsd->last_date =
1151  xaccSchedXactionGetInstanceAfter( sx,
1152  &unused,
1153  stateData );
1154  if ( xaccSchedXactionHasOccurDef( sx ) )
1155  {
1156  tsd->num_occur_rem -= 1;
1157  }
1158  tsd->num_inst += 1;
1159 }
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Definition: SchedXaction.c:678
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. If the instance is no longer useful; gnc_sx_destroy_temporal_state() it.

Definition at line 1213 of file SchedXaction.c.

1214 {
1215  GList *found_by_value;
1216 
1217  found_by_value = g_list_find_custom(
1218  sx->deferredList, deferStateData, _temporal_state_data_cmp);
1219  if (found_by_value == NULL)
1220  {
1221  g_warning("unable to find deferred instance");
1222  return;
1223  }
1224 
1225  gnc_sx_destroy_temporal_state(found_by_value->data);
1226  sx->deferredList = g_list_delete_link(sx->deferredList, found_by_value);
1227 }
void gnc_sx_destroy_temporal_state(SXTmpStateData *stateData)
GList * deferredList
Definition: SchedXaction.h:118
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 1028 of file SchedXaction.c.

1029 {
1030  g_return_if_fail(sx);
1031  if (sx->instance_num == instance_num)
1032  return;
1033  gnc_sx_begin_edit(sx);
1034  sx->instance_num = instance_num;
1035  qof_instance_set_dirty(&sx->inst);
1036  gnc_sx_commit_edit(sx);
1037 }
void gnc_sx_set_schedule ( SchedXaction sx,
GList *  schedule 
)
Parameters
[in]scheduleA GList<Recurrence*>

Definition at line 565 of file SchedXaction.c.

566 {
567  g_return_if_fail(sx);
568  gnc_sx_begin_edit(sx);
569  sx->schedule = schedule;
570  qof_instance_set_dirty(&sx->inst);
571  gnc_sx_commit_edit(sx);
572 }
void xaccSchedXactionDestroy ( SchedXaction sx)

Cleans up and frees a SchedXaction and its associated data.

Definition at line 473 of file SchedXaction.c.

474 {
475  qof_instance_set_destroying( QOF_INSTANCE(sx), TRUE );
476  gnc_sx_commit_edit( sx );
477 }
const GDate* xaccSchedXactionGetEndDate ( const SchedXaction sx)

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

Definition at line 628 of file SchedXaction.c.

629 {
630  g_assert (sx);
631  return &sx->end_date;
632 }
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 874 of file SchedXaction.c.

875 {
876  GDate last_occur, next_occur, tmpDate;
877 
878  g_date_clear( &last_occur, 1 );
879  g_date_clear( &next_occur, 1 );
880  g_date_clear( &tmpDate, 1 );
881 
882  if ( g_date_valid( &sx->last_date ) )
883  {
884  last_occur = sx->last_date;
885  }
886 
887  if ( stateData != NULL )
888  {
889  SXTmpStateData *tsd = (SXTmpStateData*)stateData;
890  last_occur = tsd->last_date;
891  }
892 
893  if ( g_date_valid( &sx->start_date ) )
894  {
895  if ( g_date_valid(&last_occur) )
896  {
897  last_occur =
898  ( g_date_compare( &last_occur,
899  &sx->start_date ) > 0 ?
900  last_occur : sx->start_date );
901  }
902  else
903  {
904  /* Think about this for a second, and you realize that if the
905  * start date is _today_, we need a last-occur date such that
906  * the 'next instance' is after that date, and equal to the
907  * start date... one day should be good.
908  *
909  * This only holds for the first instance [read: if the
910  * last[-occur]_date is invalid] */
911  last_occur = sx->start_date;
912  g_date_subtract_days( &last_occur, 1 );
913  }
914  }
915 
916  recurrenceListNextInstance(sx->schedule, &last_occur, &next_occur);
917 
918  /* out-of-bounds check */
919  if ( xaccSchedXactionHasEndDate( sx ) )
920  {
921  const GDate *end_date = xaccSchedXactionGetEndDate( sx );
922  if ( g_date_compare( &next_occur, end_date ) > 0 )
923  {
924  g_debug("next_occur past end date");
925  g_date_clear( &next_occur, 1 );
926  }
927  }
928  else if ( xaccSchedXactionHasOccurDef( sx ) )
929  {
930  if ( stateData )
931  {
932  SXTmpStateData *tsd = (SXTmpStateData*)stateData;
933  if ( tsd->num_occur_rem == 0 )
934  {
935  g_debug("no more occurances remain");
936  g_date_clear( &next_occur, 1 );
937  }
938  }
939  else
940  {
941  if ( sx->num_occurances_remain == 0 )
942  {
943  g_date_clear( &next_occur, 1 );
944  }
945  }
946  }
947 
948  return next_occur;
949 }
const GDate * xaccSchedXactionGetEndDate(const SchedXaction *sx)
Definition: SchedXaction.c:628
gboolean xaccSchedXactionHasOccurDef(const SchedXaction *sx)
Definition: SchedXaction.c:678
gboolean xaccSchedXactionHasOccurDef ( const SchedXaction sx)

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

Definition at line 678 of file SchedXaction.c.

679 {
680  return ( xaccSchedXactionGetNumOccur( sx ) != 0 );
681 }
SchedXaction* xaccSchedXactionMalloc ( QofBook book)

Creates and initializes a scheduled transaction.

Definition at line 404 of file SchedXaction.c.

405 {
406  SchedXaction *sx;
407 
408  g_return_val_if_fail (book, NULL);
409 
410  sx = g_object_new(GNC_TYPE_SCHEDXACTION, NULL);
411  xaccSchedXactionInit( sx, book );
412  qof_event_gen( &sx->inst, QOF_EVENT_CREATE , NULL);
413 
414  return sx;
415 }
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void xaccSchedXactionSetEndDate ( SchedXaction sx,
const GDate *  newEnd 
)

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

Definition at line 635 of file SchedXaction.c.

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

A copy of the name is made.

Definition at line 581 of file SchedXaction.c.

582 {
583  g_return_if_fail( newName != NULL );
584  gnc_sx_begin_edit(sx);
585  if ( sx->name != NULL )
586  {
587  g_free( sx->name );
588  sx->name = NULL;
589  }
590  sx->name = g_strdup( newName );
591  qof_instance_set_dirty(&sx->inst);
592  gnc_sx_commit_edit(sx);
593 }
void xaccSchedXactionSetNumOccur ( SchedXaction sx,
gint  numNum 
)

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

Definition at line 690 of file SchedXaction.c.

691 {
692  if (sx->num_occurances_total == new_num)
693  return;
694  gnc_sx_begin_edit(sx);
695  sx->num_occurances_remain = sx->num_occurances_total = new_num;
696  qof_instance_set_dirty(&sx->inst);
697  gnc_sx_commit_edit(sx);
698 }
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 1082 of file SchedXaction.c.

1084 {
1085  Transaction *new_trans;
1086  TTInfo *tti;
1087  TTSplitInfo *s_info;
1088  Split *new_split;
1089  GList *split_list;
1090 
1091  g_return_if_fail (book);
1092 
1093  /* delete any old transactions, if there are any */
1094  delete_template_trans( sx );
1095 
1096  for (; t_t_list != NULL; t_t_list = t_t_list->next)
1097  {
1098  tti = t_t_list->data;
1099 
1100  new_trans = xaccMallocTransaction(book);
1101 
1102  xaccTransBeginEdit(new_trans);
1103 
1104  xaccTransSetDescription(new_trans,
1105  gnc_ttinfo_get_description(tti));
1106 
1108 
1109  /* Set tran-num with gnc_set_num_action which is the same as
1110  * xaccTransSetNum with these arguments */
1111  gnc_set_num_action(new_trans, NULL,
1112  gnc_ttinfo_get_num(tti), NULL);
1113  xaccTransSetCurrency( new_trans,
1114  gnc_ttinfo_get_currency(tti) );
1115 
1116  for (split_list = gnc_ttinfo_get_template_splits(tti);
1117  split_list;
1118  split_list = split_list->next)
1119  {
1120  s_info = split_list->data;
1121  new_split = pack_split_info(s_info, sx->template_acct,
1122  new_trans, book);
1123  xaccTransAppendSplit(new_trans, new_split);
1124  }
1125  xaccTransCommitEdit(new_trans);
1126  }
1127 }
#define xaccTransAppendSplit(t, s)
Definition: Transaction.h:357
Transaction * xaccMallocTransaction(QofBook *book)
Definition: Transaction.c:513
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
Definition: Transaction.c:1920
void xaccTransSetDescription(Transaction *trans, const char *desc)
Definition: Transaction.c:2085
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Definition: Transaction.c:1354
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1579
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1380
Definition: SplitP.h:71
time64 gnc_time(time64 *tbuf)
get the current local time