3 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
5 // ------------------------------------------------------------------------------
7 function get_supplier_details_to_order(&$order, $supplier_id)
9 $sql = "SELECT curr_code,supp_name FROM ".TB_PREF."suppliers
10 WHERE supplier_id = '$supplier_id'";
11 $result = db_query($sql, "The supplier details could not be retreived");
13 $myrow = db_fetch($result);
15 $order->curr_code = $_POST['curr_code'] = $myrow["curr_code"];
16 $order->supplier_name = $_POST['supplier_name'] = $myrow["supp_name"];
17 $order->supplier_id = $_POST['supplier_id'] = $supplier_id;
20 //---------------------------------------------------------------------------------------------------
22 function create_new_po()
24 if (isset($_SESSION['PO']))
26 unset ($_SESSION['PO']->line_items);
27 $_SESSION['PO']->lines_on_order = 0;
28 unset ($_SESSION['PO']);
31 session_register("PO");
33 $_SESSION['PO'] = new purch_order;
34 $_POST['OrderDate'] = Today();
35 if (!is_date_in_fiscalyear($_POST['OrderDate']))
36 $_POST['OrderDate'] = end_fiscalyear();
37 $_SESSION['PO']->orig_order_date = $_POST['OrderDate'];
40 //---------------------------------------------------------------------------------------------------
42 function display_po_header(&$order)
46 $editable = ($order->order_no == 0);
48 start_table("width=80% $table_style2");
49 echo "<tr><td valign=center>"; // outer table
54 if (!isset($_POST['supplier_id']) && (get_global_supplier() != reserved_words::get_all()))
55 $_POST['supplier_id'] = get_global_supplier();
57 supplier_list_row(_("Supplier:"), 'supplier_id', $_POST['supplier_id'], false, true);
59 if ($order->supplier_id != $_POST['supplier_id'])
61 // supplier has changed
62 // delete all the order items - drastic but necessary because of
63 // change of currency, etc
64 $order->clear_items();
69 hidden('supplier_id', $order->supplier_id);
70 label_row(_("Supplier:"), $order->supplier_name);
73 //if ($editable || ($order->supplier_id != $_POST['supplier_id']))
74 get_supplier_details_to_order($order, $_POST['supplier_id']);
76 set_global_supplier($_POST['supplier_id']);
78 if (!is_company_currency($order->curr_code))
80 label_row(_("Supplier Currency:"), $order->curr_code);
81 exchange_rate_display($order->curr_code, get_company_currency(),
87 ref_row(_("Reference:"), 'ref', references::get_next(systypes::po()));
91 hidden('ref', $order->reference);
92 label_row(_("Reference:"), $order->reference);
97 echo "</td><td valign=center>"; // outer table
99 echo "<table height='5'>";
100 // check this out?????????
101 //if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
102 // $_POST['OrderDate'] = $order->orig_order_date;
103 //if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
105 // $_POST['OrderDate'] = Today();
106 // if (!is_date_in_fiscalyear($_POST['OrderDate']))
107 // $_POST['OrderDate'] = end_fiscalyear();
109 date_row(_("Order Date:"), 'OrderDate', $_POST['OrderDate'], 0, 0, 0);
111 text_row(_("Supplier's Reference:"), 'Requisition', null, 16, 15);
115 echo "</td><td valign=center>"; // outer table
117 echo "<table height='5'>";
119 echo "<tr><td>" . _("Receive Into:") . "</td>";
121 locations_list('StkLocation', null);
123 submit('GetAddress', _("Get Address"));
126 if (!isset($_POST['StkLocation']) || $_POST['StkLocation'] == "" ||
127 isset($_POST['GetAddress']) || !isset($_POST['delivery_address']) ||
128 $_POST['delivery_address'] == "")
130 /*If this is the first time the form loaded set up defaults */
132 //$_POST['StkLocation'] = $_SESSION['UserStockLocation'];
133 $sql = "SELECT delivery_address, phone FROM ".TB_PREF."locations WHERE loc_code='" . $_POST['StkLocation'] . "'";
134 $result = db_query($sql,"could not get location info");
136 if (db_num_rows($result) == 1)
138 $loc_row = db_fetch($result);
139 $_POST['delivery_address'] = $loc_row["delivery_address"];
140 $_SESSION['PO']->Location = $_POST['StkLocation'];
141 $_SESSION['PO']->delivery_address = $_POST['delivery_address'];
145 { /*The default location of the user is crook */
146 echo "<br>" . _("The default stock location set up for this user is not a currently defined stock location. Your system administrator needs to amend your user record.");
150 textarea_row(_("Deliver to:"), 'delivery_address', $_POST['delivery_address'], 35, 4);
154 end_table(); // outer table
157 //---------------------------------------------------------------------------------------------------
159 function display_po_items(&$order, $editable=true)
163 display_heading(_("Order Items"));
165 start_table("$table_style width=80%");
167 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
168 _("Required Delivery Date"), _("Price"), _("Line Total"));
173 foreach ($order->line_items as $po_line)
176 if ($po_line->Deleted == false)
178 $line_total = $po_line->quantity * $po_line->price;
179 if (!$editable || !isset($_GET['Edit']) || $_GET['Edit'] != $po_line->line_no)
181 alt_table_row_color($k);
182 label_cell($po_line->stock_id);
183 label_cell($po_line->item_description);
184 qty_cell($po_line->quantity);
185 label_cell($po_line->units);
186 label_cell($po_line->req_del_date);
187 amount_cell($po_line->price);
188 amount_cell($line_total);
192 edit_link_cell(SID."Edit=" . $po_line->line_no);
193 delete_link_cell(SID."Delete=" . $po_line->line_no);
199 po_item_controls($order, $po_line->stock_id);
201 $total += $line_total;
205 if (!isset($_GET['Edit']) && $editable)
206 po_item_controls($order);
208 $display_total = number_format2($total,user_price_dec());
209 label_row(_("Total Excluding Shipping/Tax"), $display_total, "colspan=6 align=right",
210 "nowrap align=right");
215 //---------------------------------------------------------------------------------------------------
217 function display_po_summary(&$po, $is_self=false, $editable=false)
219 global $table_style2;
220 start_table("$table_style2 width=90%");
223 label_cells(_("Reference"), $po->reference, "class='tableheader2'");
225 label_cells(_("Supplier"), $po->supplier_name, "class='tableheader2'");
227 if (!is_company_currency($po->curr_code))
228 label_cells(_("Order Currency"), $po->curr_code, "class='tableheader2'");
232 label_cells(_("Purchase Order"), get_trans_view_str(systypes::po(), $po->order_no),
233 "class='tableheader2'");
237 label_cells(_("Date"), $po->orig_order_date, "class='tableheader2'");
241 if (!isset($_POST['Location']))
242 $_POST['Location'] = $po->Location;
243 label_cell(_("Deliver Into Location"), "class='tableheader2'");
244 locations_list_cells(null, 'Location', $_POST['Location']);
248 label_cells(_("Deliver Into Location"), get_location_name($po->Location),
249 "class='tableheader2'");
252 if ($po->requisition_no != "")
253 label_cells(_("Supplier's Reference"), $po->requisition_no, "class='tableheader2'");
257 label_row(_("Delivery Address"), $po->delivery_address, "class='tableheader2'",
260 if ($po->Comments != "")
261 label_row(_("Order Comments"), $po->Comments, "class='tableheader2'",
266 //--------------------------------------------------------------------------------
268 function po_item_controls(&$order, $stock_id=null)
272 if (isset($_GET['Edit']) && $stock_id != null)
274 hidden('line_no', $_GET['Edit']);
276 if (!isset($_POST['stock_id']))
277 $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
278 if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
279 $_POST['qty'] = $order->line_items[$_GET['Edit']]->quantity;
280 if (!isset($_POST['price']) || ($_POST['price'] == ""))
281 $_POST['price'] = $order->line_items[$_GET['Edit']]->price;
282 if (!isset($_POST['req_del_date']) || ($_POST['req_del_date'] == ""))
283 $_POST['req_del_date'] = $order->line_items[$_GET['Edit']]->req_del_date;
285 $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
287 hidden('stock_id', $_POST['stock_id']);
288 label_cell($_POST['stock_id']);
289 label_cell($order->line_items[$_GET['Edit']]->item_description);
293 hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
295 $no_item_list = get_company_pref('no_item_list');
298 echo "<td colspan=2>\n";
299 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
304 text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if(event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'");
305 stock_purchasable_items_list_cells(null, 'stock_id', $_POST['stock_id'], false, false, "onchange='return setAccount(1, true)'");
307 $item_info = get_item_edit_info($_POST['stock_id']);
308 $_POST['units'] = $item_info["units"];
311 $_POST['price'] = get_purchase_price ($order->supplier_id, $_POST['stock_id']);
312 $_POST['req_del_date'] = add_days(Today(), 10);
315 text_cells(null, 'qty', null, 13, 15);
317 label_cell($_POST['units']);
318 date_cells(null, 'req_del_date', null, 0, 0, 0);
319 text_cells(null, 'price', null, 15, 14);
321 //$line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100);
322 $line_total = $_POST['qty'] * $_POST['price'];
323 amount_cell($line_total);
325 if (isset($_GET['Edit']))
327 submit_cells('UpdateLine', _("Update"));
328 submit_cells('CancelUpdate', _("Cancel"));
332 submit_cells('EnterLine', _("Add Item"), "colspan=2");
338 //---------------------------------------------------------------------------------------------------