New files from unstable branch
[fa-stable.git] / manufacturing / includes / work_order_issue_ui.inc
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 include_once($path_to_root . "/includes/ui.inc");
13 include_once($path_to_root . "/includes/ui/items_cart.inc");
14
15 //--------------------------------------------------------------------------------
16
17 function add_to_issue(&$order, $new_item, $new_item_qty, $standard_cost)
18 {
19     if ($order->find_cart_item($new_item))
20          display_error(_("For Part :") . $new_item . " " . "This item is already on this issue.  You can change the quantity issued of the existing line if necessary.");
21         else
22          $order->add_to_cart (count($order->line_items), $new_item, $new_item_qty, $standard_cost);
23 }
24 //---------------------------------------------------------------------------------
25
26 function display_issue_items($title, &$order)
27 {
28         global $path_to_root;
29
30         display_heading($title);
31     div_start('items_table');
32         start_table(TABLESTYLE, "width=80% colspan=7");
33         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
34                 _("Unit"), _("Unit Cost"), '');
35         if ( count($order->line_items)) $th[] = '';
36
37         table_header($th);
38 //      $total = 0;
39         $k = 0;  //row colour counter
40
41         $id = find_submit('Edit');
42         foreach ($order->line_items as $line_no=>$stock_item)
43         {
44
45 //              $total += ($stock_item->standard_cost * $stock_item->quantity);
46
47                 if ($id != $line_no)
48                 {
49                 alt_table_row_color($k);
50
51                         view_stock_status_cell($stock_item->stock_id);
52                         label_cell($stock_item->item_description);
53                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
54                         label_cell($stock_item->units);
55                         amount_cell($stock_item->standard_cost);
56 //                      amount_cell($stock_item->standard_cost * $stock_item->quantity);
57
58                         edit_button_cell("Edit$line_no", _("Edit"),
59                                 _('Edit document line'));
60                         delete_button_cell("Delete$line_no", _("Delete"),
61                                 _('Remove line from document'));
62                         end_row();
63                 }
64                 else
65                 {
66                         issue_edit_item_controls($order, $line_no);
67                 }
68         }
69
70         if ($id == -1)
71                 issue_edit_item_controls($order);
72
73 //      label_row(_("Total"), number_format2($total,user_price_dec()), "colspan=5", "align=right");
74
75     end_table();
76         div_end();
77 }
78
79 //---------------------------------------------------------------------------------
80
81 function issue_edit_item_controls(&$order, $line_no=-1)
82 {
83         global $Ajax;
84         start_row();
85
86         $id = find_submit('Edit');
87         if ($line_no != -1 && $line_no == $id)
88         {
89                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
90                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, 
91                         $order->line_items[$id]->stock_id, $dec);
92                 $_POST['std_cost'] = price_format($order->line_items[$id]->standard_cost);
93                 $_POST['units'] = $order->line_items[$id]->units;
94
95                 hidden('stock_id', $_POST['stock_id']);
96                 label_cell($_POST['stock_id']);
97                 label_cell($order->line_items[$id]->item_description);
98             $Ajax->activate('items_table');
99         }
100         else
101         {
102                 $wo_details = get_work_order($_SESSION['issue_items']->order_id);
103
104                 stock_component_items_list_cells(null, 'stock_id', 
105                         $wo_details["stock_id"], null, false, true);
106                 if (list_updated('stock_id')) {
107                             $Ajax->activate('units');
108                             $Ajax->activate('qty');
109                             $Ajax->activate('std_cost');
110                 }
111
112         $item_info = get_item_edit_info($_POST['stock_id']);
113
114                 $dec = $item_info["decimals"];
115                 $_POST['qty'] = number_format2(0, $dec);
116                 $_POST['std_cost'] = price_format($item_info["standard_cost"]);
117                 $_POST['units'] = $item_info["units"];
118         }
119
120         qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
121         label_cell($_POST['units'], '', 'units');
122
123         amount_cells(null, 'std_cost', $_POST['std_cost']);
124
125         if ($id != -1)
126         {
127                 button_cell('UpdateItem', _("Update"),
128                                 _('Confirm changes'), ICON_UPDATE);
129                 button_cell('CancelItemChanges', _("Cancel"),
130                                 _('Cancel changes'), ICON_CANCEL);
131                 hidden('LineNo', $line_no);
132                 set_focus('qty');
133         }
134         else
135         {
136                 submit_cells('AddItem', _("Add Item"), "colspan=2",
137                     _('Add new item to document'), true);
138         }
139
140         end_row();
141 }
142
143
144 //---------------------------------------------------------------------------------
145
146 function issue_options_controls()
147 {
148         global $Refs;
149
150         echo "<br>";
151         start_table();
152     ref_row(_("Reference:"), 'ref', '', $Refs->get_next(28));
153  
154         if (!isset($_POST['IssueType']))
155                 $_POST['IssueType'] = 0;
156  
157         yesno_list_row(_("Type:"), 'IssueType', $_POST['IssueType'],
158                 _("Return Items to Location"), _("Issue Items to Work order"));
159  
160         locations_list_row(_("From Location:"), 'Location');
161         workcenter_list_row(_("To Work Centre:"), 'WorkCentre');
162  
163         date_row(_("Issue Date:"), 'date_');
164
165         textarea_row(_("Memo"), 'memo_', null, 50, 3);
166
167         end_table(1);
168 }
169 //---------------------------------------------------------------------------------
170
171 ?>