Merge branch 'master' of ssh://git.freeside.biz/home/git/freeside
[freeside.git] / httemplate / misc / email-customer-statement.html
index 92ce1c4..6b88f79 100644 (file)
@@ -1,15 +1,12 @@
-
- <% include('email-customers.html',
-      'form_action'       => 'email-customer-statement.html',
-      'title'             => 'Send statement to customer',
-      'no_search_fields'  => [ 'start_date', 'end_date' ],
-      'alternate_form'    => $alternate_form,
-      'post_search_hook'  => $post_search_hook,
-      'acl'               => $acl,
-      'process_url'       => 'process/email-customer-statement.html',
-    )
- %>
-
+<& email-customers.html,
+     'form_action'       => 'email-customer-statement.html',
+     'title'             => 'Send statement to customer',
+     'no_search_fields'  => [ 'start_date', 'end_date' ],
+     'alternate_form'    => $alternate_form,
+     'post_search_hook'  => $post_search_hook,
+     'acl'               => $acl,
+     'process_url'       => 'process/email-customer-statement.html',
+&>
 <%init>
 
 my $acl = 'Resend invoices';
@@ -28,23 +25,23 @@ my $alternate_form = sub {
         my $label = ucfirst($_);
         $label =~ s/_/ /;
         include('/elements/tr-input-date-field.html',{
-          'name' => $_,
-          'value' => $cgi->param($_) || '',
-          'label' => $label,
+          'name'   => $_,
+          'value'  => ( scalar($cgi->param($_)) || '' ),
+          'label'  => $label,
           'noinit' => $noinit++
         });
       }
       qw( start_date end_date )
     ),
     '</TABLE>',
-    '<INPUT TYPE="hidden" NAME="action" VALUE="preview">',
+    '<INPUT TYPE="hidden" NAME="preview" VALUE="1">',
     '<INPUT TYPE="submit" VALUE="Preview notice">',
   );
 };
 
 my $post_search_hook = sub {
   my %opt = @_;
-  return unless $cgi->param('action') eq 'preview';
+  return unless $cgi->param('preview');
   my $cust_main = qsearchs('cust_main',$opt{'search'})
     or die "Could not find customer";
 
@@ -56,7 +53,7 @@ my $post_search_hook = sub {
   # set from/subject/html_body based on date range
 
   $cgi->param('from',
-    $opt{'conf'}->config('invoice_from')
+    $opt{'conf'}->config('invoice_from', $cust_main->agentnum)
   );
 
   # shortcut for common text
@@ -66,23 +63,18 @@ my $post_search_hook = sub {
     ($cgi->param('end_date') ? ' through ' : '') .
     $cgi->param('end_date');
 
-  $cgi->param('subject',
-    $opt{'conf'}->config('company_name') . 
-    ' statement for ' .
-    $summary_text
-  );
+  my $company_name = $opt{'conf'}->config('company_name', $cust_main->agentnum);
+  my $subject = "$company_name statement for $summary_text";
+
+  $cgi->param('subject', $subject);
 
-  $cgi->param('html_body',
-    '<P>' .
-    $opt{'conf'}->config('company_name') . 
-    ' statement of charges and payments for ' .
-    $summary_text . 
-    "</P>" .
+  $cgi->param('body',
+    "<P>$subject</P>".
     include('/elements/customer-statement.html',
       'history' => [ 
         $cust_main->payment_history(
           map {
-            $_ => parse_datetime($cgi->param($_))
+            $_ => parse_datetime(scalar($cgi->param($_)))
           }
           qw( start_date end_date ),
         ),