<?php

function display_bank_account_inquiry_filtering_controls()
{
    global $payment_person_all_types;
    
    start_form();
    start_table(TABLESTYLE_NOBORDER);
    start_row();
    bank_accounts_list_cells(_("Account:"), 'bank_account', null);

    date_cells(_("From:"), 'TransAfterDate', '', null, -30);
    date_cells(_("To:"), 'TransToDate');
    
    
    end_row();
    start_row();
//    bank_transaction_types_list_cells("Type", 'filtering_tran_type', null, '', true);
    systypes_list_cells("Type", 'filtering_tran_type', null, true, array(), '');
    two_value_list_cells("Debits / Credits", 'debit_credit', null, "Debits", "Credits", 1, 2, true, '');
    two_value_list_cells("Reconciled / Open", 'reconciled_open', null, "Reconciled", "Open", 1, 2, true, '');
    
    end_row();
    start_row();
    
    $payment_person_all_types[-1] = '';
    ksort($payment_person_all_types);
    custom_values_list_cells('Person Type:', 'person_type_id', $payment_person_all_types, null, false, true);

    $gl_tr_tp_array = array("'GL_TRANS_TYPE_BANKPAYMENT'", "'GL_TRANS_TYPE_BANKDEPOSIT'", "'GL_TRANS_TYPE_CASH_PAYMENT'", 
                            "'GL_TRANS_TYPE_CASH_RECEIPT'", "'GL_TRANS_TYPE_GL_CREDIT'", "'GL_TRANS_TYPE_GL_DEBIT'", "'GL_TRANS_TYPE_JOURNAL'");
    $list_codes_in = implode(',', $gl_tr_tp_array);
    filtered_value_list_cells('GL Trans Type:', 'gl_trans_type_id', $list_codes_in, '', null, '', true); 

    
    submit_cells('Show',_("Show"),'','', 'default');
    end_row();
    end_table(2);
    end_form();
}


function display_bank_account_inquiry_details($bank_account, $from_date, $to_date, $filtering_tran_type, $debit_credit, $reconciled_open, 
                                              $person_type_id, $gl_trans_type_id) {
    global $systypes_array;
    
    $result = get_bank_trans_for_bank_account($bank_account, $from_date, $to_date, $filtering_tran_type, $debit_credit, $reconciled_open, 
                                              $person_type_id, $gl_trans_type_id);	

    $act = get_bank_account($_POST["bank_account"]);
    display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);

    
    start_table(TABLESTYLE, "width=98%");

    $th = array(_("Type"), _("#"), _("Reference"), _("Date"), _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), _("GL Trans Type"), 
                _("Memo"),  _("Rec. Date"),""); 
    
    table_header($th);

    $bfw = get_balance_before_for_bank_account($bank_account, $from_date);

    $credit = $debit = 0;
    start_row("class='inquirybg' style='font-weight:bold'");
    label_cell(_("Opening Balance")." - ".$to_date, "colspan=4");
    display_debit_or_credit_cells($bfw);
    label_cell("");
    label_cell("", "colspan=2");

    end_row();
    $running_total = $bfw;
    if ($bfw > 0 ) 
            $debit += $bfw;
    else 
            $credit += $bfw;
    $j = 1;
    $k = 0; //row colour counter
    while ($myrow = db_fetch($result))
    {

	alt_table_row_color($k);

	$running_total += $myrow["amount"];

	$trandate = sql2date($myrow["trans_date"]);
	label_cell($systypes_array[$myrow["type"]]);
	label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
	label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
	label_cell($trandate);
	display_debit_or_credit_cells($myrow["amount"]);
	amount_cell($running_total);
	label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
	label_cell($myrow["gl_trans_type_name"]);
	label_cell(get_comments_string($myrow["type"], $myrow["trans_no"]));
        label_cell(sql2date($myrow["reconciled"]), 'align=center');
	label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
        
	end_row();
 	if ($myrow["amount"] > 0 ) 
 		$debit += $myrow["amount"];
 	else 
 		$credit += $myrow["amount"];

	if ($j == 12)
	{
		$j = 1;
		table_header($th);
	}
	$j++;
    }
    //end of while loop

    start_row("class='inquirybg' style='font-weight:bold'");
    label_cell(_("Ending Balance")." - ". $to_date, "colspan=4");
    amount_cell($debit);
    amount_cell(-$credit);
    //display_debit_or_credit_cells($running_total);
    amount_cell($debit+$credit);
    label_cell("");
    label_cell("", "colspan=4");
    end_row();
    end_table(2);
}