<?php if(Auth::user()->hasAnyPermission(['All','View Plan'])): ?>
 <div class = "col-md-12 col-sm-12">
            <div class= "card card-collapsed">
                        <div class="card-status bg-teal">
                      </div>
                               <div class="card-header"> 

              <?php if($lagging_amount <= 0): ?>
               <h3 class="card-title">Manage Installment </h3>

               <?php else: ?>
  <?php if(Auth::user()->hasAnyPermission(['All','Add Plan'])): ?>
  
               <button  class="float-right btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_make_installment"><i class="fa fa-plus"></i></button> &nbsp;&nbsp;
               <?php endif; ?>


               <h3 class="card-title">Manage Installment </h3>
               <?php endif; ?>

               <div class="card-options">
               <!--  <?php ($count = count($installment_list)); ?>
                <?php if($count > 0): ?>
        <button  class=" btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_interval_installment">Quarter/Bi Annual Plan</button>&nbsp;&nbsp;
        <?php endif; ?> -->
<?php if(Auth::user()->hasAnyPermission(['All','View Plan'])): ?>
              <?php if(sizeof($installment_list) > 0): ?>
                <?php if($booking->installment_mode != 'One Time'): ?>
                   <a data-toggle="modal" data-target="#md_update_installment_mode" href="#" class=" btn btn-sm btn-outline-primary mr-2" >Change Installment Mode</a>
                <?php endif; ?>
              <?php endif; ?>

               <a onclick="cardCollapseOnce(event,this);" href="#" class="card-options-collapse btn btn-sm btn-outline-primary" >View Plan <i class="fe fe-chevron-up"></i></a>
               <?php endif; ?>
                   
             </div>

               </div>

               <div class="alert alert-primary card-alert mb-0">
               <?php if($lagging_amount == 0): ?>
               Installments
               <?php elseif($lagging_amount < 0): ?> 
           <i style = "color: red;">Amount Exceeding: <?php echo e(EF::numberFormat($lagging_amount)); ?> </i>    <?php else: ?>     
           <i style = "color: red;">Amount Lagging: <?php echo e(EF::numberFormat($lagging_amount)); ?> </i> 
           <?php endif; ?>
                          <?php if(Auth::user()->hasAnyPermission(['All','Remove Installment'])): ?>
                 <i style = "color: red; float:right; display:none;" class="fa fa-trash btn-sm clearremove_installment_button "  onclick="bulkInstallmentRemove(event,'<?php echo e(Crypt::encrypt($booking->id)); ?>')"> Remove</i>  
                 <?php endif; ?>  
               </div>
               <div class="table-responsive ">
                 <table class="table  table-hover table-fixed  table-outline table-vcenter text-nowrap card-table table-sm">
                <thead>
                        <tr>
                           <th><input type="checkbox" onchange="selectAllInstallment(event,this)"></th>
                          <th>Sr # </th>
                          <th>Description</th> 
                          <th>Plan Amount</th>
                          <th>Updated</th>  
                          <th>Received</th>
                           <th>Balance</th>
                            <th>Due Date</th>
                          <th>Status</th>
                          <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>                          
                        </tr>
                      </thead>
                    </table>
               </div>

                      <div class="table-responsive  booking-table-height">
                    <table class="table table-hover table-fixed  table-outline table-vcenter text-nowrap card-table ">
                      
                      <tbody>
                         <?php if(isset($installment_list)): ?>
                         <?php ($plan_total = 0); ?>
                         <?php ($plan_received = 0); ?>
                         <?php ($plan_actual_total = 0); ?>


                      <?php $__currentLoopData = $installment_list; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php ($pass_data = []); ?>
                            
                        

              <?php (
                $pass_data = array(
                    'id'                  => Crypt::encrypt($rows->id),
                    'amount'              => $rows->amount,
                    'amount_in_words'     => EF::numberToWords($rows->amount),
                    'due_date'            => trim(date('Y-m-d',strtotime($rows->due_date))),
                    'description'         => $rows->description,

                  )); ?>

    <tr>
       <td> <?php if($rows->received_amount == 0): ?><input type="checkbox" class="checked_installment" value="<?php echo e(Crypt::encrypt($rows->id)); ?>"><?php endif; ?></td>
      


      <td><?php echo e($loop->iteration); ?></td>
        <td><?php echo e($rows->description); ?></td>
            <td><?php echo e(EF::numberFormat($rows->actual_amount)); ?></td>
              <td><?php echo e(EF::numberFormat($rows->amount)); ?></td>
                <td><?php echo e(EF::numberFormat($rows->received_amount)); ?></td>
                  <td>
                    <?php echo e(EF::numberFormat(($rows->amount)-($rows->received_amount))); ?>

                  </td>
                    <td><?php echo e(EF::dateFormat($rows->due_date)); ?></td>
                    <td style = "<?php if($rows->status == 'Paid'): ?> color:green; font-weight:bolder; <?php else: ?> color:red; font-weight: bolder; <?php endif; ?>"><?php echo e($rows->status); ?></td>
                   <td class="text-center"> 
        
                         <?php if($rows->status == "Unpaid"): ?>

                         

                         <?php ($payment = array(

                            'installment'      => Crypt::encrypt($rows->id),
                            'commission'       => Crypt::encrypt('0'),
                            'amount'           => ($rows->amount - $rows->received_amount),
                            'amount_in_words'  => EF::numberToWords($rows->amount - $rows->received_amount),
                            'description'      => $rows->description,
                            'user'             => Crypt::encrypt($user->id),
                            'booking'          => Crypt::encrypt($booking->id),
                            'user_type'        => $user->type,
                            'user_name'        => $user->name,
                            EF::branchWhiteLabel()['module'] => $booking->branch->name,


                            'booking_detail'   => $booking->ms.' ('.$plot->plot_id.' '.$plot->category.')',

                            'payment_type'     => 'Installment',

                         )); ?>
                                <div class="item-action dropdown">
                          <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fa fa-list-ul"></i></a>
                  <div class="dropdown-menu dropdown-menu-right">
                 
                     <?php if(Auth::user()->hasAnyPermission(['All','Update Installment'])): ?>
                    <a href="#" onclick="update(event,'<?php echo e(json_encode($pass_data)); ?>','form_update_installment','md_update_installment')" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Update</a>
                    <?php endif; ?>
                     <?php if(Auth::user()->hasAnyPermission(['All','Add Payment'])): ?>
                     <?php if($booking->is_block == 0): ?>
                      <a href="#" id="pay" class="dropdown-item" onclick="showPayPaymentModel(event,'<?php echo e(Crypt::encrypt(EF::getGenericTableIndex()['Installment'])); ?>','<?php echo e(Crypt::encrypt($rows->id)); ?>')"><i class="dropdown-icon fa fa-money"   ></i> Pay </a>
                      <?php endif; ?>
                      <?php endif; ?>
                                 <?php if(Auth::user()->hasAnyPermission(['All','Remove Installment'])): ?>
                      <?php if($rows->received_amount == 0): ?>

                      <a href="<?php echo e(route('installment.trash',['id' => Crypt::encrypt($rows->id)])); ?>" class="dropdown-item cls_delete" content="Remove Installment"><i class="dropdown-icon fa fa-trash"></i> Remove </a>
                      <?php endif; ?>
                      <?php endif; ?>
                          </div>
                          </div>
                      <?php endif; ?>    
               
                  </td>
    </tr>
    
                          <?php ($plan_actual_total += $rows->actual_amount); ?>

                          <?php ($plan_total += $rows->amount); ?>
                         <?php ($plan_received += $rows->received_amount); ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
     <?php endif; ?>
      </tbody>
      <tfoot >
        <tr style="border-top-color:  1px solid #000000 !important;">
          <td colspan="4">Total</td>
       
          <td><span class="badge badge-primary"><?php echo e(EF::numberFormat($plan_total)); ?></span></td>
          <td><span class="badge badge-success"><?php echo e(EF::numberFormat($plan_received)); ?></span></td>
          <td><span class="badge badge-danger"><?php echo e(EF::numberFormat($plan_total - $plan_received)); ?></span></td>
          <td colspan="3"></td>

          
        </tr>
      </tfoot>
  </table>
</div>    
                               
  </div>
</div>
<?php endif; ?><?php /**PATH /var/www/skylite/resources/views/installment/manage_installment.blade.php ENDPATH**/ ?>