Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE...
authorJonathan Prykop <jonathan@freeside.biz>
Fri, 23 Jan 2015 20:10:46 +0000 (14:10 -0600)
committerJonathan Prykop <jonathan@freeside.biz>
Fri, 23 Jan 2015 20:10:46 +0000 (14:10 -0600)
FS/FS/cust_bill.pm
FS/FS/cust_pkg.pm
FS/FS/part_export/a2billing.pm
FS/FS/part_pkg/global_Mixin.pm

index eff4791..7204821 100644 (file)
@@ -1066,7 +1066,7 @@ sub send {
 
   $self->email($opt)
     if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list )
-    && ! $self->invoice_noemail;
+    && ! $cust_main->invoice_noemail;
 
   $self->print($opt)
     if grep { $_ eq 'POST' } @invoicing_list; #postal
index 195ce3d..8a41791 100644 (file)
@@ -1458,6 +1458,21 @@ are mandatory.
 
 =cut
 
+# Implementation note:
+#
+# If you pkgpart-change a package that has been billed, and it's set to give
+# credit on package change, then this method gets called and then the new
+# package will have no last_bill date. Therefore the customer will be credited
+# only once (per billing period) even if there are multiple package changes.
+#
+# If you location-change a package that has been billed, this method will NOT
+# be called and the new package WILL have the last bill date of the old
+# package.
+#
+# If the new package is then canceled within the same billing cycle, 
+# credit_remaining needs to run calc_remain on the OLD package to determine
+# the amount of unused time to credit.
+
 sub credit_remaining {
   # Add a credit for remaining service
   my ($self, $mode, $time) = @_;
@@ -1474,7 +1489,23 @@ sub credit_remaining {
       and $next_bill > 0      # the package has a next bill date
       and $next_bill >= $time # which is in the future
   ) {
-    my $remaining_value = $self->calc_remain('time' => $time);
+    my $remaining_value = 0;
+
+    my $remain_pkg = $self;
+    $remaining_value = $remain_pkg->calc_remain('time' => $time);
+
+    # we may have to walk back past some package changes to get to the 
+    # one that actually has unused time
+    while ( $remaining_value == 0 ) {
+      if ( $remain_pkg->change_pkgnum ) {
+        $remain_pkg = FS::cust_pkg->by_key($remain_pkg->change_pkgnum);
+      } else {
+        # the package has really never been billed
+        return;
+      }
+      $remaining_value = $remain_pkg->calc_remain('time' => $time);
+    }
+
     if ( $remaining_value > 0 ) {
       warn "Crediting for $remaining_value on package ".$self->pkgnum."\n"
         if $DEBUG;
index b080d07..0821a34 100644 (file)
@@ -227,6 +227,12 @@ sub export_insert {
       did             => $svc->phonenum,
       billingtype     => ($self->option('billtype') eq 'Dial Out Rate' ? 2 : 3),
       activated       => 1,
+      aleg_carrier_cost_min_offp  => $part_pkg->option('a2billing_carrier_cost_min'),
+      aleg_carrier_initblock_offp => $part_pkg->option('a2billing_carrier_initblock_offp'),
+      aleg_carrier_increment_offp => $part_pkg->option('a2billing_carrier_increment_offp'),
+      aleg_retail_cost_min_offp   => $part_pkg->option('a2billing_retail_cost_min_offp'),
+      aleg_retail_initblock_offp  => $part_pkg->option('a2billing_retail_initblock_offp'),
+      aleg_retail_increment_offp  => $part_pkg->option('a2billing_retail_increment_offp'),
     );
 
     # use 'did' as the key here so that if the DID already exists, we 
index 899e73a..2637729 100644 (file)
@@ -65,7 +65,44 @@ tie my %a2billing_simultaccess, 'Tie::IxHash', (
       'type'        => 'select',
       'select_options' => \%a2billing_simultaccess,
     },  
-  },
+    'a2billing_carrier_cost_min' => {
+      'name'        => 'A2Billing inbound carrier cost',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+      },
+    },
+   'a2billing_carrer_initblock_offp' => {
+      'name'        => 'A2Billing inbound carrier min duration',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+      },
+    },
+    'a2billing_carrier_increment_offp' => {
+      'name'        => 'A2Billing inbound carrier billing block',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+      },
+    },
+    'a2billing_retail_cost_min_offp' => {
+      'name'        => 'A2Billing inbound retail cost',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+      },
+    },
+    'a2billing_retail_initblock_offp' => {
+      'name'        => 'A2Billing inbound retail min duration',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+      },
+    },
+    'a2billing_retail_increment_offp' => {
+      'name'        => 'A2Billing inbound retail billing block',
+      'display_if'  => sub {
+        FS::part_export->count("exporttype = 'a2billing'") > 0;
+     },
+   },
+
+ },
   'fieldorder' => [ qw(
     setup_fee
     recur_fee
@@ -76,6 +113,12 @@ tie my %a2billing_simultaccess, 'Tie::IxHash', (
     a2billing_tariff
     a2billing_type
     a2billing_simultaccess
+    a2billing_carrier_cost_min
+    a2billing_carrer_initblock_offp
+    a2billing_carrier_increment_offp
+    a2billing_retail_cost_min_offp
+    a2billing_retail_initblock_offp
+    a2billing_retail_increment_offp
   )],
 );