@include('dashboard.include.header')
@if(Auth::user()->type == "User")
<script>
    document.location.href = '/resellerdash'
</script>
@endif
  
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Reseller Received Orders</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/home">Home</a></li>
              <li class="breadcrumb-item active">Reseller Received COD</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">
        <div class="row">
          <div class="col-md-12">
          @foreach($paymere as $data)  
            <table class="table borderless"  border="0">
                <tbody>
                    <tr>
                    <td class="text-left"><b>Resller Name - </b>  {{ $data->id}}</td>
                    <td class="text-center"><b>Genrate By - </b>  {{ $data->genratedby}}</td>
                    <td class="text-right"><b>Status - </b> @if($data->status == 0) Not Paid @else Paid @endif </td>
                    <td class="text-right"><b>Paid Date - </b> {{$data->paiddate}}</td>
                    </tr>
                </tbody>
            </table>  
            <table class="table borderless"  border="0">
                <tbody>
                    <tr>
                    <td class="text-left"><b>Collected COD - </b>  {{ $data->collectedcod}}</td>
                    <td class="text-right"><b>Delivery Charge - </b> {{ $data->deliverycharge}} </td>
                    <td class="text-right"><b>Service Charge - </b> {{$data->servicecharge}}</td>
                    <td class="text-right"><b>Products Charge - </b> {{$data->productscharge}}</td>
                    <td class="text-right"><b>Commision - </b> {{$data->commision}}</td>
                    <td class="text-right"><b>Advance - </b> {{$data->advance}}</td>
                    <td class="text-right"><b>Payable COD - </b> {{ $data->paidamount}} </td>
                    </tr>
                </tbody>
            </table> 
            @endforeach
                </div>
          </div>

        </div>
      </div>
        <div class="card">
        <div class="card-body">
            <div class="col-md-12">
            <table id="example12" class="table table-bordered" style="width:100%;">
                    <thead>
                        <tr>
                            <th>Invoice ID</th>
                            <th>Status</th>
                            <th>Weight (KG)</th>
                            <th>COD</th>
                            <th>Delivery Charge</th>
                            <th>Service Charge</th>
                            <th>Product Charge</th>
                            <th>Net Payable</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($item as $data)
                        @php $deli=0; $tot=0; $unit=0; @endphp
                        @foreach($data->cus_or as $cudata) 
                            @php
                            $unit = ($cudata->reseller_cost)*($cudata->qty);
                            $tot += $unit;
                            @endphp
                        @endforeach
                        <tr>
                            <td><a target="_blank"  href="/viewallorders/{{$data->id}}">{{$data->id}}</a></td>
                            <td>
                            @if($data->status == 33)
                            <span class="badge badge-success">Received to Seller</span>
                            @elseif($data->status == 34)
                            <span class="badge badge-danger">Return to Seller</span>
                            @elseif($data->status == 36)
                            <span class="badge badge-dark">Refund to Seller</span>
                            @endif
                            </td>
                            <td>{{$data->weight}}</td>
                            <td>
                            @if($data->status == 33)
                            {{$data->cod}}
                            @elseif($data->status == 34)
                            0
                            @elseif($data->status == 36)
                            -{{$data->cod}}
                            @endif
                            </td>
                            <td>
                            @if($data->status == 33 OR $data->status == 36)
                            @if($data->ordertype == 2)
                            0
                            @else
                            {{$data->orderdelivery}}
                            @endif
                            @elseif($data->status == 34)
                            0
                            @endif
                            </td>
                            <td>{{$data->servicecharge}}</td>
                            <td>{{$tot}}</td>
                            <td>
                            @if($data->status == 33)
                            @if($data->ordertype == 2)
                            0
                            @else
                            {{$data->cod - ($data->orderdelivery+$data->servicecharge+$tot) }}
                            @endif
                            @elseif($data->status == 34)
                            {{0 - $data->servicecharge }}
                            @elseif($data->status == 36)
                            0
                            @endif
                            </td>
                        </tr>
                        @endforeach

                    </tbody>
                </table>
            </div>
            <br><br><hr><br><br>
            <div class="col-md-12">
            <h4>Advance</h4>
                <table id="example12" class="table table-bordered" style="width:100%; font-size:13px;">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Advance</th>
                            <th>Paid ID</th>
                            <th>Date of Paid to the Reseller</th>
                            <th>Paid Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($advance as $addata)
                          <tr>
                            <td>{{ $addata->id }}</td>
                            <td>{{ $addata->advance }}</td>
                            <td>{{ $addata->paidid }}</td>
                            <td>{{ $addata->created_at }}</td>
                            <td>{{ $addata->paiddate }}</td>
                          </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

                        <br><br><hr><br><br>
            <div class="col-md-12">
            <h4>Commision</h4>
                <table id="example12" class="table table-bordered" style="width:100%; font-size:13px;">
                    <thead>
                        <tr>
                            <th>Company Name</th>
                            <th>Commision Charge</th>
                            <th>Orders Count</th>
                            <th>Total Commision</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($comdetails as $data2)
                          <tr>
                            <td>{{ $data2['resname'] }}</td>
                            <td>{{ $data2['charge'] }}</td>
                            <td>{{ $data2['count'] }}</td>
                            <td>{{ $data2['total'] }}</td>
                          </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>



        </div>
        </div>
      

     

      </div>
    </section>
  </div>



  @include('dashboard.include.footer');

<script>
$('#reservationdate').datetimepicker({
    format: 'YYYY/MM/DD'
    });


$(document).ready(function() {
    $('#example12').DataTable({
        "responsive": true, "lengthChange": true, "autoWidth": false,"order": [[ 0, "asc" ]],
      // "buttons": ["copy", "csv", "excel", "pdf", "print"]
      "buttons": [ {extend: 'copy',footer: true,exportOptions: {columns: [0,1,2,3,4,5,6,7]}},   
      {extend: 'csv',footer: true,exportOptions: {columns: [0,1,2,3,4,5,6,7]}},
      {extend: 'excel',footer: true,exportOptions: {columns: [0,1,2,3,4,5,6,7]}},
      {extend: 'pdf',footer: true,exportOptions: {columns: [0,1,2,3,4,5,6,7]}},
      {extend: 'print',footer: true,exportOptions: {columns: [0,1,2,3,4,5,6,7]}},      
    ],


    }).buttons().container().appendTo('#example12_wrapper .col-md-6:eq(0)');
} );

</script>