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);
18 $js .= get_js_date_picker();
19 page(_("Item Adjustments Note"), false, false, "", $js);
21 //-----------------------------------------------------------------------------------------------
23 check_db_has_costable_items(_("There are no inventory items defined in the system which can be adjusted (Purchased or Manufactured)."));
25 check_db_has_movement_types(_("There are no inventory movement types defined in the system. Please define at least one inventory adjustment type."));
27 //-----------------------------------------------------------------------------------------------
29 if (isset($_GET['AddedID']))
31 $trans_no = $_GET['AddedID'];
32 $trans_type = systypes::inventory_adjustment();
34 display_notification_centered(_("Items adjustment has been processed"));
35 display_note(get_trans_view_str($trans_type, $trans_no, _("View this adjustment")));
37 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Postings for this Adjustment")), 1, 0);
39 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Adjustment"));
41 display_footer_exit();
43 //--------------------------------------------------------------------------------------------------
45 function line_start_focus() {
48 $Ajax->activate('items_table');
49 set_focus('_stock_id_edit');
51 //--------------------------------------------------------------------------------------------------
55 $_SESSION['adj_items']->from_loc = $_POST['StockLocation'];
56 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
57 $_SESSION['adj_items']->transfer_type = $_POST['type'];
58 $_SESSION['adj_items']->increase = $_POST['Increase'];
59 $_SESSION['adj_items']->memo_ = $_POST['memo_'];
61 //--------------------------------------------------------------------------------------------------
63 function copy_from_st()
65 $_POST['StockLocation'] = $_SESSION['adj_items']->from_loc;
66 $_POST['AdjDate'] = $_SESSION['adj_items']->tran_date;
67 $_POST['type'] = $_SESSION['adj_items']->transfer_type;
68 $_POST['Increase'] = $_SESSION['adj_items']->increase;
69 $_POST['memo_'] = $_SESSION['adj_items']->memo_;
72 //-----------------------------------------------------------------------------------------------
74 function handle_new_order()
76 if (isset($_SESSION['adj_items']))
78 $_SESSION['adj_items']->clear_items();
79 unset ($_SESSION['adj_items']);
82 session_register("adj_items");
84 $_SESSION['adj_items'] = new items_cart;
85 $_POST['AdjDate'] = Today();
86 if (!is_date_in_fiscalyear($_POST['AdjDate']))
87 $_POST['AdjDate'] = end_fiscalyear();
88 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
91 //-----------------------------------------------------------------------------------------------
93 function can_process()
95 $adj = &$_SESSION['adj_items'];
97 if (count($adj->line_items) == 0) {
98 display_error(_("You must enter at least one non empty item line."));
99 set_focus('stock_id');
102 if (!references::is_valid($_POST['ref']))
104 display_error( _("You must enter a reference."));
109 if (!is_new_reference($_POST['ref'], systypes::inventory_adjustment()))
111 display_error( _("The entered reference is already in use."));
116 if (!is_date($_POST['AdjDate']))
118 display_error(_("The entered date for the adjustment is invalid."));
119 set_focus('AdjDate');
122 elseif (!is_date_in_fiscalyear($_POST['AdjDate']))
124 display_error(_("The entered date is not in fiscal year."));
125 set_focus('AdjDate');
128 $failed_item = $adj->check_qoh($_POST['StockLocation'], $_POST['AdjDate'], !$_POST['Increase']);
129 if ($failed_item >= 0)
131 $line = $adj->line_items[$failed_item];
132 display_error(_("The adjustment cannot be processed because an adjustment item would cause a negative inventory balance :") .
133 " " . $line->stock_id . " - " . $line->item_description);
134 $_POST['Edit'.$failed_item] = 1; // enter edit mode
135 unset($_POST['Process']);
142 //-------------------------------------------------------------------------------
144 if (isset($_POST['Process']) && can_process()){
146 $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items,
147 $_POST['StockLocation'], $_POST['AdjDate'], $_POST['type'], $_POST['Increase'],
148 $_POST['ref'], $_POST['memo_']);
150 $_SESSION['adj_items']->clear_items();
151 unset($_SESSION['adj_items']);
153 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
154 } /*end of process credit note */
156 //-----------------------------------------------------------------------------------------------
158 function check_item_data()
160 if (!check_num('qty',0))
162 display_error(_("The quantity entered is negative or invalid."));
167 if (!check_num('std_cost', 0))
169 display_error(_("The entered standard cost is negative or invalid."));
170 set_focus('std_cost');
177 //-----------------------------------------------------------------------------------------------
179 function handle_update_item()
181 if($_POST['UpdateItem'] != "" && check_item_data())
183 $id = $_POST['LineNo'];
184 $_SESSION['adj_items']->update_cart_item($id, input_num('qty'),
185 input_num('std_cost'));
190 //-----------------------------------------------------------------------------------------------
192 function handle_delete_item($id)
194 $_SESSION['adj_items']->remove_from_cart($id);
198 //-----------------------------------------------------------------------------------------------
200 function handle_new_item()
202 if (!check_item_data())
205 add_to_order($_SESSION['adj_items'], $_POST['stock_id'],
206 input_num('qty'), input_num('std_cost'));
210 //-----------------------------------------------------------------------------------------------
211 $id = find_submit('Delete');
213 handle_delete_item($id);
215 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem'])) {
220 if (isset($_POST['AddItem']))
223 if (isset($_POST['UpdateItem']))
224 handle_update_item();
226 if (isset($_POST['CancelItemChanges'])) {
229 //-----------------------------------------------------------------------------------------------
231 if (isset($_GET['NewAdjustment']) || !isset($_SESSION['adj_items']))
236 //-----------------------------------------------------------------------------------------------
237 start_form(false, true);
239 display_order_header($_SESSION['adj_items']);
241 start_table("$table_style width=70%", 10);
244 display_adjustment_items(_("Adjustment Items"), $_SESSION['adj_items']);
245 adjustment_options_controls();
250 submit_center_first('Update', _("Update"), '', true);
251 submit_center_last('Process', _("Process Transfer"), '', true);