time/data detail on invoices
[freeside.git] / FS / FS / cust_main.pm
index a8b1dc2..807fadb 100644 (file)
@@ -591,13 +591,13 @@ sub check {
 
 # bad idea to disable, causes billing to fail because of no tax rates later
 #  unless ( $import ) {
-    unless ( qsearchs('cust_main_county', {
+    unless ( qsearch('cust_main_county', {
       'country' => $self->country,
       'state'   => '',
      } ) ) {
       return "Unknown state/county/country: ".
         $self->state. "/". $self->county. "/". $self->country
-        unless qsearchs('cust_main_county',{
+        unless qsearch('cust_main_county',{
           'state'   => $self->state,
           'county'  => $self->county,
           'country' => $self->country,
@@ -667,7 +667,7 @@ sub check {
     }
   }
 
-  $self->payby =~ /^(CARD|CHEK|BILL|COMP|PREPAY)$/
+  $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREPAY)$/
     or return "Illegal payby: ". $self->payby;
   $self->payby($1);
 
@@ -947,6 +947,8 @@ sub bill {
     my %hash = $cust_pkg->hash;
     my $old_cust_pkg = new FS::cust_pkg \%hash;
 
+    my @details = ();
+
     # bill setup
     my $setup = 0;
     unless ( $cust_pkg->setup ) {
@@ -1040,11 +1042,12 @@ sub bill {
       }
       if ( $setup > 0 || $recur > 0 ) {
         my $cust_bill_pkg = new FS::cust_bill_pkg ({
-          'pkgnum' => $cust_pkg->pkgnum,
-          'setup'  => $setup,
-          'recur'  => $recur,
-          'sdate'  => $sdate,
-          'edate'  => $cust_pkg->bill,
+          'pkgnum'  => $cust_pkg->pkgnum,
+          'setup'   => $setup,
+          'recur'   => $recur,
+          'sdate'   => $sdate,
+          'edate'   => $cust_pkg->bill,
+          'details' => \@details,
         });
         push @cust_bill_pkg, $cust_bill_pkg;
         $total_setup += $setup;
@@ -1058,26 +1061,25 @@ sub bill {
                  || $self->payby eq 'COMP'
                  || $taxable_charged == 0 ) {
 
-          my $cust_main_county =
-            qsearchs('cust_main_county',{
+          my $cust_main_county = qsearchs('cust_main_county',{
               'state'    => $self->state,
               'county'   => $self->county,
               'country'  => $self->country,
               'taxclass' => $part_pkg->taxclass,
-            } )
-            or qsearchs('cust_main_county',{
+          } );
+          $cust_main_county ||= qsearchs('cust_main_county',{
               'state'    => $self->state,
               'county'   => $self->county,
               'country'  => $self->country,
               'taxclass' => '',
-            } )
-            or do {
-              $dbh->rollback if $oldAutoCommit;
-              return
-                "fatal: can't find tax rate for state/county/country/taxclass ".
-                join('/', ( map $self->$_(), qw(state county country) ),
-                          $part_pkg->taxclass ).  "\n";
-            };
+          } );
+          unless ( $cust_main_county ) {
+            $dbh->rollback if $oldAutoCommit;
+            return
+              "fatal: can't find tax rate for state/county/country/taxclass ".
+              join('/', ( map $self->$_(), qw(state county country) ),
+                        $part_pkg->taxclass ).  "\n";
+          }
 
           if ( $cust_main_county->exempt_amount ) {
             my ($mon,$year) = (localtime($sdate) )[4,5];
@@ -1336,7 +1338,8 @@ sub collect {
       my $cust_bill_event = new FS::cust_bill_event {
         'invnum'     => $cust_bill->invnum,
         'eventpart'  => $part_bill_event->eventpart,
-        '_date'      => $invoice_time,
+        #'_date'      => $invoice_time,
+        '_date'      => time,
         'status'     => $status,
         'statustext' => $statustext,
       };