Did a sql_trail for the Direct purchase Invoice (turned on in the config.php file just before the "Process Invoice" button was clicked) and there were 144 SQL queries!
SELECT = 100
INSERT = 21
REPLACE = 3
UPDATE = 18
One BEGIN and One COMMIT.
It appears that each line item (stock_id) rate in the purchase Direct Invoice form populates the stock_master.material_cost and purch_data.price (for the specific supplier_id) fields even if it already exists and has not changed. It must certainly be here that something is going wrong.
The following SQL run on the FA db would yield the necessary sequence of SQLs that were executed:
SELECT id , `result`, msg, REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(`sql`, ''', "'"),'<','<'),'>','>'),"\n",""),"\t",""),"\r","") AS SQL_used FROM `0_sql_trail`
The file purchasing/includes/db/grn_db.inc has the function update_average_material_cost() that provides the material cost for computations in other files. Must see if there is any anomaly here - missing scope/vars, etc.
The value of the $_POST variable just before Work Order Add just before executing line 264 in manufacturing/work_order_entry.php is:
[wo_ref] => WO11
[type] => 0
[_stock_id_edit] => I3
[stock_id] => I3
[StockLocation] => DEF
[quantity] => 1
[date_] => 09/10/2015
[Labour] => 3.00
[cr_lab_acc] => 1060
[Costs] => 2.00
[cr_acc] => 1060
[ADD_ITEM] => Add Workorder
[_focus] => wo_ref
[_modified] => 0
[_token] => a8c1a6693552df346a1fd03d90b1287e8c32cd276dfc60712b91f2154ef04926
[_random] => 700059.4337549664
Only the last 2 elements change on WO Addition.
Purchase Direct Invoice SQL Trail.xls 49.5 kb, 3 downloads since 2015-10-09
You don't have the permssions to download the attachments of this post.