taxtank-core 2.1.39 → 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.
@@ -5632,6 +5632,12 @@ __decorate([
5632
5632
  __decorate([
5633
5633
  Type(() => BankAccount)
5634
5634
  ], SoleInvoice.prototype, "bankAccount", void 0);
5635
+ __decorate([
5636
+ Type(() => Date)
5637
+ ], SoleInvoice.prototype, "createdAt", void 0);
5638
+ __decorate([
5639
+ Type(() => Date)
5640
+ ], SoleInvoice.prototype, "updatedAt", void 0);
5635
5641
 
5636
5642
  class SoleInvoiceTemplate extends SoleInvoiceTemplate$1 {
5637
5643
  constructor() {
@@ -16787,7 +16793,7 @@ class SoleInvoiceService extends RestService$1 {
16787
16793
  return this.put(invoice, `${this.apiUrl}/${invoice.id}/send`);
16788
16794
  }
16789
16795
  download(invoice) {
16790
- return this.http.get(`${this.apiUrl}/${invoice.id}/download`, { responseType: 'blob' });
16796
+ return this.http.get(`${this.apiUrl}/${invoice.id}/download?v=${invoice.updatedAt.getTime()}`, { responseType: 'blob' });
16791
16797
  }
16792
16798
  /**
16793
16799
  * Return the next number from the last invoice
@@ -25130,7 +25136,7 @@ class SoleInvoiceItemForm extends AbstractForm {
25130
25136
  * a common invoice data and sole invoice items.
25131
25137
  */
25132
25138
  class SoleInvoiceForm extends AbstractForm {
25133
- constructor(invoice, soleDetailsGST,
25139
+ constructor(invoice, gst,
25134
25140
  // default template to be preselected
25135
25141
  defaultTemplate) {
25136
25142
  super({
@@ -25149,7 +25155,7 @@ class SoleInvoiceForm extends AbstractForm {
25149
25155
  .map((item) => new SoleInvoiceItemForm(item))),
25150
25156
  }, invoice);
25151
25157
  this.invoice = invoice;
25152
- this.soleDetailsGST = soleDetailsGST;
25158
+ this.gst = gst;
25153
25159
  this.defaultTemplate = defaultTemplate;
25154
25160
  // we need invoice template only for new invoices
25155
25161
  if (!invoice.id) {
@@ -25161,12 +25167,12 @@ class SoleInvoiceForm extends AbstractForm {
25161
25167
  }
25162
25168
  }
25163
25169
  // set tax exclusive by default if user is registered for gst
25164
- if (this.soleDetailsGST) {
25170
+ if (this.gst) {
25165
25171
  this.commonData.get('taxType').setValue(SoleInvoiceTaxTypeEnum.TAX_EXCLUSIVE);
25166
25172
  }
25167
25173
  }
25168
25174
  // invoice.taxType is always NONE ('No Tax') when soleDetails.isGST === false
25169
- if (!this.soleDetailsGST) {
25175
+ if (!this.gst) {
25170
25176
  this.commonData.get('taxType').setValue(SoleInvoiceTaxTypeEnum.NO_TAX);
25171
25177
  this.commonData.get('taxType').disable();
25172
25178
  // Items isGST is not available when invoice.taxType === NONE ('No Tax')
@@ -25182,7 +25188,7 @@ class SoleInvoiceForm extends AbstractForm {
25182
25188
  listenEvents() {
25183
25189
  // no need to listen tax type and items chart accounts changes when soleDetails.isGST === false
25184
25190
  // because invoice tax type always 'No Tax' in this case and not available for changing
25185
- if (this.soleDetailsGST) {
25191
+ if (this.gst) {
25186
25192
  this.listenTaxTypeChanges();
25187
25193
  this.items.controls.forEach((itemForm) => {
25188
25194
  this.listenItemChartAccountsChanges(itemForm);
@@ -25197,7 +25203,7 @@ class SoleInvoiceForm extends AbstractForm {
25197
25203
  const itemForm = new SoleInvoiceItemForm(plainToClass(SoleInvoiceItem, {}));
25198
25204
  // no need to listen items chart accounts changes when soleDetails.isGST === false
25199
25205
  // because invoice tax type always 'No Tax' in this case and not available for changing
25200
- if (this.soleDetailsGST) {
25206
+ if (this.gst) {
25201
25207
  this.listenItemChartAccountsChanges(itemForm);
25202
25208
  }
25203
25209
  this.items.push(itemForm);
@@ -25239,7 +25245,7 @@ class SoleInvoiceForm extends AbstractForm {
25239
25245
  this.commonData.get('dateTo').setValue(new Date(dateFrom.getTime() + template.termTime));
25240
25246
  }
25241
25247
  // invoice.taxType is always 'No Tax' when soleDetails.isGST = false and not available for changing
25242
- if (this.soleDetailsGST) {
25248
+ if (this.gst) {
25243
25249
  this.commonData.get('taxType').setValue(template.taxType);
25244
25250
  }
25245
25251
  }
@@ -25249,7 +25255,7 @@ class SoleInvoiceForm extends AbstractForm {
25249
25255
  listenItemChartAccountsChanges(itemForm) {
25250
25256
  itemForm.get('chartAccounts').valueChanges.subscribe((chartAccounts) => {
25251
25257
  // item.isGST is available only when item.chartAccounts.isGST === true, soleDetails.isGST === true and invoice.taxType !== NONE ('No Tax')
25252
- if (this.soleDetailsGST && chartAccounts.isGST && !this.currentValue.isNoTax()) {
25258
+ if (this.gst && chartAccounts.isGST && !this.currentValue.isNoTax()) {
25253
25259
  this.enableItemGST(itemForm);
25254
25260
  return;
25255
25261
  }
@@ -26847,14 +26853,14 @@ class AllocationRuleTransactionMetaFieldForm extends AbstractForm {
26847
26853
  class AllocationRuleTransactionForm extends AbstractForm {
26848
26854
  constructor(transaction,
26849
26855
  // Flag to enable transaction GST field
26850
- isGST) {
26856
+ soleDetails) {
26851
26857
  super({
26852
26858
  amount: new UntypedFormControl(transaction.amount),
26853
26859
  amountPercent: new UntypedFormControl(transaction.amountPercent, Validators.required),
26854
26860
  tax: new UntypedFormControl(transaction.tax, Validators.required),
26855
26861
  claimPercent: new UntypedFormControl(transaction.claimPercent, [Validators.required, Validators.min(0), Validators.max(100)]),
26856
26862
  chartAccounts: new UntypedFormControl(transaction.chartAccounts, Validators.required),
26857
- isGST: new UntypedFormControl({ value: transaction.isGST || false, disabled: !isGST }),
26863
+ isGST: new UntypedFormControl({ value: transaction.isGST || false, disabled: transaction.business?.getIsGST(soleDetails) }),
26858
26864
  loan: new UntypedFormControl(transaction.loan),
26859
26865
  incomeSource: new UntypedFormControl(transaction.incomeSource, conditionalValidator(() => transaction.chartAccounts?.isWorkIncome(), Validators.required)),
26860
26866
  metaFields: new UntypedFormArray((transaction.metaFields || []).map((metaField) => new AllocationRuleTransactionMetaFieldForm(metaField))),
@@ -26867,7 +26873,7 @@ class AllocationRuleTransactionForm extends AbstractForm {
26867
26873
  amount: new UntypedFormControl(childTransaction.amount, Validators.required)
26868
26874
  })))
26869
26875
  }, transaction);
26870
- this.isGST = isGST;
26876
+ this.soleDetails = soleDetails;
26871
26877
  this.includeDisabledFields = true;
26872
26878
  this.listenEvents();
26873
26879
  }
@@ -26904,10 +26910,16 @@ class AllocationRuleTransactionForm extends AbstractForm {
26904
26910
  }
26905
26911
  listenEvents() {
26906
26912
  this.listenChartAccountsChanges();
26913
+ this.watchBusiness();
26907
26914
  this.listenTankTypeChanges();
26908
26915
  this.listenIncomeSourceChanges();
26909
26916
  this.listenPropertyChanges();
26910
26917
  }
26918
+ watchBusiness() {
26919
+ this.get('business').valueChanges.subscribe((business) => {
26920
+ this.updateGst(business, this.value.chartAccounts);
26921
+ });
26922
+ }
26911
26923
  listenChartAccountsChanges() {
26912
26924
  this.get('chartAccounts').valueChanges.subscribe((chartAccounts) => {
26913
26925
  this.get('incomeSource').removeValidators(Validators.required);
@@ -26924,17 +26936,20 @@ class AllocationRuleTransactionForm extends AbstractForm {
26924
26936
  chartAccounts.metaFields.forEach((chartAccountsMetaField) => {
26925
26937
  this.metaFieldsArray.push(new AllocationRuleTransactionMetaFieldForm(plainToClass(AllocationRuleTransactionMetaField, { chartAccountsMetaField })));
26926
26938
  });
26927
- // sole trader registered and chartAccounts is eligible for gst
26928
- if (this.isGST && chartAccounts.isGST) {
26929
- this.get('isGST').enable();
26930
- this.get('isGST').setValue(true);
26931
- }
26932
- else {
26933
- this.get('isGST').disable();
26934
- this.get('isGST').setValue(false);
26935
- }
26939
+ this.updateGst(this.value.business, chartAccounts);
26936
26940
  });
26937
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
+ }
26938
26953
  /**
26939
26954
  * Child transaction allowance depends on tank type.
26940
26955
  * Also chart accounts are different, so we just reset child transactions when tank type changed
@@ -26989,7 +27004,7 @@ class AllocationRuleTransactionForm extends AbstractForm {
26989
27004
  * @TODO move aux methods like isSplittable/isTaxFieldHidden/etc (used in view with ngIf) to properties to improve perf
26990
27005
  */
26991
27006
  class AllocationRuleForm extends AbstractForm {
26992
- constructor(rule, rules, isGST) {
27007
+ constructor(rule, rules, soleDetails) {
26993
27008
  super({
26994
27009
  type: new FormControl(rule.type, Validators.required),
26995
27010
  name: new FormControl(rule.name, [
@@ -26999,11 +27014,11 @@ class AllocationRuleForm extends AbstractForm {
26999
27014
  conditionOperator: new FormControl(rule.conditionOperator, Validators.required),
27000
27015
  conditions: new FormArray((rule.conditions || [plainToClass(AllocationRuleCondition, {})])
27001
27016
  .map((condition) => new AllocationRuleConditionForm(condition))),
27002
- transaction: new AllocationRuleTransactionForm(rule.transaction || plainToClass(AllocationRuleTransaction, {}), isGST),
27017
+ transaction: new AllocationRuleTransactionForm(rule.transaction || plainToClass(AllocationRuleTransaction, {}), soleDetails),
27003
27018
  transferBankAccount: new FormControl(rule.transferBankAccount, Validators.required),
27004
27019
  autoAllocate: new FormControl(rule.autoAllocate || false, Validators.required),
27005
27020
  }, rule);
27006
- this.isGST = isGST;
27021
+ this.soleDetails = soleDetails;
27007
27022
  this.listenEvents();
27008
27023
  this.setupFieldsByType(rule.type);
27009
27024
  this.setupFieldsByTankType(rule.transaction?.tankType);
@@ -27061,7 +27076,7 @@ class AllocationRuleForm extends AbstractForm {
27061
27076
  this.updateChartAccountsCategories();
27062
27077
  // we have different fields for different types
27063
27078
  // @TODO separated reinit method if we need it anywhere else
27064
- this.transactionFormGroup.setValue(new AllocationRuleTransactionForm(plainToClass(AllocationRuleTransaction, {}), this.isGST).getRawValue());
27079
+ this.transactionFormGroup.setValue(new AllocationRuleTransactionForm(plainToClass(AllocationRuleTransaction, {}), this.soleDetails).getRawValue());
27065
27080
  });
27066
27081
  }
27067
27082
  listenTankTypeChanges() {