diff --git a/account/application/controllers/Welcome.php b/account/application/controllers/Welcome.php index 0adbe3f..9490757 100644 --- a/account/application/controllers/Welcome.php +++ b/account/application/controllers/Welcome.php @@ -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)"); + } } } diff --git a/account/application/controllers/inventory/Purchases.php b/account/application/controllers/inventory/Purchases.php index 41cf9f9..2841c0a 100644 --- a/account/application/controllers/inventory/Purchases.php +++ b/account/application/controllers/inventory/Purchases.php @@ -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, diff --git a/account/application/views/inventory/purchases/create.php b/account/application/views/inventory/purchases/create.php index ad9d079..0853d03 100644 --- a/account/application/views/inventory/purchases/create.php +++ b/account/application/views/inventory/purchases/create.php @@ -99,6 +99,7 @@ BalanceChoose A/C First --> +
Voucher No. # @@ -126,6 +127,12 @@
+ +
+ + +
+
@@ -180,6 +187,7 @@ +
13% VAT @@ -315,6 +323,7 @@ + @@ -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)); diff --git a/account/application/views/inventory/purchases/view.php b/account/application/views/inventory/purchases/view.php index dcfb935..5d96f42 100644 --- a/account/application/views/inventory/purchases/view.php +++ b/account/application/views/inventory/purchases/view.php @@ -71,12 +71,19 @@