*** empty log message ***
[fa-stable.git] / manufacturing / work_order_issue.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/ui/items_cart.inc");
6
7 include_once($path_to_root . "/includes/session.inc");
8
9 page(_("Issue Items to Work Order"));
10
11 include_once($path_to_root . "/includes/date_functions.inc");
12 include_once($path_to_root . "/includes/data_checks.inc");
13
14 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
15 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
16 include_once($path_to_root . "/manufacturing/includes/work_order_issue_ui.inc");
17
18 //-----------------------------------------------------------------------------------------------
19
20 if (isset($_GET['AddedID'])) 
21 {
22         echo "<center>" . _("The work order issue has been entered.");
23         echo "<br>";
24         hyperlink_no_params("search_work_orders.php", _("Select another Work Order to Process"));
25         echo "<br><br>";
26         end_page();
27         exit;
28 }
29
30 //--------------------------------------------------------------------------------------------------
31
32 function handle_new_order()
33 {
34         if (isset($_SESSION['issue_items']))
35         {
36                 $_SESSION['issue_items']->clear_items();
37                 unset ($_SESSION['issue_items']);
38         }
39
40      Session_register("issue_items");
41
42      $_SESSION['issue_items'] = new items_cart;
43      $_SESSION['issue_items']->order_id = $_GET['trans_no'];
44 }
45
46 //-----------------------------------------------------------------------------------------------
47
48 function can_process()
49 {
50         if (!is_date($_POST['date_'])) 
51         {
52                 display_error(_("The entered date for the issue is invalid."));
53                 return false;
54         } 
55         elseif (!is_date_in_fiscalyear($_POST['date_'])) 
56         {
57                 display_error(_("The entered date is not in fiscal year."));
58                 return false;
59         }
60         if (!references::is_valid($_POST['ref'])) 
61         {
62                 display_error(_("You must enter a reference."));
63                 return false;
64         }
65
66         if (!is_new_reference($_POST['ref'], 28)) 
67         {
68                 display_error(_("The entered reference is already in use."));
69                 return false;
70         }
71
72         $failed_item = $_SESSION['issue_items']->check_qoh($_POST['Location'], $_POST['date_'], !$_POST['IssueType']);
73         if ($failed_item != null) 
74         {
75         display_error( _("The issue cannot be processed because an entered item would cause a negative inventory balance :") .
76                 " " . $failed_item->stock_id . " - " .  $failed_item->item_description);
77                 return false;
78         }
79
80         return true;
81 }
82
83 if (isset($_POST['Process']))
84 {
85
86         // if failed, returns a stockID
87         $failed_data = add_work_order_issue($_SESSION['issue_items']->order_id,
88                 $_POST['ref'], $_POST['IssueType'], $_SESSION['issue_items']->line_items,
89                 $_POST['Location'], $_POST['WorkCentre'], $_POST['date_'], $_POST['memo_']);
90
91         if ($failed_data != null) 
92         {
93                 display_error(_("The process cannot be completed because there is an insufficient total quantity for a component.") . "<br>"
94                 . _("Component is :"). $failed_data[0] . "<br>"
95                 . _("From location :"). $failed_data[1] . "<br>");
96         } 
97         else 
98         {
99                 meta_forward($_SERVER['PHP_SELF'], "AddedID=1");
100         }
101
102 } /*end of process credit note */
103
104 //-----------------------------------------------------------------------------------------------
105
106 function check_item_data()
107 {
108         if (!is_numeric($_POST['qty']))
109         {
110                 display_error(_("The quantity entered is not a valid number."));
111                 return false;
112         }
113
114         if ($_POST['qty'] <= 0)
115         {
116                 display_error(_("The quantity entered must be greater than zero."));
117                 return false;
118         }
119
120         if (!is_numeric($_POST['std_cost']) || $_POST['std_cost'] < 0)
121         {
122                 display_error(_("The entered standard cost is negative or invalid."));
123                 return false;
124         }
125
126         return true;
127 }
128
129 //-----------------------------------------------------------------------------------------------
130
131 function handle_update_item()
132 {
133     if($_POST['UpdateItem'] != "" && check_item_data())
134     {
135         $_SESSION['issue_items']->update_cart_item($_POST['stock_id'], $_POST['qty'], $_POST['std_cost']);
136     }
137 }
138
139 //-----------------------------------------------------------------------------------------------
140
141 function handle_delete_item()
142 {
143         $_SESSION['issue_items']->remove_from_cart($_GET['Delete']);
144 }
145
146 //-----------------------------------------------------------------------------------------------
147
148 function handle_new_item()
149 {
150         if (!check_item_data())
151                 return;
152
153         add_to_order($_SESSION['issue_items'], $_POST['stock_id'], $_POST['qty'], $_POST['std_cost']);
154 }
155
156 //-----------------------------------------------------------------------------------------------
157
158 if ($_GET['Delete']!="")
159         handle_delete_item();
160
161 if ($_POST['AddItem']!="")
162         handle_new_item();
163
164 if ($_POST['UpdateItem']!="")
165         handle_update_item();
166
167 //-----------------------------------------------------------------------------------------------
168
169 if (isset($_GET['trans_no']))
170 {
171         handle_new_order();
172 }
173
174 //-----------------------------------------------------------------------------------------------
175
176 display_order_header($_SESSION['issue_items']);
177
178 start_form(false, true);
179
180 start_table("$table_style width=90%", '10');
181 echo "<tr><td>";
182 display_adjustment_items(_("Items to Issue"), $_SESSION['issue_items']);
183 adjustment_options_controls();
184 echo "</td></tr>";
185
186 end_table();
187
188 if (!isset($_POST['Process']))
189 {
190         start_table();
191     start_row();
192     submit_cells('Update', _("Update"));
193         if ($_SESSION['issue_items']->count_items() >= 1)
194         {
195             submit_cells('Process', _("Process Issue"));
196         }
197         end_row();
198         end_table();
199 }
200
201 end_form();
202
203 //------------------------------------------------------------------------------------------------
204
205 end_page();
206
207 ?>