fix 'Can't call method svcdb without a package or object reference' when ordering...
[freeside.git] / FS / FS / cust_main.pm
index 49702f6..28f6e90 100644 (file)
@@ -40,6 +40,7 @@ use FS::payby;
 use FS::cust_pkg;
 use FS::cust_svc;
 use FS::cust_bill;
+use FS::legacy_cust_bill;
 use FS::cust_pay;
 use FS::cust_pay_pending;
 use FS::cust_pay_void;
@@ -675,6 +676,15 @@ sub auto_agent_custid {
 
     $counter->unlock;
 
+  } elsif ( $format eq '1001XXXXXXXX' ) {
+
+    my $counter = new File::CounterFile 'cust_main.agent_custid';
+    $counter->lock;
+
+    $agent_custid = '1001'. $counter->inc;
+
+    $counter->unlock;
+
   } else {
     die "Unknown cust_main-auto_agent_custid format: $format";
   }
@@ -2481,6 +2491,7 @@ sub batch_card {
     'status' => 'O',
     'payby'  => FS::payby->payby2payment($payby),
   );
+  $pay_batch{agentnum} = $self->agentnum if $conf->exists('batch-spoolagent');
 
   my $pay_batch = qsearchs( 'pay_batch', \%pay_batch );
 
@@ -3574,6 +3585,25 @@ sub open_cust_bill {
 
 }
 
+=item legacy_cust_bill [ OPTION => VALUE... | EXTRA_QSEARCH_PARAMS_HASHREF ]
+
+Returns all the legacy invoices (see L<FS::legacy_cust_bill>) for this customer.
+
+=cut
+
+sub legacy_cust_bill {
+  my $self = shift;
+
+  #return $self->num_legacy_cust_bill unless wantarray;
+
+  map { $_ } #behavior of sort undefined in scalar context
+    sort { $a->_date <=> $b->_date }
+      qsearch({ 'table'    => 'legacy_cust_bill',
+                'hashref'  => { 'custnum' => $self->custnum, },
+                'order_by' => 'ORDER BY _date ASC',
+             });
+}
+
 =item cust_statement [ OPTION => VALUE... | EXTRA_QSEARCH_PARAMS_HASHREF ]
 
 Returns all the statements (see L<FS::cust_statement>) for this customer.