<table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed">
  <thead>
    <?php
    $start_date_1 = new DateTime($start_date);
    $end_date_1 = new DateTime($end_date);

    $starting_day = date('d',strtotime($start_date));
    $no_of_days = $end_date_1->diff($start_date_1)->format("%a");
    ?>
    <tr>
      <th style="text-align:center;font-weight: 900" colspan="<?php echo $no_of_days+3 ?>">Labour Attendance Report For the Date Period - <?php echo strtoupper(date('d F Y',strtotime($start_date))." - ".date('d F Y',strtotime($end_date))); ?></th>
    </tr>
    <tr class="" style="background-color: #ffe875 !important;">
      <th rowspan="2" colspan="2" style="vertical-align: middle;">Days</th>
      <?php for ($day=0; $day <= $no_of_days ; $day++) { ?>
        <th style="text-align: center;"><?php echo date('d',strtotime('+'.$day.' days',strtotime($start_date))); ?></th>
      <?php } ?>
    </tr>
    <tr class="" style="background-color: #ffe875 !important;">
      <?php for ($day=0; $day <= $no_of_days ; $day++) { ?>
        <th style="padding: 1px;padding-bottom: .75rem;text-align: center;">
          <?php
          $day_name = date('D',strtotime('+'.$day.' days',strtotime($start_date)));
          if(strtoupper($day_name)=='SUN'){
            echo strtoupper($day_name);
          }
          ?>
        </th>
      <?php } ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($work_contracts as $key => $value) { ?>
      <tr style="background-color: #9abeff !important;">
        <th style="text-align:center" colspan="<?php echo $no_of_days+3 ?>"><?php echo strtoupper($value->work_name)?></th>
      </tr>
      <?php
      $slno = 1;
      foreach ($value->assigned_labours as $key2 => $value2) { ?>
        <tr>
          <th><?php echo $slno?></th>
          <th><?php echo $value2->labour_name?></th>
          <?php
          $worked_days = array();
          foreach ($value2->worked_days as $key3 => $value3) {
            $worked_days[] = $value3->work_date;
          }
          for ($day=0; $day <= $no_of_days ; $day++) {
            if (in_array(date('Y-m-d',strtotime('+'.$day.' days',strtotime($start_date))), $worked_days)){
              $worked_status = "<label style='font-size: 20px;margin-bottom: 0px;padding: .5rem;padding-bottom: 0px;'>X</label>";
            }else{
              $worked_status = "";
            }
            ?>
            <th style="padding: 1px;padding-bottom: .5rem;">
              <?php echo $worked_status; ?>
            </th>
          <?php } ?>
        </tr>
        <?php
        $slno++;
      }
      foreach ($value->not_assigned_labours as $key22 => $value22) { ?>
        <tr>
          <th><?php echo $slno?></th>
          <th><?php echo $value22->labour_name?></th>
          <?php
          $worked_days = array();
          foreach ($value22->worked_days as $key33 => $value33) {
            $worked_days[] = $value33->work_date;
          }
          for ($day=0; $day <= $no_of_days ; $day++) {
            if (in_array(date('Y-m-d',strtotime('+'.$day.' days',strtotime($start_date))), $worked_days)){
              $worked_status = "<label style='font-size: 20px;margin-bottom: 0px;padding: .5rem;padding-bottom: 0px;'>X</label>";
            }else{
              $worked_status = "";
            }
            ?>
            <th style="padding: 1px;padding-bottom: .5rem;">
              <?php echo $worked_status; ?>
            </th>
          <?php } ?>
        </tr>
        <?php
        $slno++;
      } ?>
    <?php } ?>
  </tbody>
</table>
<br/><br/>
<table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed">
  <thead>
    <tr>
      <th style="text-align:center;font-weight: 900" colspan="<?php echo $no_of_days+3 ?>">Subcontract Labour Attendance Report For the Date Period - <?php echo strtoupper(date('d F Y',strtotime($start_date))." - ".date('d F Y',strtotime($end_date))); ?></th>
    </tr>
    <tr class="" style="background-color: #ffe875 !important;">
      <th rowspan="2" colspan="2" style="vertical-align: middle;">Days</th>
      <?php for ($day=0; $day <= $no_of_days ; $day++) { ?>
        <th style="text-align: center;"><?php echo date('d',strtotime('+'.$day.' days',strtotime($start_date))); ?></th>
      <?php } ?>
    </tr>
    <tr class="" style="background-color: #ffe875 !important;">
      <?php for ($day=0; $day <= $no_of_days ; $day++) { ?>
        <th style="padding: 1px;padding-bottom: .75rem;text-align: center;">
          <?php
          $day_name = date('D',strtotime('+'.$day.' days',strtotime($start_date)));
          if(strtoupper($day_name)=='SUN'){
            echo strtoupper($day_name);
          }
          ?>
        </th>
      <?php } ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($work_contracts as $key => $value) { ?>
      <tr style="background-color: #9abeff !important;">
        <th style="text-align:center" colspan="<?php echo $no_of_days+3 ?>"><?php echo strtoupper($value->work_name)?></th>
      </tr>
      <?php
      foreach ($value->subcontracts as $key11 => $value11) { ?>
        <tr style="background-color: #ffaefc !important;">
          <th style="text-align:center" colspan="<?php echo $no_of_days+3 ?>">Subcontract : <?php echo strtoupper($value11->contractor_name." - ".$value11->sub_work_name)?></th>
        </tr>
        <?php
        $slno = 1;
        foreach ($value11->labours as $key2 => $value2) { ?>
          <tr>
            <th><?php echo $slno?></th>
            <th><?php echo $value2->labour_name?></th>
            <?php
            $worked_days = array();
            foreach ($value2->worked_days as $key3 => $value3) {
              $worked_days[] = $value3->date;
            }
            for ($day=0; $day <= $no_of_days ; $day++) {
              if (in_array(date('Y-m-d',strtotime('+'.$day.' days',strtotime($start_date))), $worked_days)){
                $worked_status = "<label style='font-size: 20px;margin-bottom: 0px;padding: .5rem;padding-bottom: 0px;'>X</label>";
              }else{
                $worked_status = "";
              }
              ?>
              <th style="padding: 1px;padding-bottom: .5rem;">
                <?php echo $worked_status; ?>
              </th>
            <?php } ?>
          </tr>
          <?php
          $slno++;
        }
      }
    } ?>
  </tbody>
</table>
