/* HomeBank -- Free, easy, personal accounting for everyone.
- * Copyright (C) 1995-2014 Maxime DOYEN
+ * Copyright (C) 1995-2016 Maxime DOYEN
*
* This file is part of HomeBank.
*
#include "homebank.h"
#include "hb-archive.h"
+#include "hb-split.h"
#include "ext.h"
#include "refcount.h"
{
//duplicate the string
new_item->wording = g_strdup(src_item->wording);
+
+ if( da_splits_clone(src_item->splits, new_item->splits) > 0)
+ new_item->flags |= OF_SPLIT; //Flag that Splits are active
}
return new_item;
}
if(item->wording != NULL)
g_free(item->wording);
+ da_splits_free(item->splits);
+ //item->flags &= ~(OF_SPLIT); //Flag that Splits are cleared
+
rc_free(item);
}
}
{
g_warning("arc consistency: fixed invalid cat %d", item->kcat);
item->kcat = 0;
+ GLOBALS->changes_count++;
}
-
+
+ split_cat_consistency(item->splits);
+
// check payee exists
pay = da_pay_get(item->kpay);
if(pay == NULL)
{
g_warning("arc consistency: fixed invalid pay %d", item->kpay);
item->kpay = 0;
+ GLOBALS->changes_count++;
}
// reset dst acc for non xfer transaction
if( item->paymode != PAYMODE_INTXFER )
item->kxferacc = 0;
- // remove automation if dst_acc not exists
+ // delete automation if dst_acc not exists
if(item->paymode == PAYMODE_INTXFER)
{
acc = da_acc_get(item->kxferacc);
if(acc == NULL)
{
- item->flags &= ~(OF_AUTO); //remove flag
+ item->flags &= ~(OF_AUTO); //delete flag
}
}
/* = = = = = = = = = = = = = = = = = = = = */
+Archive *da_archive_init_from_transaction(Archive *arc, Transaction *txn)
+{
+ //fill it
+ arc->amount = txn->amount;
+ arc->kacc = txn->kacc;
+ arc->kxferacc = txn->kxferacc;
+ arc->paymode = txn->paymode;
+ arc->flags = txn->flags & (OF_INCOME);
+ arc->status = txn->status;
+ arc->kpay = txn->kpay;
+ arc->kcat = txn->kcat;
+ if(txn->wording != NULL)
+ arc->wording = g_strdup(txn->wording);
+ else
+ arc->wording = g_strdup(_("(new archive)"));
+
+ if( da_splits_clone(txn->splits, arc->splits) > 0)
+ arc->flags |= OF_SPLIT; //Flag that Splits are active
+
+ return arc;
+}
+
+
+
+
static guint32 _sched_date_get_next_post(Archive *arc, guint32 nextdate)
{
GDate *tmpdate;
guint32 nextpostdate = nextdate;
-
+
+ DB( g_print("\n[scheduled] _sched_date_get_next_post\n") );
+
tmpdate = g_date_new_julian(nextpostdate);
switch(arc->unit)
{
nextpostdate = g_date_get_julian(tmpdate);
g_date_free(tmpdate);
- /* check limit, update and maybe break */
- if(arc->flags & OF_LIMIT)
- {
- arc->limit--;
- if(arc->limit <= 0)
- {
- arc->flags ^= (OF_LIMIT | OF_AUTO); // invert flags
- nextpostdate = 0;
- }
- }
-
return nextpostdate;
}
{
gdouble value;
- value = arrondi(arc->amount, 2);
+ value = hb_amount_round(arc->amount, 2);
if( (arc->flags & OF_AUTO) && (arc->kacc > 0) && (value != 0.0) )
return TRUE;
guint32 finalpostdate;
gint shift;
+ DB( g_print("\n[scheduled] scheduled_get_postdate\n") );
+
+
finalpostdate = postdate;
tmpdate = g_date_new_julian(finalpostdate);
}
+guint32 scheduled_get_latepost_count(Archive *arc, guint32 jrefdate)
+{
+guint32 curdate = jrefdate - arc->nextdate;
+guint32 nblate = 0;
+ /*
+ switch(arc->unit)
+ {
+ case AUTO_UNIT_DAY:
+ nbpost = (curdate / arc->every);
+ g_print("debug d: %d => %f\n", curdate, nbpost);
+ break;
+ case AUTO_UNIT_WEEK:
+ nbpost = (curdate / ( 7 * arc->every));
+ g_print("debug w: %d => %f\n", curdate, nbpost);
+ break;
-guint32 scheduled_get_latepost_count(Archive *arc, guint32 jrefdate)
-{
-guint32 nbpost = 0;
-guint32 curdate = arc->nextdate;
+ case AUTO_UNIT_MONTH:
+ //approximate is sufficient
+ nbpost = (curdate / (( 365.2425 / 12) * arc->every));
+ g_print("debug m: %d => %f\n", curdate, nbpost);
+ break;
+
+ case AUTO_UNIT_YEAR:
+ //approximate is sufficient
+ nbpost = (curdate / ( 365.2425 * arc->every));
+ g_print("debug y: %d => %f\n", curdate, nbpost);
+ break;
+ }
+
+ nblate = floor(nbpost);
+
+ if(arc->flags & OF_LIMIT)
+ nblate = MIN(nblate, arc->limit);
+ nblate = MIN(nblate, 11);
+ */
+
+
+ // pre 5.1 way
+ curdate = arc->nextdate;
while(curdate <= jrefdate)
{
curdate = _sched_date_get_next_post(arc, curdate);
- nbpost++;
- // break at 11 max (to display +10)
- if(nbpost >= 11)
+ nblate++;
+ // break if over limit or at 11 max (to display +10)
+ if(nblate >= arc->limit || nblate >= 11)
break;
}
- return nbpost;
+ return nblate;
}
guint32 scheduled_date_advance(Archive *arc)
{
arc->nextdate = _sched_date_get_next_post(arc, arc->nextdate);
+
+ //#1556289
+ /* check limit, update and maybe break */
+ if(arc->flags & OF_LIMIT)
+ {
+ arc->limit--;
+ if(arc->limit <= 0)
+ {
+ arc->flags ^= (OF_LIMIT | OF_AUTO); // invert flags
+ arc->nextdate = 0;
+ }
+ }
+
return arc->nextdate;
}