suspend event option to skip packages with a start_date, RT#83847
[freeside.git] / FS / FS / cust_main.pm
index 005931a..5ba851d 100644 (file)
@@ -78,6 +78,7 @@ use FS::contact;
 use FS::Locales;
 use FS::upgrade_journal;
 use FS::reason;
+use FS::DBI;
 
 # 1 is mostly method/subroutine entry and options
 # 2 traces progress of some operations
@@ -1212,7 +1213,7 @@ sub delete {
     $ticket_dbh = $dbh;
   } elsif ($conf->config('ticket_system') eq 'RT_External') {
     my ($datasrc, $user, $pass) = $conf->config('ticket_system-rt_external_datasrc');
-    $ticket_dbh = DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 });
+    $ticket_dbh = FS::DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 });
       #or die "RT_External DBI->connect error: $DBI::errstr\n";
   }
 
@@ -1458,7 +1459,7 @@ sub merge {
     $ticket_dbh = $dbh;
   } elsif ($conf->config('ticket_system') eq 'RT_External') {
     my ($datasrc, $user, $pass) = $conf->config('ticket_system-rt_external_datasrc');
-    $ticket_dbh = DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 });
+    $ticket_dbh = FS::DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 });
       #or die "RT_External DBI->connect error: $DBI::errstr\n";
   }
 
@@ -2328,8 +2329,14 @@ Returns a list: an empty list on success or a list of errors.
 =cut
 
 sub suspend {
-  my $self = shift;
-  grep { $_->suspend(@_) } $self->unsuspended_pkgs;
+  my($self, %opt) = @_;
+
+  my @pkgs = $self->unsuspended_pkgs;
+
+  @pkgs = grep { ! $_->get('start_date') } @pkgs
+    if $opt{skip_future_startdate};
+
+  grep { $_->suspend(%opt) } @pkgs;
 }
 
 =item suspend_if_pkgpart HASHREF | PKGPART [ , PKGPART ... ]
@@ -2774,6 +2781,10 @@ sub batch_card {
                               );
   }
 
+  my $paycode = $options{paycode} || '';
+  my $batch_type = "DEBIT";
+  $batch_type = "CREDIT" if $paycode eq 'C';
+
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -2786,6 +2797,7 @@ sub batch_card {
   my %pay_batch = (
     'status' => 'O',
     'payby'  => FS::payby->payby2payment($payby),
+    'type' => $batch_type,
   );
   $pay_batch{agentnum} = $self->agentnum if $conf->exists('batch-spoolagent');
 
@@ -3676,6 +3688,31 @@ sub contact_list_email {
   values %emails;
 }
 
+=item contact_list_name_phones
+
+Returns a list of contact phone numbers.
+{ phonetypenum => '1', phonenum => 'xxxxxxxxxx', first => 'firstname', last => 'lastname', countrycode => '1' }
+=cut
+ sub contact_list_name_phones {
+   my $self = shift;
+   my $phone_type = shift;
+   warn "$me contact_list_phones" if $DEBUG;
+   return () if !$self->custnum; # not yet inserted
+   return map { $_ }
+     qsearch({
+         table     => 'contact',
+         select    => 'phonetypenum, phonenum, first, last, countrycode',
+         addl_from => ' JOIN contact_phone USING (contactnum)',
+         hashref   => { 'custnum' => $self->custnum, 'phonetypenum' => $phone_type, },
+         order_by  => 'ORDER BY contactnum DESC',
+         extra_sql => '',
+     });
+ }
+
 =item referral_custnum_cust_main
 
 Returns the customer who referred this customer (or the empty string, if