<!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">
    <title>{{ $filename }}</title>
    <style>
        .rotate {
            /* FF3.5+ */
            -moz-transform: rotate(-90.0deg);
            /* Opera 10.5 */
            -o-transform: rotate(-90.0deg);
            /* Saf3.1+, Chrome */
            -webkit-transform: rotate(-90.0deg);
            /* IE6,IE7 */
            filter: progid: DXImageTransform.Microsoft.BasicImage(rotation=0.083);
            /* IE8 */
            -ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)";
            /* Standard */
            transform: rotate(-90.0deg);
        }

        td.second {
            border: 1px dashed green;
            font-size: 15pt;
        }

        table.this {
            border-collapse: collapse;
        }

        table.this tr {
            border: 1px solid black;

        }

        table.this td {
            border: 1px solid black;
        }
    </style>

</head>

<body>
    <hr>
    <div style="font-family:Calibri;font-size:10px;">
        <table style="margin:0;padding:0;padding-top:0px;width:107%;">
            <tr>
                <td style="width:10%;display:inline-block;vertical-align:top;">
                    <div></div>
                    <img src="{{ config('app.aws_url') . $universite->nameimguni }}" alt=""
                        style="width:100px;height:100px;" />

                </td>
                <td style="width:70%;display:inline-block;text-align:center;font-family:Comic;font-size:12px;">
                    <h4 style="margin:0; font-size:15px;">REPUBLIQUE DU BENIN</h4>
                    <span>****************</span>
                    <h4 style="margin:0; font-size:15px;">MINISTERE DE L'ENSEIGNEMENT SUPERIEUR ET DE LA
                        RECHERCHE
                        SCIENTIFIQUE</h4>
                    <span>****************</span>
                    <h2 style="margin:0; font-size:15px;">{{ $universite->descruni }}</h2>
                    <span>****************</span>
                    <h3 style="margin:0;padding:0; font-size:15px;">{{ $etablissement->descreta }}</h3>
                    <span>****************</span>
                </td>
                <td style="width:10%;display:inline-block;vertical-align:top;padding-left:100px;">
                    <div></div>
                    <img src="{{ config('app.aws_url') . $etablissement->nameimgeta }}" alt=""
                        style="width:120px;height:120px; align:right;" />
                </td>
            </tr>
        </table>
    </div>
    <table border="1" cellpadding="2" cellspacing="4" style="width:100%; margin-top:50px; margin-bottom:30px;">
        <tr style="background-color:#ffffee;color:#0000FF;">
            <td align="center" class="second">{{ $data['text'] }}</td>
        </tr>
    </table>

    @foreach ($data['annees'] as $annee)
        <table style="border-color:black; width:100%" class="this" cellpadding="10">
            <thead>
                <tr style="background-color:#ffe6e6;color:#0000FF;">
                    <td width="3%" align="center">#</td>
                    <td width="8%" align="center">CREDIT UE</td>
                    <td width="8%" align="center">CODE UE</td>
                    <td width="35%">
                        <div>INTITULE UNITE D'ENSEIGNEMENT</div>
                    </td>
                    <td width="8%" align="center">CODE EC</td>
                    <td width="30%">INTITULE ELEMENT CONSTITUTIF (EC)</td>
                    <td width="8%" align="center">POIDS EC</td>
                </tr>
            </thead>
            <tbody>
                @php
                    if ($annee->annee == 1) {
                        $ids[0] = 1;
                        $ids[1] = 2;
                    } elseif ($annee->annee == 2) {
                        $ids[0] = 3;
                        $ids[1] = 4;
                    } elseif ($annee->annee == 3) {
                        $ids[0] = 5;
                        $ids[1] = 6;
                    }
                    $sumCredit = App\Models\ElementC::where(['idFiliere' => $data['idFiliere'], 'annee' => $data['etudeYear'], 'niveauFormation' => $data['formation'], 'annee_acad' => $data['acadYear']])->sum('credit');
                    $j = 0;
                @endphp
                @for ($k = 0; $k < 2; $k++)
                    @php
                        $sumCreditSem = App\Models\UnitesE::where(['idFIliere' => $data['idFiliere'], 'annee' => $data['etudeYear'], 'niveauFormation' => $data['formation'], 'annee_acad' => $data['acadYear'], 'semestre' => $ids[$k]])->sum('credit');
                        if ($sumCreditSem < 30) {
                            $color = '#ff0000';
                        } else {
                            $color = '#00ffff';
                        }
                    @endphp
                    <tr style="background-color:#d7e4db;color:#0000FF;">
                        <td width="3%"></td>
                        <td width="8%" align="center" style="background-color:{{ $color }}">
                            {{ $sumCreditSem }}
                        </td>
                        <td width="8%"></td>
                        <td width="35%"></td>
                        <td width="8%" align="center">SEMESTRE {{ $ids[$k] }}</td>
                        <td width="30%"></td>
                        <td width="8%"></td>
                    </tr>
                    @php

                        $inser = $data['session'] == 0 ? 'YES' : 'NO';
                        $unites = App\Models\UnitesE::where(['idFiliere' => $data['idFiliere'], 'annee' => $data['etudeYear'], 'niveauFormation' => $data['formation'], 'annee_acad' => $data['acadYear'], 'semestre' => $ids[$k]])->get();
                    @endphp
                    @foreach ($unites as $unite)
                        @php
                            $c = App\Http\Helpers\AdditionalHelpers::couleurAlterner();
                            if ($unite->type_ue == 0) {
                                $couleur = '#000000';
                            } elseif ($unite->type_ue == 1) {
                                $couleur = '#ff0000';
                            } elseif ($unite->type_ue == 2) {
                                $couleur = '#0000ff';
                            } elseif ($unite->type_ue == 3) {
                                $couleur = '#008100';
                            }
                            $ecus = $data['session'] == 0 ? App\Models\ElementC::where(['idFiliere' => $data['idFiliere'], 'annee' => $data['etudeYear'], 'annee_acad' => $data['acadYear'], 'code_unite' => $unite->code_unite, 'insertion' => $inser])->get() : App\Models\ElementC::where(['idFiliere' => $data['idFiliere'], 'annee' => $data['etudeYear'], 'annee_acad' => $data['acadYear'], 'code_unite' => $unite->code_unite, 'rattrapage' => $inser])->get();
                            $total = $ecus->count();
                        @endphp
                        @if ($total > 0)
                            @php
                                $j++;
                            @endphp
                            <tr>
                                <td width="3%" align="center" rowspan="{{ $total }}">
                                    {{ $j }}</td>
                                <td width="8%" align="center" style="background-color:{{ $c }}"
                                    rowspan="{{ $total }}">{{ $unite->credit }}
                                </td>
                                <td width="8%" align="center" rowspan="{{ $total }}">
                                    {{ $unite->code_unite }}
                                </td>
                                <td width="35%" rowspan="{{ $total }}">
                                    <font color="{{ $couleur }}">{{ $unite->intituleUnite }}</font>
                                </td>
                                <td width="8%" align="center">{{ $ecus[0]->code_ecu }}</td>
                                <td width="30%">{{ $ecus[0]->intituleEcu }}</td>
                                <td width="8%"align="center">{{ $ecus[0]->credit }}</td>
                            </tr>
                            @for ($i = 1; $i < $ecus->count(); $i++)
                                <tr>
                                    <td width="8%" align="center">{{ $ecus[$i]->code_ecu }}</td>
                                    <td width="30%">{{ $ecus[$i]->intituleEcu }}</td>
                                    <td width="8%" align="center">{{ $ecus[$i]->credit }}</td>
                                </tr>
                            @endfor
                        @endif
                    @endforeach
                @endfor
                @php
                    if ($sumCredit < 60) {
                        $color = '#ff0000';
                    } else {
                        $color = '#00ffff';
                    }
                @endphp
                <tr style="background-color:#d7e4db;color:#0000FF;">
                    <td colspan="6" align="center">
                        TOTAL CREDIT SEMESTRE {{ $ids[0] }} & SEMESTRE {{ $ids[1] }}
                    </td>
                    <td align="center" style="background-color:{{ $color }}">{{ $sumCredit }}
                    </td>
                </tr>
            </tbody>
        </table>
        <br>
    @endforeach

    <table style="width:50%;margin:0;padding:5;border:1px solid black" class="this">
        <tbody>
            <tr>
                <td style="background-color: #d7e4db" colspan="2" align="center"> LEGENDE TABLEAU DE
                    SPECIFICATION</td>
            </tr>
            <tr>
                <td style="background-color: #000000" width="7%">
                    <div></div>
                </td>

                <td width="40%"> Unité de Connaissance Fondamentales </td>
            </tr>

            <tr>
                <td style="background-color: #ff0000" width="7%"> </td>

                <td width="40%"> Unité de Spécialité </td>
            </tr>

            <tr>
                <td style="background-color: #0000ff" width="7%"> </td>

                <td width="40%"> Unité de Méthodologie </td>
            </tr>

            <tr>
                <td style="background-color: #008100" width="7%"> </td>

                <td width="40%"> Unité de Culture Générale </td>
            </tr>
        </tbody>
    </table>

</body>

</html>
