<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Accord Devis</title>
</head>
<style>
    body {
        font-family: fantasy;
    }

    .page-break {
        page-break-after: always;
    }

    th {
        text-align: left;
    }

    td {
        text-align: center;
    }

    .page-number {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        padding: 5px;
    }

    .logo {
        position: fixed;
    }
</style>

<body>

    <img src="img/amea2.png" style="height:auto; width:190px; float: left !important;margin-top:-6%;" alt="Logo"
        class="logo">

    {{-- <img src="img/amea2.png" style="height:auto; width:170px; float: left !important" alt="Logo" class="logo"> --}}
    <span style="float: right !important"> REFERENCE DOSSIER <span>{{ $dossier->ref ?? null }}</span> <br>
        <span> <strong>Accord Devis Expert</strong> </span>
        <br><span>{{ $dossier->mode->mode ?? null }}</span></span>
    </span>


    <div style="margin-top: 80px;">
        <div>
            <table style="border: 1px solid;width: 48%;border-collapse: collapse;font-size:81%;">
                <tr>
                    <th style="border: 1px solid; width: 43%;"> ASSURANCE</th>
                    <th style="border: 1px solid;">{{ $dossier->company->company ?? null }}</th>
                </tr>
                <tr>
                    <th style="border: 1px solid;">REPARATEUR</th>
                    <td style="border: 1px solid;">{{ $dossier->garage->libelle ?? null }}</td>
                </tr>

                <tr>
                    <th style="border: 1px solid;">Intermidiaire</th>
                    <td style="border: 1px solid;"> {{ $dossier->intermidiaire->company ?? null }}</td>
                </tr>

                <tr>
                    <th style="border: 1px solid;">Numero Sinistre</th>
                    <td style="border: 1px solid;">{{ $dossier->numero_sinistre ?? null }}</td>
                </tr>
            </table>
        </div>
        <div>
            <table
                style="border:1px solid; width: 48%; border-collapse:collapse;font-size:81%; float: right; margin-top: -11%;">

                <tr>
                    <th style="border: 1px solid; width: 43%;">NOM</th>
                    <td style="border: 1px solid;">{{ $dossier->insured->name ?? null }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">NUMERO POLICE</th>
                    <td style="border: 1px solid;">{{ $dossier->numero_police ?? null }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">IMMATRICULATION</th>
                    <td style="border: 1px solid;">{{ $dossier->matricule ?? $dossier->new_matricule }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">Vehicule</th>
                    <td style="border: 1px solid;">
                        {{ $dossier->vehiculemodel->brand->brand ?? null }}-{{ $dossier->vehiculemodel->name ?? null }}
                    </td>
                </tr>

            </table>
        </div>
    </div>
    <div style="margin-top: 30px;">
        <div>
            <span style="float: left !imporant;"> Assuré {{ $dossier->company->company ?? null }}</span>
            <span style="float: right !imporant; margin-left:52%;">Tiers </span>
        </div>
        <div style="margin-top: 25px;">
            <table style="border: 1px solid;width: 48%;border-collapse: collapse; font-size:81%;">
                <tr>
                    <th style="border: 1px solid; width: 43%;">NOM</th>
                    <td style="border: 1px solid;">{{ $dossier->insured->name ?? null }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">NUMERO POLICE</th>
                    <td style="border: 1px solid;">{{ $dossier->numero_police ?? null }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">IMMATRICULATION</th>
                    <td style="border: 1px solid;">{{ $dossier->matricule ?? $dossier->new_matricule }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">Vehicule</th>
                    <td style="border: 1px solid;">
                        {{ $dossier->vehiculemodel->brand->brand ?? null }}-{{ $dossier->vehiculemodel->name ?? null }}
                    </td>
                </tr>

            </table>
        </div>
        <div>
            <table
                style="border: 1px solid;width: 48%;border-collapse: collapse;font-size:81%;float: right;margin-top: -11%;">
                <tr>
                    <th style="border: 1px solid; width: 43%;">NOM</th>
                    <td style="border: 1px solid;">{{ $dossier->opponent->name ?? null }}</td>

                </tr>
                <tr>
                    <th style="border: 1px solid;">COMPAGNIE</th>
                    <td style="border: 1px solid;">{{ $dossier->opponent->company->company ?? null }}</td>

                </tr>
                <tr>
                    <th style="border: 1px solid;">IMMATRICULATION</th>
                    <td style="border: 1px solid;">{{ $dossier->opponent->matricule ?? null }}</td>

                </tr>
                <tr>
                    <th style="border: 1px solid;">NUMERO POLICE</th>
                    <td style="border: 1px solid;">{{ $dossier->opponent->numero_attestation ?? null }}</td>
                </tr>
            </table>
        </div>
    </div>

    {{-- <span style="border:2px solid #000;">CIRCONSTANCE DE L'EXPERTISE/<span></span></span> --}}

    </div>


    {{-- <img src="data:image/svg+xml;base64,'.{{$img}}.'"  width="100" height="100" />; --}}

    <hr style="margin-top: 20px">


    <table style="margin-top:10px; border: 1px solid;border-collapse: collapse; width: 100%;height:42%;font-size:12px">
        <tr>
            <td style="border: 1px solid; width: 23% !important;">DESINATION</td>
            <td style="border: 1px solid; width: 11% !important;">QTE</td>
            <td style="border: 1px solid; width: 15% !important;">OPERATION</td>
            <td style="border: 1px solid; width: 11% !important;">Type</td>
            <td style="border: 1px solid; width: 11% !important;">REMISE</td>
            <td style="border: 1px solid; width: 11% !important;">VETUSTE</td>
            <td style="border: 1px solid; width: 13% !important;">Prix U</td>
            <td style="border: 1px solid; width: 13% !important;">Montant</td>


        </tr>
        @if ($devis->piece)
            @foreach ($devis->piece as $piece)
                <tr>
                    <td style="border: 1px solid; width:  11% !important;">{{ $piece->piece ?? null }}</td>
                    <td style="border: 1px solid; width:  11% !important;">{{ $piece->pivot->qte ?? null }}</td>
                    <td style="border: 1px solid; width:  11% !important;">
                        {{ $piece->pivot->operation->operation ?? null }}
                    </td>
                    <td style="border: 1px solid; width:  11% !important;">
                        {{ $piece->pivot->typereparation->type ?? null }}
                    </td>
                    <td style="border: 1px solid; width:  11% !important;">{{ $piece->pivot->remise ?? null }} %</td>
                    <td style="border: 1px solid; width:  11% !important;">{{ $piece->pivot->vetuste ?? null }}</td>
                    <td style="border: 1px solid; width:  11% !important;">{{ $piece->pivot->prix_unitaire ?? null }}
                    <td style="border: 1px solid; width:  11% !important;">
                        @if ($piece->pivot->type_reparation_id == 1)
                            @php
                                $rem =
                                    $piece->pivot->qte * $piece->pivot->prix_unitaire * ($piece->pivot->remise / 100);
                                $ttlp = $piece->pivot->prix_unitaire * $piece->pivot->qte - $rem;
                                $vet = $ttlp * ($piece->pivot->vetuste / 100);
                                $ttlp = $ttlp - $vet;
                            @endphp
                        @else
                            @php
                                $rem =
                                    $piece->pivot->qte * $piece->pivot->prix_unitaire * ($piece->pivot->remise / 100);
                                $tvaa = ($piece->pivot->prix_unitaire * $piece->pivot->qte - $rem) * 0.2;
                                $ttlp = $piece->pivot->prix_unitaire * $piece->pivot->qte - $rem + $tvaa;

                                if ($devis->taux && $devis->taux->tva_deductible) {
                                    $vet =
                                        ($piece->pivot->qte * $piece->pivot->prix_unitaire - $rem) *
                                        ($piece->pivot->vetuste / 100);
                                } else {
                                    $vet =
                                        ($piece->pivot->qte * $piece->pivot->prix_unitaire - $rem + $tvaa) *
                                        ($piece->pivot->vetuste / 100);
                                }
                                $ttlp = $ttlp - $vet;
                            @endphp
                        @endif
                        {{ $ttlp }}
                    </td>
                </tr>
            @endforeach
        @endif
    </table>
    <div style="margin-top: 60px;">
        <div>
            <table style="border: 1px solid;width: 31%;border-collapse: collapse;font-size:70%;float:left;">
                <tr>
                    <th style="border: 1px solid; width: 43%;"> MONTANT PIECES</th>
                    <th style="border: 1px solid;"> {{ $montantpieces ?? null }}
                        {{ $dossier->currency->symbole ?? null }}</th>
                </tr>
                <tr>
                    <th style="border: 1px solid;">MO CARROUSSERIE</th>
                    <td style="border: 1px solid;">

                        {{ $main01 + $main02 + $main03 }} {{ $dossier->currency->symbole ?? null }}

                    </td>
                </tr>

                <tr>
                    <th style="border: 1px solid;">MO PEINTURE</th>
                    <td style="border: 1px solid;">
                        {{ $main04 ?? 0 }}
                        {{ $dossier->currency->symbole ?? null }}

                    </td>
                </tr>

            </table>
        </div>
        <div>
            <table
                style="border:1px solid; width:31%; border-collapse:collapse;font-size:70%; float:right;margin-left:25px">

                <tr>
                    <th style="border: 1px solid; width: 43%;">MONTANT TOTAL HT</th>
                    <td style="border: 1px solid;"> {{ number_format($ht, 2, '.', ',') }}
                        {{ $dossier->currency->symbole }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">TVA</th>
                    <td style="border: 1px solid;"> {{ number_format($tva, 2, '.', ',') }}
                        {{ $dossier->currency->symbole }}</td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">MONTANT TOTAL TTC</th>
                    <td style="border: 1px solid;">{{ number_format($ttl, 2, '.', ',') }}
                        {{ $dossier->currency->symbole }}</td>
                </tr>


            </table>
        </div>
        <div>
            <table style="border:1px solid; width: 31%; border-collapse:collapse;font-size:70%; float: right; ">

                <tr>
                    <th style="border: 1px solid; width: 43%;">MO MECANIQUE</th>
                    <td style="border: 1px solid;">
                        {{ $main07 ?? 0 }}
                        {{ $dossier->currency->symbole ?? null }}
                    </td>
                </tr>
                <tr>
                    <th style="border: 1px solid; width: 43%;">MO CONTROLE</th>
                    <td style="border: 1px solid;">
                        {{ $main06 ?? 0 }}
                        {{ $dossier->currency->symbole ?? null }}
                    </td>
                </tr>
                <tr>
                    <th style="border: 1px solid;">INGREDIENTS</th>
                    <td style="border: 1px solid;">

                        {{ $ingr ?? null }}
                        {{ $dossier->currency->symbole ?? null }}
                    </td>
                </tr>


            </table>
        </div>

    </div>






    <div style="margin-top: 30px">

        <p style="text-align: center;font-size:66%; margin-top:70px">
            Parc Plaza Bd.Yaakoub Al Mansour lmm.G2 28800 -Mohammedia <br>
            Tél : 052330564-Fax : 0523305672 -E-mail :amea.maroc@gmail.com <br>
            RC:12583 -TP: 39570820-IF:14392431 -CNSS:4472213-ICE:001376800000001
        </p>
        <div>
            <img src="img/sign.png"
                style="height:auto;float: right; width:180px;margin-top: 0px  !important;position: absolute;bottom:0;">
        </div>




    </div>



    <br>



    <div>




    </div>

    <script type="text/php">
        if (isset($pdf)) {
            $pageText = "{PAGE_NUM} / {PAGE_COUNT}";
            $font = null;
            $size = 12;
            $color = array(0, 0, 0);
            $wordSpace = 0.0;
            $charSpace = 0.0;
            $angle = 0.0;
            $x = 280;
            $y = 800;
            $align = 'center';
            $font = $fontMetrics->get_font("Arial", "bold");
            $pdf->page_text($x, $y, $pageText, $font, $size, $color, $wordSpace, $charSpace, $angle);
        }
    </script>
</body>

</html>
