The person who wrote this script is no longer supporting the program. We added a field to the end of the input file and need it to come out with the output. I am grasping at straws to see if someone could help.
Thanks
#!/usr/bin/perl#GPT Invoice Proc - in production 11-8-11
# Modified 03-14-2012 to eliminate KwikTag output for Laserfiche workflow
my $FileStat=0;
my $strng='';
my $time;
my $Workfile='';
my $FLC=2;
my $FSize;
my $FDir;
my $KTdir;
my $KTopened=0;
my $HldInvNo='';
my $BCode;
my $x=0;
my $n;
my $LineCount=0;
my $strng='';
my $ParmPass;
my $ParmReturn;
my $PrintLine="Yes";
my $strlen;
my @LngNote;
my $LngNoteNDX;
#N_ is for Notes line, I_ is for itemized line
$FDir='C:\E21Watch\GPT_Invc_Crdt\Stage';
$KTdir = 'C:\E21Watch\GPT_Invc_Crdt\Output_KwikTag\Invoices';
chdir $FDir;
opendir (THISDIR, ".");
@allfiles = readdir THISDIR;
closedir THISDIR;
sub KTagFix
{ #substitutes illegal kwik tag characters with legal ones
$ParmReturn='';
$ParmPass =~ s/\"/`/g;
$ParmPass =~ s/&/&/g;
$ParmPass =~ s/#/#/g;
$ParmPass =~ s/\*/~/g;
$ParmReturn=$ParmPass;
}
for($FLC=2;$FLC<1000;$FLC++)
{ if($allfiles[$FLC])
{ if(uc($allfiles[$FLC]) =~ m/.PRC/)
{ $Workfile = $allfiles[$FLC];
print "$Workfile\n";
$FileStat=open(SESAME,$Workfile);
$time=time();
$time=$time + int(rand(15076));
open (OUTFILE, ">", $FDir ."\\" .substr($Workfile,0,length($Workfile)-4) ."_" .$time .'.csv');
while ($line=<SESAME>)
{
#PROC FOR EACH FILE STARTS HERE
if(substr($line,0,1) ne '=')
{ ( $InvNo, $SldCode,$SldName,$SldAddr1, $SldAddr2, $SldAddr3, $SldCity, $SldState, $SldZip,
$ShpCode, $ShpName, $ShpAddr1, $ShpAddr2, $ShpAddr3, $ShpCity, $ShpState, $ShpZip,
$InvDate, $OrderDate, $Terms, $ShpVia, $CstPO, $Rep, $Route,
$QtyShp, $QtyOrd, $ItemNo, $Pounds, $CommNo, $MfgNo, $UPC, $PrtCode, $PrtDesc, $UnitPrice, $ListPrice, $NetPrice, $Exten,
$TotPounds, $TotPieces, $TotMerch, $BalDue, $Phone,
$frtShp, $frtMisc, $frtStop, $frtUtil, $frtSpdr,
$Freight, $InvType, $Notes, $ItemSeq, $RePrint,
$StateTx, $CntyTx, $CityTx, $CntryTx, $Typ1Tx, $Typ2Tx, $Typ3Tx, $Typ4Tx,
$TTax, $Handling, $Discount, $Allowance, $AllowDesc, $AllowTot, $StopNo,
$DiscDate, $DiscAmt, $ReasonCode, $ReasonDesc, $OrigInvoice, $CustEmail, $OrderNo, $ReleaseNo, $OrdMerchTot,
$OrdAllowTot, $OrdDiscTot, $OrdHandTot, $OrdFreightTot, $OrdTaxTot, $OrderTot, $OrdLbsTot, $OrdPcsTot, $InvGroup,
$extra4, $extra3, $extra2, $extra1
)=split ('\|',$line);
# 9, 8, 7, 13, 5, 5, 5, 8, 7, 9, 9, 4
$BCode=$InvNo;
if(length($PrtDesc)>56)
{ $PrtDesc=substr($PrtDesc,0,56);}
if(substr($BCode,0,1) gt '@')
{ $BCode=substr($BCode,1,length($BCode)-1);}
if(length($PrtCode)>9)
{ print "part length too long - $PrtCode\n";}
if(($QtyShp and $PrtDesc) or ($QtyOrd and $PrtDesc))
{ $PrintLine="Yes";} else
{ $PrintLine="No";}
$QtyShp=sprintf("%*s",5, $QtyShp);
$QtyOrd=sprintf("%*s",5, $QtyOrd);
$ItemNo=sprintf("%*s",-9, substr($PrtCode,0,9));
$MfgNo=sprintf("%*s",-9, substr($MfgNo,0,9));
$UPC=sprintf("%*s",-14, substr($UPC,0,14));
$PrtDesc=sprintf("%*s",-56, $PrtDesc);
$ListPrice=sprintf("%*s",8, $ListPrice);
$UnitPrice=sprintf("%*s",9, $UnitPrice);
$Exten=sprintf("%*s",9,$Exten);
$ItemSeq=sprintf("%*s",4,$ItemSeq);
if($Freight>0 or $Freight<0) #For Output Line 30
{ $Freight='Total Freight: ' .$Freight;} else
{ $Freight='';}
if($Handling>0 or $Handling<0)
{ $Handling='Handling: ' .$Handling;} else
{ $Handling='';} #For Output Line 35
if($Discount==0 or length($Discount)==0)
{ $Discount='';}
if($frtSpdr>0 or $frtSpdr<0) #For Output Line 39
{ $frtSpdr='Fuel Surcharge:' .$frtSpdr;} else
{ $frtSpdr='';}
if($CntyTx>0 or $CntyTx<0) #For Output Line 40
{ $CntyTx='County Tax: ' .$CntyTx;} else
{ $CntyTx='';}
if($StateTx>0 or $StateTx<0) #For Output Line 41
{ $StateTx='State Tax: ' .$StateTx;} else
{ $StateTx='';}
if($CityTx>0 or $CityTx<0) #For Output Line 43
{ $CityTx='City Tax: ' .$CityTx;} else
{ $CityTx='';}
if($Typ1Tx>0 or $Typ1Tx<0) #For Output Line 44
{ $Typ1Tx='Local Tax: ' .$Typ1Tx;} else
{ $Typ1Tx='';}
if(index($AllowTot,'-',0)>0)
{ $x=index($AllowTot,'-',0);
$AllowTot = '-' .substr($AllowTot,0,$x);
}
if(index($Discount,'-',0)>0)
{ $x=index($Discount,'-',0);
$Discount = '-' .substr($Discount,0,$x);
}
if($Discount<0 or $Discount>0)
{ $AllowDesc = "Hill's Rotational Allowance";}
$OrderNo=sprintf("%*s",-9,$OrderNo);
$OrdLbsTot=sprintf("%*s",8,$OrdLbsTot);
$OrdPcsTot=sprintf("%*s",5,$OrdPcsTot);
$OrdMerchTot=sprintf("%*s",9,$OrdMerchTot);
# if($OrdFreightTot==0)
# {$OrdFreightTot='';}
$OrdFreightTot=sprintf("%*s",8,$OrdFreightTot);
$OrdTaxTot=sprintf("%*s",8,$OrdTaxTot);
$OrdHandTot=sprintf("%*s",8,$OrdHandTot);
$OrdAllowTot=sprintf("%*s",8,$OrdAllowTot);
$OrderTot=sprintf("%*s",8,$OrderTot);
$OrdDiscTot=sprintf("%*s",8,$OrdDiscTot);
$InvGroup=sprintf("%*s",2,$InvGroup);
# if(length($CustEmail)>0)
# { $CustEmail=sprintf("%*s",(70-length($InvNo)),$CustEmail) .' EMAIL'; }
#Adjusting for requirement change on TotTax and AllowTot field - not needed anymore - forcing value to zero 11_28_2011
$AllowTot=0;
$TTax=0;
if($InvNo ne 'invoice_numb')
{
if ($InvNo ne $HldInvNo)
{ $HldInvNo=$InvNo;
$LineCount=0;
# if(uc($InvType) eq 'CREDIT')
# { $CntyTx = $CntyTx .'-';
# $StateTx = $StateTx .'-';
# $CityTx = $CityTx .'-';
# $Typ1Tx = $Typ1Tx .'-';
# }
print OUTFILE "\f";
print OUTFILE "$InvNo\n$SldCode\n$SldName\n$SldAddr1\n$SldAddr2\n$SldAddr3\n$SldCity\n$SldState\n$SldZip\n";
print OUTFILE "$ShpCode\n$ShpName\n$ShpAddr1\n$ShpAddr2\n$ShpAddr3\n$ShpCity\n$ShpState\n$ShpZip\n";
print OUTFILE "$InvDate\n$OrderDate\n$Terms\n$ShpVia\n$CstPO\n$Rep\n$Route\n";
print OUTFILE "$TotPounds\n$TotPieces\n$TotMerch\n$BalDue\n$Phone\n$Freight\n$InvType\n$ItemSeq\n$RePrint\n";
print OUTFILE "$TTax\n$Handling\n$Discount\n$AllowTot\n$AllowDesc\n$frtSpdr\n$CntyTx\n$StateTx\n";
print OUTFILE "$StopNo\n$CityTx\n$Typ1Tx\n$DiscDate\n$DiscAmt\n$CustEmail\n";
# print OUTFILE "$OrderNo\n$ReleaseNo\n$OrdMerchTot\n$OrdAllowTot\n$OrdDiscTot\n$OrdHandTot\n";
# print OUTFILE "$OrdFreightTot\n$OrdTaxTot\n$OrderTot\n$OrdLbsTot\n$OrdPcsTot\n$InvGroup\n";
#9, 17, 24, 33, 41, 47, 53, 59
if(uc($InvType) eq 'INVOICE')
{ print OUTFILE "N_***CLAIMS FOR SHORTAGES OR DAMAGE***\n";
print OUTFILE "N_***MUST BE MADE WITHIN 48 HOURS ***\n";
print OUTFILE "N_***FROM THE DATE OF DELIVERY ***\n";
}
}
$LineCount += 1;
if ($Notes)
{ $n=0;
$x=1;
$strlen=length($Notes);
while($x > 0)
{ $x=index($Notes,' ',40);
$LngNote[$n]=substr($Notes,0,$x+1);
$Notes=substr($Notes,$x+1,$strlen-$x+1);
if($x>0)
{$n += 1;}
}
if(length($Notes)>0)
{ $LngNote[$n]=$Notes;}
for($x=0;$x<$n+1;$x++)
{ print OUTFILE "N_$LngNote[$x]\n";}
# print OUTFILE "N_$Notes\n";
} else
{ if($PrintLine eq "Yes")
{ #print "line $QtyShp " .length($QtyShp) ." - " .length($QtyShp) ." - " .length($PrtDesc) ."\n";
print OUTFILE "I_$QtyOrd $QtyShp $ItemNo $MfgNo $UPC $PrtDesc $ListPrice $UnitPrice $Exten $OrderNo ";
print OUTFILE "$OrdLbsTot $OrdPcsTot $OrdMerchTot $OrdFreightTot $OrdTaxTot $OrdHandTot $OrdAllowTot $OrderTot $OrdDiscTot $InvGroup\n";
} else
{ $LineCount -+ 1;}
}
}
}
#PROC FOR EACH FILE ENDS HERE
}
# print OUTFILE "I_\nI_\n";
# print OUTFILE "I_" .sprintf("%*s",47,' ') ."Total Pounds: " .$TotPounds ."\n";
close SESAME;
close OUTFILE;
# close QTAG;
system("erase $Workfile");
} else
{ print "No File to Process\n";}
#End of testing WorkFile Extension
} else
{$FLC=1001;}
#End of check for next file in directory
}