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



function display_gl_batch_header_view($gl_batch_no)
{
    global $systypes_array;

        display_heading($systypes_array[ST_GL_BATCH]." #".$gl_batch_no);


        $gl_batch_h = view_gl_batch_header($gl_batch_no);
        
        if($gl_batch_h['deleted_by'] > 0){
            start_table(TABLESTYLE2, "width=80%");
            $th = array(_("GL Batch No"), _("Type"), _("Transaction Date"), _("Created By"), _("Created On"), _("Deleted By"), _("Deleted On"));
        }else{
            start_table(TABLESTYLE2, "width=60%");
            $th = array(_("GL Batch No"), _("Type"), _("Transaction Date"), _("Created By"), _("Created On"));
            
        }

        table_header($th);

        label_cell($gl_batch_no, "align=center");
        label_cell($systypes_array[$gl_batch_h['gl_batch_type']]);
        label_cell(sql2date($gl_batch_h['tran_date']), "align=center");
        label_cell($gl_batch_h['created_user_name'], "align=center");
        label_cell($gl_batch_h['created_on'], "align=center");
        
        if($gl_batch_h['deleted_by'] > 0){
            label_cell($gl_batch_h['deleted_user_name'], "align=center");
            label_cell($gl_batch_h['deleted_on'], "align=center");
        }

        end_table(1);

        if($gl_batch_h['deleted_by'] > 0){
            br(1);
            $deleted_msg = "This ".$systypes_array[ST_GL_BATCH]." has been deleted and it has no ".$systypes_array[ST_FI_BATCH]."es.";
            display_note($deleted_msg);
            return 0;
        }


        display_heading("FI Batches");

        start_table(TABLESTYLE2, "width=70%");


        $result = view_gl_batch_details($gl_batch_no);
        
        $records = db_num_rows($result);

        $th = array(_("FI Batch No"), _("Type"), _("Cutoff Date"), _("Transaction Count"), _("Total"), _("Created By"), _("Created On"));               

        table_header($th);

        $k=0;
        $credit = $debit = 0;
        while($myrow = db_fetch($result)){

            global $systypes_array;

            alt_table_row_color($k);

            $link = get_journal_trans_view_str(ST_FI_BATCH, $myrow['id']);
            label_cell($link, "align=center");  
            
            label_cell($systypes_array[$myrow['trans_type']]);   
            label_cell($myrow['cutoff_date']);   

            $transaction_count = get_fi_batch_transaction_count($myrow['id']);
            label_cell($transaction_count, "align=center");  

            $fi_batch_total = get_fi_batch_total($myrow['id']);
            label_cell(number_format($fi_batch_total,2), "align=right");   

            label_cell($myrow['real_name'], "align=center");   
            label_cell($myrow['created_on'], "align=center");  
        }

//    start_row("class='inquirybg' style='font-weight:bold'");
//    label_cell(_("Total". spaces(10)), "colspan=4 align=right");
//    amount_cell($debit);
//    amount_cell(-$credit);
//    
//    end_row();
	end_table(1);
        
     return $records;
}