Support the ongoing development of Laravel.io →
Blade JavaScript Laravel
0
moderator

Hello @patelmahmed

Can you explain more in what you need and what you have tried?

0

i want to add gst tex in laravel e-commerce website...3 type gst in india..how product gst add in laravel 8

0

Calculate GST Tax in Amount in laravel e-commerce website...explain step by step brief

0

To add SGST, CGST, and IGST calculations to your e-commerce website's cart and checkout pages using JavaScript, you can follow these steps:

Create a function to determine the type of tax (CGST + SGST or IGST) based on the buyer's and seller's GSTIN:

function determineTaxType(buyerGstin, sellerGstin) {
  return buyerGstin.substring(0, 2) === sellerGstin.substring(0, 2) ? 'intraState' : 'interState';
}
Create a function to calculate the tax amounts based on the tax type and tax rates:
function calculateTaxes(taxType, taxRates, taxableAmount) {
  const taxes = { cgst: 0, sgst: 0, igst: 0 };

  if (taxType === 'intraState') {
    taxes.cgst = taxableAmount * taxRates.cgst / 100;
    taxes.sgst = taxableAmount * taxRates.sgst / 100;
  } else {
    taxes.igst = taxableAmount * taxRates.igst / 100;
  }

  return taxes;
}

Define the tax rates for your products:

const taxRates = {
  product1: { cgst: 9, sgst: 9, igst: 18 },
  product2: { cgst: 14, sgst: 14, igst: 28 },
  // Add more products and their tax rates
};

Use the above functions to calculate the taxes for each item in the cart:

const cartItems = [
  { id: 'product1', price: 100, quantity: 2 },
  { id: 'product2', price: 200, quantity: 1 },
  // Add more items
];

const buyerGstin = '27XXXXXXX1234Z5';
const sellerGstin = '29XXXXXXX1234Z5';

const taxType = determineTaxType(buyerGstin, sellerGstin);

cartItems.forEach((item) => {
  const taxableAmount = item.price * item.quantity;
  const taxes = calculateTaxes(taxType, taxRates[item.id], taxableAmount);

  item.cgst = taxes.cgst;
  item.sgst = taxes.sgst;
  item.igst = taxes.igst;
});

Display the calculated taxes on the cart and checkout pages, and include them in the total amount.

<!-- Cart table -->
<table>
  <!-- Table header -->
  <tr>
    <th>Product</th>
    <th>Price</th>
    <th>Quantity</th>
    <th>CGST</th>
    <th>SGST</th>
    <th>IGST</th>
    <th>Total</th>
  </tr>
  <!-- Cart items -->
  <tr v-for="item in cartItems">
    <td>{{ item.id }}</td>
    <td>{{ item.price }}</td>
    <td>{{ item.quantity }}</td>
    <td>{{ item.cgst.toFixed(2) }}</td>
    <td>{{ item.sgst.toFixed(2) }}</td>
    <td>{{ item.igst.toFixed(2) }}</td>
    <td>{{ (item.price * item.quantity + item.cgst + item.sgst + item.igst).toFixed(2) }}</td>
  </tr>
</table>

By following these steps, you can add SGST, CGST, and IGST calculations in your e-commerce website's cart and checkout pages using JavaScript. Adjust the tax rates and GSTINs according to your specific use case and product catalog.

0

Thanks for the steps. You made my day. I also would like to help you by sharing the https://casinosanalyzer.com/online-casinos/candyland.casino website with you where you online casinos sites through which you can make money. I am also using that platform to find online real money gaming sites.

Last updated 1 year ago.

bencullendev liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

muhammed patelmahmed Joined 2 Feb 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.