*** empty log message ***
authorivan <ivan>
Thu, 7 Mar 2002 14:10:10 +0000 (14:10 +0000)
committerivan <ivan>
Thu, 7 Mar 2002 14:10:10 +0000 (14:10 +0000)
FS/FS/cust_bill.pm
FS/FS/part_export.pm
FS/FS/part_export_option.pm
FS/FS/queue.pm

index 1ec9298..6de88cc 100644 (file)
@@ -388,7 +388,7 @@ sub send {
   #my @print_text = $cust_bill->print_text; #( date )
   my @invoicing_list = $self->cust_main->invoicing_list;
   if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice
-    $ENV{SMTPHOSTS} = $smtpmachine;
+    #$ENV{SMTPHOSTS} = $smtpmachine;
     $ENV{MAILADDRESS} = $invoice_from;
     my $header = new Mail::Header ( [
       "From: $invoice_from",
@@ -401,11 +401,14 @@ sub send {
     my $message = new Mail::Internet (
       'Header' => $header,
       'Body' => [ $self->print_text ], #( date)
+      #'Debug' => 1,
     );
-    $message->smtpsend
-      or return "(customer # ". $self->custnum. ") can't send invoice email".
-                " for ". join(', ', grep { $_ ne 'POST' } @invoicing_list ).
-                " to server $smtpmachine!";
+    $!=0;
+    $message->smtpsend( Host => $smtpmachine )
+      or $message->smtpsend( Host => $smtpmachine, Debug => 1 )
+        or return "(customer # ". $self->custnum. ") can't send invoice email".
+                  " to ". join(', ', grep { $_ ne 'POST' } @invoicing_list ).
+                  " via server $smtpmachine with SMTP: $!";
 
   #} elsif ( grep { $_ eq 'POST' } @invoicing_list ) {
   } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) {
@@ -880,7 +883,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.20 2002-02-26 09:06:51 ivan Exp $
+$Id: cust_bill.pm,v 1.21 2002-03-07 14:10:10 ivan Exp $
 
 =head1 BUGS
 
index 67371bc..a0de03b 100644 (file)
@@ -2,8 +2,9 @@ package FS::part_export;
 
 use strict;
 use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::part_svc;
+use FS::part_export_option;
 
 @ISA = qw(FS::Record);
 
@@ -18,7 +19,10 @@ FS::part_export - Object methods for part_export records
   $record = new FS::part_export \%hash;
   $record = new FS::part_export { 'column' => 'value' };
 
-  $error = $record->insert;
+  ($new_record, $options) = $template_recored->clone( $svcpart );
+
+  $error = $record->insert( { 'option' => 'value' } );
+  $error = $record->insert( \$options );
 
   $error = $new_record->replace($old_record);
 
@@ -34,7 +38,7 @@ fields are currently supported:
 
 =over 4
 
-=item eventpart - primary key
+=item exportnum - primary key
 
 =item svcpart - Service definition (see L<FS::part_svc>) to which this export applies
 
@@ -63,14 +67,76 @@ points to.  You can ask the object for a copy with the I<hash> method.
 
 sub table { 'part_export'; }
 
-=item insert
+=item clone SVCPART
+
+An alternate constructor.  Creates a new export by duplicating an existing
+export.  The given svcpart is assigned to the new export.
+
+Returns a list consisting of the new export object and a hashref of options.
+
+=cut
+
+sub clone {
+  my $self = shift;
+  my $class = ref($self);
+  my %hash = $self->hash;
+  $hash{'exportnum'} = '';
+  $hash{'svcpart'} = shift;
+  ( $class->new( \%hash ),
+    { map { $_->optionname => $_->optionvalue }
+        qsearch('part_export_option', { 'exportnum' => $self->exportnum } )
+    }
+  );
+}
+
+=item insert HASHREF
 
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
 
+If a hash reference of options is supplied, part_export_option records are
+created (see L<FS::part_export_option>).
+
 =cut
 
-# the insert method can be inherited from FS::Record
+#false laziness w/queue.pm
+sub insert {
+  my $self = shift;
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = $self->SUPER::insert;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  my $options = shift;
+  foreach my $optionname ( keys %{$options} ) {
+    my $part_export_option = new FS::part_export_option ( {
+      'optionname'  => $optionname,
+      'optionvalue' => $options->{$optionname},
+    } );
+    $error = $part_export_option->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  '';
+
+};
 
 =item delete
 
@@ -121,6 +187,17 @@ sub check {
   ''; #no error
 }
 
+=item part_svc
+
+Returns the service definition (see L<FS::part_svc>) for this export.
+
+=cut
+
+sub part_svc {
+  my $self = shift;
+  qsearchs('part_svc', { svcpart => $self->svcpart } );
+}
+
 =back
 
 =head1 BUGS
index 4ce70b4..1ce0de6 100644 (file)
@@ -38,7 +38,7 @@ currently supported:
 
 =item exportnum - export (see L<FS::part_export>)
 
-=item option - option name
+=item optionname - option name
 
 =item opeionvalue - option value
 
@@ -105,7 +105,7 @@ sub check {
   my $error = 
     $self->ut_numbern('optionnum')
     || $self->ut_number('exportnum')
-    || $self->ut_alpha('option')
+    || $self->ut_alpha('optionname')
     || $self->ut_textn('optionvalue')
   ;
   return $error if $error;
index 3260de2..a6d78e1 100644 (file)
@@ -78,6 +78,7 @@ created (see L<FS::queue_arg>).
 
 =cut
 
+#false laziness w/part_export.pm
 sub insert {
   my $self = shift;
 
@@ -289,7 +290,7 @@ END
 
 =head1 VERSION
 
-$Id: queue.pm,v 1.6 2002-02-22 06:42:28 ivan Exp $
+$Id: queue.pm,v 1.7 2002-03-07 14:10:10 ivan Exp $
 
 =head1 BUGS