taxtank-core 2.0.12 → 2.0.13

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.
@@ -4652,6 +4652,15 @@ var ServicePromoCodeDurationEnum;
4652
4652
  })(ServicePromoCodeDurationEnum || (ServicePromoCodeDurationEnum = {}));
4653
4653
 
4654
4654
  class ServicePromoCode extends AbstractModel {
4655
+ getProductsIds() {
4656
+ return this.products.map(product => product.id);
4657
+ }
4658
+ hasProduct(product) {
4659
+ return this.products.length ? this.getProductsIds().includes(product.id) : true;
4660
+ }
4661
+ isProductPercentOff(product) {
4662
+ return !!(this.hasProduct(product) && this.percentOff);
4663
+ }
4655
4664
  isDurationForever() {
4656
4665
  return this.duration === ServicePromoCodeDurationEnum.FOREVER;
4657
4666
  }
@@ -4678,6 +4687,9 @@ class ServicePromoCode extends AbstractModel {
4678
4687
  return label;
4679
4688
  }
4680
4689
  }
4690
+ __decorate([
4691
+ Type(() => ServiceProduct)
4692
+ ], ServicePromoCode.prototype, "products", void 0);
4681
4693
 
4682
4694
  class ServiceSubscription extends ServiceSubscription$1 {
4683
4695
  constructor() {
@@ -4700,20 +4712,20 @@ class ServiceSubscription extends ServiceSubscription$1 {
4700
4712
  return this.items.reduce((sum, item) => sum + item.total, 0);
4701
4713
  }
4702
4714
  get discountAmount() {
4703
- return this.initialPrice - this.price;
4715
+ if (!this.promoCode) {
4716
+ return 0;
4717
+ }
4718
+ const discountApplicable = this.items
4719
+ .map(item => item.price)
4720
+ .filter(price => this.promoCode.getProductsIds().includes(price.product.id))
4721
+ .reduce((sum, price) => sum + price.amount, 0) || this.initialPrice;
4722
+ if (this.promoCode.amountOff) {
4723
+ return Math.min(discountApplicable, this.promoCode.amountOff);
4724
+ }
4725
+ return discountApplicable * (this.promoCode.percentOff / 100);
4704
4726
  }
4705
4727
  get price() {
4706
- let price = this.items.reduce((sum, item) => sum + item.total, 0);
4707
- if (this.promoCode) {
4708
- if (this.promoCode.amountOff) {
4709
- price = price - this.promoCode.amountOff;
4710
- }
4711
- else {
4712
- price = price - price * (this.promoCode.percentOff / 100);
4713
- }
4714
- }
4715
- // promo code can't make price < 0
4716
- return price > 0 ? price : 0;
4728
+ return this.initialPrice - this.discountAmount;
4717
4729
  }
4718
4730
  /**
4719
4731
  * get title of subscription
@@ -22521,7 +22533,8 @@ var FormValidationsEnum;
22521
22533
  class DocumentFolderForm extends AbstractForm {
22522
22534
  constructor(folder) {
22523
22535
  super({
22524
- name: new UntypedFormControl(folder.name, [Validators.required, Validators.maxLength(FormValidationsEnum.INPUT_MAX_LENGTH)])
22536
+ name: new FormControl(folder.name, [Validators.required, Validators.maxLength(FormValidationsEnum.INPUT_MAX_LENGTH)]),
22537
+ parent: new FormControl({ value: folder.parent, disabled: true }),
22525
22538
  }, folder);
22526
22539
  }
22527
22540
  }
@@ -22529,7 +22542,7 @@ class DocumentFolderForm extends AbstractForm {
22529
22542
  class DocumentForm extends AbstractForm {
22530
22543
  constructor(document) {
22531
22544
  super({
22532
- folder: new FormControl(document.folder, Validators.required),
22545
+ folder: new FormControl({ value: document.folder, disabled: true }, Validators.required),
22533
22546
  file: new FormControl(document.file, Validators.required),
22534
22547
  }, document);
22535
22548
  }