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_MANUFISSUE';
15 include_once($path_to_root . "/includes/ui/items_cart.inc");
17 include_once($path_to_root . "/includes/session.inc");
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
22 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
23 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
24 include_once($path_to_root . "/manufacturing/includes/work_order_issue_ui.inc");
26 if ($use_popup_windows)
27 $js .= get_js_open_window(800, 500);
29 $js .= get_js_date_picker();
31 page(_($help_context = "Issue Items to Work Order"), false, false, "", $js);
33 //-----------------------------------------------------------------------------------------------
35 if (isset($_GET['AddedID']))
37 $id = $_GET['AddedID'];
38 display_notification(_("The work order issue has been entered."));
40 display_note(get_trans_view_str(ST_WORKORDER, $id, _("View this Work Order")));
42 display_note(get_gl_view_str(ST_WORKORDER, $id, _("View the GL Journal Entries for this Work Order")), 1);
44 hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
46 display_footer_exit();
48 //--------------------------------------------------------------------------------------------------
50 function line_start_focus() {
53 $Ajax->activate('items_table');
54 set_focus('_stock_id_edit');
57 //--------------------------------------------------------------------------------------------------
59 function handle_new_order()
61 if (isset($_SESSION['issue_items']))
63 $_SESSION['issue_items']->clear_items();
64 unset ($_SESSION['issue_items']);
67 $_SESSION['issue_items'] = new items_cart(ST_MANUISSUE);
68 $_SESSION['issue_items']->order_id = $_GET['trans_no'];
71 //-----------------------------------------------------------------------------------------------
72 function can_process()
76 if (!is_date($_POST['date_']))
78 display_error(_("The entered date for the issue is invalid."));
82 elseif (!is_date_in_fiscalyear($_POST['date_']))
84 display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
88 if (!$Refs->is_valid($_POST['ref']))
90 display_error(_("You must enter a reference."));
95 if (!is_new_reference($_POST['ref'], ST_MANUISSUE))
97 display_error(_("The entered reference is already in use."));
102 $failed_item = $_SESSION['issue_items']->check_qoh($_POST['Location'], $_POST['date_'], !$_POST['IssueType']);
103 if ($failed_item != -1)
105 display_error(_("The issue cannot be processed because it would cause negative inventory balance for marked items as of document date or later."));
112 if (isset($_POST['Process']) && can_process())
115 // if failed, returns a stockID
116 $failed_data = add_work_order_issue($_SESSION['issue_items']->order_id,
117 $_POST['ref'], $_POST['IssueType'], $_SESSION['issue_items']->line_items,
118 $_POST['Location'], $_POST['WorkCentre'], $_POST['date_'], $_POST['memo_']);
120 if ($failed_data != null)
122 display_error(_("The process cannot be completed because there is an insufficient total quantity for a component.") . "<br>"
123 . _("Component is :"). $failed_data[0] . "<br>"
124 . _("From location :"). $failed_data[1] . "<br>");
128 meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_SESSION['issue_items']->order_id);
131 } /*end of process credit note */
133 //-----------------------------------------------------------------------------------------------
135 function check_item_data()
137 if (input_num('qty') == 0 || !check_num('qty', 0))
139 display_error(_("The quantity entered is negative or invalid."));
144 if (!check_num('std_cost', 0))
146 display_error(_("The entered standard cost is negative or invalid."));
147 set_focus('std_cost');
154 //-----------------------------------------------------------------------------------------------
156 function handle_update_item()
158 if($_POST['UpdateItem'] != "" && check_item_data())
160 $id = $_POST['LineNo'];
161 $_SESSION['issue_items']->update_cart_item($id, input_num('qty'), input_num('std_cost'));
166 //-----------------------------------------------------------------------------------------------
168 function handle_delete_item($id)
170 $_SESSION['issue_items']->remove_from_cart($id);
174 //-----------------------------------------------------------------------------------------------
176 function handle_new_item()
178 if (!check_item_data())
181 add_to_issue($_SESSION['issue_items'], $_POST['stock_id'], input_num('qty'),
182 input_num('std_cost'));
186 //-----------------------------------------------------------------------------------------------
187 $id = find_submit('Delete');
189 handle_delete_item($id);
191 if (isset($_POST['AddItem']))
194 if (isset($_POST['UpdateItem']))
195 handle_update_item();
197 if (isset($_POST['CancelItemChanges'])) {
201 //-----------------------------------------------------------------------------------------------
203 if (isset($_GET['trans_no']))
208 //-----------------------------------------------------------------------------------------------
210 display_wo_details($_SESSION['issue_items']->order_id);
215 start_table(TABLESTYLE, "width=90%", 10);
217 display_issue_items(_("Items to Issue"), $_SESSION['issue_items']);
218 issue_options_controls();
223 submit_center('Process', _("Process Issue"), true, '', 'default');
227 //------------------------------------------------------------------------------------------------