<?php
global $TABLE_GL_DATA;
global $connect;
$PREPARED_SQL = odbc_prepare($c onnect, "INSERT INTO $TABLE_GL_DATA
VALUES (?,?,?,?,?,?,?) ");
function Generate_GL_Dat a()
{
global $connect;
global $TABLE_WORKING;
$query = "SELECT INVOICE, TRACKING, AMOUNT, REFERENCE, SNAME, SADD1,
SADD2, SADD3, SCITY, SSTATE, SZIP, RNAME, RADD1, RADD2, RADD3, "
."RCITY, RSTATE, RZIP FROM $TABLE_WORKING WHERE BATCHNUM = " .
$_GET["BATCH_NUMB ER"];
$result = odbc_exec($conn ect, $query);
while (odbc_fetch_row ($result)) {
Parse_Results($ result);
}
odbc_commit($co nnect);
}
Function Parse_Results($ result)
{
$INVOICE = odbc_result($re sult, "INVOICE");
$TRACKING = odbc_result($re sult, "TRACKING") ;
$AMOUNT = odbc_result($re sult, "AMOUNT");
$REFERNECES = odbc_result($re sult, "REFERENCE" );
$SZIP = odbc_result($re sult, "SZIP");
$RZIP = odbc_result($re sult, "RZIP");
// First attempt to take any cost centers from the reference data and
use those
if ( Generate_From_P rofitCenters($R EFERNECES, $INVOICE, $TRACKING,
$AMOUNT) )
return;
// Now check for order numbers in the reference field and if they
exist obtain GJ data
if (Generate_From_ Orders($REFERNE CES, $SZIP) )
return;
// Now check for RMA numbers in the reference field and if they exist
obtain the GJ data
if ( Generate_From_R MA($REFERNECES, $RZIP) )
return;
// For all others check if they are known Vendors (ie they exist in
the Vendor Master file)
if ( Generate_From_K nown_Vendor($RE FERNECES) )
return;
//Generate_Defaul ts($INVOICE, $TRACKING, $AMOUNT);
//return;
global $PREPARED_SQL;
// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"0000000000 ", "00000000", $AMOUNT, "U");
print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
function Generate_Defaul ts($INVOICE, $TRACKING, $AMOUNT)
{
global $PREPARED_SQL;
// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"0000000000 ", "00000000", $AMOUNT, "U");
print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
Function Generate_From_P rofitCenters($R EFERENCES, $INVOICE, $TRACKING,
$AMOUNT)
{
global $PREPARED_SQL;
/** Regular expression to find the following
Starts with the number 1 with and contains a total of 10 digits
OR Starts with the number 1 and has the format of 1### #### ##
OR Starts with the number 1 and has the format of 1###.####.##
*/
$reg_exp = "/1\\d\\d\\d\\d\\ d\\d\\d\\d\\d|1 \\d\\d\\d \\d\\d\\d\\d
\\d\\d|1\\d\\d\ \d\\.\\d\\d\\d\ \d\\.\\d\\d/";
preg_match_all( $reg_exp, $REFERENCES, $results);
$c = sizeof($results[0]);
$rand_num = rand(0, $c-1);
echo "<BR> $TRACKING $REFERENCES <BR>";
for ($i = 0; $i < $c; $i++) {
// Remove any instances of periods or spaces
$results[0][$i] = trim(str_replac e(" ", "", $results[0][$i]));
$results[0][$i] = trim(str_replac e(".", "", $results[0][$i]));
// We round down all partials because we'll add the remainder penny
to a random one
$partial_amount = floor($AMOUNT / $c * 100) / 100;
// Check if we're on the last found profit center AND the TOTAL
amount / number of profit centers doesn't divide evenly
// If so we have to tack on the remainder to a random portion
if ($i == $rand_num && ($AMOUNT / $c) != $partial_amount ) {
$partial_amount = $AMOUNT - ($partial_amoun t * ($c - 1));
}
if (strpos($REFERE NCES, "<p id='status'
style='display: none'>OUTGOING< p>") !== false)
$ACCOUNT = "50050000";
else
$ACCOUNT = "50106000";
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"{$results[0][$i]}", "$ACCOUNT", $partial_amount , "U");
//print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
if ($c > 0) // Let the application know if we found any ProfitCenters
return true;
else
return false;
}
Originally I had the code from function Generate_Defaul ts(..) in
Parse_Results but I was getting a very strange error message
Warning: odbc_execute() [function.odbc-execute]: SQL error:
[IBM][Client Access Express ODBC Driver (32-bit)]Wrong number of
parameters., SQL state 07001 in SQLExecute in
C:\Inetpub\Acco unting\WebSys\A ccounts_Payable \Freight_EDI\Ge nerate_GL_Data. php
on line 110
If I comment out the code (like it is above) and use the function
Generate_Defaul ts(..) I don't get this error message.
Now if I do the reverse (leave the default in Parse_Results() ) and
comment out Generate_From_P rofitCenters() it works...
It almost seems like there is an issue with scope and my variable
$PREPARED_SQL
Any ideas?
global $TABLE_GL_DATA;
global $connect;
$PREPARED_SQL = odbc_prepare($c onnect, "INSERT INTO $TABLE_GL_DATA
VALUES (?,?,?,?,?,?,?) ");
function Generate_GL_Dat a()
{
global $connect;
global $TABLE_WORKING;
$query = "SELECT INVOICE, TRACKING, AMOUNT, REFERENCE, SNAME, SADD1,
SADD2, SADD3, SCITY, SSTATE, SZIP, RNAME, RADD1, RADD2, RADD3, "
."RCITY, RSTATE, RZIP FROM $TABLE_WORKING WHERE BATCHNUM = " .
$_GET["BATCH_NUMB ER"];
$result = odbc_exec($conn ect, $query);
while (odbc_fetch_row ($result)) {
Parse_Results($ result);
}
odbc_commit($co nnect);
}
Function Parse_Results($ result)
{
$INVOICE = odbc_result($re sult, "INVOICE");
$TRACKING = odbc_result($re sult, "TRACKING") ;
$AMOUNT = odbc_result($re sult, "AMOUNT");
$REFERNECES = odbc_result($re sult, "REFERENCE" );
$SZIP = odbc_result($re sult, "SZIP");
$RZIP = odbc_result($re sult, "RZIP");
// First attempt to take any cost centers from the reference data and
use those
if ( Generate_From_P rofitCenters($R EFERNECES, $INVOICE, $TRACKING,
$AMOUNT) )
return;
// Now check for order numbers in the reference field and if they
exist obtain GJ data
if (Generate_From_ Orders($REFERNE CES, $SZIP) )
return;
// Now check for RMA numbers in the reference field and if they exist
obtain the GJ data
if ( Generate_From_R MA($REFERNECES, $RZIP) )
return;
// For all others check if they are known Vendors (ie they exist in
the Vendor Master file)
if ( Generate_From_K nown_Vendor($RE FERNECES) )
return;
//Generate_Defaul ts($INVOICE, $TRACKING, $AMOUNT);
//return;
global $PREPARED_SQL;
// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"0000000000 ", "00000000", $AMOUNT, "U");
print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
function Generate_Defaul ts($INVOICE, $TRACKING, $AMOUNT)
{
global $PREPARED_SQL;
// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"0000000000 ", "00000000", $AMOUNT, "U");
print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
Function Generate_From_P rofitCenters($R EFERENCES, $INVOICE, $TRACKING,
$AMOUNT)
{
global $PREPARED_SQL;
/** Regular expression to find the following
Starts with the number 1 with and contains a total of 10 digits
OR Starts with the number 1 and has the format of 1### #### ##
OR Starts with the number 1 and has the format of 1###.####.##
*/
$reg_exp = "/1\\d\\d\\d\\d\\ d\\d\\d\\d\\d|1 \\d\\d\\d \\d\\d\\d\\d
\\d\\d|1\\d\\d\ \d\\.\\d\\d\\d\ \d\\.\\d\\d/";
preg_match_all( $reg_exp, $REFERENCES, $results);
$c = sizeof($results[0]);
$rand_num = rand(0, $c-1);
echo "<BR> $TRACKING $REFERENCES <BR>";
for ($i = 0; $i < $c; $i++) {
// Remove any instances of periods or spaces
$results[0][$i] = trim(str_replac e(" ", "", $results[0][$i]));
$results[0][$i] = trim(str_replac e(".", "", $results[0][$i]));
// We round down all partials because we'll add the remainder penny
to a random one
$partial_amount = floor($AMOUNT / $c * 100) / 100;
// Check if we're on the last found profit center AND the TOTAL
amount / number of profit centers doesn't divide evenly
// If so we have to tack on the remainder to a random portion
if ($i == $rand_num && ($AMOUNT / $c) != $partial_amount ) {
$partial_amount = $AMOUNT - ($partial_amoun t * ($c - 1));
}
if (strpos($REFERE NCES, "<p id='status'
style='display: none'>OUTGOING< p>") !== false)
$ACCOUNT = "50050000";
else
$ACCOUNT = "50106000";
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING" ,
"{$results[0][$i]}", "$ACCOUNT", $partial_amount , "U");
//print_r($myarra y);
$result = odbc_execute($P REPARED_SQL, $myarray );
}
if ($c > 0) // Let the application know if we found any ProfitCenters
return true;
else
return false;
}
Originally I had the code from function Generate_Defaul ts(..) in
Parse_Results but I was getting a very strange error message
Warning: odbc_execute() [function.odbc-execute]: SQL error:
[IBM][Client Access Express ODBC Driver (32-bit)]Wrong number of
parameters., SQL state 07001 in SQLExecute in
C:\Inetpub\Acco unting\WebSys\A ccounts_Payable \Freight_EDI\Ge nerate_GL_Data. php
on line 110
If I comment out the code (like it is above) and use the function
Generate_Defaul ts(..) I don't get this error message.
Now if I do the reverse (leave the default in Parse_Results() ) and
comment out Generate_From_P rofitCenters() it works...
It almost seems like there is an issue with scope and my variable
$PREPARED_SQL
Any ideas?