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