Skip to content

Commit 539cc20

Browse files
uds5501abhinavk96
authored andcommitted
feat: show tax information on public ticket page (#3078)
* implement tax information on public page * add tax inclusion message in component * change template for tax inclusion message * resolve taxInfo promise * add conditions for include ticket price * fix linting errors
1 parent 741f067 commit 539cc20

File tree

7 files changed

+132
-34
lines changed

7 files changed

+132
-34
lines changed

app/components/public/ticket-list.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export default Component.extend(FormMixin, {
1919
return !this.hasTicketsInOrder;
2020
}),
2121

22+
showTaxIncludedMessage: computed('taxInfo.isTaxIncludedInPrice', function() {
23+
if (this.taxInfo !== null) {
24+
return (this.taxInfo.isTaxIncludedInPrice);
25+
}
26+
return false;
27+
}),
28+
2229
accessCodeTickets : A(),
2330
discountedTickets : A(),
2431

@@ -29,13 +36,18 @@ export default Component.extend(FormMixin, {
2936
}),
3037
hasTicketsInOrder: computed('[email protected]', function() {
3138
return sumBy(this.tickets.toArray(),
32-
ticket => ticket.getWithDefault('orderQuantity', 0)
39+
ticket => (ticket.orderQuantity || 0)
3340
) > 0;
3441
}),
3542

3643
total: computed('[email protected]', '[email protected]', function() {
44+
if (this.taxInfo !== null) {
45+
return sumBy(this.tickets.toArray(),
46+
ticket => (ticket.ticketPriceWithTax || 0) * (ticket.orderQuantity || 0)
47+
);
48+
}
3749
return sumBy(this.tickets.toArray(),
38-
ticket => (ticket.getWithDefault('price', 0) - ticket.getWithDefault('discount', 0)) * ticket.getWithDefault('orderQuantity', 0)
50+
ticket => ((ticket.price || 0) - (ticket.discount || 0)) * (ticket.orderQuantity || 0)
3951
);
4052
}),
4153
actions: {
@@ -57,6 +69,15 @@ export default Component.extend(FormMixin, {
5769
this.tickets.removeObject(ticket);
5870
});
5971
this.discountedTickets.forEach(ticket => {
72+
let taxRate = ticket.get('event.tax.rate');
73+
let ticketPrice = ticket.get('price');
74+
if (taxRate && !this.showTaxIncludedMessage) {
75+
let ticketPriceWithTax = ticketPrice * (1 + taxRate / 100);
76+
ticket.set('ticketPriceWithTax', ticketPriceWithTax);
77+
} else if (taxRate && this.showTaxIncludedMessage) {
78+
let includedTaxAmount = (taxRate * ticketPrice) / (100 + taxRate);
79+
ticket.set('includedTaxAmount', includedTaxAmount);
80+
}
6081
ticket.set('discount', 0);
6182
});
6283
this.accessCodeTickets.clear();
@@ -94,13 +115,17 @@ export default Component.extend(FormMixin, {
94115
let tickets = await discountCode.get('tickets');
95116
tickets.forEach(ticket => {
96117
let ticketPrice = ticket.get('price');
97-
if (discountType === 'amount') {
98-
ticket.set('discount', Math.min(ticketPrice, discountValue));
99-
this.discountedTickets.addObject(ticket);
100-
} else {
101-
ticket.set('discount', ticketPrice * (discountValue / 100));
102-
this.discountedTickets.addObject(ticket);
118+
let taxRate = ticket.get('event.tax.rate');
119+
let discount = discountType === 'amount' ? Math.min(ticketPrice, discountValue) : ticketPrice * (discountValue / 100);
120+
ticket.set('discount', discount);
121+
if (taxRate && !this.showTaxIncludedMessage) {
122+
let ticketPriceWithTax = (ticketPrice - ticket.discount) * (1 + taxRate / 100);
123+
ticket.set('ticketPriceWithTax', ticketPriceWithTax);
124+
} else if (taxRate && this.showTaxIncludedMessage) {
125+
let includedTaxAmount = (taxRate * (ticketPrice - discount)) / (100 + taxRate);
126+
ticket.set('includedTaxAmount', includedTaxAmount);
103127
}
128+
this.discountedTickets.addObject(ticket);
104129
this.set('invalidPromotionalCode', false);
105130
});
106131
} else {

app/controllers/public/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ export default Controller.extend({
113113
return;
114114
}
115115
let { order, event } = this.model;
116-
let tax = await event.get('tax');
117-
if (tax) {
118-
if (!tax.get('isTaxIncludedInPrice')) {
119-
let taxedPrice = (order.amount) * (tax.rate) / 100 + (order.amount);
120-
order.set('amount', taxedPrice);
121-
}
122-
}
123116
order.tickets.forEach(ticket => {
124117
let numberOfAttendees = ticket.orderQuantity;
125118
while (numberOfAttendees--) {

app/models/ticket.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,31 @@ export default ModelBase.extend({
4646

4747
itemTotal: computed('price', 'quantity', function() {
4848
return this.price * this.quantity;
49+
}),
50+
51+
/**
52+
* This attribute computes total ticket price payable after inclusion
53+
* of additional taxes on the base ticket price
54+
*/
55+
ticketPriceWithTax: computed('event.tax.isTaxIncludedInPrice', 'event.tax.rate', function() {
56+
let taxType = this.event.get('tax.isTaxIncludedInPrice');
57+
if (!taxType) {
58+
return ((1 + this.event.get('tax.rate') / 100) * this.price).toFixed(2);
59+
}
60+
return this.price;
61+
}),
62+
63+
/**
64+
* This attribute computes value added tax amount in the cases
65+
* when tax amount is included in ticket price, otherwise return
66+
* 0
67+
*/
68+
includedTaxAmount: computed('event.tax.isTaxIncludedInPrice', 'event.tax.rate', function() {
69+
const taxType = this.event.get('tax.isTaxIncludedInPrice');
70+
if (taxType) {
71+
const taxRate = this.event.get('tax.rate');
72+
return ((taxRate * this.price) / (100 + taxRate)).toFixed(2);
73+
}
74+
return 0;
4975
})
5076
});

app/routes/public/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export default Route.extend({
5757
'page[size]': 0
5858
}),
5959

60-
sponsors: await eventDetails.get('sponsors'),
61-
62-
order: this.store.createRecord('order', {
60+
sponsors : await eventDetails.get('sponsors'),
61+
tax : await eventDetails.get('tax'),
62+
order : this.store.createRecord('order', {
6363
event : eventDetails,
6464
user : this.get('authManager.currentUser'),
6565
tickets : []

app/templates/components/public/ticket-list.hbs

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<tr>
55
<th>{{t 'Type'}}</th>
66
<th class="four wide">{{t 'Sales Ends'}}</th>
7-
<th class="ui two wide">{{t 'Price'}}</th>
7+
<th class="ui three wide">{{t 'Price'}}</th>
88
<th class="one wide">{{t 'Quantity'}}</th>
99
<th class="ui right aligned two wide">{{t 'Subtotal'}}</th>
1010
</tr>
@@ -22,22 +22,64 @@
2222
{{/if}}
2323
</td>
2424
<td>{{moment-format ticket.salesEndsAt 'ddd, DD MMMM YY, h:mm A'}}</td>
25-
{{#if (eq ticket.type 'donation') }}
26-
<div class="three wide column">
27-
<td id="{{ticket.id}}_price">{{input type='number' value=ticket.price}}</td>
28-
</div>
25+
{{#if ticket.discount}}
26+
<td>
27+
<div id="{{ticket.id}}_price" class="strike text">
28+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
29+
</div>
30+
<div id="{{ticket.id}}_discount">
31+
{{currency-symbol eventCurrency}} {{format-number (sub ticket.price ticket.discount)}}
32+
{{#if taxInfo}}
33+
{{#if showTaxIncludedMessage}}
34+
<small class="ui gray-text small">
35+
{{t 'includes'}} {{currency-symbol eventCurrency}} {{format-number ticket.includedTaxAmount}}
36+
</small>
37+
{{else}}
38+
<small class="ui gray-text small">
39+
+ {{currency-symbol eventCurrency}} {{format-number (add (sub ticket.ticketPriceWithTax ticket.price) ticket.discount)}}
40+
</small>
41+
{{/if}}
42+
<div>
43+
<small class="ui gray-text tiny aligned right">({{taxInfo.name}})</small>
44+
</div>
45+
{{/if}}
46+
</div>
47+
</td>
2948
{{else}}
30-
{{#if ticket.discount}}
31-
<td>
32-
<div id="{{ticket.id}}_price" class="strike text">
33-
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
34-
</div>
35-
<div id="{{ticket.id}}_discount">
36-
{{currency-symbol eventCurrency}} {{format-number (sub ticket.price ticket.discount)}}
49+
<td id="{{ticket.id}}_price">
50+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
51+
{{#if (and taxInfo (not-eq ticket.type 'free'))}}
52+
{{#if showTaxIncludedMessage}}
53+
<small class="ui gray-text small">
54+
{{t 'includes'}} {{currency-symbol eventCurrency}} {{format-number ticket.includedTaxAmount}}
55+
</small>
56+
{{else}}
57+
<small class="ui gray-text small">
58+
+ {{currency-symbol eventCurrency}} {{format-number (sub ticket.ticketPriceWithTax ticket.price)}}
59+
</small>
60+
{{/if}}
61+
<div>
62+
<small class="ui gray-text tiny aligned right">({{taxInfo.name}})</small>
3763
</div>
38-
</td>
64+
{{/if}}
65+
</td>
66+
{{#if (eq ticket.type 'donation') }}
67+
<div class="three wide column">
68+
<td id="{{ticket.id}}_price">{{input type='number' value=ticket.price}}</td>
69+
</div>
3970
{{else}}
40-
<td id="{{ticket.id}}_price">{{currency-symbol eventCurrency}} {{format-number ticket.price}}</td>
71+
{{#if ticket.discount}}
72+
<td>
73+
<div id="{{ticket.id}}_price" class="strike text">
74+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
75+
</div>
76+
<div id="{{ticket.id}}_discount">
77+
{{currency-symbol eventCurrency}} {{format-number (sub ticket.price ticket.discount)}}
78+
</div>
79+
</td>
80+
{{else}}
81+
<td id="{{ticket.id}}_price">{{currency-symbol eventCurrency}} {{format-number ticket.price}}</td>
82+
{{/if}}
4183
{{/if}}
4284
{{/if}}
4385
<td>
@@ -56,7 +98,11 @@
5698
</div>
5799
</td>
58100
<td id='{{ticket.id}}_subtotal' class="ui right aligned">
59-
{{currency-symbol eventCurrency}} {{format-number (mult (sub ticket.price ticket.discount) ticket.orderQuantity)}}
101+
{{#if taxInfo}}
102+
{{currency-symbol eventCurrency}} {{format-number (mult ticket.ticketPriceWithTax ticket.orderQuantity)}}
103+
{{else}}
104+
{{currency-symbol eventCurrency}} {{format-number (mult (sub ticket.price ticket.discount) ticket.orderQuantity)}}
105+
{{/if}}
60106
</td>
61107
</tr>
62108
{{/unless}}

app/templates/public/index.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
order=model.order
2121
attendees=model.attendees
2222
code=code
23+
taxInfo=model.tax
2324
currentEventIdentifier=model.event.identifier
2425
createNewUserViaEmail=(action 'createNewUserViaEmail')
2526
loginExistingUser=(action 'loginExistingUser')

tests/integration/components/public/ticket-list-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { setupIntegrationTest } from 'open-event-frontend/tests/helpers/setup-in
55
import hbs from 'htmlbars-inline-precompile';
66
import { render } from '@ember/test-helpers';
77

8+
89
module('Integration | Component | public/ticket list', function(hooks) {
910
setupIntegrationTest(hooks);
1011

@@ -50,10 +51,16 @@ module('Integration | Component | public/ticket list', function(hooks) {
5051
})
5152
]
5253
);
54+
const eventTax = EmberObject.create({
55+
name : 'Sample Tax',
56+
rate : 20,
57+
isTaxIncludedInPrice : true
58+
});
5359
test('it renders', async function(assert) {
5460
this.set('data', tickets);
61+
this.set('taxInfo', eventTax);
5562
this.actions.placeOrder = function() { };
56-
await render(hbs `{{public/ticket-list data=data placeOrder=(action 'placeOrder') eventCurrency='USD'}}`);
63+
await render(hbs `{{public/ticket-list data=data placeOrder=(action 'placeOrder') eventCurrency='USD' taxInfo=taxInfo}}`);
5764
assert.ok(this.element.innerHTML.trim().includes('Standard Ticket'));
5865
});
5966
});

0 commit comments

Comments
 (0)