else
$memo_ = $_SESSION["wa_current_user"]->username . " - " . $memo_;
}
- if ($type != ST_WORKORDER && (!is_subledger_account($account) || $account==get_company_pref('grn_clearing_act')))
+ if (!is_subledger_account($account) || $account==get_company_pref('grn_clearing_act'))
$person_id = $person_type_id = null;
$sql = "INSERT INTO ".TB_PREF."gl_trans ( type, type_no, tran_date,
function get_gl_wo_cost_trans($trans_id, $cost_type=-1)
{
- $sql = "SELECT gl.*, chart.account_name FROM ".TB_PREF."gl_trans gl, ".TB_PREF."chart_master chart
- WHERE chart.account_code=gl.account AND gl.type=".ST_WORKORDER." AND gl.type_no=".db_escape($trans_id)."
- AND gl.person_type_id=".PT_WORKORDER;
- if ($cost_type!= -1)
- $sql .= " AND gl.person_id=".db_escape($cost_type);
+ $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
+ WHERE
+ costing.workorder_id=".db_escape($trans_id)
+ ." AND chart.account_code=gl.account
+ AND gl.type=costing.trans_type
+ AND gl.type_no=costing.trans_no";
+ if ($cost_type != -1)
+ $sql .= " AND costing.cost_type=".db_escape($cost_type);
$sql .= " AND amount < 0";
-
+
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 add_material_cost($stock_id, $qty, $date_, $advanced=false)
+function add_material_cost($stock_id, $qty, $date_, $advanced=false, $woid=0)
{
$m_cost = 0;
$result = get_bom($stock_id);
$m_cost += ($bom_item['quantity'] * $standard_cost);
}
$bom_cost = $m_cost;
-
+ // new 2015.10.15
+ // additilnal costs.
+ $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)
{
if ($qoh == 0)
- $material_cost += $m_cost;
+ $material_cost = $m_cost; // corrected 27.10.2014
else
$material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty);
}
$qoh = 0;
if ($adj_only)
{
- if ($qty != 0)
- $costs = $qty * $costs;
if ($qoh>0)
- $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
+ {
+ 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;
-$costs);
//GL Posting to inventory adjustment account
add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
- $stock_gl_code["adjustment_account"],
+ $stock_gl_code["assembly_account"],
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
$costs);
$qoh = 0;
if ($adj_only)
{
- if ($qty != 0)
- $costs = $qty * $costs;
if ($qoh>0)
- $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;
+ {
+ 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;
-$costs);
//GL Posting to inventory adjustment account
add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
- $stock_gl_code["adjustment_account"],
+ $stock_gl_code["assembly_account"],
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
$costs);
$qoh = 0;
if ($adj_only)
{
- if ($qty != 0)
- $costs = $qty * $costs;
if ($qoh>0)
- $material_cost = $costs / $qoh;
+ $material_cost = ($qoh * $material_cost + $costs) / $qoh;
else // Journal Entry if QOH is 0/negative
{
global $Refs;
-$costs);
//GL Posting to inventory adjustment account
add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
- $stock_gl_code["adjustment_account"],
+ $stock_gl_code["assembly_account"],
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
$costs);
else
{
if ($qoh + $qty != 0)
- $material_cost = ($qty * $costs) / ($qoh + $qty);
+ $material_cost = ($qoh * $material_cost + $qty * $costs) / ($qoh + $qty);
}
$sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+"
.db_escape($material_cost)
begin_transaction();
$journal_id = get_next_trans_no(ST_JOURNAL);
+
if (!$ref) $ref = $Refs->get_next(ST_JOURNAL, null, $date);
add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $cr_acc,
***********************************************************************/
//--------------------------------------------------------------------------------------
-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;
- // new 2015.10.15
- // additilnal costs.
- $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'] - $i_cost; // $i_cost was already added to material cost
- $m_cost += $i_cost;
- /* no, why will we do that?? Joe Hunt 2015.10.17
- 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) // 27.10.2014 apmuthu and dz.
- $material_cost = $m_cost;
- else
- $material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty);
- }
- if ($advanced && $cost_adjust) // new 2010-02-10
- 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");
-}
-
-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);
-
- $stock_gl_code = get_stock_gl_code($stock_id);
- $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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
- $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) // 27.10.2014 dz
- $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);
-
- $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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
- $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) // 27.10.2014 dz
- $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=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)
- $costs /= $qty;
- $sql = "SELECT 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'];
- $qoh = get_qoh_on_date($stock_id);
- if ($qoh < 0)
- $qoh = 0;
- if ($adj_only)
- {
- if ($qoh>0)
- $material_cost = ($qoh * $material_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);
-
- $stock_gl_code = get_stock_gl_code($stock_id);
- $memo = "WO Issue 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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
- $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) // 27.10.2014 dz
- $material_cost = $costs / $qty;
- }
- }
- else
- {
- if ($qoh + $qty != 0)
- $material_cost = ($qoh * $material_cost + $qty * $costs) / ($qoh + $qty);
- }
- $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");
-}
-
function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
$type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
{
function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced=0, $costs=0, $cr_acc="", $labour=0, $cr_lab_acc="")
{
- global $wo_cost_types;
+ //global $wo_cost_types;
$result = get_bom($stock_id);
// credit all the components
$item_accounts = get_stock_gl_code($stock_id);
if ($costs != 0.0)
{
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_acc,
- 0, 0, $wo_cost_types[WO_OVERHEAD], -$costs, PT_WORKORDER, WO_OVERHEAD);
- $is_bank_to = is_bank_account($cr_acc);
- if ($is_bank_to)
- {
- add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
- $date_, -$costs, PT_WORKORDER, WO_OVERHEAD, get_company_currency(),
- "Cannot insert a destination bank transaction");
- }
-
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
- $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_OVERHEAD], $costs,
- PT_WORKORDER, WO_OVERHEAD);
+ add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $item_accounts["assembly_account"],
+ $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
}
if ($labour != 0.0) // only for quick
{
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_lab_acc,
- 0, 0, $wo_cost_types[WO_LABOUR], -$labour, PT_WORKORDER, WO_LABOUR);
- $is_bank_to = is_bank_account($cr_lab_acc);
- if ($is_bank_to)
- {
- add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
- $date_, -$labour, PT_WORKORDER, WO_LABOUR, get_company_currency(),
- "Cannot insert a destination bank transaction");
- }
-
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
- $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_LABOUR], $labour,
- PT_WORKORDER, WO_LABOUR);
+ add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $item_accounts["assembly_account"],
+ $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
}
// debit total components $total_cost
$stockitem = get_item($stock_id);
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");
alt_table_row_color($k);
label_cell(get_gl_view_str( $myrow["type"], $myrow["type_no"], $myrow["type_no"]));
- label_cell($wo_cost_types[$myrow['person_id']]);
+ label_cell($wo_cost_types[$myrow['cost_type']]);
$date = sql2date($myrow["tran_date"]);
label_cell($date);
amount_cell(-($myrow['amount']));
//--------------------------------------------------------------------------------------------------
-function can_process()
+function can_process($wo_details)
{
- global $wo_details;
-
if (!check_num('costs', 0))
{
display_error(_("The amount entered is not a valid number or less then zero."));
//--------------------------------------------------------------------------------------------------
-if (isset($_POST['process']) && can_process() == true)
+if (isset($_POST['process']) && can_process($wo_details) == true)
{
$date = $_POST['date_'];
- begin_transaction();
- add_gl_trans_std_cost(ST_WORKORDER, $_POST['selected_id'], $_POST['date_'], $_POST['cr_acc'],
- 0, 0, $date.": ".$wo_cost_types[$_POST['PaymentType']], -input_num('costs'), PT_WORKORDER, $_POST['PaymentType']);
- $is_bank_to = is_bank_account($_POST['cr_acc']);
- if ($is_bank_to)
- {
- add_bank_trans(ST_WORKORDER, $_POST['selected_id'], $is_bank_to, "",
- $_POST['date_'], -input_num('costs'), PT_WORKORDER, $_POST['PaymentType'], get_company_currency(),
- "Cannot insert a destination bank transaction");
- }
+ $memo = $_POST['memo'];
+ $ref = $_POST['ref'];
+
+ add_wo_costs_journal($_POST['selected_id'], input_num('costs'), $_POST['PaymentType'],
+ $_POST['cr_acc'], $_POST['db_acc'], $date, $_POST['dim1'], $_POST['dim2'], $memo, $ref);
- add_gl_trans_std_cost(ST_WORKORDER, $_POST['selected_id'], $_POST['date_'], $_POST['db_acc'],
- $_POST['dim1'], $_POST['dim2'], $date.": ".$wo_cost_types[$_POST['PaymentType']], input_num('costs'), PT_WORKORDER,
- $_POST['PaymentType']);
-
- //Apply the costs to manfuctured stock item as adjustement
- $wo = get_work_order($_POST['selected_id']);
- if ($_POST['PaymentType'] == 0)
- add_labour_cost($wo['stock_id'], $wo['units_reqd'], $_POST['date_'], input_num('costs'), true);
- else
- add_overhead_cost($wo['stock_id'], $wo['units_reqd'], $_POST['date_'], input_num('costs'), true);
-
- commit_transaction();
meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']);
}