]> Dogcows Code - chaz/homebank/blobdiff - src/hb-archive.c
import homebank-5.1.2
[chaz/homebank] / src / hb-archive.c
index 0ede27030cce95f71fb29d1ef1f7c0f67da9a627..c552f85d60ec02b867a7b9e2fb01de3fa94e0b28 100644 (file)
@@ -1,5 +1,5 @@
 /*  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.
  *
@@ -19,6 +19,7 @@
 
 #include "homebank.h"
 #include "hb-archive.h"
+#include "hb-split.h"
 
 /****************************************************************************/
 /* Debug macros                                                             */
@@ -51,6 +52,9 @@ Archive *new_item = g_memdup(src_item, sizeof(Archive));
        {
                //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;
 }
@@ -62,6 +66,9 @@ void da_archive_free(Archive *item)
                if(item->wording != NULL)
                        g_free(item->wording);
 
+               da_splits_free(item->splits);
+               //item->flags &= ~(OF_SPLIT); //Flag that Splits are cleared            
+               
                g_free(item);
        }
 }
@@ -107,27 +114,31 @@ Payee *pay;
        {
                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
                }
        }
 
@@ -135,11 +146,38 @@ Payee *pay;
 
 /* = = = = = = = = = = = = = = = = = = = = */
 
+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)
        {
@@ -161,17 +199,6 @@ guint32 nextpostdate = nextdate;
        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;
 }
 
@@ -180,7 +207,7 @@ gboolean scheduled_is_postable(Archive *arc)
 {
 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;
 
@@ -195,6 +222,9 @@ GDateWeekday wday;
 guint32 finalpostdate;
 gint shift;
 
+       DB( g_print("\n[scheduled] scheduled_get_postdate\n") );
+
+
        finalpostdate = postdate;
        
        tmpdate = g_date_new_julian(finalpostdate);
@@ -232,24 +262,58 @@ gint shift;
 }
 
 
+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;
 }
 
 
@@ -257,6 +321,19 @@ guint32 curdate = arc->nextdate;
 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;
 }
 
This page took 0.023788 seconds and 4 git commands to generate.