Changed the Quantity routines to use the Item Units decimals if any. A lot of files.
[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         $k = 0;  //row colour counter
48
49         foreach ($order->line_items as $stock_item)
50         {
51
52                 if ($_GET['Edit'] != $stock_item->stock_id)
53                 {
54                 alt_table_row_color($k);
55
56                 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>");
57                 label_cell($stock_item->item_description);
58                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
59                 if (strlen($stock_item->units))
60                         label_cell($stock_item->units);
61                 else
62                         label_cell("");
63                         amount_cell($stock_item->standard_cost);
64
65                 edit_link_cell(SID . "Edit=$stock_item->stock_id");
66                 delete_link_cell(SID . "Delete=$stock_item->stock_id");
67                 end_row();
68                 }
69                 else
70                 {
71                         adjustment_edit_item_controls($order, $stock_item->stock_id);
72                 }
73         }
74
75         if (!isset($_GET['Edit']))
76                 adjustment_edit_item_controls($order);
77
78     end_table();
79 }
80
81 //---------------------------------------------------------------------------------
82
83 function adjustment_edit_item_controls(&$order, $stock_id=null)
84 {
85         start_row();
86
87         if (isset($_GET['Edit']) && $stock_id != null)
88         {
89                 if (!isset($_POST['stock_id']))
90                         $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
91                 if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
92                         $_POST['qty'] = $order->line_items[$stock_id]->quantity;
93                 if (!isset($_POST['std_cost']) || ($_POST['std_cost'] == ""))
94                         $_POST['std_cost'] = $order->line_items[$stock_id]->standard_cost;
95
96                 $_POST['units'] = $order->line_items[$stock_id]->units;
97
98                 hidden('stock_id', $_POST['stock_id']);
99                 label_cell($_POST['stock_id']);
100                 label_cell($order->line_items[$stock_id]->item_description);
101         }
102         else
103         {
104                 $wo_details = get_work_order($_SESSION['issue_items']->order_id);
105
106         echo "<td colspan=2>";
107         stock_component_items_list('stock_id', $wo_details["stock_id"], $_POST['stock_id'], false, true);
108         echo "</td>";
109
110         $item_info = get_item_edit_info($_POST['stock_id']);
111
112                 $_POST['qty'] = 0;
113                 $_POST['std_cost'] = $item_info["standard_cost"];
114                 $_POST['units'] = $item_info["units"];
115         }
116
117
118         text_cells(null, 'qty', $_POST['qty'], 13, 15);
119         label_cell($_POST['units']);
120         text_cells(null, 'std_cost', $_POST['std_cost'], 15, 14);
121
122         if (isset($_GET['Edit']))
123         {
124         submit_cells('UpdateItem', _("Update"));
125         submit_cells('CancelItemChanges', _("Cancel"));
126         }
127         else
128         {
129                 submit_cells('AddItem', _("Add Item"), "colspan=2");
130         }
131
132         end_row();
133 }
134
135
136 //---------------------------------------------------------------------------------
137
138 function adjustment_options_controls()
139 {
140         echo "<br>";
141         start_table();
142
143     ref_row(_("Reference:"), 'ref', '', references::get_next(28));
144
145         if (!isset($_POST['IssueType']))
146                 $_POST['IssueType'] = 0;
147
148         yesno_list_row(_("Type:"), 'IssueType', $_POST['IssueType'],
149                 _("Return Items to Location"), _("Issue Items to Work order"));
150
151         locations_list_row(_("From Location:"), 'Location', $_POST['Location']);
152         workcenter_list_row(_("To Work Centre:"), 'WorkCentre', $_POST['WorkCentre']);
153
154         date_row(_("Issue Date:"), 'date_');
155
156         textarea_row(_("Memo:"), 'memo_', $_POST['memo_'], 50, 3);
157
158         end_table();
159 }
160
161
162 //---------------------------------------------------------------------------------
163
164 ?>