[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / manufacturing / work_order_release.php
1 <?php
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_MANUFRELEASE';
13 $path_to_root = "..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 include_once($path_to_root . "/includes/date_functions.inc");
17
18 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
19 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
20
21 $js = "";
22 if ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if (user_use_date_picker())
25         $js .= get_js_date_picker();
26 page(_($help_context = "Work Order Release to Manufacturing"), false, false, "", $js);
27
28 if (isset($_GET["trans_no"]))
29 {
30         $selected_id = $_GET["trans_no"];
31 }
32 elseif (isset($_POST["selected_id"]))
33 {
34         $selected_id = $_POST["selected_id"];
35 }
36 else
37 {
38         display_note("This page must be called with a work order reference");
39         exit;
40 }
41
42 //------------------------------------------------------------------------------------
43
44 function can_process($myrow)
45 {
46         if ($myrow['released'])
47         {
48                 display_error(_("This work order has already been released."));
49                 set_focus('released');
50                 return false;
51         }
52
53         // make sure item has components
54     // We don't need to stop the user to release it if it's and advanced order.
55     // The user know what he is doing.
56
57     if (!has_bom($myrow['stock_id']) && $myrow['type'] != WO_ADVANCED)
58         {
59                 display_error(_("This Work Order cannot be released. The selected item to manufacture does not have a bom."));
60                 set_focus('stock_id');
61                 return false;
62         }
63
64         return true;
65 }
66
67 //------------------------------------------------------------------------------------
68 if (isset($_POST['release']))
69 {
70         release_work_order($selected_id, $_POST['released_date'], $_POST['memo_']);
71
72         display_notification(_("The work order has been released to manufacturing."));
73
74     display_note(get_trans_view_str(ST_WORKORDER, $selected_id, _("View this Work Order")));
75
76         hyperlink_no_params("search_work_orders.php", _("Select another &work order"));
77         br();
78
79         $Ajax->activate('_page_body');
80         end_page();
81         exit;
82 }
83
84 //------------------------------------------------------------------------------------
85
86 start_form();
87
88 $myrow = get_work_order($selected_id);
89
90 $_POST['released'] = $myrow["released"];
91 $_POST['memo_'] = "";
92
93 if (can_process($myrow))
94 {
95         start_table(TABLESTYLE2);
96
97     label_row(_("Work Order #:"), $selected_id);
98     label_row(_("Work Order Reference:"), $myrow["wo_ref"]);
99
100     date_row(_("Released Date") . ":", 'released_date');
101
102     textarea_row(_("Memo:"), 'memo_', $_POST['memo_'], 40, 5);
103
104     end_table(1);
105
106     submit_center('release', _("Release Work Order"), true, '', 'default');
107
108     hidden('selected_id', $selected_id);
109     hidden('stock_id', $myrow['stock_id']);
110
111 }
112
113 end_form();
114
115 end_page();
116