Skip to content

Commit 4f50d2e

Browse files
committed
fix
1 parent 0eb0ead commit 4f50d2e

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

app/components/public/ticket-list.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Component from '@ember/component';
22
import { computed } from '@ember/object';
3+
import { debounce } from '@ember/runloop';
34
import FormMixin from 'open-event-frontend/mixins/form';
45
import { inject as service } from '@ember/service';
56
import { sumBy, merge } from 'lodash-es';
@@ -27,13 +28,6 @@ export default Component.extend(FormMixin, {
2728
}
2829
}),
2930

30-
showTaxIncludedMessage: computed('taxInfo.isTaxIncludedInPrice', function() {
31-
if (this.taxInfo !== null) {
32-
return (this.taxInfo.isTaxIncludedInPrice);
33-
}
34-
return false;
35-
}),
36-
3731
accessCodeTickets : A(),
3832
discountedTickets : A(),
3933

@@ -88,8 +82,7 @@ export default Component.extend(FormMixin, {
8882
);
8983
}),
9084

91-
orderAmountInput: computed('[email protected]', 'order.discountCode', function() {
92-
console.log(this.order.tickets.toArray());
85+
orderAmountInput: computed('[email protected]', '[email protected]', 'order.discountCode', function() {
9386

9487
return {
9588
tickets: this.order.tickets.toArray().map(ticket => ({
@@ -115,15 +108,16 @@ export default Component.extend(FormMixin, {
115108
this.set('code', null);
116109
this.order.set('accessCode', undefined);
117110
this.order.set('discountCode', undefined);
111+
this.tickets.forEach(ticket => {
112+
ticket.set('discount', null);
113+
});
118114
this.accessCodeTickets.forEach(ticket => {
119115
ticket.set('isHidden', true);
120116
this.tickets.removeObject(ticket);
121117
});
122-
this.discountedTickets.forEach(ticket => {
123-
ticket.set('discount', 0);
124-
});
125118
this.accessCodeTickets.clear();
126119
this.discountedTickets.clear();
120+
this.send('updateOrderAmount');
127121
}
128122

129123
}
@@ -150,13 +144,10 @@ export default Component.extend(FormMixin, {
150144
const discountCode = await this.store.queryRecord('discount-code', { eventIdentifier: this.event.id, code: this.promotionalCode, include: 'event,tickets' });
151145
const discountCodeEvent = await discountCode.event;
152146
if (this.currentEventIdentifier === discountCodeEvent.identifier) {
153-
const discountType = discountCode.type;
154-
const discountValue = discountCode.value;
155147
this.order.set('discountCode', discountCode);
156148
const tickets = await discountCode.tickets;
157149
tickets.forEach(ticket => {
158-
const ticketPrice = ticket.price;
159-
const discount = discountType === 'amount' ? Math.min(ticketPrice, discountValue) : ticketPrice * (discountValue / 100);
150+
const discount = discountCode.type === 'amount' ? Math.min(ticket.price, discountCode.value) : ticket.price * (discountCode.value / 100);
160151
ticket.set('discount', discount);
161152
this.discountedTickets.addObject(ticket);
162153
this.set('invalidPromotionalCode', false);
@@ -179,19 +170,16 @@ export default Component.extend(FormMixin, {
179170
this.set('promotionalCodeApplied', true);
180171
this.set('promotionalCode', 'Promotional code applied successfully');
181172
}
182-
this.order.set('amount', this.total);
183173
this.send('updateOrderAmount');
184174
},
185175

186176
async updateOrder(ticket, count) {
187177
ticket.set('orderQuantity', count);
188-
this.order.set('amount', this.total);
189-
if (!this.total) {
190-
this.order.set('amount', 0);
191-
}
192178
if (count > 0) {
193179
this.order.tickets.addObject(ticket);
194180
} else {
181+
ticket.set('subTotal', null);
182+
ticket.set('discountInfo', null);
195183
if (this.order.tickets.includes(ticket)) {
196184
this.order.tickets.removeObject(ticket);
197185
}
@@ -201,18 +189,18 @@ export default Component.extend(FormMixin, {
201189
},
202190

203191
async updateOrderAmount() {
204-
console.log(this.orderAmountInput);
205-
206192
this.set('orderAmount', await this.loader.post('/orders/calculate-amount', this.orderAmountInput));
207-
208-
console.log(this.orderAmount);
209193
},
210194

211195
handleKeyPress() {
212196
if (event.code === 'Enter') {
213197
this.send('applyPromotionalCode');
214198
this.set('code', this.promotionalCode);
215199
}
200+
},
201+
202+
onChangeDonation() {
203+
debounce(this, () => this.send('updateOrderAmount'), this.tickets, 250);
216204
}
217205
},
218206
didInsertElement() {

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,28 @@
4242
@name={{ticket.id}} placeholder={{t "Enter Donation"}}
4343
@min={{ticket.minPrice}}
4444
@max={{ticket.maxPrice}}
45-
@value={{ticket.price}} />
45+
@value={{ticket.price}}
46+
@keyUp={{action "onChangeDonation"}} />
4647
</div>
4748
{{else}}
4849
<div class="{{if ticket.discount 'strike text'}}">
49-
{{currency-symbol this.eventCurrency}} {{format-number ticket.price}}
50+
{{currency-symbol this.eventCurrency}} {{format-money ticket.price}}
5051
</div>
5152
{{#if ticket.discount}}
5253
<div>
53-
{{currency-symbol this.eventCurrency}} {{format-number (sub ticket.price ticket.discount)}}
54+
{{currency-symbol this.eventCurrency}} {{format-money (sub ticket.price ticket.discount)}}
5455
</div>
5556
{{/if}}
5657
{{/if}}
5758
{{#if (and this.taxInfo (not-eq ticket.type 'free'))}}
5859
<p>
59-
{{#if this.showTaxIncludedMessage}}
60+
{{#if this.taxInfo.isTaxIncludedInPrice}}
6061
<small class="ui gray-text small">
61-
{{t 'includes'}} {{currency-symbol this.eventCurrency}} {{format-number ticket.includedTaxAmount}}
62+
{{t 'includes'}} {{currency-symbol this.eventCurrency}} {{format-money ticket.includedTaxAmount}}
6263
</small>
6364
{{else}}
6465
<small class="ui gray-text small">
65-
+ {{currency-symbol this.eventCurrency}} {{format-number (sub ticket.ticketPriceWithTax ticket.price)}}
66+
+ {{currency-symbol this.eventCurrency}} {{format-money (sub ticket.ticketPriceWithTax ticket.price)}}
6667
</small>
6768
{{/if}}
6869
<span>
@@ -93,23 +94,35 @@
9394
</div>
9495
</td>
9596
<td id='{{ticket.id}}_subtotal' class="ui right aligned">
96-
{{currency-symbol this.eventCurrency}} {{format-number ticket.subTotal}}
97+
{{currency-symbol this.eventCurrency}} {{format-money ticket.subTotal}}
9798
</td>
9899
</tr>
99100
{{/unless}}
100101
{{/each}}
101102
</tbody>
102103
<tfoot class="full-width">
103104
<tr>
104-
<th></th>
105-
<th></th>
106-
<th></th>
107-
<th></th>
108-
<th colspan="4">
109-
<div class="ui right aligned small primary icon">
110-
{{t 'Total'}}: {{currency-symbol this.eventCurrency}} {{format-number this.total}}
111-
</div>
112-
</th>
105+
<td></td>
106+
<td></td>
107+
<td colspan="3">
108+
<table class="ui small" style="float: right;">
109+
<tbody>
110+
{{#if orderAmount.tax}}
111+
<tr><td>{{t 'Sub-Total'}}</td><td>{{currency-symbol this.eventCurrency}} {{format-money this.orderAmount.sub_total}}</td></tr>
112+
<tr>
113+
<td>
114+
<div>{{t 'Tax'}} ({{this.orderAmount.tax.percent}}% {{this.orderAmount.tax.name}})</div>
115+
{{#if orderAmount.tax.included}}
116+
<small class="ui gray-text small">Included in Total</small>
117+
{{/if}}
118+
</td>
119+
<td>{{currency-symbol this.eventCurrency}} {{this.orderAmount.tax.amount}}</td>
120+
</tr>
121+
{{/if}}
122+
<tr><td>{{t 'Total'}}</td><td>{{currency-symbol this.eventCurrency}} {{format-money this.orderAmount.total}}</td></tr>
123+
</tbody>
124+
</table>
125+
</td>
113126
</tr>
114127
</tfoot>
115128
</table>

0 commit comments

Comments
 (0)