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 = input_num('OldMaterialCost') + input_num('OldLabourCost')
34 + input_num('OldOverheadCost');
35 $new_cost = input_num('material_cost') + input_num('labour_cost')
36 + input_num('overhead_cost');
38 $should_update = true;
40 if (!check_num('material_cost') || !check_num('labour_cost') ||
41 !check_num('overhead_cost'))
43 display_error( _("The entered cost is not numeric."));
44 set_focus('material_cost');
45 $should_update = false;
47 elseif ($old_cost == $new_cost)
49 display_error( _("The new cost is the same as the old cost. Cost was not updated."));
50 $should_update = false;
55 $update_no = stock_cost_update($_POST['stock_id'],
56 input_num('material_cost'), input_num('labour_cost'),
57 input_num('overhead_cost'), $old_cost);
59 display_note(_("Cost has been updated."));
63 display_note(get_gl_view_str(systypes::cost_update(), $update_no, _("View the GL Journal Entries for this Cost Update")), 1, 0);
68 //-----------------------------------------------------------------------------------------
70 start_form(false, true);
72 if (!isset($_POST['stock_id']))
73 $_POST['stock_id'] = get_global_stock_item();
75 echo "<center>" . _("Item:"). " ";
76 stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
79 set_global_stock_item($_POST['stock_id']);
81 $sql = "SELECT description, units, last_cost, actual_cost, material_cost, labour_cost,
82 overhead_cost, mb_flag
83 FROM ".TB_PREF."stock_master
84 WHERE stock_id='" . $_POST['stock_id'] . "'
85 GROUP BY description, units, last_cost, actual_cost, material_cost, labour_cost, overhead_cost, mb_flag";
86 $result = db_query($sql);
87 check_db_error("The cost details for the item could not be retrieved", $sql);
89 $myrow = db_fetch($result);
91 hidden("OldMaterialCost", $myrow["material_cost"]);
92 hidden("OldLabourCost", $myrow["labour_cost"]);
93 hidden("OldOverheadCost", $myrow["overhead_cost"]);
95 start_table($table_style2);
96 label_row(_("Last Cost"), price_format($myrow["last_cost"]),
97 "class='tableheader2'", "nowrap align=right");
99 amount_row(_("Standard Material Cost Per Unit"), "material_cost",
100 price_format($myrow["material_cost"]), "", "", "class='tableheader2'");
102 if ($myrow["mb_flag"]=='M')
104 amount_row(_("Standard Labour Cost Per Unit"), "labour_cost",
105 price_format($myrow["labour_cost"]), '', "", "class='tableheader2'");
106 amount_row(_("Standard Overhead Cost Per Unit"), "overhead_cost",
107 price_format($myrow["overhead_cost"]), "", "", "class='tableheader2'");
111 hidden("labour_cost", 0);
112 hidden("overhead_cost", 0);
116 submit_center('UpdateData', _("Update"));