communigate provisioning phase 2: Domain:Account Defaults:Settings: RulesAllowed...
[freeside.git] / FS / FS / cust_main.pm
index 2574ca7..4595e15 100644 (file)
@@ -2,7 +2,8 @@ package FS::cust_main;
 
 require 5.006;
 use strict;
-use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use vars qw( @EXPORT_OK $DEBUG $me $conf
              @encrypted_fields
              $import $ignore_expired_card
              $skip_fuzzyfiles @fuzzyfields
@@ -25,7 +26,7 @@ use String::Approx qw(amatch);
 use Business::CreditCard 0.28;
 use Locale::Country;
 use FS::UID qw( getotaker dbh driver_name );
-use FS::Record qw( qsearchs qsearch dbdef );
+use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
 use FS::Misc qw( generate_email send_email generate_ps do_print );
 use FS::Msgcat qw(gettext);
 use FS::payby;
@@ -66,11 +67,8 @@ use FS::type_pkgs;
 use FS::payment_gateway;
 use FS::agent_payment_gateway;
 use FS::banned_pay;
-use FS::payinfo_Mixin;
 use FS::TicketSystem;
 
-@ISA = qw( FS::payinfo_Mixin FS::Record );
-
 @EXPORT_OK = qw( smart_search );
 
 $realtime_bop_decline_quiet = 0;
@@ -304,9 +302,9 @@ IP address from which payment information was received
 
 Tax exempt, empty or `Y'
 
-=item otaker
+=item usernum
 
-Order taker (assigned automatically, see L<FS::UID>)
+Order taker (see L<FS::access_user>)
 
 =item comments
 
@@ -7449,7 +7447,7 @@ sub referral_cust_main_ncancelled {
 
 Like referral_cust_main, except returns a flat list of all unsuspended (and
 uncancelled) packages for each customer.  The number of items in this list may
-be useful for comission calculations (perhaps after a C<grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ).
+be useful for commission calculations (perhaps after a C<grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ).
 
 =cut
 
@@ -7511,8 +7509,10 @@ sub credit {
     $cust_credit->set('reason', $reason)
   }
 
-  $cust_credit->addlinfo( delete $options{'addlinfo'} )
-    if exists($options{'addlinfo'});
+  for (qw( addlinfo eventnum )) {
+    $cust_credit->$_( delete $options{$_} )
+      if exists($options{$_});
+  }
 
   $cust_credit->insert(%options);
 
@@ -8524,6 +8524,15 @@ sub search {
   }
 
   ##
+  # do the same for user
+  ##
+
+  if ( $params->{'usernum'} =~ /^(\d+)$/ and $1 ) {
+    push @where,
+      "cust_main.usernum = $1";
+  }
+
+  ##
   # parse status
   ##
 
@@ -8558,13 +8567,23 @@ sub search {
 
     next unless exists($params->{$field});
 
-    my($beginning, $ending) = @{$params->{$field}};
+    my($beginning, $ending, $hour) = @{$params->{$field}};
 
     push @where,
       "cust_main.$field IS NOT NULL",
       "cust_main.$field >= $beginning",
       "cust_main.$field <= $ending";
 
+    # XXX: do this for mysql and/or pull it out of here
+    if(defined $hour) {
+      if ($dbh->{Driver}->{Name} eq 'Pg') {
+        push @where, "extract(hour from to_timestamp(cust_main.$field)) = $hour";
+      }
+      else {
+        warn "search by time of day not supported on ".$dbh->{Driver}->{Name}." databases";
+      }
+    }
+
     $orderby ||= "ORDER BY cust_main.$field";
 
   }
@@ -9710,14 +9729,7 @@ sub _agent_plandata {
   
   my $agentnum = $self->agentnum;
 
-  my $regexp = '';
-  if ( driver_name =~ /^Pg/i ) {
-    $regexp = '~';
-  } elsif ( driver_name =~ /^mysql/i ) {
-    $regexp = 'REGEXP';
-  } else {
-    die "don't know how to use regular expressions in ". driver_name. " databases";
-  }
+  my $regexp = regexp_sql();
 
   my $part_event_option =
     qsearchs({
@@ -9783,6 +9795,9 @@ sub _upgrade_data { #class method
   my $sth = dbh->prepare($sql) or die dbh->errstr;
   $sth->execute or die $sth->errstr;
 
+  local($ignore_expired_card) = 1;
+  $class->_upgrade_otaker(%opts);
+
 }
 
 =back