<style>
#header {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#header td, #customers th {
 
  padding:4px;
  font-size:10px;
}

#header tr:nth-child(even){background-color: #ffffff;}

#header tr:hover {background-color: #ddd;}

#header th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  padding:4px;
  color:black;
}
</style>




<style>
#scan {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#scan td, #scan th {
 
  padding: 8px;
  font-size:11px;
}

#scan tr:nth-child(even){background-color: #ffffff;}

#scan tr:hover {background-color: #ddd;}

#scan th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  padding:4px;
  color:black;
}
</style>


<style>
#scan {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#scan td, #scan th {
  border-collapse: collapse;
  padding: 8px;
  font-size:11px;
}

#scan tr:nth-child(even){background-color: #ffffff;}

#scan tr:hover {background-color: #ddd;}

#scan th {
  border-collapse: collapse;
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  padding:4px;
  color:black;
}
</style>



<style>
#details {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
  border:1px solid black;
}

#details td, #details th {
 
  padding: 8px;
  font-size:11px;
}

#details tr:nth-child(even){background-color: #ffffff;}

#details tr:hover {background-color: #ddd;}

#details th {
  padding-top: 12px;
 font-style:bold;
  padding-bottom: 12px;
  text-align: left;
  padding:4px;
  color:black;
}
</style>

<style>
#sign {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#sign td, #sign th {

  padding: 8px;
  font-size:11px;
  text-align: center;
}

#sign tr:nth-child(even){background-color: #ffffff;}

#sign tr:hover {background-color: #ddd;}

#sign th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  padding:4px;
  color:black;
}

.stylela{

  border-bottom:1px solid black;
  margin:6px 0 6px 0;

}

</style>


<table id="header">
  <tr>
    <th rowspan="4"  style="width:50px"><br><img src="{{ asset('img/ARRAHN1.png') }}" style="width:70px"></img></th>
    <th colspan="1">KOPERASI PERMODALAN KELANTAN BERHAD</th>
  </tr>
  <tr>
    <td>{{ $cawangan_detail['namacaw'] }}</td>
    <td></td>
  </tr>
  <tr>
    <td>{{ $cawangan_detail['alamat1'] }}</td>
    <td></td>
  </tr>
  <tr>
    <td>{{ $cawangan_detail['alamat2'].' No Tel : '. $cawangan_detail['notel'].' No Faks : '. $cawangan_detail['nofaks'] }}</td>
    <td></td>
  </tr>
</table>
<br>

<table id="scan">
  <tr>
    <th colspan ="5"><b>LAPORAN MARHUN TERKUMPUL</b></th>
    <th> </th>
    <th> </th>
    <th><b> Tarikh Cetak:</b>
        @php 
          $myDateTime = DateTime::createFromFormat('Y-m-d', $tarikh_cetak);
          $formattedweddingdate = $myDateTime->format('d-m-Y');
          echo($formattedweddingdate)
        @endphp
    </th>
    <th></th>
  </tr>
  <tr>
    <td style="width:10px"> <b>TARIKH</b></td>
    <td>@php 
          $myDateTime = DateTime::createFromFormat('Y-m-d', $tebus_date);
          $formattedweddingdate = $myDateTime->format('d-m-Y');
          echo($formattedweddingdate)
        @endphp</td>
    <td style="width:50px">   
    </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>

<br>
<table id="details">
  <tr>
    <th colspan="5"></th>
    <th colspan="4" style="text-align: center;border-right:1px solid black;">Pembiayaan Asal</th>
    <th colspan="5" style="text-align: center;">Semakan</th>
  </tr>
  <tr>
    <th class="stylela">Bil</th>
    <th class="stylela">No Rujukan</th>
    <th class="stylela">No K/P</th>
    <th class="stylela">Nama</th>
    <th class="stylela">Pembiayaan</th>
    <th class="stylela">Marhun</th>
    <th class="stylela">Mutu</th>
    <th class="stylela">Berat</th>
    <th class="stylela" style="border-right:1px solid black;">N. Marhun</th>
    <th class="stylela">Marhun</th>
    <th class="stylela">Mutu</th>
    <th class="stylela">Berat</th>
    <th class="stylela">N.Marhun</th>
    <th class="stylela">Catatan</th>
  </tr>
  @php $counter = 1;$totalberat = 0;$totalnm = 0;$masuk = false;$pertama = true;$totalkeseluruhanmarhun = 0;$totalkeseluruhanpinjaman = 0;$totalkeseluruhanberat = 0;@endphp

  @foreach($marhun as $index=>$item)
  @php $totalkeseluruhanmarhun += floatval($item['n_marhun']);$totalkeseluruhanberat += floatval($item['berat']);  @endphp 
    <tr>
      @if($index == 0)
        {{-- <td>masuk mula</td> --}}
         <td>{{ $counter }}</td>
        <td>{{ $item['norujukan'] }}</td>
        <td>{{ $item['nokp'] }}</td>
        <td>{{ $item['nama'] }}</td>
        <td>{{ number_format($item['pinjaman'],2) }}</td>
        <td style="border-top:1px solid black;">{{ $item['marhun'] }}</td>
        <td style="border-top:1px solid black;">{{ $item['karat'] }}</td>
        <td style="border-top:1px solid black;">{{ $item['berat'] }}</td>
        <td style="border-right:1px solid black;border-top:1px solid black;">{{ number_format($item['n_marhun'],2) }}</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        @if($index != sizeof($marhun) - 1)
          {{-- <td>kedua</td> --}}
            @if($item['norujukan'] != $marhun[$index+1]['norujukan'])
                <tr>
                  {{-- <td>ketiga</td> --}}
                  <td class="stylela" colspan="6"></td>
                  <td class="stylela" style="font-weight: bold;"> JUMLAH</td>
                  <td class="stylela"> {{ number_format($item['berat'],2) }}</td>
                  <td class="stylela" style="border-right:1px solid black;"> {{ number_format($item['n_marhun'],2) }}</td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                </tr>
            @endif
        @endif
        @php $counter++; $masuk = true;$totalnm += floatval($item['n_marhun']);$totalberat += floatval($item['berat']); @endphp
      @else
        @if($item['norujukan'] == $marhun[$index-1]['norujukan'])
                {{-- <td>masuk 1</td> --}}
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>{{ $item['marhun'] }}</td>
                <td>{{ $item['karat'] }}</td>
                <td>{{ number_format($item['berat'],2) }}</td>
                <td style="border-right:1px solid black;">{{ number_format($item['n_marhun'],2) }}</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                  @php  
                  $totalberat += floatval($item['berat']);
                  $totalnm += floatval($item['n_marhun']); 
                  @endphp
        @else
        
          @php  
          $totalberat += floatval($item['berat']);
          $totalnm += floatval($item['n_marhun']); 
          @endphp

          {{-- <td>masuk2</td> --}}
          <td style="border-top:1px solid black;">{{ $counter }}</td>
          <td style="border-top:1px solid black;">{{ $item['norujukan'] }}</td>
          <td style="border-top:1px solid black;">{{ $item['nokp'] }}</td>
          <td style="border-top:1px solid black;">{{ $item['nama'] }}</td>
          <td style="border-top:1px solid black;">{{ number_format($item['pinjaman'],2) }}</td>
          <td style="border-top:1px solid black;">{{ $item['marhun'] }}</td>
          <td style="border-top:1px solid black;">{{ $item['karat'] }}</td>
          <td style="border-top:1px solid black;">{{ number_format($item['berat'],2) }}</td>
          <td style="border-right:1px solid black;border-top:1px solid black;">{{ number_format($item['n_marhun'],2) }}</td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          
          @php $counter++; $masuk = true; @endphp
        @endif
      @endif

      @if(($index != sizeof($marhun) - 1 && $masuk == true))
      {{-- <td>kucen</td> --}}
        @if($item['norujukan'] != $marhun[$index+1]['norujukan'])
          <tr>
            <td class="stylela" colspan="6"></td>
            <td class="stylela"> JUMLAH</td>
            <td class="stylela"> {{ number_format($totalberat,2) }}</td>
            <td class="stylela" style="border-right:1px solid black;"> {{ number_format($totalnm,2) }}</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
        @php $totalberat = 0;$totalnm = 0;@endphp
        @endif 
      @endif

      @if(($index == sizeof($marhun) - 1))
      {{-- <td>kucen2</td> --}}
          <tr>
            <td class="stylela" colspan="6"></td>
            <td class="stylela"> JUMLAH</td>
            <td class="stylela"> {{ number_format($totalberat,2) }}</td>
            <td class="stylela" style="border-right:1px solid black;"> {{ number_format($totalnm,2) }}</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
        @php $totalberat = 0;$totalnm = 0;@endphp
      @endif

     
    </tr>    
  @endforeach
  <tr>
    <td colspan="4"></td>
    <td></td>
    <td></td>
    <td><b>JUMLAH</b></td>
    <td>{{ number_format($totalkeseluruhanberat,2) }}</td>
    <td style="border-right:1px solid black;">{{ number_format($totalkeseluruhanmarhun,2) }}</td>
    <td style="border-top:1px solid black;">
    <td style="border-top:1px solid black;">
    <td style="border-top:1px solid black;">
    <td style="border-top:1px solid black;">
    <td style="border-top:1px solid black;">
  </tr>
</table>

<br>
<br>
<table id="sign">
  <tr>
    <td></td>
    <td colspan="2"> .................................................................. </td>
    <td> </td>
    <td colspan="2">.................................................................. </td>
    <td> </td>
  </tr>
  <tr>
    <td></td>
    <td colspan="2"><B> DI SEMAK</B> </td>
    <td> </td>
    <td colspan="2"><B>DI SAHKAN </B></td>
    <td> </td>
  </tr>
</table>






