From: Janusz Dobrowolski Date: Sat, 2 Jan 2016 10:08:32 +0000 (+0100) Subject: Overhead and labour cost changed to define standard costs. X-Git-Tag: v2.4.2~19^2~73 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=fc449c48a8d4ba23bfb18318dff08746340a440c Overhead and labour cost changed to define standard costs. --- diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index daac59ad..b2560f75 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -79,6 +79,7 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension function add_gl_trans_std_cost($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_, $amount, $person_type_id=null, $person_id=null, $err_msg="") { + if ($amount != 0) return add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_, $amount, null, $person_type_id, $person_id, $err_msg); @@ -204,9 +205,10 @@ function get_gl_trans($type, $trans_id) //-------------------------------------------------------------------------------- -function get_gl_wo_cost_trans($trans_id, $cost_type=-1) +function get_gl_wo_cost_trans($trans_id, $cost_type=-1, $all_gl=false) { - $sql = "SELECT costing.*, gl.*, chart.account_name, com.memo_ FROM " + $sql = "SELECT costing.*, gl.*, chart.account_name, com.memo_ + FROM " .TB_PREF."wo_costing costing, " .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type AND gl.type_no=com.id," .TB_PREF."chart_master chart @@ -217,10 +219,48 @@ function get_gl_wo_cost_trans($trans_id, $cost_type=-1) AND gl.type_no=costing.trans_no"; if ($cost_type != -1) $sql .= " AND costing.cost_type=".db_escape($cost_type); - $sql .= " AND amount < 0"; - + $sql .= $all_gl ? " AND amount != 0" : " AND amount < 0"; + return db_query($sql, "The gl transactions could not be retrieved"); } + +function get_gl_wo_issue_trans($trans_id, $person_id=-1, $all_gl=false) +{ + $sql = "SELECT issue.*, gl.*, chart.account_name, com.memo_ + FROM " + .TB_PREF."wo_issues issue," + .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type AND gl.type_no=com.id," + .TB_PREF."chart_master chart + WHERE issue.workorder_id=".db_escape($trans_id) + ." AND chart.account_code=gl.account + AND gl.type=".ST_MANUISSUE." AND gl.type_no=issue.issue_no"; +// ." AND gl.person_type_id=".PT_WORKORDER; + if ($person_id != -1) + $sql .= " AND gl.person_id=".db_escape($person_id); + $sql .= $all_gl ? " AND amount != 0" : " AND amount < 0"; + $sql .= " ORDER BY type, type_no"; + return db_query($sql, "The gl transactions could not be retrieved"); +} + +function get_gl_wo_productions($trans_id, $all_gl=false) +{ + $sql = "SELECT rcv.*, gl.*, chart.account_name, com.memo_ + FROM " + .TB_PREF."wo_manufacture rcv, " + .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type AND gl.type_no=com.id," + .TB_PREF."chart_master chart + WHERE + rcv.workorder_id=".db_escape($trans_id) + ." AND chart.account_code=gl.account + AND gl.type=".ST_MANURECEIVE." + AND gl.type_no=rcv.id + AND amount != 0 " + .($all_gl ? " AND amount != 0" : " AND amount < 0") + ." ORDER BY type, type_no"; + + return db_query($sql, "The gl transactions could not be retrieved"); +} + function get_gl_balance_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0) { $from = date2sql($from_date); diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 6d562cf8..19f54f2b 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -86,10 +86,11 @@ function check_negative_stock($stock_id, $delta_qty, $location=null, $date=null) function get_item_edit_info($stock_id) { - $sql = "SELECT material_cost + labour_cost + overhead_cost AS standard_cost, units, decimals - FROM ".TB_PREF."stock_master,".TB_PREF."item_units + $sql = "SELECT item.material_cost, item.units, unit.decimals + FROM ".TB_PREF."stock_master item," + .TB_PREF."item_units unit WHERE stock_id=".db_escape($stock_id) - ." AND ".TB_PREF."stock_master.units=".TB_PREF."item_units.abbr"; + ." AND item.units=unit.abbr"; $result = db_query($sql, "The standard cost cannot be retrieved"); return db_fetch($result); @@ -97,10 +98,11 @@ function get_item_edit_info($stock_id) //-------------------------------------------------------------------------------------- -function get_standard_cost($stock_id) +function get_unit_cost($stock_id) { - $sql = "SELECT (material_cost + labour_cost + overhead_cost) AS std_cost - FROM ".TB_PREF."stock_master s WHERE stock_id=".db_escape($stock_id); + $sql = "SELECT material_cost + FROM ".TB_PREF."stock_master + WHERE stock_id=".db_escape($stock_id); $result = db_query($sql, "The standard cost cannot be retrieved"); $myrow = db_fetch_row($result); @@ -112,7 +114,8 @@ function get_standard_cost($stock_id) function is_inventory_item($stock_id) { - $sql = "SELECT stock_id FROM ".TB_PREF."stock_master + $sql = "SELECT stock_id FROM " + .TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id)." AND mb_flag <> 'D'"; $result = db_query($sql, "Cannot query is inventory item or not"); @@ -153,8 +156,8 @@ function get_already_delivered($stock_id, $location, $trans_no) return $row[0]; } /* - FIXME: $to ? Returns start move_id in latest negative status period for $stock_id + FIXME: $to ? */ function last_negative_stock_trans_id($stock_id, $to) { @@ -352,7 +355,7 @@ function handle_negative_inventory($stock_id, $quantity, $standard_cost, $date_) $id = get_next_trans_no(ST_JOURNAL); $ref = $Refs->get_next(ST_JOURNAL, null, $date_); - $diff = round($qoh*get_standard_cost($stock_id) + $quantity*$standard_cost, user_price_dec()); + $diff = round($qoh*get_unit_cost($stock_id) + $quantity*$standard_cost, user_price_dec()); if ($diff != 0) { @@ -417,8 +420,7 @@ function update_stock_move($type, $trans_no, $stock_id, $cost) function get_stock_moves($type, $type_no) { - $sql = "SELECT move.*, item.description, item.mb_flag, item.units, stock.location_name, - item.material_cost + item.labour_cost + item.overhead_cost AS FixedStandardCost + $sql = "SELECT move.*, item.description, item.mb_flag, item.units, stock.location_name FROM ".TB_PREF."stock_moves move," .TB_PREF."locations stock," .TB_PREF."stock_master item diff --git a/includes/db/manufacturing_db.inc b/includes/db/manufacturing_db.inc index 0a4035f0..dc635c3a 100644 --- a/includes/db/manufacturing_db.inc +++ b/includes/db/manufacturing_db.inc @@ -222,8 +222,8 @@ function get_bom($item) $sql = "SELECT bom.*, loc.location_name, centre.name AS WorkCentreDescription, item.description, item.mb_flag AS ResourceType, - item.material_cost+item.labour_cost+item.overhead_cost AS standard_cost, units, - bom.quantity * (item.material_cost+ item.labour_cost+ item.overhead_cost) AS ComponentCost + item.material_cost AS ProductCost, units, + bom.quantity * item.material_cost AS ComponentCost FROM ".TB_PREF."workcentres centre, ".TB_PREF."locations loc, ".TB_PREF."bom bom diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 1284a918..389ea530 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -51,7 +51,7 @@ function get_gl_view_str($type, $trans_no, $label="", $force=false, $class='', $ $label = _("GL"); $icon = ICON_GL; } - $url = ($type == ST_WORKORDER && !work_order_is_closed($trans_no)) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no" + $url = ($type == ST_WORKORDER) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no" : "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no"; return viewer_link($label, $url, $class, $id, $icon); diff --git a/inventory/cost_update.php b/inventory/cost_update.php index 6fa3a019..35347000 100644 --- a/inventory/cost_update.php +++ b/inventory/cost_update.php @@ -52,8 +52,7 @@ if (isset($_GET['stock_id'])) $should_update = false; if (isset($_POST['UpdateData'])) { - - $old_cost = get_standard_cost($_POST['stock_id']); + $old_cost = get_unit_cost($_POST['stock_id']); $new_cost = input_num('material_cost') + input_num('labour_cost') + input_num('overhead_cost'); @@ -131,7 +130,7 @@ $_POST['material_cost'] = price_decimal_format($myrow["material_cost"], $dec1); $_POST['labour_cost'] = price_decimal_format($myrow["labour_cost"], $dec2); $_POST['overhead_cost'] = price_decimal_format($myrow["overhead_cost"], $dec3); -amount_row(_("Standard Material Cost Per Unit"), "material_cost", null, "class='tableheader2'", null, $dec1); +amount_row(_("Unit cost"), "material_cost", null, "class='tableheader2'", null, $dec1); if ($myrow["mb_flag"]=='M') { diff --git a/inventory/includes/db/items_trans_db.inc b/inventory/includes/db/items_trans_db.inc index 84ba75ae..58d7722d 100644 --- a/inventory/includes/db/items_trans_db.inc +++ b/inventory/includes/db/items_trans_db.inc @@ -31,8 +31,8 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co begin_transaction(); $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", - labour_cost=".db_escape($labour_cost).", - overhead_cost=".db_escape($overhead_cost).", + labour_cost=".db_escape($labour_cost).", + overhead_cost=".db_escape($overhead_cost)." WHERE stock_id=".db_escape($stock_id); db_query($sql,"The cost details for the inventory item could not be updated"); diff --git a/inventory/includes/item_adjustments_ui.inc b/inventory/includes/item_adjustments_ui.inc index e2f585b6..66223fb4 100644 --- a/inventory/includes/item_adjustments_ui.inc +++ b/inventory/includes/item_adjustments_ui.inc @@ -160,8 +160,7 @@ function adjustment_edit_item_controls(&$order, $line_no=-1) $item_info = get_item_edit_info($_POST['stock_id']); $dec = $item_info['decimals']; $_POST['qty'] = number_format2(0, $dec); - //$_POST['std_cost'] = price_format($item_info["standard_cost"]); - $_POST['std_cost'] = price_decimal_format($item_info["standard_cost"], $dec2); + $_POST['std_cost'] = price_decimal_format($item_info["material_cost"], $dec2); $_POST['units'] = $item_info["units"]; } diff --git a/manufacturing/includes/db/work_order_costing_db.inc b/manufacturing/includes/db/work_order_costing_db.inc index efc6f405..2502be76 100644 --- a/manufacturing/includes/db/work_order_costing_db.inc +++ b/manufacturing/includes/db/work_order_costing_db.inc @@ -35,64 +35,6 @@ function delete_wo_costing($trans_type, $trans_no) db_query($sql, "could not delete work order costing"); } -//-------------------------------------------------------------------------------------- - -function add_material_cost($stock_id, $qty, $date_, $advanced=false, $woid=0) -{ - $m_cost = 0; - $result = get_bom($stock_id); - while ($bom_item = db_fetch($result)) - { - $standard_cost = get_standard_cost($bom_item['component']); - $m_cost += ($bom_item['quantity'] * $standard_cost); - } - $bom_cost = $m_cost; - $i_cost = 0; - if ($woid != 0 && work_order_has_issues($woid)) - { - $res = get_additional_issues($woid); - while ($issue = db_fetch($res)) - { - $standard_cost = get_standard_cost($issue['stock_id']); - $i_cost += ($issue['qty_issued'] * $standard_cost) / $qty; - } - } - $sql = "SELECT material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = " - .db_escape($stock_id); - $result = db_query($sql); - $myrow = db_fetch($result); - $material_cost = $myrow['material_cost']; - $m_cost += $i_cost; - /* - if ($advanced) - { - //reduce overhead_cost and labour_cost from price as those will remain as is - $m_cost = $m_cost - $myrow['labour_cost'] - $myrow['overhead_cost']; - } - */ - $qoh = get_qoh_on_date($stock_id); - $cost_adjust = false; - if ($qoh < 0) - { - if ($qoh + $qty >= 0) - $cost_adjust = true; - $qoh = 0; - } - if ($qoh + $qty != 0) - { - if ($qoh == 0) - $material_cost = $m_cost; - else - $material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty); - } - - if ($advanced && $cost_adjust) - adjust_deliveries($stock_id, $bom_cost, $date_); - - $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)." - WHERE stock_id=".db_escape($stock_id); - db_query($sql,"The cost details for the inventory item could not be updated"); -} /* Updates average material cost for item. @@ -164,124 +106,6 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date) db_query($sql,"The cost details for the inventory item could not be updated"); } -function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false) -{ - if ($qty != 0) - $costs /= $qty; - $sql = "SELECT overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = " - .db_escape($stock_id); - $result = db_query($sql); - $myrow = db_fetch($result); - $overhead_cost = $myrow['overhead_cost']; - $qoh = get_qoh_on_date($stock_id); - if ($qoh < 0) - $qoh = 0; - if ($adj_only) - { - if ($qoh>0) - { - if ($qoh + $qty != 0) - $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty); - elseif ($qty == 0) - $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh; - } - else // Journal Entry if QOH is 0/negative - { - global $Refs; - - $id = get_next_trans_no(ST_JOURNAL); - $ref = $Refs->get_next(ST_JOURNAL, null, $date_); - - $stock_gl_code = get_stock_gl_code($stock_id); - add_journal(ST_JOURNAL, $id, $costs, $date_, get_company_currency(), $ref); - $memo = "WO Overhead cost settlement JV for zero/negative respository of ".$stock_id; - //Reverse the inventory effect if $qoh <=0 - add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, - $stock_gl_code["inventory_account"], - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, - -$costs); - //GL Posting to inventory adjustment account - add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, - $stock_gl_code["assembly_account"], - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, - $costs); - - add_audit_trail(ST_JOURNAL, $id, $date_); - add_comments(ST_JOURNAL, $id, $date_, $memo); - $Refs->save(ST_JOURNAL, $id, $ref); - if ($qty != 0) - $overhead_cost = ($qoh * $overhead_cost + $costs) / $qty; - } - } - else - { - if ($qoh + $qty != 0) - $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty); - } - $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=".db_escape($overhead_cost)." - WHERE stock_id=".db_escape($stock_id); - db_query($sql,"The cost details for the inventory item could not be updated"); -} - -function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false) -{ - if ($qty != 0) - $costs /= $qty; - $sql = "SELECT labour_cost FROM ".TB_PREF."stock_master WHERE stock_id = " - .db_escape($stock_id); - $result = db_query($sql); - $myrow = db_fetch($result); - $labour_cost = $myrow['labour_cost']; - $qoh = get_qoh_on_date($stock_id); - if ($qoh < 0) - $qoh = 0; - if ($adj_only) - { - if ($qoh>0) - { - if ($qoh + $qty != 0) - $labour_cost = ($qoh * $labour_cost + $qty * $costs) / ($qoh + $qty); - elseif ($qty == 0) - $labour_cost = ($qoh * $labour_cost + $costs) / $qoh; - } - else // Journal Entry if QOH is 0/negative - { - global $Refs; - - $id = get_next_trans_no(ST_JOURNAL); - $ref = $Refs->get_next(ST_JOURNAL, null, $date_); - add_journal(ST_JOURNAL, $id, $costs, $date_, get_company_currency(), $ref); - - $stock_gl_code = get_stock_gl_code($stock_id); - $memo = "WO labour cost settlement JV for zero/negative respository of ".$stock_id; - //Reverse the inventory effect if $qoh <=0 - add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, - $stock_gl_code["inventory_account"], - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, - -$costs); - //GL Posting to inventory adjustment account - add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, - $stock_gl_code["assembly_account"], - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, - $costs); - - add_audit_trail(ST_JOURNAL, $id, $date_); - add_comments(ST_JOURNAL, $id, $date_, $memo); - $Refs->save(ST_JOURNAL, $id, $ref); - if ($qty != 0) - $labour_cost = ($qoh * $labour_cost + $costs) / $qty; - } - } - else - { - if ($qoh + $qty != 0) - $labour_cost = ($qoh * $labour_cost + $qty * $costs) / ($qoh + $qty); - } - $sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=".db_escape($labour_cost)." - WHERE stock_id=".db_escape($stock_id); - db_query($sql,"The cost details for the inventory item could not be updated"); -} - function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false) { if ($qty != 0) @@ -366,6 +190,17 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $db_acc, $da add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $db_acc, $dim1, $dim2, $wo_cost_types[$cost_type], $amount); + $wip = get_company_pref('wip_act'); + + if ($db_acc != $wip) + { + add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $db_acc, + 0, 0, $wo_cost_types[$cost_type], -$amount); + + add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $wip, + 0, 0, $wo_cost_types[$cost_type], $amount); + } + $Refs->save(ST_JOURNAL, $journal_id, $ref); add_wo_costing($wo_id, $cost_type, ST_JOURNAL, $journal_id); @@ -376,6 +211,39 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $db_acc, $da commit_transaction(); } +/* + Process component usage: generate and post stock move, update average component cost. +*/ +function work_order_production_gl($woid, $stock_id, $quantity, $date_, $rcv_no) +{ + $result = get_wo_requirements($woid); + + // credit all the components + $total_cost = 0; + while ($bom_item = db_fetch($result)) + { + + update_wo_requirement_issued($bom_item['id'], $bom_item["units_req"] * $quantity, $bom_item["ComponentCost"]); + + // insert a -ve stock move for each item + add_stock_move(ST_MANURECEIVE, $bom_item["stock_id"], $rcv_no, + $bom_item["loc_code"], $date_, "", -$bom_item["units_req"] * $quantity, $bom_item["ComponentCost"], 0); + + if (!is_service($bom_item["mb_flag"])) + $ivaccount = $bom_item["inventory_account"]; + else + $ivaccount = $bom_item["assembly_account"]; + + $memo = $date_.": ".$bom_item["units_req"] ." * ".$bom_item["description"]; + + $total_cost += add_gl_trans_std_cost(ST_MANURECEIVE, $rcv_no, $date_, $ivaccount, 0, 0, + $memo, -$bom_item["ComponentCost"] * $bom_item["units_req"] * $quantity); + } + + add_gl_trans_std_cost(ST_MANURECEIVE, $rcv_no, $date_, get_company_pref('wip_act'), + 0, 0, $memo, -$total_cost); +} + function void_wo_costing($wo_id) { $res = get_wo_costing($wo_id); diff --git a/manufacturing/includes/db/work_order_issues_db.inc b/manufacturing/includes/db/work_order_issues_db.inc index 4fe8b13d..b980781a 100644 --- a/manufacturing/includes/db/work_order_issues_db.inc +++ b/manufacturing/includes/db/work_order_issues_db.inc @@ -36,15 +36,13 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w foreach ($items as $item) { - if ($to_work_order) $item->quantity = -$item->quantity; - // Stamp the standard_cost - $standard_cost = get_standard_cost($item->stock_id); + $unit_cost = get_unit_cost($item->stock_id); // insert a -ve stock move for each item add_stock_move(ST_MANUISSUE, $item->stock_id, $number, - $location, $date_, $memo_, -$item->quantity, $standard_cost); + $location, $date_, $memo_, -$item->quantity, $unit_cost); $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued, unit_cost) SELECT ".db_escape($number).",".db_escape($item->stock_id).",".db_escape($item->quantity).", material_cost @@ -53,8 +51,8 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w db_query($sql,"A work order issue item could not be added"); - $standard_cost = get_standard_cost($item->stock_id); - $issue_cost = $standard_cost * $item->quantity; + $unit_cost = get_unit_cost($item->stock_id); + $issue_cost = $unit_cost * $item->quantity; $stockitem = get_item($item->stock_id); @@ -64,7 +62,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w else $ivaccount = $stockitem["assembly_account"]; - $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0, + $total_cost += add_gl_trans_std_cost(ST_MANUISSUE, $number, $date_, $ivaccount, 0, 0, $date_.": "._("Issue of")." ".$stockitem["description"], -$issue_cost); $issue_total += $issue_cost; } @@ -78,7 +76,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w if (!$wip_account) // backward compatibility $wip_account = $stockitem["inventory_account"]; - add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $wip_account, + add_gl_trans_std_cost(ST_MANUISSUE, $number, $date_, $wip_account, 0, 0, $date_.": "._("Issue to")." ".$stockitem["description"], -$total_cost); if ($memo_) diff --git a/manufacturing/includes/db/work_order_produce_items_db.inc b/manufacturing/includes/db/work_order_produce_items_db.inc index 9ce682b3..d4b3832e 100644 --- a/manufacturing/includes/db/work_order_produce_items_db.inc +++ b/manufacturing/includes/db/work_order_produce_items_db.inc @@ -9,14 +9,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo) +function work_order_produce($woid, $ref, $quantity, $date_, $memo, $close_wo) { global $Refs; +// FIXME: support for WO_UNASSEMBLY case begin_transaction(); $args = func_get_args(); - $args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo_','close_wo'), + $args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo','close_wo'), $args); $args->trans_no = 0; hook_db_prewrite($args, ST_MANURECEIVE); @@ -35,7 +36,7 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo) // ------------------------------------------------------------------------- // insert -ve and update averaged component unit cost for BOM usage (in wo_requirements) - work_order_receive_costs($woid, $product["stock_id"], $quantity, $date_, $id); + work_order_production_gl($woid, $product["stock_id"], $quantity, $date_, $id); // update wo quantity and close wo if requested (or finished) $closed = work_order_update_finished_quantity($woid, $quantity, $date_, $close_wo); @@ -70,19 +71,24 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo) $o_cost = get_gl_wo_cost($woid, WO_OVERHEAD); $l_cost += get_gl_wo_cost($woid, WO_LABOUR); - $unit_cost = ($o_cost+$m_cost+$l_cost)/($product['units_issued']+$quantity); + $total_cost = $o_cost + $m_cost + $l_cost; - update_material_cost($product['stock_id'], $product['units_issued']+$quantity, $unit_cost, $date_); - // FIXME: ? -// update_labour_cost(stock_id, qty, unit_cost); -// update_overheads_cost(stock_id, qty, unit_cost); + add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, get_company_pref('wip_act'), + 0, 0, $memo, -$total_cost); + + add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product['inventory_account'], + 0, 0, $memo, $total_cost); + + $unit_cost = $total_cost/($product['units_issued']+$quantity); add_stock_move(ST_WORKORDER, $product["stock_id"], $woid, $product["loc_code"], $date_, $ref, $product['units_issued']+$quantity, $unit_cost); + + update_material_cost($product['stock_id'], $product['units_issued']+$quantity, $unit_cost, $date_); } - if ($memo_) - add_comments(ST_MANURECEIVE, $id, $date_, $memo_); + if ($memo) + add_comments(ST_MANURECEIVE, $id, $date_, $memo); $Refs->save(ST_MANURECEIVE, $id, $ref); add_audit_trail(ST_MANURECEIVE, $id, $date_, _("Production.")); @@ -93,40 +99,6 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo) commit_transaction(); } -/* - Process component usage: generate and post stock move, update average component cost. -*/ -function work_order_receive_costs($woid, $stock_id, $quantity, $date_, $rcv_no) -{ - $result = get_wo_requirements($woid); - - // credit all the components - $total_cost = 0; - while ($bom_item = db_fetch($result)) - { - - $bom_cost = $bom_item["ComponentCost"] * $quantity; - - update_wo_requirement_issued($bom_item['id'], $bom_item["units_req"] * $quantity, $bom_item["ComponentCost"]); - - // insert a -ve stock move for each item - add_stock_move(ST_MANURECEIVE, $bom_item["stock_id"], $rcv_no, - $bom_item["loc_code"], $date_, "", -$bom_item["units_req"] * $quantity, $bom_item["ComponentCost"], 0); - - if (!is_service($bom_item["mb_flag"])) - $ivaccount = $bom_item["inventory_account"]; - else - $ivaccount = $bom_item["assembly_account"]; - - $memo = $date_.": ".$bom_item["units_req"] ." * ".$bom_item["description"]; - $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0, - $memo, -$bom_cost); - } - - add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, get_company_pref('wip_act'), - 0, 0, $memo, -$total_cost); -} - //-------------------------------------------------------------------------------------------- function get_work_order_produce($id) diff --git a/manufacturing/includes/db/work_order_requirements_db.inc b/manufacturing/includes/db/work_order_requirements_db.inc index 395ad653..6bb171c7 100644 --- a/manufacturing/includes/db/work_order_requirements_db.inc +++ b/manufacturing/includes/db/work_order_requirements_db.inc @@ -13,7 +13,7 @@ function get_wo_requirements($woid) { $sql = "SELECT req.*, item.description, item.mb_flag, loc.location_name, center.name AS WorkCentreDescription, - (item.material_cost+item.overhead_cost+item.labour_cost) as ComponentCost, + item.material_cost as ComponentCost, item.inventory_account, item.assembly_account FROM (".TB_PREF."wo_requirements req," diff --git a/manufacturing/includes/db/work_orders_db.inc b/manufacturing/includes/db/work_orders_db.inc index 8dcaaed3..11c9204f 100644 --- a/manufacturing/includes/db/work_orders_db.inc +++ b/manufacturing/includes/db/work_orders_db.inc @@ -14,36 +14,27 @@ */ function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc) -{ - if (!($type == WO_ADVANCED)) - return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc); - else - return add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc); -} - -/* - Advanced wrok order entry. -*/ -function add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id, - $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc) { global $Refs; begin_transaction(); $args = func_get_args(); $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id', - 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args); + 'type', 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args); + $args->woid = 0; hook_db_prewrite($args, ST_WORKORDER); + if ($type != WO_ADVANCED) + $required_by = $date_; + $date = date2sql($date_); $required = date2sql($required_by); - $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, stock_id, type, date_, required_by) VALUES (".db_escape($wo_ref).", ".db_escape($loc_code).", " .db_escape($units_reqd).", ".db_escape($stock_id).", - ".WO_ADVANCED.", '$date', ".db_escape($required).")"; + ".db_escape($type).", '$date', ".db_escape($required).")"; db_query($sql, "could not add work order"); $woid = db_insert_id(); @@ -56,6 +47,24 @@ function add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id, $args->woid = $woid; hook_db_postwrite($args, ST_WORKORDER); + if ($type != WO_ADVANCED) + { + $stockitem = get_item($stock_id); + release_work_order($woid, $date_, ''); + if ($costs != 0) + add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $stockitem["assembly_account"], + $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]); + if ($labour != 0) + add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $stockitem["assembly_account"], + $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]); + + if ($type == WO_UNASSEMBLY) + $units_reqd = -$units_reqd; + + $ref = $Refs->get_next(ST_MANURECEIVE, null, $date_); + work_order_produce($woid, $ref, $units_reqd, $date_, '', true); + } + commit_transaction(); return $woid; @@ -113,8 +122,10 @@ function delete_work_order($woid, $stock_id, $qty, $date) function get_work_order($woid, $allow_null=false) { $sql = "SELECT wo.*,st.description As StockItemName,l.location_name, - l.delivery_address,l.email, l.contact - FROM ".TB_PREF."workorders wo, ".TB_PREF."stock_master st, ".TB_PREF."locations l + l.delivery_address,l.email, l.contact, st.inventory_account, st.assembly_account + FROM ".TB_PREF."workorders wo, " + .TB_PREF."stock_master st, " + .TB_PREF."locations l WHERE st.stock_id=wo.stock_id AND l.loc_code=wo.loc_code AND wo.id=".db_escape($woid)." @@ -239,13 +250,8 @@ function void_work_order($woid) // restore average product costs $date = sql2date($work_order['date_']); $qty = $work_order['units_reqd']; - add_material_cost($work_order['stock_id'], -$qty, $date); // remove avg. cost for qty - $cost = get_gl_wo_cost($woid, WO_LABOUR); // get the labour cost and reduce avg cost - if ($cost != 0) - add_labour_cost($work_order['stock_id'], -$qty, $date, $cost); - $cost = get_gl_wo_cost($woid, WO_OVERHEAD); // get the overhead cost and reduce avg cost - if ($cost != 0) - add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost); + + // FIXME: update_material_cost // close workorder $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = " @@ -266,7 +272,8 @@ function void_work_order($woid) // void everything inside the work order : issues, productions, payments $date = sql2date($work_order['date_']); - add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty + // FIXME: update_material_cost + $result = get_work_order_productions($woid); // check the produced quantity $qty = 0; while ($row = db_fetch($result)) @@ -283,8 +290,8 @@ function void_work_order($woid) $issue_no = 0; while ($row = db_fetch($result)) { - $std_cost = get_standard_cost($row['stock_id']); - $icost = $std_cost * $row['qty_issued']; + $unit_cost = get_unit_cost($row['stock_id']); + $icost = $unit_cost * $row['qty_issued']; $cost += $icost; if ($issue_no == 0) $issue_no = $row['issue_no']; @@ -299,9 +306,6 @@ function void_work_order($woid) if ($cost != 0) add_issue_cost($work_order['stock_id'], -$qty, $date, $cost); - if ($cost != 0) - add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost); - $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = " .db_escape($woid); db_query($sql, "The work order couldn't be voided"); diff --git a/manufacturing/includes/db/work_orders_quick_db.inc b/manufacturing/includes/db/work_orders_quick_db.inc deleted file mode 100644 index 14570f18..00000000 --- a/manufacturing/includes/db/work_orders_quick_db.inc +++ /dev/null @@ -1,162 +0,0 @@ -. -***********************************************************************/ -/* - Quick work order entry, $type is either WO_ASSEMBLY, or WO_UNASSEMBLY - All changes in material and manufactured item stock are made during work order entry. -*/ -function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, - $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc) -{ - global $Refs; - - begin_transaction(); - $args = func_get_args(); - $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id', - 'type', 'date_', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args); - $args->woid = 0; - hook_db_prewrite($args, ST_WORKORDER); - - // if unassembling, reverse the stock movements - if ($type == WO_UNASSEMBLY) - $units_reqd = -$units_reqd; - - add_material_cost($stock_id, $units_reqd, $date_); - - $date = date2sql($date_); - if (!isset($costs) || ($costs == "")) - $costs = 0; - add_overhead_cost($stock_id, $units_reqd, $date_, $costs); - if (!isset($labour) || ($labour == "")) - $labour = 0; - add_labour_cost($stock_id, $units_reqd, $date_, $labour); - - $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, units_issued, stock_id, - type, additional_costs, date_, released_date, required_by, released, closed) - VALUES (".db_escape($wo_ref).", ".db_escape($loc_code).", ".db_escape($units_reqd) - .", ".db_escape($units_reqd).", ".db_escape($stock_id).", - ".db_escape($type).", ".db_escape($costs).", '$date', '$date', '$date', 1, 1)"; - db_query($sql, "could not add work order"); - - $woid = db_insert_id(); - - //-------------------------------------------------------------------------- - - // create Work Order Requirements based on the bom - $result = get_bom($stock_id); - - while ($bom_item = db_fetch($result)) - { - - $unit_quantity = $bom_item["quantity"]; - $item_quantity = $bom_item["quantity"] * $units_reqd; - - - $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, units_issued, loc_code) - VALUES ($woid, " . "'" . $bom_item["component"] . "'" . ", - '". $bom_item["workcentre_added"] . "', - $unit_quantity, $item_quantity, '" . $bom_item["loc_code"] . "')"; - - db_query($sql, "The work order requirements could not be added"); - - // insert a -ve stock move for each item - $UnitCost = get_standard_cost($bom_item["component"]); - add_stock_move(ST_WORKORDER, $bom_item["component"], $woid, - $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, $UnitCost, $UnitCost); - } - - // ------------------------------------------------------------------------- - //Negative Stock Handling - $qoh = get_qoh_on_date($stock_id); - $cost_adjust = false; - if ($qoh < 0) - { - if ($qoh + $units_reqd >= 0) - $cost_adjust = true; - } - - //Negative Stock Handling First; Prior to add_stock_move - if ($cost_adjust) - adjust_deliveries($stock_id, get_standard_cost($stock_id), $date_); - - // ------------------------------------------------------------------------- - - // insert a +ve stock move for the item being manufactured - add_stock_move(ST_WORKORDER, $stock_id, $woid, $loc_code, $date_, - $wo_ref, $units_reqd, 0); - - // ------------------------------------------------------------------------- - - work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $costs, $cr_acc, $labour, $cr_lab_acc); - - // ------------------------------------------------------------------------- - - add_comments(ST_WORKORDER, $woid, $date_, $memo_); - - $Refs->save(ST_WORKORDER, $woid, $wo_ref); - add_audit_trail(ST_WORKORDER, $woid, $date_,_("Quick production.")); - - $args->woid = $woid; - hook_db_postwrite($args, ST_WORKORDER); - - commit_transaction(); - return $woid; -} - -//-------------------------------------------------------------------------------------- - -function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $costs, $cr_acc, $labour, $cr_lab_acc) -{ - $result = get_bom($stock_id); - - // credit all the components - $total_cost = 0; - while ($bom_item = db_fetch($result)) - { - - $bom_accounts = get_stock_gl_code($bom_item["component"]); - - $bom_cost = $bom_item["ComponentCost"] * $units_reqd; // ?? * $bom_item["quantity"] - - $memo = $bom_item["quantity"] ." * ".$bom_item["description"]; - - if (!is_service($bom_accounts["mb_flag"])) - $ivaccount = $bom_accounts["inventory_account"]; - else - $ivaccount = $bom_accounts["assembly_account"]; - $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0, - $memo, -$bom_cost); - } - - $stockitem = get_item($stock_id); - // credit additional costs - if ($costs != 0.0) - { - add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $stockitem["assembly_account"], - $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]); - } - - if ($labour != 0.0) - { - add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $stockitem["assembly_account"], - $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]); - } - - // debit total components $total_cost - $memo = _("Produced")." ".$units_reqd. " * ".$stockitem["description"]; - - add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $stockitem["inventory_account"], - 0, 0, $memo, -$total_cost); - - $UnitWOCost = ($total_cost + $costs + $labour)/$units_reqd; - update_stock_move(ST_WORKORDER, $woid, $stock_id, $UnitWOCost); -} - diff --git a/manufacturing/includes/manufacturing_db.inc b/manufacturing/includes/manufacturing_db.inc index 16428eec..8df5b16b 100644 --- a/manufacturing/includes/manufacturing_db.inc +++ b/manufacturing/includes/manufacturing_db.inc @@ -13,7 +13,6 @@ include_once($path_to_root . "/includes/db/manufacturing_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_centres_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_orders_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_order_costing_db.inc"); -include_once($path_to_root . "/manufacturing/includes/db/work_orders_quick_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_order_issues_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_order_produce_items_db.inc"); include_once($path_to_root . "/manufacturing/includes/db/work_order_requirements_db.inc"); diff --git a/manufacturing/includes/manufacturing_ui.inc b/manufacturing/includes/manufacturing_ui.inc index 2d55477b..71997576 100644 --- a/manufacturing/includes/manufacturing_ui.inc +++ b/manufacturing/includes/manufacturing_ui.inc @@ -26,7 +26,7 @@ function display_bom($item_check) start_table(TABLESTYLE); $th = array(_("Component"), _("Description"), _("Work Centre"), - _("From Location"), _("Quantity"), _("Unit Cost"), _("Total Cost")); + _("From Location"), _("Quantity"), _("Unit Cost"), _("Cost")); table_header($th); @@ -45,19 +45,34 @@ function display_bom($item_check) label_cell($myrow["WorkCentreDescription"]); label_cell($myrow["location_name"]); qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"])); - amount_cell($myrow["standard_cost"]); + amount_cell($myrow["ProductCost"]); amount_cell($myrow["ComponentCost"]); end_row(); $total_cost += $myrow["ComponentCost"]; $j++; - If ($j == 12) + if ($j == 12) { $j = 1; table_header($th); - }//end of page full new headings if - }//end of while + } + } + $item = get_item($item_check); + if ($item['labour_cost'] != 0) + { + alt_table_row_color($k); + label_cells(_("Standard Labour Cost"), number_format2($item['labour_cost'],user_price_dec()), + "colspan=6 align=left", "class=odd_row nowrap align=right"); + end_row(); + } + if ($item['overhead_cost'] != 0) + { + alt_table_row_color($k); + label_cells(_("Standard Overhead Cost"), number_format2($item['overhead_cost'],user_price_dec()), + "colspan=6 align=left", "nowrap align=right"); + end_row(); + } label_row("" . _("Total Cost") . "", "" . number_format2($total_cost,user_price_dec()) ."", "colspan=6 align=right", "nowrap align=right"); end_table(); diff --git a/manufacturing/includes/work_order_issue_ui.inc b/manufacturing/includes/work_order_issue_ui.inc index 936685ab..066f80d6 100644 --- a/manufacturing/includes/work_order_issue_ui.inc +++ b/manufacturing/includes/work_order_issue_ui.inc @@ -116,7 +116,7 @@ function issue_edit_item_controls(&$order, $line_no=-1) $dec = $item_info["decimals"]; $_POST['qty'] = number_format2(0, $dec); - $std_cost = $item_info["standard_cost"]; + $std_cost = $item_info["material_cost"]; $_POST['units'] = $item_info["units"]; } diff --git a/manufacturing/view/wo_costs_view.php b/manufacturing/view/wo_costs_view.php index 6e139ec6..80ed02db 100644 --- a/manufacturing/view/wo_costs_view.php +++ b/manufacturing/view/wo_costs_view.php @@ -33,33 +33,54 @@ if ($_GET['trans_no'] != "") } //------------------------------------------------------------------------------------------------- - +function print_gl_rows($result, $title) +{ + global $systypes_array; + + if (db_num_rows($result)) + { + table_section_title($title, 7); + while($myrow = db_fetch($result)) { + start_row(); + label_cell(sql2date($myrow["tran_date"])); + label_cell(get_trans_view_str($myrow['type'],$myrow["type_no"], $systypes_array[$myrow['type']]. ' '.$myrow['type_no'])); + label_cell($myrow['account']); + label_cell($myrow['account_name']); + display_debit_or_credit_cells($myrow['amount']); + label_cell($myrow['memo_']); + end_row(); + } + } +} function display_wo_costs($prod_id) { - global $wo_cost_types; - - $costs = get_gl_wo_cost_trans($prod_id); - br(1); start_table(TABLESTYLE); - $th = array(_("Date"), _("Type"), _("Amount"), _("Memo"), ''); - table_header($th); - while($myrow = db_fetch($costs)) { - start_row(); - label_cell(sql2date($myrow["tran_date"])); - label_cell($wo_cost_types[$myrow["cost_type"]]); - amount_cell(-$myrow['amount']); - label_cell($myrow['memo_']); - label_cell(get_trans_view_str($myrow['trans_type'],$myrow["trans_no"])); - end_row(); - } + + $th = array(_("Date"), _("Transaction"), _("Account Code"), _("Account Name"), + _("Debit"), _("Credit"), _("Memo")); + + table_header($th); + + $productions = get_gl_wo_productions($prod_id, true); + print_gl_rows($productions, _("Finished Product Requirements")); + + $issues = get_gl_wo_issue_trans($prod_id, -1, true); + print_gl_rows($issues, _("Additional Material Issues")); + + $costs = get_gl_wo_cost_trans($prod_id, -1, true); + print_gl_rows($costs, _("Additional Costs")); + + $wo = get_gl_trans(ST_WORKORDER, $prod_id); + print_gl_rows($wo, _("Finished Product Receival")); end_table(1); } //------------------------------------------------------------------------------------------------- - display_heading(sprintf(_("Production Costs for Work Order # %d"), $wo_id)); +display_wo_details($wo_id, true); + display_wo_costs($wo_id); //------------------------------------------------------------------------------------------------- diff --git a/manufacturing/work_order_costs.php b/manufacturing/work_order_costs.php index 6bdb60e7..244c4a17 100644 --- a/manufacturing/work_order_costs.php +++ b/manufacturing/work_order_costs.php @@ -133,20 +133,23 @@ br(); date_row(_("Date:"), 'date_'); ref_row(_("Reference:"), 'ref', ''); -yesno_list_row(_("Type:"), 'PaymentType', null, $wo_cost_types[WO_OVERHEAD], $wo_cost_types[WO_LABOUR]); +yesno_list_row(_("Type:"), 'PaymentType', null, $wo_cost_types[WO_OVERHEAD], $wo_cost_types[WO_LABOUR], true); +if (list_updated('PaymentType')) + $Ajax->activate('costs'); -$item_accounts = get_stock_gl_code($wo_details['stock_id']); -$_POST['db_acc'] = $item_accounts['assembly_account']; +$item = get_item($wo_details['stock_id']); +$_POST['db_acc'] = $item['assembly_account']; $r = get_default_bank_account(get_company_pref('curr_default')); $_POST['cr_acc'] = $r[0]; +$_POST['costs'] = price_format(get_post('PaymentType')==WO_OVERHEAD ? $item['overhead_cost'] : $item['labour_cost']); amount_row(_("Additional Costs:"), 'costs'); gl_all_accounts_list_row(_("Debit Account"), 'db_acc', null); gl_all_accounts_list_row(_("Credit Account"), 'cr_acc', null); textarea_row(_("Memo:"), 'memo', null, 40, 5); end_table(1); -hidden('dim1', $item_accounts["dimension_id"]); -hidden('dim2', $item_accounts["dimension2_id"]); +hidden('dim1', $item["dimension_id"]); +hidden('dim2', $item["dimension2_id"]); submit_center('process', _("Process Additional Cost"), true, '', true); diff --git a/manufacturing/work_order_entry.php b/manufacturing/work_order_entry.php index cafdf211..6a47ad5a 100644 --- a/manufacturing/work_order_entry.php +++ b/manufacturing/work_order_entry.php @@ -343,7 +343,6 @@ if (isset($selected_id)) $_POST['date_'] = sql2date($myrow["date_"]); $_POST['RequDate'] = sql2date($myrow["required_by"]); $_POST['released_date'] = sql2date($myrow["released_date"]); - $_POST['memo_'] = ""; $_POST['units_issued'] = $myrow["units_issued"]; $_POST['Costs'] = price_format($myrow["additional_costs"]); @@ -362,6 +361,7 @@ if (isset($selected_id)) else { $_POST['units_issued'] = $_POST['released'] = 0; + ref_row(_("Reference:"), 'wo_ref', '', $Refs->get_next(ST_WORKORDER, null, get_post('date_')), false, ST_WORKORDER); wo_types_list_row(_("Type:"), 'type', null); @@ -405,20 +405,19 @@ else date_row(_("Date") . ":", 'date_', '', true); hidden('RequDate', ''); - $bank_act = get_default_bank_account(); - if (!isset($_POST['Labour'])) + if (!isset($_POST['Labour']) || list_updated('stock_id') || list_updated('type')) { - $_POST['Labour'] = price_format(0); + $bank_act = get_default_bank_account(); + $item = get_item(get_post('stock_id')); + $_POST['Labour'] = price_format(get_post('type') == WO_ASSEMBLY ? $item['labour_cost'] : 0); $_POST['cr_lab_acc'] = $bank_act['account_code']; + $_POST['Costs'] = price_format(get_post('type') == WO_ASSEMBLY ? $item['overhead_cost'] : 0); + $_POST['cr_acc'] = $bank_act['account_code']; + $Ajax->activate('_page_body'); } amount_row($wo_cost_types[WO_LABOUR], 'Labour'); gl_all_accounts_list_row(_("Credit Labour Account"), 'cr_lab_acc', null); - if (!isset($_POST['Costs'])) - { - $_POST['Costs'] = price_format(0); - $_POST['cr_acc'] = $bank_act['account_code']; - } amount_row($wo_cost_types[WO_OVERHEAD], 'Costs'); gl_all_accounts_list_row(_("Credit Overhead Account"), 'cr_acc', null); diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 90d84eb4..d5efafdb 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -41,18 +41,11 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, if (is_inventory_item($stock_id) && !$adj_only) handle_negative_inventory($stock_id, $qty, $price_in_home_currency, $date); - $sql = "SELECT mb_flag, material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id); + $sql = "SELECT mb_flag, material_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id); $result = db_query($sql); $myrow = db_fetch($result); $material_cost = $myrow['material_cost']; - //Price adjustment for manufactured item - if (!$adj_only && $myrow['mb_flag'] == 'M') - { - //reduce overhead_cost and labour_cost from price as those will remain as is - $price_in_home_currency = $price_in_home_currency - $myrow['labour_cost'] - $myrow['overhead_cost']; - } - $cost_adjust = false; $qoh = get_qoh_on_date($stock_id); @@ -132,7 +125,7 @@ function add_grn(&$po) { /*This must be the first receipt of goods against this line */ /*Need to get the standard cost as it is now so we can process GL jorunals later*/ - $order_line->standard_cost = get_standard_cost($order_line->stock_id); + $order_line->standard_cost = get_unit_cost($order_line->stock_id); } // Update the purchase data table add_or_update_purchase_data($po->supplier_id, $order_line->stock_id, $order_line->price, diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index 94f2f72f..89c4d94b 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -197,7 +197,7 @@ function add_direct_supp_trans($cart) foreach($cart->line_items as $key => $line) { $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id, $line->item_description, $line->receive_qty, 0, $line->receive_qty, - $line->price, $line->price, true, get_standard_cost($line->stock_id), ''); + $line->price, $line->price, true, get_unit_cost($line->stock_id), ''); $total += round2(($line->receive_qty * $line->price), user_price_dec()); } $inv->tax_overrides = $cart->tax_overrides; diff --git a/reporting/rep104.php b/reporting/rep104.php index 4246e8e0..c2dc63a3 100644 --- a/reporting/rep104.php +++ b/reporting/rep104.php @@ -33,7 +33,7 @@ print_price_listing(); function fetch_items($category=0) { $sql = "SELECT item.stock_id, item.description AS name, - item.material_cost+item.labour_cost+item.overhead_cost AS Standardcost, + item.material_cost AS Standardcost, item.category_id,item.units, category.description FROM ".TB_PREF."stock_master item, diff --git a/reporting/rep301.php b/reporting/rep301.php index 403e4b4b..30cc9ac9 100644 --- a/reporting/rep301.php +++ b/reporting/rep301.php @@ -105,8 +105,8 @@ function getTransactions($category, $location, $date) item.description, item.inactive, move.loc_code, SUM(move.qty) AS QtyOnHand, - item.material_cost + item.labour_cost + item.overhead_cost AS UnitCost, - SUM(move.qty) *(item.material_cost + item.labour_cost + item.overhead_cost) AS ItemTotal + item.material_cost AS UnitCost, + SUM(move.qty) * item.material_cost AS ItemTotal FROM " .TB_PREF."stock_master item," .TB_PREF."stock_category category," diff --git a/reporting/rep304.php b/reporting/rep304.php index 28297c58..971c7e20 100644 --- a/reporting/rep304.php +++ b/reporting/rep304.php @@ -45,7 +45,7 @@ function getTransactions($category, $location, $fromcust, $from, $to, $show_serv move.tran_date, SUM(-move.qty) AS qty, SUM(-move.qty*move.price) AS amt, - SUM(-IF(move.standard_cost <> 0, move.qty * move.standard_cost, move.qty *(item.material_cost + item.labour_cost + item.overhead_cost))) AS cost + SUM(-IF(move.standard_cost <> 0, move.qty * move.standard_cost, move.qty *item.material_cost)) AS cost FROM ".TB_PREF."stock_master item, ".TB_PREF."stock_category category, ".TB_PREF."debtor_trans trans, diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index b3598782..ec206552 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -181,7 +181,7 @@ function add_credit_movements_item(&$credit_note, &$credit_line, $credit_type, $price, $credited_invoice=0) { //Chaitanya : Stamp current cost in stock moves $credit_line does not fetch cost - $curr_std_cost = get_standard_cost($credit_line->stock_id); + $curr_std_cost = get_unit_cost($credit_line->stock_id); $reference = _("Return"); if ($credited_invoice) { @@ -210,12 +210,12 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, $total = 0; /* insert gl_trans to credit stock and debit cost of sales at standard cost*/ - $standard_cost = get_standard_cost($order_line->stock_id); - if ($standard_cost != 0) { + $unit_cost = get_unit_cost($order_line->stock_id); + if ($unit_cost != 0) { /*first the cost of sales entry*/ $total += add_gl_trans_std_cost(ST_CUSTCREDIT, $credit_no, $date_, $stock_gl_codes["cogs_account"], - $dim, $dim2, "", -($standard_cost * $order_line->qty_dispatched), + $dim, $dim2, "", -($unit_cost * $order_line->qty_dispatched), PT_CUSTOMER, $order->customer_id, "The cost of sales GL posting could not be inserted"); @@ -228,7 +228,7 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, } $total += add_gl_trans_std_cost(ST_CUSTCREDIT, $credit_no, $date_, $stock_entry_account, 0, 0, - "", ($standard_cost * $order_line->qty_dispatched), + "", ($unit_cost * $order_line->qty_dispatched), PT_CUSTOMER, $order->customer_id, "The stock side (or write off) of the cost of sales GL posting could not be inserted"); diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 6337ba7c..3f8ffc87 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -78,7 +78,7 @@ function write_sales_delivery(&$delivery,$bo_policy) $line_tax = get_full_price_for_item($delivery_line->stock_id, $delivery_line->price, 0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price; - $delivery_line->standard_cost = get_standard_cost($delivery_line->stock_id); + $delivery_line->standard_cost = get_unit_cost($delivery_line->stock_id); /* add delivery details for all lines */ write_customer_trans_detail_item(ST_CUSTDELIVERY, $delivery_no, $delivery_line->stock_id, diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 7f3257af..710a5300 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -285,7 +285,7 @@ function get_sales_order_details($order_no, $trans_type) { qty_sent as qty_done, item.units, item.mb_flag, - item.material_cost + item.labour_cost + item.overhead_cost AS standard_cost + item.material_cost FROM ".TB_PREF."sales_order_details line," .TB_PREF."stock_master item WHERE line.stk_code = item.stock_id @@ -340,7 +340,7 @@ function read_sales_order($order_no, &$order, $trans_type) { $order->add_to_cart($line_no,$myrow["stk_code"],$myrow["quantity"], $myrow["unit_price"], $myrow["discount_percent"], - $myrow["qty_done"], $myrow["standard_cost"], $myrow["description"], $myrow["id"] ); + $myrow["qty_done"], $myrow["material_cost"], $myrow["description"], $myrow["id"] ); $line_no++; } } diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 949ee79e..2177d2e7 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -47,7 +47,7 @@ function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $d function get_calculated_price($stock_id, $add_pct) { - $avg = get_standard_cost($stock_id); + $avg = get_unit_cost($stock_id); if ($avg == 0) return 0; return round2($avg * (1 + $add_pct / 100), user_price_dec()); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 48577693..3517196d 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -531,7 +531,7 @@ function check_item_data() return false; } - $cost_home = get_standard_cost(get_post('stock_id')); // Added 2011-03-27 Joe Hunt + $cost_home = get_unit_cost(get_post('stock_id')); // Added 2011-03-27 Joe Hunt $cost = $cost_home / get_exchange_rate_from_home_currency($_SESSION['Items']->customer_currency, $_SESSION['Items']->document_date); if (input_num('price') < $cost) { diff --git a/sql/alter2.4rc1.sql b/sql/alter2.4rc1.sql index b220d62a..a2f3e6f2 100644 --- a/sql/alter2.4rc1.sql +++ b/sql/alter2.4rc1.sql @@ -30,3 +30,4 @@ ALTER TABLE `0_wo_issue_items` ADD COLUMN `unit_cost` double NOT NULL default ' ALTER TABLE `0_wo_requirements` CHANGE COLUMN `std_cost` `unit_cost` double NOT NULL default '0'; ALTER TABLE `0_stock_master` DROP COLUMN `last_cost`; +UPDATE `0_stock_master` SET `material_cost`=`material_cost`+`labour_cost`+`overhead_cost`;