Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/models/order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import attr from 'ember-data/attr';
import { computed } from '@ember/object';
import ModelBase from 'open-event-frontend/models/base';
import { belongsTo, hasMany } from 'ember-data/relationships';
import CustomPrimaryKeyMixin from 'open-event-frontend/mixins/custom-primary-key';
Expand Down Expand Up @@ -37,5 +38,15 @@ export default ModelBase.extend(CustomPrimaryKeyMixin, {
discountCode : belongsTo('discount-code'),
accessCode : belongsTo('access-code'),
tickets : hasMany('ticket', { readOnly: true }),
attendees : hasMany('attendee')
attendees : hasMany('attendee'),

taxAmount: computed('amount', 'event.tax.isTaxIncludedInPrice', 'event.tax.rate', function() {
const taxType = this.event.get('tax.isTaxIncludedInPrice');
const taxRate = this.event.get('tax.rate');
if (taxType) {
return ((taxRate * this.amount) / (100 + taxRate)).toFixed(2);
} else {
return ((this.amount) / (1 + taxRate / 100) * (taxRate / 100)).toFixed(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share thoght process behind this.

Copy link
Member Author

@divyamtayal divyamtayal Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let x be amount without taxIncluded
So we need to calculate tax which will can be calculated by totalAmount = x + x*taxRate/100;
where x * taxRate / 100 is tax added on top of it which is given by

totalAmount / ( 1 + taxRate / 100 ) * ( taxRate / 100 )  which gives
(taxRate * totalAmount) / (100 + taxRate)

here both if else statement means same, so I'll change that.

@maze-runnar pls have a look

}
})
});
2 changes: 1 addition & 1 deletion app/templates/components/orders/order-summary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<small class="ui gray-text small">{{t 'Included in Total' }}</small>
{{/if}}
</td>
<td><CurrencyAmount @currency={{this.eventCurrency}} @amount={{sub this.data.amount this.total}}/></td>
<td><CurrencyAmount @currency={{this.eventCurrency}} @amount={{this.data.taxAmount}}/></td>
</tr>
{{/if}}
<tr><td>{{t 'Grand Total'}}</td>
Expand Down