RT#42591: OBH Adding Quotation error
[freeside.git] / FS / FS / Template_Mixin.pm
index 775cc3d..6b23149 100644 (file)
@@ -147,6 +147,10 @@ sub print_latex {
   $template ||= $self->_agent_template
     if $self->can('_agent_template');
 
+  #the new way
+  $self->set('mode', $params{mode})
+    if $params{mode};
+
   my $pkey = $self->primary_key;
   my $tmp_template = $self->table. '.'. $self->$pkey. '.XXXXXXXX';
 
@@ -1059,7 +1063,7 @@ sub print_generic {
   # start setting up summary subtotals
   my @summary_subtotals;
   my $method = $conf->config('summary_subtotals_method');
-  if ( $method and $method ne $conf->config($tc.'sections_method') ) {
+  if ( ( ref($self) ne 'FS::quotation' ) and $method and $method ne $conf->config($tc.'sections_method') ) {
     # then re-section them by the correct method
     my %section_method = ( by_category => 1 );
     if ( $conf->config('summary_subtotals_method') eq 'location' ) {
@@ -1666,6 +1670,13 @@ sub print_generic {
 
   } else { # this is where we actually create the invoice
 
+    if ( $params{no_addresses} ) {
+      delete $invoice_data{$_} foreach qw(
+        payname company address1 address2 city state zip country
+      );
+      $invoice_data{returnaddress} = '~';
+    }
+
     warn "filling in template for invoice ". $self->invnum. "\n"
       if $DEBUG;
     warn join("\n", map " $_ => ". $invoice_data{$_}, keys %invoice_data). "\n"
@@ -2345,12 +2356,19 @@ sub mimebuild_pdf {
   );
 }
 
+=item postal_mail_fsinc
 
+Sends this invoice to the Freeside Internet Services, Inc. print and mail
+service.
+
+=cut
 
 use CAM::PDF;
+use IO::Socket::SSL;
 use LWP::UserAgent;
 use HTTP::Request::Common qw( POST );
 use JSON::XS;
+use MIME::Base64;
 sub postal_mail_fsinc {
   my ( $self, %opt ) = @_;
 
@@ -2382,14 +2400,20 @@ sub postal_mail_fsinc {
   } else {
     die "Unparsable company_address; contact support\@freeside.biz\n";
   }
+  $company_city =~ s/,$//;
 
-  my $file = $self->print_pdf(%opt);
+  my $file = $self->print_pdf(%opt, 'no_addresses' => 1);
   my $pages = CAM::PDF->new($file)->numPages;
 
-  my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname'=>0 });
+  my $ua = LWP::UserAgent->new(
+    'ssl_opts' => { 
+      verify_hostname => 0,
+      SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
+    }
+  );
   my $response = $ua->request( POST $url, [
     'support-key'      => scalar($conf->config('support-key')),
-    'file'             => $file,
+    'file'             => encode_base64($file),
     'pages'            => $pages,
 
     #from:
@@ -2427,28 +2451,11 @@ sub postal_mail_fsinc {
 
   die $content->{error}."\n"
     if $content->{error};
-}
-
-1;
-    'address1'         => $bill_location->address1,
-    'address2'         => $bill_location->address2,
-    'city'             => $bill_location->city,
-    'state'            => $bill_location->state,
-    'zip'              => $bill_location->zip,
-    'country'          => $bill_location->country,
-  ]);
-
-  die "Print connection error: ". $response->message
-    unless $response->is_success;
 
-  local $@;
-  my $content = eval { decode_json($response->content) };
-  die "Print JSON error : $@\n" if $@;
-
-  die $content->{error}."\n"
-    if $content->{error};
+  #TODO: store this so we can query for a status later
+  warn "Invoice printed, ID ". $content->{id}. "\n";
 
-  #TODO: get some kind of letter ID back we can later retreive a status on
+  $content->{id};
 }
 
 =item _items_sections OPTIONS
@@ -3278,7 +3285,7 @@ sub _items_cust_bill_pkg {
         my @details = $cust_bill_pkg->details;
 
         # and I guess they're never bundled either?
-        if ( $cust_bill_pkg->setup != 0 ) {
+        if (( $cust_bill_pkg->setup != 0 ) || ( $cust_bill_pkg->setup_show_zero )) {
           my $description = $desc;
           $description .= ' Setup'
             if $cust_bill_pkg->recur != 0
@@ -3299,7 +3306,7 @@ sub _items_cust_bill_pkg {
                              ),
           };
         }
-        if ( $cust_bill_pkg->recur != 0 ) {
+        if (( $cust_bill_pkg->recur != 0 ) || ( $cust_bill_pkg->recur_show_zero )) {
           #push @b, {
           $r = {
             'pkgnum'      => $cust_bill_pkg->pkgpart, #so it displays in Ref