~mdoyen/homebank/5.3.x

« back to all changes in this revision

Viewing changes to src/ui-split.c

  • Committer: Maxime Doyen
  • Date: 2020-01-09 20:52:00 UTC
  • Revision ID: homebank@free.fr-20200109205200-3ic3jdusu3kia20v
5.3 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  HomeBank -- Free, easy, personal accounting for everyone.
2
 
 *  Copyright (C) 1995-2019 Maxime DOYEN
 
2
 *  Copyright (C) 1995-2020 Maxime DOYEN
3
3
 *
4
4
 *  This file is part of HomeBank.
5
5
 *
334
334
 
335
335
        data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(widget), GTK_TYPE_WINDOW)), "inst_data");
336
336
 
337
 
        amount= g_strtod(gtk_entry_get_text(GTK_ENTRY(data->ST_amount)), NULL);
 
337
        amount = g_strtod(gtk_entry_get_text(GTK_ENTRY(data->ST_amount)), NULL);
338
338
 
339
339
        tmpval = hb_amount_round(amount, 2) != 0.0 ? TRUE : FALSE;
340
340
        gtk_widget_set_sensitive (data->BT_apply, tmpval);
405
405
        g_signal_handler_block(data->ST_amount, data->hid_amt);
406
406
 
407
407
        ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_cat), 0);
408
 
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), 0.0);
 
408
        if( data->mode == SPLIT_MODE_EMPTY )
 
409
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), 0.0);
409
410
        gtk_entry_set_text(GTK_ENTRY(data->ST_memo), "");
410
411
 
411
412
        g_signal_handler_unblock(data->ST_amount, data->hid_amt);
412
413
        g_signal_handler_unblock(data->PO_cat, data->hid_cat);
413
414
 
 
415
        gtk_widget_grab_focus(data->ST_amount);
 
416
        
414
417
        data->isedited = FALSE;
415
418
}
416
419
 
561
564
                amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
562
565
                if(amount)
563
566
                {
 
567
                        //#1848604 force sign according txn type
 
568
                        if( hb_amount_type_match(amount, data->txntype) == FALSE)
 
569
                                amount *= -1;
 
570
 
564
571
                        split->amount = amount;
565
572
                        split->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_cat));
566
573
                        split->memo = g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_memo)));
576
583
                                -1);
577
584
 
578
585
                        ui_split_dialog_compute (widget, data);
579
 
                        
580
586
                }
581
587
                else
582
588
                {
625
631
{
626
632
struct ui_split_dialog_data *data;
627
633
gint i, count, nbvalid;
628
 
gchar buf[48];
 
634
gchar buf[48], *msg;
629
635
gboolean sensitive;
630
636
GtkTreeModel *model;
631
637
GtkTreeIter     iter;
663
669
        data->remsplit = data->amount - data->sumsplit;
664
670
 
665
671
 
666
 
        //validation: 2 split min
 
672
        //validation: 2 split min, if 0 split
 
673
        //Accept button is not disabled to enable empty the splits
667
674
        sensitive = FALSE;
668
675
        if( (count == 0) || nbvalid >= 2 )
669
676
                sensitive = TRUE;
670
 
        gtk_dialog_set_response_sensitive(GTK_DIALOG(data->dialog), GTK_RESPONSE_ACCEPT, sensitive);
671
677
 
672
 
        if( hb_amount_round(data->amount, 2) != 0.0 )
 
678
        if( data->mode == SPLIT_MODE_AMOUNT )
673
679
        {
674
680
                if(!data->remsplit)
675
681
                        g_sprintf(buf, "----");
676
682
                else
 
683
                {
677
684
                        g_snprintf(buf, 48, "%.2f", data->remsplit);
678
 
 
 
685
                        //#1845841 bring back checkpoint with initial amount + init remainder
 
686
                        sensitive = (count > 1) ? FALSE : sensitive;
 
687
                        gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), data->remsplit);
 
688
                }
 
689
                                
679
690
                gtk_label_set_label(GTK_LABEL(data->LB_remain), buf);
680
691
 
681
692
                g_snprintf(buf, 48, "%.2f", data->amount);
684
695
 
685
696
        g_snprintf(buf, 48, "%.2f", data->sumsplit);
686
697
        gtk_label_set_text(GTK_LABEL(data->LB_sumsplit), buf);
687
 
        
 
698
 
 
699
        //if split sum sign do not match
 
700
        msg = "";
 
701
        if( hb_amount_type_match(data->sumsplit, data->txntype) == FALSE )
 
702
        {
 
703
                sensitive = FALSE;
 
704
                msg = _("Warning: sum of splits and transaction type don't match");
 
705
        }
 
706
        gtk_label_set_text(GTK_LABEL(data->LB_msg), msg);
 
707
 
 
708
        gtk_dialog_set_response_sensitive(GTK_DIALOG(data->dialog), GTK_RESPONSE_ACCEPT, sensitive);
688
709
}
689
710
 
690
711
 
709
730
}
710
731
 
711
732
 
712
 
GtkWidget *ui_split_dialog (GtkWidget *parent, GPtrArray **src_splits, gdouble amount, void (update_callbackFunction(GtkWidget*, gdouble)))
 
733
GtkWidget *ui_split_dialog (GtkWidget *parent, GPtrArray **src_splits, gint txntype, gdouble amount, void (update_callbackFunction(GtkWidget*, gdouble)))
713
734
{
714
735
struct ui_split_dialog_data *data;
715
736
GtkWidget *dialog, *content, *table, *box, *scrollwin;
742
763
        //todo: init should move 
743
764
        //clone splits or create new
744
765
        data->src_splits = *src_splits;
 
766
        data->txntype = txntype;
 
767
        data->mode = (hb_amount_round(amount, 2) != 0.0) ? SPLIT_MODE_AMOUNT : SPLIT_MODE_EMPTY;
745
768
        data->amount = amount;
746
769
        data->sumsplit = amount;
747
 
        
 
770
 
748
771
        if( *src_splits != NULL )
749
772
                data->tmp_splits = da_splits_clone(*src_splits); 
750
773
        else
834
857
                gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 0);
835
858
 
836
859
 
837
 
        if( hb_amount_round(data->amount, 2) != 0.0 )
 
860
        if( data->mode == SPLIT_MODE_AMOUNT )
838
861
        {
839
862
                row++;
840
863
                label = gtk_label_new(_("Transaction amount:"));
869
892
        data->LB_sumsplit = widget;
870
893
        gtk_grid_attach (GTK_GRID (table), widget, 2, row, 1, 1);
871
894
 
 
895
        row++;
 
896
        label = gtk_label_new(NULL);
 
897
        gtk_widget_set_halign (label, GTK_ALIGN_END);
 
898
        data->LB_msg = label;
 
899
        gtk_grid_attach (GTK_GRID (table), label, 0, row, 4, 1);
872
900
 
873
901
        //connect all our signals
874
902
        g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_split)), "changed", G_CALLBACK (ui_split_selection), data);