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"));
170 if (count($order->line_items)) $th[] = '';
175 foreach ($order->line_items as $po_line)
178 if ($po_line->Deleted == false)
180 $line_total = round($po_line->quantity * $po_line->price, user_price_dec());
181 if (!$editable || !isset($_GET['Edit']) || $_GET['Edit'] != $po_line->line_no)
183 alt_table_row_color($k);
184 label_cell($po_line->stock_id);
185 label_cell($po_line->item_description);
186 qty_cell($po_line->quantity);
187 label_cell($po_line->units);
188 label_cell($po_line->req_del_date);
189 amount_cell($po_line->price);
190 amount_cell($line_total);
194 edit_link_cell(SID."Edit=" . $po_line->line_no);
195 delete_link_cell(SID."Delete=" . $po_line->line_no);
201 po_item_controls($order, $po_line->stock_id);
203 $total += $line_total;
207 if (!isset($_GET['Edit']) && $editable)
208 po_item_controls($order);
210 $display_total = price_format($total);
211 label_row(_("Total Excluding Shipping/Tax"), $display_total, "colspan=6 align=right",
212 "nowrap align=right");
217 //---------------------------------------------------------------------------------------------------
219 function display_po_summary(&$po, $is_self=false, $editable=false)
221 global $table_style2;
222 start_table("$table_style2 width=90%");
225 label_cells(_("Reference"), $po->reference, "class='tableheader2'");
227 label_cells(_("Supplier"), $po->supplier_name, "class='tableheader2'");
229 if (!is_company_currency($po->curr_code))
230 label_cells(_("Order Currency"), $po->curr_code, "class='tableheader2'");
234 label_cells(_("Purchase Order"), get_trans_view_str(systypes::po(), $po->order_no),
235 "class='tableheader2'");
239 label_cells(_("Date"), $po->orig_order_date, "class='tableheader2'");
243 if (!isset($_POST['Location']))
244 $_POST['Location'] = $po->Location;
245 label_cell(_("Deliver Into Location"), "class='tableheader2'");
246 locations_list_cells(null, 'Location', $_POST['Location']);
250 label_cells(_("Deliver Into Location"), get_location_name($po->Location),
251 "class='tableheader2'");
254 if ($po->requisition_no != "")
255 label_cells(_("Supplier's Reference"), $po->requisition_no, "class='tableheader2'");
259 label_row(_("Delivery Address"), $po->delivery_address, "class='tableheader2'",
262 if ($po->Comments != "")
263 label_row(_("Order Comments"), $po->Comments, "class='tableheader2'",
268 //--------------------------------------------------------------------------------
270 function po_item_controls(&$order, $stock_id=null)
274 if (isset($_GET['Edit']) && $stock_id != null)
276 hidden('line_no', $_GET['Edit']);
278 if (!isset($_POST['stock_id']))
279 $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
280 if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
281 $_POST['qty'] = qty_format($order->line_items[$_GET['Edit']]->quantity);
282 if (!isset($_POST['price']) || ($_POST['price'] == ""))
283 $_POST['price'] = price_format($order->line_items[$_GET['Edit']]->price);
284 if (!isset($_POST['req_del_date']) || ($_POST['req_del_date'] == ""))
285 $_POST['req_del_date'] = $order->line_items[$_GET['Edit']]->req_del_date;
287 $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
289 hidden('stock_id', $_POST['stock_id']);
290 label_cell($_POST['stock_id']);
291 label_cell($order->line_items[$_GET['Edit']]->item_description);
295 hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
297 $no_item_list = get_company_pref('no_item_list');
300 echo "<td colspan=2>\n";
301 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
306 text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if(event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'");
307 stock_purchasable_items_list_cells(null, 'stock_id', $_POST['stock_id'], false, false, "onchange='return setAccount(1, true)'");
309 $item_info = get_item_edit_info($_POST['stock_id']);
310 $_POST['units'] = $item_info["units"];
312 $_POST['qty'] = qty_format(1);
313 $_POST['price'] = price_format(get_purchase_price ($order->supplier_id, $_POST['stock_id']));
314 $_POST['req_del_date'] = add_days(Today(), 10);
317 qty_cells(null, 'qty', null);
319 label_cell($_POST['units']);
320 date_cells(null, 'req_del_date', null, 0, 0, 0);
321 amount_cells(null, 'price', null);
323 //$line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100);
324 $line_total = round(input_num('qty') * input_num('price'), user_price_dec());
325 amount_cell($line_total);
327 if (isset($_GET['Edit']))
329 submit_cells('UpdateLine', _("Update"));
330 submit_cells('CancelUpdate', _("Cancel"));
334 submit_cells('EnterLine', _("Add Item"), "colspan=2");
340 //---------------------------------------------------------------------------------------------------