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 //-----------------------------------------------------------------------------------------------
53 function handle_new_order()
55 if (isset($_SESSION['adj_items']))
57 $_SESSION['adj_items']->clear_items();
58 unset ($_SESSION['adj_items']);
61 session_register("adj_items");
63 $_SESSION['adj_items'] = new items_cart(systypes::inventory_adjustment());
64 $_POST['AdjDate'] = Today();
65 if (!is_date_in_fiscalyear($_POST['AdjDate']))
66 $_POST['AdjDate'] = end_fiscalyear();
67 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
70 //-----------------------------------------------------------------------------------------------
72 function can_process()
74 $adj = &$_SESSION['adj_items'];
76 if (count($adj->line_items) == 0) {
77 display_error(_("You must enter at least one non empty item line."));
78 set_focus('stock_id');
81 if (!references::is_valid($_POST['ref']))
83 display_error( _("You must enter a reference."));
88 if (!is_new_reference($_POST['ref'], systypes::inventory_adjustment()))
90 display_error( _("The entered reference is already in use."));
95 if (!is_date($_POST['AdjDate']))
97 display_error(_("The entered date for the adjustment is invalid."));
101 elseif (!is_date_in_fiscalyear($_POST['AdjDate']))
103 display_error(_("The entered date is not in fiscal year."));
104 set_focus('AdjDate');
107 $failed_item = $adj->check_qoh($_POST['StockLocation'], $_POST['AdjDate'], !$_POST['Increase']);
108 if ($failed_item >= 0)
110 $line = $adj->line_items[$failed_item];
111 display_error(_("The adjustment cannot be processed because an adjustment item would cause a negative inventory balance :") .
112 " " . $line->stock_id . " - " . $line->item_description);
113 $_POST['Edit'.$failed_item] = 1; // enter edit mode
114 unset($_POST['Process']);
121 //-------------------------------------------------------------------------------
123 if (isset($_POST['Process']) && can_process()){
125 $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items,
126 $_POST['StockLocation'], $_POST['AdjDate'], $_POST['type'], $_POST['Increase'],
127 $_POST['ref'], $_POST['memo_']);
129 $_SESSION['adj_items']->clear_items();
130 unset($_SESSION['adj_items']);
132 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
133 } /*end of process credit note */
135 //-----------------------------------------------------------------------------------------------
137 function check_item_data()
139 if (!check_num('qty',0))
141 display_error(_("The quantity entered is negative or invalid."));
146 if (!check_num('std_cost', 0))
148 display_error(_("The entered standard cost is negative or invalid."));
149 set_focus('std_cost');
156 //-----------------------------------------------------------------------------------------------
158 function handle_update_item()
160 if($_POST['UpdateItem'] != "" && check_item_data())
162 $id = $_POST['LineNo'];
163 $_SESSION['adj_items']->update_cart_item($id, input_num('qty'),
164 input_num('std_cost'));
169 //-----------------------------------------------------------------------------------------------
171 function handle_delete_item($id)
173 $_SESSION['adj_items']->remove_from_cart($id);
177 //-----------------------------------------------------------------------------------------------
179 function handle_new_item()
181 if (!check_item_data())
184 add_to_order($_SESSION['adj_items'], $_POST['stock_id'],
185 input_num('qty'), input_num('std_cost'));
189 //-----------------------------------------------------------------------------------------------
190 $id = find_submit('Delete');
192 handle_delete_item($id);
194 if (isset($_POST['AddItem']))
197 if (isset($_POST['UpdateItem']))
198 handle_update_item();
200 if (isset($_POST['CancelItemChanges'])) {
203 //-----------------------------------------------------------------------------------------------
205 if (isset($_GET['NewAdjustment']) || !isset($_SESSION['adj_items']))
210 //-----------------------------------------------------------------------------------------------
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();
224 submit_center_first('Update', _("Update"), '', null);
225 submit_center_last('Process', _("Process Adjustment"), '', true);