! -> Note
$ -> Affected files
-06-Jun-2009
+
+08-Jun-2009
+! Changed Advanced Manufacturing payments to be more flexible and simpler. Removed from Payment.
+$ /gl/includes/db/gl_db_trans.inc
+ /gl/includes/ui/gl_bank_ui.inc
+ /includes/types.inc
+ /includes/ui/ui_lists.inc
+ /manufacturing/search_work_orders.php
+ /manufacturing/work_order_costs.php (new file)
+ /manufacturing/work_order_entry.php
# Overhead costs in Manufacturing/Assembling wasn't added to stock overhead cost
$ /manufacturing/work_order_add_finished.php
/manufacturing/work_order_issue.php
/manufacturing/work_order_release.php
+ /manufacturing/includes/manufacturing_ui.inc
/manufacturing/includes/db/work_orders_db.inc
/manufacturing/includes/db/work_orders_quick_db.inc
+ /manufacturing/view/work_order_view.php
05-Jun-2009 Joe Hunt
# Missing underscore in gettext string
//--------------------------------------------------------------------------------
+function get_gl_wo_cost_trans($trans_id, $person_id=-1)
+{
+ $sql = "SELECT ".TB_PREF."gl_trans.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."gl_trans, ".TB_PREF."chart_master
+ WHERE ".TB_PREF."chart_master.account_code=".TB_PREF."gl_trans.account
+ AND ".TB_PREF."gl_trans.type=".systypes::work_order()." AND ".TB_PREF."gl_trans.type_no=$trans_id
+ AND ".TB_PREF."gl_trans.person_type_id=".payment_person_types::WorkOrder();
+ if ($person_id != -1)
+ $sql .= " AND ".TB_PREF."gl_trans.person_id=$person_id";
+ $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);
text_row_ex($payment ?_("To the Order of:"):_("Name:"),
'person_id', 40, 50);
break;
- case payment_person_types::WorkOrder() :
- workorders_list_row(_("Work Order:"), 'person_id', null);
- break;
+ //case payment_person_types::WorkOrder() :
+ // workorders_list_row(_("Work Order:"), 'person_id', null);
+ // break;
case payment_person_types::supplier() :
supplier_list_row(_("Supplier:"), 'person_id', null, false, true);
break;
$acc = get_supplier_accounts($_POST['person_id']);
$_POST['code_id'] = $acc['payable_account'];
}
- elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
- $_POST['code_id'] = get_company_pref('default_assembly_act');
+ //elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
+ // $_POST['code_id'] = get_company_pref('default_assembly_act');
else {
$_POST['code_id'] =
get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
$qe = get_quick_entry($person_id);
return ($full?payment_person_types::type_name($type) . " ":"") . $qe["description"];
case payment_person_types::WorkOrder() :
- $wo = get_work_order($person_id);
- return ($full?payment_person_types::type_name($type) . " ":"") . $wo["wo_ref"];
+ global $wo_cost_types;
+ return $wo_cost_types[$person_id];
case payment_person_types::customer() :
return ($full?payment_person_types::type_name($type) . " ":"") . get_customer_name($person_id);
case payment_person_types::supplier() :
}
}
+define('WO_LABOUR', 0);
+define('WO_OVERHEAD', 1);
+
+$wo_cost_types = array(
+ WO_LABOUR => _("Labour Cost"),
+ WO_OVERHEAD => _("Overhead Cost"),
+);
+
$quick_actions = array(
'=' => _('Remainder'), // post current base amount to GL account
'a' => _('Amount'), // post amount to GL account
QE_SUPPINV => _("Supplier Invoice/Credit")
);
-
-
?>
\ No newline at end of file
{
if (payment_person_types::has_items($type['id']))
{
- $items[$type['id']] = $type['name'];
+ if ($type['id'] != payment_person_types::WorkOrder())
+ $items[$type['id']] = $type['name'];
}
}
// -------------------------------------------------------------------------
- work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, 0, true);
+ work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, true);
// -------------------------------------------------------------------------
if ($memo_)
db_query($sql,"The cost details for the inventory item could not be updated");
}
-function add_additional_cost($stock_id, $qty, $date_, $costs)
+function add_overhead_cost($stock_id, $qty, $date_, $costs)
{
if ($qty != 0)
$costs /= $qty;
db_query($sql,"The cost details for the inventory item could not be updated");
}
+function add_labour_cost($stock_id, $qty, $date_, $costs)
+{
+ if ($qty != 0)
+ $costs /= $qty;
+ $sql = "SELECT labour_cost FROM ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
+ $result = db_query($sql);
+ $myrow = db_fetch($result);
+ $labour_cost = $myrow['labour_cost'];
+ $qoh = get_qoh_on_date($stock_id, null, $date_);
+ if ($qoh + $qty <= 0)
+ $labour_cost = 0;
+ else
+ $labour_cost = ($qoh * $labour_cost + $qty * $costs) / ($qoh + $qty);
+ $sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=$labour_cost
+ WHERE stock_id='$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)
{
if ($qty != 0)
}
function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
- $type, $date_, $required_by, $costs, $memo_)
+ $type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
{
if (!($type == wo_types::advanced()))
- return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $costs, $memo_);
+ return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc);
begin_transaction();
function work_order_has_payments($woid)
{
- $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
+ $result = get_gl_wo_cost_trans($woid);
return (db_num_rows($result) != 0);
}
***********************************************************************/
//--------------------------------------------------------------------------------------
-function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $additional_costs, $memo_)
+function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
{
begin_transaction();
add_material_cost($stock_id, $units_reqd, $date_);
$date = date2sql($date_);
- if (!isset($additional_costs) || ($additional_costs == ""))
- $additional_costs = 0;
- if ($additional_costs != 0)
- add_additional_cost($stock_id, $units_reqd, $date_, $additional_costs);
+ if (!isset($costs) || ($costs == ""))
+ $costs = 0;
+ if ($costs != 0)
+ add_overhead_cost($stock_id, $units_reqd, $date_, $costs);
+ if (!isset($labour) || ($labour == ""))
+ $labour = 0;
+ if ($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).", $units_reqd, $units_reqd, '$stock_id',
- $type, $additional_costs, '$date', '$date', '$date', 1, 1)";
+ $type, $costs, '$date', '$date', '$date', 1, 1)";
db_query($sql, "could not add work order");
$woid = db_insert_id();
// -------------------------------------------------------------------------
- work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs);
+ work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, false, $costs, $cr_acc, $labour, $cr_lab_acc);
// -------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
-function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs, $advanced=false)
+function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced=false, $costs=0, $cr_acc="", $labour=0, $cr_lab_acc="")
{
+ global $wo_cost_types;
$result = get_bom($stock_id);
// credit all the components
$bom_accounts = get_stock_gl_code($bom_item["component"]);
- $bom_cost = $bom_item["standard_cost"] * $bom_item["quantity"] * $units_reqd;
+ $bom_cost = $bom_item["ComponentCost"] * $units_reqd;
if ($advanced)
{
{
// also take the additional issues
$res = get_additional_issues($woid);
+ $wo = get_work_order($woid);
$issue_total = 0;
while ($item = db_fetch($res))
{
$standard_cost = get_standard_cost($item['stock_id']);
- $issue_cost = $standard_cost * $item['qty_issued'];
+ $issue_cost = $standard_cost * $item['qty_issued'] * $units_reqd / $wo['units_reqd'];
$issue = get_stock_gl_code($item['stock_id']);
add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $issue["inventory_account"], 0, 0,
null, -$issue_cost);
}
add_issue_cost($stock_id, $units_reqd, $date_, $issue_total);
$total_cost += $issue_total;
- $pcost = 0; // fix bank payments as additional cost.
- $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
- while ($row = db_fetch($result))
- $pcost += -$row['amount'];
- if ($pcost != 0)
- add_additional_cost($stock_id, $units_reqd, $date_, $pcost);
+ $result = get_gl_wo_cost_trans($woid, WO_LABOUR);
+ $lcost = 0;
+ while ($row = db_fetch_row($result))
+ $lcost += -$row['amount'];
+ if ($lcost != 0)
+ add_labour_cost($stock_id, $units_reqd, $date_, $lcost * $units_reqd / $wo['units_reqd']);
+ $result = get_gl_wo_cost_trans($woid, WO_OVERHEAD);
+ $ocost = 0;
+ while ($row = db_fetch_row($result))
+ $ocost += -$row['amount'];
+ if ($ocost != 0)
+ add_overhead_cost($stock_id, $units_reqd, $date_, $ocost * $units_reqd / $wo['units_reqd']);
}
// credit additional costs
$item_accounts = get_stock_gl_code($stock_id);
- add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
- $item_accounts["dimension_id"], $item_accounts["dimension2_id"], null, -$additional_costs);
-
- // debit total components + additional
- $total_cost += $additional_costs;
+ if ($costs != 0.0)
+ {
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $cr_acc,
+ 0, 0, $wo_cost_types[WO_OVERHEAD], -$costs, payment_person_types::WorkOrder(), WO_OVERHEAD);
+ $is_bank_to = is_bank_account($cr_acc);
+ if ($is_bank_to)
+ {
+ add_bank_trans(systypes::work_order(), $woid, $is_bank_to, "",
+ $date_, -$costs, payment_person_types::WorkOrder(), WO_OVERHEAD, get_company_currency(),
+ "Cannot insert a destination bank transaction");
+ }
+
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
+ $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_OVERHEAD], $costs,
+ payment_person_types::WorkOrder(), WO_OVERHEAD);
+ }
+ if ($labour != 0.0)
+ {
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $cr_lab_acc,
+ 0, 0, $wo_cost_types[WO_LABOUR], -$labour, payment_person_types::WorkOrder(), WO_LABOUR);
+ $is_bank_to = is_bank_account($cr_lab_acc);
+ if ($is_bank_to)
+ {
+ add_bank_trans(systypes::work_order(), $woid, $is_bank_to, "",
+ $date_, -$labour, payment_person_types::WorkOrder(), WO_LABOUR, get_company_currency(),
+ "Cannot insert a destination bank transaction");
+ }
+
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
+ $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_LABOUR], $labour,
+ payment_person_types::WorkOrder(), WO_LABOUR);
+ }
+ // debit total components
+ //$total_cost += $additional_costs;
add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["inventory_account"],
0, 0, null, $total_cost);
}
function display_wo_payments($woid)
{
- global $path_to_root, $table_style;
+ global $path_to_root, $table_style, $wo_cost_types;
- $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
+ //$result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
+ $result = get_gl_wo_cost_trans($woid);
if (db_num_rows($result) == 0)
{
- display_note(_("There are no Payments for this Order."), 0, 1);
+ display_note(_("There are no additional costs for this Order."), 0, 1);
}
else
{
start_table($table_style);
- $th = array(_("#"), _("Reference"), _("Date"), _("Amount"));
+ $th = array(_("#"), _("Type"), _("Date"), _("Amount"));
table_header($th);
$k = 0; //row colour counter
-
+
while ($myrow = db_fetch($result))
{
alt_table_row_color($k);
- label_cell(get_trans_view_str(1, $myrow["trans_no"]));
- label_cell($myrow['ref']);
- label_cell(sql2date($myrow["trans_date"]));
+ label_cell(get_gl_view_str(systypes::work_order(), $myrow["type_no"], $myrow["type_no"]));
+ label_cell($wo_cost_types[$myrow['person_id']]);
+ $date = sql2date($myrow["tran_date"]);
+ label_cell($date);
amount_cell(-($myrow['amount']));
- label_cell($myrow['bank_curr_code']);
end_row();
}
function costs_link($row)
{
+/*
return $row["closed"] || !$row["released"] ? '' :
pager_link(_('Costs'),
"/gl/gl_bank.php?NewPayment=1&PayType="
.payment_person_types::WorkOrder(). "&PayPerson=" .$row["id"]);
+*/
+ return $row["closed"] || !$row["released"] ? '' :
+ pager_link(_('Costs'),
+ "/manufacturing/work_order_costs.php?trans_no=" .$row["id"]);
}
function view_gl_link($row)
display_heading2(_("Productions"));
display_wo_productions($woid);
echo "</td><td>";
- display_heading2(_("Payments"));
+ display_heading2(_("Additional Costs"));
+ display_wo_payments($woid);
+ echo "</td></tr></table>";
+ }
+ else
+ {
+ echo "<br><table cellspacing=7><tr valign=top><td>";
+ display_heading2(_("Additional Costs"));
display_wo_payments($woid);
echo "</td></tr></table>";
}
if (isset($_GET['AddedID']))
{
+ include_once($path_to_root . "/reporting/includes/reporting.inc");
+ $id = $_GET['AddedID'];
+ $stype = systypes::work_order();
display_notification(_("The manufacturing process has been entered."));
+
+ display_note(get_trans_view_str($stype, $id, _("View this Work Order")));
+
+ display_note(get_gl_view_str($stype, $id, _("View the GL Journal Entries for this Work Order")), 1);
+ $ar = array('PARAM_0' => $_GET['date'], 'PARAM_1' => $_GET['date'], 'PARAM_2' => $stype);
+ display_note(print_link(_("Print the GL Journal Entries for this Work Order"), 702, $ar), 1);
hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
$id = work_order_produce($_POST['selected_id'], $_POST['ref'], $_POST['quantity'],
$_POST['date_'], $_POST['memo_'], $close_wo);
- meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']."&date=".$_POST['date_']);
}
//-------------------------------------------------------------------------------------
$_POST['quantity'] = max($wo_details["units_reqd"] - $wo_details["units_issued"], 0);
}
-start_table();
+start_table($table_style2);
+br();
ref_row(_("Reference:"), 'ref', '', references::get_next(29));
include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(900, 500);
if ($use_date_picker)
$js .= get_js_date_picker();
page(_("Work Order Entry"), false, false, "", $js);
if (isset($_GET['AddedID']))
{
$id = $_GET['AddedID'];
+ $stype = systypes::work_order();
display_notification_centered(_("The work order been added."));
+ display_note(get_trans_view_str($stype, $id, _("View this Work Order")));
+
+ if ($_GET['type'] != wo_types::advanced())
+ {
+ include_once($path_to_root . "/reporting/includes/reporting.inc");
+ display_note(get_gl_view_str($stype, $id, _("View the GL Journal Entries for this Work Order")), 1);
+ $ar = array('PARAM_0' => $_GET['date'], 'PARAM_1' => $_GET['date'], 'PARAM_2' => $stype);
+ display_note(print_link(_("Print the GL Journal Entries for this Work Order"), 702, $ar), 1);
+ }
+
safe_exit();
}
hyperlink_no_params("", _("Enter a new work order"));
hyperlink_no_params("search_work_orders.php", _("Select an existing work order"));
- echo "<br>";
- end_form();
- end_page();
- exit;
+
+ display_footer_exit();
}
//-------------------------------------------------------------------------------------
if (!references::is_valid($_POST['wo_ref']))
{
display_error(_("You must enter a reference."));
- set_focus('wo_ref');
+ set_focus('wo_ref');
return false;
}
if (!is_new_reference($_POST['wo_ref'], systypes::work_order()))
{
display_error(_("The entered reference is already in use."));
- set_focus('wo_ref');
+ set_focus('wo_ref');
return false;
}
}
if (!has_bom($_POST['stock_id']))
{
display_error(_("The selected item to manufacture does not have a bom."));
- set_focus('stock_id');
+ set_focus('stock_id');
return false;
}
+ if ($_POST['Labour'] == "")
+ $_POST['Labour'] = price_format(0);
+ if (!check_num('Labour', 0))
+ {
+ display_error( _("The labour cost entered is invalid or less than zero."));
+ set_focus('Labour');
+ return false;
+ }
if ($_POST['Costs'] == "")
$_POST['Costs'] = price_format(0);
if (!check_num('Costs', 0))
{
display_error( _("The cost entered is invalid or less than zero."));
- set_focus('Costs');
+ set_focus('Costs');
return false;
}
{
display_error(_("The work order cannot be processed because there is an insufficient quantity for component:") .
" " . $bom_item["component"] . " - " . $bom_item["description"] . ". " . _("Location:") . " " . $bom_item["location_name"]);
- set_focus('quantity');
+ set_focus('quantity');
return false;
}
}
{
if (!is_date($_POST['RequDate']))
{
- set_focus('RequDate');
+ set_focus('RequDate');
display_error( _("The date entered is in an invalid format."));
return false;
}
if ($_POST['units_issued'] > input_num('quantity'))
{
- set_focus('quantity');
+ set_focus('quantity');
display_error(_("The quantity cannot be changed to be less than the quantity already manufactured for this order."));
return false;
}
$id = add_work_order($_POST['wo_ref'], $_POST['StockLocation'], input_num('quantity'),
$_POST['stock_id'], $_POST['type'], $_POST['date_'],
- $_POST['RequDate'], input_num('Costs'), $_POST['memo_']);
+ $_POST['RequDate'], $_POST['memo_'], input_num('Costs'), $_POST['cr_acc'], input_num('Labour'), $_POST['cr_lab_acc']);
- meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$id&type=".$_POST['type']."&date=".$_POST['date_']);
}
//-------------------------------------------------------------------------------------
date_row(_("Date") . ":", 'date_');
hidden('RequDate', '');
+ $sql = "SELECT DISTINCT account_code FROM ".TB_PREF."bank_accounts";
+ $rs = db_query($sql,"could not get bank accounts");
+ $r = db_fetch_row($rs);
+ if (!isset($_POST['Labour']))
+ {
+ $_POST['Labour'] = price_format(0);
+ $_POST['cr_lab_acc'] = $r[0];
+ }
+ 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);
-
- amount_row(_("Total Additional Costs:"), 'Costs');
+ $_POST['cr_acc'] = $r[0];
+ }
+ amount_row($wo_cost_types[WO_OVERHEAD], 'Costs');
+ gl_all_accounts_list_row(_("Credit Overhead Account"), 'cr_acc', null);
+
}
if ($_POST['released'])
{
display_notification(_("The work order issue has been entered."));
+ display_note(get_trans_view_str(systypes::work_order(), $_GET['AddedID'], _("View this Work Order")));
+
hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
display_footer_exit();
}
else
{
- meta_forward($_SERVER['PHP_SELF'], "AddedID=1");
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_SESSION['issue_items']->order_id);
}
} /*end of process credit note */
include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(800, 500);
if ($use_date_picker)
$js .= get_js_date_picker();
page(_("Work Order Release to Manufacturing"), false, false, "", $js);
display_notification(_("The work order has been released to manufacturing."));
+ display_note(get_trans_view_str(systypes::work_order(), $selected_id, _("View this Work Order")));
+
hyperlink_no_params("search_work_orders.php", _("Select another &work order"));
$Ajax->activate('_page_body');