[freeside-devel] putting the balance_due value in templates

Luke S Crawford lsc at prgmr.com
Sun May 25 17:54:42 PDT 2008


Ivan Kohler <ivan at freeside.biz> writes:
> Seems like it would be more reasonable to add "balance_due" to the 
> %invoice_data hash that's used by T:T fill_in() rather than shoving it 
> directly in the FS::cust_bill::_template package.

Ok, I did that for the other invoice types, but it didn't seem to work for
the text type.  

> Also, there are two other kinds of invoices to make the variable 
> available in... 99% of folks never see the plaintext invoices.  :)

got the other two cases:  the text case is still kinda messy.  Full diff -u below:

debian64:~/freeside# diff -u   FS/FS/cust_bill.pm.orig FS/FS/cust_bill.pm
--- FS/FS/cust_bill.pm.orig     2008-05-26 05:44:17.000000000 +0000
+++ FS/FS/cust_bill.pm  2008-05-26 08:44:08.000000000 +0000
@@ -1651,7 +1651,7 @@
   $date = $self->_date;
   $agent = $self->cust_main->agent->agent;
   $page = 1;
-
+  $FS::cust_bill::_template::balance_due = $self->owed + $pr_total;
   if ( $FS::cust_bill::invoice_lines ) {
     $total_pages =
       int( scalar(@FS::cust_bill::buf) / $FS::cust_bill::invoice_lines );
@@ -1802,6 +1802,8 @@
     'terms'        => $conf->config('invoice_default_terms') || 'Payable upon receipt',
     #'notes'        => join("\n", $conf->config('invoice_latexnotes') ),
     'conf_dir'     => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
+    'balance_due'     => $balance_due,
+
   );
 
   my $countrydefault = $conf->config('countrydefault') || 'US';
@@ -2165,6 +2167,10 @@
   $html_template->compile()
     or die 'While compiling ' . $templatefile . ': ' . $Text::Template::ERROR;
 
+   my( $pr_total, @pr_cust_bill ) = $self->previous; #previous balance
+  my $balance_due = $self->owed + $pr_total;
+
+
   my %invoice_data = (
     'custnum'      => $self->custnum,
     'invnum'       => $self->invnum,
@@ -2183,6 +2189,8 @@
     'cid'          => $cid,
     'template'     => $template,
 #    'conf_dir'     => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
+    'balance_due'     => $balance_due,
+
   );
 
   if (


> If you wanted to be even MORE correct, And if you wanted to be super 
> correct, you could submit a patch (diff -u) against both HEAD and 
> FREESIDE_1_7_BRANCH which implemented the change.

Lemme know if this is good and I'll diff against head


LSC> I think this might be useful for many of the 'push' billing types (like
LSC> paypal, e-gold, etc...)  
> 
> There's work that could be done to support the "push"/"third-party" 
> billing types better.

If you can point me in the correct direction here, I'd appriciate it.  Thanks!


More information about the freeside-devel mailing list