2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_LOCATIONTRANSFER';
14 include_once($path_to_root . "/includes/ui/items_cart.inc");
16 include_once($path_to_root . "/includes/session.inc");
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/inventory/includes/stock_transfers_ui.inc");
22 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
24 if ($SysPrefs->use_popup_windows)
25 $js .= get_js_open_window(800, 500);
26 if (user_use_date_picker())
27 $js .= get_js_date_picker();
29 if (isset($_GET['NewTransfer'])) {
30 if (isset($_GET['FixedAsset'])) {
31 $page_security = 'SA_ASSETTRANSFER';
32 $_SESSION['page_title'] = _($help_context = "Fixed Assets Location Transfers");
35 $_SESSION['page_title'] = _($help_context = "Inventory Location Transfers");
38 page($_SESSION['page_title'], false, false, "", $js);
40 //-----------------------------------------------------------------------------------------------
42 check_db_has_costable_items(_("There are no inventory items defined in the system (Purchased or manufactured items)."));
44 //-----------------------------------------------------------------------------------------------
46 if (isset($_GET['AddedID']))
48 $trans_no = $_GET['AddedID'];
49 $trans_type = ST_LOCTRANSFER;
51 display_notification_centered(_("Inventory transfer has been processed"));
52 display_note(get_trans_view_str($trans_type, $trans_no, _("&View this transfer")));
54 $itm = db_fetch(get_stock_transfer_items($_GET['AddedID']));
56 if (is_fixed_asset($itm['mb_flag']))
57 hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Fixed Assets Transfer"), "NewTransfer=1&FixedAsset=1");
59 hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Inventory Transfer"), "NewTransfer=1");
61 display_footer_exit();
63 //--------------------------------------------------------------------------------------------------
65 function line_start_focus() {
68 $Ajax->activate('items_table');
69 set_focus('_stock_id_edit');
71 //-----------------------------------------------------------------------------------------------
73 function handle_new_order()
75 if (isset($_SESSION['transfer_items']))
77 $_SESSION['transfer_items']->clear_items();
78 unset ($_SESSION['transfer_items']);
81 $_SESSION['transfer_items'] = new items_cart(ST_LOCTRANSFER);
82 $_SESSION['transfer_items']->fixed_asset = isset($_GET['FixedAsset']);
83 $_POST['AdjDate'] = new_doc_date();
84 if (!is_date_in_fiscalyear($_POST['AdjDate']))
85 $_POST['AdjDate'] = end_fiscalyear();
86 $_SESSION['transfer_items']->tran_date = $_POST['AdjDate'];
89 //-----------------------------------------------------------------------------------------------
91 if (isset($_POST['Process']))
94 $tr = &$_SESSION['transfer_items'];
97 if (count($tr->line_items) == 0) {
98 display_error(_("You must enter at least one non empty item line."));
99 set_focus('stock_id');
102 if (!check_reference($_POST['ref'], ST_LOCTRANSFER))
107 elseif (!is_date($_POST['AdjDate']))
109 display_error(_("The entered transfer date is invalid."));
110 set_focus('AdjDate');
113 elseif (!is_date_in_fiscalyear($_POST['AdjDate']))
115 display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
116 set_focus('AdjDate');
119 elseif ($_POST['FromStockLocation'] == $_POST['ToStockLocation'])
121 display_error(_("The locations to transfer from and to must be different."));
122 set_focus('FromStockLocation');
125 elseif (!$SysPrefs->allow_negative_stock())
127 $low_stock = $tr->check_qoh($_POST['FromStockLocation'], $_POST['AdjDate'], true);
131 display_error(_("The transfer cannot be processed because it would cause negative inventory balance in source location for marked items as of document date or later."));
136 if ($input_error == 1)
137 unset($_POST['Process']);
140 //-------------------------------------------------------------------------------
142 if (isset($_POST['Process']))
145 $trans_no = add_stock_transfer($_SESSION['transfer_items']->line_items,
146 $_POST['FromStockLocation'], $_POST['ToStockLocation'],
147 $_POST['AdjDate'], $_POST['ref'], $_POST['memo_']);
148 new_doc_date($_POST['AdjDate']);
149 $_SESSION['transfer_items']->clear_items();
150 unset($_SESSION['transfer_items']);
152 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
153 } /*end of process credit note */
155 //-----------------------------------------------------------------------------------------------
157 function check_item_data()
159 if (!check_num('qty', 0) || input_num('qty') == 0)
161 display_error(_("The quantity entered must be a positive number."));
168 //-----------------------------------------------------------------------------------------------
170 function handle_update_item()
172 $id = $_POST['LineNo'];
173 if (!isset($_POST['std_cost']))
174 $_POST['std_cost'] = $_SESSION['transfer_items']->line_items[$id]->standard_cost;
175 $_SESSION['transfer_items']->update_cart_item($id, input_num('qty'), $_POST['std_cost']);
179 //-----------------------------------------------------------------------------------------------
181 function handle_delete_item($id)
183 $_SESSION['transfer_items']->remove_from_cart($id);
187 //-----------------------------------------------------------------------------------------------
189 function handle_new_item()
191 if (!isset($_POST['std_cost']))
192 $_POST['std_cost'] = 0;
193 add_to_order($_SESSION['transfer_items'], $_POST['stock_id'], input_num('qty'), $_POST['std_cost']);
197 //-----------------------------------------------------------------------------------------------
198 $id = find_submit('Delete');
200 handle_delete_item($id);
202 if (isset($_POST['AddItem']) && check_item_data())
205 if (isset($_POST['UpdateItem']) && check_item_data())
206 handle_update_item();
208 if (isset($_POST['CancelItemChanges'])) {
211 //-----------------------------------------------------------------------------------------------
213 if (isset($_GET['NewTransfer']) || !isset($_SESSION['transfer_items']))
215 if (isset($_GET['fixed_asset']))
216 check_db_has_disposable_fixed_assets(_("There are no fixed assets defined in the system."));
218 check_db_has_costable_items(_("There are no inventory items defined in the system (Purchased or manufactured items)."));
223 //-----------------------------------------------------------------------------------------------
226 display_order_header($_SESSION['transfer_items']);
228 start_table(TABLESTYLE, "width='70%'", 10);
231 display_transfer_items(_("Items"), $_SESSION['transfer_items']);
232 transfer_options_controls();
237 submit_center_first('Update', _("Update"), '', null);
238 submit_center_last('Process', _("Process Transfer"), '', 'default');