
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.js"></script>
<style type="">
  .pd-left{
    padding: 30px;
  }
  .btn-default {
    color: #fff;
    background-color: #089bab;
    border-color: #089bab;
    font-weight: 500;
}
.btn-default:hover{
  color: #fff;

}
.martop30{
  margin-top: 40px;
}
.clbl{
    color: #089bab;
}
</style>
            <!-- TOP Nav Bar END -->
  <div class="container-fluid">
     <div class="row">
        <div class="col-sm-12">
           <div class="iq-card">
              <div class="iq-card-header d-flex justify-content-between">
                 <div class="iq-header-title">
                    <h4 class="card-title">Daily Collection Report - <?= $date ?></h4>
                 </div>
                 <div class="iq-dateform">
                  <form method="post" onsubmit="return updateActionUrl();" id="filterForm">
                    <div class="input-group mt-2 mb-3">
                        <input type="date" id="filter_date" name="filter_date" class="form-control" placeholder="Choose date" value="<?= isset($date) ? date('Y-m-d', strtotime($date)) : date('Y-m-d') ?>" required>
                          <div class="input-group-append">
                              <button class="btn btn-primary" type="submit">Submit</button>
                          </div>
                      </div>
                  </form>

                 </div>
                    <span class="table-add float-right mb-3 mr-2 mt-2">
                    <!-- <a href="<?php echo base_url(); ?>customer/export/" class="btn btn-default"><i class="fa fa-file-excel-o" aria-hidden="true"></i> Export</a><a href="javascript:void(0)" class="btn btn-default" data-toggle="modal" data-target="#import_popup"><i class="fa fa-file-excel-o" aria-hidden="true"></i> Import</a> -->
                    <!-- <a href="<?php echo base_url(); ?>Reservation/add" class="btn btn-sm iq-bg-success"><i
                       class="ri-add-fill"><span class="pl-1">Book Now</span></i>
                    </a> -->
                    <button onclick="printDiv('#printArea');" class="btn btn-default"><i class="fa fa-file-excel-o" aria-hidden="true"></i>Print</button>
                    </span>
              </div>
        
       
              
                  
          <div class="iq-card-body" id="printArea">
             <div id="table" class="table-editable">
                              
            <!-- <h2>Daily Collection Report - <?= $date ?></h2> -->

    <h5 class="clbl"><strong>Total Collection:</strong>&#8377; <?= number_format($total_collection, 2) ?></h5>
    <h5 class="clbl"><strong>Total Transactions:</strong> <?= $total_transactions ?></h5>
    <hr>

    <h5>Collection by Payment Mode</h5><br>
    <table border="1" class="table">
        <tr>
            <th>Payment Mode</th>
            <th>Amount</th>
        </tr>
        <?php foreach ($collection_by_mode as $row): ?>
            <tr>
                <td><?= $row['payment_mode'] ?></td>
                <td>&#8377; <?= number_format($row['total_amount'], 2) ?></td>
            </tr>
        <?php endforeach; ?>
    </table>

    <h5>All Transactions</h5><br>
    <table border="1" class="table">
        <tr>
            <th>SL.No.</th>
            <th>Payment Purpose</th>
            <th>Payment Mode</th>
            <th>Amount</th>
            <th>Date</th>
        </tr>
        <?php 
        $sl=0;
        foreach ($payments as $payment): 
          $sl++;
        ?>
            <tr>
                <td><?= $sl; ?></td>
                <td><?= $payment['payment_purpose'] ?></td>
                <td><?= $payment['payment_mode'] ?></td>
                <td>&#8377; <?= number_format($payment['p_amount'], 2) ?></td>
                <td><?= $payment['p_date'] ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
             
                           </div>
                        </div>
       
                     </div>
                  </div>
               </div>
            </div>
            <!-- Footer -->
<script>
function updateActionUrl() {
    var date = document.getElementById('filter_date').value;
    if (date) {
        document.getElementById('filterForm').action = "<?= base_url(); ?>Report/daily_report/" + date;
    }

    return true; // Allow form submission
}
</script>
      <script type="text/javascript">
function printDiv() {
var divToPrint = document.getElementById('printArea').innerHTML;
//alert(divToPrint);
//console.log(divToPrint);
var newWin = window.open();
newWin.document.write('<html><head><title>Daily Collection Report</title>');
newWin.document.write('</head><body >');
newWin.document.write(divToPrint);
newWin.document.write('</body></html>');
console.log(divToPrint);
newWin.document.close();
newWin.print();
//newWin.close();
//window.print();
}
</script>