531e9983a5186a61d4314399b3f98f388fc91fd0
[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_order(&$order, $new_item, $new_item_qty, $standard_cost)
9 {
10     $already_on_order = 0;
11
12         foreach ($order->line_items as $order_item) 
13         {
14         if (strcasecmp($order_item->stock_id, $new_item) == 0) 
15         {
16             $already_on_order = 1;
17             display_error(_("For Part :") . $new_item . " " . "This item is already on this order.  You can change the quantity ordered of the existing line if necessary.");
18         }
19         }
20
21     if ($already_on_order != 1)
22     {
23          $order->add_to_cart($new_item, $new_item_qty, $standard_cost);
24     } /* end of if not already on the order */
25 }
26
27 //--------------------------------------------------------------------------------
28
29 function display_order_header(&$order)
30 {
31         display_wo_details($_SESSION['issue_items']->order_id);
32         echo "<br>";
33 }
34
35 //---------------------------------------------------------------------------------
36
37 function display_adjustment_items($Title, &$order)
38 {
39         global $table_style, $path_to_root;
40
41         display_heading($Title);
42         start_table("$table_style colspan=7");
43         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
44                 _("Unit"), _("Unit Cost"));
45         table_header($th);      
46
47         $subtotal = 0;
48         $k = 0;  //row colour counter
49
50         foreach ($order->line_items as $stock_item) 
51         {
52
53                 if ($_GET['Edit'] != $stock_item->stock_id)
54                 {
55                 alt_table_row_color($k);
56
57                 label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $stock_item->stock_id . "'>$stock_item->stock_id</a>");
58                 label_cell($stock_item->item_description);
59                 qty_cell($stock_item_quantity);
60                 if (strlen($stock_item->units))
61                         label_cell($stock_item->units);
62                 else
63                         label_cell("");
64                         amount_cell($stock_item->standard_cost);
65
66                 edit_link_cell(SID . "Edit=$stock_item->stock_id");
67                 delete_link_cell(SID . "Delete=$stock_item->stock_id");
68                 end_row();
69                 } 
70                 else 
71                 {
72                         adjustment_edit_item_controls($order, $stock_item->stock_id);
73                 }
74         }
75
76         if (!isset($_GET['Edit']))
77                 adjustment_edit_item_controls($order);
78
79     end_table();
80 }
81
82 //---------------------------------------------------------------------------------
83
84 function adjustment_edit_item_controls(&$order, $stock_id=null)
85 {
86         start_row();
87
88         if (isset($_GET['Edit']) && $stock_id != null)
89         {
90                 if (!isset($_POST['stock_id']))
91                         $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
92                 if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
93                         $_POST['qty'] = $order->line_items[$stock_id]->quantity;
94                 if (!isset($_POST['std_cost']) || ($_POST['std_cost'] == ""))
95                         $_POST['std_cost'] = $order->line_items[$stock_id]->standard_cost;
96
97                 $_POST['units'] = $order->line_items[$stock_id]->units;
98
99                 hidden('stock_id', $_POST['stock_id']);
100                 label_cell($_POST['stock_id']);
101                 label_cell($order->line_items[$stock_id]->item_description);
102         }
103         else
104         {
105                 $wo_details = get_work_order($_SESSION['issue_items']->order_id);
106
107         echo "<td colspan=2>";
108         stock_component_items_list('stock_id', $wo_details["stock_id"], $_POST['stock_id'], false, true);
109         echo "</td>";
110
111         $item_info = get_item_edit_info($_POST['stock_id']);
112
113                 $_POST['qty'] = 0;
114                 $_POST['std_cost'] = $item_info["standard_cost"];
115                 $_POST['units'] = $item_info["units"];
116         }
117
118
119         text_cells(null, 'qty', $_POST['qty'], 13, 15);
120         label_cell($_POST['units']);
121         text_cells(null, 'std_cost', $_POST['std_cost'], 15, 14);
122
123         if (isset($_GET['Edit'])) 
124         {
125         submit_cells('UpdateItem', _("Update"));
126         submit_cells('CancelItemChanges', _("Cancel"));
127         } 
128         else 
129         {
130                 submit_cells('AddItem', _("Add Item"), "colspan=2");
131         }
132
133         end_row();
134 }
135
136
137 //---------------------------------------------------------------------------------
138
139 function adjustment_options_controls()
140 {
141         echo "<br>";
142         start_table();
143
144     ref_row(_("Reference:"), 'ref', references::get_next(28));
145
146         if (!isset($_POST['IssueType']))
147                 $_POST['IssueType'] = 0;
148
149         yesno_list_row(_("Type:"), 'IssueType', $_POST['IssueType'],
150                 _("Return Items to Location"), _("Issue Items to Work order"));
151
152         locations_list_row(_("From Location:"), 'Location', $_POST['Location']);
153         workcenter_list_row(_("To Work Centre:"), 'WorkCentre', $_POST['WorkCentre']);
154
155         date_row(_("Issue Date:"), 'date_');
156
157         textarea_row(_("Memo:"), 'memo_', $_POST['memo_'], 50, 3);
158
159         end_table();
160 }
161
162
163 //---------------------------------------------------------------------------------
164
165 ?>