[freeside-commits] branch master updated. ea830c61145a0c659f24e55a4640db4e2036c06f

Ivan ivan at 420.am
Tue Jun 26 20:28:43 PDT 2012


The branch, master has been updated
       via  ea830c61145a0c659f24e55a4640db4e2036c06f (commit)
      from  83b8a19421cb0e62234485961c35154d1357c61b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ea830c61145a0c659f24e55a4640db4e2036c06f
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Jun 26 20:28:37 2012 -0700

    quantities for regular packages in addition to one-time charges, RT#13136

diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index bc9b938..e7b9530 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -963,7 +963,6 @@ sub _make_lines {
   # bill recurring fee
   ### 
 
-  #XXX unit stuff here too
   my $recur = 0;
   my $unitrecur = 0;
   my @recur_discounts = ();
@@ -1022,6 +1021,9 @@ sub _make_lines {
     return "$@ running $method for $cust_pkg\n"
       if ( $@ );
 
+    #base_cancel???
+    $unitrecur = $cust_pkg->part_pkg->base_recur || $recur; #XXX uuh
+
     if ( $increment_next_bill ) {
 
       my $next_bill = $part_pkg->add_freq($sdate, $options{freq_override} || 0);
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index de535aa..22559e9 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -2204,11 +2204,14 @@ field, I<num_avail>, which specifies the number of available services.
 
 sub available_part_svc {
   my $self = shift;
+
+  my $pkg_quantity = $self->quantity || 1;
+
   grep { $_->num_avail > 0 }
     map {
           my $part_svc = $_->part_svc;
           $part_svc->{'Hash'}{'num_avail'} = #evil encapsulation-breaking
-            $_->quantity - $self->num_cust_svc($_->svcpart);
+            $pkg_quantity * $_->quantity - $self->num_cust_svc($_->svcpart);
 
 	  # more evil encapsulation breakage
 	  if($part_svc->{'Hash'}{'num_avail'} > 0) {
@@ -2250,6 +2253,8 @@ sub part_svc {
   my $self = shift;
   my %opt = @_;
 
+  my $pkg_quantity = $self->quantity || 1;
+
   #XXX some sort of sort order besides numeric by svcpart...
   my @part_svc = sort { $a->svcpart <=> $b->svcpart } map {
     my $pkg_svc = $_;
@@ -2257,7 +2262,7 @@ sub part_svc {
     my $num_cust_svc = $self->num_cust_svc($part_svc->svcpart);
     $part_svc->{'Hash'}{'num_cust_svc'} = $num_cust_svc; #more evil
     $part_svc->{'Hash'}{'num_avail'}    =
-      max( 0, $pkg_svc->quantity - $num_cust_svc );
+      max( 0, $pkg_quantity * $pkg_svc->quantity - $num_cust_svc );
     $part_svc->{'Hash'}{'cust_pkg_svc'} =
         $num_cust_svc ? [ $self->cust_svc($part_svc->svcpart) ] : []
       unless exists($opt{summarize_size}) && $opt{summarize_size} > 0
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index 0e44f5d..f86db2e 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -161,6 +161,9 @@ sub calc_recur {
     $charge *= $param->{freq_override} if $param->{freq_override};
   }
 
+  my $quantity = $cust_pkg->quantity || 1;
+  $charge *= $quantity;
+
   my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
   return sprintf('%.2f', $charge - $discount);
 }
diff --git a/conf/invoice-unitprice b/conf/invoice-unitprice
new file mode 100644
index 0000000..e69de29
diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi
index fab8525..ba4c5b1 100644
--- a/httemplate/edit/process/quick-cust_pkg.cgi
+++ b/httemplate/edit/process/quick-cust_pkg.cgi
@@ -48,6 +48,9 @@ die 'unknown custnum' unless $cust_main;
 $cgi->param('pkgpart') =~ /^(\d+)$/
   or die 'illegal pkgpart '. $cgi->param('pkgpart');
 my $pkgpart = $1;
+$cgi->param('quantity') =~ /^(\d+)$/
+  or die 'illegal quantity '. $cgi->param('quantity');
+my $quantity = $1;
 $cgi->param('refnum') =~ /^(\d*)$/
   or die 'illegal refnum '. $cgi->param('refnum');
 my $refnum = $1;
@@ -78,6 +81,7 @@ if ( $cgi->param('qualnum') ) {
 my $cust_pkg = new FS::cust_pkg {
   'custnum'              => $custnum,
   'pkgpart'              => $pkgpart,
+  'quantity'             => $quantity,
   'start_date'           => ( scalar($cgi->param('start_date'))
                                 ? parse_datetime($cgi->param('start_date'))
                                 : ''
diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html
index 2332f20..7aa024a 100644
--- a/httemplate/misc/order_pkg.html
+++ b/httemplate/misc/order_pkg.html
@@ -32,6 +32,15 @@
     &>
 % }
 
+% if ( $conf->exists('invoice-unitprice') ) {
+    <TR>
+      <TH ALIGN="right"><% mt('Quantity') |h %> </TD>
+      <TD>
+        <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
+      </TD>
+    </TR>
+% }
+
 <TR>
   <TH ALIGN="right"><% mt('Start date') |h %> </TD>
   <TD COLSPAN=6>
@@ -163,6 +172,11 @@ if ( $cgi->param('lock_pkgpart') ) {
 
 my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
 
+my $quantity = 1;
+if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
+  $quantity = $1;
+}
+
 my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
 my $start_date = '';
 if( ! $conf->exists('order_pkg-no_start_date') ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_main/Billing.pm                   |    4 +++-
 FS/FS/cust_pkg.pm                            |    9 +++++++--
 FS/FS/part_pkg/flat.pm                       |    3 +++
 conf/{agent_defaultpkg => invoice-unitprice} |    0
 httemplate/edit/process/quick-cust_pkg.cgi   |    4 ++++
 httemplate/misc/order_pkg.html               |   14 ++++++++++++++
 6 files changed, 31 insertions(+), 3 deletions(-)
 copy conf/{agent_defaultpkg => invoice-unitprice} (100%)




More information about the freeside-commits mailing list