<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%;
}

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

#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;
}

@media print {
  .new-page {
    page-break-before: always;
  }
}

</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 style="font-size:20px;font-weight:bold;">{{ $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 PENEBUSAN</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>Bil</th>
    <th>Norujukan</th>
    <th>Nama</th>
    <th>No KP</th>
    <th>T Gadai</th>
    <th>T Tebus</th>
    <th>JBG</th>
    <th width="6%;">Pembiayaan(RM)</th>
    <th width="6%;">Upah/Keuntungan(RM)</th>
    <th width="6%;">Bayaran(RM)</th>
  </tr>
  @php $counter = 1; $totalbayaran = 0;@endphp
  @foreach($tebus as $index=>$item)
  @php $totalbayaran += $item['bakipjm'] @endphp
    @if($index > 0)
        @if($item['teller'] != $tebus[$index - 1]['teller'])
            <tr>
                <td colspan="12">Teller : <b>{{ $item['teller'] }}</b></td>
            </tr>
            @php $totalpinjamanteller = 0;$totalupahteller = 0;$totalbayaranteller = 0; @endphp
        @endif
    @else
        <tr>
            <td colspan="12">Teller : <b>{{ $item['teller'] }}</b></td>
        </tr>
        @php $totalpinjamanteller = 0;$totalupahteller = 0;$totalbayaranteller = 0; @endphp
    @endif
    <tr>
      <td>{{ $counter }}</td>
      <td>{{ $item['norujukan'] }}</td>
      <td>
        @php
            $gadai_detail = Http::get($api_url . '/api/gadai/norujukan/'. $item['norujukan'])->json();
            $customer_detail = Http::get($api_url . '/api/customers/' . $gadai_detail[0][0]['nokp'])->json();
            
            echo $customer_detail[0]['nama'];
        @endphp
      </td>
      <td>{{$gadai_detail[0][0]['nokp']}}</td>
      <td>
        @php 
          $myDateTime = DateTime::createFromFormat('Y-m-d', $gadai_detail[0][0]['t_gadai']);
          $formattedweddingdate = $myDateTime->format('d-m-Y');
          echo($formattedweddingdate)
        @endphp
      </td>
      <td>{{$item['t_tebus']}}</td>
      <td>{{$item['jbg']}}</td>
      <td>{{$item['pinjaman']}}</td>
      <td>{{$item['bakiupah']}}</td>
      <td>{{$item['bakipjm']}}</td>
    </tr>
    @php $counter++; @endphp
    @php $totalpinjamanteller += $item['pinjaman'];$totalupahteller += $item['bakiupah'];$totalbayaranteller += $item['bakipjm']; @endphp
    @if($index+1 < sizeof($tebus))
        @if($item['teller'] != $tebus[$index + 1]['teller'])
            <tr class="new-page">
                <td colspan="7"><b>{{ $counter-1 }}</b> Jumlah Bagi Teller : <b>{{ $item['teller'] }}</b></td>
                <td><b>{{ number_format($totalpinjamanteller,2) }} </b></td>
                <td><b>{{ number_format($totalupahteller,2) }} </b></td>
                <td><b>{{ number_format($totalbayaranteller,2) }} </b></td>
            </tr>
            @php $counter = 0; @endphp
        @endif
    @else
        <tr class="new-page">
            <td colspan="7"><b>{{ $counter-1 }}</b> Jumlah Bagi Teller : <b>{{ $item['teller'] }}</b></td>
            <td><b>{{ number_format($totalpinjamanteller,2) }} </b></td>
            <td><b>{{ number_format($totalupahteller,2) }} </b></td>
            <td><b>{{ number_format($totalbayaranteller,2) }} </b></td>
        </tr>
    @endif
  @endforeach
</table>

<h5 style="float:right;">JUMLAH KESELURUHAN BAYARAN : RM {{ number_format($totalbayaran,2) }}</h5>

<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>

<h4>Laporan Transaksi Penebusan</h4>
<br>

<table id="details">
  <thead>
    <th>Bil</th>
    <th>Jenis</th>
    <th>Penebusan(RM)</th>
    <th>Keuntungan(RM)</th>
    <th>Rebate(RM)</th>
  </thead>
  <tr>
    <td>{{ $tebuspengasingan['biltawarruq'] }}</td>
    <td>Tawarruq</td>
    <td>{{ number_format($tebuspengasingan['totaltawarruq'],2) }}</td>
    <td>{{ number_format($tebuspengasingan['keuntungantawarruq'],2) }}</td>
    <td>{{ number_format($tebuspengasingan['totalrebate'],2) }}</td>
  </tr>
  <tr>
    <td>{{ $tebuspengasingan['bilarrahn'] }}</td>
    <td>Ar-Rahn</td>
    <td>{{ number_format($tebuspengasingan['totalarrahn'],2) }}</td>
    <td>{{ number_format($tebuspengasingan['keuntunganarrahn'],2) }}</td>
    <td> Not Applicable </td>
  </tr>
  <tr>
    <td>{{ $upahlama['bil'] }}</td>
    <td>Bayaran Upah</td>
    <td> Not Applicable </td>
    <td>{{ number_format($upahlama['total'],2) }}</td>
    <td> Not Applicable </td>
  </tr>
</table>






