quantities for regular packages in addition to one-time charges, RT#13136
authorIvan Kohler <ivan@freeside.biz>
Wed, 27 Jun 2012 03:28:37 +0000 (20:28 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 27 Jun 2012 03:28:37 +0000 (20:28 -0700)
FS/FS/cust_main/Billing.pm
FS/FS/cust_pkg.pm
FS/FS/part_pkg/flat.pm
conf/invoice-unitprice [new file with mode: 0644]
httemplate/edit/process/quick-cust_pkg.cgi
httemplate/misc/order_pkg.html

index bc9b938..e7b9530 100644 (file)
@@ -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);
index de535aa..22559e9 100644 (file)
@@ -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
index 0e44f5d..f86db2e 100644 (file)
@@ -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 (file)
index 0000000..e69de29
index fab8525..ba4c5b1 100644 (file)
@@ -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'))
                                 : ''
index 2332f20..7aa024a 100644 (file)
     &>
 % }
 
+% 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') ) {