<style>
body { font-family: dejavusans, sans-serif; font-size: 10px; }
table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
th, td { border: 1px solid #ccc; padding: 4px; text-align: left; }
.section-title { background: #eee; font-weight: bold; }
</style>

<h3>FICHE DE SALAIRE - <?= htmlspecialchars($payslip['period']) ?></h3>
<p><strong><?= htmlspecialchars($payslip['last_name'] . ' ' . $payslip['first_name']) ?></strong><br>
Matricule : <?= $payslip['matricule'] ?> | Profession : <?= $payslip['profession'] ?><br>
<?php $date_entree = DateTime::createFromFormat('Y-m-d', $payslip['date_entree']); ?>
Entrée : <?= date_format($date_entree,"d/m/Y") ?> | Sortie : <?= $payslip['date_sortie'] ?: '-' ?><br>
Statut : <?= $payslip['statut_fiscal'] ?> <br>Classe : <?= $payslip['classe'] ?> | Taux : <?= $payslip['taux_impot'] ?><br>IBAN : <?= $payslip['iban'] ?><br>
</p>

<table>
<thead><tr class="section-title"><th width="15%">Type</th><th width="40%">Description</th><th width="15%">Base</th><th width="10%">Taux</th><th width="20%">Montant</th></tr></thead>
<tbody>
<tr><td width="15%">B/RB</td><td colspan="3"  width="65%">Rémunération de base</td><td width="20%" style="text-align: right;"><strong><?= number_format($payslip['gross_salary'], 2, ',', ' ') ?> €</strong></td></tr>
<?php foreach ($benefits as $b): ?>
<tr><td width="15%"><?= $b['code'] ?></td><td colspan="3"><?= $b['label'] ?></td><td style="text-align: right;"><?= number_format($b['amount'], 2, ',', ' ') ?> €</td></tr>
<?php endforeach; ?>
<tr><td colspan="4">Total avantages en nature</td><td width="20%" style="text-align: right;"><strong><?= number_format($payslip['benefits'], 2, ',', ' ') ?> €</strong></td></tr>
<tr style="background-color:	#F0F0F0;" class="section-title"><td colspan="4">Brut total</td><td width="20%" style="text-align: right;"><?= number_format($payslip['total_gross'], 2, ',', ' ') ?> €</td></tr>
<?php foreach ($cotisations as $c): ?>
<tr><td width="15%"><?= $c['code'] ?></td><td width="40%"><?= $c['label'] ?></td><td width="15%" style="text-align: right;"><?= number_format($c['base'] , 2, ',', ' ') ?></td><td  width="10%" style="text-align: right;"><?= number_format($c['rate'], 2) ?>%</td><td width="20%" style="text-align: right;"><?= number_format($c['amount'], 2, ',', ' ') ?> €</td></tr>
<?php endforeach; ?>
<tr  style="background-color:	#F0F0F0;" class="section-title"><td colspan="4">Total cotisations</td><td   width="20%" style="text-align: right;"><?= number_format($payslip['social_charges'], 2, ',', ' ') ?> €</td></tr>
<?php foreach ($abattements as $a): ?>
<tr><td width="15%"><?= $a['keyname'] ?></td><td colspan="3"><?= $a['label'] ?></td><td style="text-align: right;"><?= number_format($a['amount'], 2, ',', ' ') ?> €</td></tr>
<?php endforeach; ?>
<tr style="background-color:	#F0F0F0;" class="section-title"><td colspan="4">Total abattements</td><td style="text-align: right;"><?= number_format($payslip['abattements'], 2, ',', ' ') ?> €</td></tr>
<tr class="section-title"><td colspan="4">Imposable</td><td style="text-align: right;"><?= number_format($payslip['gross_salary'] - $payslip['social_charges'] - $payslip['abattements'], 2, ',', ' ') ?> €</td></tr>
<tr><td>Impôt</td><td>Base : <?= number_format($payslip['gross_salary'] - $payslip['social_charges'] - $payslip['abattements'], 2, ',', ' ') ?> €</td><td colspan="2">Taux : <?= number_format($payslip['taux_impot'], 2) ?>%</td><td style="text-align: right; background-color:	#F0F0F0;"><?= number_format($payslip['impots'], 2, ',', ' ') ?> €</td></tr>
<tr><td colspan="4">Crédits impôt (CIS: <?= $payslip['cis'] ?> € / CO2: <?= $payslip['co2'] ?> €)</td><td style="text-align: right;"><?= $payslip['cis']  + $payslip['co2'] ?> €</td></tr>
<tr class="section-title"><td colspan="4">Net après impôts</td><td style="text-align: right;"><?= number_format($payslip['net_apres_impot'], 2, ',', ' ') ?> €</td></tr>
<?php foreach ($plus_minus as $pm): ?>
<tr><td colspan="4"><?= $pm['label'] ?></td><td style="text-align: right;"><?= number_format($pm['amount'], 2, ',', ' ') ?> €</td></tr>
<?php endforeach; ?>
<?php if (isset($payslip['benefits']) && $payslip['benefits'] > 0): ?>
    <tr>
        <td colspan="4">Avantages en nature</td>
        <td style="text-align: right;"> - <?= number_format($payslip['benefits'], 2, ',', ' ') ?> €</td>
    </tr>
<?php endif; ?>
<tr class="section-title"><td colspan="4">Total ajouts/diminutions</td><td style="text-align: right;"><?= number_format($payslip['other_plus'] + $payslip['other_minus'] - $payslip['benefits'], 2, ',', ' ') ?> €</td></tr>
<tr style="background-color:	#F0F0F0;"class="section-title"><td colspan="4">Net à payer</td><td style="text-align: right;"><?= number_format($payslip['net_final'], 2, ',', ' ') ?> €</td></tr>
</tbody>
</table>
<p><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></p>
<p><strong>Cumuls <?= $year ?> :</strong></p>
<table>
<thead><tr class="section-title"><th style="font-size: x-small;" width="12.5%">Brut :</th><th style="font-size: x-small;" width="12.5%">Cotisations :</th><th style="font-size: x-small;" width="12.5%">Net avant impôts :</th><th style="font-size: x-small;" width="12.5%">Impôts :</th><th style="font-size: x-small;" width="12.5%">Net après impôts :</th><th style="font-size: x-small;" width="12.5%">Ajouts :</th><th style="font-size: x-small;" width="12.5%">Diminutions :</th><th style="font-size: x-small;" width="12.5%">Net à payer :</th></tr></thead>
<tbody>
<tr><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['gross_total'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['charges_total'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['net_avant_impot'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['impots_total'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['net_total'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['ajouts'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['diminutions'], 2, ',', ' ') ?> €</td><td style="font-size: x-small; text-align: right;"><?= number_format($cumuls['net_a_payer'], 2, ',', ' ') ?> €</td></tr>
</tbody>
</table>