purchasevoucher

This commit is contained in:
Sampanna Rimal 2024-08-06 12:48:20 +05:45
parent d164f3139d
commit 52f9c0dd15
4 changed files with 52 additions and 6 deletions

View File

@ -221,5 +221,18 @@ class Welcome extends CI_Controller
$this->db->query("ALTER TABLE tbl_items ADD COLUMN units_id INT(11)"); $this->db->query("ALTER TABLE tbl_items ADD COLUMN units_id INT(11)");
} }
$query = $this->db->query("SHOW COLUMNS FROM tbl_purchases LIKE 'vatToggle'");
// If the column doesn't exist, alter the table to add it
if ($query->num_rows() == 0) {
$this->db->query("ALTER TABLE tbl_purchases ADD COLUMN vatToggle INT(11)");
}
$query = $this->db->query("SHOW COLUMNS FROM tbl_sales LIKE 'vatToggle'");
// If the column doesn't exist, alter the table to add it
if ($query->num_rows() == 0) {
$this->db->query("ALTER TABLE tbl_sales ADD COLUMN vatToggle INT(11)");
}
} }
} }

View File

@ -24,6 +24,7 @@ class Purchases extends CI_Controller
$this->db->where('purchases_id', $id); $this->db->where('purchases_id', $id);
$data['PurchaseDetails'] = $this->db->get("tbl_purchasedetails")->result(); $data['PurchaseDetails'] = $this->db->get("tbl_purchasedetails")->result();
$data['pageTitle'] = "View Purchase"; $data['pageTitle'] = "View Purchase";
// print_r($data);die;
loadView("inventory/purchases/view", $data); loadView("inventory/purchases/view", $data);
break; break;
case 'create': case 'create':
@ -35,6 +36,7 @@ class Purchases extends CI_Controller
'purchase_date' => filter_var($_POST['purchase_date']), 'purchase_date' => filter_var($_POST['purchase_date']),
'discount' => filter_var($_POST['discountpercentage']), 'discount' => filter_var($_POST['discountpercentage']),
'created_on' => date('Y-m-d H:i:s'), 'created_on' => date('Y-m-d H:i:s'),
'vatToggle' => filter_var($_POST['vatToggleValue']),
'created_by' => 'admin', 'created_by' => 'admin',
'remarks' => '', 'remarks' => '',
'status' => 1, 'status' => 1,

View File

@ -99,6 +99,7 @@
<legend><span id="selectedAccountName"></span> Balance</legend><span id="selectedAccountBalance" style="padding: 6px 0px; display: inline-block; text-align: right; width: 100%;">Choose A/C First</span> <legend><span id="selectedAccountName"></span> Balance</legend><span id="selectedAccountBalance" style="padding: 6px 0px; display: inline-block; text-align: right; width: 100%;">Choose A/C First</span>
</fieldset> --> </fieldset> -->
</div> </div>
<div class="col-2"> <div class="col-2">
<fieldset> <fieldset>
<legend> Voucher No. #</legend><input type="text" readonly class="form-control2" id="voucher_no" value="<?php echo generateVoucherNo(); ?>" name="voucher_no"> <legend> Voucher No. #</legend><input type="text" readonly class="form-control2" id="voucher_no" value="<?php echo generateVoucherNo(); ?>" name="voucher_no">
@ -126,6 +127,12 @@
<!--COL END--> <!--COL END-->
</div> </div>
</fieldset> </fieldset>
<div class="mt-3">
<label for="vatToggle">VAT</label>
<input type="checkbox" id="vatToggle" checked>
</div>
<input type="hidden" id="vatToggleValue" name="vatToggleValue" value="0">
<!-- Purchase Details Section --> <!-- Purchase Details Section -->
<div class="col-12 table-responsive p-0 mt-3"> <div class="col-12 table-responsive p-0 mt-3">
<table class="table table-striped"> <table class="table table-striped">
@ -180,6 +187,7 @@
<td></td> <td></td>
</tr> </tr>
<tr> <tr>
<td class="text-right "><b>13% VAT</b></td> <td class="text-right "><b>13% VAT</b></td>
<td class="text-right"> <td class="text-right">
<input type="text" class="form-control" name="tax" id="tax" /> <input type="text" class="form-control" name="tax" id="tax" />
@ -315,6 +323,7 @@
<!-- <button type="reset" class="btn btn-default">Reset</button> --> <!-- <button type="reset" class="btn btn-default">Reset</button> -->
<button class="btn btn-primary" type="submit" name="submit">Save</button> <button class="btn btn-primary" type="submit" name="submit">Save</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
@ -328,6 +337,18 @@
var counter = $('.purchase-detail').length; var counter = $('.purchase-detail').length;
// Clone purchase detail div // Clone purchase detail div
var purchaseDetailClone = $(".purchase-detail").clone().show(); var purchaseDetailClone = $(".purchase-detail").clone().show();
$("#vatToggle").change(function() {
if (this.checked) {
$('#vatToggleValue').val('0');
$("tfoot tr:nth-child(4)").show();
} else {
//1 because i will use this for conditions so that it does not alter previously entered vouchers
$('#vatToggleValue').val('1');
$("tfoot tr:nth-child(4)").hide();
}
calculateTotals();
});
// Add Purchase Detail // Add Purchase Detail
$(document).on("click", ".addPurchaseDetail", function() { $(document).on("click", ".addPurchaseDetail", function() {
counter+=1; counter+=1;
@ -419,7 +440,10 @@
// var discountpercent = parseFloat($("input[name=discountpercentage]").val()); // var discountpercent = parseFloat($("input[name=discountpercentage]").val());
// var discountamount = subtotal * (discountpercent/100); // var discountamount = subtotal * (discountpercent/100);
var taxable = subtotal - discountamount; var taxable = subtotal - discountamount;
var tax = taxable * 0.13; var tax = 0;
if ($('#vatToggle').is(':checked')) {
tax = taxable * 0.13; // Include 13% VAT if checkbox is checked
}
var grandTotal = taxable + tax; var grandTotal = taxable + tax;
$("#subtotal").val(subtotal.toFixed(2)); $("#subtotal").val(subtotal.toFixed(2));

View File

@ -71,12 +71,19 @@
<div class="row bill-footer"> <div class="row bill-footer">
<div class="col text-right"> <div class="col text-right">
<p><strong>Subtotal:</strong> <?php echo myCurrency($total,true); ?></p> <p><strong>Subtotal:</strong> <?php echo myCurrency($total,true); ?></p>
<?php $discounted = 0; ?>
<?php if($discount > 0): ?>
<p><strong>Discount percent:</strong> <?php echo myCurrency($discount,true); ?></p> <p><strong>Discount percent:</strong> <?php echo myCurrency($discount,true); ?></p>
<?php $discounted = ($total*$discount/100) ?> <?php $discounted = ($total*$discount/100) ?>
<p><strong>Discount amount:</strong> <?php echo myCurrency($discounted,true); ?></p> <p><strong>Discount amount:</strong> <?php echo myCurrency($discounted,true); ?></p>
<?php endif; ?>
<?php $taxable = $total - $discounted ?> <?php $taxable = $total - $discounted ?>
<?php $tax = 0; ?>
<?php //print_r($Purchase->vatToggle);die; ?>
<?php if($Purchase->vatToggle != 1): ?>
<p><strong>Taxable amount:</strong> <?php echo myCurrency($taxable,true); ?></p> <p><strong>Taxable amount:</strong> <?php echo myCurrency($taxable,true); ?></p>
<p><strong>Tax (13%):</strong> <?php echo myCurrency($tax=($taxable*13)/100,true); ?></p> <p><strong>Tax (13%):</strong> <?php echo myCurrency($tax=($taxable*13)/100,true); ?></p>
<?php endif; ?>
<p><strong>Total:</strong> <?php echo myCurrency(($taxable+$tax),true); ?></p> <p><strong>Total:</strong> <?php echo myCurrency(($taxable+$tax),true); ?></p>
</div> </div>
</div> </div>