5 include_once($path_to_root . "/includes/ui/items_cart.inc");
7 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/inventory/includes/item_adjustments_ui.inc");
13 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(800, 500);
17 page(_("Item Adjustments Note"), false, false, "", $js);
19 //-----------------------------------------------------------------------------------------------
21 check_db_has_costable_items(_("There are no inventory items defined in the system which can be adjusted (Purchased or Manufactured)."));
23 check_db_has_movement_types(_("There are no inventory movement types defined in the system. Please define at least one inventory adjustment type."));
25 //-----------------------------------------------------------------------------------------------
27 if (isset($_GET['AddedID']))
29 $trans_no = $_GET['AddedID'];
30 $trans_type = systypes::inventory_adjustment();
32 display_notification_centered(_("Items adjustment has been processed"));
33 display_note(get_trans_view_str($trans_type, $trans_no, _("View this adjustment")));
35 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Adjustment")), 1, 0);
37 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Adjustment"));
39 display_footer_exit();
42 //--------------------------------------------------------------------------------------------------
46 $_SESSION['adj_items']->from_loc = $_POST['StockLocation'];
47 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
48 $_SESSION['adj_items']->transfer_type = $_POST['type'];
49 $_SESSION['adj_items']->increase = $_POST['Increase'];
50 $_SESSION['adj_items']->memo_ = $_POST['memo_'];
53 //--------------------------------------------------------------------------------------------------
55 function copy_from_st()
57 $_POST['StockLocation'] = $_SESSION['adj_items']->from_loc;
58 $_POST['AdjDate'] = $_SESSION['adj_items']->tran_date;
59 $_POST['type'] = $_SESSION['adj_items']->transfer_type;
60 $_POST['Increase'] = $_SESSION['adj_items']->increase;
61 $_POST['memo_'] = $_SESSION['adj_items']->memo_;
64 //-----------------------------------------------------------------------------------------------
66 function handle_new_order()
68 if (isset($_SESSION['adj_items']))
70 $_SESSION['adj_items']->clear_items();
71 unset ($_SESSION['adj_items']);
74 session_register("adj_items");
76 $_SESSION['adj_items'] = new items_cart;
77 $_POST['AdjDate'] = Today();
78 if (!is_date_in_fiscalyear($_POST['AdjDate']))
79 $_POST['AdjDate'] = end_fiscalyear();
80 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
83 //-----------------------------------------------------------------------------------------------
85 function can_process()
87 if (!references::is_valid($_POST['ref']))
89 display_error( _("You must enter a reference."));
93 if (!is_new_reference($_POST['ref'], systypes::inventory_adjustment()))
95 display_error( _("The entered reference is already in use."));
99 if (!is_date($_POST['AdjDate']))
101 display_error(_("The entered date for the adjustment is invalid."));
104 elseif (!is_date_in_fiscalyear($_POST['AdjDate']))
106 display_error(_("The entered date is not in fiscal year."));
109 $failed_item = $_SESSION['adj_items']->check_qoh($_POST['StockLocation'], $_POST['AdjDate'], !$_POST['Increase']);
110 if ($failed_item != null)
112 display_error(_("The adjustment cannot be processed because an adjustment item would cause a negative inventory balance :") .
113 " " . $failed_item->stock_id . " - " . $failed_item->item_description);
120 //-------------------------------------------------------------------------------
122 if (isset($_POST['Process']) && can_process()){
124 $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items,
125 $_POST['StockLocation'], $_POST['AdjDate'], $_POST['type'], $_POST['Increase'],
126 $_POST['ref'], $_POST['memo_']);
128 $_SESSION['adj_items']->clear_items();
129 unset($_SESSION['adj_items']);
130 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
131 } /*end of process credit note */
133 //-----------------------------------------------------------------------------------------------
135 function check_item_data()
137 if (!is_numeric($_POST['qty']))
139 display_error(_("The quantity entered is not a valid number."));
143 if ($_POST['qty'] <= 0)
145 display_error(_("The quantity entered must be greater than zero."));
149 if (!is_numeric($_POST['std_cost']) || $_POST['std_cost'] < 0)
151 display_error(_("The entered standard cost is negative or invalid."));
158 //-----------------------------------------------------------------------------------------------
160 function handle_update_item()
162 if($_POST['UpdateItem'] != "" && check_item_data())
164 $_SESSION['adj_items']->update_cart_item($_POST['stock_id'], $_POST['qty'], $_POST['std_cost']);
168 //-----------------------------------------------------------------------------------------------
170 function handle_delete_item()
172 $_SESSION['adj_items']->remove_from_cart($_GET['Delete']);
175 //-----------------------------------------------------------------------------------------------
177 function handle_new_item()
179 if (!check_item_data())
182 add_to_order($_SESSION['adj_items'], $_POST['stock_id'], $_POST['qty'], $_POST['std_cost']);
185 //-----------------------------------------------------------------------------------------------
187 if (isset($_GET['Delete']) || isset($_GET['Edit']))
190 if (isset($_GET['Delete']))
191 handle_delete_item();
193 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem']))
196 if (isset($_POST['AddItem']))
199 if (isset($_POST['UpdateItem']))
200 handle_update_item();
202 //-----------------------------------------------------------------------------------------------
204 if (isset($_GET['NewAdjustment']) || !isset($_SESSION['adj_items']))
209 //-----------------------------------------------------------------------------------------------
211 start_form(false, true);
213 display_order_header($_SESSION['adj_items']);
215 start_table("$table_style width=70%", 10);
218 display_adjustment_items(_("Adjustment Items"), $_SESSION['adj_items']);
219 adjustment_options_controls();
226 submit_cells('Update', _("Update"));
227 if ($_SESSION['adj_items']->count_items() >= 1)
229 submit_cells('Process', _("Process Adjustment"));