~mdoyen/homebank/trunk

« back to all changes in this revision

Viewing changes to src/list-operation.c

  • Committer: Maxime Doyen
  • Date: 2020-09-06 09:50:00 UTC
  • Revision ID: homebank@free.fr-20200906095000-05h4na2yv8ab58p5
5.4.3 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
        if(txn->date > GLOBALS->today)
188
188
        {
189
189
                g_object_set(renderer, 
190
 
                //      "scale-set", TRUE, 
191
 
                        "scale", 0.8,
 
190
                //      "scale-set", TRUE,
 
191
                //5.4.3 scale disabled
 
192
                //      "scale", 0.8,
192
193
                //      "style-set", TRUE,
193
194
                        "style",        PANGO_STYLE_OBLIQUE,
194
195
                NULL);
195
196
        }
196
197
        else
197
198
        {
198
 
                g_object_set(renderer, "scale-set", FALSE, "style-set", FALSE,
 
199
                //5.4.3 scale disabled
 
200
                g_object_set(renderer, "style-set", FALSE,
 
201
                //g_object_set(renderer, "scale-set", FALSE, "style-set", FALSE,
199
202
                NULL);
200
203
        }
201
204
        
596
599
 
597
600
/* = = = = = = = = = = = = = = = = */
598
601
 
 
602
 
 
603
static void list_txn_to_string_line(GString *node, gchar sep, Transaction *ope, guint32 kcat, gchar *memo, gdouble amount, gboolean incacc)
 
604
{
 
605
Payee *payee;
 
606
Category *category;
 
607
gchar *tags;
 
608
char strbuf[G_ASCII_DTOSTR_BUF_SIZE];
 
609
 
 
610
        //account
 
611
        if( incacc )
 
612
        {
 
613
        Account *acc = da_acc_get(ope->kacc);
 
614
        
 
615
                g_string_append (node, (acc != NULL) ? acc->name : "");
 
616
                g_string_append_c (node, sep );
 
617
        }
 
618
 
 
619
        //date
 
620
        hb_sprint_date(strbuf, ope->date);
 
621
        g_string_append (node, strbuf );
 
622
        g_string_append_c (node, sep );
 
623
        
 
624
        //paymode
 
625
        g_snprintf(strbuf, sizeof (strbuf), "%d", ope->paymode);
 
626
        g_string_append (node, strbuf );
 
627
        g_string_append_c (node, sep );
 
628
 
 
629
        //info
 
630
        g_string_append (node, (ope->info != NULL) ? ope->info : "" );
 
631
        g_string_append_c (node, sep );
 
632
                
 
633
        //payee 
 
634
        payee = da_pay_get(ope->kpay);
 
635
        g_string_append (node, (payee->name != NULL) ? payee->name : "");
 
636
        g_string_append_c (node, sep );
 
637
 
 
638
        //memo
 
639
        g_string_append (node, (memo != NULL) ? memo : "" );
 
640
        g_string_append_c (node, sep );
 
641
 
 
642
        //amount
 
643
 
 
644
 
 
645
        //#793719
 
646
        //g_ascii_dtostr (amountbuf, sizeof (amountbuf), ope->amount);
 
647
        //#1750257 use locale numdigit
 
648
        //g_ascii_formatd (amountbuf, sizeof (amountbuf), "%.2f", ope->amount);
 
649
        //TODO: or not we should use the currency fmt here
 
650
        g_snprintf(strbuf, sizeof (strbuf), "%.2f", amount);
 
651
 
 
652
        DB( g_print("amount = %f '%s'\n", amount, strbuf) );
 
653
        g_string_append (node, strbuf );
 
654
        g_string_append_c (node, sep );
 
655
 
 
656
        //status
 
657
        g_string_append (node, transaction_get_status_string(ope) );
 
658
        g_string_append_c (node, sep );
 
659
 
 
660
 
 
661
        //category
 
662
        category = da_cat_get(kcat);
 
663
        g_string_append (node, (category->fullname != NULL) ? category->fullname : "" );
 
664
        g_string_append_c (node, sep );
 
665
 
 
666
        //tags
 
667
        tags = tags_tostring(ope->tags);
 
668
        g_string_append (node, tags != NULL ? tags : "");
 
669
        g_free(tags);
 
670
 
 
671
        //eol
 
672
        g_string_append (node, "\n" );
 
673
 
 
674
}
 
675
 
 
676
 
599
677
//#1847907 v 5.3.2 add reconcile as c column like in pdf export
600
 
GString *list_txn_to_string(GtkTreeView *treeview, gboolean clipboard)
 
678
GString *list_txn_to_string(GtkTreeView *treeview, gboolean clipboard, gboolean incsplit, gboolean incacc)
601
679
{
602
680
struct list_txn_data *data = NULL;
603
681
GtkTreeModel *model;
604
682
GtkTreeIter     iter;
605
683
gboolean valid;
606
684
GString *node;
607
 
const gchar *format;
608
685
Transaction *ope;
609
 
gchar datebuf[16];
610
 
gchar *payeename, *categoryname;
611
686
gdouble amount, samount;
612
 
Payee *payee;
613
 
Category *category;
614
 
gchar *tags;
615
 
char amountbuf[G_ASCII_DTOSTR_BUF_SIZE];
 
687
gchar sep;
616
688
 
617
689
        data = g_object_get_data(G_OBJECT(treeview), "inst_data");
618
690
        
619
691
        node = g_string_new(NULL);
620
692
 
621
 
        if(clipboard)
622
 
        {
623
 
                g_string_append (node, "date\tpaymode\tinfo\tpayee\tmemo\tamount\tc\tcategory\ttags\n");
624
 
                format = "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n";
625
 
        }
626
 
        else
627
 
        {
628
 
                g_string_append (node, "date;paymode;info;payee;memo;amount;c;category;tags\n");
629
 
                format = "%s;%d;%s;%s;%s;%s;%s;%s;%s\n";
630
 
        }
631
 
        
 
693
        sep = (clipboard == TRUE) ? '\t' : ';';
 
694
 
 
695
        // header line
 
696
        if( incacc )
 
697
        {
 
698
                g_string_append (node, "account" );
 
699
                g_string_append_c (node, sep );
 
700
        }
 
701
        g_string_append (node, "date" );
 
702
        g_string_append_c (node, sep );
 
703
        g_string_append (node, "paymode" );
 
704
        g_string_append_c (node, sep );
 
705
        g_string_append (node, "info" );
 
706
        g_string_append_c (node, sep );
 
707
        g_string_append (node, "payee" );
 
708
        g_string_append_c (node, sep );
 
709
        g_string_append (node, "memo" );
 
710
        g_string_append_c (node, sep );
 
711
        g_string_append (node, "amount" );
 
712
        g_string_append_c (node, sep );
 
713
        g_string_append (node, "c" );
 
714
        g_string_append_c (node, sep );
 
715
        g_string_append (node, "category" );
 
716
        g_string_append_c (node, sep );
 
717
        g_string_append (node, "tags");
 
718
        g_string_append (node, "\n" );
 
719
 
 
720
        // each txn     
632
721
        model = gtk_tree_view_get_model(treeview);
633
722
        valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
634
723
        while (valid)
638
727
                    MODEL_TXN_SPLITAMT, &samount,
639
728
                        -1);
640
729
 
641
 
                hb_sprint_date(datebuf, ope->date);
642
 
 
643
 
                payee = da_pay_get(ope->kpay);
644
 
                payeename = (payee->name == NULL) ? "" : payee->name;
645
 
                category = da_cat_get(ope->kcat);
646
 
                categoryname = (category->name == NULL) ? NULL : category->fullname;
647
 
                tags = tags_tostring(ope->tags);
648
 
 
649
 
                amount = ope->amount;
650
 
                //for detail display the split part (if any)
651
 
                if( data && (data->list_type == LIST_TXN_TYPE_DETAIL) )
652
 
                        amount = samount;
653
 
 
654
 
                //#793719
655
 
                //g_ascii_dtostr (amountbuf, sizeof (amountbuf), ope->amount);
656
 
                //#1750257 use locale numdigit
657
 
                //g_ascii_formatd (amountbuf, sizeof (amountbuf), "%.2f", ope->amount);
658
 
                //TODO: we should use the currency fmt here
659
 
                g_snprintf(amountbuf, sizeof (amountbuf), "%.2f", amount);
660
 
 
661
 
                DB( g_print("amount = %f '%s'\n", amount, amountbuf) );
662
 
 
663
 
                g_string_append_printf(node, format,
664
 
                                datebuf,
665
 
                                ope->paymode,
666
 
                                ope->info != NULL ? ope->info : "",
667
 
                                payeename,
668
 
                                ope->memo != NULL ? ope->memo : "",
669
 
                                amountbuf,
670
 
                        transaction_get_status_string(ope),
671
 
                                categoryname != NULL ? categoryname : "",
672
 
                                tags != NULL ? tags : ""
673
 
                                );
674
 
 
675
 
                //leak
676
 
                g_free(tags);
 
730
                //normal export: if we don't want split or the txn has no split
 
731
                if( (incsplit == FALSE) )
 
732
                {
 
733
                        amount = ope->amount;
 
734
                        //for detail display the split part (if any)
 
735
                        if( data && (data->list_type == LIST_TXN_TYPE_DETAIL) )
 
736
                                amount = samount;
 
737
                        list_txn_to_string_line(node, sep, ope, ope->kcat, ope->memo, amount, incacc);
 
738
                }
 
739
                else
 
740
                {
 
741
                        if( (ope->splits == NULL) )
 
742
                        {
 
743
                                list_txn_to_string_line(node, sep, ope, ope->kcat, ope->memo, ope->amount, incacc);
 
744
                        }
 
745
                        else
 
746
                        {
 
747
                        guint i, nbsplit = da_splits_length(ope->splits);
 
748
 
 
749
                                for(i=0;i<nbsplit;i++)
 
750
                                {
 
751
                                Split *split = da_splits_get(ope->splits, i);
 
752
                                        list_txn_to_string_line(node, sep, ope, split->kcat, split->memo, split->amount, incacc);
 
753
                                }
 
754
                        }
 
755
                }
677
756
 
678
757
                valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
679
758
        }