PDF转换库的数据渲染问题

时间:2018-06-28 10:57:44

标签: php

我正在开发一个小的功能,该功能可以将从数据库中检索到的数据呈现为图表,从而每月显示一次数据。由于用户是讲法语的人,因此我尝试使用以下脚本中带注释的代码段用法语翻译月份数据。

<?php

    function getMonths($begin, $end)
    {
        $monthsData = array();

        $dateBegin = new \DateTime($begin);
        $dateEnd = new \DateTime($end);

        while ($dateBegin->getTimestamp() < $dateEnd->getTimestamp()) {
            $monthsData[] = $dateBegin->format('F Y');
            $dateBegin->add(new \DateInterval('P1M'));
        }

        return $monthsData;
    }


    $monthsData = getMonths('2018-05-01', '2020-01-01' );


    $percentApporteurData = $_SESSION['reqPourcentageApporteur'];

    $recupapporteur = "select * from apporteuraffaire where id_apporteur ='".$useridapporteur."'";
    $execrecupapporteur = mysql_query($recupapporteur);
    $apporteur = mysql_fetch_assoc($execrecupapporteur);



    $recupcodepromo = "select * from codepromo where codepromo ='".$apporteur['codeapporteur']."'";
    $execrecupcodepromo = mysql_query($recupcodepromo);
    $codepromo = mysql_fetch_assoc($execrecupcodepromo);



  $listeventes = "select * from reporting_formulaire2 where codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0 and numeroattestation<>'' and statusachat>9 and statusachat<>15 and statusachat<>14 and statusachat<19 ORDER BY  `idformulaire2` DESC ";    
            $exelisteaffaire = mysql_query($listeventes);
            $nombreaffaire =  mysql_num_rows($exelisteaffaire);
            $rf2Data = mysql_fetch_assoc($exelisteaffaire);

            $_SESSION['rf2Data'] = $rf2Data;

?>

<?php
if ($nombreaffaire > 0) {
?>


<?php 
    $listeville="SELECT * FROM  `villedumaroc` where idville='".$apporteur['villeapporteur']."' ";
    $exelisteville=  mysql_query($listeville);
    $resultatville=mysql_fetch_assoc($exelisteville);
?>

<?php

$reqClients = "select DATE_FORMAT(datemodificationstatus, '%M %Y') AS datemodif, SUM(prixpack) AS montant_du_mois  
from reporting_formulaire2 where codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0 and numeroattestation<>'' 
and statusachat>9 and statusachat<>15 and statusachat<>14 and statusachat<19 
group by datemodif
ORDER BY  `idformulaire2` DESC";
$execReqClient = mysql_query($reqClients);

$grid = array();
while ($client = mysql_fetch_assoc($execReqClient) ) {
    $grid[$client['datemodif']] = number_format(($client['montant_du_mois'] * $percentApporteurData['pourcentage_valeur']/100), 2,',',' ');
}

}

?>

<div class="col-sm-offset-2">
    <center>
        <table class="table table-striped table-hover table-bordered">
    <tr>
        <td><strong>Mois</strong></td>
        <td><strong>Gains (Dhs)</strong></td>
        <td><strong>Fiche comptable du mois</strong></td>
    </tr>
    <?php
        foreach ($grid as $key => $value) {

        /*$yearMonths = array(
            "January" => "Janvier",
            "February" => "Février",
            "March" => "Mars",
            "April" => "Avril",
            "May" => "Mai",
            "June" => "Juin",
            "July" => "Juillet",
            "August" => "Août",
            "September" => "Septembre",
            "October" => "Octobre",
            "November" => "Novembre",
            "December" => "Décembre",
        );

        $key = explode(' ',$key);
        foreach ($yearMonths as $k => $v) {
            //$k = explode(' ', $k);
            if ($key[0] == $k) {
                $key = $v.' '.$key[1];
            }
        }*/




            ?>

                <tr>
                    <td><?php echo $key; ?></td>
                    <td><?php echo $value; ?></td>
                    <td>
                        <?php  ob_start(); ?> 
                        <div class="col-sm-12 col-xs-12 col-lg-12">
                            <table width='700px' colspan='1' rowspan='1'>
                                <tr>
                                    <td>
                                        <center>
                                            <br>
                                            <img src="img/logo-helvetica-by-sanad.png">
                                        </center>
                                    </td>
                                </tr>  
                            </table>
                            <br><br><br>

                        </div>

                        <div class="col-sm-12 col-xs-12 col-lg-12">

                        <table width='700px' colspan='1' rowspan='1'>
                            <tr>
                                <td>
                                    <center> 
                                        <br> 
                                        <b><u>AFFAIRES DU MOIS (<?php echo $key; ?>)</b></u> 
                                    </center>
                                </td>
                            </tr>
                        </table>    
                        <br><br>
                        <table style="border-style:solid; border-width:1px;background-color: grey;margin-top: 3px;margin-bottom: 3px;" border=1 width='700px' colspan='1' rowspan='1'>
                            <tr style="background-color: #fff;height: 40px;">
                                <td  align='left' style="height: 40px;width: 33%;padding: 0px 5px 5px 5px;">

                                    <center>   
                                        <table style="background-color: grey;width: 240px;height: 20px;">
                                            <tr><td style="text-align: center;"><p style="color: #fff;margin-bottom: 0px;"><b>Apporteur d&apos;affaires</b></p></td></tr>
                                        </table>
                                    </center>
                                    <br>
                                    <table style="width: 100%;border-color: gray;border-left: 0px;border-right: 0px;border-top: 0px;border-bottom: 0px;margin-top: 3px;" border="2"  cellpadding=2 cellspacing=2>
                                        <tr>
                                            <td style="width: 20%;">Nom et pr&eacute;nom</td>
                                            <td style="background-color: #ebebeb;width: 40%;">&nbsp;<?php echo $apporteur['nomapporteur']." ".$apporteur['prenomapporteur']; ?></td>
                                            <td style="width: 20%;" >&nbsp;E-mail</td>
                                            <td style="background-color: #ebebeb;width: 20%">&nbsp;<?php echo $apporteur['emailapporteur'];?></td>
                                        </tr>
                                        <tr>
                                            <td style="width: 20%;">T&eacute;l&eacute;phone</td>
                                            <td style="background-color: #ebebeb;width: 40%;">&nbsp;<?php echo $apporteur['telephoneapporteur'];?></td>
                                            <td style="width: 20%;" >&nbsp;Ville</td>
                                            <td style="background-color: #ebebeb;width: 20%">&nbsp;<?php echo $resultatville['nomville'];?></td>
                                        </tr>
                                    </table>
                                </td>    
                            </tr>
                        </table>
                        </div>
                        <br><br>

                    <div class="col-sm-12 col-xs-12 col-lg-12">

                        <table style="border-style:solid;border-color: grey; border-width:1px;background-color: grey;margin-top: 3px;margin-bottom: 3px;" border=1 width='700px' colspan='1' rowspan='1'>
                            <br><br>
                            <tr style="background-color: #fff;">
                                <td colspan="5">
                                    <center>
                                        <table style="background-color: grey; width: 240px;height: 20px;margin-top: 3px;margin-bottom: 3px;">
                                            <tr>
                                                <td style="text-align: center;">

                                                    <p style="color: #fff;margin-bottom: 0px;"><b>Commissions</b></p>

                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                            </tr>
                            <br><br>
                            <tr style="background-color: #d6d6d6;font-weight: 700;">
                                <td>&nbsp;Client</td>
                                <td style="text-align: center;">&nbsp;Pack&nbsp;</td> 
                                <td style="text-align: center;">&nbsp;Prix du pack&nbsp;</td>
                                <td style="text-align: center;">&nbsp;Pourcentage&nbsp;</td>
                                <td style="text-align: center;">&nbsp;Commission&nbsp;</td>
                            </tr>    

                            <?php
                            $listeventes = "select nom, prenom, nomprenom, pack, prixpack, DATE_FORMAT(datemodificationstatus, '%M %Y') AS datemodifstatut  from reporting_formulaire2 where codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0 and numeroattestation<>'' and statusachat>9 and statusachat<>15 and statusachat<>14 and statusachat<19 ORDER BY  `idformulaire2` DESC ";    
            $exelisteaffaire = mysql_query($listeventes);
            $nombreaffaire =  mysql_num_rows($exelisteaffaire);
            //$rf2Data = mysql_fetch_assoc($exelisteaffaire);
                                $afrs = array();
                                $array = array();

                                    while ($ref = mysql_fetch_assoc($exelisteaffaire)) {
                                        $mois = $ref['datemodifstatut']; 
                                            $array[$mois] = array();
                                            $array[$mois][$ref['nomprenom']] = array();
                                            $array[$mois][$ref['nomprenom']]['nomprenom'] = $ref['nomprenom'] ;
                                        $array[$mois][$ref['nomprenom']]['pack'] = $ref['pack'];
                                        $array[$mois][$ref['nomprenom']]['prixpack'] = $ref['prixpack'];
                                        $array['pourcentage'] = $percentApporteurData['pourcentage_valeur'];
                                    }



                                    foreach ($array as $index => $val) {

                                        if ($index == $key) {

                                            foreach ($array[$key] as $n => $arr){


                            ?>
                            <tr style="background-color: #fff;">
                                <td><b>&nbsp;<?php echo $arr['nomprenom']; ?></b></td>
                                <td style="text-align: center;">&nbsp;<?php echo $arr['pack']; ?></td>
                                <td style="text-align: center;">&nbsp;<?php echo $arr['prixpack']; ?></td>
                                <td style="text-align: right;padding-right: 4px;">
                                    <?php 
                                        if (isset($percentApporteurData['pourcentage_valeur']) && is_numeric($percentApporteurData['pourcentage_valeur'])) {
                                            echo $percentApporteurData['pourcentage_valeur'];
                                        } else {
                                            echo "0";
                                        }
                                    ?>
                                </td>
                                <td style="text-align: right;padding-right: 4px;">
                                    <?php

                                        $percentage = 0;
                                        if (isset($percentApporteurData['pourcentage_valeur']) && is_numeric($percentApporteurData['pourcentage_valeur'])) {
                                            $percentage = $percentApporteurData['pourcentage_valeur'];
                                        }
                                        echo number_format(($arr['prixpack'] * $percentage / 100), 2,',',' ');
                                        $afr = $arr['prixpack'] * $percentage / 100;
                                        $afrs[] = $afr;
                                    ?>
                                </td>

                            </tr>
                            <?php

                                $totalAfrs = 0;
                                for ($i = 0; $i < count($afrs); $i++) { 
                                    $totalAfrs += $afrs[$i];

                                }

                                $array[$mois]['total'] = $totalAfrs;
                            ?>                         

                            <tr style="background-color: #fff;height: 20px;"><td colspan="5" height='40'></td></tr>                  

                            <tr style="background-color: #fff;">
                                <td colspan="4" style="text-align: right;"><b>Total&nbsp;</b></td>

                                <td style="background-color: #d6d6d6;text-align: right;padding-right: 4px;"> &nbsp;
                                    <?php
                                        echo number_format($totalAfrs,2,',',' ');  
                                    ?>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div>    
                        <p style="font-size: 12px;text-align: left;">  
                            <br><br><br><br>
                            Ce montant total de vos commissions <span style="font-weight: bold;">(<?php echo number_format($totalAfrs,2,',',' '); ?> Dhs)</span> vous sera vers&eacute; sur votre compte bancaire n&deg; <?php echo $apporteur['ribcomplet'];?>
                        </p>
                        <p style="font-size: 12px;text-align: left;">  
                            <br><br><br><br>
                            Fait &agrave; Casablanca, le <?php echo date('d/m/Y');?>
                        </p>
                        <br><br>
                    </div>                            

                    <?php $monthContent = ob_get_clean(); ?>   
                    <?php 

                        require_once( 'pdf/MPDF57/mpdf.php'); // Include mdpf
                        $stylesheet = file_get_contents('pdf/pdf.css'); // Get css content
                        $html = '<div id="pdf-content">
                                    Your PDF Content goes here (Text/HTML)
                                </div>';
                        // Setup PDF
                        //$mpdf = new mPDF('utf-8', 'A4-L'); // New PDF object with encoding & page size
                        $mpdf = new mPDF('utf-8', 'A4'); // New PDF object with encoding & page size
                        $mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping
                        $mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping
                        // PDF header content
                        $mpdf->SetHTMLHeader('<div class="pdf-header">

                                              </div>'); 
                        // PDF footer content                      
                        $mpdf->SetHTMLFooter('<div class="pdf-footer">

                                              </div>'); 

                        $mpdf->WriteHTML($stylesheet,1); // Writing style to pdf
                        $content = mb_convert_encoding($content, 'UTF-8', 'UTF-8');
                        $mpdf->WriteHTML($monthContent); // Writing html to pdf
                        //$mpdf->Output('lubus_mdpf_demo6.pdf','D'); // For Download

                        //$nomfichierserveur="pdf/save/apporteuraffaire/comptabilite/test.pdf";
                        $fichierPDF = "pdf/save/apporteuraffaire/comptabilite/".str_replace(' ','',$key)."_".$apporteur['nomapporteur']."-".$apporteur['prenomapporteur']."_Fiche-Comptable.pdf";

                        $mpdf->Output($fichierPDF, 'F');//enregistrer sur serveur

                    ?> 

                        <a href="<?php echo $fichierPDF; ?>" class="list-group-item">
                            <img width="10%" height="10%" src="img/logopdf.png" />
                        </a>

                    </td>
                </tr>
            <?php

            }
                                        }
                                    }

        }
    ?>
</table>
    </center>
</div>

我上面的脚本正在渲染此视图: enter image description here

每当我取消注释代码段的注释,以便我可以用法语翻译月份名称时,就会得到以下输出:

enter image description here

上面看到的输出是PDF文件的内容。 有什么建议吗?

P.S:单独测试时,注释后的代码段的工作方式:

<?php
$grid = array(
    "February 2018" => 498.90,
    "June 2018" => 1000,
    "May 2018" => 500.00,
    "April 2018" => 300.90,
    "March 2018" => 250.50,
);



$yearMonths = array(
    "January" => "Janvier",
    "February" => "Février",
    "March" => "Mars",
    "April" => "Avril",
    "May" => "Mai",
    "June" => "Juin",
    "July" => "Juillet",
    "August" => "Août",
    "September" => "Septembre",
    "October" => "Octobre",
    "November" => "Novembre",
    "December" => "Décembre",
    );

 $keys = array();   
foreach ($grid as $key => $value) {
    $key = explode(' ',$key);

    foreach ($yearMonths as $k => $v) {
        //$k = explode(' ', $k);
        if ($key[0] == $k) {
            $keys[] = $v.' '.$key[1];
        }
    }
}  

var_dump($keys);

array(5) {
  [0]=>
  string(13) "Février 2018"
  [1]=>
  string(9) "Juin 2018"
  [2]=>
  string(8) "Mai 2018"
  [3]=>
  string(10) "Avril 2018"
  [4]=>
  string(9) "Mars 2018"
}

1 个答案:

答案 0 :(得分:0)

问题来自while循环下面的foreach循环。确保仅使用while循环后,所有内容都像一个超级按钮。这是我运行良好的新代码:

<?php

    function getMonths($begin, $end)
    {
        $monthsData = array();

        $dateBegin = new \DateTime($begin);
        $dateEnd = new \DateTime($end);

        while ($dateBegin->getTimestamp() < $dateEnd->getTimestamp()) {
            $monthsData[] = $dateBegin->format('F Y');
            $dateBegin->add(new \DateInterval('P1M'));
        }

        return $monthsData;
    }


    $monthsData = getMonths('2018-05-01', '2020-01-01' );


    $percentApporteurData = $_SESSION['reqPourcentageApporteur'];

    $recupapporteur = "select * from apporteuraffaire where id_apporteur ='".$useridapporteur."'";
    $execrecupapporteur = mysql_query($recupapporteur);
    $apporteur = mysql_fetch_assoc($execrecupapporteur);



    $recupcodepromo = "select * from codepromo where codepromo ='".$apporteur['codeapporteur']."'";
    $execrecupcodepromo = mysql_query($recupcodepromo);
    $codepromo = mysql_fetch_assoc($execrecupcodepromo);



  $listeventes = "select * from reporting_formulaire2 where codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0 and statusachat>7 and statusachat<>15 and statusachat<>14 and statusachat<19 ORDER BY  `idformulaire2` DESC ";    
            $exelisteaffaire = mysql_query($listeventes);
            $nombreaffaire =  mysql_num_rows($exelisteaffaire);
            $rf2Data = mysql_fetch_assoc($exelisteaffaire);

            $_SESSION['rf2Data'] = $rf2Data;

?>

<?php
if ($nombreaffaire > 0) {
?>


<?php 
    $listeville="SELECT * FROM  `villedumaroc` where idville='".$apporteur['villeapporteur']."' ";
    $exelisteville=  mysql_query($listeville);
    $resultatville=mysql_fetch_assoc($exelisteville);
?>

<?php

$reqClients = "select DATE_FORMAT(datemodificationstatus, '%M %Y') AS datemodif, SUM(prixpack) AS montant_du_mois  
from reporting_formulaire2 where codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0  
and statusachat>7 and statusachat<>15 and statusachat<>14 and statusachat<19 
group by datemodif
ORDER BY  `idformulaire2` DESC";
$execReqClient = mysql_query($reqClients);

$grid = array();
while ($client = mysql_fetch_assoc($execReqClient) ) {
    $grid[$client['datemodif']] = number_format(($client['montant_du_mois'] * $percentApporteurData['pourcentage_valeur']/100), 2,',',' ');
}

}

?>

<div class="col-sm-offset-2">
    <center>
        <table class="table table-striped table-hover table-bordered">
    <tr>
        <td><strong>Mois</strong></td>
        <td><strong>Gains (Dhs)</strong></td>
        <td><strong>Fiche comptable du mois</strong></td>
    </tr>
    <?php
        foreach ($grid as $key => $value) {
            $yearMonths = array(
            "January" => "Janvier",
            "February" => "Février",
            "March" => "Mars",
            "April" => "Avril",
            "May" => "Mai",
            "June" => "Juin",
            "July" => "Juillet",
            "August" => "Août",
            "September" => "Septembre",
            "October" => "Octobre",
            "November" => "Novembre",
            "December" => "Décembre",
        );

        $key2 = explode(' ',$key);
        foreach ($yearMonths as $k => $v) {
            //$k = explode(' ', $k);
            if ($key2[0] == $k) {
                $key2 = $v.' '.$key2[1];
            }
        }
            ?>

                <tr>
                    <td><?php echo $key2; ?></td>
                    <td><?php echo $value; ?></td>
                    <td>
                        <?php  ob_start(); ?> 
                        <div class="col-sm-12 col-xs-12 col-lg-12">
                            <table width='700px' colspan='1' rowspan='1'>
                                <tr>
                                    <td>
                                        <center>
                                            <br>
                                            <img src="img/logo-helvetica-by-sanad.png">
                                        </center>
                                    </td>
                                </tr>  
                            </table>
                            <br><br><br>

                        </div>

                        <div class="col-sm-12 col-xs-12 col-lg-12">

                        <table width='700px' colspan='1' rowspan='1'>
                            <tr>
                                <td>
                                    <center> 
                                        <br> 
                                        <b><u>AFFAIRES DU MOIS (<?php echo $key; ?>)</b></u> 
                                    </center>
                                </td>
                            </tr>
                        </table>    
                        <br><br>
                        <table style="border-style:solid; border-width:1px;background-color: grey;margin-top: 3px;margin-bottom: 3px;" border=1 width='700px' colspan='1' rowspan='1'>
                            <tr style="background-color: #fff;height: 40px;">
                                <td  align='left' style="height: 40px;width: 33%;padding: 0px 5px 5px 5px;">

                                    <center>   
                                        <table style="background-color: grey;width: 240px;height: 20px;">
                                            <tr><td style="text-align: center;"><p style="color: #fff;margin-bottom: 0px;"><b>Apporteur d&apos;affaires</b></p></td></tr>
                                        </table>
                                    </center>
                                    <br>
                                    <table style="width: 100%;border-color: gray;border-left: 0px;border-right: 0px;border-top: 0px;border-bottom: 0px;margin-top: 3px;" border="2"  cellpadding=2 cellspacing=2>
                                        <tr>
                                            <td style="width: 20%;">Nom et pr&eacute;nom</td>
                                            <td style="background-color: #ebebeb;width: 40%;">&nbsp;<?php echo $apporteur['nomapporteur']." ".$apporteur['prenomapporteur']; ?></td>
                                            <td style="width: 20%;" >&nbsp;E-mail</td>
                                            <td style="background-color: #ebebeb;width: 20%">&nbsp;<?php echo $apporteur['emailapporteur'];?></td>
                                        </tr>
                                        <tr>
                                            <td style="width: 20%;">T&eacute;l&eacute;phone</td>
                                            <td style="background-color: #ebebeb;width: 40%;">&nbsp;<?php echo $apporteur['telephoneapporteur'];?></td>
                                            <td style="width: 20%;" >&nbsp;Ville</td>
                                            <td style="background-color: #ebebeb;width: 20%">&nbsp;<?php echo $resultatville['nomville'];?></td>
                                        </tr>
                                    </table>
                                </td>    
                            </tr>
                        </table>
                        </div>
                        <br><br>

                    <div class="col-sm-12 col-xs-12 col-lg-12">

                        <table style="border-style:solid;border-color: grey; border-width:1px;background-color: grey;margin-top: 3px;margin-bottom: 3px;" border=1 width='700px' colspan='1' rowspan='1'>
                            <br><br>
                            <tr style="background-color: #fff;">
                                <td colspan="5">
                                    <center>
                                        <table style="background-color: grey; width: 240px;height: 20px;margin-top: 3px;margin-bottom: 3px;">
                                            <tr>
                                                <td style="text-align: center;">

                                                    <p style="color: #fff;margin-bottom: 0px;"><b>Commissions</b></p>

                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                            </tr>
                            <br><br>
                            <tr style="background-color: #d6d6d6;font-weight: 700;">
                                <td>&nbsp;Client</td>
                                <td style="text-align: center;">&nbsp;Pack&nbsp;</td> 
                                <td style="text-align: center;">&nbsp;Prix du pack&nbsp;</td>
                                <td style="text-align: center;">&nbsp;Pourcentage&nbsp;</td>
                                <td style="text-align: center;">&nbsp;Commission&nbsp;</td>
                            </tr>    

                            <?php
                            $listeventes = "select nom, prenom, nomprenom, pack, prixpack, DATE_FORMAT(datemodificationstatus, '%M %Y') AS datemodifstatut  from reporting_formulaire2 where DATE_FORMAT(datemodificationstatus, '%M %Y') = '". $key ."' and codepromo ='".$codepromo['idcodepromo']."' and codepromo <> 0 and statusachat>7 and statusachat<>15 and statusachat<>14 and statusachat<19 ORDER BY  `idformulaire2` DESC ";    
                            $exelisteaffaire = mysql_query($listeventes);
                            $nombreaffaire =  mysql_num_rows($exelisteaffaire);
                            //$rf2Data = mysql_fetch_assoc($exelisteaffaire);
                                $afrs = array();
                                $array = array();

                                    while ($ref = mysql_fetch_assoc($exelisteaffaire)) {

                            ?>
                            <tr style="background-color: #fff;">
                                <td><b>&nbsp;<?php echo $ref['nomprenom']; ?></b></td>
                                <td style="text-align: center;">&nbsp;<?php echo $ref['pack']; ?></td>
                                <td style="text-align: center;">&nbsp;<?php echo $ref['prixpack']; ?></td>
                                <td style="text-align: right;padding-right: 4px;">
                                    <?php 
                                        if (isset($percentApporteurData['pourcentage_valeur']) && is_numeric($percentApporteurData['pourcentage_valeur'])) {
                                            echo $percentApporteurData['pourcentage_valeur'];
                                        } else {
                                            echo "0";
                                        }
                                    ?>
                                </td>
                                <td style="text-align: right;padding-right: 4px;">
                                    <?php

                                        $percentage = 0;
                                        if (isset($percentApporteurData['pourcentage_valeur']) && is_numeric($percentApporteurData['pourcentage_valeur'])) {
                                            $percentage = $percentApporteurData['pourcentage_valeur'];
                                        }
                                        echo number_format(($ref['prixpack'] * $percentage / 100), 2,',',' ');
                                        $afr = $ref['prixpack'] * $percentage / 100;
                                        $afrs[] = $afr;
                                    ?>
                                </td>

                            </tr>
                            <?php
                                 }               


                                $totalAfrs = 0;

                                for ($i = 0; $i < count($afrs); $i++) { 
                                    $totalAfrs += $afrs[$i];

                                }

                                $array[$mois]['total'] = $totalAfrs;
                            ?>                         

                            <tr style="background-color: #fff;height: 20px;"><td colspan="5" height='40'></td></tr>                  

                            <tr style="background-color: #fff;">
                                <td colspan="4" style="text-align: right;"><b>Total&nbsp;</b></td>

                                <td style="background-color: #d6d6d6;text-align: right;padding-right: 4px;"> &nbsp;
                                    <?php
                                        echo number_format($totalAfrs,2,',',' ');  
                                    ?>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div>    
                        <p style="font-size: 12px;text-align: left;">  
                            <br><br><br><br>
                            Ce montant total de vos commissions <span style="font-weight: bold;">(<?php echo number_format($totalAfrs,2,',',' '); ?> Dhs)</span> vous sera vers&eacute; sur votre compte bancaire n&deg; <?php echo $apporteur['ribcomplet'];?>
                        </p>
                        <p style="font-size: 12px;text-align: left;">  
                            <br><br><br><br>
                            Fait &agrave; Casablanca, le <?php echo date('d/m/Y');?>
                        </p>
                        <br><br>
                    </div>                            

                    <?php $monthContent = ob_get_clean(); ?>   
                    <?php 

                        require_once( 'pdf/MPDF57/mpdf.php'); // Include mdpf
                        $stylesheet = file_get_contents('pdf/pdf.css'); // Get css content
                        $html = '<div id="pdf-content">
                                    Your PDF Content goes here (Text/HTML)
                                </div>';
                        // Setup PDF
                        //$mpdf = new mPDF('utf-8', 'A4-L'); // New PDF object with encoding & page size
                        $mpdf = new mPDF('utf-8', 'A4'); // New PDF object with encoding & page size
                        $mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping
                        $mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping
                        // PDF header content
                        $mpdf->SetHTMLHeader('<div class="pdf-header">

                                              </div>'); 
                        // PDF footer content                      
                        $mpdf->SetHTMLFooter('<div class="pdf-footer">

                                              </div>'); 

                        $mpdf->WriteHTML($stylesheet,1); // Writing style to pdf
                        $monthContent = mb_convert_encoding($monthContent, 'UTF-8', 'UTF-8');
                        $mpdf->WriteHTML($monthContent); // Writing html to pdf
                        //$mpdf->Output('lubus_mdpf_demo6.pdf','D'); // For Download

                        //$nomfichierserveur="pdf/save/apporteuraffaire/comptabilite/test.pdf";
                        $fichierPDF = "pdf/save/apporteuraffaire/comptabilite/".str_replace(' ','',$key)."_".$apporteur['nomapporteur']."-".$apporteur['prenomapporteur']."_Fiche-Comptable.pdf";

                        $mpdf->Output($fichierPDF, 'F');//enregistrer sur serveur

                    ?> 

                        <a href="<?php echo $fichierPDF; ?>" class="list-group-item">
                            <img width="10%" height="10%" src="img/logopdf.png" />
                        </a>

                    </td>
                </tr>
            <?php




        }
    ?>
</table>
    </center>
</div>