Moving 2.0 development version to main trunk.
[fa-stable.git] / inventory / cost_update.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/session.inc");
6
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");
12
13 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
14 $js = "";
15 if ($use_popup_windows)
16         $js .= get_js_open_window(900, 500);
17 page(_("Inventory Item Cost Update"), false, false, "", $js);
18
19 //--------------------------------------------------------------------------------------
20
21 check_db_has_costable_items(_("There are no costable inventory items defined in the system (Purchased or manufactured items)."));
22
23 if (isset($_GET['stock_id']))
24 {
25         $_POST['stock_id'] = $_GET['stock_id'];
26 }
27
28 //--------------------------------------------------------------------------------------
29 if (isset($_POST['UpdateData']))
30 {
31
32         $old_cost = $_POST['OldMaterialCost'] + $_POST['OldLabourCost']
33             + $_POST['OldOverheadCost'];
34         $new_cost = input_num('material_cost') + input_num('labour_cost')
35              + input_num('overhead_cost');
36
37         $should_update = true;
38
39         if (!check_num('material_cost') || !check_num('labour_cost') ||
40                 !check_num('overhead_cost'))
41         {
42                 display_error( _("The entered cost is not numeric."));
43                 set_focus('material_cost');
44                 $should_update = false;
45         }
46         elseif ($old_cost == $new_cost)
47         {
48                 display_error( _("The new cost is the same as the old cost. Cost was not updated."));
49                 $should_update = false;
50         }
51
52         if ($should_update)
53         {
54                 $update_no = stock_cost_update($_POST['stock_id'], 
55                     input_num('material_cost'), input_num('labour_cost'), 
56                     input_num('overhead_cost'), $old_cost);
57
58         display_note(_("Cost has been updated."));
59
60         if ($update_no > 0)
61         {
62                 display_note(get_gl_view_str(systypes::cost_update(), $update_no, _("View the GL Journal Entries for this Cost Update")), 1, 0);
63         }
64         }
65 }
66
67 if (isset($_POST['_stock_id_update']))
68         $Ajax->activate('cost_table');
69 //-----------------------------------------------------------------------------------------
70
71 start_form(false, true);
72
73 if (!isset($_POST['stock_id']))
74         $_POST['stock_id'] = get_global_stock_item();
75
76 echo "<center>" . _("Item:"). "&nbsp;";
77 stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
78
79 echo "</center><hr>";
80 set_global_stock_item($_POST['stock_id']);
81
82 $sql = "SELECT description, units, material_cost, labour_cost,
83         overhead_cost, mb_flag
84         FROM ".TB_PREF."stock_master
85         WHERE stock_id='" . $_POST['stock_id'] . "'
86         GROUP BY description, units, material_cost, labour_cost, overhead_cost, mb_flag";
87 $result = db_query($sql);
88 check_db_error("The cost details for the item could not be retrieved", $sql);
89
90 $myrow = db_fetch($result);
91 div_start('cost_table');
92 hidden("OldMaterialCost", $myrow["material_cost"]);
93 hidden("OldLabourCost", $myrow["labour_cost"]);
94 hidden("OldOverheadCost", $myrow["overhead_cost"]);
95
96 start_table($table_style2);
97
98 $_POST['material_cost'] = price_format($myrow["material_cost"]);
99 $_POST['labour_cost'] = price_format($myrow["labour_cost"]);
100 $_POST['overhead_cost'] = price_format($myrow["overhead_cost"]);
101
102 amount_row(_("Standard Material Cost Per Unit"), "material_cost",
103         null, "class='tableheader2'");
104
105 if ($myrow["mb_flag"]=='M')
106 {
107         amount_row(_("Standard Labour Cost Per Unit"), "labour_cost",
108                 null, "class='tableheader2'");
109         amount_row(_("Standard Overhead Cost Per Unit"), "overhead_cost",
110                 null, "class='tableheader2'");
111 }
112 else
113 {
114         hidden("labour_cost", 0);
115         hidden("overhead_cost", 0);
116 }
117
118 end_table(1);
119 div_end();
120 submit_center('UpdateData', _("Update"));
121
122 end_form();
123 end_page();
124
125 ?>