<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_RECONCILE';
$path_to_root = "../..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/db/bank_account_transactions_mismatches_inquiry_db.inc");
include_once($path_to_root . "/gl/includes/db/gl_db_bank_accounts.inc");



$js = '';
set_focus('account');
if ($SysPrefs->use_popup_windows)
    $js .= get_js_open_window(800, 500);
if (user_use_date_picker())
    $js .= get_js_date_picker();

page(_($help_context = "Bank GL Mismatches Inquiry"), false, false, '', $js);

global $Ajax;

function display_bank_account_transactions_mismatched_inquiry($bank_account_id) 
{
    
    
    
    global $systypes_array;
    start_table(TABLESTYLE, "width=75%");
        $th = array(_("Trans Type"),  _("Trans#"), _("Tran Date"), 
                    _("Bank Tran#"), _("Bank Amount"), 
                    _("FI Tran#"), _("FI Amount"), 
                    _("GL Tran#"), _("GL Amount"),                     
                    _("Bank To GL/FI Comparison"));
        table_header($th);
        
        if(!($bank_account_id > 0)){
            end_table(2);
//        br(2);
        display_note("Please select a bank account");
        
        return;
    }

        $bank_account = get_bank_account($bank_account_id);
        $result = get_bank_account_transactions_mismatched($bank_account_id, $bank_account['account_code']);
        $k = $j = 0; //row colour counter
        while ($row = db_fetch($result)) {
            alt_table_row_color($k);
            
            $comparission_name = "";
                if ($row['bank_gl_fi_tran_type'] == 'Bank GL') {
                    $bank_tran_id = $row['bank_gl_fi_tran_id']; 
                    $gl_tran_id = $fi_tran_id = '';
                    $comparission_name = "Bank: Yes, GL: No";
                } elseif ($row['bank_gl_fi_tran_type'] == 'GL Bank') {
                    $gl_tran_id = $row['bank_gl_fi_tran_id']; 
                    $bank_tran_id = $fi_tran_id = '';
                    $comparission_name = "GL: Yes, Bank: No";
                } elseif ($row['bank_gl_fi_tran_type'] == 'Bank FI') {
                    $bank_tran_id = $row['bank_gl_fi_tran_id']; 
                    $gl_tran_id = $fi_tran_id = '';
                    $comparission_name = "Bank: Yes, FI: No";
                } elseif ($row['bank_gl_fi_tran_type'] == 'FI Bank') {
                    $fi_tran_id = $row['bank_gl_fi_tran_id'];
                    $bank_tran_id = $gl_tran_id = '';
                    $comparission_name = "FI: Yes, Bank: No";
                }
                
                
                label_cell($systypes_array[$row["type"]]);
                $link = get_trans_view_str($row["type"], $row["tran_no"]);
                label_cell($link, 'align=center');
                label_cell(($row["tran_date"]!= '0000-00-00') ? sql2date($row["tran_date"]) : '', 'align=center');
                label_cell($bank_tran_id, 'align=center');
                if ($row["bank_amount"] !== null) {
                    label_cell(number_format($row["bank_amount"], 2), 'align=right');
                } else {
                    label_cell(number_format(0, 2), 'align=right');
                }
                label_cell($fi_tran_id, 'align=center');
                if ($row["fi_amount"] !== null) {
                    label_cell(number_format($row["fi_amount"], 2), 'align=right');
                } else {
                    label_cell(number_format(0, 2), 'align=right');
                }
                label_cell($gl_tran_id, 'align=center');
                label_cell(number_format($row["gl_amount"], 2), 'align=right');
                
                label_cell($comparission_name);
            end_row();
        }
    end_table(2);
}

start_form();

    start_table();
        bank_accounts_list_cells('Bank Account:', 'bank_account_id', null, true, 'Select a bank account');
        submit_cells('Search', _("Search"), '', '', 'default');
    end_table(2);

    $Ajax->activate('bank_account_transactions_mismatched');
    div_start('bank_account_transactions_mismatched');
        display_bank_account_transactions_mismatched_inquiry($_POST['bank_account_id']);
    div_end();

end_form();

end_page();

?>
