<?php

function display_unapproved_gL_adjustment_details_inquiry_filters() {

    global $systypes_array, $payment_person_all_types;
    
    $values_array[ST_CASH_PAYMENT] = $systypes_array[ST_CASH_PAYMENT];
    $values_array[ST_CASH_RECEIPT] = $systypes_array[ST_CASH_RECEIPT];
    $values_array[ST_GL_CREDIT] = $systypes_array[ST_GL_CREDIT];
    $values_array[ST_GL_DEBIT] = $systypes_array[ST_GL_DEBIT];


    start_table(TABLESTYLE_NOBORDER);
        start_row();
            ref_cells(_("#:"), 'tran_id');
            ref_cells(_("Reference:"), 'Ref', '',null, _('Enter reference fragment or leave empty'));
//            journal_types_list_cells(_("Type:"), "filterType");
            custom_values_list_cells(_("Type:"), "filterType", $values_array, null, '', true);
        end_row();    
        start_row();
            date_cells(_("From:"), 'FromDate', '', null, -14);
            date_cells(_("To:"), 'ToDate');
//            two_value_list_cells("Status:", 'status', null, "Approved", "Unapproved", AS_APPROVED, 0, true, 'All');
//            custom_values_list_cells(_("Status:"), "status", $status_array, null, false, true);
            gl_all_accounts_list_cells(_("Account:"), 'account', null, false, false, _("All Accounts"));
            
        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_CASH_PAYMENT'", "'GL_TRANS_TYPE_CASH_RECEIPT'", 
                                    "'GL_TRANS_TYPE_GL_CREDIT'", "'GL_TRANS_TYPE_GL_DEBIT'");
            $list_codes_in = implode(',', $gl_tr_tp_array);
            filtered_value_list_cells('GL Trans Type:', 'gl_trans_type_id', $list_codes_in, '', null, '', true); 
            //        end_row();
            ref_cells(_("Line Comment:"), 'Memo', '',null, _('Enter memo fragment or leave empty'));
            submit_cells('Search_UAGLAI', _("Display"), '', '', 'default');
        end_row();
    end_table();


    
    echo '<hr>';
}

function display_unapproved_gL_adjustment_details_inquiry() {
    global $systypes_array, $payment_person_all_types;
        
    $result = get_unapproved_gl_adjustments_details(get_post('filterType',-1), get_post('FromDate'), get_post('ToDate'), 
                                                get_post('Ref'), get_post('tran_id'), get_post('account',''),
                                                get_post('person_type_id',-1), get_post('gl_trans_type_id',-1), get_post('Memo', ''));
    $colspan =6;
	
    start_table(TABLESTYLE, "width=98%");

    $th = array(_("Date"), _("Type"), _("#"), _("Reference"), _("Person Type"), _("Person"), _("GL Trans Type"),
                _("Account"), _("Debit"), _("Credit"), _("Line Comment")); 
    
    table_header($th);

    $k = $j = $running_total = $debits = $credits = 0;
    
    while ($myrow = db_fetch($result)) {

        alt_table_row_color($k);

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

            if($myrow["line_amount"] > 0){
                $debits += $myrow["line_amount"];
            }
            if($myrow["line_amount"] < 0){
                $credits += $myrow["line_amount"];
            }

            $trandate = sql2date($myrow["tran_date"]);
            label_cell($trandate);

            label_cell($systypes_array[$myrow["type"]]);
            label_cell(get_journal_trans_view_str($myrow["type"], $myrow["trans_no"], $myrow["trans_no"]));

            label_cell($myrow["reference"]);
            
            label_cell($payment_person_all_types[$myrow["person_type_id"]]);

            label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"], true, $myrow['person_detail_id']));
            
            label_cell($myrow["gl_trans_type_name"]);
            
             
             
            $account_formatted_name = get_gl_account_formatted_name($myrow["account"]);
            label_cell($account_formatted_name);

            display_debit_or_credit_cells($myrow["line_amount"]);
            
            label_cell($myrow["memo_"]);

        end_row();

        $j++;
        if ($j == 12) {
            $j = 1;
            table_header($th);
        }
    }


                start_row("class='inquirybg'");
                    label_cell("<b>" . _("Total") . "</b>", "colspan=8 align=right");
                    amount_cell($debits, true);
                    amount_cell(abs($credits), true); 
                    label_cell("", "colspan=1");
                end_row();
            

	end_table(2);
        
	if (db_num_rows($result) == 0)
            display_note(_("No transactions have been created for the specified criteria."), 0, 1);

}

?>