@@ -19,6 +19,13 @@ export default Component.extend(FormMixin, {
19
19
return ! this . hasTicketsInOrder ;
20
20
} ) ,
21
21
22
+ showTaxIncludedMessage : computed ( 'taxInfo.isTaxIncludedInPrice' , function ( ) {
23
+ if ( this . taxInfo !== null ) {
24
+ return ( this . taxInfo . isTaxIncludedInPrice ) ;
25
+ }
26
+ return false ;
27
+ } ) ,
28
+
22
29
accessCodeTickets : A ( ) ,
23
30
discountedTickets : A ( ) ,
24
31
@@ -29,13 +36,18 @@ export default Component.extend(FormMixin, {
29
36
} ) ,
30
37
hasTicketsInOrder :
computed ( '[email protected] ' , function ( ) {
31
38
return sumBy ( this . tickets . toArray ( ) ,
32
- ticket => ticket . getWithDefault ( ' orderQuantity' , 0 )
39
+ ticket => ( ticket . orderQuantity || 0 )
33
40
) > 0 ;
34
41
} ) ,
35
42
36
43
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
+ }
37
49
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 )
39
51
) ;
40
52
} ) ,
41
53
actions : {
@@ -57,6 +69,15 @@ export default Component.extend(FormMixin, {
57
69
this . tickets . removeObject ( ticket ) ;
58
70
} ) ;
59
71
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
+ }
60
81
ticket . set ( 'discount' , 0 ) ;
61
82
} ) ;
62
83
this . accessCodeTickets . clear ( ) ;
@@ -94,13 +115,17 @@ export default Component.extend(FormMixin, {
94
115
let tickets = await discountCode . get ( 'tickets' ) ;
95
116
tickets . forEach ( ticket => {
96
117
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 ) ;
103
127
}
128
+ this . discountedTickets . addObject ( ticket ) ;
104
129
this . set ( 'invalidPromotionalCode' , false ) ;
105
130
} ) ;
106
131
} else {
0 commit comments