taxtank-core 0.32.10 → 0.32.11

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.
@@ -4,7 +4,7 @@ import * as i1$1 from '@angular/common';
4
4
  import { formatDate, CommonModule, CurrencyPipe, DatePipe } from '@angular/common';
5
5
  import * as i1 from '@angular/common/http';
6
6
  import { HttpParams, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
7
- import { map, mergeMap, filter, first as first$1, catchError, take, switchMap, finalize, debounceTime, distinctUntilChanged, delay } from 'rxjs/operators';
7
+ import { map, mergeMap, filter, first as first$1, catchError, take, switchMap, finalize, debounceTime, distinctUntilChanged, startWith, delay } from 'rxjs/operators';
8
8
  import { ReplaySubject, Subject, Observable, throwError, combineLatest, BehaviorSubject, forkJoin, of, from, merge as merge$1 } from 'rxjs';
9
9
  import { plainToClass, Type, Transform, Exclude, Expose, classToPlain } from 'class-transformer';
10
10
  import get from 'lodash/get';
@@ -40,6 +40,7 @@ import html2pdf from 'html2pdf.js';
40
40
  import * as xlsx from 'xlsx';
41
41
  import * as FileSaver from 'file-saver';
42
42
  import isEqual from 'lodash/isEqual';
43
+ import { RxwebValidators } from '@rxweb/reactive-form-validators';
43
44
 
44
45
  /**
45
46
  * https://api-uat.corelogic.asia/property/au/v2/suggest.json
@@ -1654,6 +1655,7 @@ var MonthNumberEnum;
1654
1655
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan'];
1655
1656
 
1656
1657
  /**
1658
+ * @TODO refactor with Map
1657
1659
  * List of collections grouped by passed property
1658
1660
  */
1659
1661
  class CollectionDictionary {
@@ -1834,7 +1836,7 @@ class Collection {
1834
1836
  groupBy(path = 'id') {
1835
1837
  return new CollectionDictionary(this, path);
1836
1838
  }
1837
- indexBy(path) {
1839
+ indexBy(path = 'id') {
1838
1840
  return new Dictionary(this.items, path);
1839
1841
  }
1840
1842
  filter(callback) {
@@ -8186,6 +8188,7 @@ class VehicleExpenseCollection extends Collection {
8186
8188
  }
8187
8189
 
8188
8190
  /**
8191
+ * @TODO refactor with Map
8189
8192
  * List of objects grouped by passed property
8190
8193
  */
8191
8194
  class Dictionary {
@@ -8194,10 +8197,6 @@ class Dictionary {
8194
8197
  if (!items.length) {
8195
8198
  return;
8196
8199
  }
8197
- // Do nothing if provided path was not found in the 1st item
8198
- if (!hasIn(items[0], path.split('.')[0])) {
8199
- return;
8200
- }
8201
8200
  this.groupItems(items, path);
8202
8201
  }
8203
8202
  add(key, value) {
@@ -8214,6 +8213,10 @@ class Dictionary {
8214
8213
  return Object.values(this.items);
8215
8214
  }
8216
8215
  groupItems(items, path) {
8216
+ // Do nothing if provided path was not found in the 1st item
8217
+ if (!hasIn(items[0], path.split('.')[0])) {
8218
+ return;
8219
+ }
8217
8220
  items.forEach((item) => {
8218
8221
  let key = get(item, path);
8219
8222
  // if object does not have property for grouping it will be grouped as 'other'
@@ -8226,6 +8229,9 @@ class Dictionary {
8226
8229
  get keys() {
8227
8230
  return Object.keys(this.items);
8228
8231
  }
8232
+ get length() {
8233
+ return this.keys.length;
8234
+ }
8229
8235
  }
8230
8236
 
8231
8237
  class SoleBusinessLossesCollection extends Collection {
@@ -10345,10 +10351,12 @@ class Budget extends Budget$1 {
10345
10351
  }
10346
10352
  }
10347
10353
  __decorate([
10348
- Type(() => BudgetRule)
10354
+ Type(() => BudgetRule),
10355
+ Expose()
10349
10356
  ], Budget.prototype, "rules", void 0);
10350
10357
  __decorate([
10351
- Type(() => User)
10358
+ Type(() => User),
10359
+ Expose()
10352
10360
  ], Budget.prototype, "user", void 0);
10353
10361
 
10354
10362
  class TaxReturnCategory extends TaxReturnCategory$1 {
@@ -20320,6 +20328,7 @@ class AbstractForm extends UntypedFormGroup {
20320
20328
  // @TODO vik required, otherwise modelClass won't exist
20321
20329
  model, validatorOrOpts, asyncValidator) {
20322
20330
  super(controls, validatorOrOpts, asyncValidator);
20331
+ this.excludeExtraneousValues = false;
20323
20332
  /**
20324
20333
  * @TODO Alex bad name, it's also about unchanged
20325
20334
  * Flag display if some form values changed
@@ -20379,7 +20388,7 @@ class AbstractForm extends UntypedFormGroup {
20379
20388
  * @param data
20380
20389
  */
20381
20390
  createModelInstance(data = {}) {
20382
- return plainToClass(this.modelClass, data);
20391
+ return plainToClass(this.modelClass, data, { excludeExtraneousValues: this.excludeExtraneousValues });
20383
20392
  }
20384
20393
  /**
20385
20394
  * emit current form values
@@ -20596,17 +20605,26 @@ class AddressForm extends AbstractForm {
20596
20605
  class BudgetForm extends AbstractForm {
20597
20606
  constructor(budget) {
20598
20607
  super({
20599
- rules: new UntypedFormArray((budget.rules || [plainToClass(BudgetRule, {})]).map((rule) => new UntypedFormGroup({
20600
- chartAccounts: new UntypedFormControl(rule.chartAccounts, Validators.required),
20601
- amount: new UntypedFormControl(rule.amount, Validators.required)
20602
- })))
20608
+ category: new UntypedFormControl(),
20609
+ searchQuery: new UntypedFormControl(''),
20610
+ rules: new UntypedFormArray((budget.rules || [plainToClass(BudgetRule, {})]).map((budgetRule) => BudgetForm.createRuleFormGroup(budgetRule))),
20603
20611
  }, budget);
20604
- this.filteredRules = this.rulesArray.controls;
20612
+ this.excludeExtraneousValues = true;
20613
+ combineLatest([
20614
+ this.get('category').valueChanges.pipe(startWith(null)),
20615
+ this.get('searchQuery').valueChanges.pipe(startWith(null))
20616
+ ]).subscribe(() => this.filterRules());
20617
+ this.total = budget.rulesCollection.sumBy('amount');
20618
+ this.get('rules').valueChanges.subscribe((rules) => {
20619
+ this.total = new Collection(rules).sumBy('amount');
20620
+ });
20605
20621
  }
20606
20622
  get rulesArray() {
20607
20623
  return this.get('rules');
20608
20624
  }
20609
- filterRules(searchQuery, categories) {
20625
+ filterRules() {
20626
+ const category = this.get('category').value;
20627
+ const searchQuery = this.get('searchQuery').value;
20610
20628
  let filteredRules = this.rulesArray.controls;
20611
20629
  if (searchQuery) {
20612
20630
  filteredRules = filteredRules.filter((ruleGroup) => {
@@ -20618,24 +20636,31 @@ class BudgetForm extends AbstractForm {
20618
20636
  return chartAccountsName.includes(searchQuery) || ruleAmount.includes(searchQuery);
20619
20637
  });
20620
20638
  }
20621
- filteredRules = filteredRules.filter((ruleGroup) => {
20622
- const chartAccounts = ruleGroup.get('chartAccounts').value;
20623
- if (!chartAccounts) {
20624
- return true;
20625
- }
20626
- return categories.includes(chartAccounts?.category);
20627
- });
20628
- this.filteredRules = filteredRules;
20639
+ if (category) {
20640
+ filteredRules = filteredRules.filter((ruleGroup) => {
20641
+ const chartAccounts = ruleGroup.get('chartAccounts').value;
20642
+ if (!chartAccounts) {
20643
+ return true;
20644
+ }
20645
+ return chartAccounts.category === category;
20646
+ });
20647
+ }
20648
+ this.filteredRules = new Map(filteredRules.map((rule) => [this.rulesArray.controls.indexOf(rule), rule]));
20629
20649
  }
20630
- addRule() {
20631
- const formGroup = new UntypedFormGroup({
20632
- chartAccounts: new UntypedFormControl(null, Validators.required),
20633
- amount: new UntypedFormControl(null, Validators.required)
20650
+ static createRuleFormGroup(budgetRule) {
20651
+ return new UntypedFormGroup({
20652
+ chartAccounts: new UntypedFormControl(budgetRule.chartAccounts, [Validators.required, RxwebValidators.unique()]),
20653
+ amount: new UntypedFormControl(budgetRule.amount, Validators.required)
20634
20654
  });
20635
- this.rulesArray.push(formGroup);
20655
+ }
20656
+ addRule(budgetRule = plainToClass(BudgetRule, {})) {
20657
+ const rule = BudgetForm.createRuleFormGroup(budgetRule);
20658
+ this.rulesArray.push(rule);
20659
+ this.filteredRules.set(this.rulesArray.controls.indexOf(rule), rule);
20636
20660
  }
20637
20661
  deleteRule(index) {
20638
20662
  this.rulesArray.removeAt(index);
20663
+ this.filteredRules.delete(index);
20639
20664
  }
20640
20665
  }
20641
20666