@joe, we can add this function to purchasing/includes/db/grn_db.inc. to create a log file in the company's folder for each item whenever the average cost is updated in the system for any reason.
This function (in my instance) also sends an Email Alert to BCC Email of the company.
function update_cost_log($new_material_cost, $curr_material_cost, $qty, $price, $stock_id, $qoh )
{
global $path_to_root, $db_connections;
$company = $db_connections[$_SESSION["wa_current_user"]->company]["name"]; //added by faisal
$date = Today()." ".Now();// date("Y-m-d h:i:sa", $d);
$tran_type = $qty > 0 ? "Stock IN" : "Stock Out";
$log = "date=$date, company=$company, stock_id=".get_item($stock_id)['description'].",";
$log .="Quntity On Hand=$qoh,";
$log .= "Current Material Cost=$curr_material_cost,";
$log .= "$tran_type=$qty,";
$log .= "Price to Receive Stock=$price,";
$log .= "Calculated Material Cost = $new_material_cost";
file_put_contents(company_path()."/".$stock_id.'.log',$log.PHP_EOL,FILE_APPEND);
if (!get_company_pref('avg_cost_alert')) return;
require_once($path_to_root . "/reporting/includes/class.mail.inc");
$mail = new email("ABC", "smtp@abc.net");
$mail->phpmailer->addAddress(get_company_pref('bcc_email'));
$mail->subject("Average Cost Alert");
$mail->text($log);
$mail->send();
}
This function can be called at Line # 74 in the above file as below
if ($curr_material_cost <> $material_cost)
update_cost_log($material_cost, $curr_material_cost, $qty, $price_in_home_currency, $stock_id, $qoh); //by faisal
The same process can be repeated for manufacturing/includes/db/work_order_costing_db.inc
www.boxygen.pk