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)");
}
$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);
$data['PurchaseDetails'] = $this->db->get("tbl_purchasedetails")->result();
$data['pageTitle'] = "View Purchase";
// print_r($data);die;
loadView("inventory/purchases/view", $data);
break;
case 'create':
@ -35,6 +36,7 @@ class Purchases extends CI_Controller
'purchase_date' => filter_var($_POST['purchase_date']),
'discount' => filter_var($_POST['discountpercentage']),
'created_on' => date('Y-m-d H:i:s'),
'vatToggle' => filter_var($_POST['vatToggleValue']),
'created_by' => 'admin',
'remarks' => '',
'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>
</fieldset> -->
</div>
<div class="col-2">
<fieldset>
<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-->
</div>
</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 -->
<div class="col-12 table-responsive p-0 mt-3">
<table class="table table-striped">
@ -180,6 +187,7 @@
<td></td>
</tr>
<tr>
<td class="text-right "><b>13% VAT</b></td>
<td class="text-right">
<input type="text" class="form-control" name="tax" id="tax" />
@ -315,6 +323,7 @@
<!-- <button type="reset" class="btn btn-default">Reset</button> -->
<button class="btn btn-primary" type="submit" name="submit">Save</button>
</div>
</form>
</div>
</div>
@ -328,6 +337,18 @@
var counter = $('.purchase-detail').length;
// Clone purchase detail div
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
$(document).on("click", ".addPurchaseDetail", function() {
counter+=1;
@ -419,7 +440,10 @@
// var discountpercent = parseFloat($("input[name=discountpercentage]").val());
// var discountamount = subtotal * (discountpercent/100);
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;
$("#subtotal").val(subtotal.toFixed(2));

View File

@ -71,12 +71,19 @@
<div class="row bill-footer">
<div class="col text-right">
<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>
<?php $discounted = ($total*$discount/100) ?>
<p><strong>Discount amount:</strong> <?php echo myCurrency($discounted,true); ?></p>
<?php endif; ?>
<?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>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>
</div>
</div>