eWay self-signup fixes
[freeside.git] / FS / FS / cust_pkg.pm
index 66d8bae..5bb07d4 100644 (file)
@@ -661,7 +661,25 @@ sub cancel {
   }
 
   my %svc;
-  unless ( $date ) {
+  if ( $date ) {
+       # copied from below
+       foreach my $cust_svc (
+         #schwartz
+         map  { $_->[0] }
+         sort { $a->[1] <=> $b->[1] }
+         map  { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
+         qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
+       ) {
+
+         my $error = $cust_svc->cancel( ('date' => $date) );
+
+         if ( $error ) {
+           $dbh->rollback if $oldAutoCommit;
+           return "Error expiring cust_svc: $error";
+         }
+       }
+
+  } else {
     foreach my $cust_svc (
       #schwartz
       map  { $_->[0] }
@@ -707,7 +725,9 @@ sub cancel {
   return '' if $date; #no errors
 
   my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $self->cust_main->invoicing_list;
-  if ( !$options{'quiet'} && $conf->exists('emailcancel') && @invoicing_list ) {
+  if ( !$options{'quiet'} && 
+        $conf->exists('emailcancel', $self->cust_main->agentnum) && 
+        @invoicing_list ) {
     my $msgnum = $conf->config('cancel_msgnum', $self->cust_main->agentnum);
     my $error = '';
     if ( $msgnum ) {
@@ -1726,6 +1746,13 @@ sub available_part_svc {
           my $part_svc = $_->part_svc;
           $part_svc->{'Hash'}{'num_avail'} = #evil encapsulation-breaking
             $_->quantity - $self->num_cust_svc($_->svcpart);
+
+         # more evil encapsulation breakage
+         if($part_svc->{'Hash'}{'num_avail'} > 0) {
+           my @exports = $part_svc->part_export_did;
+           $part_svc->{'Hash'}{'can_get_dids'} = scalar(@exports);
+         }
+
           $part_svc;
         }
       $self->part_pkg->pkg_svc;
@@ -3327,9 +3354,21 @@ sub bulk_change {
 sub _upgrade_data {  # class method
   my ($class, %opts) = @_;
   $class->_upgrade_otaker(%opts);
-  my $sql =('UPDATE cust_pkg SET contract_end = NULL WHERE contract_end = -1');
-  my $sth = dbh->prepare($sql);
-  $sth->execute or die $sth->errstr;
+  my @statements = (
+    # RT#10139, bug resulting in contract_end being set when it shouldn't
+  'UPDATE cust_pkg SET contract_end = NULL WHERE contract_end = -1',
+    # RT#10830, bad calculation of prorate date near end of year
+    # the date range for bill is December 2009, and we move it forward
+    # one year if it's before the previous bill date (which it should 
+    # never be)
+  'UPDATE cust_pkg SET bill = bill + (365*24*60*60) WHERE bill < last_bill
+  AND bill > 1259654400 AND bill < 1262332800 AND (SELECT plan FROM part_pkg 
+  WHERE part_pkg.pkgpart = cust_pkg.pkgpart) = \'prorate\'',
+  );
+  foreach my $sql (@statements) {
+    my $sth = dbh->prepare($sql);
+    $sth->execute or die $sth->errstr;
+  }
 }
 
 =back