Some more fixes related to ajax combos behaviour and usage
[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
30 if (isset($_POST['UpdateData']))
31 {
32
33         $old_cost = $_POST['OldMaterialCost'] + $_POST['OldLabourCost']
34             + $_POST['OldOverheadCost'];
35         $new_cost = input_num('material_cost') + input_num('labour_cost')
36              + input_num('overhead_cost');
37
38         $should_update = true;
39
40         if (!check_num('material_cost') || !check_num('labour_cost') ||
41                 !check_num('overhead_cost'))
42         {
43                 display_error( _("The entered cost is not numeric."));
44                 set_focus('material_cost');
45                 $should_update = false;
46         }
47         elseif ($old_cost == $new_cost)
48         {
49                 display_error( _("The new cost is the same as the old cost. Cost was not updated."));
50                 $should_update = false;
51         }
52
53         if ($should_update)
54         {
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);
58
59         display_note(_("Cost has been updated."));
60
61         if ($update_no > 0)
62         {
63                 display_note(get_gl_view_str(systypes::cost_update(), $update_no, _("View the GL Journal Entries for this Cost Update")), 1, 0);
64         }
65         }
66 }
67
68 if (isset($_POST['_stock_id_update']))
69         $Ajax->activate('cost_table');
70 //-----------------------------------------------------------------------------------------
71
72 start_form(false, true);
73
74 if (!isset($_POST['stock_id']))
75         $_POST['stock_id'] = get_global_stock_item();
76
77 echo "<center>" . _("Item:"). "&nbsp;";
78 stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
79
80 echo "</center><hr>";
81 set_global_stock_item($_POST['stock_id']);
82
83 $sql = "SELECT description, units, last_cost, actual_cost, material_cost, labour_cost,
84         overhead_cost, mb_flag
85         FROM ".TB_PREF."stock_master
86         WHERE stock_id='" . $_POST['stock_id'] . "'
87         GROUP BY description, units, last_cost, actual_cost, material_cost, labour_cost, overhead_cost, mb_flag";
88 $result = db_query($sql);
89 check_db_error("The cost details for the item could not be retrieved", $sql);
90
91 $myrow = db_fetch($result);
92 div_start('cost_table');
93 hidden("OldMaterialCost", $myrow["material_cost"]);
94 hidden("OldLabourCost", $myrow["labour_cost"]);
95 hidden("OldOverheadCost", $myrow["overhead_cost"]);
96
97 start_table($table_style2);
98 label_row(_("Last Cost"), price_format($myrow["last_cost"]),
99         "class='tableheader2'", "nowrap align=right");
100
101 amount_row(_("Standard Material Cost Per Unit"), "material_cost",
102         price_format($myrow["material_cost"]), "class='tableheader2'");
103
104 if ($myrow["mb_flag"]=='M')
105 {
106         amount_row(_("Standard Labour Cost Per Unit"), "labour_cost",
107                 price_format($myrow["labour_cost"]), "class='tableheader2'");
108         amount_row(_("Standard Overhead Cost Per Unit"), "overhead_cost",
109                 price_format($myrow["overhead_cost"]), "class='tableheader2'");
110 }
111 else
112 {
113         hidden("labour_cost", 0);
114         hidden("overhead_cost", 0);
115 }
116
117 end_table(1);
118 div_end();
119 submit_center('UpdateData', _("Update"));
120
121 end_form();
122 end_page();
123
124 ?>