$page_security = 2;
$path_to_root="../..";
+include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
end_form();
+//---------------------------------------------------------------------------------------------
+function trans_view($trans)
+{
+ return get_trans_view_str(systypes::po(), $trans["order_no"]);
+}
+
+function edit_link($row)
+{
+ return pager_link( _("Edit"),
+ "/purchasing/po_entry_items.php?" . SID
+ . "ModifyOrderNumber=" . $row["order_no"]);
+}
+
+function prt_link($row)
+{
+ return print_document_link($row['order_no'], _("Print"), true, 18);
+}
+
+function receive_link($row)
+{
+ return pager_link( _("Receive"),
+ "/purchasing/po_receive_items.php?" . SID
+ . "PONumber=" . $row["order_no"]);
+}
+
+function check_overdue($row)
+{
+ return $row['OverDue']==1;
+}
//---------------------------------------------------------------------------------------------
if (isset($_POST['order_number']) && ($_POST['order_number'] != ""))
unset($selected_stock_item);
}
-$today = date2sql(Today());
-
//figure out the sql required from the inputs available
-$sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.into_stock_location,
- ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference,
- ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name,
- Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue,
- Sum(".TB_PREF."purch_order_details.delivery_date < '" . $today. "'
- AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received)) As OverDue
- FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
- WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
- AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
- AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location
- AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
+$sql = "SELECT
+ porder.order_no,
+ porder.reference,
+ supplier.supp_name,
+ location.location_name,
+ porder.requisition_no,
+ porder.ord_date,
+ supplier.curr_code,
+ Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
+ Sum(line.delivery_date < '". date2sql(Today()) ."'
+ AND (line.quantity_ordered > line.quantity_received)) As OverDue
+ FROM "
+ .TB_PREF."purch_orders as porder, "
+ .TB_PREF."purch_order_details as line, "
+ .TB_PREF."suppliers as supplier, "
+ .TB_PREF."locations as location
+ WHERE porder.order_no = line.order_no
+ AND porder.supplier_id = supplier.supplier_id
+ AND location.loc_code = porder.into_stock_location
+ AND (line.quantity_ordered > line.quantity_received) ";
if (isset($order_number) && $order_number != "")
{
- $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
+ $sql .= "AND porder.reference LIKE '%". $order_number . "%'";
}
else
{
-
$data_after = date2sql($_POST['OrdersAfterDate']);
$data_before = date2sql($_POST['OrdersToDate']);
- $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
- $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$data_before'";
+ $sql .= " AND porder.ord_date >= '$data_after'";
+ $sql .= " AND porder.ord_date <= '$data_before'";
if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
{
- $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
+ $sql .= " AND porder.into_stock_location = '". $_POST['StockLocation'] . "' ";
}
if (isset($selected_stock_item))
{
- $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
+ $sql .= " AND line.item_code='". $selected_stock_item ."' ";
}
} //end not order number selected
-$sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
+$sql .= " GROUP BY porder.order_no";
$result = db_query($sql,"No orders were returned");
/*show a table of the orders returned by the sql */
+$cols = array(
+ _("#") => array('fun'=>'trans_view', 'ord'=>''),
+ _("Reference"),
+ _("Supplier") => array('ord'=>''),
+ _("Location"),
+ _("Supplier's Reference"),
+ _("Order Date") => array('type'=>'date', 'ord'=>'desc'),
+ _("Currency") => array('align'=>'center'),
+ _("Order Total") => 'amount',
+ array('insert'=>true, 'fun'=>'edit_link'),
+ array('insert'=>true, 'fun'=>'prt_link'),
+ array('insert'=>true, 'fun'=>'receive_link')
+);
+
+if (get_post('StockLocation') != $all_items) {
+ $cols[_("Location")] = 'skip';
+}
-div_start('orders_tbl');
-start_table("$table_style colspan=7 width=80%");
-
-if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
- $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
- _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
-else
- $th = array(_("#"), _("Reference"), _("Supplier"),
- _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
+$table =& new_db_pager('orders_tbl', $sql, $cols);
+$table->set_marker('check_overdue', _("Marked orders have overdue items."));
-table_header($th);
-$j = 1;
-$k = 0; //row colour counter
-$overdue_items = false;
-while ($myrow = db_fetch($result))
+if (get_post('SearchOrders'))
{
-
- if ($myrow["OverDue"] == 1)
- {
- start_row("class='overduebg'");
- $overdue_items = true;
- }
- else
- {
- alt_table_row_color($k);
- }
-
- $modify = "$path_to_root/purchasing/po_entry_items.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
- $receive = "$path_to_root/purchasing/po_receive_items.php?" . SID . "PONumber=" . $myrow["order_no"];
-
- $date = sql2date($myrow["ord_date"]);
-
- label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
- label_cell($myrow["reference"]);
- label_cell($myrow["supp_name"]);
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
- label_cell($myrow["location_name"]);
- label_cell($myrow["requisition_no"]);
- label_cell($date);
- label_cell($myrow["curr_code"]);
- amount_cell($myrow["OrderValue"]);
- label_cell("<a href=$modify>" . _("Edit") . "</a>");
- label_cell(print_document_link($myrow['order_no'], _("Print"), true, 18));
- label_cell("<a href=$receive>" . _("Receive") . "</a>");
- end_row();
-
- $j++;
- If ($j == 12)
- {
- $j = 1;
- table_header($th);
- }
-//end of page full new headings if
-}
-//end of while loop
-
-end_table();
-
-if ($overdue_items)
- display_note(_("Marked orders have overdue items."), 0, 1, "class='overduefg'");
-div_end();
+ $table->set_sql($sql);
+ $table->set_columns($cols);
+ $Ajax->activate('orders_tbl');
+}
+ start_form();
+ display_db_pager($table);
+ end_form();
end_page();
?>
$page_security = 2;
$path_to_root="../..";
+include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
end_form();
//---------------------------------------------------------------------------------------------
-
if (isset($_POST['order_number']))
{
$order_number = $_POST['order_number'];
}
//---------------------------------------------------------------------------------------------
+function trans_view($trans)
+{
+ return get_trans_view_str(systypes::po(), $trans["order_no"]);
+}
-//figure out the sql required from the inputs available
-$sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.into_stock_location,
- ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference, ".TB_PREF."locations.location_name,
- ".TB_PREF."suppliers.curr_code, Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue
- FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
- WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
- AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
- AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location ";
+function prt_link($row)
+{
+ return print_document_link($row['order_no'], _("Print"), true, 18);
+}
+
+//---------------------------------------------------------------------------------------------
+
+$sql = "SELECT
+ porder.order_no,
+ porder.reference,
+ supplier.supp_name,
+ location.location_name,
+ porder.requisition_no,
+ porder.ord_date,
+ supplier.curr_code,
+ Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
+ porder.into_stock_location
+ FROM ".TB_PREF."purch_orders as porder, "
+ .TB_PREF."purch_order_details as line, "
+ .TB_PREF."suppliers as supplier, "
+ .TB_PREF."locations as location
+ WHERE porder.order_no = line.order_no
+ AND porder.supplier_id = supplier.supplier_id
+ AND location.loc_code = porder.into_stock_location ";
if (isset($order_number) && $order_number != "")
{
- $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
+ $sql .= "AND porder.reference LIKE '%". $order_number . "%'";
}
else
{
$data_after = date2sql($_POST['OrdersAfterDate']);
$date_before = date2sql($_POST['OrdersToDate']);
- $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
- $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$date_before'";
+ $sql .= " AND porder.ord_date >= '$data_after'";
+ $sql .= " AND porder.ord_date <= '$date_before'";
if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
{
- $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
+ $sql .= " AND porder.into_stock_location = '". $_POST['StockLocation'] . "' ";
}
if (isset($selected_stock_item))
{
- $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
+ $sql .= " AND line.item_code='". $selected_stock_item ."' ";
}
} //end not order number selected
-$sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
-
-$result = db_query($sql,"No orders were returned");
-
-div_start('orders_tbl');
-start_table("$table_style colspan=7 width=80%");
-
-if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
- $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
- _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"");
-else
- $th = array(_("#"), _("Reference"), _("Supplier"),
- _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"");
-
-table_header($th);
-
-$j = 1;
-$k = 0; //row colour counter
-while ($myrow = db_fetch($result))
-{
-
- alt_table_row_color($k);
-
- $date = sql2date($myrow["ord_date"]);
-
- label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
- label_cell($myrow["reference"]);
- label_cell($myrow["supp_name"]);
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
- label_cell($myrow["location_name"]);
- label_cell($myrow["requisition_no"]);
- label_cell($date);
- label_cell($myrow["curr_code"]);
- amount_cell($myrow["OrderValue"]);
- label_cell(print_document_link($myrow['order_no'], _("Print"), true, 18));
- end_row();
-
- $j++;
- if ($j == 12)
- {
- $j = 1;
- table_header($th);
- }
+$sql .= " GROUP BY porder.order_no";
+
+$cols = array(
+ _("#") => array('fun'=>'trans_view', 'ord'=>''),
+ _("Reference"),
+ _("Supplier") => array('ord'=>''),
+ _("Location"),
+ _("Supplier's Reference"),
+ _("Order Date") => array('type'=>'date', 'ord'=>'desc'),
+ _("Currency") => array('align'=>'center'),
+ _("Order Total") => 'amount',
+ array('insert'=>true, 'fun'=>'prt_link'),
+);
+
+if (get_post('StockLocation') != $all_items) {
+ $cols[_("Location")] = 'skip';
}
-
-end_table(2);
-div_end();
//---------------------------------------------------------------------------------------------------
+$table =& new_db_pager('orders_tbl', $sql, $cols);
+
+if (get_post('SearchOrders'))
+{
+ $table->set_sql($sql);
+ $table->set_columns($cols);
+ $Ajax->activate('orders_tbl');
+}
+ start_form();
+ display_db_pager($table);
+ end_form();
end_page();
?>
$page_security=2;
$path_to_root="../..";
+include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
end_row();
end_table();
end_form();
+//------------------------------------------------------------------------------------------------
+function check_overdue($row)
+{
+ return ($row['TotalAmount']>$row['Allocated']) &&
+ $row['OverDue'] == 1;
+}
+function systype_name($dummy, $type)
+{
+ return systypes::name($type);
+}
-//------------------------------------------------------------------------------------------------
+function view_link($trans)
+{
+ return get_trans_view_str($trans["type"], $trans["trans_no"]);
+}
-function get_transactions()
+function due_date($row)
{
- global $db;
+ return (($row["type"] == 20) || ($row["type"]== 21))
+ ? $row["due_date"] : "";
+}
- $date_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
+function fmt_balance($row)
+{
+ $value = ($row["type"] == 1 || $row["type"] == 21 || $row["type"] == 22)
+ ? -$row["TotalAmount"] - $row["Allocated"]
+ : $row["TotalAmount"] - $row["Allocated"];
+ return $value;
+}
+
+function alloc_link($row)
+{
+ $link =
+ pager_link(_("Allocations"),
+ "/purchasing/allocations/supplier_allocate.php?trans_no=" .
+ $row["trans_no"]. "&trans_type=" . $row["type"] );
+
+ return (($row["type"] == 1 || $row["type"] == 21 || $row["type"] == 22)
+ && (-$row["TotalAmount"] - $row["Allocated"]) > 0)
+ ? $link : '';
+}
+
+function fmt_debit($row)
+{
+ $value = -$row["TotalAmount"];
+ return $value>=0 ? price_format($value) : '';
+
+}
+
+function fmt_credit($row)
+{
+ $value = $row["TotalAmount"];
+ return $value>0 ? price_format($value) : '';
+}
+//------------------------------------------------------------------------------------------------
+
+ $date_after = date2sql($_POST['TransAfterDate']);
+ $date_to = date2sql($_POST['TransToDate']);
// Sherifoz 22.06.03 Also get the description
- $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
- ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
- (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount) AS TotalAmount, ".TB_PREF."supp_trans.alloc AS Allocated,
- ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
- ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
- FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
- WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
- AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
- AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
+ $sql = "SELECT
+ trans.type,
+ trans.trans_no,
+ trans.reference,
+ supplier.supp_name,
+ trans.supp_reference,
+ trans.tran_date,
+ trans.due_date,
+ supplier.curr_code,
+ (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
+ trans.alloc AS Allocated,
+ ((trans.type = 20 OR trans.type = 21) AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
+ FROM "
+ .TB_PREF."supp_trans as trans, "
+ .TB_PREF."suppliers as supplier
+ WHERE supplier.supplier_id = trans.supplier_id
+ AND trans.tran_date >= '$date_after'
+ AND trans.tran_date <= '$date_to'";
if ($_POST['supplier_id'] != reserved_words::get_all())
- $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
+ $sql .= " AND trans.supplier_id = '" . $_POST['supplier_id'] . "'";
if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
{
if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
{
- $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
+ $sql .= " AND trans.type = 20 ";
}
elseif ($_POST['filterType'] == '3')
{
- $sql .= " AND ".TB_PREF."supp_trans.type = 22 ";
+ $sql .= " AND trans.type = 22 ";
}
elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
{
- $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
+ $sql .= " AND trans.type = 21 ";
}
if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
{
$today = date2sql(Today());
- $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
+ $sql .= " AND trans.due_date < '$today' ";
}
}
$sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
}
- $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
-
- return db_query($sql,"No supplier transactions were returned");
+$cols = array(
+ _("Type") => array('fun'=>'systype_name'),
+ _("Number") => array('fun'=>'view_link', 'ord'=>''),
+ _("Reference"),
+ _("Supplier") => array('ord'=>''),
+ _("Supp Reference"),
+ _("Date") => array('type'=>'date', 'ord'=>'asc'),
+ _("Due Date") => array('fun'=>'due_date'),
+ _("Currency") => array('align'=>'center'),
+ _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
+ _("Credit") => array('align'=>'right', 'insert'=>true, 'fun'=>'fmt_credit'),
+ _("Allocated") => 'amount',
+ _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'fmt_balance'),
+ array('insert'=>true, 'fun'=>'alloc_link')
+ );
+
+if ($_POST['supplier_id'] != reserved_words::get_all()) {
+ $cols[_("Supplier")] = 'skip';
+ $cols[_("Currency")] = 'skip';
}
-
//------------------------------------------------------------------------------------------------
-$result = get_transactions();
-//------------------------------------------------------------------------------------------------
+$table =& new_db_pager('doc_tbl', $sql, $cols);
+$table->set_marker('check_overdue', _("Marked items are overdue."));
+
if(get_post('RefreshInquiry'))
{
+ $table->set_sql($sql);
+ $table->set_columns($cols);
$Ajax->activate('doc_tbl');
}
-//------------------------------------------------------------------------------------------------
-
-/*show a table of the transactions returned by the sql */
-
-div_start('doc_tbl');
-if (db_num_rows($result) == 0)
-{
- display_note(_("There are no transactions to display for the given dates."), 1, 1);
-} else
-{
- start_table("$table_style width=90%");
- if ($_POST['supplier_id'] == reserved_words::get_all())
- $th = array(_("Type"), _("Number"), _("Reference"), _("Supplier"),
- _("Supp Reference"), _("Date"), _("Due Date"), _("Currency"),
- _("Debit"), _("Credit"), _("Allocated"), _("Balance"), "");
- else
- $th = array(_("Type"), _("Number"), _("Reference"), _("Supp Reference"), _("Date"), _("Due Date"),
- _("Debit"), _("Credit"), _("Allocated"), _("Balance"), "");
- table_header($th);
-
- $j = 1;
- $k = 0; //row colour counter
- $over_due = false;
- while ($myrow = db_fetch($result))
- {
-
- if (($myrow['TotalAmount']>$myrow['Allocated']) && $myrow['OverDue'] == 1)
- {
- start_row("class='overduebg'");
- $over_due = true;
- }
- else
- {
- alt_table_row_color($k);
- }
-
- $date = sql2date($myrow["tran_date"]);
-
- $duedate = ((($myrow["type"] == 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
-
-
- label_cell(systypes::name($myrow["type"]));
- label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
- label_cell($myrow["reference"]);
- if ($_POST['supplier_id'] == reserved_words::get_all())
- label_cell($myrow["supp_name"]);
- label_cell($myrow["supp_reference"]);
- label_cell($date);
- label_cell($duedate);
- if ($_POST['supplier_id'] == reserved_words::get_all())
- label_cell($myrow["curr_code"]);
- if ($myrow["TotalAmount"] >= 0)
- label_cell("");
- amount_cell(abs($myrow["TotalAmount"]));
- if ($myrow["TotalAmount"] < 0)
- label_cell("");
- amount_cell($myrow["Allocated"]);
- if ($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22)
- $balance = -$myrow["TotalAmount"] - $myrow["Allocated"];
- else
- $balance = $myrow["TotalAmount"] - $myrow["Allocated"];
- amount_cell($balance);
-
- if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
- $balance > 0)
- {
- label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" .
- $myrow["trans_no"]. "&trans_type=" . $myrow["type"] . "'>" . _("Allocations") . "</a>");
- }
- else
- label_cell("");
-
- end_row();
-
- $j++;
- If ($j == 12)
- {
- $j = 1;
- table_header($th);
- }
- //end of page full new headings if
- }
- //end of while loop
-
- end_table(1);
- if ($over_due)
- display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");
-}
-div_end();
+ start_form();
+ display_db_pager($table);
+ end_form();
end_page();
?>