taxtank-core 2.1.40 → 2.1.41

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.
@@ -25136,7 +25136,7 @@ class SoleInvoiceItemForm extends AbstractForm {
25136
25136
  * a common invoice data and sole invoice items.
25137
25137
  */
25138
25138
  class SoleInvoiceForm extends AbstractForm {
25139
- constructor(invoice, soleDetailsGST,
25139
+ constructor(invoice, gst,
25140
25140
  // default template to be preselected
25141
25141
  defaultTemplate) {
25142
25142
  super({
@@ -25155,7 +25155,7 @@ class SoleInvoiceForm extends AbstractForm {
25155
25155
  .map((item) => new SoleInvoiceItemForm(item))),
25156
25156
  }, invoice);
25157
25157
  this.invoice = invoice;
25158
- this.soleDetailsGST = soleDetailsGST;
25158
+ this.gst = gst;
25159
25159
  this.defaultTemplate = defaultTemplate;
25160
25160
  // we need invoice template only for new invoices
25161
25161
  if (!invoice.id) {
@@ -25167,12 +25167,12 @@ class SoleInvoiceForm extends AbstractForm {
25167
25167
  }
25168
25168
  }
25169
25169
  // set tax exclusive by default if user is registered for gst
25170
- if (this.soleDetailsGST) {
25170
+ if (this.gst) {
25171
25171
  this.commonData.get('taxType').setValue(SoleInvoiceTaxTypeEnum.TAX_EXCLUSIVE);
25172
25172
  }
25173
25173
  }
25174
25174
  // invoice.taxType is always NONE ('No Tax') when soleDetails.isGST === false
25175
- if (!this.soleDetailsGST) {
25175
+ if (!this.gst) {
25176
25176
  this.commonData.get('taxType').setValue(SoleInvoiceTaxTypeEnum.NO_TAX);
25177
25177
  this.commonData.get('taxType').disable();
25178
25178
  // Items isGST is not available when invoice.taxType === NONE ('No Tax')
@@ -25188,7 +25188,7 @@ class SoleInvoiceForm extends AbstractForm {
25188
25188
  listenEvents() {
25189
25189
  // no need to listen tax type and items chart accounts changes when soleDetails.isGST === false
25190
25190
  // because invoice tax type always 'No Tax' in this case and not available for changing
25191
- if (this.soleDetailsGST) {
25191
+ if (this.gst) {
25192
25192
  this.listenTaxTypeChanges();
25193
25193
  this.items.controls.forEach((itemForm) => {
25194
25194
  this.listenItemChartAccountsChanges(itemForm);
@@ -25203,7 +25203,7 @@ class SoleInvoiceForm extends AbstractForm {
25203
25203
  const itemForm = new SoleInvoiceItemForm(plainToClass(SoleInvoiceItem, {}));
25204
25204
  // no need to listen items chart accounts changes when soleDetails.isGST === false
25205
25205
  // because invoice tax type always 'No Tax' in this case and not available for changing
25206
- if (this.soleDetailsGST) {
25206
+ if (this.gst) {
25207
25207
  this.listenItemChartAccountsChanges(itemForm);
25208
25208
  }
25209
25209
  this.items.push(itemForm);
@@ -25245,7 +25245,7 @@ class SoleInvoiceForm extends AbstractForm {
25245
25245
  this.commonData.get('dateTo').setValue(new Date(dateFrom.getTime() + template.termTime));
25246
25246
  }
25247
25247
  // invoice.taxType is always 'No Tax' when soleDetails.isGST = false and not available for changing
25248
- if (this.soleDetailsGST) {
25248
+ if (this.gst) {
25249
25249
  this.commonData.get('taxType').setValue(template.taxType);
25250
25250
  }
25251
25251
  }
@@ -25255,7 +25255,7 @@ class SoleInvoiceForm extends AbstractForm {
25255
25255
  listenItemChartAccountsChanges(itemForm) {
25256
25256
  itemForm.get('chartAccounts').valueChanges.subscribe((chartAccounts) => {
25257
25257
  // item.isGST is available only when item.chartAccounts.isGST === true, soleDetails.isGST === true and invoice.taxType !== NONE ('No Tax')
25258
- if (this.soleDetailsGST && chartAccounts.isGST && !this.currentValue.isNoTax()) {
25258
+ if (this.gst && chartAccounts.isGST && !this.currentValue.isNoTax()) {
25259
25259
  this.enableItemGST(itemForm);
25260
25260
  return;
25261
25261
  }
@@ -26853,14 +26853,14 @@ class AllocationRuleTransactionMetaFieldForm extends AbstractForm {
26853
26853
  class AllocationRuleTransactionForm extends AbstractForm {
26854
26854
  constructor(transaction,
26855
26855
  // Flag to enable transaction GST field
26856
- isGST) {
26856
+ soleDetails) {
26857
26857
  super({
26858
26858
  amount: new UntypedFormControl(transaction.amount),
26859
26859
  amountPercent: new UntypedFormControl(transaction.amountPercent, Validators.required),
26860
26860
  tax: new UntypedFormControl(transaction.tax, Validators.required),
26861
26861
  claimPercent: new UntypedFormControl(transaction.claimPercent, [Validators.required, Validators.min(0), Validators.max(100)]),
26862
26862
  chartAccounts: new UntypedFormControl(transaction.chartAccounts, Validators.required),
26863
- isGST: new UntypedFormControl({ value: transaction.isGST || false, disabled: !isGST }),
26863
+ isGST: new UntypedFormControl({ value: transaction.isGST || false, disabled: transaction.business?.getIsGST(soleDetails) }),
26864
26864
  loan: new UntypedFormControl(transaction.loan),
26865
26865
  incomeSource: new UntypedFormControl(transaction.incomeSource, conditionalValidator(() => transaction.chartAccounts?.isWorkIncome(), Validators.required)),
26866
26866
  metaFields: new UntypedFormArray((transaction.metaFields || []).map((metaField) => new AllocationRuleTransactionMetaFieldForm(metaField))),
@@ -26873,7 +26873,7 @@ class AllocationRuleTransactionForm extends AbstractForm {
26873
26873
  amount: new UntypedFormControl(childTransaction.amount, Validators.required)
26874
26874
  })))
26875
26875
  }, transaction);
26876
- this.isGST = isGST;
26876
+ this.soleDetails = soleDetails;
26877
26877
  this.includeDisabledFields = true;
26878
26878
  this.listenEvents();
26879
26879
  }
@@ -26910,10 +26910,16 @@ class AllocationRuleTransactionForm extends AbstractForm {
26910
26910
  }
26911
26911
  listenEvents() {
26912
26912
  this.listenChartAccountsChanges();
26913
+ this.watchBusiness();
26913
26914
  this.listenTankTypeChanges();
26914
26915
  this.listenIncomeSourceChanges();
26915
26916
  this.listenPropertyChanges();
26916
26917
  }
26918
+ watchBusiness() {
26919
+ this.get('business').valueChanges.subscribe((business) => {
26920
+ this.updateGst(business, this.value.chartAccounts);
26921
+ });
26922
+ }
26917
26923
  listenChartAccountsChanges() {
26918
26924
  this.get('chartAccounts').valueChanges.subscribe((chartAccounts) => {
26919
26925
  this.get('incomeSource').removeValidators(Validators.required);
@@ -26930,17 +26936,20 @@ class AllocationRuleTransactionForm extends AbstractForm {
26930
26936
  chartAccounts.metaFields.forEach((chartAccountsMetaField) => {
26931
26937
  this.metaFieldsArray.push(new AllocationRuleTransactionMetaFieldForm(plainToClass(AllocationRuleTransactionMetaField, { chartAccountsMetaField })));
26932
26938
  });
26933
- // sole trader registered and chartAccounts is eligible for gst
26934
- if (this.isGST && chartAccounts.isGST) {
26935
- this.get('isGST').enable();
26936
- this.get('isGST').setValue(true);
26937
- }
26938
- else {
26939
- this.get('isGST').disable();
26940
- this.get('isGST').setValue(false);
26941
- }
26939
+ this.updateGst(this.value.business, chartAccounts);
26942
26940
  });
26943
26941
  }
26942
+ updateGst(business, chartAccounts) {
26943
+ // update gst if applicable
26944
+ if (business?.getIsGST(this.soleDetails) && chartAccounts.isGST) {
26945
+ this.get('isGST').enable();
26946
+ this.get('isGST').patchValue(true);
26947
+ }
26948
+ else {
26949
+ this.get('isGST').patchValue(false);
26950
+ this.get('isGST').disable();
26951
+ }
26952
+ }
26944
26953
  /**
26945
26954
  * Child transaction allowance depends on tank type.
26946
26955
  * Also chart accounts are different, so we just reset child transactions when tank type changed
@@ -26995,7 +27004,7 @@ class AllocationRuleTransactionForm extends AbstractForm {
26995
27004
  * @TODO move aux methods like isSplittable/isTaxFieldHidden/etc (used in view with ngIf) to properties to improve perf
26996
27005
  */
26997
27006
  class AllocationRuleForm extends AbstractForm {
26998
- constructor(rule, rules, isGST) {
27007
+ constructor(rule, rules, soleDetails) {
26999
27008
  super({
27000
27009
  type: new FormControl(rule.type, Validators.required),
27001
27010
  name: new FormControl(rule.name, [
@@ -27005,11 +27014,11 @@ class AllocationRuleForm extends AbstractForm {
27005
27014
  conditionOperator: new FormControl(rule.conditionOperator, Validators.required),
27006
27015
  conditions: new FormArray((rule.conditions || [plainToClass(AllocationRuleCondition, {})])
27007
27016
  .map((condition) => new AllocationRuleConditionForm(condition))),
27008
- transaction: new AllocationRuleTransactionForm(rule.transaction || plainToClass(AllocationRuleTransaction, {}), isGST),
27017
+ transaction: new AllocationRuleTransactionForm(rule.transaction || plainToClass(AllocationRuleTransaction, {}), soleDetails),
27009
27018
  transferBankAccount: new FormControl(rule.transferBankAccount, Validators.required),
27010
27019
  autoAllocate: new FormControl(rule.autoAllocate || false, Validators.required),
27011
27020
  }, rule);
27012
- this.isGST = isGST;
27021
+ this.soleDetails = soleDetails;
27013
27022
  this.listenEvents();
27014
27023
  this.setupFieldsByType(rule.type);
27015
27024
  this.setupFieldsByTankType(rule.transaction?.tankType);
@@ -27067,7 +27076,7 @@ class AllocationRuleForm extends AbstractForm {
27067
27076
  this.updateChartAccountsCategories();
27068
27077
  // we have different fields for different types
27069
27078
  // @TODO separated reinit method if we need it anywhere else
27070
- this.transactionFormGroup.setValue(new AllocationRuleTransactionForm(plainToClass(AllocationRuleTransaction, {}), this.isGST).getRawValue());
27079
+ this.transactionFormGroup.setValue(new AllocationRuleTransactionForm(plainToClass(AllocationRuleTransaction, {}), this.soleDetails).getRawValue());
27071
27080
  });
27072
27081
  }
27073
27082
  listenTankTypeChanges() {