[freeside-commits] freeside/FS/FS Schema.pm, 1.15, 1.16 cust_bill.pm, 1.146, 1.147 cust_pay_batch.pm, 1.11, 1.12 pay_batch.pm, NONE, 1.1

Jeff Finucane,420,, jeff at wavetail.420.am
Sat May 20 13:06:32 PDT 2006


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv31811/FS/FS

Modified Files:
	Schema.pm cust_bill.pm cust_pay_batch.pm 
Added Files:
	pay_batch.pm 
Log Message:
first stab at BoM download

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Schema.pm	14 May 2006 16:47:31 -0000	1.15
+++ Schema.pm	20 May 2006 20:06:29 -0000	1.16
@@ -538,10 +538,21 @@
       'index' => [ [ 'paynum' ], [ 'invnum' ] ],
     },
 
+    'pay_batch' => { #batches of payments to an external processor
+      'columns' => [
+        'batchnum',   'serial',    '',   '', '', '', 
+        'status',  'char', 'NULL',     1, '', '', 
+      ],
+      'primary_key' => 'batchnum',
+      'unique' => [],
+      'index' => [],
+    },
+
     'cust_pay_batch' => { #what's this used for again?  list of customers
                           #in current CARD batch? (necessarily CARD?)
       'columns' => [
         'paybatchnum',   'serial',    '',   '', '', '', 
+        'batchnum',   'int',    '',   '', '', '', 
         'invnum',   'int',    '',   '', '', '', 
         'custnum',   'int',    '',   '', '', '', 
         'last',     'varchar', '',     $char_d, '', '', 
@@ -553,7 +564,7 @@
         'zip',      'varchar', 'NULL', 10, '', '', 
         'country',  'char', '',     2, '', '', 
         #        'trancode', 'int', '', '', '', ''
-        'cardnum',  'varchar', '',     16, '', '', 
+        'payinfo',  'varchar', '',     512, '', '', 
         #'exp',      @date_type, '', ''
         'exp',      'varchar', '',     11, '', '', 
         'payname',  'varchar', 'NULL', $char_d, '', '', 
@@ -561,7 +572,7 @@
       ],
       'primary_key' => 'paybatchnum',
       'unique' => [],
-      'index' => [ ['invnum'], ['custnum'] ],
+      'index' => [ ['batchnum'], ['invnum'], ['custnum'] ],
     },
 
     'cust_pkg' => {

--- NEW FILE: pay_batch.pm ---
package FS::pay_batch;

use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );

@ISA = qw(FS::Record);

=head1 NAME

FS::pay_batch - Object methods for pay_batch records

=head1 SYNOPSIS

  use FS::pay_batch;

  $record = new FS::pay_batch \%hash;
  $record = new FS::pay_batch { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::pay_batch object represents an example.  FS::pay_batch inherits from
FS::Record.  The following fields are currently supported:

=over 4

=item batchnum - primary key

=item status - 


=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new example.  To add the example to the database, see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

# the new method can be inherited from FS::Record, if a table method is defined

sub table { 'pay_batch'; }

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

=cut

# the insert method can be inherited from FS::Record

=item delete

Delete this record from the database.

=cut

# the delete method can be inherited from FS::Record

=item replace OLD_RECORD

Replaces the OLD_RECORD with this one in the database.  If there is an error,
returns the error, otherwise returns false.

=cut

# the replace method can be inherited from FS::Record

=item check

Checks all fields to make sure this is a valid example.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

# the check method should currently be supplied - FS::Record contains some
# data checking routines

sub check {
  my $self = shift;

  my $error = 
    $self->ut_numbern('batchnum')
    || $self->ut_enum('status', [ '', 'I', 'R' ])
  ;
  return $error if $error;

  $self->SUPER::check;
}

=back

=head1 BUGS

The author forgot to customize this manpage.

=head1 SEE ALSO

L<FS::Record>, schema.html from the base documentation.

=cut

1;


Index: cust_pay_batch.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay_batch.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cust_pay_batch.pm	2 Apr 2006 22:13:34 -0000	1.11
+++ cust_pay_batch.pm	20 May 2006 20:06:30 -0000	1.12
@@ -37,7 +37,7 @@
 
 =item paybatchnum - primary key (automatically assigned)
 
-=item cardnum
+=item payinfo
 
 =item exp - card expiration 
 
@@ -119,7 +119,7 @@
   my $error = 
       $self->ut_numbern('paybatchnum')
     || $self->ut_numbern('trancode') #depriciated
-    || $self->ut_number('cardnum') 
+    || $self->ut_number('payinfo') 
     || $self->ut_money('amount')
     || $self->ut_number('invnum')
     || $self->ut_number('custnum')
@@ -137,14 +137,19 @@
   $self->first =~ /^([\w \,\.\-\']+)$/ or return "Illegal first name";
   $self->first($1);
 
-  my $cardnum = $self->cardnum;
-  $cardnum =~ s/\D//g;
-  $cardnum =~ /^(\d{13,16})$/
-    or return "Illegal credit card number";
-  $cardnum = $1;
-  $self->cardnum($cardnum);
-  validate($cardnum) or return "Illegal credit card number";
-  return "Unknown card type" if cardtype($cardnum) eq "Unknown";
+  # FIXME
+  # there is no point in false laziness here
+  # we will effectively set "check_payinfo to 0"
+  # we can change that when we finish the refactor
+  
+  #my $cardnum = $self->cardnum;
+  #$cardnum =~ s/\D//g;
+  #$cardnum =~ /^(\d{13,16})$/
+  #  or return "Illegal credit card number";
+  #$cardnum = $1;
+  #$self->cardnum($cardnum);
+  #validate($cardnum) or return "Illegal credit card number";
+  #return "Unknown card type" if cardtype($cardnum) eq "Unknown";
 
   if ( $self->exp eq '' ) {
     return "Expiration date required"; #unless 
@@ -305,6 +310,21 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  my $pay_batch = qsearchs('pay_batch',{'batchnum'=> $paybatch});
+  unless ($pay_batch && $pay_batch->status eq 'I') {
+    $dbh->rollback if $oldAutoCommit;
+    return "batch $paybatch is not in transit";
+  };
+
+  my %batchhash = $pay_batch->hash;
+  $batchhash{'status'} = 'R';   # Resolved
+  my $newbatch = new FS::pay_batch ( \%batchhash );
+  my $error = $newbatch->replace($paybatch);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error
+  }
+
   my $total = 0;
   my $line;
   while ( defined($line=<$fh>) ) {

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- cust_bill.pm	14 May 2006 16:47:31 -0000	1.146
+++ cust_bill.pm	20 May 2006 20:06:30 -0000	1.147
@@ -13,7 +13,7 @@
 use Locale::Country;
 use FS::UID qw( datasrc );
 use FS::Misc qw( send_email send_fax );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::cust_main_Mixin;
 use FS::cust_main;
 use FS::cust_bill_pkg;
@@ -1282,8 +1282,22 @@
 sub batch_card {
   my $self = shift;
   my $cust_main = $self->cust_main;
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $pay_batch = qsearchs('pay_batch'=> '');
+
+  unless ($pay_batch) {
+    $pay_batch = new FS::pay_batch;
+    my $error = $pay_batch->insert;
+    if ( $error ) {
+      die "error creating new batch: $error\n";
+    }
+  }
 
   my $cust_pay_batch = new FS::cust_pay_batch ( {
+    'batchnum' => $pay_batch->getfield('batchnum'),
     'invnum'   => $self->getfield('invnum'),
     'custnum'  => $cust_main->getfield('custnum'),
     'last'     => $cust_main->getfield('last'),
@@ -1294,7 +1308,7 @@
     'state'    => $cust_main->getfield('state'),
     'zip'      => $cust_main->getfield('zip'),
     'country'  => $cust_main->getfield('country'),
-    'cardnum'  => $cust_main->payinfo,
+    'payinfo'  => $cust_main->payinfo,
     'exp'      => $cust_main->getfield('paydate'),
     'payname'  => $cust_main->getfield('payname'),
     'amount'   => $self->owed,
@@ -1302,6 +1316,8 @@
   my $error = $cust_pay_batch->insert;
   die $error if $error;
 
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
   '';
 }
 



More information about the freeside-commits mailing list