@sellout/models 0.0.108 → 0.0.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sellout/models",
3
- "version": "0.0.108",
3
+ "version": "0.0.109",
4
4
  "description": "Sellout.io models",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,8 +17,8 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "@hapi/joi": "^16.1.7",
20
- "@sellout/service": "^0.0.108",
21
- "@sellout/utils": "^0.0.108",
20
+ "@sellout/service": "^0.0.109",
21
+ "@sellout/utils": "^0.0.109",
22
22
  "@types/hapi__joi": "^16.0.1",
23
23
  "@types/shortid": "^0.0.29",
24
24
  "apollo-link-debounce": "^2.1.0",
@@ -32,5 +32,5 @@
32
32
  "protobufjs": "^6.11.2",
33
33
  "typescript": "^4.4.2"
34
34
  },
35
- "gitHead": "f64d10d501ae0ff62171846f9c4ce5b83b5bba52"
35
+ "gitHead": "314575a9bae7a664a22b810532633cd53920a78b"
36
36
  }
@@ -20,6 +20,7 @@ const mutation = gql`
20
20
  address {
21
21
  state
22
22
  city
23
+ timezone
23
24
  }
24
25
  }
25
26
  organization {
@@ -20,6 +20,7 @@ const mutation = gql`
20
20
  age
21
21
  sendQRCode
22
22
  hasOrders
23
+ taxDeduction
23
24
  organization {
24
25
  orgName
25
26
  }
@@ -20,9 +20,9 @@ const mutation = gql`
20
20
  lng
21
21
  placeId
22
22
  placeName
23
- timezone
24
23
  }
25
24
  url
25
+ tax
26
26
  imageUrls
27
27
  venueGlobalId
28
28
  }
@@ -43,6 +43,7 @@ const mutation = gql`
43
43
  imageUrls
44
44
  }
45
45
  published
46
+ taxDeduction
46
47
  salesBeginImmediately
47
48
  ...EventSchedule
48
49
  ...Location
@@ -33,6 +33,7 @@ const mutation = gql`
33
33
  imageUrls
34
34
  }
35
35
  published
36
+ taxDeduction
36
37
  salesBeginImmediately
37
38
  ...EventSchedule
38
39
  ...Location
@@ -20,9 +20,9 @@ const mutation = gql`
20
20
  lng
21
21
  placeId
22
22
  placeName
23
- timezone
24
23
  }
25
24
  url
25
+ tax
26
26
  imageUrls
27
27
  venueGlobalId
28
28
  }
@@ -30,9 +30,11 @@ const query = gql`
30
30
  address {
31
31
  state
32
32
  city
33
+ timezone
33
34
  }
34
35
  imageUrls
35
36
  }
37
+ taxDeduction
36
38
  published
37
39
  salesBeginImmediately
38
40
  ...EventSchedule
@@ -30,10 +30,12 @@ const query = gql`
30
30
  address {
31
31
  state
32
32
  city
33
+ timezone
33
34
  }
34
35
  imageUrls
35
36
  }
36
37
  published
38
+ taxDeduction
37
39
  salesBeginImmediately
38
40
  ...EventSchedule
39
41
  ...Location
@@ -39,6 +39,7 @@ const query = gql`
39
39
  address {
40
40
  state
41
41
  city
42
+ timezone
42
43
  }
43
44
  }
44
45
  }
@@ -83,6 +84,7 @@ const query = gql`
83
84
  refundReason
84
85
  promotionCode
85
86
  type
87
+ tax
86
88
  channel
87
89
  ipAddress
88
90
  address {
@@ -14,21 +14,23 @@ const query = gql`
14
14
  }
15
15
  orgId
16
16
  eventId
17
- eventName
18
- # event {
19
- # _id
20
- # posterImageUrl
21
- # schedule {
22
- # startsAt
23
- # }
24
- # venue {
25
- # name
26
- # address {
27
- # state
28
- # city
29
- # }
30
- # }
31
- # }
17
+ venueIds
18
+ eventName
19
+ event {
20
+ _id
21
+ posterImageUrl
22
+ schedule {
23
+ startsAt
24
+ }
25
+ venue {
26
+ _id
27
+ address {
28
+ state
29
+ city
30
+ timezone
31
+ }
32
+ }
33
+ }
32
34
  fees {
33
35
  _id
34
36
  name
@@ -54,6 +56,7 @@ const query = gql`
54
56
  promotionCode
55
57
  type
56
58
  channel
59
+ tax
57
60
  ipAddress
58
61
  address {
59
62
  lat
@@ -33,10 +33,12 @@ const query = gql`
33
33
  address {
34
34
  state
35
35
  city
36
+ timezone
36
37
  }
37
38
  imageUrls
38
39
  }
39
40
  published
41
+ taxDeduction
40
42
  salesBeginImmediately
41
43
  ...EventSchedule
42
44
  ...Location
@@ -22,6 +22,7 @@ const query = gql`
22
22
  placeName
23
23
  timezone
24
24
  }
25
+ tax
25
26
  url
26
27
  imageUrls
27
28
  venueGlobalId
@@ -24,6 +24,7 @@ const query = gql`
24
24
  timezone
25
25
  }
26
26
  url
27
+ tax
27
28
  imageUrls
28
29
  venueGlobalId
29
30
  }
@@ -38,6 +38,10 @@ export enum EventAgeEnum {
38
38
  TwentyOnePlus = '21+',
39
39
  }
40
40
 
41
+ export enum EventTaxDeductionEnum {
42
+ false = 'No',
43
+ true = 'Yes',
44
+ }
41
45
  export enum SendQRCodeEnum {
42
46
  UponOrder = 'Upon order',
43
47
  TwoWeeksBefore = 'Two weeks before show',
@@ -50,6 +54,10 @@ export enum EventProcessAsEnum {
50
54
  // Free = 'Free',
51
55
  }
52
56
 
57
+ export enum EventSaleTaxEnum {
58
+ SalesTax="Sales tax"
59
+ }
60
+
53
61
  export default interface IEvent {
54
62
  _id?: string;
55
63
  orgId: string;
@@ -63,6 +71,7 @@ export default interface IEvent {
63
71
  publishable: boolean;
64
72
  seatingChartKey?: string;
65
73
  age?: EventAgeEnum;
74
+ taxDeduction?: boolean;
66
75
  active?: boolean;
67
76
  userAgreement?: string;
68
77
  processAs?: EventProcessAsEnum;
@@ -9,6 +9,8 @@ import { OrderChannelEnum } from '../enums/OrderChannelEnum';
9
9
  import IProcessingFee from './IProcessingFees';
10
10
  import IUser from "./IUser";
11
11
  import IFee from "./IFee";
12
+ import IEvent from "./IEvent";
13
+ import IVenue from "./IVenue";
12
14
 
13
15
  export default interface IOrder {
14
16
  _id?: string;
@@ -34,14 +36,19 @@ export default interface IOrder {
34
36
  promotionCode?: string;
35
37
  ipAddress?: string;
36
38
  address?: IAddress;
39
+ tax?: number;
37
40
  customFields?: IOrderCustomField[];
38
41
  refundReason?: string; // BACKFILL
39
42
  payments: IPayment[];
40
43
  processingFee?: IProcessingFee
41
44
  };
42
45
 
46
+ export interface IEventGraphQL extends IEvent {
47
+ venue?: IVenue;
48
+ }
43
49
 
44
50
  export interface IOrderGraphQL extends IOrder {
45
51
  user: IUser;
46
52
  fees: IFee;
53
+ event: IEventGraphQL;
47
54
  };
@@ -7,6 +7,7 @@ export default interface IPayment {
7
7
  transferAmount: number;
8
8
  feeAmount: number;
9
9
  feeIds: string[];
10
+ tax?: number;
10
11
  createdAt: number;
11
12
  createdBy: string;
12
13
  promotionCode?: string;
@@ -6,6 +6,7 @@ export default interface IVenue {
6
6
  name: string;
7
7
  description: string;
8
8
  capacity: number;
9
+ tax?: string;
9
10
  url?: string;
10
11
  imageUrls?: string[];
11
12
  venueGlobalId?: string;
@@ -33,6 +33,7 @@ message Event {
33
33
  bool published = 27;
34
34
  bool salesBeginImmediately = 28;
35
35
  bool cancel = 29;
36
+ bool taxDeduction = 30;
36
37
  }
37
38
 
38
39
  message EventSchedule {
@@ -34,6 +34,7 @@ message Order {
34
34
  string refundReason = 23;
35
35
  repeated Payment payments = 24;
36
36
  ProcessingFees processingFee = 25;
37
+ float tax = 26;
37
38
  }
38
39
 
39
40
  message ProcessingFees {
@@ -102,6 +103,7 @@ message Payment {
102
103
  string createdBy = 7;
103
104
  string promotionCode = 8;
104
105
  string paymentMethodType = 9;
106
+ int32 tax = 10;
105
107
  }
106
108
 
107
109
  /****************************************************************************************
@@ -14,6 +14,7 @@ message Venue {
14
14
  repeated string imageUrls = 6;
15
15
  string venueGlobalId = 7;
16
16
  Address address = 8;
17
+ float tax = 9;
17
18
  }
18
19
 
19
20
  // Create Venue
@@ -451,6 +451,11 @@ export default {
451
451
  required: true,
452
452
  default: false
453
453
  },
454
+ taxDeduction: {
455
+ type: Boolean,
456
+ required: true,
457
+ default: false
458
+ },
454
459
  userAgreement: {
455
460
  type: String,
456
461
  required: false
@@ -180,6 +180,10 @@ const Payment = {
180
180
  type: Number,
181
181
  required: false,
182
182
  },
183
+ tax: {
184
+ type: Number,
185
+ required: false,
186
+ },
183
187
  feeIds: [{
184
188
  type: String,
185
189
  required: false,
@@ -229,6 +233,10 @@ export default {
229
233
  type: String,
230
234
  required: true,
231
235
  },
236
+ tax: {
237
+ type: Number,
238
+ default: null,
239
+ },
232
240
  venueIds: [{
233
241
  type: String,
234
242
  required: false,
@@ -26,6 +26,10 @@ export default {
26
26
  type: String,
27
27
  default: null,
28
28
  },
29
+ tax: {
30
+ type: Number,
31
+ default: null,
32
+ },
29
33
  imageUrls: [
30
34
  {
31
35
  type: String,
@@ -879,20 +879,20 @@ export default {
879
879
  return intervals[interval]();
880
880
  },
881
881
 
882
- getDateFormat(time: any, interval: AnalyticsIntervalEnum) {
882
+ getDateFormat(time: any, interval: AnalyticsIntervalEnum, timezone: string = 'America/Denver') {
883
883
  switch(interval) {
884
884
  case AnalyticsIntervalEnum.Hour:
885
- return Time.format(time, 'h:mma');
885
+ return Time.format(time, 'h:mma',timezone);
886
886
  case AnalyticsIntervalEnum.Day:
887
- return Time.format(time, 'MMM DD');
887
+ return Time.format(time, 'MMM DD',timezone);
888
888
  case AnalyticsIntervalEnum.Week:
889
- return `${Time.format(time, 'MMM DD')} - ${Time.format(time + (Time.DAY * 7), 'MMM DD')}`;
889
+ return `${Time.format(time, 'MMM DD',timezone)} - ${Time.format(time + (Time.DAY * 7), 'MMM DD',timezone)}`;
890
890
  case AnalyticsIntervalEnum.Month:
891
- return Time.format(time, 'MMM YYYY');
891
+ return Time.format(time, 'MMM YYYY',timezone);
892
892
  case AnalyticsIntervalEnum.Year:
893
- return Time.format(time, 'YYYY');
893
+ return Time.format(time, 'YYYY',timezone);
894
894
  default:
895
- return Time.format(time, 'MMM DD');
895
+ return Time.format(time, 'MMM DD',timezone);
896
896
  }
897
897
  },
898
898
 
@@ -34,6 +34,15 @@ export default {
34
34
  return true;
35
35
  });
36
36
  },
37
+
38
+ taxFees(fees: any[] = []) {
39
+ return fees.filter((fee) => {
40
+ if (fee.name.toLowerCase() === 'sales tax') {
41
+ return true;
42
+ }
43
+ return false;
44
+ });
45
+ },
37
46
  /****************************************************************************************
38
47
  * Fee validate
39
48
  ****************************************************************************************/
@@ -165,11 +165,11 @@ class PaymentUtil {
165
165
  })
166
166
  const upgradeFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Upgrade);
167
167
  // Orders mattes here. Flat type fees must be applied before Percent type fees
168
- const orderFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Order).sort(({ type }) => {
168
+ const orderFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Order && f.name != 'Sales tax').sort(({ type }) => {
169
169
  if (type === 'Flat') return -1;
170
170
  else return 1;
171
171
  });
172
-
172
+ const salesTax = fees.filter(f => f.name == 'Sales tax');
173
173
 
174
174
  function applyTicketFee(ticket: ICreateOrderTicketParams, fee: IFee): number {
175
175
  // Ignore seated fees if not seated
@@ -201,7 +201,7 @@ class PaymentUtil {
201
201
  if (fee.type === FeeTypeEnum.Flat) {
202
202
  return upgrade.price + fee.value;
203
203
  } if (fee.type === FeeTypeEnum.Percent) {
204
- return (upgrade.price / (1 - fee.value / 100));
204
+ return (upgrade.price * fee.value / 100);
205
205
  }
206
206
  } else {
207
207
  return 0;
@@ -220,21 +220,29 @@ class PaymentUtil {
220
220
 
221
221
  const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0);
222
222
 
223
+ const ticketTaxFeeTotal = tickets.reduce((cur, ticket) => {
224
+ return cur + salesTax.reduce((cur, fee) => {
225
+ const value = cur + applyTicketFee(ticket, fee);
226
+ return value;
227
+ }, 0);
228
+ }, 0);
223
229
  const ticketFeeTotal = tickets.reduce((cur, ticket) => {
224
230
  return cur + ticketFees.reduce((cur, fee) => {
225
231
  const value = cur + applyTicketFee(ticket, fee);
226
- // console.log(`${fee.name}: ${value}`);
227
232
  return value;
228
233
  }, 0);
229
234
  }, 0);
230
235
 
231
236
  const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0);
232
237
 
238
+ const upgradeTaxFeeTotal = upgrades.reduce((cur, upgrade) => {
239
+ return cur + salesTax.reduce((curr, fee) => curr + applyUpgradeFee(upgrade, fee), 0);
240
+ }, 0);
241
+
233
242
  const upgradeFeeTotal = upgrades.reduce((cur, upgrade) => {
234
243
  return cur + upgradeFees.reduce((cur, fee) => cur + applyUpgradeFee(upgrade, fee), 0);
235
244
  }, 0);
236
-
237
- const orderSubtotal = Math.round(ticketTotal + ticketFeeTotal + upgradeTotal + upgradeFeeTotal);
245
+ const orderSubtotal = Math.round(ticketTotal + ticketTaxFeeTotal + ticketFeeTotal + upgradeTaxFeeTotal + upgradeTotal + upgradeFeeTotal);
238
246
 
239
247
  // console.log(`Order SubTotal:`, orderSubtotal);
240
248
 
@@ -251,16 +259,31 @@ class PaymentUtil {
251
259
  tickets = [],
252
260
  upgrades = [],
253
261
  paymentMethodType,
262
+ // fees
254
263
  } = params;
255
264
 
256
265
  if(paymentMethodType === PaymentMethodTypeEnum.None) return 0;
257
- const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0);
258
- const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0);
266
+
267
+ const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price , 0); // + (ticket.price * tax/100)
268
+ const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0); // + (upgrade.price * tax/100)
259
269
  return ticketTotal + upgradeTotal;
260
270
  }
261
271
  calculateFee(params: IPaymentCalculatorParams): number {
272
+ let {
273
+ fees
274
+ } = params;
275
+ const salesTax = fees.filter(f => f.name == 'Sales tax');
276
+ const tax = salesTax.length > 0 ? salesTax[0].value : 0
262
277
  const total = this.calculatePaymentTotal(params);
263
- const subtotal = this.calculatePaymentSubtotal(params);
278
+ let subtotal = this.calculatePaymentSubtotal(params);
279
+ subtotal = subtotal + (subtotal*tax/100)
280
+ return Math.round(total - subtotal);
281
+ }
282
+
283
+ calculateFeeWithoutTax(params: IPaymentCalculatorParams): number {
284
+
285
+ const total = this.calculatePaymentTotal(params);
286
+ let subtotal = this.calculatePaymentSubtotal(params);
264
287
  return Math.round(total - subtotal);
265
288
  }
266
289
  calculateOrganizationFee(params: IPaymentCalculatorParams): number {
@@ -272,7 +295,6 @@ class PaymentUtil {
272
295
  } = params;
273
296
 
274
297
  fees = FeeUtil.promoterFees(fees);
275
-
276
298
  return this.calculateFee({
277
299
  tickets,
278
300
  upgrades,
@@ -280,6 +302,24 @@ class PaymentUtil {
280
302
  paymentMethodType,
281
303
  });
282
304
  }
305
+
306
+
307
+ calculateTaxFee(params: IPaymentCalculatorParams): number {
308
+ let {
309
+ tickets = [],
310
+ upgrades = [],
311
+ fees = [],
312
+ paymentMethodType,
313
+ } = params;
314
+
315
+ fees = FeeUtil.taxFees(fees);
316
+ return this.calculateFeeWithoutTax({
317
+ tickets,
318
+ upgrades,
319
+ fees,
320
+ paymentMethodType,
321
+ });
322
+ }
283
323
  calculatePlatformFee(params: IPaymentCalculatorParams): number {
284
324
  let {
285
325
  tickets = [],
@@ -310,6 +350,11 @@ class PaymentUtil {
310
350
  const organizationFee = this.calculateOrganizationFee(params);
311
351
  return total - subtotal - organizationFee;
312
352
  }
353
+ // calculateTaxFee(params: IPaymentCalculatorParams): number {
354
+ // const organizationFee = this.calculateTaxFee(params);
355
+ // console.log(organizationFee,'............................salesTax..')
356
+ // return organizationFee;
357
+ // }
313
358
 
314
359
  }
315
360