add desc method to cust_bill_pkg and use it in cust_bill... this should help with...
authorivan <ivan>
Sat, 9 Jul 2005 10:36:43 +0000 (10:36 +0000)
committerivan <ivan>
Sat, 9 Jul 2005 10:36:43 +0000 (10:36 +0000)
17 files changed:
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/part_export/sqlradius.pm
FS/FS/part_pkg/flat.pm
FS/FS/part_pkg/flat_comission.pm
FS/FS/part_pkg/flat_comission_cust.pm
FS/FS/part_pkg/flat_comission_pkg.pm
FS/FS/part_pkg/flat_delayed.pm
FS/FS/part_pkg/prepaid.pm [new file with mode: 0644]
FS/FS/part_pkg/prorate.pm
FS/FS/part_pkg/sesmon_hour.pm
FS/FS/part_pkg/sesmon_minute.pm
FS/FS/part_pkg/sql_external.pm
FS/FS/part_pkg/sql_generic.pm
FS/FS/part_pkg/sqlradacct_hour.pm
FS/FS/part_pkg/subscription.pm
FS/FS/part_pkg/voip_sqlradacct.pm

index 26c3d4b..8b34cb9 100644 (file)
@@ -818,7 +818,7 @@ sub send_csv {
   ) or die "can't create csv";
   print CSV $csv->string. "\n";
 
-  #new charges (false laziness w/print_text)
+  #new charges (false laziness w/print_text and _items stuff)
   foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
 
     my($pkg, $setup, $recur, $sdate, $edate);
@@ -1061,7 +1061,7 @@ L<Time::Local> and L<Date::Parse> for conversion functions.
 
 =cut
 
-#still some false laziness w/print_text
+#still some false laziness w/_items stuff (and send_csv)
 sub print_text {
 
   my( $self, $today, $template ) = @_;
@@ -1102,50 +1102,49 @@ sub print_text {
     ( grep { ! $_->pkgnum } $self->cust_bill_pkg ),  #then taxes
   ) {
 
-    if ( $cust_bill_pkg->pkgnum > 0 ) {
+    my $desc = $cust_bill_pkg->desc;
 
-      my $cust_pkg = qsearchs('cust_pkg', { pkgnum =>$cust_bill_pkg->pkgnum } );
-      my $part_pkg = qsearchs('part_pkg', { pkgpart=>$cust_pkg->pkgpart } );
-      my $pkg = $part_pkg->pkg;
+    if ( $cust_bill_pkg->pkgnum > 0 ) {
 
       if ( $cust_bill_pkg->setup != 0 ) {
-        my $description = $pkg;
+        my $description = $desc;
         $description .= ' Setup' if $cust_bill_pkg->recur != 0;
         push @buf, [ $description,
                      $money_char. sprintf("%10.2f", $cust_bill_pkg->setup) ];
         push @buf,
           map { [ "  ". $_->[0]. ": ". $_->[1], '' ] }
-              $cust_pkg->h_labels($self->_date);
+              $cust_bill_pkg->cust_pkg->h_labels($self->_date);
       }
 
       if ( $cust_bill_pkg->recur != 0 ) {
         push @buf, [
-          "$pkg (" . time2str("%x", $cust_bill_pkg->sdate) . " - " .
-                                time2str("%x", $cust_bill_pkg->edate) . ")",
+          "$desc (" . time2str("%x", $cust_bill_pkg->sdate) . " - " .
+                      time2str("%x", $cust_bill_pkg->edate) . ")",
           $money_char. sprintf("%10.2f", $cust_bill_pkg->recur)
         ];
         push @buf,
           map { [ "  ". $_->[0]. ": ". $_->[1], '' ] }
-              $cust_pkg->h_labels($cust_bill_pkg->edate, $cust_bill_pkg->sdate);
+              $cust_bill_pkg->cust_pkg->h_labels( $cust_bill_pkg->edate,
+                                                  $cust_bill_pkg->sdate );
       }
 
       push @buf, map { [ "  $_", '' ] } $cust_bill_pkg->details;
 
     } else { #pkgnum tax or one-shot line item
-      my $itemdesc = defined $cust_bill_pkg->dbdef_table->column('itemdesc')
-                     ? ( $cust_bill_pkg->itemdesc || 'Tax' )
-                     : 'Tax';
+
       if ( $cust_bill_pkg->setup != 0 ) {
-        push @buf, [ $itemdesc,
+        push @buf, [ $desc,
                      $money_char. sprintf("%10.2f", $cust_bill_pkg->setup) ];
       }
       if ( $cust_bill_pkg->recur != 0 ) {
-        push @buf, [ "$itemdesc (". time2str("%x", $cust_bill_pkg->sdate). " - "
-                                  . time2str("%x", $cust_bill_pkg->edate). ")",
+        push @buf, [ "$desc (". time2str("%x", $cust_bill_pkg->sdate). " - "
+                              . time2str("%x", $cust_bill_pkg->edate). ")",
                      $money_char. sprintf("%10.2f", $cust_bill_pkg->recur)
                    ];
       }
+
     }
+
   }
 
   push @buf,['','-----------'];
@@ -1305,7 +1304,7 @@ L<Time::Local> and L<Date::Parse> for conversion functions.
 
 =cut
 
-#still some false laziness w/print_text
+#still some false laziness w/print_text (mostly print_text should use _items stuff though)
 sub print_latex {
 
   my( $self, $today, $template ) = @_;
@@ -1999,21 +1998,19 @@ sub _items_cust_bill_pkg {
   my @b = ();
   foreach my $cust_bill_pkg ( @$cust_bill_pkg ) {
 
-    if ( $cust_bill_pkg->pkgnum > 0 ) {
+    my $desc = $cust_bill_pkg->desc;
 
-      my $cust_pkg = qsearchs('cust_pkg', { pkgnum =>$cust_bill_pkg->pkgnum } );
-      my $part_pkg = qsearchs('part_pkg', { pkgpart=>$cust_pkg->pkgpart } );
-      my $pkg = $part_pkg->pkg;
+    if ( $cust_bill_pkg->pkgnum > 0 ) {
 
       if ( $cust_bill_pkg->setup != 0 ) {
-        my $description = $pkg;
+        my $description = $desc;
         $description .= ' Setup' if $cust_bill_pkg->recur != 0;
-        my @d = $cust_pkg->h_labels_short($self->_date);
+        my @d = $cust_bill_pkg->cust_pkg->h_labels_short($self->_date);
         push @d, $cust_bill_pkg->details if $cust_bill_pkg->recur == 0;
         push @b, {
           description     => $description,
           #pkgpart         => $part_pkg->pkgpart,
-          pkgnum          => $cust_pkg->pkgnum,
+          pkgnum          => $cust_bill_pkg->pkgnum,
           amount          => sprintf("%.2f", $cust_bill_pkg->setup),
           ext_description => \@d,
         };
@@ -2021,33 +2018,31 @@ sub _items_cust_bill_pkg {
 
       if ( $cust_bill_pkg->recur != 0 ) {
         push @b, {
-          description     => "$pkg (" .
+          description     => "$desc (" .
                                time2str('%x', $cust_bill_pkg->sdate). ' - '.
                                time2str('%x', $cust_bill_pkg->edate). ')',
           #pkgpart         => $part_pkg->pkgpart,
-          pkgnum          => $cust_pkg->pkgnum,
+          pkgnum          => $cust_bill_pkg->pkgnum,
           amount          => sprintf("%.2f", $cust_bill_pkg->recur),
-          ext_description => [ $cust_pkg->h_labels_short($cust_bill_pkg->edate,
-                                                         $cust_bill_pkg->sdate),
-                               $cust_bill_pkg->details,
-                             ],
+          ext_description =>
+            [ $cust_bill_pkg->cust_pkg->h_labels_short( $cust_bill_pkg->edate,
+                                                        $cust_bill_pkg->sdate),
+              $cust_bill_pkg->details,
+            ],
         };
       }
 
     } else { #pkgnum tax or one-shot line item (??)
 
-      my $itemdesc = defined $cust_bill_pkg->dbdef_table->column('itemdesc')
-                     ? ( $cust_bill_pkg->itemdesc || 'Tax' )
-                     : 'Tax';
       if ( $cust_bill_pkg->setup != 0 ) {
         push @b, {
-          'description' => $itemdesc,
+          'description' => $desc,
           'amount'      => sprintf("%.2f", $cust_bill_pkg->setup),
         };
       }
       if ( $cust_bill_pkg->recur != 0 ) {
         push @b, {
-          'description' => "$itemdesc (".
+          'description' => "$desc (".
                            time2str("%x", $cust_bill_pkg->sdate). ' - '.
                            time2str("%x", $cust_bill_pkg->edate). ')',
           'amount'      => sprintf("%.2f", $cust_bill_pkg->recur),
index 2267323..77429f2 100644 (file)
@@ -204,6 +204,25 @@ sub details {
     #qsearch ( 'cust_bill_pkg_detail', { 'lineitemnum' => $self->lineitemnum });
 }
 
+=item desc
+
+Returns a description for this line item.  For typical line items, this is the
+I<pkg> field of the corresponding B<FS::part_pkg> object (see L<FS::part_pkg>).
+For one-shot line items and named taxes, it is the I<itemdesc> field of this
+line item, and for generic taxes, simply returns "Tax".
+
+=cut
+
+sub desc {
+  my $self = shift;
+
+  if ( $self->pkgnum > 0 ) {
+    $self->cust_pkg->part_pkg->pkg;
+  } else {
+    $self->itemdesc || 'Tax';
+  }
+}
+
 =back
 
 =head1 BUGS
index 03802b2..772da12 100644 (file)
@@ -529,7 +529,8 @@ sub update_svc_acct {
         warn "  svc_acct.seconds found (". $svc_acct->seconds.
              ") - decrementing\n"
           if $DEBUG;
-        $svc_acct->decrement_seconds($AcctSessionTime);
+        my $error = $svc_acct->decrement_seconds($AcctSessionTime);
+        die $error if $error;
         $status = 'done';
       } else {
         warn "  no existing seconds value for svc_acct - skiping\n" if $DEBUG;
index 2a460b0..f2f3a8d 100644 (file)
@@ -78,4 +78,8 @@ sub is_free_options {
   qw( setup_fee recur_fee );
 }
 
+sub is_prepaid {
+  0; #no, we're postpaid
+}
+
 1;
index 21c03c2..442415e 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::flat_comission;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 9f2e6ca..4abe66a 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::flat_comission_cust;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 20d235c..0f4d02a 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::flat_comission_pkg;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 4a04583..ec11699 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::flat_delayed;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
diff --git a/FS/FS/part_pkg/prepaid.pm b/FS/FS/part_pkg/prepaid.pm
new file mode 100644 (file)
index 0000000..5e7d2ba
--- /dev/null
@@ -0,0 +1,28 @@
+package FS::part_pkg::prepaid;
+
+use strict;
+use vars qw(@ISA %info);
+use FS::part_pkg::flat;
+
+@ISA = qw(FS::part_pkg::flat);
+
+%info = (
+  'name' => 'Prepaid, flat rate',
+  'fields' => {
+    'setup_fee' => { 'name' => 'One-time setup fee for this package',
+                     'default' => 0,
+                   },
+    'recur_fee' => { 'name' => 'Initial and recharge fee for this package',
+                     'default' => 0,
+                   }
+  },
+  'fieldorder' => [ 'setup_fee', 'recur_fee', ],
+  'weight' => 25,
+);
+
+sub is_prepaid {
+  1;
+}
+
+1;
+
index f8a4826..86c64d5 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw(@ISA %info);
 use Time::Local qw(timelocal);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 41c7f25..b80fac3 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::sesmon_hour;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index cd859bf..6af7c08 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::sesmon_minute;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 28a4897..6aba915 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw(@ISA %info);
 use DBI;
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 646957c..b8ee286 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw(@ISA %info);
 use DBI;
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index 7ecb970..19887ea 100644 (file)
@@ -3,7 +3,7 @@ package FS::part_pkg::sqlradacct_hour;
 use strict;
 use vars qw(@ISA %info);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index e03573b..36b5a96 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw(@ISA %info);
 use Time::Local qw(timelocal);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
index db38a44..382ebac 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw(@ISA $DEBUG %info);
 use Date::Format;
 use FS::Record qw(qsearchs qsearch);
-use FS::part_pkg;
+use FS::part_pkg::flat;
 #use FS::rate;
 use FS::rate_prefix;