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();
44 //--------------------------------------------------------------------------------------------------
48 $_SESSION['adj_items']->from_loc = $_POST['StockLocation'];
49 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
50 $_SESSION['adj_items']->transfer_type = $_POST['type'];
51 $_SESSION['adj_items']->increase = $_POST['Increase'];
52 $_SESSION['adj_items']->memo_ = $_POST['memo_'];
55 //--------------------------------------------------------------------------------------------------
57 function copy_from_st()
59 $_POST['StockLocation'] = $_SESSION['adj_items']->from_loc;
60 $_POST['AdjDate'] = $_SESSION['adj_items']->tran_date;
61 $_POST['type'] = $_SESSION['adj_items']->transfer_type;
62 $_POST['Increase'] = $_SESSION['adj_items']->increase;
63 $_POST['memo_'] = $_SESSION['adj_items']->memo_;
66 //-----------------------------------------------------------------------------------------------
68 function handle_new_order()
70 if (isset($_SESSION['adj_items']))
72 $_SESSION['adj_items']->clear_items();
73 unset ($_SESSION['adj_items']);
76 session_register("adj_items");
78 $_SESSION['adj_items'] = new items_cart;
79 $_POST['AdjDate'] = Today();
80 if (!is_date_in_fiscalyear($_POST['AdjDate']))
81 $_POST['AdjDate'] = end_fiscalyear();
82 $_SESSION['adj_items']->tran_date = $_POST['AdjDate'];
85 //-----------------------------------------------------------------------------------------------
87 function can_process()
89 if (!references::is_valid($_POST['ref']))
91 display_error( _("You must enter a reference."));
95 if (!is_new_reference($_POST['ref'], systypes::inventory_adjustment()))
97 display_error( _("The entered reference is already in use."));
101 if (!is_date($_POST['AdjDate']))
103 display_error(_("The entered date for the adjustment is invalid."));
106 elseif (!is_date_in_fiscalyear($_POST['AdjDate']))
108 display_error(_("The entered date is not in fiscal year."));
111 $failed_item = $_SESSION['adj_items']->check_qoh($_POST['StockLocation'], $_POST['AdjDate'], !$_POST['Increase']);
112 if ($failed_item != null)
114 display_error(_("The adjustment cannot be processed because an adjustment item would cause a negative inventory balance :") .
115 " " . $failed_item->stock_id . " - " . $failed_item->item_description);
122 //-------------------------------------------------------------------------------
124 if (isset($_POST['Process']) && can_process()){
126 $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items,
127 $_POST['StockLocation'], $_POST['AdjDate'], $_POST['type'], $_POST['Increase'],
128 $_POST['ref'], $_POST['memo_']);
130 $_SESSION['adj_items']->clear_items();
131 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."));
145 if (!check_num('std_cost', 0))
147 display_error(_("The entered standard cost is negative or invalid."));
154 //-----------------------------------------------------------------------------------------------
156 function handle_update_item()
158 if($_POST['UpdateItem'] != "" && check_item_data())
160 $_SESSION['adj_items']->update_cart_item($_POST['stock_id'],
161 input_num('qty'), input_num('std_cost'));
165 //-----------------------------------------------------------------------------------------------
167 function handle_delete_item()
169 $_SESSION['adj_items']->remove_from_cart($_GET['Delete']);
172 //-----------------------------------------------------------------------------------------------
174 function handle_new_item()
176 if (!check_item_data())
179 add_to_order($_SESSION['adj_items'], $_POST['stock_id'],
180 input_num('qty'), input_num('std_cost'));
183 //-----------------------------------------------------------------------------------------------
185 if (isset($_GET['Delete']) || isset($_GET['Edit']))
188 if (isset($_GET['Delete']))
189 handle_delete_item();
191 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem']))
194 if (isset($_POST['AddItem']))
197 if (isset($_POST['UpdateItem']))
198 handle_update_item();
200 //-----------------------------------------------------------------------------------------------
202 if (isset($_GET['NewAdjustment']) || !isset($_SESSION['adj_items']))
207 //-----------------------------------------------------------------------------------------------
209 start_form(false, true);
211 display_order_header($_SESSION['adj_items']);
213 start_table("$table_style width=70%", 10);
216 display_adjustment_items(_("Adjustment Items"), $_SESSION['adj_items']);
217 adjustment_options_controls();
224 submit_cells('Update', _("Update"));
225 if ($_SESSION['adj_items']->count_items() >= 1)
227 submit_cells('Process', _("Process Adjustment"));