<?php 
    }
    ?>
				   		
                </TR>
                <TR> 
                  <TD bgColor="#e1e1e1" colSpan=<?php 
    echo $FG_TOTAL_TABLE_COL;
    ?>
 height="1">
                </TR>
				<?php 
    $ligne_number = 0;
    foreach ($list as $recordset) {
        $ligne_number++;
        $recordset[0] = display_GMT($recordset[0], $_SESSION["gmtoffset"], 1);
        ?>
				
               		 <TR bgcolor="<?php 
        echo $FG_TABLE_ALTERNATE_ROW_COLOR[$ligne_number % 2];
        ?>
"  onMouseOver="bgColor='#C4FFD7'" onMouseOut="bgColor='<?php 
        echo $FG_TABLE_ALTERNATE_ROW_COLOR[$ligne_number % 2];
        ?>
'"> 
						<TD align="<?php 
        echo $FG_TABLE_COL[$i][3];
        ?>
" class="tableBody"><?php 
        echo $ligne_number + $current_page * $FG_LIMITE_DISPLAY . ".&nbsp;";
        ?>
$clause_last_billing = "id_card = " . $_SESSION["card_id"];
$result = $billing_table->Get_list($DBHandle, $clause_last_billing, "date", "desc");
$call_table = new Table('cc_call', 'COALESCE(SUM(sessionbill),0)');
$clause_call_billing = "card_id = " . $_SESSION["card_id"] . " AND ";
$clause_charge = "id_cc_card = " . $_SESSION["card_id"] . " AND ";
$desc_billing = "";
$desc_billing_postpaid = "";
$start_date = null;
if (is_array($result) && !empty($result[0][0])) {
    $clause_call_billing .= "stoptime >= '" . $result[0][1] . "' AND ";
    $clause_charge .= "creationdate >= '" . $result[0][1] . "' AND  ";
    $desc_billing = gettext("Cost of calls between the ") . display_GMT($result[0][1], $_SESSION["gmtoffset"], 1) . " and " . display_GMT(gmdate("Y/m/d H:i:s"), $_SESSION["gmtoffset"], 1);
    $desc_billing_postpaid = "Amount for periode between the " . date("Y-m-d", strptime($result[0][1])) . " and {$date_bill}";
    $start_date = $result[0][1];
} else {
    $desc_billing = gettext("Cost of calls before the ") . display_GMT(gmdate("Y/m/d H:i:s"), $_SESSION["gmtoffset"], 1);
}
$clause_call_billing .= "stoptime < NOW() ";
$clause_charge .= "creationdate < NOW() ";
$result_calls = $call_table->Get_list($DBHandle, $clause_call_billing);
$receipt_items = array();
// COMMON BEHAVIOUR FOR PREPAID AND POSTPAID ... GENERATE A RECEIPT FOR THE CALLS OF THE MONTH
if (is_array($result_calls)) {
    $item = new ReceiptItem(null, $desc_billing, gmdate("Y/m/d H:i:s"), $result_calls[0][0], 'CALLS');
    $receipt_items[] = $item;
}
// GENERATE RECEIPT FOR CHARGE ALREADY CHARGED
$table_charge = new Table("cc_charge", "*");
$result = $table_charge->Get_list($DBHandle, $clause_charge . " AND charged_status = 1");
if (is_array($result)) {
    foreach ($result as $charge) {
            } else {
                $record_display = $recordset[$i];
            }
            if (is_numeric($FG_TABLE_COL[$i][5]) && strlen($record_display) > $FG_TABLE_COL[$i][5]) {
                $record_display = substr($record_display, 0, $FG_TABLE_COL[$i][5] - 3) . "";
            }
            ?>
                 		 <TD align="<?php 
            echo $FG_TABLE_COL[$i][3];
            ?>
" class="invoice_td_rightborder"><?php 
            if (isset($FG_TABLE_COL[$i][11]) && strlen($FG_TABLE_COL[$i][11]) > 1) {
                call_user_func($FG_TABLE_COL[$i][11], $record_display);
            } else {
                if ($i == 0) {
                    echo display_GMT($record_display, $_SESSION["gmtoffset"], 1);
                } else {
                    echo stripslashes($record_display);
                }
            }
            ?>
</TD>
				 		 <?php 
        }
    }
    //foreach ($list as $recordset)
    if ($ligne_number < $FG_LIMITE_DISPLAY) {
        $ligne_number_end = $ligne_number + 2;
    }
    while ($ligne_number < $ligne_number_end) {
        $ligne_number++;
            echo gettext("DESCRIPTION");
            ?>
</td>
						<td class="invoice_td" align="right" width="20%"><?php 
            echo gettext("TOTALCOST");
            ?>
</td>
					</tr>
					<?php 
            $i = 0;
            foreach ($list_total_day_charge as $data) {
                $i = ($i + 1) % 2;
                ?>
					<tr class="invoice_rows">
						<td align="center" class="invoice_td"><?php 
                echo display_GMT($data[0], $_SESSION["gmtoffset"], 0);
                ?>
</td>
						<td class="invoice_td" align="center"><?php 
                echo $data[3];
                ?>
</td>
						<td  class="invoice_td" align="right"><?php 
                echo number_format(convert_currency($currencies_list, $data[1], $data[2], $selected_currency), 3) . " " . $selected_currency;
                ?>
</td>
					</tr> 
					<?php 
            }
            ?>
					<tr>