~mdoyen/homebank/trunk

« back to all changes in this revision

Viewing changes to src/hb-filter.c

  • Committer: Maxime Doyen
  • Date: 2023-11-12 08:46:40 UTC
  • Revision ID: homebank@free.fr-20231112084640-x96hyb1h81il30y2
5.7.2 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
329
329
{
330
330
gint i;
331
331
 
 
332
        g_return_if_fail( flt != NULL );
 
333
 
332
334
        DB( g_print("\n[filter] default reset all %p\n", flt) );
333
335
 
334
336
        for(i=0;i<FLT_GRP_MAX;i++)
369
371
{
370
372
Tag *tag;
371
373
 
 
374
        g_return_if_fail( flt != NULL );
 
375
 
372
376
        DB( g_print("\n[filter] set tag by id\n") );
373
377
        
374
378
        if(flt->tag)
391
395
GList *lst_acc, *lnk_acc;
392
396
GList *lnk_txn;
393
397
 
 
398
        g_return_if_fail( flt != NULL );
 
399
 
394
400
        DB( g_print("\n[filter] set date bounds %p\n", flt) );
395
401
 
396
402
        flt->mindate = 0;
455
461
{
456
462
gboolean retval = FALSE;
457
463
 
 
464
        g_return_val_if_fail( flt != NULL, FALSE );
 
465
 
458
466
        DB( g_print("\n[filter] range future enabled\n") );
459
467
 
460
468
        DB( g_print(" fltrang=%d range=%d\n", flt->range, range) );
477
485
        }
478
486
 
479
487
        //TODO: custom date
 
488
 
480
489
        if( range == FLT_RANGE_MISC_ALLDATE )
481
490
        {
482
491
        GDate *date1, *date2;
486
495
                date1 = g_date_new_julian(GLOBALS->today);
487
496
                date2 = g_date_new_julian(flt->maxdate);
488
497
 
489
 
                if( date2 > date1 && (g_date_get_year(date2) == g_date_get_year(date1)
 
498
                if( date2 > date1
 
499
                 && (g_date_get_year(date2) == g_date_get_year(date1)
490
500
                 && g_date_get_month(date2) == g_date_get_month(date1)) )
491
501
                {
492
502
                        retval = TRUE;
502
512
}
503
513
 
504
514
 
505
 
guint32 filter_get_maxdate_forecast(Filter *filter)
 
515
//5.7 used only in rep_stats 
 
516
guint32 filter_get_maxdate_forecast(Filter *flt)
506
517
{
507
 
guint32 retval = filter->maxdate;
 
518
guint32 retval;
 
519
 
 
520
        retval = flt->maxdate;
508
521
 
509
522
        DB( g_print("\n[filter] get maxdate to forecast\n") );
510
523
 
511
 
        if( filter_preset_daterange_future_enable(filter, filter->range) )
 
524
        //if( filter_preset_daterange_future_enable(filter, filter->range) )
512
525
        {
513
526
        GDate *post_date = g_date_new();
514
527
 
526
539
 
527
540
 
528
541
//used only in register
529
 
void filter_preset_daterange_add_futuregap(Filter *filter, gint nbdays)
 
542
void filter_preset_daterange_add_futuregap(Filter *flt, gint nbdays)
530
543
{
 
544
        g_return_if_fail( flt != NULL );
 
545
 
531
546
        DB( g_print("\n[filter] range add future gap\n") );
532
547
        
533
 
        filter->nbdaysfuture = 0;
 
548
        flt->nbdaysfuture = 0;
534
549
        //#1840998 if future active and visible: we should always maxdate to today + nbdays
535
 
        if( filter_preset_daterange_future_enable(filter, filter->range) )
 
550
        if( filter_preset_daterange_future_enable(flt, flt->range) )
536
551
        {
537
552
        guint32 jforcedmax = GLOBALS->today + nbdays;
538
553
 
539
 
                if( filter->maxdate < jforcedmax )
540
 
                        filter->nbdaysfuture = jforcedmax - filter->maxdate;
 
554
                if( flt->maxdate < jforcedmax )
 
555
                        flt->nbdaysfuture = jforcedmax - flt->maxdate;
541
556
                //else
542
557
                //      filter->nbdaysfuture = nbdays;
543
558
 
544
 
                DB( g_print(" today=%d, tmpmax=%d, nbdays=%d\n final=%d", GLOBALS->today, jforcedmax, nbdays, filter->nbdaysfuture) );
 
559
                DB( g_print(" today=%d, tmpmax=%d, nbdays=%d\n final=%d", GLOBALS->today, jforcedmax, nbdays, flt->nbdaysfuture) );
545
560
        }
546
561
}
547
562
 
553
568
guint16 month, year, yfiscal, qnum;
554
569
GDateWeekday wday;
555
570
 
 
571
        g_return_if_fail( flt != NULL );
 
572
 
556
573
        DB( g_print("\n[filter] daterange set %p %d\n", flt, range) );
557
574
 
558
575
        flt->range = range;
731
748
void filter_preset_type_set(Filter *flt, gint type, gint mode)
732
749
{
733
750
 
 
751
        g_return_if_fail( flt != NULL );
 
752
 
734
753
        DB( g_print("\n[filter] preset type set\n") );
735
754
 
736
755
        flt->option[FLT_GRP_TYPE] = FLT_OFF;
763
782
/* = = = = = = = = = = = = = = = = */
764
783
 
765
784
 
766
 
static void filter_group_import_keys(Filter *flt, gint group, gchar *text)
767
 
{
768
 
gchar **str_array;
769
 
gint len, i;
770
 
 
771
 
        DB( g_print(" import keys '%s'\n", text) );
772
 
 
773
 
        str_array = g_strsplit (text, ",", -1);
774
 
        len = g_strv_length( str_array );
775
 
        for(i=0;i<len;i++)
776
 
        {
777
 
        guint32 key = atoi(str_array[i]);
778
 
 
779
 
                
780
 
                switch(group)
781
 
                {
782
 
                        case FLT_GRP_ACCOUNT:
783
 
                                if( da_acc_get(i) )
784
 
                                {
785
 
                                        da_flt_status_acc_set(flt, key, TRUE);
786
 
                                        DB( g_print(" set acc='%d' to true\n", key) );
787
 
                                }
788
 
                                break;
789
 
                        case FLT_GRP_PAYEE:
790
 
                                if( da_pay_get(i) )
791
 
                                {
792
 
                                        da_flt_status_pay_set(flt, key, TRUE);
793
 
                                        DB( g_print(" set pay='%d' to true\n", key) );
794
 
                                }
795
 
                                break;
796
 
                        case FLT_GRP_CATEGORY:
797
 
                                if( da_cat_get(i) )
798
 
                                {
799
 
                                        da_flt_status_cat_set(flt, key, TRUE);
800
 
                                        DB( g_print(" set cat='%d' to true\n", key) );
801
 
                                }
802
 
                                break;
803
 
                        /*case FLT_GRP_TAG:
804
 
                                da_flt_status_tag_set(flt, key, TRUE);
805
 
                                break;*/
806
 
                }
807
 
        }
808
 
        g_strfreev(str_array);
809
 
}
810
 
 
811
 
 
812
 
void filter_group_import(Filter *flt, gint group, const gchar *text)
813
 
{
814
 
gchar **str_array;
815
 
gint len;
816
 
 
817
 
 
818
 
        switch(group)
819
 
        {
820
 
                case FLT_GRP_DATE:
821
 
                        str_array = g_strsplit (text, "|", 4);
822
 
                        len = g_strv_length( str_array );
823
 
 
824
 
                        if(len == 2)
825
 
                        {
826
 
                                flt->option[group] = atoi(str_array[0]);
827
 
                                flt->range = atoi(str_array[1]);
828
 
                        }
829
 
                        if(len == 4 && flt->range == FLT_RANGE_MISC_CUSTOM)
830
 
                        {
831
 
                                flt->mindate = atoi(str_array[2]);
832
 
                                flt->maxdate = atoi(str_array[3]);
833
 
                        }
834
 
                        g_strfreev(str_array);
835
 
                        break;
836
 
                
837
 
                case FLT_GRP_ACCOUNT:
838
 
                        str_array = g_strsplit (text, "|", 2);
839
 
                        len = g_strv_length( str_array );
840
 
 
841
 
                        if(len == 2)
842
 
                        {
843
 
                                flt->option[group] = atoi(str_array[0]);
844
 
                                filter_group_import_keys(flt, FLT_GRP_ACCOUNT, str_array[1]);
845
 
                        }
846
 
                        g_strfreev(str_array);
847
 
                        break;
848
 
 
849
 
                case FLT_GRP_PAYEE:
850
 
                        str_array = g_strsplit (text, "|", 2);
851
 
                        len = g_strv_length( str_array );
852
 
 
853
 
                        if(len == 2)
854
 
                        {
855
 
                                flt->option[group] = atoi(str_array[0]);
856
 
                                filter_group_import_keys(flt, FLT_GRP_PAYEE, str_array[1]);
857
 
                        }
858
 
                        g_strfreev(str_array);
859
 
                        break;
860
 
 
861
 
                case FLT_GRP_CATEGORY:
862
 
                        str_array = g_strsplit (text, "|", 2);
863
 
                        len = g_strv_length( str_array );
864
 
 
865
 
                        if(len == 2)
866
 
                        {
867
 
                                flt->option[group] = atoi(str_array[0]);
868
 
                                filter_group_import_keys(flt, FLT_GRP_CATEGORY, str_array[1]);
869
 
                        }
870
 
                        g_strfreev(str_array);
871
 
                        break;
872
 
 
873
 
                        
874
 
                        
875
 
        }
876
 
}
877
 
 
878
 
 
879
 
 
880
 
gchar *filter_group_export(Filter *flt, gint group)
881
 
{
882
 
gchar *retval = NULL;
883
 
GString *node;
884
 
guint i;
885
 
 
886
 
        switch(group)
887
 
        {
888
 
                case FLT_GRP_DATE:
889
 
                        if(flt->option[group] > 0)
890
 
                        {
891
 
                                //TODO: maybe always keep 4 values here
892
 
                                if(flt->range == FLT_RANGE_MISC_CUSTOM)
893
 
                                        retval = g_strdup_printf("%d|%d|%d|%d", flt->option[group], flt->range, flt->mindate, flt->maxdate);
894
 
                                else
895
 
                                        retval = g_strdup_printf("%d|%d", flt->option[group], flt->range);
896
 
                        }
897
 
                        break;
898
 
                case FLT_GRP_ACCOUNT:
899
 
                        if(flt->option[group] > 0)
900
 
                        {
901
 
                                node = g_string_sized_new(flt->gbacc->len);
902
 
                                g_string_append_printf(node, "%d|", flt->option[group]);
903
 
                                DB( g_printf("acc len:%d\n", flt->gbacc->len) );
904
 
                                for(i=0;i<flt->gbacc->len;i++)
905
 
                                {
906
 
                                        if( da_acc_get(i) )
907
 
                                                if( da_flt_status_acc_get(flt, i) == TRUE )
908
 
                                                        g_string_append_printf(node, "%d,", i);
909
 
                                }
910
 
                                g_string_erase(node, node->len-1, 1);
911
 
                                retval = node->str;
912
 
                                g_string_free(node, FALSE);
913
 
                                DB( g_printf(" '%s'\n", retval) );
914
 
                                node = NULL;
915
 
                        }
916
 
                        break;
917
 
                case FLT_GRP_PAYEE:
918
 
                        if(flt->option[group] > 0)
919
 
                        {
920
 
                                node = g_string_sized_new(flt->gbpay->len);
921
 
                                g_string_append_printf(node, "%d|", flt->option[group]);
922
 
                                DB( g_printf("pay len:%d\n", flt->gbpay->len) );
923
 
                                for(i=0;i<flt->gbpay->len;i++)
924
 
                                {
925
 
                                        if( da_pay_get(i) )
926
 
                                                if( da_flt_status_pay_get(flt, i) == TRUE )
927
 
                                                        g_string_append_printf(node, "%d,", i);
928
 
                                }
929
 
                                g_string_erase(node, node->len-1, 1);
930
 
                                retval = node->str;
931
 
                                g_string_free(node, FALSE);
932
 
                                DB( g_printf(" '%s'\n", retval) );
933
 
                                node = NULL;
934
 
                        }
935
 
                        break;
936
 
                case FLT_GRP_CATEGORY:
937
 
                        if(flt->option[group] > 0)
938
 
                        {
939
 
                                node = g_string_sized_new(flt->gbcat->len);
940
 
                                g_string_append_printf(node, "%d|", flt->option[group]);
941
 
                                DB( g_printf("cat len:%d\n", flt->gbcat->len) );
942
 
                                for(i=0;i<flt->gbcat->len;i++)
943
 
                                {
944
 
                                        if( da_cat_get(i) )
945
 
                                                if( da_flt_status_cat_get(flt, i) == TRUE )
946
 
                                                        g_string_append_printf(node, "%d,", i);
947
 
                                }
948
 
                                g_string_erase(node, node->len-1, 1);
949
 
                                retval = node->str;
950
 
                                g_string_free(node, FALSE);
951
 
                                DB( g_printf(" '%s'\n", retval) );
952
 
                                node = NULL;
953
 
                        }                       break;
954
 
                case FLT_GRP_TAG:
955
 
                        if(flt->option[group] > 0)
956
 
                        {
957
 
                
958
 
 
959
 
                        }
960
 
                        break;
961
 
                case FLT_GRP_TEXT:
962
 
                        if(flt->option[group] > 0)
963
 
                        {
964
 
                
965
 
 
966
 
                        }
967
 
                        break;
968
 
                case FLT_GRP_AMOUNT:
969
 
                        if(flt->option[group] > 0)
970
 
                        {
971
 
                
972
 
 
973
 
                        }
974
 
                        break;
975
 
                case FLT_GRP_PAYMODE:
976
 
                        if(flt->option[group] > 0)
977
 
                        {
978
 
                
979
 
 
980
 
                        }
981
 
                        break;
982
 
                case FLT_GRP_STATUS:
983
 
                        if(flt->option[group] > 0)
984
 
                        {
985
 
                
986
 
 
987
 
                        }
988
 
                        break;
989
 
                case FLT_GRP_TYPE:
990
 
                        if(flt->option[group] > 0)
991
 
                        {
992
 
                
993
 
 
994
 
                        }
995
 
                        break;
996
 
        }
997
 
        return retval;
998
 
}
999
 
 
1000
 
 
1001
 
 
1002
785
void filter_preset_status_set(Filter *flt, gint status)
1003
786
{
1004
787
 
 
788
        g_return_if_fail( flt != NULL );
 
789
 
1005
790
        DB( g_print("\n[filter] preset status set\n") );
1006
791
        
1007
792
        /* any status */
1074
859
GDate *date;
1075
860
gchar *retval = NULL;
1076
861
 
 
862
        g_return_val_if_fail( flt != NULL, NULL );
 
863
 
1077
864
        DB( g_print("\n[filter] daterange text get\n") );
1078
865
        
1079
866
        date = g_date_new_julian(flt->mindate);
1168
955
guint count, i;
1169
956
gboolean retval = FALSE;
1170
957
 
 
958
        g_return_val_if_fail( flt != NULL, FALSE );
 
959
 
1171
960
        if(flt->gbtag == NULL)
1172
961
                return FALSE;
1173
962
 
1338
1127
gboolean status;
1339
1128
gint insert = 1;
1340
1129
 
 
1130
        g_return_val_if_fail( flt != NULL, 1 );
 
1131
 
1341
1132
/* account */
1342
1133
        if(flt->option[FLT_GRP_ACCOUNT])
1343
1134
        {