This topic is locked
[SOLVED]

 Count Records in BeforeAdd Event

2/19/2014 5:25:05 AM
PHPRunner General questions
C
cms001 author

Hi ,
I am trying to check if the stock count is more than what is ordered in the before add event.

// GET CURRENT STOCK ITEM COUNT ON HAND:
//ID_MS = INTEGER VALUE

//$SESSION["BookingID"] = INTEGER VALUE


global $conn;

$rs = "select qtyonhand_ms from items_t where id_ms = " + $_SESSION["BookingID"];

//I am getting an error here

//$data = db_query($rs.$conn); //not sure how to retrieve the qtyonhand here

$data=db_fetch_array($rs,$conn);
$limit = $data["qtyonhand_ms"];
If $values["QTY_EM"] > $limit
$message = "STOCK AVAILABLE ON THIS DAY not enough.";

return false;
}

else

{

// if dont exist do something else
return true;


Please assist - I am fairly new to this !

A
Anapolis 2/19/2014



Hi ,
I am trying to check if the stock count is more than what is ordered in the before add event.

// GET CURRENT STOCK ITEM COUNT ON HAND:
//ID_MS = INTEGER VALUE

//$SESSION["BookingID"] = INTEGER VALUE
global $conn;

$rs = "select qtyonhand_ms from items_t where id_ms = " + $_SESSION["BookingID"];

//I am getting an error here

//$data = db_query($rs.$conn); //not sure how to retrieve the qtyonhand here

$data=db_fetch_array($rs,$conn);
$limit = $data["qtyonhand_ms"];
If $values["QTY_EM"] > $limit
$message = "STOCK AVAILABLE ON THIS DAY not enough.";

return false;
}

else

{

// if dont exist do something else
return true;


Please assist - I am fairly new to this !


I would guess that your first error is from the + you use:
$rs = "select qtyonhand_ms from items_t where id_ms = " + $_SESSION["BookingID"];
instead use a concatenation with this period sign .
$rs = "select qtyonhand_ms from items_t where id_ms = " . $_SESSION["BookingID"];
and this --
If $values["QTY_EM"] > $limit
should be
If ($values["QTY_EM"]) > $limit

C
cms001 author 2/19/2014

Hi,

Thanks for the reply,
I have made the changes as you indicated:

global $conn;

//CHANGE LAST SECTION OF CODE TO " . $_SESSION["BookingID"];

$rs = "select qtyonhand_ms from items_t where id_ms = " . $_SESSION["BookingID"];



//$data = db_query($rs.$conn);

$data=db_fetch_array($rs,$conn);
$limit = $data["qtyonhand_ms"];
//ADD BRACKETS

If ($values["QTY_EM"]) > $limit
$message = "STOCK AVAILABLE ON THIS DAY not enough.";

return false;
}

else

{

// if dont exist do something else
return true;


but am getting an error:

Parse error: syntax error, unexpected '>' in C:\cmsPHP\jcastle\output\include\calitems_t_events.php on line 47

Sergey Kornilov admin 2/19/2014

Run this code through syntax validator in PHPRunner. It looks like a lot of missing and misplaced parenthesis and curly brackets.

C
cms001 author 2/20/2014



Run this code through syntax validator in PHPRunner. It looks like a lot of missing and misplaced parenthesis and curly brackets.


Initially run the syntax checker, but it did not pick up the errors
But: got it to work

global $conn;

$strSQLExists = "select qtyall_ms from items_t where id_ms = " . $values["ITEMID_EM"] ;

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
$maxQty = ($data["qtyall_ms"]);
if($maxQty > 3)

{

//TEST BIGGER THAN 3

$message = "The data is " .$maxQty ;

return false;

}

else

{

//TEST 2

$message = "The data is not 3 " ;

return false;

}