:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/kreative_crm/quatation/**
:: Editing File: invoice_add.php
<?php ob_start(); include 'header.php'; $page_title = "Add Invoice"; $page_parent = "Invoices"; $page_parent_link = "invoice.php"; include 'breadcrumb.php'; include 'menu.php'; ?> <div class="page-body"> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="card shadow-sm"> <div class="card-header pb-0 card-no-border"> <h2>Add New Invoice</h2> </div> <div class="card-body"> <form id="invoiceForm" method="POST" action="invoice_save.php"> <div class="row g-3"> <!-- Start KRP2025-501 Invoice Number -- <div class="col-md-4"> <label class="form-label fw-bold">Invoice Number</label> <input type="text" name="invoice_no" class="form-control" placeholder="Enter Invoice Number" required> </div> --> <?php // Fetch the last invoice number $prefix = "KRP2025-"; // Change this prefix each year if needed $query = "SELECT invoice_no FROM invoices ORDER BY id DESC LIMIT 1"; $result = mysqli_query($conn, $query); if ($row = mysqli_fetch_assoc($result)) { // Extract the numeric part after the dash $lastNumber = (int)substr($row['invoice_no'], strrpos($row['invoice_no'], '-') + 1); $nextNumber = $lastNumber + 1; } else { // Start from 501 if no invoices exist yet $nextNumber = 501; } $newInvoiceNo = $prefix . $nextNumber; ?> <div class="col-md-4"> <label class="form-label fw-bold">Invoice Number</label> <input type="text" name="invoice_no" class="form-control" value="<?php echo $newInvoiceNo; ?>" readonly> </div> <!-- Client / Party Name --> <div class="col-md-4"> <label class="form-label fw-bold">Client Name</label> <select name="client_id" id="client_id" class="form-select" > <option value="">-- Select Client --</option> <?php $clients = mysqli_query($conn, "SELECT id, name FROM clients ORDER BY name ASC"); while ($c = mysqli_fetch_assoc($clients)) { echo "<option value='{$c['id']}'>{$c['name']}</option>"; } ?> </select> </div> <!-- Invoice Date --> <div class="col-md-4"> <label class="form-label fw-bold">Party Name</label> <input type="text" name="party_name" class="form-control" > </div> <!-- Invoice Date current date & time -- <div class="col-md-6"> <label class="form-label fw-bold">Invoice Date</label> <input type="datetime-local" name="invoice_date" class="form-control"> </div> --> <?php date_default_timezone_set('Asia/Kolkata'); ?> <div class="col-md-6"> <label class="form-label fw-bold">Invoice Date</label> <input type="datetime-local" name="invoice_date" class="form-control" value="<?php echo date('Y-m-d\TH:i'); ?>"> </div> <!-- Payment Mode --> <div class="col-md-6"> <label class="form-label fw-bold">Payment Mode</label> <select name="payment_mode" class="form-select"> <option value="">Select</option> <option value="CASH">Cash</option> <option value="CREDIT">Credit</option> <option value="ONLINE">Online</option> </select> </div> <!-- Receiver GSTIN -- <div class="col-md-4"> <label class="form-label fw-bold">Receiver GSTIN</label> <input type="text" name="receiver_gstin" class="form-control" placeholder="Enter GSTIN"> </div> <!-- Receiver Address -- <div class="col-md-6"> <label class="form-label fw-bold">Receiver Address</label> <textarea name="receiver_address" class="form-control" rows="3" placeholder="Enter Address"></textarea> </div> <!-- Items Table --> <div class="col-md-12 mt-4"> <h5>Items Purchased</h5> <table class="table table-bordered" id="itemsTable"> <thead class="table-light"> <tr> <th>Description</th> <th>HSN</th> <th>Price</th> <th>Qty</th> <th>Tax %</th> <th>Taxable Amt</th> <th>Action</th> </tr> </thead> <tbody> <tr> <td><input name="description[]" class="form-control" placeholder="Enter item"></td> <td><input name="hsn_code[]" class="form-control"></td> <td><input type="number" step="0.01" name="price[]" class="form-control price" value="0"></td> <td><input type="number" step="0.01" name="quantity[]" class="form-control qty" value="1"></td> <td><input type="number" step="0.01" name="tax_percent[]" class="form-control tax" value="0"></td> <td><input type="number" step="0.01" name="taxable_amount[]" class="form-control total" readonly></td> <td><button type="button" class="btn btn-danger btn-sm removeRow">X</button></td> </tr> </tbody> </table> <button id="addItem" type="button" class="btn btn-outline-primary btn-sm">+ Add Item</button> </div> <!-- Totals Section --> <div class="col-md-4 offset-md-8"> <div class="card p-2"> <div class="mb-2"> <label class="form-label fw-bold">Sub Total (₹)</label> <input type="text" name="sub_total" class="form-control" id="sub_total" value="0"> </div> <div class="mb-2"> <label class="form-label fw-bold">Tax Total (₹)</label> <input type="text" name="tax_total" class="form-control" id="tax_total" value="0"> </div> <div class="mb-2"> <label class="form-label fw-bold">Advance Amount (₹)</label> <input type="number" step="0.01" name="advance_amount" class="form-control" id="advance_amount" value="0"> </div> <div class="mb-2"> <label class="form-label fw-bold">Remaining Total (₹)</label> <input type="text" name="grand_total" class="form-control" id="grand_total" value="0"> </div> </div> </div> </div> <!-- Buttons --> <div class="text-start mt-4"> <button type="submit" class="btn btn-success">Submit</button> <a href="payment_details_list.php" class="btn btn-secondary">Cancel</a> </div> </form> </div> </div> </div> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', function () { const addItemBtn = document.getElementById('addItem'); const itemsTable = document.getElementById('itemsTable').getElementsByTagName('tbody')[0]; const advanceAmountInput = document.getElementById('advance_amount'); function recalcTotals() { let sub = 0, taxTotal = 0; const rows = itemsTable.querySelectorAll('tr'); rows.forEach(r => { const price = parseFloat(r.querySelector('.price').value) || 0; const qty = parseFloat(r.querySelector('.qty').value) || 0; const tax = parseFloat(r.querySelector('.tax').value) || 0; const line = price * qty; const taxAmt = line * (tax / 100); r.querySelector('.total').value = line.toFixed(2); sub += line; taxTotal += taxAmt; }); const advanceAmount = parseFloat(advanceAmountInput.value) || 0; document.getElementById('sub_total').value = sub.toFixed(2); document.getElementById('tax_total').value = taxTotal.toFixed(2); // Grand Total = Sub + Tax - Advance const grandTotal = (sub + taxTotal - advanceAmount).toFixed(2); document.getElementById('grand_total').value = grandTotal; } // Listen to price/qty/tax changes itemsTable.addEventListener('input', function (e) { if (['price', 'qty', 'tax'].some(cls => e.target.classList.contains(cls))) { recalcTotals(); } }); // Listen to advance amount change advanceAmountInput.addEventListener('input', recalcTotals); // Add new row addItemBtn.addEventListener('click', function () { const newRow = document.createElement('tr'); newRow.innerHTML = ` <td><input name="description[]" class="form-control" placeholder="Enter item"></td> <td><input name="hsn_code[]" class="form-control"></td> <td><input type="number" step="0.01" name="price[]" class="form-control price" value="0"></td> <td><input type="number" step="0.01" name="quantity[]" class="form-control qty" value="1"></td> <td><input type="number" step="0.01" name="tax_percent[]" class="form-control tax" value="0"></td> <td><input type="number" step="0.01" name="taxable_amount[]" class="form-control total" readonly></td> <td><button type="button" class="btn btn-danger btn-sm removeRow">X</button></td>`; itemsTable.appendChild(newRow); }); // Remove row itemsTable.addEventListener('click', function (e) { if (e.target.classList.contains('removeRow')) { e.target.closest('tr').remove(); recalcTotals(); } }); // Initial calculation recalcTotals(); }); </script> <?php include 'footer.php'; ob_end_flush(); ?>