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_WORKORDERCOST';
14 include_once($path_to_root . "/includes/session.inc");
15 include_once($path_to_root . "/includes/inventory.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/gl/includes/db/gl_db_bank_trans.inc");
20 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
21 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
24 if ($SysPrefs->use_popup_windows)
25 $js .= get_js_open_window(900, 500);
26 if (user_use_date_picker())
27 $js .= get_js_date_picker();
28 page(_($help_context = "Work Order Additional Costs"), false, false, "", $js);
30 if (isset($_GET['trans_no']) && $_GET['trans_no'] != "")
32 $_POST['selected_id'] = $_GET['trans_no'];
35 //--------------------------------------------------------------------------------------------------
37 if (isset($_GET['AddedID']))
39 $id = $_GET['AddedID'];
40 $stype = ST_WORKORDER;
42 display_notification(_("The additional cost has been entered."));
44 display_note(get_trans_view_str($stype, $id, _("View this Work Order")));
46 display_note(get_gl_view_str($stype, $id, _("View the GL Journal Entries for this Work Order")), 1);
48 hyperlink_params("work_order_costs.php", _("Enter another additional cost."), "trans_no=$id");
50 hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
57 //--------------------------------------------------------------------------------------------------
59 $wo_details = get_work_order($_POST['selected_id']);
61 if (strlen($wo_details[0]) == 0)
63 display_error(_("The order number sent is not valid."));
67 //--------------------------------------------------------------------------------------------------
69 function can_process($wo_details)
71 if (input_num('costs')<=0)
73 display_error(_("The amount entered is not a valid number or less then zero."));
78 if (!is_date($_POST['date_']))
80 display_error(_("The entered date is invalid."));
84 elseif (!is_date_in_fiscalyear($_POST['date_']))
86 display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
90 if (date_diff2(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0)
92 display_error(_("The additional cost date cannot be before the release date of the work order."));
100 //--------------------------------------------------------------------------------------------------
102 if (isset($_POST['process']) && can_process($wo_details) == true)
104 $date = $_POST['date_'];
105 $memo = $_POST['memo'];
106 $ref = $_POST['ref'];
108 add_wo_costs_journal($_POST['selected_id'], input_num('costs'), $_POST['PaymentType'],
109 $_POST['cr_acc'], $date, $_POST['dim1'], $_POST['dim2'], $memo, $ref);
111 meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']);
114 //-------------------------------------------------------------------------------------
116 display_wo_details($_POST['selected_id']);
118 //-------------------------------------------------------------------------------------
120 if (!isset($_POST['ref']))
121 $_POST['ref'] = $Refs->get_next(ST_JOURNAL, null, Today());
125 hidden('selected_id', $_POST['selected_id']);
126 //hidden('WOReqQuantity', $_POST['WOReqQuantity']);
128 start_table(TABLESTYLE2);
133 date_row(_("Date:"), 'date_');
134 ref_row(_("Reference:"), 'ref', '');
136 yesno_list_row(_("Type:"), 'PaymentType', null, $wo_cost_types[WO_OVERHEAD], $wo_cost_types[WO_LABOUR], true);
137 if (list_updated('PaymentType'))
138 $Ajax->activate('costs');
140 $item = get_item($wo_details['stock_id']);
141 $r = get_default_bank_account(get_company_pref('curr_default'));
142 $_POST['cr_acc'] = $r[0];
143 $_POST['costs'] = price_format(get_post('PaymentType')==WO_OVERHEAD ? $item['overhead_cost'] : $item['labour_cost']);
145 amount_row(_("Additional Costs:"), 'costs');
146 gl_all_accounts_list_row(_("Credit Account"), 'cr_acc', null);
147 textarea_row(_("Memo:"), 'memo', null, 40, 5);
149 hidden('dim1', $item["dimension_id"]);
150 hidden('dim2', $item["dimension2_id"]);
152 submit_center('process', _("Process Additional Cost"), true, '', true);