<?php

function display_iou_bank_payments_inquiry_filtering_controls()
{
    global $systypes_array;
    
    
    start_table(TABLESTYLE_NOBORDER);
    start_row();
    
//    amount_cells("IOU No.", 'iou_no', null, null, null, 0);
//    ref_cells("IOU No.", 'iou_no');
    text_cells("Trans. #.", 'filtering_trans_no', null, 6);
    text_cells("IOU #.", 'iou_no', null, 6);
    project_list_cells(_("Project:"), 'project_id', null, _('All projects'));
    end_row();
    
    start_row();
    $trans_types[ST_IOU_BANKPAYMENT] = $systypes_array[ST_IOU_BANKPAYMENT];
    $trans_types[ST_IOU_BANKPAYMENT_RETURN] = $systypes_array[ST_IOU_BANKPAYMENT_RETURN];
    
    custom_values_list_cells('Trans. Type:', 'filtering_tran_type', $trans_types, null, '', true);
//    systypes_list_cells("Type", 'filtering_tran_type', null, true, array(), '');
    bank_accounts_list_cells(_("Bank Account:"), 'bank_account', null, true, '');

    end_row();
    
    start_row();
    
    date_cells(_("From Date:"), 'from_date', '', null, -30);
    date_cells(_("To Date:"), 'to_date');

//    bank_transaction_types_list_cells("Type", 'filtering_tran_type', null, '', true);
    
    
    submit_cells('Show',_("Display"),'','', 'default');
    end_row();
    end_table(1);

}



function systype_name($dummy, $type)
{
	global $systypes_array;
	
	return $systypes_array[$type];
}

function view_link($row) 
{
	return get_trans_view_str($row["type"], $row["trans_no"]);
}

function gl_link($row) 
{
	return get_gl_view_str($row["type"], $row["trans_no"]);
}

function _project_name($row) {

        return $row['project_description'];
}
function _iou_link($row) {
    return get_petty_cash_trans_view_str(ST_I_OWE_YOU, $row["person_id"]);
}

function _tran_date($row) {
    return sql2date($row['trans_date']);
}

function _reference($row) {
    return $row['ref'];
}

function _memo($row) {
    
    return get_comments_string($row["type"], $row["trans_no"]);
        
}

function _amount($row) {
    
    return number_format(-$row["amount"],2);
        
}

function display_iou_bank_payments_inquiry(){
    
    $sql = get_sql_for_iou_bank_payments_inquiry($_POST['bank_account'], get_post('from_date'), get_post('to_date'), get_post('filtering_tran_type'),
                                        get_post('filtering_trans_no'), get_post('project_id'), get_post('iou_id'));

    $cols = array( 
            _("Date") =>array('fun'=>'_tran_date', 'align'=>'center'),
            _("Type") => array('fun'=>'systype_name'), 
            _("Trans #") => array('fun'=>'view_link', 'align'=>'center'),
            _("Reference")=> array('fun'=>'_reference'),
            _("IOU #") => array('fun'=>'_iou_link', 'align'=>'center'),
            _("Project") => array('fun'=>'_project_name'), 
            _("Amount") => array('fun'=>'_amount', 'align'=>'right'),
            _("Memo") => array('fun'=>'_memo') 

            //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);
} 