I had the problem that i needed the amount of my products in stock.
Solved this whith a simple formatting function.
num ist the product number,
amount the amount in the package (there can be multiple packages in stock containing this product)
[pre]
/**
displays num whith total amount available
formatting function for num field
*/
function dadabik_format_num_amount($value)
{
// fetch DB connection
global $conn;
// get the number of products in stock from the num field
$sql = "
SELECT num, sum(amountl) as number
FROM `Stock`
WHERE num= :my_num
";
//prepared query PDO
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':my_num', $value);
$res = execute_prepared_db($res_prepare,0);
// Fetch the result row
$row = fetch_row_db($res_prepare) ;
// You cound return $value here if you like , its the same
// I dont like linebreaks in productnumbers
$retval= "<nobr>".$row['num']. "</nobr>";
// Here we add the ammount
$retval.= "<div style=\"text-align:right\">";
$retval.= "({$row['number']})";
// return the formatted string
return $retval;
}
[/pre]
The output column looks like :
[pre]
Product number
----------------------
HR-55-KRDPP
(45566767)
BR-66-LLOPT
(500)
TT-89-POTZE
(90664)
...
[/pre]
So you always got a overviewof how many producst still in stock.
You can even create another table for stock warnings and add an entry in this table every time a product goes below a certain amount . Possibly it would be better to add a check like this in the delete/update hook.
Solved this whith a simple formatting function.
num ist the product number,
amount the amount in the package (there can be multiple packages in stock containing this product)
[pre]
/**
displays num whith total amount available
formatting function for num field
*/
function dadabik_format_num_amount($value)
{
// fetch DB connection
global $conn;
// get the number of products in stock from the num field
$sql = "
SELECT num, sum(amountl) as number
FROM `Stock`
WHERE num= :my_num
";
//prepared query PDO
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':my_num', $value);
$res = execute_prepared_db($res_prepare,0);
// Fetch the result row
$row = fetch_row_db($res_prepare) ;
// You cound return $value here if you like , its the same
// I dont like linebreaks in productnumbers
$retval= "<nobr>".$row['num']. "</nobr>";
// Here we add the ammount
$retval.= "<div style=\"text-align:right\">";
$retval.= "({$row['number']})";
// return the formatted string
return $retval;
}
[/pre]
The output column looks like :
[pre]
Product number
----------------------
HR-55-KRDPP
(45566767)
BR-66-LLOPT
(500)
TT-89-POTZE
(90664)
...
[/pre]
So you always got a overviewof how many producst still in stock.
You can even create another table for stock warnings and add an entry in this table every time a product goes below a certain amount . Possibly it would be better to add a check like this in the delete/update hook.