<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>بطاقة النتائج المدرسية</title>
    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        @media print {
            @page {
                size: landscape;
                margin: 0.5cm;
            }
            body {
                -webkit-print-color-adjust: exact;
            }
            .no-print {
                display: none;
            }
        }
      
    </style>
</head>
<body class="bg-gray-100 flex justify-center min-h-screen ">
    <div class="bg-white w-[100%] border border-black rounded  overflow-hidden">
        <!-- Header -->
        <div class="p-2 border-b border-black">
            <div class="flex justify-between text-xs">
                <div>
                    <div class="flex items-center text-gray-800 text-sm">
                        <p class="font-semibold">الجمهورية التونسية</p>
                        <span class="px-2">|</span>
                        <p>وزارة التربية</p>
                    </div>
                    
                    <p class="text-gray-800">المندوبية الجهوية للتربية بمدنين</p>
                    <p class="text-gray-800">المعهد الثانوي الخاص 1966 جرجيس</p>
                </div>
                <div class="text-center">
                    <p class="text-sm font-bold text-gray-900">الدفتر المدرسي</p>
               
                </div>
                <div class="text-right">
                    <p class="text-gray-800">السنة الدراسية:<span id="current-year"></span></p>
                </div>
            </div>
        </div>

        <!-- Student Details -->
        <div class="p-2 border-b border-black text-xs">
            <div class="flex justify-between text-gray-700">
                <p>اسم التلميذ (ة) و لقبه (ها)  <?php echo e($eleve->first_name); ?> <?php echo e($eleve->last_name); ?> </p>
                <p>رقم التسجيل   <?php echo e($eleve->code); ?> </p>
                <p>تاريخ الولادة: <?php echo e($eleve->date); ?></p>
            </div>
            <div class="flex justify-between text-gray-700">
            <p>    القسم : <?php echo e($classe->name); ?> <?php echo e($classe->year); ?></p>

                <p>عدد التلاميذ: <?php echo e($nbreleve->eleves_count); ?></p>
            </div>
        </div>

        <!-- Table -->
        <table class="w-full border-collapse border border-black text-[10px]">
            <thead class="bg-gray-200 text-gray-700">
                <tr>
                    <th class="border border-black px-1 py-1">المواد</th>

                    <th class="border border-gray-700 px-4 py-2" colspan="2">
                        <div style="text-align: center; border-bottom: 1px solid gray; margin-bottom: 5px;">الثلاثي الأول</div>
                        <div style="display: flex; justify-content: space-evenly; align-items: center;">
                            <span style="flex: 1; text-align: center;">المعدل</span>
                            <div style="width: 1px; height: 100%; background-color: gray;"></div>
                            <span style="flex: 1; text-align: center;">الرتبة</span>
                        </div>
                    </th>
                    <th class="border border-gray-700 px-4 py-2" colspan="2">
                        <div style="text-align: center; border-bottom: 1px solid gray; margin-bottom: 5px;">الثلاثي الثاني</div>
                        <div style="display: flex; justify-content: space-evenly; align-items: center;">
                            <span style="flex: 1; text-align: center;">المعدل</span>
                            <div style="width: 1px; height: 100%; background-color: gray;"></div>
                            <span style="flex: 1; text-align: center;">الرتبة</span>
                        </div>
                    </th>
          
                    <th class="border border-gray-700 px-4 py-2" colspan="2">
                        <div style="text-align: center; border-bottom: 1px solid gray; margin-bottom: 5px;">الثلاثي الثالث</div>
                        <div style="display: flex; justify-content: space-evenly; align-items: center;">
                            <span style="flex: 1; text-align: center;">المعدل</span>
                            <div style="width: 1px; height: 100%; background-color: gray;"></div>
                            <span style="flex: 1; text-align: center;">الرتبة</span>
                        </div>
                    </th>
                    <th class="border border-gray-700 px-4 py-2" colspan="2">
                        <div style="text-align: center; border-bottom: 1px solid gray; margin-bottom: 5px;">السنوي</div>
                        <div style="display: flex; justify-content: space-evenly; align-items: center;">
                            <span style="flex: 1; text-align: center;">المعدل</span>
                            <div style="width: 1px; height: 100%; background-color: gray;"></div>
                            <span style="flex: 1; text-align: center;">الرتبة</span>
                        </div>
                    </th>
                    <th class="border border-black px-1 py-1"> الأستاذ (ة)</th>
                    <th class="border border-black px-1 py-1">ملاحظات الأستاذ (ة) </th>
                    <th class="border border-black px-1 py-1">الامضاء </th>

                </tr>
            </thead>
            <tbody>
            <?php
    $iterationCount = 0; // Initialize iteration counter
?>
<?php
$subjectOrder = [
  'عربية', 'فلسفة', 'انقليزية', 'فرنسية', 'تاريخ',
  'جغرافيا', 'تربية مدنية', 'تربية اسلامية', 'رياضيات', 
  'علوم طبيعية', 'علوم فيزياء', 'علوم فيزيائية', 'اقتصاد', 'تصرف',
  'تربية تشكلية', 'المانية', 'رياضة', 'اعلامية'
];

    // Sort the collection manually by your custom order
    $dataSorted = collect($subjectOrder)->map(function($name) use ($data) {
        return $data->firstWhere('matiere.name', $name);
    })->filter(); // remove nulls if any subject is missing
?>

<?php $__currentLoopData = $dataSorted; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subject): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <tr>
        <td class="border border-black px-1 py-1" style="color: black; font-size: 0.75rem;">
            <?php echo e($subject->matiere->name ?? '-'); ?>

        </td>

        
        <?php
            $quarter1 = $data->where('score_id', 1)->where('matiere_id', $subject->matiere_id)->first();
        ?>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter1->quarter_average ?? '-'); ?></td>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter1->rank ?? '-'); ?></td>

        
        <?php
            $quarter2 = $data->where('score_id', 2)->where('matiere_id', $subject->matiere_id)->first();
        ?>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter2->quarter_average ?? '-'); ?></td>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter2->rank ?? '-'); ?></td>

        
        <?php
            $quarter3 = $data->where('score_id', 3)->where('matiere_id', $subject->matiere_id)->first();
        ?>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter3->quarter_average ?? '-'); ?></td>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($quarter3->rank ?? '-'); ?></td>

        
      <?php
    $gen = $genSubjects->where('matiere_id', $subject->matiere_id)->first();
?>

<td class="border border-gray-700 px-4 py-2 text-center">
    <?php echo e($gen->moyenne ?? '-'); ?>

</td>
        <td class="border border-gray-700 px-4 py-2 text-center"><?php echo e($gen->rank ?? '-'); ?></td>

         
        <td class="border border-black px-1 py-1"><?php echo e($subject->professor->first_name); ?> <?php echo e($subject->professor->last_name); ?></td>


        <td class="border border-black px-1 py-1"></td>

       
        <td class="border border-black px-1 py-1"></td>
    </tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


<!--<?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subject): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>-->
<!--    <?php-->
<!--        $iterationCount++;-->
<!--        if ($iterationCount > $scount) break; // Stop iteration if count exceeds $scount-->
<!--    ?>-->
<!--    <tr>-->
        <!-- Subject Name -->
<!--        <td class="border border-black px-1 py-1" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($subject->matiere->name ?? '-'); ?>-->
<!--        </td>-->

        <!-- الثلاثي الأول -->
<!--        <?php-->
<!--            $quarter1 = $data->where('score_id', 1)->where('matiere_id', $subject->matiere_id)->first();-->
<!--        ?>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter1->quarter_average ?? '-'); ?>-->
<!--        </td>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter1->rank ?? '-'); ?>-->
<!--        </td>-->

        <!-- الثلاثي الثاني -->
<!--        <?php-->
<!--            $quarter2 = $data->where('score_id', 2)->where('matiere_id', $subject->matiere_id)->first();-->
<!--        ?>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter2->quarter_average ?? '-'); ?>-->
<!--        </td>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter2->rank ?? '-'); ?>-->
<!--        </td>-->

        <!-- الثلاثي الثالث -->
<!--        <?php-->
<!--            $quarter3 = $data->where('score_id', 3)->where('matiere_id', $subject->matiere_id)->first();-->
<!--        ?>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter3->quarter_average ?? '-'); ?>-->
<!--        </td>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($quarter3->rank ?? '-'); ?>-->
<!--        </td>-->

        <!-- السنوي -->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
            <!-- Calculate annual average if needed -->
<!--        </td>-->
<!--        <td class="border border-gray-700 px-4 py-2 text-center" style="color: black; font-size: 0.75rem;">-->
            <!-- Add annual rank if needed -->
<!--        </td>-->

        <!-- الأستاذ (ة) -->
<!--        <td class="border border-black px-1 py-1" style="color: black; font-size: 0.75rem;">-->
<!--            <?php echo e($subject->professor->first_name); ?> <?php echo e($subject->professor->last_name); ?>-->
<!--        </td>-->

        <!-- ملاحظات الأستاذ (ة) -->
<!--        <td class="border border-black px-1 py-1" style="color: black; font-size: 0.75rem;"></td>-->

        <!-- الامضاء -->
<!--        <td class="border border-black px-1 py-1"></td>-->
<!--    </tr>-->
<!--<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>-->
 
            </tbody>
        </table>
        <table class="table-fixed w-full border-collapse">
        <thead class="bg-gray-200 text-gray-700">
          <tr>

          <th class="border border-gray-400  text-sm font-bold text-gray-700">
              فترة الامتحان
            </th>
            <th class="border border-gray-400  text-sm font-bold text-gray-700">
              المعدل
            </th>
          <th class="border border-gray-400  text-sm font-bold text-gray-700">
            الرتبة
            </th>
            <th class="border border-gray-400  text-sm font-bold text-gray-700">
            الجوائز و العقوبات
            </th>
            <th class="border border-gray-400  text-sm font-bold text-gray-700">
المعدل السنوي  :  <?php echo e($moyennegen); ?>

            </th>
        
           
         
         
            <th class="border border-gray-400  text-sm font-bold text-gray-700">
              قرار مجلس القسم و ملاحظات المدير
            </th>
            <th class="border border-gray-400  text-sm font-bold text-gray-700">
              قرار مجلس التوجيه
            </th>
          </tr>
        </thead>
        <tbody>
  



          <tr>
          <td class="border border-gray-400 text-center  text-gray-700">
              الثلاثي الأول
            </td>
           
           
            <td class="border border-gray-400 text-center  text-gray-700">
                
            <?php if(number_format($m, 2) == '0.00'): ?>
    معفى
<?php else: ?>
    <?php echo e(number_format($m, 2)); ?>

<?php endif; ?>

            
            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
            <?php echo e($rank1); ?>

            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
              
              </td>
            <td
              rowspan="4"
              class="border border-gray-400 text-center  text-sm text-gray-700"
            >
              عدد التلاميذ:  <?php echo e($nbreleve->eleves_count); ?> <br />
الرتبة  :    <?php echo e($rankgen); ?>

            </td>
            <td
              rowspan="4"
              class="border border-gray-400 text-center text-sm text-gray-700"
            >
             المدير (ة) : رحاب المحروق
            </td>
            <td
              rowspan="4"
              class="border border-gray-400 text-center  text-sm text-gray-700"
            >
               
            </td>
          </tr>
          <tr>
          <td class="border border-gray-400 text-center  text-gray-700">
              الثلاثي الثاني
            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
           
<?php if(number_format($mdeux, 2) == '0.00'): ?>
    معفى
<?php else: ?>
    <?php echo e(number_format($mdeux, 2)); ?>

<?php endif; ?>

            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
            <?php echo e($rank2); ?>


            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
              
              </td>
        
          </tr>
          <tr>
          <td class="border border-gray-400 text-center  text-gray-700">
              الثلاثي الثالث
            </td>
            <td class="border border-gray-400 text-center text-gray-700">
         
<?php if(number_format($mth, 2) == '0.00'): ?>
    معفى
<?php else: ?>
    <?php echo e(number_format($mth, 2)); ?>

<?php endif; ?>
            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
            <?php echo e($rank3); ?>


            </td>
            <td class="border border-gray-400 text-center  text-gray-700">
              
            </td>
         
          </tr>
        </tbody>
      </table>
    </div>

 
</body>
<script>
       
 const currentYear = new Date().getFullYear(); 
const academicYear = `${currentYear}/${currentYear - 1}`; 


        // Display the year in the span with id "current-year"
        document.getElementById("current-year").textContent = academicYear;

       // Get the full path from the URL
       const path = window.location.pathname;

// Split the path into segments
const segments = path.split('/');

// Select the element to display the result
const display = document.getElementById('scoreDisplay');

// Extract the value after '/score/' (e.g., 1, 2, or 3)
const scoreIndex = segments.indexOf('score');
const scoreValue = scoreIndex !== -1 ? segments[scoreIndex + 1] : null;

// Check the score value and update the display
if (scoreValue === '1') {
    display.textContent = 'الثلاثي الأول';
} else if (scoreValue === '2') {
    display.textContent = 'الثلاثي الثاني';
} else if (scoreValue === '3') {
    display.textContent = 'الثلاثي الثالث';
} else {
    display.textContent = 'مسار غير معروف';
}
    </script>
</html>
<?php /**PATH /home/wzhvrvkx/public_html/my-app/resources/views/classes/dossiers.blade.php ENDPATH**/ ?>