X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=manufacturing%2Fincludes%2Fdb%2Fwork_order_requirements_db.inc;h=6bb171c7329d85131ea11a1f9a60dbed0f68f39e;hb=fc449c48a8d4ba23bfb18318dff08746340a440c;hp=b919561be42bc3b42b10ef2512adf63b5547fac3;hpb=d1babda7c01b314d35fb89f2d195553b55936532;p=fa-stable.git diff --git a/manufacturing/includes/db/work_order_requirements_db.inc b/manufacturing/includes/db/work_order_requirements_db.inc index b919561b..6bb171c7 100644 --- a/manufacturing/includes/db/work_order_requirements_db.inc +++ b/manufacturing/includes/db/work_order_requirements_db.inc @@ -11,39 +11,43 @@ ***********************************************************************/ function get_wo_requirements($woid) { - $sql = "SELECT ".TB_PREF."wo_requirements.*, ".TB_PREF."stock_master.description, - ".TB_PREF."stock_master.mb_flag, - ".TB_PREF."locations.location_name, - ".TB_PREF."workcentres.name AS WorkCentreDescription FROM - (".TB_PREF."wo_requirements, ".TB_PREF."locations, " - .TB_PREF."workcentres) INNER JOIN ".TB_PREF."stock_master ON - ".TB_PREF."wo_requirements.stock_id = ".TB_PREF."stock_master.stock_id + $sql = "SELECT req.*, item.description, item.mb_flag, loc.location_name, + center.name AS WorkCentreDescription, + item.material_cost as ComponentCost, + item.inventory_account, + item.assembly_account + FROM (".TB_PREF."wo_requirements req," + .TB_PREF."locations loc," + .TB_PREF."workcentres center) + INNER JOIN ".TB_PREF."stock_master item ON req.stock_id=item.stock_id WHERE workorder_id=".db_escape($woid)." - AND ".TB_PREF."locations.loc_code = ".TB_PREF."wo_requirements.loc_code - AND ".TB_PREF."workcentres.id=workcentre"; + AND loc.loc_code = req.loc_code + AND center.id=workcentre"; return db_query($sql, "The work order requirements could not be retrieved"); } +function get_requirements_costs($woid) +{ + $sql = "SELECT SUM(units_req*unit_cost) cost + FROM ".TB_PREF."wo_requirements + WHERE workorder_id=".db_escape($woid); + + $result = db_query($sql, "The work order requirements costs could not be retrieved"); + $costs = db_fetch($result); + + return $costs['cost'] ? $costs['cost'] : 0; +} + //-------------------------------------------------------------------------------------- function create_wo_requirements($woid, $stock_id) { - // create Work Order Requirements based on the bom - $result = get_bom($stock_id); - - while ($myrow = db_fetch($result)) - { - - $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code) - VALUES (".db_escape($woid).", '" . - $myrow["component"] . "', '" . - $myrow["workcentre_added"] . "', '" . - $myrow["quantity"] . "', '" . - $myrow["loc_code"] . "')"; - - db_query($sql, "The work order requirements could not be added"); - } + $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code) + SELECT ".db_escape($woid).", component, workcentre_added, quantity, loc_code + FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id); + + db_query($sql, "The work order requirements could not be added"); } //-------------------------------------------------------------------------------------- @@ -56,12 +60,16 @@ function delete_wo_requirements($woid) //-------------------------------------------------------------------------------------- - -function update_wo_requirement_issued($woid, $stock_id, $quantity) +/* + Update total component units issued and average component cost +*/ +function update_wo_requirement_issued($id, $quantity, $cost) { - $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = units_issued + ".db_escape($quantity)." - WHERE workorder_id = ".db_escape($woid)." AND stock_id = ".db_escape($stock_id); - + $sql = "UPDATE ".TB_PREF."wo_requirements SET + unit_cost = (units_issued*unit_cost+".$quantity*$cost.")/(units_issued+".$quantity."), + units_issued = units_issued + ".db_escape($quantity)." + WHERE id = ".db_escape($id); + db_query($sql, "The work requirements issued quantity couldn't be updated"); } @@ -69,11 +77,9 @@ function update_wo_requirement_issued($woid, $stock_id, $quantity) function void_wo_requirements($woid) { - $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0 WHERE workorder_id = " - .db_escape($woid); + $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0 + WHERE workorder_id = ".db_escape($woid); db_query($sql, "The work requirements issued quantity couldn't be voided"); } -//-------------------------------------------------------------------------------------- -