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