diff options
| author | ivan <ivan> | 2004-11-22 18:20:21 +0000 | 
|---|---|---|
| committer | ivan <ivan> | 2004-11-22 18:20:21 +0000 | 
| commit | a5a258c91c5dc78897d16627b8092385ceb4c4d2 (patch) | |
| tree | ed92c98b0ed7c2a8647b8b92c50bd2acfc8e394b /FS/FS | |
| parent | 97ddf39b5798913bbd2b0205b2767df2cd362a2b (diff) | |
promo codes and separate signup addresses for hdn
Diffstat (limited to 'FS/FS')
| -rw-r--r-- | FS/FS/ClientAPI/Signup.pm | 53 | ||||
| -rw-r--r-- | FS/FS/Record.pm | 2 | ||||
| -rw-r--r-- | FS/FS/cust_pkg.pm | 62 | ||||
| -rw-r--r-- | FS/FS/part_pkg.pm | 3 | 
4 files changed, 73 insertions, 47 deletions
diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index bdcd2fbf1..dc627e9bd 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -75,6 +75,8 @@ sub signup_info {      'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), +    'ship_enabled' => defined dbdef->table('cust_main')->column('ship_last'), +      'msgcat' => { map { $_=>gettext($_) } qw(        passwords_dont_match invalid_card unknown_card_type not_a empty_password      ) }, @@ -102,11 +104,28 @@ sub signup_info {      }    } -  if ( $agentnum ) { +  $signup_info->{'part_pkg'} = []; +  if ( $packet->{'promo_code'} ) { +    $signup_info->{'part_pkg'} = +      [ map { { 'payby'   => [ $_->payby ], %{$_->hashref} } } +          grep { $_->svcpart('svc_acct') } +            qsearch( 'part_pkg', { 'promo_code' => { +                                     op=>'ILIKE', +                                     value=>$packet->{'promo_code'} +                                   }, +                                   'disabled'   => '',                  } ) +      ]; + +    $signup_info->{'error'} = 'Unknown promotional code' +      unless @{ $signup_info->{'part_pkg'} }; +  } + +  if ( $agentnum && ! @{ $signup_info->{'part_pkg'} } ) {      $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}; -  } else { -    delete $signup_info->{'part_pkg'};    } +  # else { +  # delete $signup_info->{'part_pkg'}; +  #}    if ( $session ) {      my $agent_signup_info = { %$signup_info }; @@ -158,10 +177,17 @@ sub new_customer {                         || $conf->config('signup_server-default_refnum'),      map { $_ => $packet->{$_} } qw( -      last first ss company address1 address2 city county state zip country -      daytime night fax payby payinfo paycvv paydate payname referral_custnum -      comments -    ), + +      last first ss company address1 address2 +      city county state zip country +      daytime night fax + +      ship_last ship_first ship_ss ship_company ship_address1 ship_address2 +      ship_city ship_county ship_state ship_zip ship_country +      ship_daytime ship_night ship_fax + +      payby payinfo paycvv paydate payname referral_custnum comments +    )    } ); @@ -185,10 +211,11 @@ sub new_customer {    my $cust_pkg = new FS::cust_pkg ( {      #later#'custnum' => $custnum, -    'pkgpart' => $packet->{'pkgpart'}, +    'pkgpart'    => $packet->{'pkgpart'}, +    'promo_code' => $packet->{'promo_code'},    } ); -  my $error = $cust_pkg->check; -  return { 'error' => $error } if $error; +  #my $error = $cust_pkg->check; +  #return { 'error' => $error } if $error;    my $svc_acct = new FS::svc_acct ( {      'svcpart'   => $svcpart, @@ -214,15 +241,15 @@ sub new_customer {    my $y = $svc_acct->setdefault; # arguably should be in new method    return { 'error' => $y } if $y && !ref($y); -  $error = $svc_acct->check; -  return { 'error' => $error } if $error; +  #$error = $svc_acct->check; +  #return { 'error' => $error } if $error;    #setup a job dependancy to delay provisioning    my $placeholder = new FS::queue ( {      'job'    => 'FS::ClientAPI::Signup::__placeholder',      'status' => 'locked',    } ); -  $error = $placeholder->insert; +  my $error = $placeholder->insert;    return { 'error' => $error } if $error;    use Tie::RefHash; diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index f0026d5d2..5a6bb579e 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -1424,7 +1424,7 @@ on the column first.  sub ut_foreign_key {    my( $self, $field, $table, $foreign ) = @_;    qsearchs($table, { $foreign => $self->getfield($field) }) -    or return "Can't find $field ". $self->getfield($field). +    or return "Can't find ". $self->table. ".$field ". $self->getfield($field).                " in $table.$foreign";    '';  } diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 3bce653b5..1f1ae4090 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -145,32 +145,9 @@ sub table { 'cust_pkg'; }  Adds this billing item to the database ("Orders" the item).  If there is an  error, returns the error, otherwise returns false. -=cut - -sub insert { -  my $self = shift; - -  # custnum might not have have been defined in sub check (for one-shot new -  # customers), so check it here instead -  # (is this still necessary with transactions?) - -  my $error = $self->ut_number('custnum'); -  return $error if $error; - -  my $cust_main = $self->cust_main; -  return "Unknown custnum: ". $self->custnum unless $cust_main; - -  unless ( $disable_agentcheck ) { -    my $agent = qsearchs( 'agent', { 'agentnum' => $cust_main->agentnum } ); -    my $pkgpart_href = $agent->pkgpart_hashref; -    return "agent ". $agent->agentnum. -           " can't purchase pkgpart ". $self->pkgpart -      unless $pkgpart_href->{ $self->pkgpart }; -  } - -  $self->SUPER::insert; - -} +If the additional field I<promo_code> is defined instead of I<pkgpart>, it +will be used to look up the package definition and agent restrictions will be +ignored.  =item delete @@ -233,8 +210,8 @@ sub check {    my $error =       $self->ut_numbern('pkgnum') -    || $self->ut_numbern('custnum') -    || $self->ut_number('pkgpart') +    || $self->ut_foreign_key('custnum', 'cust_main', 'custnum') +    || $self->ut_numbern('pkgpart')      || $self->ut_numbern('setup')      || $self->ut_numbern('bill')      || $self->ut_numbern('susp') @@ -242,12 +219,31 @@ sub check {    ;    return $error if $error; -  if ( $self->custnum ) {  -    return "Unknown customer ". $self->custnum unless $self->cust_main; -  } +  if ( $self->promo_code ) { + +    my $promo_part_pkg = +      qsearchs('part_pkg', { +        'pkgpart'    => $self->pkgpart, +        'promo_code' => { op=>'ILIKE', value=>$self->promo_code }, +      } ); +    return 'Unknown promotional code' unless $promo_part_pkg; +    $self->pkgpart($promo_part_pkg->pkgpart); + +  } else {  + +    unless ( $disable_agentcheck ) { +      my $agent = +        qsearchs( 'agent', { 'agentnum' => $self->cust_main->agentnum } ); +      my $pkgpart_href = $agent->pkgpart_hashref; +      return "agent ". $agent->agentnum. +             " can't purchase pkgpart ". $self->pkgpart +        unless $pkgpart_href->{ $self->pkgpart }; +    } -  return "Unknown pkgpart: ". $self->pkgpart -    unless qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } ); +    $error = $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart' ); +    return $error if $error; + +  }    $self->otaker(getotaker) unless $self->otaker;    $self->otaker =~ /^([\w\.\-]{0,16})$/ or return "Illegal otaker"; diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index d7cc3cb34..2f3cb8b8b 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -54,6 +54,8 @@ inherits from FS::Record.  The following fields are currently supported:  =item comment - Text name of this package definition (non-customer-viewable) +=item promo_code - Promotional code +  =item setup - Setup fee expression (deprecated)  =item freq - Frequency of recurring fee @@ -288,6 +290,7 @@ sub check {    my $error = $self->ut_numbern('pkgpart')      || $self->ut_text('pkg')      || $self->ut_text('comment') +    || $self->ut_textn('promo_code')      || $self->ut_alphan('plan')      || $self->ut_enum('setuptax', [ '', 'Y' ] )      || $self->ut_enum('recurtax', [ '', 'Y' ] )  | 
