0,
'Cheque' => 0,
'Metal' => 0,
'Cash' => 0,
'Card' => 0
];
$payments_q = mysqli_query($con,
"SELECT payment_type, SUM(amount) total_amount
FROM invoice_payments
WHERE invoice_id='$id'
GROUP BY payment_type"
);
while ($payment = mysqli_fetch_assoc($payments_q)) {
$ptype = trim($payment['payment_type']); // no strtolower/ucfirst
if (array_key_exists($ptype, $payments)) {
$payments[$ptype] = (float)$payment['total_amount'];
}
}
/* ================= METAL & DUES ================= */
$metal = 106365.00;
$dues = 0.00;
/* ================= FINAL AMOUNT ================= */
$final_amount = round((float)$invoice['final_amount'], 2);
$round_final_amount = round($final_amount);
$round_off = $round_final_amount - $final_amount;
/* ================= DISCOUNT ================= */
$discount_type = $invoice['discount_type'] ?? 'value';
$discount_value = (float)($invoice['discount_value'] ?? 0);
$discount_amount = 0;
if ($discount_value > 0) {
if ($discount_type == 'percent') {
$discount_amount = ($items_subtotal + $other_charges) * $discount_value / 100;
} else {
$discount_amount = $discount_value;
}
}
/* ===================================================
SINGLE DOWNLOAD BLOCK (FINAL)
=================================================== */
if (isset($_GET['download'])) {
ob_end_clean();
$options = new Options();
$options->set('defaultFont', 'DejaVu Sans');
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
ob_start();
if ($_GET['download'] == '1') {
include 'invoice_view_print.php';
$filename = "invoice_main_{$invoice['invoice_no']}.pdf";
}
elseif ($_GET['download'] == '2') {
include 'invoice_view_print1.php';
$filename = "invoice_copy_{$invoice['invoice_no']}.pdf";
}
else {
exit;
}
$html = ob_get_clean();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Cache-Control: private, max-age=0, must-revalidate");
header("Pragma: public");
echo $dompdf->output();
exit;
}
/* ================= NUMBER TO WORDS ================= */
if (!function_exists('numberToWords')) {
function numberToWords($num) {
$num = round($num);
$ones = [
0 => '', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four',
5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight',
9 => 'Nine', 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve',
13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen',
16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen',
19 => 'Nineteen'
];
$tens = [
2 => 'Twenty', 3 => 'Thirty', 4 => 'Forty',
5 => 'Fifty', 6 => 'Sixty', 7 => 'Seventy',
8 => 'Eighty', 9 => 'Ninety'
];
if ($num == 0) return 'Zero';
$result = '';
if ($num >= 10000000) {
$result .= numberToWords(floor($num / 10000000)) . ' Crore ';
$num %= 10000000;
}
if ($num >= 100000) {
$result .= numberToWords(floor($num / 100000)) . ' Lakh ';
$num %= 100000;
}
if ($num >= 1000) {
$result .= numberToWords(floor($num / 1000)) . ' Thousand ';
$num %= 1000;
}
if ($num >= 100) {
$result .= $ones[floor($num / 100)] . ' Hundred ';
$num %= 100;
}
if ($num > 0) {
if ($num < 20) {
$result .= $ones[$num] . ' ';
} else {
$result .= $tens[floor($num / 10)];
if ($num % 10 > 0) {
$result .= ' ' . $ones[$num % 10];
}
}
}
return trim($result);
}
}
/* ================= STATE CODE ================= */
$state_codes = [
// ===== STATES =====
'andhra pradesh' => '37',
'arunachal pradesh' => '12',
'assam' => '18',
'bihar' => '10',
'chhattisgarh' => '22',
'goa' => '30',
'gujarat' => '24',
'haryana' => '06',
'himachal pradesh' => '02',
'jharkhand' => '20',
'karnataka' => '29',
'kerala' => '32',
'madhya pradesh' => '23',
'maharashtra' => '27',
'manipur' => '14',
'meghalaya' => '17',
'mizoram' => '15',
'nagaland' => '13',
'odisha' => '21',
'punjab' => '03',
'rajasthan' => '08',
'sikkim' => '11',
'tamil nadu' => '33',
'telangana' => '36',
'tripura' => '16',
'uttar pradesh' => '09',
'uttarakhand' => '05',
'west bengal' => '19',
// ===== UNION TERRITORIES =====
'andaman and nicobar islands' => '35',
'chandigarh' => '04',
'dadra and nagar haveli and daman and diu' => '26',
'delhi' => '07',
'jammu and kashmir' => '01',
'ladakh' => '38',
'lakshadweep' => '31',
'puducherry' => '34'
];
$state_code = $state_codes[$state] ?? '';
$formatted_date = date('d-m-Y', strtotime($invoice['invoice_date']));
$formatted_time = date('h:i:s A', strtotime($invoice['invoice_date']));
$customer_name = ucwords(strtolower($invoice['client_name']));
$customer_address = ucwords(strtolower($invoice['address']));
$customer_city = ucwords(strtolower($invoice['city']));
$customer_state = ucwords(strtolower($invoice['state']));
/* ================= NORMAL PAGE LOAD ================= */
$title = "Invoice View";
include 'include/header.php';
?>
|
R.P. JEWELLERS & SONS
Shree Rameshwar Prasad Sonar
GSTIN: 19BXRPP1193E1ZO PAN No. BXRPP1193E
|
| Invoice No:
= htmlspecialchars($invoice['invoice_no']) ?>
|
Name:
= htmlspecialchars($customer_name) ?>
|
Phone:
= htmlspecialchars($invoice['phone']) ?>
|
Date:
= $formatted_date ?>
|
|
Address:
= htmlspecialchars($customer_address) ?>,
= htmlspecialchars($customer_city) ?>,
= htmlspecialchars($customer_state) ?> -
= htmlspecialchars($invoice['pincode']) ?>
|
| PAN:
= htmlspecialchars($invoice['pan_no']) ?>
|
GST:
= htmlspecialchars($invoice['gst_no']) ?>
|
State Code:
= $state_code ?>
|
| TOTAL |
= number_format($items_subtotal, 2) ?>
|
| UPI: |
Cheque: |
Metal: |
Cash: |
Card: |
| ₹
= number_format($payments['UPI'], 2) ?>
|
₹
= number_format($payments['Cheque'], 2) ?>
|
₹
= number_format($payments['Metal'], 2) ?>
|
₹
= number_format($payments['Cash'], 2) ?>
|
₹
= number_format($payments['Card'], 2) ?>
|
Total :
= numberToWords($round_final_amount) ?> Only
|
| Total : |
₹
= number_format($items_subtotal, 2) ?>
|
| C-GST 1.5% : |
₹
= number_format($cgst, 2) ?>
|
| S-GST 1.5% : |
₹
= number_format($sgst, 2) ?>
|
| HM CGST 9% : |
₹
= number_format($hm_cgst, 2) ?>
|
| HM SGST 9% : |
₹
= number_format($hm_sgst, 2) ?>
|
| I-GST 3% : |
₹
= number_format($igst, 2) ?>
|
| HM IGST 18% : |
₹
= number_format($hm_igst, 2) ?>
|
0): ?>
| Discount
(
= $discount_value ?>%)
:
|
- ₹
= number_format($discount_amount, 2) ?>
|
| Final Amount : |
₹
= number_format($final_amount, 2) ?>
|
| Round Off : |
₹
= number_format($round_off, 2) ?>
|
| Grand Total : |
₹
= number_format($round_final_amount, 2) ?>
|
|
0) : ?>
| SL |
Charge Name |
Amount |
$charge) : ?>
|
= $idx + 1 ?>
|
= htmlspecialchars($charge['charge_name']) ?>
|
= number_format($charge['amount'], 2) ?>
|
|
Total Other Charges
|
= number_format($other_charges, 2) ?>
|
| Grand Total |
₹
= number_format($grand_total_with_other, 2) ?>
|
|
___________________________ Customer Signature
|
___________________________ For R P JEWELLERS & SONS
|