Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Taxes and Discounts to Kasir Object #16

Closed
6 tasks done
risangbaskoro opened this issue Feb 8, 2023 · 3 comments · Fixed by #29
Closed
6 tasks done

Apply Taxes and Discounts to Kasir Object #16

risangbaskoro opened this issue Feb 8, 2023 · 3 comments · Fixed by #29
Labels
feature New feature or request

Comments

@risangbaskoro
Copy link
Member

risangbaskoro commented Feb 8, 2023

Taxes and Discounts is basically just another item. For discounts, the value must subtract the gross_amount from item_details.

Create a discount() method to add discount. This method receives these parameters:

  • int $amount - The amount of discount. Automatically converts to a negative value if fixed, positive if percentage.
  • string|null $name - The name of applied discount. Defaults to null. If null, 'Discount #<discount_id>' name will be used.
  • bool $percent - Determine if the discount in fixed value or in percentage of gross_amount. Default: false.

Create a tax() method to add tax. This method receives these parameters:

  • int $amount - The amount of tax. Automatically converts to a negative value if fixed, positive if percentage.
  • string|null $name - The name of applied tax. Defaults to null. If null, 'Tax #<tax_id>' name will be used.
  • bool $percent - Determine if the tax in fixed value or in percentage of gross_amount. Default: false.
@risangbaskoro
Copy link
Member Author

risangbaskoro commented Feb 9, 2023

Example for double discount in percentage:

Given a gross amount of Rp10000

The transaction have two discounts:

  • discount #1: 20%
  • discount #2: 10%

First, we're doing Rp10000 - 20%, so it would be Rp8000.
Then, the final amount would be Rp8000 - 10%, which is Rp7200.

This also applies with taxes, and multiple discounts and taxes.

@risangbaskoro
Copy link
Member Author

Keeping an index of how many discounts or taxes has been applied would be helpful.

If it's the first index, the discount or tax will be calculated normally from gross amount. If it's not, calculate the discount or tax from the previous result of applied discount or tax.

@risangbaskoro
Copy link
Member Author

Generally, taxes are applied after discounts are applied. By this nature, we can prevent $kasir->tax()->discount() to apply taxes before the discounts is applied.

We can approach this by reversing taxes, do the discount calculation for the gross_amount, and then reapply the taxes.

@risangbaskoro risangbaskoro added the feature New feature or request label Feb 21, 2023
@risangbaskoro risangbaskoro linked a pull request Feb 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant