taxtank-core 0.28.113 → 0.28.115

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.
@@ -1787,8 +1787,9 @@
1787
1787
  /**
1788
1788
  * Get total sum of items by field
1789
1789
  */
1790
- Collection.prototype.sumBy = function (path) {
1791
- return +this.items.reduce(function (sum, item) { return sum + Number(get__default["default"](item, path)); }, 0).toFixed(2);
1790
+ Collection.prototype.sumBy = function (path, abs) {
1791
+ if (abs === void 0) { abs = false; }
1792
+ return +this.items.reduce(function (sum, item) { return sum + (abs ? Math.abs(Number(get__default["default"](item, path))) : Number(get__default["default"](item, path))); }, 0).toFixed(2);
1792
1793
  };
1793
1794
  Collection.prototype.groupBy = function (path) {
1794
1795
  if (path === void 0) { path = ''; }
@@ -3498,6 +3499,16 @@
3498
3499
  ChartAccountsTypeEnum[ChartAccountsTypeEnum["EXPENSE"] = 2] = "EXPENSE";
3499
3500
  })(exports.ChartAccountsTypeEnum || (exports.ChartAccountsTypeEnum = {}));
3500
3501
 
3502
+ /**
3503
+ * most of chartAccounts could have only negative or positive amount,
3504
+ * but there are exceptions like advance income (free loan from company u work for), it's positive number when you receive it,
3505
+ * and negative when you pay it back (still income, but with negative amount)
3506
+ */
3507
+ exports.ChartAccountsKeepSign = void 0;
3508
+ (function (ChartAccountsKeepSign) {
3509
+ ChartAccountsKeepSign[ChartAccountsKeepSign["ADVANCE"] = 556] = "ADVANCE";
3510
+ })(exports.ChartAccountsKeepSign || (exports.ChartAccountsKeepSign = {}));
3511
+
3501
3512
  // @TODO Artem TT-2308 move everything
3502
3513
 
3503
3514
  var ChartAccountsMetadata = /** @class */ (function (_super) {
@@ -5863,7 +5874,7 @@
5863
5874
  // salary included transactions affect parent transaction amount and as a result grossAmount, skip to avoid double sum
5864
5875
  grossAmount += new Collection(this.transactions)
5865
5876
  .filter(function (t) { var _a; return !((_a = t.chartAccounts) === null || _a === void 0 ? void 0 : _a.isSalaryIncluded()); })
5866
- .sumBy('amount');
5877
+ .sumBy('amount', true);
5867
5878
  if (this.isWorkTank()) {
5868
5879
  grossAmount += this.frankingCredit - this.taxFreeComponent - this.eligibleForReduction;
5869
5880
  }
@@ -5885,6 +5896,14 @@
5885
5896
  enumerable: false,
5886
5897
  configurable: true
5887
5898
  });
5899
+ /**
5900
+ * most of the transactions could have only positive or negative amount depends on chartAccounts, so we ignore
5901
+ * user's choice and transform amount, but there are exceptions like advance (negative or positive amount)
5902
+ */
5903
+ Transaction.prototype.ignoreSign = function () {
5904
+ var _a;
5905
+ return !(((_a = this.chartAccounts) === null || _a === void 0 ? void 0 : _a.id) in exports.ChartAccountsKeepSign);
5906
+ };
5888
5907
  return Transaction;
5889
5908
  }(Transaction$1));
5890
5909
  __decorate([
@@ -18566,8 +18585,6 @@
18566
18585
  __extends(AbstractForm, _super);
18567
18586
  function AbstractForm(controls, model, validatorOrOpts, asyncValidator) {
18568
18587
  var _this = _super.call(this, controls, validatorOrOpts, asyncValidator) || this;
18569
- // @TODO remove and use getRawValue instead of value (needs testing and refactoring)
18570
- _this.submitDisabledFields = false;
18571
18588
  /**
18572
18589
  * @TODO Alex bad name, it's also about unchanged
18573
18590
  * Flag display if some form values changed
@@ -18601,15 +18618,17 @@
18601
18618
  * Check validation and return a new instance of generic model.
18602
18619
  * Merge form value to initial object
18603
18620
  * @param data Additional data object which be merged to form value
18621
+ * @param includeDisabledFields ignore disabled fields
18604
18622
  */
18605
- AbstractForm.prototype.submit = function (data) {
18623
+ AbstractForm.prototype.submit = function (data, includeDisabledFields) {
18606
18624
  if (data === void 0) { data = {}; }
18625
+ if (includeDisabledFields === void 0) { includeDisabledFields = false; }
18607
18626
  this.submitted = true;
18608
18627
  this.markAllAsTouched();
18609
18628
  if (!this.disabled && !this.valid) {
18610
18629
  return null;
18611
18630
  }
18612
- var value = this.submitDisabledFields ? this.getRawValue() : this.value;
18631
+ var value = includeDisabledFields ? this.getRawValue() : this.value;
18613
18632
  var model = this.createModelInstance(Object.assign({}, this.model, value, data));
18614
18633
  this.onSubmit.emit(model);
18615
18634
  return model;
@@ -19620,7 +19639,6 @@
19620
19639
  gst: new forms.FormControl({ value: report.gst, disabled: true }),
19621
19640
  }, report) || this;
19622
19641
  _this.report = report;
19623
- _this.submitDisabledFields = true;
19624
19642
  // prefill income/expense data based on transactions/depreciations filtered by specified date
19625
19643
  rxjs.combineLatest([_this.get('dateFrom').valueChanges, _this.get('dateTo').valueChanges])
19626
19644
  .subscribe(function (_a) {
@@ -19653,6 +19671,10 @@
19653
19671
  });
19654
19672
  return _this;
19655
19673
  }
19674
+ BasReportForm.prototype.submit = function (data) {
19675
+ if (data === void 0) { data = {}; }
19676
+ return _super.prototype.submit.call(this, data, true);
19677
+ };
19656
19678
  return BasReportForm;
19657
19679
  }(AbstractForm));
19658
19680
 
@@ -20967,17 +20989,14 @@
20967
20989
  };
20968
20990
  TransactionBaseForm.prototype.watchChartAccounts = function () {
20969
20991
  var _this = this;
20970
- this.get('chartAccounts').valueChanges.subscribe(function (value) {
20971
- if (!(value instanceof ChartAccounts)) {
20972
- return;
20973
- }
20992
+ this.get('chartAccounts').valueChanges.subscribe(function (chartAccounts) {
20974
20993
  // recalculate claim percent for selected chart accounts
20975
- _this.updateClaimPercent(value);
20994
+ _this.updateClaimPercent(chartAccounts);
20976
20995
  if (!_this.isGstApplicable()) {
20977
20996
  return;
20978
20997
  }
20979
20998
  // update gst if applicable
20980
- if (value.isGST) {
20999
+ if (chartAccounts.isGST) {
20981
21000
  _this.get('isGST').enable();
20982
21001
  _this.get('isGST').patchValue(true);
20983
21002
  }
@@ -21071,7 +21090,7 @@
21071
21090
  var formGroup = new forms.FormGroup({
21072
21091
  id: new forms.FormControl(transaction.id),
21073
21092
  chartAccounts: new forms.FormControl(transaction.chartAccounts, [forms.Validators.required, autocompleteValidator()]),
21074
- amount: new forms.FormControl(Math.abs(transaction.amount), [forms.Validators.required]),
21093
+ amount: new forms.FormControl(transaction.amount, [forms.Validators.required]),
21075
21094
  });
21076
21095
  this.get('transactions').push(formGroup);
21077
21096
  };
@@ -21084,19 +21103,22 @@
21084
21103
  */
21085
21104
  TransactionForm.prototype.buildTransactions = function (transaction) {
21086
21105
  var _this = this;
21087
- return this.get('transactions').value.map(function (childTransaction) { return Object.assign({
21088
- description: childTransaction.chartAccounts.name,
21089
- date: transaction.date,
21090
- claimPercent: transaction.claimPercent,
21091
- source: exports.TransactionSourceEnum.BANK_TRANSACTION,
21092
- type: childTransaction.chartAccounts.isExpense() ? exports.TransactionTypeEnum.DEBIT : exports.TransactionTypeEnum.CREDIT,
21093
- incomeSource: transaction.incomeSource,
21094
- property: transaction.property
21095
- }, _this.model.transactions.find(function (transaction) { return transaction.id === childTransaction['id']; }) || {}, childTransaction); });
21106
+ return this.get('transactions').value.map(function (childTransaction) {
21107
+ var _a, _b, _c;
21108
+ return Object.assign({
21109
+ description: (_a = childTransaction.chartAccounts) === null || _a === void 0 ? void 0 : _a.name,
21110
+ date: transaction.date,
21111
+ claimPercent: (transaction.claimPercent * ((_b = childTransaction.chartAccounts) === null || _b === void 0 ? void 0 : _b.taxablePercent)) / 100,
21112
+ source: exports.TransactionSourceEnum.BANK_TRANSACTION,
21113
+ type: ((_c = childTransaction.chartAccounts) === null || _c === void 0 ? void 0 : _c.isExpense()) ? exports.TransactionTypeEnum.DEBIT : exports.TransactionTypeEnum.CREDIT,
21114
+ incomeSource: transaction.incomeSource,
21115
+ property: transaction.property
21116
+ }, _this.model.transactions.find(function (transaction) { return transaction.id === childTransaction['id']; }) || {}, childTransaction);
21117
+ });
21096
21118
  };
21097
21119
  TransactionForm.prototype.submit = function (data) {
21098
21120
  if (data === void 0) { data = {}; }
21099
- return _super.prototype.submit.call(this, Object.assign(data, { transactions: this.buildTransactions(this.currentValue) }));
21121
+ return _super.prototype.submit.call(this, Object.assign(data, { transactions: this.buildTransactions(this.currentValue) }), true);
21100
21122
  };
21101
21123
  return TransactionForm;
21102
21124
  }(TransactionBaseForm));
@@ -21106,6 +21128,8 @@
21106
21128
  function WorkIncomeForm(transaction, registeredForGst, allocations) {
21107
21129
  var _this = this;
21108
21130
  var _a;
21131
+ // for work income we need to show netAmount instead of amount (because some adjustments are included in amount)
21132
+ transaction.amount = transaction.netAmount;
21109
21133
  _this = _super.call(this, transaction, registeredForGst, allocations, {
21110
21134
  // additional data related to work income (like tax instalments)
21111
21135
  metadata: new forms.FormArray((transaction.metadata || []).map(function (transactionMetadata) {
@@ -21120,10 +21144,6 @@
21120
21144
  }, forms.Validators.required),
21121
21145
  incomeSource: new forms.FormControl(transaction.incomeSource, [forms.Validators.required, autocompleteValidator()]),
21122
21146
  }) || this;
21123
- // @TODO we use amount field as netAmount to avoid extra watcher for amount recalculation
21124
- if (transaction.id) {
21125
- _this.get('amount').setValue(transaction.netAmount);
21126
- }
21127
21147
  // forbid to edit some fields for allocated transaction
21128
21148
  if (allocations.length) {
21129
21149
  _this.get('chartAccounts').disable();
@@ -21132,6 +21152,10 @@
21132
21152
  if (!((_a = transaction.chartAccounts) === null || _a === void 0 ? void 0 : _a.isSalary())) {
21133
21153
  _this.get('transactions').disable();
21134
21154
  }
21155
+ // amount changes are not available for transactions with allocations or during allocate process
21156
+ if (allocations.length || transaction.operation === exports.TransactionOperationEnum.ALLOCATE) {
21157
+ _this.get('amount').disable();
21158
+ }
21135
21159
  _this.listenEvents();
21136
21160
  return _this;
21137
21161
  }
@@ -21151,23 +21175,17 @@
21151
21175
  WorkIncomeForm.prototype.watchChartAccounts = function () {
21152
21176
  var _this = this;
21153
21177
  _super.prototype.watchChartAccounts.call(this);
21154
- this.get('chartAccounts').valueChanges.subscribe(function (value) {
21155
- // some fields depend on ChartAccounts and can't be filled until it's selected
21156
- if (!(value instanceof ChartAccounts)) {
21157
- _this.get('tax').disable();
21158
- _this.get('transactions').disable();
21159
- return;
21160
- }
21178
+ this.get('chartAccounts').valueChanges.subscribe(function (chartAccounts) {
21161
21179
  _this.buildMetadataForm();
21162
21180
  // tax make no sense for pre-paying tax category
21163
- if (value.isNRAS()) {
21181
+ if (chartAccounts.isNRAS()) {
21164
21182
  _this.get('tax').disable();
21165
21183
  }
21166
21184
  else {
21167
21185
  _this.get('tax').enable();
21168
21186
  }
21169
21187
  // adjustments possible only for salary chartAccounts
21170
- if (value.isSalary()) {
21188
+ if (chartAccounts.isSalary()) {
21171
21189
  _this.get('transactions').enable();
21172
21190
  }
21173
21191
  else {