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);
//--------------------------------------------------------------------------------
-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
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);
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);
//--------------------------------------------------------------------------------------
-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);
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");
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)
{
$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)
{
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
$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
$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);
$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');
$_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')
{
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");
$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"];
}
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.
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)
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);
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);
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
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);
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;
}
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_)
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-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);
// -------------------------------------------------------------------------
// 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);
$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."));
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)
{
$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,"
*/
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();
$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;
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)."
// 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 = "
// 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))
$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'];
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");
+++ /dev/null
-<?php
-/**********************************************************************
- Copyright (C) FrontAccounting, LLC.
- Released under the terms of the GNU General Public License, GPL,
- as published by the Free Software Foundation, either version 3
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-/*
- 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);
-}
-
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");
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);
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("<b>" . _("Total Cost") . "</b>", "<b>" . number_format2($total_cost,user_price_dec()) ."</b>",
"colspan=6 align=right", "nowrap align=right");
end_table();
$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"];
}
}
//-------------------------------------------------------------------------------------------------
-
+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);
//-------------------------------------------------------------------------------------------------
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);
$_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"]);
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);
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);
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);
{
/*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,
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;
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,
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,"
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,
$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) {
$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");
}
$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");
$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,
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
{
$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++;
}
}
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());
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)
{
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`;