billing2/customers/.hta_slug/print-invoice.php

166 lines
6.5 KiB
PHP

<?php
require('../.hta_config/conf.php');
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT * FROM invoice WHERE customerId = :customerId AND invoiceId = :invoiceId");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
$stmt->execute();
$invoiceInfo = $stmt->fetch(PDO::FETCH_ASSOC);
$emiPlans = [];
if ($invoiceInfo['tenure'] > 1) {
$stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiDate ASC");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
$stmt->execute();
$emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
<div class="container my-5">
<div class="invoice-box">
<h2 class="text-center fw-bold" style="color: #374151;">Invoice</h2><hr>
<div class="d-flex justify-content-between">
<div class="w-100">
<h6>Invoice ID: <?= $invoiceInfo['invoiceId'] ?></h6>
<h6>Customer: <?= $invoiceInfo['customerName'] ?></h6>
<p style="width: 70%;"><strong>Address:</strong> <?= $invoiceInfo['address'] ?></p>
</div>
<div class="w-100 d-flex flex-column align-items-end">
<h6>Invoice Date: <?= $invoiceInfo['invoiceDate'] ?></h6>
<h6>Payment Mode: <?= $invoiceInfo['paymentMode'] ?></h6>
<p><strong>Agent:</strong> <?= $invoiceInfo['salesAgent'] ?></p>
</div>
</div>
<table class="table table-bordered mt-3">
<thead class="text-white" style="background-color: #374151;">
<tr>
<th>Item</th>
<th>Description</th>
<th>Qty</th>
<th>Rate</th>
<th>Discount(%)</th>
<th>Discount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><?= $invoiceInfo['item'] ?></td>
<td><?= $invoiceInfo['description'] ?></td>
<td><?= $invoiceInfo['qty'] ?></td>
<td><?= $invoiceInfo['rate'] ?></td>
<td><?= $invoiceInfo['discount'] ?>%</td>
<td>$<?= $invoiceInfo['discountAmount'] ?></td>
<td>$<?= number_format($invoiceInfo['totalAmount'], 2) ?></td>
</tr>
</tbody>
</table>
<!-- EMI Table (if tenure > 1) -->
<?php if ($invoiceInfo['tenure'] > 1): ?>
<h5 class="mt-4" style="color: #374151;">EMI Payment Plan</h5>
<table class="table table-striped">
<thead>
<tr>
<th>EMI No.</th>
<th>EMI Date</th>
<th>Payment Date</th>
<th>EMI Amount</th>
<th>Outstanding</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($emiPlans as $emi): if($emi['emiAmount'] !== null) {?>
<tr>
<td><?= $emi['emiNumber'] ?></td>
<td><?= $emi['emiDate'] ?></td>
<td><?= $emi['payStatus'] == 1 ? $emi['paymentDate'] : 'Unpaid' ?></td>
<td>$<?= number_format($emi['emiAmount'], 2) ?></td>
<td>$<?= number_format($emi['outstanding'], 2) ?></td>
<td>
<?= ($emi['payStatus'] == 1) ? '<span class="badge bg-success">Paid</span>' : '<span class="badge bg-danger">Pending</span>' ?>
</td>
</tr>
<?php } endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<h5 class="mt-4" style="color: #374151;">Additional Payment Details:</h5>
<table class="table table-striped " style="font-size: 12px;">
<thead class="">
<tr>
<th>Payment Amount</th>
<th>Payment Date</th>
<th>Payment Source</th>
<th>Transaction ID</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($emiPlans as $emiAdditional) {
if (!is_null($emiAdditional['adPaymentAmount']) && $emiAdditional['adPaymentAmount'] > 0) {
?>
<tr>
<td><?= number_format($emiAdditional['adPaymentAmount'], 2) ?></td>
<td><?= !empty($emiAdditional['adPaymentDate']) ? $emiAdditional['adPaymentDate'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentSource']) ? $emiAdditional['adPaymentSource'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentTran']) ? $emiAdditional['adPaymentTran'] : '-' ?></td>
<td><?= !empty($emiAdditional['adPaymentRemarks']) ? $emiAdditional['adPaymentRemarks'] : '-' ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<p class="text-muted mt-3"><strong>Admin Note:</strong> <?= $invoiceInfo['adminNote'] ?></p>
<p style="font-size: 12px;"><strong>Invoice Generate Date: </strong><span id="invoiceGenDate"></span></p>
<button onclick="window.print()" class="btn text-white btn-print w-100" style="background-color: #374151;">Print Invoice</button>
</div>
</div>
<script>
document.getElementById('invoiceGenDate').textContent = new Date().toLocaleDateString('en-GB');
</script>
<style>
body {
background-color: #f8f9fa;
}
.invoice-box {
max-width: 800px;
margin: auto;
padding: 30px;
border: 1px solid #ddd;
background: #fff;
border-radius: 10px;
}
.text-blue { color: #007bff; }
.btn-print { margin-top: 20px; }
@media print {
body * {
visibility: hidden;
}
.invoice-box, .invoice-box * {
visibility: visible;
}
.invoice-box {
position: absolute;
left: 0;
top: 0;
width: 100%;
}
.btn-print {
display: none; /* Hide print button */
}
}
</style>