allow exports to add links to customer view (#1407)
[freeside.git] / FS / FS / cust_main.pm
index de4d38d..73bdc14 100644 (file)
@@ -2166,8 +2166,7 @@ sub bill {
       # only for figuring next bill date, nothing else, so, reset $sdate again
       # here
       $sdate = $cust_pkg->bill || $cust_pkg->setup || $time;
-      $cust_pkg->last_bill($sdate)
-        if $cust_pkg->dbdef_table->column('last_bill');
+      $cust_pkg->last_bill($sdate);
 
       if ( $part_pkg->freq =~ /^\d+$/ ) {
         $mon += $part_pkg->freq;
@@ -4633,13 +4632,14 @@ the error, otherwise returns false.
 
 sub charge {
   my $self = shift;
-  my ( $amount, $pkg, $comment, $taxclass, $additional );
+  my ( $amount, $pkg, $comment, $taxclass, $additional, $classnum );
   if ( ref( $_[0] ) ) {
     $amount     = $_[0]->{amount};
     $pkg        = exists($_[0]->{pkg}) ? $_[0]->{pkg} : 'One-time charge';
     $comment    = exists($_[0]->{comment}) ? $_[0]->{comment}
                                            : '$'. sprintf("%.2f",$amount);
     $taxclass   = exists($_[0]->{taxclass}) ? $_[0]->{taxclass} : '';
+    $classnum   = exists($_[0]->{classnum}) ? $_[0]->{classnum} : '';
     $additional = $_[0]->{additional};
   }else{
     $amount     = shift;
@@ -4666,6 +4666,7 @@ sub charge {
     'plan'     => 'flat',
     'freq'     => 0,
     'disabled' => 'Y',
+    'classnum' => $classnum ? $classnum : '',
     'taxclass' => $taxclass,
   } );
 
@@ -5191,8 +5192,8 @@ sub _money_table_where {
   my @where = ();
   push @where, "cust_main.custnum = $table.custnum" unless $opt{'total'};
   if ( $table eq 'cust_bill' || $opt{'unapplied_date'} ) {
-    push @where, "$table._date <= $start" if length($start);
-    push @where, "$table._date >  $end"   if length($end);
+    push @where, "$table._date <= $start" if defined($start) && length($start);
+    push @where, "$table._date >  $end"   if defined($end)   && length($end);
   }
   push @where, @{$opt{'where'}} if $opt{'where'};
   my $where = scalar(@where) ? 'WHERE '. join(' AND ', @where ) : '';
@@ -5329,10 +5330,14 @@ sub smart_search {
 
     }
 
-  } elsif ( $search =~ /^\s*(\d+)\s*$/ ) { # customer # search
-                                           # (also try agent_custid)
-                                           # (regex needs tweaking if your
-                                           #  legacy cust numbers have letters)
+  # custnum search (also try agent_custid), with some tweaking options if your
+  # legacy cust "numbers" have letters
+  } elsif ( $search =~ /^\s*(\d+)\s*$/
+            || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
+                 && $search =~ /^\s*(\w\w?\d+)\s*$/
+               )
+          )
+  {
 
     push @cust_main, qsearch( {
       'table'     => 'cust_main',