Hello,
I posted this before and respondents wanted more code to help decipher
it. So I'm posting again with code below.
I have a script that is run by crontab. It Opens $user_file (flat file)
and checks for accounts with current date and charges the users card if
it's 30 days old. It also sends a reminder to those who are on the 30
day free trial. Sometimes it puts this... SCALAR(0x82dea94) or
something similar at the beginning of the a line in the $user_file. The
scipt only processes 20 lines at a time (every minute) to avoid server
time out.
Thanks in advance for your help.
sub billing_engine {
$e_number = "-1";
open (USERS, "$user_file") || &billerror
("$user_file Billing Notice" );
flock(USERS, 2);
while (<USERS>)
{
$line = $_;
chomp $line;
@fields = split (/\|/, $line);
@line =$line;
foreach $jiggy(@line){
$e_number++;
if (($start eq "$e_number")..($end eq "$e_number")){
$namelist .="$fields[1]\n";
$yes_row_count++;
($dbmonth,$dbday,$dbyear) = split (/\//, $fields[$field_for_update]);
$julian_day = &jday($dbmonth,$dbday,$dbyear);
($today_month,$today_day,$today_year) = split (/\//, &get_date);
$today = &jday($today_month,$today_day,$today_year);
$updated_days_ago = ($today - $julian_day);
if($fields[$field_for_account_status] eq "Ok"){
$current_row .= "$line";
@chargerow = $current_row;
foreach $customer (@chargerow){
if ($updated_days_ago >= "30"){
$auth_count++;
&auto_send_to_authorizenet;
if($declined){
$fields[$field_for_account_status] = "Ten_Days_Left";
$new_current_row .= join('|' => @fields) . "\n";
$email_user = $fields[$field_for_email];
&declined_email;
&admin_declined_email;
$email_user = "";
}
else{ #not declined
$fields[$field_for_account_status] = "Ok";
$fields[$field_for_update] = "$current_date";
$new_current_row .= join('|' => @fields) . "\n";
$email_user = $fields[$field_for_email];
&write_log;
&account_paid_email;
&admin_account_paid_email;
$email_user = "";
}#else not declined
}# if 30 days old
#save all the ones not 30 days old yet
else{ $new_current_row .= "$line\n";}
}# foreach chargerow
$new_current_row = "$new_current_row";
}#status Ok
###########################################
else {#not Ok
$bill_row .= "$line";
@bill_row = $bill_row;
foreach $bill (@bill_row ){
#This is what we do with all the people on 30 day trial
$bill_row_count++;
################
if($fields[$field_for_account_status] eq "One_Day_Left"){
$One_bill_row_count++;
$Thirty_bill_row_count++;
$fields[$field_for_account_status] = "Delete";
$Thirty_bill_row .= join('|' => @fields) . "\n";
}
#################
elsif($fields[$field_for_account_status] eq "Two_Days_Left"){
$Thirty_bill_row_count++;
$fields[$field_for_account_status] = "One_Day_Left";
$Thirty_bill_row .= join('|' => @fields) . "\n";
$email_user = $fields[$field_for_email];
&thirty_day_email;
$email_user = "";
}
#etc to 30-day-trial
#################
elsif($fields[$field_for_account_status] eq "30-Day-Trial"){
$Thirty_bill_row_count++;
$fields[$field_for_account_status] = "TwentyNine_Days_Left";
$Thirty_bill_row .= join('|' => @fields) . "\n";
$email_user = $fields[$field_for_email];
&thirty_day_email;
$email_user = "";
}
#################
elsif($fields[$field_for_account_status] eq "Donated"){
$Thirty_bill_row_count++;
$fields[$field_for_account_status] = "Donated";
$Thirty_bill_row .= join('|' => @fields) . "\n";
$email_user = $fields[$field_for_email];
$email_user = "";
}
#################
else{
$Leftover_bill_row_count++;
$Thirty_bill_row_count++;
$fields[$field_for_account_status] = "LeftOver";
$Thirty_bill_row .= join('|' => @fields) . "\n";
}
#################
}#foreach $bill
}#else
}#@billingnumber
else{ $hold_row_count++;
$hold_row .="$line\n"; }
}#jiggy
}#while
flock(USERS, 8);
close (USERS);
open (USERS, ">$user_file") || &billerror("$user_file Billing Notice");
flock(USERS, 2);
print USERS "$hold_row";
print USERS "$new_current_row";
print USERS "$Thirty_bill_row";
flock(USERS, 8);
close (USERS);
############
}#billing engine