<?php include("include/header.php"); ?>
<?php 
$id = $_GET['borrower'];
$data_inicial = $_GET['data_inicial']." 00:00:00";
$data_final = $_GET['data_final']." 23:59:00";
?>
<style>
    .cabecalho{
        text-align: center;
    }
    .cabecalho img{
        width:54px;
        height: 54px;
    }
    .info{
        text-align: center;
    }
    .head .form-group{
        display: flex;
        flex-direction: row;
        justify-content: center;
    }
    .head .form-group .p{
        margin-right: 30px;
    }
    .rel .tabela{
        width:90%;
        margin: 10px auto;
        text-align: center;
        font-size: 10pt;
    }
    .rel table tbody tr td{
        padding: 7px 0;
    }
    .rodape{
    
        text-align: center;
        width: 90%;
        margin: 70px auto;
    }
    .rodape table{
        width: 100%;
        
    }
    .rodape table .no-print{
        padding:5px 15px;
        background: #000;
        color: #fff;
    }
    hr{
        width: 100%;
        text-align: center;
        border:2px solid #666;
    }
    @media print
    {    
        .no-print, .no-print *
        {
            display: none !important;
        }
    }
</style>
<div class="cabecalho">
    <img src="emblema.jpg">
    <p>REPÚBLICA DE MOÇAMBIQUE</p>
    <p><b>Portugal Junior Microcredito E.I</b></p>
</div>
<div class="info">
    <h4>EXTRATO DE POUPANCAS DE <?php echo $data_inicial ?> A <?php echo $data_final ?></h4>
</div>
<div class="head">
    <?php 
			    $id = $_GET['id'];
			    $mt = mysqli_query($link, "SELECT * FROM borrowers WHERE id = '$id' LIMIT 0,1") or die (mysqli_error($link));
			    while($dad = mysqli_fetch_array($mt)){
			        $mutuario = $dad['fname']." ".$dad['lname'];
			        $conta = $dad['account'];
			        $cell = $dad['phone'];
			  ?>
                <div class="form-group">
                    <p class="p"><span>Número de Conta:</span><span><?php echo $conta ?></span></p>
                     <p><span>Mutuário:</span><span><?php echo $mutuario ?></span></p>
                </div>
                <br>
			  <?php
			    }
			  ?>
</div>
<div class="rel">
    <table class="tabela">
        <thead>
            <tr>
                <th>Data</th>
                <th>Valor</th>
            </tr>
        </thead>
        <tbody>
            <?php
        $select2 = mysqli_query($link, "SELECT * FROM savings WHERE id_borrowers = '$id' AND data BETWEEN '$data_inicial' AND '$data_final' ORDER BY data") or die (mysqli_error($link));
        while($dados2 = mysqli_fetch_array($select2)){
            $data = $dados2['data'];
            $amount = $dados2['amount'];
            $select1 = mysqli_query($link, "SELECT * FROM systemset") or die (mysqli_error($link));
            while($row1 = mysqli_fetch_array($select1))
            {
            $currency = $row1['currency']; 
            ?>
                <tr>
                <td><?php echo $data ?></td>
                <td><?php echo $currency.number_format($amount,2,".",","); ?></td>
                </tr>
            <?php
            }
        }
?>
<?php
        $select01 = mysqli_query($link, "SELECT sum(amount) as amounts FROM savings WHERE id_borrowers = '$id' AND data BETWEEN '$data_inicial' AND '$data_final'") or die (mysqli_error($link));
        while($dados01 = mysqli_fetch_array($select01)){
            $amounts = $dados01['amounts'];
            $select1 = mysqli_query($link, "SELECT * FROM systemset") or die (mysqli_error($link));
            while($row1 = mysqli_fetch_array($select1))
            {
            $currency = $row1['currency']; 
            ?>
                <tr>
                <td><b><?php echo "Totais" ?></b></td>
               
                <td><b><?php echo $currency.number_format($amounts,2,".",","); ?></b></td>
                
                </tr>
            <?php
            }
        }
?>
        </tbody>
    </table>
                
</div>

<div class="rodape">
    <hr>
    <table>
        <tr>
            <td><img src="1622834_cards_credit_method_pay_payment_icon.png" width="80px" height="80px"></td>
            <td>Sede: Tete, Av. da Liberdade n<sup>o</sup> 067, Telef. 252-23328, Fax 25223330</td>
            <td><button class="no-print" onclick = "window.print();return false">Imprimir</button></td>
        </tr>
    </table>
</div>