@@ -278,6 +278,7 @@ struct _print_check_dialog
278278
279279 Split * split ;
280280 GList * splits ;
281+ Account * account ;
281282
282283 GtkWidget * format_combobox ;
283284 gint format_max ;
@@ -369,6 +370,44 @@ get_check_address( PrintCheckDialog *pcd)
369370 return address ;
370371}
371372
373+ struct _trans_amount
374+ {
375+ const Transaction * trans ;
376+ gnc_numeric amount ;
377+ };
378+
379+ static void
380+ subtotal_subaccount (const Account * account , struct _trans_amount * trans_amount )
381+ {
382+ /* Get the amount of this account in the transaction.*/
383+ gnc_numeric amount = xaccTransGetAccountAmount (trans_amount -> trans , account );
384+ /* Accumulate. */
385+ trans_amount -> amount = gnc_numeric_add_fixed (trans_amount -> amount , amount );
386+ }
387+
388+ /* This function returns the amount of the check.
389+ */
390+ static gnc_numeric
391+ get_check_amount (PrintCheckDialog * pcd )
392+ {
393+ gnc_numeric amount ;
394+ if (pcd -> account )
395+ {
396+ /* A parent account, e.g. from a subaccount register plugin page.
397+ * Subtotal the amount of all splits from descendant accounts. */
398+ struct _trans_amount trans_amount ;
399+ trans_amount .trans = xaccSplitGetParent (pcd -> split );
400+ trans_amount .amount = gnc_numeric_zero ();
401+ gnc_account_foreach_descendant (pcd -> account , (AccountCb )subtotal_subaccount , & trans_amount );
402+ amount = trans_amount .amount ;
403+ }
404+ else
405+ {
406+ /* Print just the amount of the split. */
407+ amount = xaccSplitGetAmount (pcd -> split );
408+ }
409+ return gnc_numeric_abs (amount );
410+ }
372411
373412//@{
374413/** @name Split printing functions */
@@ -1606,10 +1645,13 @@ initialize_format_combobox (PrintCheckDialog *pcd)
16061645/*****************************************************
16071646 * gnc_ui_print_check_dialog_create *
16081647 * make a new print check dialog and wait for it. *
1648+ * If account is given, this is a parent account to *
1649+ * subtotal the amount of all splits under it. *
16091650 *****************************************************/
16101651void
16111652gnc_ui_print_check_dialog_create (GtkWidget * parent ,
1612- GList * splits )
1653+ GList * splits ,
1654+ Account * account )
16131655{
16141656 PrintCheckDialog * pcd ;
16151657 GtkBuilder * builder ;
@@ -1620,6 +1662,7 @@ gnc_ui_print_check_dialog_create(GtkWidget *parent,
16201662 pcd = g_new0 (PrintCheckDialog , 1 );
16211663 pcd -> caller_window = GTK_WINDOW (parent );
16221664 pcd -> splits = g_list_copy (splits );
1665+ pcd -> account = account ;
16231666
16241667 builder = gtk_builder_new ();
16251668 gnc_builder_add_from_file (builder , "dialog-print-check.glade" , "adjustment1" );
@@ -2112,7 +2155,7 @@ draw_page_items(GtkPrintContext *context,
21122155 trans = xaccSplitGetParent (pcd -> split );
21132156 /* This was valid when the check printing dialog was instantiated. */
21142157 g_return_if_fail (trans );
2115- amount = gnc_numeric_abs ( xaccSplitGetAmount ( pcd -> split ) );
2158+ amount = get_check_amount ( pcd );
21162159
21172160 if (format -> font )
21182161 default_desc = pango_font_description_from_string (format -> font );
0 commit comments