5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/includes/banking.inc");
10 include_once($path_to_root . "/includes/manufacturing.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(900, 500);
17 page(_("Inventory Item Cost Update"), false, false, "", $js);
19 //--------------------------------------------------------------------------------------
21 check_db_has_costable_items(_("There are no costable inventory items defined in the system (Purchased or manufactured items)."));
23 if (isset($_GET['stock_id']))
25 $_POST['stock_id'] = $_GET['stock_id'];
28 //--------------------------------------------------------------------------------------
30 if (isset($_POST['UpdateData']))
33 $old_cost = $_POST['OldMaterialCost'] + $_POST['OldLabourCost'] + $_POST['OldOverheadCost'];
34 $new_cost = $_POST['material_cost'] + $_POST['labour_cost'] + $_POST['overhead_cost'];
36 $should_update = true;
38 if (!is_numeric($_POST['material_cost']) || !is_numeric($_POST['labour_cost']) ||
39 !is_numeric($_POST['overhead_cost']))
41 display_error( _("The entered cost is not numeric."));
42 $should_update = false;
44 elseif ($old_cost == $new_cost)
46 display_error( _("The new cost is the same as the old cost. Cost was not updated."));
47 $should_update = false;
52 $update_no = stock_cost_update($_POST['stock_id'], $_POST['material_cost'],
53 $_POST['labour_cost'], $_POST['overhead_cost'], $old_cost);
55 display_note(_("Cost has been updated."));
59 display_note(get_gl_view_str(systypes::cost_update(), $update_no, _("View the GL Journal Entries for this Cost Update")), 1, 0);
64 //-----------------------------------------------------------------------------------------
66 start_form(false, true);
68 if (!isset($_POST['stock_id']))
69 $_POST['stock_id'] = get_global_stock_item();
71 echo "<center>" . _("Item:"). " ";
72 stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
75 set_global_stock_item($_POST['stock_id']);
77 $sql = "SELECT description, units, last_cost, actual_cost, material_cost, labour_cost,
78 overhead_cost, mb_flag
79 FROM ".TB_PREF."stock_master
80 WHERE stock_id='" . $_POST['stock_id'] . "'
81 GROUP BY description, units, last_cost, actual_cost, material_cost, labour_cost, overhead_cost, mb_flag";
82 $result = db_query($sql);
83 check_db_error("The cost details for the item could not be retrieved", $sql);
85 $myrow = db_fetch($result);
87 hidden("OldMaterialCost", $myrow["material_cost"]);
88 hidden("OldLabourCost", $myrow["labour_cost"]);
89 hidden("OldOverheadCost", $myrow["overhead_cost"]);
91 start_table($table_style2);
92 label_row(_("Last Cost"), number_format2($myrow["last_cost"],user_price_dec()),
93 "class='tableheader2'", "nowrap align=right");
95 text_row(_("Standard Material Cost Per Unit"), "material_cost",
96 number_format($myrow["material_cost"],user_price_dec()), "", "", "class='tableheader2'");
98 if ($myrow["mb_flag"]=='M')
100 text_row(_("Standard Labour Cost Per Unit"), "labour_cost",
101 number_format($myrow["labour_cost"],user_price_dec()), "", "", "class='tableheader2'");
102 text_row(_("Standard Overhead Cost Per Unit"), "overhead_cost",
103 number_format($myrow["overhead_cost"],user_price_dec()), "", "", "class='tableheader2'");
107 hidden("labour_cost", 0);
108 hidden("overhead_cost", 0);
112 submit_center('UpdateData', _("Update"));