<?php
require_once('/home/leadltht/fastlinkinternet.com/administrator/data-provider/config.php'); // Ensure the correct path to config.php
if(isset($_GET['id']) && $_GET['id'] > 0){
$qry = $conn->query("SELECT c.*,CONCAT(m.lastname,', ', m.firstname,' ',COALESCE(m.middlename,'')) as fullname from `collection_list` c inner join member_list m on c.member_id = m.id where c.id = '{$_GET['id']}' ");
if($qry->num_rows > 0){
foreach($qry->fetch_assoc() as $k => $v){
$$k=$v;
}
}else{
?>
<center>Unknown collection</center>
<style>
#uni_modal .modal-footer{
display:none
}
</style>
<div class="text-right">
<button class="btn btndefault bg-gradient-dark btn-flat" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
<?php
exit;
}
}
?>
<style>
#uni_modal .modal-footer{
display:none
}
</style>
<div class="container-fluid">
<div id="outprint">
<div class="row">
<div class="col-md-6">
<dl>
<dt class="text-muted">Ref. Code:</dt>
<dd class="pl-3"><?= isset($code) ? $code : "" ?></dd>
<dt class="text-muted">Receipt Number:</dt>
<dd class="pl-3"><?= isset($receipt) ? ($receipt) : "" ?></dd>
<dt class="text-muted">Date Collected:</dt>
<dd class="pl-3"><?= isset($date_collected) ? date("D F d, Y", strtotime($date_collected)) : "" ?></dd>
<dt class="text-muted">Collected By:</dt>
<dd class="pl-3"><?= isset($collected_by) ? ($collected_by) : "" ?></dd>
<dt class="text-muted">Subscriber Name:</dt>
<dd class="pl-3"><?= isset($fullname) ? ($fullname) : "" ?></dd>
</dl>
</div>
<div class="col-md-6">
<table class="table table-stripped table-bordered">
<thead>
<tr>
<th class="text-center">Category</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<?php
$collection = $conn->query("SELECT i.*,c.name as `category` FROM `collection_items` i inner join category_list c on i.category_id = c.id where i.collection_id = '{$id}' ");
while($row = $collection->fetch_assoc()):
?>
<tr>
<td class="px-2 py-1 align-middle"><?= $row['category'] ?></td>
<td class="px-2 py-1 align-middle text-right"><?= format_num($row['fee']) ?></td>
</tr>
<?php endwhile; ?>
</tbody>
<tfoot>
<tr>
<th class="px-1 py-1 text-center">Total</th>
<th class="px-1 py-1 text-right"><?= format_num($total_amount) ?></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<div class="clear-fix mb-3"></div>
<div class="text-right">
<button class="btn btn-light border btn-flat btn-sm" type="button" id="print"><i class="fa fa-print"></i> Print</button>
<button class="btn btn-light border btn-flat btn-sm" type="button" id="print-portable"><i class="fa fa-print"></i> Print Portable Receipt</button>
<button class="btn btn-default bg-gradient-dark btn-sm btn-flat" type="button" data-dismiss="modal"><i class="fa f-times"></i> Close</button>
</div>
</div>
<noscript id="print-header">
<style>
#sys_logo{
width:5em !important;
height:5em !important;
object-fit:scale-down !important;
object-position:center center !important;
}
</style>
<div class="d-flex align-items-center">
<div class="col-auto text-center pl-4">
<img src="<?= validate_image($_settings->info('logo')) ?>" alt=" System Logo" id="sys_logo" class="img-circle border border-dark">
</div>
<div class="col-auto flex-shrink-1 flex-grow-1 px-4">
<h4 class="text-center m-0"><?= $_settings->info('name') ?></h4>
<h3 class="text-center m-0"><b>Collection Report</b></h3>
<h5 class="text-center m-0">For <?= isset($fullname) ? ucwords($fullname) : 'N/A' ?></h5>
<h5 class="text-center m-0"></h5>
</div>
</div>
<hr>
</noscript>
<script>
$('#print').click(function(){
start_loader();
var head = $('head').clone()
var p = $('#outprint').clone()
var el = $('<div>')
var header = $($('noscript#print-header').html()).clone()
head.find('title').text("Collection Montly Report - Print View")
el.append(head)
el.append(header)
el.append(p)
var nw = window.open("","_blank","width=1000,height=900,top=50,left=75")
nw.document.write(el.html())
nw.document.close()
setTimeout(() => {
nw.print()
setTimeout(() => {
nw.close()
end_loader()
}, 200);
}, 500);
})
// Print for Portable Printer Receipt
$(document).on('click', '#print-portable', function() {
// Extract values from the modal for plain text printing
var refCode = $('.modal-body').find('dd:eq(0)').text() || ''; // Ref. Code
var receiptNumber = $('.modal-body').find('dd:eq(1)').text() || 'N/A'; // Receipt Number
var dateCollected = $('.modal-body').find('dd:eq(2)').text() || 'N/A'; // Date Collected
var collectedBy = $('.modal-body').find('dd:eq(3)').text() || 'N/A'; // Collected By
var subscriberName = $('.modal-body').find('dd:eq(4)').text() || 'N/A'; // Subscriber Name
// Extract table content (Categories and Amounts)
var tableRows = '';
$('.modal-body table tbody tr').each(function() {
var category = $(this).find('td:eq(0)').text();
var amount = $(this).find('td:eq(1)').text();
tableRows += `<p>${category}: ${amount}</p>`;
});
// Create a simplified layout for portable printers
var portableReceipt = `
<div style="font-size: 12px;">
<div style="text-align: center;">
<img src="https://fastlinkinternet.com/administrator/data-provider/uploads/fastlink.png" alt="Logo" style="max-width: 150px;">
</div>
<h3>ACKNOWLEDGEMENT RECEIPT</h3>
<p>FASTLINK INTERNET</p>
<p>CP No: 09453306374 </p>
<hr>
<p><strong>Ref. Code:</strong> ${refCode}</p>
<p><strong>Receipt Number:</strong> ${receiptNumber}</p>
<p><strong>Date Collected:</strong> ${dateCollected}</p>
<p><strong>Collected By:</strong> ${collectedBy}</p>
<p><strong>Subscriber Name:</strong> ${subscriberName}</p>
<hr>
<h4>Category and Amount</h4>
${tableRows}
<hr>
<p><strong>Total:</strong> ${$('.modal-body').find('tfoot th:eq(1)').text()}</p>
<h3>THANK YOU FOR YOUR PAYMENT</h3>
</div>
`;
// Store receipt data in sessionStorage to make it available in the new page
sessionStorage.setItem('portableReceipt', portableReceipt);
// Redirect to the receipt preview page
window.location.href = 'receipt_preview.html';
});
</script>