 <!--.row-->
 @php
 $remain_td = 0;
@endphp
<div class="row no-print" style="margin-bottom: 1rem;  margin-top: 53px;">
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">Report</div>
            <div class="panel-wrapper collapse in" aria-expanded="true">
                <div class="panel-body">


                    <div class="col-sm-12 text-center">

                        <div>
                            <h2><strong>
                                @foreach($project_names as $key => $project_name)
                                {{ $project_name }}
                                @if($key < count($project_names) - 1)
                                    , 
                                @endif
                            @endforeach    
                            </strong></h2>

                            <h4><strong> Recovery Dues Till {{ date('d/m/Y') }}</strong></h4>
                        </div>
                    </div>


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

<!--./row-->



@permission('due-payments')
    <div class="row">

        <div class="col-sm-12">
            <div class="white-box">

                <h3 class="box-title"> Due Amounts <a href="{{ route('properties.due') }}"
                        style="float: right;font-size: 12px"><u>View All</u></a></h3>


                <div class="table-responsive">
                    <table id="myTable1" class="table table-bordered">
                        <thead>
                            <tr>
                                <th>Sr No.</th>
                                <th>Unit No.</th>
                                <th>Member Name</th>
                                <th>Dealer</th>
                                <th>Net Amount</th>
                                <th class="text-center">Received Amount</th>
                                <th class="text-center">Due Amount</th>
                                <th>Due Date</th>
                                <th>Action</th>

                                <th style="border-right: none;">Installments</th>


                                <?php
                                
                                for ($i = 1; $i < $max_due; $i++) {
                                    echo '<th class=" text-center" style="border-right: none; border-left: none;"></th>';
                                }
                                ?>

                            </tr>
                        </thead>
                        <tbody>
                            <?php $count = 1;
                            $net_amount = 0;
                            $receive_amount = 0;
                            $due_amount = 0; ?>
                            @permission('view-membership')
                                <?php $view_membership = true; ?>
                            @else
                                <?php $view_membership = false; ?>
                            @endpermission

                             
                            @if (isset($properties))
                                @foreach ($properties as $statement)
                                
                                    @if ($dueAmt[$statement->id] > 0)
                                        @if ($color[$statement->id] == 'red')
                                            <tr style="color:red;">
                                            @elseif($color[$statement->id] == 'orange')
                                            <tr style="color:orange;">
                                            @else
                                            <tr style="color:black;">
                                        @endif
                                        <td style="min-width: 10rem;">{{ $count++ }}</td>

                                        <td style="min-width: 13rem;">
                                            {{ $statement->inventory ? $statement->inventory->unit_number : '' }}
                                        </td>
                                        <td style="min-width: 13rem;">
                                            {{ $statement->customer ? $statement->customer->name : '' }}</td>
                                        <td style="min-width: 13rem;">
                                            @if ($statement->dealer)
                                                {{ $statement->dealer->name }}
                                            @endif
                                        </td>
                                        <td class="text-right" style="min-width: 13rem;">
                                            {{ number_format($statement->net_pay) }} PKR
                                            <?php $net_amount += $statement->net_pay; ?>
                                        </td>
                                        <td class="text-right" style="min-width: 13rem;">
                                            {{ number_format($receivedAmt[$statement->id]) }} PKR
                                            <?php $receive_amount += $receivedAmt[$statement->id]; ?>
                                        </td>
                                        <td class="text-right" style="min-width: 13rem;">
                                            {{ number_format($dueAmt[$statement->id]) }} PKR
                                            <?php $due_amount += $dueAmt[$statement->id]; ?>
                                        </td>
                                        <td style="min-width: 13rem;">
                                            {{ $dueDate[$statement->id] ? date('d/m/Y', strtotime($dueDate[$statement->id]->due_date)) : '' }}
                                            <br>
                                            @foreach ($dueMonth[$statement->id] as $s)
                                                @if ($loop->last)
                                                    {{ date('M', strtotime($s->due_date)) }}
                                                @else
                                                    {{ date('M', strtotime($s->due_date)) }} -
                                                @endif
                                            @endforeach

                                        </td>

                                        <td>
                                            @if ($view_membership)
                                                <center> <a
                                                        href="{{ route('statement.detail', ['id' => $statement->id]) }}"
                                                        data-toggle="tooltip" data-original-title="View"> <i
                                                            class="fa fa-eye text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                </center>
                                            @endif
                                        </td>
                                        <?php 
                                              $remain_td =  0;

                                              $payment_head = [1,3,2,7];

                                               $counter = 0;

                                                $tax_total = 0; 

                                                for ($j=0; $j < count($payment_head); $j++) 
                                                     { 
                               
                                         ?>

                                        @foreach ($dueMonth[$statement->id] as $key => $s)
                                            <?php
                                            $remain_td = $max_due - count($dueMonth[$statement->id]);
                                            ?>

                                            @if ($s->payment_head == $payment_head[$j])
                                                @if ($statement->customer->is_filer == 1)
                                                    <?php $tax_total = $s->due * 0.01; ?>
                                                @else
                                                    <?php $tax_total = $s->due * 0.02; ?>
                                                @endif

                                                <td class="printFV text-center id_{{ $counter++ }}"
                                                    data-amount="{{ round($s->due + $tax_total) }}"
                                                    style="min-width: 13rem; ">

                                                    @if ($payment_head[$j] == \App\CustomerStatement::down_payment)
                                                        Down Payment
                                                    @elseif($payment_head[$j] == \App\CustomerStatement::possession)
                                                        Possession Fee
                                                    @elseif($payment_head[$j] == \App\CustomerStatement::installment)
                                                        Installment - {{ $s->inst_no }}
                                                    @elseif($payment_head[$j] == \App\CustomerStatement::other)
                                                        Other
                                                    @endif

                                                    <br> {{ number_format($s->due) }}
                                                    <hr>
                                                    Tax
                                                    <br>

                                                    {{ number_format($tax_total) }}
                                                </td>
                                            @endif
                                        @endforeach

                                        <?php

                                               }
                                
                                            for ($i=0; $i < $remain_td; $i++) 
                                                      { 
                                                               echo '<td class="printFV text-center">-</td>';
                                                       }
                                         ?>


                                        </tr>
                                    @endif
                                @endforeach
                            @else
                                <td>Null</td>
                            @endif

                            <tr>
                                <td><strong>Total:</strong></td>
                                <td></td>
                                <td></td>
                                <td></td>

                                <td class="text-right">{{ number_format($net_amount) }} PKR</td>
                                <td class="text-right">{{ number_format($receive_amount) }} PKR</td>
                                <td class="text-right">{{ number_format($due_amount) }} PKR</td>

                                <td></td>
                                <td></td>


                                <?php
                                
                                for ($i = 0; $i <= $remain_td; $i++) {
                                    echo '<td class="printFV text-center" id="grand_total_' . $i . '"></td>';
                                }
                                ?>


                            </tr>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endpermission



<!-- /row -->