}
//---------------------------------------------------------------------------------------------
function trans_view($trans)
{
    return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
}
function edit_link($row)
{
    if (@$_GET['popup']) {
        return '';
    }
    return pager_link(_("Edit"), "/purchasing/po_entry_items.php?" . SID . "ModifyOrderNumber=" . $row["order_no"], ICON_EDIT);
}
function prt_link($row)
{
    return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
}
//---------------------------------------------------------------------------------------------
$sql = get_sql_for_po_search_completed();
$cols = array(_("#") => array('fun' => 'trans_view', 'ord' => ''), _("Reference"), _("Supplier") => array('ord' => ''), _("Location"), _("Supplier's Reference"), _("Order Date") => array('name' => 'ord_date', 'type' => 'date', 'ord' => 'desc'), _("Currency") => array('align' => 'center'), _("Order Total") => 'amount', array('insert' => true, 'fun' => 'edit_link'), array('insert' => true, 'fun' => 'prt_link'));
if (get_post('StockLocation') != $all_items) {
    $cols[_("Location")] = 'skip';
}
//---------------------------------------------------------------------------------------------------
$table =& new_db_pager('orders_tbl', $sql, $cols);
$table->width = "80%";
display_db_pager($table);
if (!@$_GET['popup']) {
    end_form();
    end_page();
}
    } elseif ($row['type'] == ST_BANKPAYMENT) {
        // bank payment printout not defined yet.
        return '';
    } else {
        return print_document_link($row['trans_no'] . "-" . $row['type'], _("Print"), true, $row['type'], ICON_PRINT);
    }
}
function check_overdue($row)
{
    return $row['OverDue'] == 1 && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
}
//------------------------------------------------------------------------------------------------
$sql = get_sql_for_customer_inquiry();
//------------------------------------------------------------------------------------------------
db_query("set @bal:=0");
$cols = array(_("Type") => array('fun' => 'systype_name', 'ord' => ''), _("#") => array('fun' => 'trans_view', 'ord' => ''), _("Order") => array('fun' => 'order_view'), _("Reference"), _("Date") => array('name' => 'tran_date', 'type' => 'date', 'ord' => 'desc'), _("Due Date") => array('type' => 'date', 'fun' => 'due_date'), _("Customer") => array('ord' => ''), _("Branch") => array('ord' => ''), _("Currency") => array('align' => 'center'), _("Debit") => array('align' => 'right', 'fun' => 'fmt_debit'), _("Credit") => array('align' => 'right', 'insert' => true, 'fun' => 'fmt_credit'), _("RB") => array('align' => 'right', 'type' => 'amount'), array('insert' => true, 'fun' => 'gl_view'), array('insert' => true, 'fun' => 'credit_link'), array('insert' => true, 'fun' => 'edit_link'), array('insert' => true, 'fun' => 'prt_link'));
if ($_POST['customer_id'] != ALL_TEXT) {
    $cols[_("Customer")] = 'skip';
    $cols[_("Currency")] = 'skip';
}
if ($_POST['filterType'] == ALL_TEXT) {
    $cols[_("RB")] = 'skip';
}
$table =& new_db_pager('trans_tbl', $sql, $cols);
$table->set_marker('check_overdue', _("Marked items are overdue."));
$table->width = "85%";
display_db_pager($table);
if (!@$_GET['popup']) {
    end_form();
    end_page(@$_GET['popup'], false, false);
}
    } elseif ($row["type"] == ST_CUSTPAYMENT && $row['TotalAmount'] <= 0) {
        /*its a negative receipt */
        return '';
    } elseif ($row["type"] == ST_SALESINVOICE && $row['TotalAmount'] - $row['Allocated'] > 0) {
        return pager_link(_("Payment"), "/sales/customer_payments.php?customer_id=" . $row["debtor_no"] . "&SInvoice=" . $row["trans_no"], ICON_MONEY);
    }
}
function fmt_debit($row)
{
    $value = $row['type'] == ST_CUSTCREDIT || $row['type'] == ST_CUSTPAYMENT || $row['type'] == ST_BANKDEPOSIT ? -$row["TotalAmount"] : $row["TotalAmount"];
    return $value >= 0 ? price_format($value) : '';
}
function fmt_credit($row)
{
    $value = !($row['type'] == ST_CUSTCREDIT || $row['type'] == ST_CUSTPAYMENT || $row['type'] == ST_BANKDEPOSIT) ? -$row["TotalAmount"] : $row["TotalAmount"];
    return $value > 0 ? price_format($value) : '';
}
//------------------------------------------------------------------------------------------------
$sql = get_sql_for_customer_allocation_inquiry(get_post('TransAfterDate'), get_post('TransToDate'), get_post('customer_id'), get_post('filterType'), check_value('showSettled'));
//------------------------------------------------------------------------------------------------
$cols = array(_("Type") => array('fun' => 'systype_name'), _("#") => array('fun' => 'view_link'), _("Reference"), _("Order") => array('fun' => 'order_link', 'ord' => ''), _("Date") => array('name' => 'tran_date', 'type' => 'date', 'ord' => 'asc'), _("Due Date") => array('type' => 'date', 'fun' => 'due_date'), _("Customer") => array('name' => 'name', 'ord' => 'asc'), _("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['customer_id'] != ALL_TEXT) {
    $cols[_("Customer")] = 'skip';
    $cols[_("Currency")] = 'skip';
}
$table =& new_db_pager('doc_tbl', $sql, $cols);
$table->set_marker('check_overdue', _("Marked items are overdue."));
$table->width = "80%";
display_db_pager($table);
end_form();
end_page();
function prt_link($row)
{
    return print_document_link($row['trans_no'], _("Print"), true, ST_CUSTDELIVERY, ICON_PRINT);
}
function invoice_link($row)
{
    return $row["Outstanding"] == 0 ? '' : pager_link(_('Invoice'), "/sales/customer_invoice.php?DeliveryNumber=" . $row['trans_no'], ICON_DOC);
}
function check_overdue($row)
{
    return date1_greater_date2(Today(), sql2date($row["due_date"])) && $row["Outstanding"] != 0;
}
//------------------------------------------------------------------------------------------------
$sql = get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item, $_POST['customer_id']);
$cols = array(_("Delivery #") => array('fun' => 'trans_view'), _("Customer"), 'branch_code' => 'skip', _("Branch") => array('ord' => ''), _("Contact"), _("Reference"), _("Cust Ref"), _("Delivery Date") => array('type' => 'date', 'ord' => ''), _("Due By") => 'date', _("Delivery Total") => array('type' => 'amount', 'ord' => ''), _("Currency") => array('align' => 'center'), submit('BatchInvoice', _("Batch"), false, _("Batch Invoicing")) => array('insert' => true, 'fun' => 'batch_checkbox', 'align' => 'center'), array('insert' => true, 'fun' => 'edit_link'), array('insert' => true, 'fun' => 'invoice_link'), array('insert' => true, 'fun' => 'prt_link'));
//-----------------------------------------------------------------------------------
if (isset($_SESSION['Batch'])) {
    foreach ($_SESSION['Batch'] as $trans => $del) {
        unset($_SESSION['Batch'][$trans]);
    }
    unset($_SESSION['Batch']);
}
$table =& new_db_pager('deliveries_tbl', $sql, $cols);
$table->set_marker('check_overdue', _("Marked items are overdue."));
//$table->width = "92%";
display_db_pager($table);
end_form();
end_page();
?>

function voiding_controls()
{
    global $selected_id;
    $not_implemented = array(ST_PURCHORDER, ST_SALESORDER, ST_SALESQUOTE, ST_COSTUPDATE);
    start_form();
    start_table(TABLESTYLE_NOBORDER);
    start_row();
    systypes_list_cells(_("Type:"), 'filterType', null, true, $not_implemented);
    if (list_updated('filterType')) {
        $selected_id = -1;
    }
    if (!isset($_POST['FromTransNo'])) {
        $_POST['FromTransNo'] = "1";
    }
    if (!isset($_POST['ToTransNo'])) {
        $_POST['ToTransNo'] = "999999";
    }
    ref_cells(_("from #:"), 'FromTransNo');
    ref_cells(_("to #:"), 'ToTransNo');
    submit_cells('ProcessSearch', _("Search"), '', '', 'default');
    end_row();
    end_table(1);
    $trans_ref = false;
    $sql = get_sql_for_view_transactions($_POST['filterType'], $_POST['FromTransNo'], $_POST['ToTransNo'], $trans_ref);
    if ($sql == "") {
        return;
    }
    $cols = array(_("#") => array('insert' => true, 'fun' => 'view_link'), _("Reference") => array('fun' => 'ref_view'), _("Date") => array('type' => 'date', 'fun' => 'date_view'), _("GL") => array('insert' => true, 'fun' => 'gl_view'), _("Select") => array('insert' => true, 'fun' => 'select_link'));
    $table =& new_db_pager('transactions', $sql, $cols);
    $table->width = "40%";
    display_db_pager($table);
    start_table(TABLESTYLE2);
    if ($selected_id != -1) {
        hidden('trans_no', $selected_id);
        hidden('selected_id', $selected_id);
    } else {
        hidden('trans_no', '');
        $_POST['memo_'] = '';
    }
    label_row(_("Transaction #:"), $selected_id == -1 ? '' : $selected_id);
    date_row(_("Voiding Date:"), 'date_');
    textarea_row(_("Memo:"), 'memo_', null, 30, 4);
    end_table(1);
    if (!isset($_POST['ProcessVoiding'])) {
        submit_center('ProcessVoiding', _("Void Transaction"), true, '', 'default');
    } else {
        if (!exist_transaction($_POST['filterType'], $_POST['trans_no'])) {
            display_error(_("The entered transaction does not exist or cannot be voided."));
            unset($_POST['trans_no']);
            unset($_POST['memo_']);
            unset($_POST['date_']);
            submit_center('ProcessVoiding', _("Void Transaction"), true, '', 'default');
        } else {
            display_warning(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
            br();
            submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
            submit_center_last('CancelVoiding', _("Cancel"), '', 'cancel');
        }
    }
    end_form();
}
<?php

$page_security = 'SA_WORKORDERANALYTIC';
$path_to_root = "../..";
include $path_to_root . "/includes/db_pager.inc";
include $path_to_root . "/includes/session.inc";
page(_($help_context = "Inventory Item Where Used Inquiry"));
include $path_to_root . "/includes/ui.inc";
check_db_has_stock_items(_("There are no items defined in the system."));
start_form(false, true);
if (!isset($_POST['stock_id'])) {
    $_POST['stock_id'] = get_global_stock_item();
}
echo "<center>" . _("Select an item to display its parent item(s).") . "&nbsp;";
echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
echo "<hr></center>";
set_global_stock_item($_POST['stock_id']);
//-----------------------------------------------------------------------------
function select_link($row)
{
    return pager_link($row["parent"] . " - " . $row["description"], "/manufacturing/manage/bom_edit.php?stock_id=" . $row["parent"]);
}
$sql = get_sql_for_where_used();
$cols = array(_("Parent Item") => array('fun' => 'select_link'), _("Work Centre"), _("Location"), _("Quantity Required"));
$table =& new_db_pager('usage_table', $sql, $cols);
$table->width = "80%";
display_db_pager($table);
end_form();
end_page();
function handle_search()
{
    if (check_valid_entries() == true) {
        $trans_ref = false;
        $sql = get_sql_for_view_transactions($_POST['filterType'], $_POST['FromTransNo'], $_POST['ToTransNo'], $trans_ref);
        if ($sql == "") {
            return;
        }
        $print_type = $_POST['filterType'];
        $print_out = $print_type == ST_SALESINVOICE || $print_type == ST_CUSTCREDIT || $print_type == ST_CUSTDELIVERY || $print_type == ST_PURCHORDER || $print_type == ST_SALESORDER || $print_type == ST_SALESQUOTE || $print_type == ST_CUSTPAYMENT || $print_type == ST_SUPPAYMENT || $print_type == ST_WORKORDER;
        $cols = array(_("#") => array('insert' => true, 'fun' => 'view_link'), _("Reference") => array('fun' => 'ref_view'), _("Date") => array('type' => 'date', 'fun' => 'date_view'), _("Print") => array('insert' => true, 'fun' => 'prt_link'), _("GL") => array('insert' => true, 'fun' => 'gl_view'));
        if (!$print_out) {
            array_remove($cols, 3);
        }
        if (!$trans_ref) {
            array_remove($cols, 1);
        }
        $table =& new_db_pager('transactions', $sql, $cols);
        $table->width = "40%";
        display_db_pager($table);
    }
}
function view_link($row)
{
    return get_trans_view_str($row["type"], $row["type_no"]);
}
function gl_link($row)
{
    return get_gl_view_str($row["type"], $row["type_no"]);
}
$editors = array(ST_JOURNAL => "/gl/gl_journal.php?ModifyGL=Yes&trans_no=%d&trans_type=%d", ST_BANKPAYMENT => "/gl/gl_bank.php?ModifyPayment=Yes&trans_no=%d&trans_type=%d", ST_BANKDEPOSIT => "/gl/gl_bank.php?ModifyDeposit=Yes&trans_no=%d&trans_type=%d", ST_SALESINVOICE => "/sales/customer_invoice.php?ModifyInvoice=%d", ST_CUSTDELIVERY => "/sales/customer_delivery.php?ModifyDelivery=%d");
function edit_link($row)
{
    global $editors;
    $ok = true;
    if ($row['type'] == ST_SALESINVOICE) {
        $myrow = get_customer_trans($row["type_no"], $row["type"]);
        if ($myrow['alloc'] != 0 || get_voided_entry(ST_SALESINVOICE, $row["type_no"]) !== false) {
            $ok = false;
        }
    }
    return isset($editors[$row["type"]]) && !is_closed_trans($row["type"], $row["type_no"]) && $ok ? pager_link(_("Edit"), sprintf($editors[$row["type"]], $row["type_no"], $row["type"]), ICON_EDIT) : '';
}
$sql = get_sql_for_journal_inquiry(get_post('filterType', -1), get_post('FromDate'), get_post('ToDate'), get_post('Ref'), get_post('Memo'), check_value('AlsoClosed'));
$cols = array(_("#") => array('fun' => 'journal_pos', 'align' => 'center'), _("Date") => array('name' => 'tran_date', 'type' => 'date', 'ord' => 'desc'), _("Type") => array('fun' => 'systype_name'), _("Trans #") => array('fun' => 'view_link'), _("Reference"), _("Amount") => array('type' => 'amount'), _("Memo"), _("User"), _("View") => array('insert' => true, 'fun' => 'gl_link'), array('insert' => true, 'fun' => 'edit_link'));
if (!check_value('AlsoClosed')) {
    $cols[_("#")] = 'skip';
}
$table =& new_db_pager('journal_tbl', $sql, $cols);
$table->width = "80%";
display_db_pager($table);
end_form();
end_page();
function display_rows($type)
{
    $sql = get_sql_for_attached_documents($type);
    $cols = array(_("#") => array('fun' => 'trans_view', 'ord' => ''), _("Description") => array('name' => 'description'), _("Filename") => array('name' => 'filename'), _("Size") => array('name' => 'filesize'), _("Filetype") => array('name' => 'filetype'), _("Date Uploaded") => array('name' => 'tran_date', 'type' => 'date'), array('insert' => true, 'fun' => 'edit_link'), array('insert' => true, 'fun' => 'view_link'), array('insert' => true, 'fun' => 'download_link'), array('insert' => true, 'fun' => 'delete_link'));
    $table =& new_db_pager('trans_tbl', $sql, $cols);
    $table->width = "60%";
    display_db_pager($table);
}
    end_outer_table(1);
    submit_add_or_update_center($selected_id == -1, '', 'both');
}
start_form();
echo "<center>" . _("Select a customer: ") . "&nbsp;&nbsp;";
echo customer_list('customer_id', null, false, true);
echo "</center><br>";
$num_branches = db_customer_has_branches($_POST['customer_id']);
$sql = get_sql_for_customer_branches();
//------------------------------------------------------------------------------------------------
if ($num_branches) {
    $cols = array('branch_code' => 'skip', _("Short Name"), _("Name"), _("Contact"), _("Sales Person"), _("Area"), _("Phone No"), _("Fax No"), _("E-mail") => 'email', _("Tax Group"), _("Inactive") => 'inactive', ' ' => array('insert' => true, 'fun' => 'select_link'), array('insert' => true, 'fun' => 'edit_link'), array('insert' => true, 'fun' => 'del_link'));
    if (!@$_REQUEST['popup']) {
        $cols[' '] = 'skip';
    }
    $table =& new_db_pager('branch_tbl', $sql, $cols, 'cust_branch');
    $table->set_inactive_ctrl('cust_branch', 'branch_code');
    //$table->width = "85%";
    display_db_pager($table);
} else {
    display_note(_("The selected customer does not have any branches. Please create at least one branch."));
}
tabbed_content_start('tabs', array('settings' => array(_('&General settings'), $selected_id != -1), 'contacts' => array(_('&Contacts'), $selected_id != -1)));
switch (get_post('_tabs_sel')) {
    default:
    case 'settings':
        branch_settings($selected_id);
        break;
    case 'contacts':
        $contacts = new contacts('contacts', $selected_id, 'cust_branch');
        $contacts->show();