taxtank-core 0.13.0 → 0.13.1

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/common/http'), require('rxjs'), require('rxjs/operators'), require('class-transformer'), require('@auth0/angular-jwt'), require('lodash/get'), require('lodash/flatten'), require('lodash/hasIn'), require('lodash/first'), require('lodash/last'), require('lodash/uniqBy'), require('lodash/concat'), require('lodash/compact'), require('moment'), require('moment-range'), require('lodash/cloneDeep'), require('@angular/forms'), require('lodash'), require('event-source-polyfill/src/eventsource.min.js'), require('@angular/router'), require('lodash/clone'), require('jspdf'), require('jspdf-autotable'), require('@stripe/stripe-js'), require('xlsx'), require('file-saver')) :
3
- typeof define === 'function' && define.amd ? define('taxtank-core', ['exports', '@angular/core', '@angular/common', '@angular/common/http', 'rxjs', 'rxjs/operators', 'class-transformer', '@auth0/angular-jwt', 'lodash/get', 'lodash/flatten', 'lodash/hasIn', 'lodash/first', 'lodash/last', 'lodash/uniqBy', 'lodash/concat', 'lodash/compact', 'moment', 'moment-range', 'lodash/cloneDeep', '@angular/forms', 'lodash', 'event-source-polyfill/src/eventsource.min.js', '@angular/router', 'lodash/clone', 'jspdf', 'jspdf-autotable', '@stripe/stripe-js', 'xlsx', 'file-saver'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["taxtank-core"] = {}, global.ng.core, global.ng.common, global.ng.common.http, global.rxjs, global.rxjs.operators, global.classTransformer, global.angularJwt, global.get, global.flatten, global.hasIn, global.first, global.last, global.uniqBy, global.concat, global.compact, global.moment, global.momentRange, global.cloneDeep$1, global.ng.forms, global._, global.eventsource_min_js, global.ng.router, global.clone, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
- })(this, (function (exports, i0, i2, i1, rxjs, operators, classTransformer, angularJwt, get, flatten, hasIn, first, last, uniqBy, concat, compact, moment, momentRange, cloneDeep$1, forms, _, eventsource_min_js, i1$1, clone, jsPDF, autoTable, stripeJs, xlsx, FileSaver) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/common/http'), require('rxjs'), require('rxjs/operators'), require('class-transformer'), require('@auth0/angular-jwt'), require('lodash/get'), require('lodash/flatten'), require('lodash/hasIn'), require('lodash/first'), require('lodash/last'), require('lodash/compact'), require('lodash/uniqBy'), require('lodash/concat'), require('moment'), require('moment-range'), require('lodash/cloneDeep'), require('@angular/forms'), require('lodash/fromPairs'), require('lodash'), require('event-source-polyfill/src/eventsource.min.js'), require('@angular/router'), require('lodash/clone'), require('jspdf'), require('jspdf-autotable'), require('@stripe/stripe-js'), require('xlsx'), require('file-saver')) :
3
+ typeof define === 'function' && define.amd ? define('taxtank-core', ['exports', '@angular/core', '@angular/common', '@angular/common/http', 'rxjs', 'rxjs/operators', 'class-transformer', '@auth0/angular-jwt', 'lodash/get', 'lodash/flatten', 'lodash/hasIn', 'lodash/first', 'lodash/last', 'lodash/compact', 'lodash/uniqBy', 'lodash/concat', 'moment', 'moment-range', 'lodash/cloneDeep', '@angular/forms', 'lodash/fromPairs', 'lodash', 'event-source-polyfill/src/eventsource.min.js', '@angular/router', 'lodash/clone', 'jspdf', 'jspdf-autotable', '@stripe/stripe-js', 'xlsx', 'file-saver'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["taxtank-core"] = {}, global.ng.core, global.ng.common, global.ng.common.http, global.rxjs, global.rxjs.operators, global.classTransformer, global.angularJwt, global.get, global.flatten, global.hasIn, global.first, global.last, global.compact, global.uniqBy, global.concat, global.moment, global.momentRange, global.cloneDeep$1, global.ng.forms, global.fromPairs, global._, global.eventsource_min_js, global.ng.router, global.clone, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
+ })(this, (function (exports, i0, i2, i1, rxjs, operators, classTransformer, angularJwt, get, flatten, hasIn, first, last, compact, uniqBy, concat, moment, momentRange, cloneDeep$1, forms, fromPairs, _, eventsource_min_js, i1$1, clone, jsPDF, autoTable, stripeJs, xlsx, FileSaver) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -32,11 +32,12 @@
32
32
  var hasIn__default = /*#__PURE__*/_interopDefaultLegacy(hasIn);
33
33
  var first__default = /*#__PURE__*/_interopDefaultLegacy(first);
34
34
  var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
35
+ var compact__default = /*#__PURE__*/_interopDefaultLegacy(compact);
35
36
  var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
36
37
  var concat__default = /*#__PURE__*/_interopDefaultLegacy(concat);
37
- var compact__default = /*#__PURE__*/_interopDefaultLegacy(compact);
38
38
  var moment__namespace = /*#__PURE__*/_interopNamespace(moment);
39
39
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep$1);
40
+ var fromPairs__default = /*#__PURE__*/_interopDefaultLegacy(fromPairs);
40
41
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
41
42
  var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);
42
43
  var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
@@ -1370,10 +1371,10 @@
1370
1371
  /**
1371
1372
  * Sort collection items by provided field
1372
1373
  */
1373
- Collection.prototype.sortBy = function (filed, isDesc) {
1374
- if (filed === void 0) { filed = 'id'; }
1374
+ Collection.prototype.sortBy = function (field, isDesc) {
1375
+ if (field === void 0) { field = 'id'; }
1375
1376
  if (isDesc === void 0) { isDesc = true; }
1376
- sort(this.items, filed, isDesc);
1377
+ sort(this.items, field, isDesc);
1377
1378
  };
1378
1379
  Collection.prototype.getByDateRange = function (from, to, dateField) {
1379
1380
  if (dateField === void 0) { dateField = 'date'; }
@@ -1385,7 +1386,7 @@
1385
1386
  var AccountSetupItemCollection = /** @class */ (function (_super) {
1386
1387
  __extends(AccountSetupItemCollection, _super);
1387
1388
  function AccountSetupItemCollection(items) {
1388
- var _this = _super.call(this, items) || this;
1389
+ var _this = _super.call(this, compact__default["default"](items)) || this;
1389
1390
  _this.sortBy('isCompleted', false);
1390
1391
  return _this;
1391
1392
  }
@@ -3038,6 +3039,7 @@
3038
3039
  UserRolesEnum["SUBSCRIPTION"] = "ROLE_USER_SUBSCRIPTION";
3039
3040
  UserRolesEnum["WORK_TANK"] = "ROLE_USER_WORK";
3040
3041
  UserRolesEnum["PROPERTY_TANK"] = "ROLE_USER_PROPERTY";
3042
+ UserRolesEnum["SOLE_TANK"] = "ROLE_USER_SOLE";
3041
3043
  UserRolesEnum["SWITCH_USER"] = "ROLE_PREVIOUS_ADMIN";
3042
3044
  })(exports.UserRolesEnum || (exports.UserRolesEnum = {}));
3043
3045
 
@@ -5373,6 +5375,42 @@
5373
5375
  return PropertyReportItemDepreciationCollection;
5374
5376
  }(PropertyReportItemCollection));
5375
5377
 
5378
+ /**
5379
+ * Vehicle expense for logbook section
5380
+ */
5381
+ var VehicleExpense = /** @class */ (function () {
5382
+ function VehicleExpense(amount, claimPercent, description) {
5383
+ this.amount = amount;
5384
+ this.claimPercent = claimPercent;
5385
+ this.description = description;
5386
+ }
5387
+ VehicleExpense.prototype.getClaimAmount = function () {
5388
+ return +(this.amount * (this.claimPercent / 100)).toFixed(2);
5389
+ };
5390
+ return VehicleExpense;
5391
+ }());
5392
+
5393
+ var VehicleExpenseCollection = /** @class */ (function (_super) {
5394
+ __extends(VehicleExpenseCollection, _super);
5395
+ function VehicleExpenseCollection(transactions, depreciations, vehicleClaim) {
5396
+ var _this = _super.call(this) || this;
5397
+ _this.setItems(transactions, depreciations, vehicleClaim);
5398
+ return _this;
5399
+ }
5400
+ VehicleExpenseCollection.prototype.setItems = function (transactions, depreciations, vehicleClaim) {
5401
+ var _a;
5402
+ this.items = [];
5403
+ var transactionsByChartAccounts = new CollectionDictionary(transactions, 'chartAccounts.name');
5404
+ var transactionExpenses = transactionsByChartAccounts.keys.map(function (chartAccountsName) {
5405
+ return new VehicleExpense(transactionsByChartAccounts.get(chartAccountsName).amount, vehicleClaim.workUsage, chartAccountsName);
5406
+ });
5407
+ // group all depreciations into one expense item
5408
+ var depreciationExpense = new VehicleExpense(depreciations.getCurrentYearForecastAmount(), vehicleClaim.workUsage, 'Depreciation');
5409
+ (_a = this.items).push.apply(_a, __spreadArray([depreciationExpense], __read(transactionExpenses)));
5410
+ };
5411
+ return VehicleExpenseCollection;
5412
+ }(Collection));
5413
+
5376
5414
  var ServiceSubscriptionCollection = /** @class */ (function (_super) {
5377
5415
  __extends(ServiceSubscriptionCollection, _super);
5378
5416
  function ServiceSubscriptionCollection() {
@@ -6345,6 +6383,7 @@
6345
6383
  */
6346
6384
  var AccountSetupItem = /** @class */ (function () {
6347
6385
  function AccountSetupItem() {
6386
+ this.clientIncomeTypes = [];
6348
6387
  }
6349
6388
  return AccountSetupItem;
6350
6389
  }());
@@ -8652,6 +8691,7 @@
8652
8691
  ROLE_USER_SUBSCRIPTION: [exports.UserRolesEnum.SUBSCRIPTION],
8653
8692
  ROLE_USER_WORK: [exports.UserRolesEnum.WORK_TANK],
8654
8693
  ROLE_USER_PROPERTY: [exports.UserRolesEnum.PROPERTY_TANK],
8694
+ ROLE_USER_SOLE: [exports.UserRolesEnum.SOLE_TANK],
8655
8695
  ROLE_PREVIOUS_ADMIN: [exports.UserRolesEnum.SWITCH_USER]
8656
8696
  };
8657
8697
 
@@ -8764,17 +8804,20 @@
8764
8804
  _a[AccountSetupItemsEnum.SALARY] = classTransformer.plainToClass(AccountSetupItem, {
8765
8805
  title: 'Add your work income forecast',
8766
8806
  description: 'One the most important steps is to add your salary or wage incomes so we can automatically calculate tax withheld and your forecasted tax position.',
8767
- url: '/client/work-tank/forecasting'
8807
+ url: '/client/work-tank/forecasting',
8808
+ clientIncomeTypes: ['salary']
8768
8809
  }),
8769
8810
  _a[AccountSetupItemsEnum.OTHER_INCOME] = classTransformer.plainToClass(AccountSetupItem, {
8770
8811
  title: 'Add any other expected incomes',
8771
8812
  description: 'To ensure an accurate tax position forecast, add estimates for any other income types, like dividends, interest, trusts, annuities, director payments etc.',
8772
- url: '/client/work-tank/forecasting'
8813
+ url: '/client/work-tank/forecasting',
8814
+ clientIncomeTypes: ['dividends', 'other']
8773
8815
  }),
8774
8816
  _a[AccountSetupItemsEnum.PROPERTY] = classTransformer.plainToClass(AccountSetupItem, {
8775
8817
  title: 'Add your properties',
8776
8818
  description: 'Add your properties to seamlessly manage your rental incomes and expenses, whilst tracking your cash position, tax positions and equity forecasts in real time.',
8777
- url: '/client/property-tank'
8819
+ url: '/client/property-tank',
8820
+ clientIncomeTypes: ['property']
8778
8821
  }),
8779
8822
  _a[AccountSetupItemsEnum.BANK_FEEDS] = classTransformer.plainToClass(AccountSetupItem, {
8780
8823
  title: 'Link banks and select accounts',
@@ -8789,7 +8832,8 @@
8789
8832
  _a[AccountSetupItemsEnum.SOLE_INCOME] = classTransformer.plainToClass(AccountSetupItem, {
8790
8833
  title: 'Add your business details',
8791
8834
  description: 'Add your business details, logo and payment terms to create invoice templates in minutes.',
8792
- url: '/client/sole-tank/forecasting'
8835
+ url: '/client/sole-tank/forecasting',
8836
+ clientIncomeTypes: ['sole']
8793
8837
  }),
8794
8838
  _a[AccountSetupItemsEnum.TRANSACTION] = classTransformer.plainToClass(AccountSetupItem, {
8795
8839
  title: 'Allocation transactions',
@@ -9510,7 +9554,11 @@
9510
9554
  */
9511
9555
  TransactionAllocationService.prototype.onTransactionsCreated = function () {
9512
9556
  var _this = this;
9513
- this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTIONS_CREATED).subscribe(function () {
9557
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTIONS_CREATED).subscribe(function (transactions) {
9558
+ // @TODO Alex hack: research and refactor cache update logic, dont reset cache each time transactions changed
9559
+ if (transactions[0].isTransfer) {
9560
+ return;
9561
+ }
9514
9562
  // Update allocations cache to synchronize data and fire subscriptions
9515
9563
  _this.resetCache();
9516
9564
  });
@@ -9521,6 +9569,7 @@
9521
9569
  TransactionAllocationService.prototype.onDepreciationCreated = function () {
9522
9570
  var _this = this;
9523
9571
  this.eventDispatcherService.on(exports.AppEventTypeEnum.DEPRECIATIONS_CREATED).subscribe(function () {
9572
+ // @TODO Alex hack: research and refactor cache update logic, dont reset cache each time depreciations changed
9524
9573
  // Update allocations cache to synchronize data and fire subscriptions
9525
9574
  _this.resetCache();
9526
9575
  });
@@ -9531,6 +9580,7 @@
9531
9580
  TransactionAllocationService.prototype.onTransactionDeleted = function () {
9532
9581
  var _this = this;
9533
9582
  this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTION_DELETED).subscribe(function () {
9583
+ // @TODO Alex hack: research and refactor cache update logic, dont reset cache each time transactions changed
9534
9584
  // Update allocations cache to synchronize data and fire subscriptions
9535
9585
  _this.resetCache();
9536
9586
  });
@@ -9581,427 +9631,787 @@
9581
9631
  }]
9582
9632
  }] });
9583
9633
 
9634
+ function enumToList(data) {
9635
+ var list = [];
9636
+ for (var key in data) {
9637
+ if (Number(key) >= 0) {
9638
+ list.push({
9639
+ label: data[key],
9640
+ value: Number(key)
9641
+ });
9642
+ }
9643
+ }
9644
+ return list;
9645
+ }
9646
+
9647
+ var MessagesEnum;
9648
+ (function (MessagesEnum) {
9649
+ MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
9650
+ MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
9651
+ MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
9652
+ })(MessagesEnum || (MessagesEnum = {}));
9653
+
9584
9654
  /**
9585
- * Service handling user's account setup process.
9586
- * Checks required steps and their completion
9655
+ * Service for transactions business logic
9587
9656
  */
9588
- var AccountSetupService = /** @class */ (function () {
9589
- function AccountSetupService(clientIncomeTypesService, propertyService, incomeSourceService, bankAccountsService, transactionAllocationService, vehicleClaimService) {
9590
- this.clientIncomeTypesService = clientIncomeTypesService;
9591
- this.propertyService = propertyService;
9592
- this.incomeSourceService = incomeSourceService;
9593
- this.bankAccountsService = bankAccountsService;
9594
- this.transactionAllocationService = transactionAllocationService;
9595
- this.vehicleClaimService = vehicleClaimService;
9596
- this.cacheSubject = new rxjs.ReplaySubject(1);
9657
+ var TransactionService = /** @class */ (function (_super) {
9658
+ __extends(TransactionService, _super);
9659
+ function TransactionService() {
9660
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
9661
+ // url part for Transaction API
9662
+ _this.url = 'transactions';
9663
+ _this.modelClass = Transaction;
9664
+ _this.transactionDeleted = new i0.EventEmitter();
9665
+ return _this;
9597
9666
  }
9598
9667
  /**
9599
- * Get list of account setup items for current user
9668
+ * Listen events from Event Dispatcher services
9600
9669
  */
9601
- AccountSetupService.prototype.get = function () {
9670
+ TransactionService.prototype.listenEvents = function () {
9671
+ this.listenDepreciationChange();
9672
+ this.listenPropertyShareUpdate();
9673
+ };
9674
+ /**
9675
+ * get list of all user's TaxTank transactions
9676
+ */
9677
+ TransactionService.prototype.get = function () {
9602
9678
  var _this = this;
9603
9679
  if (!this.cache) {
9604
- this.clientIncomeTypesService.get().subscribe(function (incomeTypes) {
9605
- rxjs.combineLatest(_this.createBatch(incomeTypes)).subscribe(function (items) {
9606
- _this.cache = new AccountSetupItemCollection(items);
9607
- _this.cacheSubject.next(_this.cache);
9608
- });
9680
+ // set cache as default empty array to avoid multiple backend requests
9681
+ this.cache = [];
9682
+ this.fetch()
9683
+ .subscribe(function (transactions) {
9684
+ _this.cache = transactions;
9685
+ _this.updateCache();
9609
9686
  });
9610
9687
  }
9611
- return this.cacheSubject.asObservable();
9688
+ return this.cacheSubject.asObservable().pipe(
9689
+ // assign child transactions (fees) to parent transactions
9690
+ operators.map(function (transactions) {
9691
+ transactions.forEach(function (transaction) {
9692
+ transaction.transactions = transactions
9693
+ // get list of child transactions
9694
+ .filter(function (t) { return t.parentTransaction && t.parentTransaction.id === transaction.id; });
9695
+ });
9696
+ sort(transactions, 'date', false);
9697
+ return transactions;
9698
+ }));
9612
9699
  };
9613
9700
  /**
9614
- * Get a single AccountSetupItem and check it's completion
9701
+ * Add single new transaction
9702
+ * @param model New Transaction instance for saving
9615
9703
  */
9616
- AccountSetupService.prototype.create = function (itemType, request) {
9617
- return request.pipe(operators.map(function (result) {
9618
- var item = ACCOUNT_SETUP_ITEMS[itemType];
9619
- if (result.length) {
9620
- item.isCompleted = true;
9621
- }
9622
- return item;
9704
+ TransactionService.prototype.add = function (model) {
9705
+ var _this = this;
9706
+ // we don't have POST API endpoint for single transaction
9707
+ return this.addBatch([model])
9708
+ .pipe(operators.map(function (newTransactions) {
9709
+ // @TODO alex
9710
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_CREATED, newTransactions[0]));
9711
+ return newTransactions[0];
9623
9712
  }));
9624
9713
  };
9625
9714
  /**
9626
- * Get batch of requests to get list of required AccountSetupItem's.
9627
- * Some items are optional and depends of user's client income types
9715
+ * get transactions related with property
9628
9716
  */
9629
- AccountSetupService.prototype.createBatch = function (incomeTypes) {
9630
- var batch = [];
9631
- // Salary item is completed when user added salary income source
9632
- if (incomeTypes.salary) {
9633
- batch.push(this.create(AccountSetupItemsEnum.SALARY, this.getIncomeSourcesByType(exports.IncomeSourceTypeEnum.SALARY)));
9634
- }
9635
- // Other income item is completed when user added at least one other income source
9636
- if (incomeTypes.dividends || incomeTypes.other) {
9637
- batch.push(this.create(AccountSetupItemsEnum.OTHER_INCOME, this.getIncomeSourcesByType(exports.IncomeSourceTypeEnum.OTHER)));
9638
- }
9639
- // Rental income item is completed when user added at least one property
9640
- if (incomeTypes.property) {
9641
- batch.push(this.create(AccountSetupItemsEnum.PROPERTY, this.propertyService.get()));
9642
- }
9643
- // Bank feeds item is completed when user added at least one bank account (basiq or manual)
9644
- batch.push(this.create(AccountSetupItemsEnum.BANK_FEEDS, this.bankAccountsService.get()));
9645
- // Logbook item is completed when user has at least one vehicle claim with any method (klms or logbook)
9646
- batch.push(this.create(AccountSetupItemsEnum.WORK_LOGBOOK, this.vehicleClaimService.get()));
9647
- // @TODO waiting for sole tank forecast page
9648
- // Sole item is completed when user added at least one sole income source
9649
- // if (incomeTypes.soleTrader) {
9650
- // batch.push(
9651
- // this.prepareItem(
9652
- // AccountSetupItemsEnum.SOLE_INCOME,
9653
- // this.getIncomeSourcesByType(IncomeSourceTypeEnum.SOLE)
9654
- // )
9655
- // );
9656
- // }
9657
- // Allocation item is completed when user added at least one transaction allocation
9658
- batch.push(this.create(AccountSetupItemsEnum.TRANSACTION, this.transactionAllocationService.get()));
9659
- return batch;
9717
+ TransactionService.prototype.getByPropertyId = function (propertyId) {
9718
+ return this.get()
9719
+ .pipe(operators.map(function (transactions) {
9720
+ return transactions.filter(function (transaction) {
9721
+ var _a;
9722
+ return ((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id) === propertyId;
9723
+ });
9724
+ }));
9660
9725
  };
9661
9726
  /**
9662
- * @TODO work with collection when services refactored
9727
+ * get list of transactions with tank type 'Work'
9663
9728
  */
9664
- AccountSetupService.prototype.getIncomeSourcesByType = function (type) {
9665
- return this.incomeSourceService.get().pipe(operators.map(function (incomeSources) {
9666
- return new IncomeSourceCollection(incomeSources).getBy('type', type).toArray();
9729
+ TransactionService.prototype.getWorkTransactions = function () {
9730
+ return this.get()
9731
+ .pipe(operators.map(function (transactions) {
9732
+ return transactions.filter(function (transaction) { return transaction.isWorkTank(); });
9667
9733
  }));
9668
9734
  };
9669
- return AccountSetupService;
9670
- }());
9671
- AccountSetupService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, deps: [{ token: ClientIncomeTypesService }, { token: PropertyService }, { token: IncomeSourceService }, { token: BankAccountService }, { token: TransactionAllocationService }, { token: VehicleClaimService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
9672
- AccountSetupService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, providedIn: 'root' });
9673
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, decorators: [{
9674
- type: i0.Injectable,
9675
- args: [{
9676
- providedIn: 'root'
9677
- }]
9678
- }], ctorParameters: function () { return [{ type: ClientIncomeTypesService }, { type: PropertyService }, { type: IncomeSourceService }, { type: BankAccountService }, { type: TransactionAllocationService }, { type: VehicleClaimService }]; } });
9679
-
9680
- var AddressService = /** @class */ (function () {
9681
- function AddressService(http, environment) {
9682
- this.http = http;
9683
- this.environment = environment;
9684
- this.countriesSubject = new rxjs.ReplaySubject(1);
9685
- }
9686
- AddressService.prototype.getCountries = function () {
9687
- var _this = this;
9688
- if (!this._countries) {
9689
- this.http.get(this.environment.apiV2 + "/countries")
9690
- .pipe(operators.map(function (response) {
9691
- return response['hydra:member'].map(function (item) { return classTransformer.plainToClass(Country, item); });
9692
- }))
9693
- .subscribe(function (countries) {
9694
- _this._countries = countries;
9695
- _this.countriesSubject.next(countries);
9696
- });
9697
- }
9698
- return this.countriesSubject.asObservable();
9699
- };
9700
- return AddressService;
9701
- }());
9702
- AddressService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, deps: [{ token: i1__namespace.HttpClient }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
9703
- AddressService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, providedIn: 'root' });
9704
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, decorators: [{
9705
- type: i0.Injectable,
9706
- args: [{
9707
- providedIn: 'root'
9708
- }]
9709
- }], ctorParameters: function () {
9710
- return [{ type: i1__namespace.HttpClient }, { type: undefined, decorators: [{
9711
- type: i0.Inject,
9712
- args: ['environment']
9713
- }] }];
9714
- } });
9715
-
9716
- /**
9717
- * Service to work with assets (documents, receipts, e.t.c.)
9718
- */
9719
- var AssetsService = /** @class */ (function () {
9720
- function AssetsService(http, userSwitcherService, environment) {
9721
- this.http = http;
9722
- this.userSwitcherService = userSwitcherService;
9723
- this.environment = environment;
9724
- this.impersonatedClient = this.userSwitcherService.get();
9725
- }
9726
9735
  /**
9727
- * Get asset link
9728
- * @param asset to get the link for
9736
+ * Get list of property holding costs (transactions related to vacant land property)
9729
9737
  */
9730
- AssetsService.prototype.getLink = function (asset) {
9731
- return this.http.get(this.environment.apiV2 + "/assets/" + asset.type + "/" + asset.id);
9738
+ TransactionService.prototype.getPropertyHoldingCosts = function (propertyId) {
9739
+ return this.http.get(this.environment.apiV2 + "/" + this.url + "?propertyId=" + propertyId + "&propertyCategoryId=" + exports.PropertyCategoryListEnum.VACANT_LAND)
9740
+ .pipe(operators.map(function (transactionsBase) {
9741
+ return transactionsBase.map(function (transactionBase) { return classTransformer.plainToClass(Transaction, transactionBase); });
9742
+ }));
9732
9743
  };
9733
9744
  /**
9734
- * Download asset
9735
- * @param asset which should be downloaded
9736
- * @TODO refactor
9745
+ * get list of taxable transactions with tank type 'Work'
9737
9746
  */
9738
- AssetsService.prototype.download = function (asset) {
9739
- return this.environment.apiV2 + "/assets/" + asset.type + "/" + asset.id + "/download?bearer=" + localStorage.getItem('token') + (this.impersonatedClient ? "&_switch_user=" + this.impersonatedClient : '');
9747
+ TransactionService.prototype.getTaxableWorkTransactions = function () {
9748
+ return this.getWorkTransactions()
9749
+ .pipe(operators.map(function (transactions) {
9750
+ return transactions.filter(function (transaction) { return !!transaction.chartAccounts.taxReturnItem; });
9751
+ }));
9740
9752
  };
9741
- // @Todo refactor to event dispatcher
9742
9753
  /**
9743
- * Delete asset
9744
- * @param entityId: id of asset main entity (property, folder, transaction, e.t.c.)
9745
- * @param asset which should be deleted
9754
+ * add multiple transactions
9755
+ * @param transactions List of new Transaction instances for saving
9746
9756
  */
9747
- AssetsService.prototype.delete = function (entityId, asset) {
9748
- return this.http.delete(this.environment.apiV2 + "/" + asset.entityType + "/" + entityId + "/" + asset.type + "/" + asset.id);
9749
- };
9750
- return AssetsService;
9751
- }());
9752
- AssetsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, deps: [{ token: i1__namespace.HttpClient }, { token: UserSwitcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
9753
- AssetsService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, providedIn: 'root' });
9754
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, decorators: [{
9755
- type: i0.Injectable,
9756
- args: [{
9757
- providedIn: 'root'
9758
- }]
9759
- }], ctorParameters: function () {
9760
- return [{ type: i1__namespace.HttpClient }, { type: UserSwitcherService }, { type: undefined, decorators: [{
9761
- type: i0.Inject,
9762
- args: ['environment']
9763
- }] }];
9764
- } });
9765
-
9766
- /**
9767
- * Service that handling banks logic
9768
- */
9769
- var BankService = /** @class */ (function (_super) {
9770
- __extends(BankService, _super);
9771
- function BankService() {
9772
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
9773
- _this.modelClass = Bank;
9774
- _this.url = 'banks';
9775
- _this.isHydra = true;
9776
- return _this;
9777
- }
9778
- return BankService;
9779
- }(RestService));
9780
- BankService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
9781
- BankService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, providedIn: 'root' });
9782
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, decorators: [{
9783
- type: i0.Injectable,
9784
- args: [{
9785
- providedIn: 'root'
9786
- }]
9787
- }] });
9788
-
9789
- /**
9790
- * @TODO move to collection
9791
- */
9792
- var BankTransactionCalculationService = /** @class */ (function () {
9793
- function BankTransactionCalculationService() {
9794
- }
9795
- /**
9796
- * Sum of allocations for passed bank transactions
9797
- */
9798
- BankTransactionCalculationService.prototype.getAllocatedAmount = function (bankTransactions, allocations) {
9799
- return allocations.getByBankTransactionsIds(bankTransactions.getIds()).amount;
9757
+ TransactionService.prototype.addBatch = function (transactions) {
9758
+ var _this = this;
9759
+ transactions = ___default["default"].cloneDeep(transactions);
9760
+ return this.http.post(this.environment.apiV2 + "/" + this.url, transactions)
9761
+ .pipe(operators.map(function (response) {
9762
+ var _c;
9763
+ var addedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
9764
+ transactions.forEach(function (transaction, index) {
9765
+ // @TODO backend: need to upload file in the same backend endpoint with transaction add/update
9766
+ // check if passed receipt and upload file
9767
+ if (transaction.file) {
9768
+ transaction.id = response[index].id;
9769
+ addedTransactions[index].file = transaction.file;
9770
+ _this.uploadReceipt(addedTransactions[index]);
9771
+ }
9772
+ // @TODO Viktor: implement API for saving of nested transactions
9773
+ // add child transactions if exist
9774
+ if (transaction.transactions.length) {
9775
+ transaction.transactions.forEach(function (childTransaction) {
9776
+ childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: addedTransactions[index].id });
9777
+ });
9778
+ _this.addBatch(transaction.transactions).subscribe();
9779
+ }
9780
+ // add transfer transaction to cache
9781
+ if (transaction.operation === exports.TransactionOperationEnum.TRANSFER) {
9782
+ addedTransactions.push(addedTransactions[0].transfer);
9783
+ }
9784
+ });
9785
+ if (_this.cache) {
9786
+ (_c = _this.cache).push.apply(_c, __spreadArray([], __read(addedTransactions)));
9787
+ _this.updateCache();
9788
+ }
9789
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
9790
+ _this.toastService.success(MessagesEnum.CREATED_MESSAGE);
9791
+ return addedTransactions;
9792
+ }));
9800
9793
  };
9801
9794
  /**
9802
- * Difference between total bank transactions amount and sum of allocations for passed bank transactions
9795
+ * update existing transaction
9796
+ * @param transaction Transaction instance for updating
9803
9797
  */
9804
- BankTransactionCalculationService.prototype.getUnallocatedAmount = function (bankTransactionCollection, allocations) {
9805
- return bankTransactionCollection.getAmount() - allocations.amount;
9798
+ TransactionService.prototype.update = function (transaction) {
9799
+ var _this = this;
9800
+ return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + transaction.id, transaction)
9801
+ .pipe(operators.map(function (response) {
9802
+ var updatedTransaction = classTransformer.plainToClass(Transaction, response);
9803
+ // @TODO need to upload file in the same backend endpoint with transaction add/update
9804
+ // check if passed new receipt and upload file
9805
+ if (transaction.file) {
9806
+ updatedTransaction.file = transaction.file;
9807
+ _this.uploadReceipt(updatedTransaction);
9808
+ }
9809
+ // @TODO Viktor: implement API for saving of nested transactions
9810
+ if (transaction.transactions.length) {
9811
+ // add parent transaction to child transactions
9812
+ transaction.transactions.forEach(function (childTransaction) {
9813
+ childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: updatedTransaction.id });
9814
+ });
9815
+ // separate child transactions by id existing to define add or update action.
9816
+ var childTransactionsToUpdate = transaction.transactions.filter(function (t) { return t.id; });
9817
+ var childTransactionsToAdd = transaction.transactions.filter(function (t) { return !t.id; });
9818
+ // update child transactions
9819
+ if (childTransactionsToUpdate.length) {
9820
+ _this.updateBatch(childTransactionsToUpdate).subscribe();
9821
+ }
9822
+ // add child transactions
9823
+ if (childTransactionsToAdd.length) {
9824
+ _this.addBatch(childTransactionsToAdd).subscribe();
9825
+ }
9826
+ }
9827
+ _this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
9828
+ replace(_this.cache, updatedTransaction);
9829
+ _this.updateCache();
9830
+ return updatedTransaction;
9831
+ }));
9806
9832
  };
9807
9833
  /**
9808
- * Check if bank transaction is allocated
9834
+ * update multiple transactions
9835
+ * @param transactions list of transactions for updating
9809
9836
  */
9810
- BankTransactionCalculationService.prototype.isAllocated = function (bankTransaction, allocations) {
9811
- return bankTransaction.amount === this.getAllocatedAmount(new BankTransactionCollection([bankTransaction]), allocations);
9837
+ TransactionService.prototype.updateBatch = function (transactions) {
9838
+ var _this = this;
9839
+ return this.http.put(this.environment.apiV2 + "/" + this.url, transactions)
9840
+ .pipe(operators.map(function (response) {
9841
+ var updatedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
9842
+ updatedTransactions.forEach(function (updatedTransaction) {
9843
+ replace(_this.cache, updatedTransaction);
9844
+ });
9845
+ _this.updateCache();
9846
+ return updatedTransactions;
9847
+ }));
9812
9848
  };
9813
9849
  /**
9814
- * Get collection of allocated bank transactions
9815
- * @TODO Alex: consider to move to collection
9850
+ * delete transaction and related transactions
9851
+ * @param model
9816
9852
  */
9817
- BankTransactionCalculationService.prototype.getAllocatedBankTransactions = function (bankTransactions, allocations) {
9853
+ TransactionService.prototype.delete = function (model) {
9818
9854
  var _this = this;
9819
- return new BankTransactionCollection(bankTransactions.items.filter(function (bankTransaction) {
9820
- return _this.isAllocated(bankTransaction, allocations);
9855
+ return this.http.delete(this.environment.apiV2 + "/" + this.url + "/" + model.id)
9856
+ .pipe(operators.map(function () {
9857
+ _this.cache = _this.cache.filter(function (transaction) {
9858
+ var _a;
9859
+ // when delete transfer we delete actually 2 transactions
9860
+ if (model.isTransfer) {
9861
+ var ids = [model.id];
9862
+ // get id of related transfer transaction
9863
+ if (model.transfer) {
9864
+ // just take id if we delete source transaction
9865
+ ids.push(model.transfer.id);
9866
+ }
9867
+ else {
9868
+ // find source transaction id if we delete destination transaction
9869
+ ids.push(_this.cache.find(function (t) { return t.transfer.id === model.id; }).id);
9870
+ }
9871
+ return !ids.includes(transaction.id);
9872
+ }
9873
+ return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
9874
+ });
9875
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_DELETED, model));
9876
+ _this.toastService.success(MessagesEnum.DELETED_MESSAGE);
9877
+ _this.updateCache();
9878
+ _this.transactionDeleted.emit(model);
9821
9879
  }));
9822
9880
  };
9823
9881
  /**
9824
- * Get collection of unallocated bank transactions
9825
- * @TODO Alex: consider to move to collection
9882
+ * upload transaction receipt image
9883
+ * @param transaction Еhe transaction for which the receipt will be imported
9826
9884
  */
9827
- BankTransactionCalculationService.prototype.getUnallocatedBankTransactions = function (bankTransactions, allocations) {
9885
+ TransactionService.prototype.uploadReceipt = function (transaction) {
9828
9886
  var _this = this;
9829
- return new BankTransactionCollection(bankTransactions.items.filter(function (bankTransaction) {
9830
- return !_this.isAllocated(bankTransaction, allocations);
9831
- }));
9887
+ var formData = new FormData();
9888
+ formData.append('file', transaction.file);
9889
+ transaction.receipt = null;
9890
+ this.http.post(this.environment.apiV2 + "/" + this.url + "/" + transaction.id + "/receipts", formData)
9891
+ .subscribe(function (receiptResponse) {
9892
+ // we don't need to keep file after save
9893
+ transaction.file = null;
9894
+ transaction.receipt = classTransformer.plainToClass(TransactionReceipt, receiptResponse);
9895
+ replace(_this.cache, transaction);
9896
+ _this.updateCache();
9897
+ });
9832
9898
  };
9833
9899
  /**
9834
- * Allocated sum of credit transactions
9900
+ * calculate gross income amount based on transaction amount and taxes (fees)
9901
+ * @param transaction Transaction instance for calculation
9835
9902
  */
9836
- BankTransactionCalculationService.prototype.getCreditAmount = function (bankTransactions, allocations) {
9837
- return allocations.getByBankTransactionsIds(bankTransactions.creditTransactions.getIds()).amount;
9903
+ TransactionService.prototype.calculateGrossAmount = function (transaction) {
9904
+ var amount = transaction.amount || 0;
9905
+ // gross income amount includes amount of fees for property tank and tax for work tank
9906
+ if (transaction.isPropertyTank()) {
9907
+ amount += transaction.transactions.reduce(function (sum, item) { return sum + item.amount; }, 0);
9908
+ }
9909
+ else {
9910
+ // @TODO Alex: fix logic after TT-641 ready
9911
+ amount += (transaction.tax || 0);
9912
+ }
9913
+ return amount;
9838
9914
  };
9839
9915
  /**
9840
- * Allocated sum of debit transactions
9916
+ * get label for transaction tax field depended of selected chart account.
9917
+ * tax type depends of chart account heading or category.
9841
9918
  */
9842
- BankTransactionCalculationService.prototype.getDebitAmount = function (bankTransactions, allocations) {
9843
- return allocations.getByBankTransactionsIds(bankTransactions.debitTransactions.getIds()).amount;
9919
+ TransactionService.prototype.getTaxLabel = function (chartAccounts) {
9920
+ var _a, _b;
9921
+ // get simple array of ids from enum with taxable chart accounts headings
9922
+ var taxableCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxableEnum)
9923
+ .map(function (item) { return item.value; });
9924
+ // get simple array of ids from enum with tax deductible chart accounts headings
9925
+ var deductibleCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxDeductibleEnum)
9926
+ .map(function (item) { return item.value; });
9927
+ // check if one of ids arrays includes current chart accounts heading id and set tax label
9928
+ // otherwise label is empty for this class
9929
+ switch (true) {
9930
+ case taxableCAHeadingsIds.includes((_a = chartAccounts.heading) === null || _a === void 0 ? void 0 : _a.id):
9931
+ return exports.ChartAccountsTaxLabelsEnum.TAX_PAID;
9932
+ case deductibleCAHeadingsIds.includes((_b = chartAccounts.heading) === null || _b === void 0 ? void 0 : _b.id):
9933
+ return exports.ChartAccountsTaxLabelsEnum.TAX_DEDUCTED;
9934
+ case CHART_ACCOUNTS_CATEGORIES.workIncome.includes(chartAccounts.category):
9935
+ return exports.ChartAccountsTaxLabelsEnum.TAX_WITHHELD;
9936
+ default:
9937
+ return null;
9938
+ }
9844
9939
  };
9845
- return BankTransactionCalculationService;
9846
- }());
9847
- BankTransactionCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
9848
- BankTransactionCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, providedIn: 'root' });
9849
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, decorators: [{
9940
+ /**
9941
+ * Listen to EventDispatcherService event related to Depreciation changing
9942
+ */
9943
+ TransactionService.prototype.listenDepreciationChange = function () {
9944
+ var _this = this;
9945
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.DEPRECIATION_DELETED).subscribe(function () {
9946
+ _this.fetch()
9947
+ .subscribe(function (transactions) {
9948
+ _this.cache = transactions;
9949
+ _this.updateCache();
9950
+ });
9951
+ });
9952
+ };
9953
+ /**
9954
+ * Listen to EventDispatcherService event related to Property Share changing
9955
+ */
9956
+ TransactionService.prototype.listenPropertyShareUpdate = function () {
9957
+ var _this = this;
9958
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED).subscribe(function () { return _this.resetCache(); });
9959
+ };
9960
+ return TransactionService;
9961
+ }(RestService));
9962
+ TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
9963
+ TransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, providedIn: 'root' });
9964
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, decorators: [{
9850
9965
  type: i0.Injectable,
9851
9966
  args: [{
9852
9967
  providedIn: 'root'
9853
9968
  }]
9854
9969
  }] });
9855
9970
 
9856
- var BankAccountCalculationService = /** @class */ (function () {
9857
- function BankAccountCalculationService(bankTransactionCalculationService) {
9858
- this.bankTransactionCalculationService = bankTransactionCalculationService;
9971
+ /**
9972
+ * Service handling user's account setup process.
9973
+ * Checks required steps and their completion
9974
+ */
9975
+ var AccountSetupService = /** @class */ (function () {
9976
+ function AccountSetupService(clientIncomeTypesService, propertyService, incomeSourceService, bankAccountsService, transactionAllocationService, vehicleClaimService, transactionService) {
9977
+ this.clientIncomeTypesService = clientIncomeTypesService;
9978
+ this.propertyService = propertyService;
9979
+ this.incomeSourceService = incomeSourceService;
9980
+ this.bankAccountsService = bankAccountsService;
9981
+ this.transactionAllocationService = transactionAllocationService;
9982
+ this.vehicleClaimService = vehicleClaimService;
9983
+ this.transactionService = transactionService;
9984
+ this.cacheSubject = new rxjs.ReplaySubject(1);
9859
9985
  }
9860
9986
  /**
9861
- * Sum of bank accounts opening balances and their bank transactions allocated amounts
9987
+ * Get list of account setup items for current user
9862
9988
  */
9863
- BankAccountCalculationService.prototype.getTaxTankBalance = function (bankAccounts, bankTransactions, allocations) {
9864
- return bankAccounts.getOpeningBalance() +
9865
- this.bankTransactionCalculationService.getAllocatedAmount(bankTransactions.getByBankAccountsIds(bankAccounts.getIds()), allocations);
9989
+ AccountSetupService.prototype.get = function () {
9990
+ var _this = this;
9991
+ if (!this.cache) {
9992
+ this.clientIncomeTypesService.get().subscribe(function (incomeTypes) {
9993
+ _this.clientIncomeTypesId = incomeTypes.id;
9994
+ rxjs.combineLatest(_this.createBatch(incomeTypes)).subscribe(function (items) {
9995
+ _this.cache = new AccountSetupItemCollection(items);
9996
+ _this.cacheSubject.next(_this.cache);
9997
+ });
9998
+ });
9999
+ }
10000
+ return this.cacheSubject.asObservable();
9866
10001
  };
9867
10002
  /**
9868
- * get difference between total loans amount and total cash amount
10003
+ * Prepare client income types to update to hide depended account setup items
9869
10004
  */
9870
- BankAccountCalculationService.prototype.getNetPosition = function (bankAccounts, bankTransactions, allocations) {
9871
- return bankAccounts.currentBalance - this.getTaxTankBalance(bankAccounts.getLoanAccounts(), bankTransactions, allocations);
10005
+ AccountSetupService.prototype.prepareIncomeTypes = function (item) {
10006
+ return classTransformer.plainToClass(ClientIncomeTypes, Object.assign({ id: this.clientIncomeTypesId }, fromPairs__default["default"](item.clientIncomeTypes.map(function (type) { return [type, false]; }))));
9872
10007
  };
9873
- return BankAccountCalculationService;
10008
+ /**
10009
+ * Get a single AccountSetupItem and check it's completion
10010
+ */
10011
+ AccountSetupService.prototype.create = function (itemType, request) {
10012
+ return request.pipe(operators.map(function (result) {
10013
+ var item = ACCOUNT_SETUP_ITEMS[itemType];
10014
+ if (result.length) {
10015
+ item.isCompleted = true;
10016
+ }
10017
+ return item;
10018
+ }));
10019
+ };
10020
+ /**
10021
+ * Get batch of requests to get list of required AccountSetupItem's.
10022
+ * Some items are optional and depends of user's client income types
10023
+ */
10024
+ AccountSetupService.prototype.createBatch = function (incomeTypes) {
10025
+ var batch = [];
10026
+ // Salary item is completed when user added salary income source
10027
+ if (incomeTypes.salary) {
10028
+ batch.push(this.create(AccountSetupItemsEnum.SALARY, this.getIncomeSourcesByType(exports.IncomeSourceTypeEnum.SALARY)));
10029
+ }
10030
+ // Other income item is completed when user added at least one other income source
10031
+ if (incomeTypes.dividends || incomeTypes.other) {
10032
+ batch.push(this.create(AccountSetupItemsEnum.OTHER_INCOME, this.getIncomeSourcesByType(exports.IncomeSourceTypeEnum.OTHER)));
10033
+ }
10034
+ // Rental income item is completed when user added at least one property
10035
+ if (incomeTypes.property) {
10036
+ batch.push(this.create(AccountSetupItemsEnum.PROPERTY, this.propertyService.get()));
10037
+ }
10038
+ // Bank feeds item is completed when user added at least one bank account (basiq or manual)
10039
+ batch.push(this.create(AccountSetupItemsEnum.BANK_FEEDS, this.bankAccountsService.get()));
10040
+ // Logbook item is completed when user has at least one vehicle claim with any method (klms or logbook)
10041
+ batch.push(this.getLogbookItem());
10042
+ // @TODO waiting for sole tank forecast page
10043
+ // Sole item is completed when user added at least one sole income source
10044
+ // if (incomeTypes.soleTrader) {
10045
+ // batch.push(
10046
+ // this.prepareItem(
10047
+ // AccountSetupItemsEnum.SOLE_INCOME,
10048
+ // this.getIncomeSourcesByType(IncomeSourceTypeEnum.SOLE)
10049
+ // )
10050
+ // );
10051
+ // }
10052
+ // Allocation item is completed when user added at least one transaction allocation
10053
+ batch.push(this.create(AccountSetupItemsEnum.TRANSACTION, this.transactionAllocationService.get()));
10054
+ return batch;
10055
+ };
10056
+ /**
10057
+ * @TODO work with collection when services refactored
10058
+ */
10059
+ AccountSetupService.prototype.getIncomeSourcesByType = function (type) {
10060
+ return this.incomeSourceService.get().pipe(operators.map(function (incomeSources) {
10061
+ return new IncomeSourceCollection(incomeSources).getBy('type', type).toArray();
10062
+ }));
10063
+ };
10064
+ /**
10065
+ * Show logbook item when user has at least 1 vehicle transaction
10066
+ */
10067
+ AccountSetupService.prototype.getLogbookItem = function () {
10068
+ return rxjs.combineLatest([
10069
+ this.transactionService.get(),
10070
+ this.create(AccountSetupItemsEnum.WORK_LOGBOOK, this.vehicleClaimService.get())
10071
+ ]).pipe(operators.map(function (_a) {
10072
+ var _b = __read(_a, 2), transactions = _b[0], item = _b[1];
10073
+ if (new TransactionCollection(transactions).getVehicleTransactions().length) {
10074
+ return item;
10075
+ }
10076
+ return null;
10077
+ }));
10078
+ };
10079
+ return AccountSetupService;
9874
10080
  }());
9875
- BankAccountCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, deps: [{ token: BankTransactionCalculationService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
9876
- BankAccountCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, providedIn: 'root' });
9877
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, decorators: [{
10081
+ AccountSetupService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, deps: [{ token: ClientIncomeTypesService }, { token: PropertyService }, { token: IncomeSourceService }, { token: BankAccountService }, { token: TransactionAllocationService }, { token: VehicleClaimService }, { token: TransactionService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
10082
+ AccountSetupService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, providedIn: 'root' });
10083
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AccountSetupService, decorators: [{
9878
10084
  type: i0.Injectable,
9879
10085
  args: [{
9880
10086
  providedIn: 'root'
9881
10087
  }]
9882
- }], ctorParameters: function () { return [{ type: BankTransactionCalculationService }]; } });
10088
+ }], ctorParameters: function () { return [{ type: ClientIncomeTypesService }, { type: PropertyService }, { type: IncomeSourceService }, { type: BankAccountService }, { type: TransactionAllocationService }, { type: VehicleClaimService }, { type: TransactionService }]; } });
9883
10089
 
9884
- /**
9885
- * BankConnection means user account at specific bank (usually each user has only one at the same bank)
9886
- * service handles BankConnection management
9887
- */
9888
- var BankConnectionService = /** @class */ (function (_super) {
9889
- __extends(BankConnectionService, _super);
9890
- function BankConnectionService() {
9891
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
9892
- _this.modelClass = BankConnection;
9893
- _this.url = 'bank-connections';
9894
- return _this;
10090
+ var AddressService = /** @class */ (function () {
10091
+ function AddressService(http, environment) {
10092
+ this.http = http;
10093
+ this.environment = environment;
10094
+ this.countriesSubject = new rxjs.ReplaySubject(1);
9895
10095
  }
9896
- BankConnectionService.prototype.listenEvents = function () {
9897
- this.listenToAddedBankAccounts();
9898
- };
9899
- BankConnectionService.prototype.post = function (bankConnection) {
9900
- var _this = this;
9901
- return this.http.post(this.environment.apiV2 + "/" + this.url, bankConnection)
9902
- .pipe(operators.map(function (bankConnectionBase) {
9903
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.BANK_CONNECTION_ADDED, null));
9904
- return classTransformer.plainToClass(BankConnection, bankConnectionBase);
9905
- }));
9906
- };
9907
- BankConnectionService.prototype.listenToAddedBankAccounts = function () {
10096
+ AddressService.prototype.getCountries = function () {
9908
10097
  var _this = this;
9909
- this.eventDispatcherService.on(exports.AppEventTypeEnum.BANK_ACCOUNT_CREATED).subscribe(function () {
9910
- _this.resetCache();
9911
- });
10098
+ if (!this._countries) {
10099
+ this.http.get(this.environment.apiV2 + "/countries")
10100
+ .pipe(operators.map(function (response) {
10101
+ return response['hydra:member'].map(function (item) { return classTransformer.plainToClass(Country, item); });
10102
+ }))
10103
+ .subscribe(function (countries) {
10104
+ _this._countries = countries;
10105
+ _this.countriesSubject.next(countries);
10106
+ });
10107
+ }
10108
+ return this.countriesSubject.asObservable();
9912
10109
  };
9913
- return BankConnectionService;
9914
- }(RestService));
9915
- BankConnectionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
9916
- BankConnectionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, providedIn: 'root' });
9917
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, decorators: [{
10110
+ return AddressService;
10111
+ }());
10112
+ AddressService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, deps: [{ token: i1__namespace.HttpClient }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
10113
+ AddressService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, providedIn: 'root' });
10114
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AddressService, decorators: [{
9918
10115
  type: i0.Injectable,
9919
10116
  args: [{
9920
10117
  providedIn: 'root'
9921
10118
  }]
9922
- }] });
10119
+ }], ctorParameters: function () {
10120
+ return [{ type: i1__namespace.HttpClient }, { type: undefined, decorators: [{
10121
+ type: i0.Inject,
10122
+ args: ['environment']
10123
+ }] }];
10124
+ } });
9923
10125
 
9924
10126
  /**
9925
- * Service for bank transactions business logic
10127
+ * Service to work with assets (documents, receipts, e.t.c.)
9926
10128
  */
9927
- var BankTransactionService = /** @class */ (function (_super) {
9928
- __extends(BankTransactionService, _super);
9929
- function BankTransactionService() {
9930
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
9931
- // url part for BankTransaction API
9932
- _this.url = 'bank-transactions';
9933
- _this.modelClass = BankTransaction;
9934
- return _this;
10129
+ var AssetsService = /** @class */ (function () {
10130
+ function AssetsService(http, userSwitcherService, environment) {
10131
+ this.http = http;
10132
+ this.userSwitcherService = userSwitcherService;
10133
+ this.environment = environment;
10134
+ this.impersonatedClient = this.userSwitcherService.get();
9935
10135
  }
9936
- BankTransactionService.prototype.listenEvents = function () {
9937
- this.listenBankTransactionsImport();
9938
- };
9939
- ;
9940
10136
  /**
9941
- * get list of bank transactions for passed bank account id
9942
- * @param bankAccountId Id of bank account we search bank transactions for
10137
+ * Get asset link
10138
+ * @param asset to get the link for
9943
10139
  */
9944
- BankTransactionService.prototype.getByBankAccountId = function (bankAccountId) {
9945
- return this.get()
9946
- .pipe(operators.map(function (bankTransactions) {
9947
- return bankTransactions.filter(function (bankTransaction) { return bankTransaction.bankAccount.id === bankAccountId; });
9948
- }));
10140
+ AssetsService.prototype.getLink = function (asset) {
10141
+ return this.http.get(this.environment.apiV2 + "/assets/" + asset.type + "/" + asset.id);
9949
10142
  };
9950
10143
  /**
9951
- * Get list of bank transactions for provided financial year
9952
- * @TODO VIK/Alex: consider to use one endpoint to get bank transactions for 2 fin years
10144
+ * Download asset
10145
+ * @param asset which should be downloaded
10146
+ * @TODO refactor
9953
10147
  */
9954
- BankTransactionService.prototype.getTransactionsByYear = function (finYear) {
9955
- return this.http.get(this.environment.apiV2 + "/bank-transactions?financialYear=" + finYear)
9956
- .pipe(operators.map(function (bankTransactionsBase) {
9957
- return bankTransactionsBase.map(function (bankTransaction) { return classTransformer.plainToClass(BankTransaction, bankTransaction); });
9958
- }));
10148
+ AssetsService.prototype.download = function (asset) {
10149
+ return this.environment.apiV2 + "/assets/" + asset.type + "/" + asset.id + "/download?bearer=" + localStorage.getItem('token') + (this.impersonatedClient ? "&_switch_user=" + this.impersonatedClient : '');
9959
10150
  };
10151
+ // @Todo refactor to event dispatcher
9960
10152
  /**
9961
- * import bank transactions from csv file
9962
- * @param bankAccountId Bank account id we import bank transactions for
9963
- * @param file File with bank transactions for import
10153
+ * Delete asset
10154
+ * @param entityId: id of asset main entity (property, folder, transaction, e.t.c.)
10155
+ * @param asset which should be deleted
9964
10156
  */
9965
- BankTransactionService.prototype.import = function (bankAccountId, file) {
9966
- var _this = this;
9967
- var formData = new FormData();
9968
- formData.append('file', file);
9969
- return this.http.post(this.environment.apiV2 + "/bank-accounts/" + bankAccountId + "/bank-transaction-imports", formData)
9970
- .pipe(operators.map(function (response) {
9971
- var _a;
9972
- var newBankTransactions = response.map(function (bankTransaction) { return classTransformer.plainToClass(BankTransaction, bankTransaction); });
9973
- // push new items to cache only if we already have cache. Otherwise cache will contain only new items.
9974
- if (_this.cache) {
9975
- // just current year's transactions should be added
9976
- (_a = _this.cache).push.apply(_a, __spreadArray([], __read(newBankTransactions.filter(function (bt) { return new FinancialYear().includes(bt.date); }))));
9977
- _this.updateCache();
9978
- }
9979
- return newBankTransactions;
9980
- }));
9981
- };
9982
- BankTransactionService.prototype.listenBankTransactionsImport = function () {
9983
- var _this = this;
9984
- this.eventDispatcherService.on(exports.AppEventTypeEnum.NOTIFICATION_ADDED).subscribe(function (notification) {
9985
- if (!notification.isRead && notification.eventType === exports.UserEventTypeClientTypeEnum.BASIQ_FIRST_IMPORT_COMPLETE) {
9986
- _this.resetCache();
9987
- }
9988
- });
10157
+ AssetsService.prototype.delete = function (entityId, asset) {
10158
+ return this.http.delete(this.environment.apiV2 + "/" + asset.entityType + "/" + entityId + "/" + asset.type + "/" + asset.id);
9989
10159
  };
9990
- return BankTransactionService;
9991
- }(RestService));
9992
- BankTransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
9993
- BankTransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, providedIn: 'root' });
9994
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, decorators: [{
10160
+ return AssetsService;
10161
+ }());
10162
+ AssetsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, deps: [{ token: i1__namespace.HttpClient }, { token: UserSwitcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
10163
+ AssetsService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, providedIn: 'root' });
10164
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: AssetsService, decorators: [{
9995
10165
  type: i0.Injectable,
9996
10166
  args: [{
9997
10167
  providedIn: 'root'
9998
10168
  }]
9999
- }] });
10000
-
10001
- /**
10002
- * basiq is a middleman between bank and user
10003
- * service is responsible for fetching bank related information
10004
- */
10169
+ }], ctorParameters: function () {
10170
+ return [{ type: i1__namespace.HttpClient }, { type: UserSwitcherService }, { type: undefined, decorators: [{
10171
+ type: i0.Inject,
10172
+ args: ['environment']
10173
+ }] }];
10174
+ } });
10175
+
10176
+ /**
10177
+ * Service that handling banks logic
10178
+ */
10179
+ var BankService = /** @class */ (function (_super) {
10180
+ __extends(BankService, _super);
10181
+ function BankService() {
10182
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
10183
+ _this.modelClass = Bank;
10184
+ _this.url = 'banks';
10185
+ _this.isHydra = true;
10186
+ return _this;
10187
+ }
10188
+ return BankService;
10189
+ }(RestService));
10190
+ BankService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
10191
+ BankService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, providedIn: 'root' });
10192
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankService, decorators: [{
10193
+ type: i0.Injectable,
10194
+ args: [{
10195
+ providedIn: 'root'
10196
+ }]
10197
+ }] });
10198
+
10199
+ /**
10200
+ * @TODO move to collection
10201
+ */
10202
+ var BankTransactionCalculationService = /** @class */ (function () {
10203
+ function BankTransactionCalculationService() {
10204
+ }
10205
+ /**
10206
+ * Sum of allocations for passed bank transactions
10207
+ */
10208
+ BankTransactionCalculationService.prototype.getAllocatedAmount = function (bankTransactions, allocations) {
10209
+ return allocations.getByBankTransactionsIds(bankTransactions.getIds()).amount;
10210
+ };
10211
+ /**
10212
+ * Difference between total bank transactions amount and sum of allocations for passed bank transactions
10213
+ */
10214
+ BankTransactionCalculationService.prototype.getUnallocatedAmount = function (bankTransactionCollection, allocations) {
10215
+ return bankTransactionCollection.getAmount() - allocations.amount;
10216
+ };
10217
+ /**
10218
+ * Check if bank transaction is allocated
10219
+ */
10220
+ BankTransactionCalculationService.prototype.isAllocated = function (bankTransaction, allocations) {
10221
+ return bankTransaction.amount === this.getAllocatedAmount(new BankTransactionCollection([bankTransaction]), allocations);
10222
+ };
10223
+ /**
10224
+ * Get collection of allocated bank transactions
10225
+ * @TODO Alex: consider to move to collection
10226
+ */
10227
+ BankTransactionCalculationService.prototype.getAllocatedBankTransactions = function (bankTransactions, allocations) {
10228
+ var _this = this;
10229
+ return new BankTransactionCollection(bankTransactions.items.filter(function (bankTransaction) {
10230
+ return _this.isAllocated(bankTransaction, allocations);
10231
+ }));
10232
+ };
10233
+ /**
10234
+ * Get collection of unallocated bank transactions
10235
+ * @TODO Alex: consider to move to collection
10236
+ */
10237
+ BankTransactionCalculationService.prototype.getUnallocatedBankTransactions = function (bankTransactions, allocations) {
10238
+ var _this = this;
10239
+ return new BankTransactionCollection(bankTransactions.items.filter(function (bankTransaction) {
10240
+ return !_this.isAllocated(bankTransaction, allocations);
10241
+ }));
10242
+ };
10243
+ /**
10244
+ * Allocated sum of credit transactions
10245
+ */
10246
+ BankTransactionCalculationService.prototype.getCreditAmount = function (bankTransactions, allocations) {
10247
+ return allocations.getByBankTransactionsIds(bankTransactions.creditTransactions.getIds()).amount;
10248
+ };
10249
+ /**
10250
+ * Allocated sum of debit transactions
10251
+ */
10252
+ BankTransactionCalculationService.prototype.getDebitAmount = function (bankTransactions, allocations) {
10253
+ return allocations.getByBankTransactionsIds(bankTransactions.debitTransactions.getIds()).amount;
10254
+ };
10255
+ return BankTransactionCalculationService;
10256
+ }());
10257
+ BankTransactionCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
10258
+ BankTransactionCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, providedIn: 'root' });
10259
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionCalculationService, decorators: [{
10260
+ type: i0.Injectable,
10261
+ args: [{
10262
+ providedIn: 'root'
10263
+ }]
10264
+ }] });
10265
+
10266
+ var BankAccountCalculationService = /** @class */ (function () {
10267
+ function BankAccountCalculationService(bankTransactionCalculationService) {
10268
+ this.bankTransactionCalculationService = bankTransactionCalculationService;
10269
+ }
10270
+ /**
10271
+ * Sum of bank accounts opening balances and their bank transactions allocated amounts
10272
+ */
10273
+ BankAccountCalculationService.prototype.getTaxTankBalance = function (bankAccounts, bankTransactions, allocations) {
10274
+ return bankAccounts.getOpeningBalance() +
10275
+ this.bankTransactionCalculationService.getAllocatedAmount(bankTransactions.getByBankAccountsIds(bankAccounts.getIds()), allocations);
10276
+ };
10277
+ /**
10278
+ * get difference between total loans amount and total cash amount
10279
+ */
10280
+ BankAccountCalculationService.prototype.getNetPosition = function (bankAccounts, bankTransactions, allocations) {
10281
+ return bankAccounts.currentBalance - this.getTaxTankBalance(bankAccounts.getLoanAccounts(), bankTransactions, allocations);
10282
+ };
10283
+ return BankAccountCalculationService;
10284
+ }());
10285
+ BankAccountCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, deps: [{ token: BankTransactionCalculationService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
10286
+ BankAccountCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, providedIn: 'root' });
10287
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankAccountCalculationService, decorators: [{
10288
+ type: i0.Injectable,
10289
+ args: [{
10290
+ providedIn: 'root'
10291
+ }]
10292
+ }], ctorParameters: function () { return [{ type: BankTransactionCalculationService }]; } });
10293
+
10294
+ /**
10295
+ * BankConnection means user account at specific bank (usually each user has only one at the same bank)
10296
+ * service handles BankConnection management
10297
+ */
10298
+ var BankConnectionService = /** @class */ (function (_super) {
10299
+ __extends(BankConnectionService, _super);
10300
+ function BankConnectionService() {
10301
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
10302
+ _this.modelClass = BankConnection;
10303
+ _this.url = 'bank-connections';
10304
+ return _this;
10305
+ }
10306
+ BankConnectionService.prototype.listenEvents = function () {
10307
+ this.listenToAddedBankAccounts();
10308
+ };
10309
+ BankConnectionService.prototype.post = function (bankConnection) {
10310
+ var _this = this;
10311
+ return this.http.post(this.environment.apiV2 + "/" + this.url, bankConnection)
10312
+ .pipe(operators.map(function (bankConnectionBase) {
10313
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.BANK_CONNECTION_ADDED, null));
10314
+ return classTransformer.plainToClass(BankConnection, bankConnectionBase);
10315
+ }));
10316
+ };
10317
+ BankConnectionService.prototype.listenToAddedBankAccounts = function () {
10318
+ var _this = this;
10319
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.BANK_ACCOUNT_CREATED).subscribe(function () {
10320
+ _this.resetCache();
10321
+ });
10322
+ };
10323
+ return BankConnectionService;
10324
+ }(RestService));
10325
+ BankConnectionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
10326
+ BankConnectionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, providedIn: 'root' });
10327
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankConnectionService, decorators: [{
10328
+ type: i0.Injectable,
10329
+ args: [{
10330
+ providedIn: 'root'
10331
+ }]
10332
+ }] });
10333
+
10334
+ /**
10335
+ * Service for bank transactions business logic
10336
+ */
10337
+ var BankTransactionService = /** @class */ (function (_super) {
10338
+ __extends(BankTransactionService, _super);
10339
+ function BankTransactionService() {
10340
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
10341
+ // url part for BankTransaction API
10342
+ _this.url = 'bank-transactions';
10343
+ _this.modelClass = BankTransaction;
10344
+ return _this;
10345
+ }
10346
+ BankTransactionService.prototype.listenEvents = function () {
10347
+ this.listenBankTransactionsImport();
10348
+ };
10349
+ ;
10350
+ /**
10351
+ * get list of bank transactions for passed bank account id
10352
+ * @param bankAccountId Id of bank account we search bank transactions for
10353
+ */
10354
+ BankTransactionService.prototype.getByBankAccountId = function (bankAccountId) {
10355
+ return this.get()
10356
+ .pipe(operators.map(function (bankTransactions) {
10357
+ return bankTransactions.filter(function (bankTransaction) { return bankTransaction.bankAccount.id === bankAccountId; });
10358
+ }));
10359
+ };
10360
+ /**
10361
+ * Get list of bank transactions for provided financial year
10362
+ * @TODO VIK/Alex: consider to use one endpoint to get bank transactions for 2 fin years
10363
+ */
10364
+ BankTransactionService.prototype.getTransactionsByYear = function (finYear) {
10365
+ return this.http.get(this.environment.apiV2 + "/bank-transactions?financialYear=" + finYear)
10366
+ .pipe(operators.map(function (bankTransactionsBase) {
10367
+ return bankTransactionsBase.map(function (bankTransaction) { return classTransformer.plainToClass(BankTransaction, bankTransaction); });
10368
+ }));
10369
+ };
10370
+ /**
10371
+ * import bank transactions from csv file
10372
+ * @param bankAccountId Bank account id we import bank transactions for
10373
+ * @param file File with bank transactions for import
10374
+ */
10375
+ BankTransactionService.prototype.import = function (bankAccountId, file) {
10376
+ var _this = this;
10377
+ var formData = new FormData();
10378
+ formData.append('file', file);
10379
+ return this.http.post(this.environment.apiV2 + "/bank-accounts/" + bankAccountId + "/bank-transaction-imports", formData)
10380
+ .pipe(operators.map(function (response) {
10381
+ var _a;
10382
+ var newBankTransactions = response.map(function (bankTransaction) { return classTransformer.plainToClass(BankTransaction, bankTransaction); });
10383
+ // push new items to cache only if we already have cache. Otherwise cache will contain only new items.
10384
+ if (_this.cache) {
10385
+ // just current year's transactions should be added
10386
+ (_a = _this.cache).push.apply(_a, __spreadArray([], __read(newBankTransactions.filter(function (bt) { return new FinancialYear().includes(bt.date); }))));
10387
+ _this.updateCache();
10388
+ }
10389
+ return newBankTransactions;
10390
+ }));
10391
+ };
10392
+ BankTransactionService.prototype.listenBankTransactionsImport = function () {
10393
+ var _this = this;
10394
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.NOTIFICATION_ADDED).subscribe(function (notification) {
10395
+ if (!notification.isRead && notification.eventType === exports.UserEventTypeClientTypeEnum.BASIQ_FIRST_IMPORT_COMPLETE) {
10396
+ _this.resetCache();
10397
+ }
10398
+ });
10399
+ };
10400
+ return BankTransactionService;
10401
+ }(RestService));
10402
+ BankTransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
10403
+ BankTransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, providedIn: 'root' });
10404
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: BankTransactionService, decorators: [{
10405
+ type: i0.Injectable,
10406
+ args: [{
10407
+ providedIn: 'root'
10408
+ }]
10409
+ }] });
10410
+
10411
+ /**
10412
+ * basiq is a middleman between bank and user
10413
+ * service is responsible for fetching bank related information
10414
+ */
10005
10415
  var BasiqService = /** @class */ (function (_super) {
10006
10416
  __extends(BasiqService, _super);
10007
10417
  function BasiqService() {
@@ -11845,343 +12255,6 @@
11845
12255
  }]
11846
12256
  }] });
11847
12257
 
11848
- function enumToList(data) {
11849
- var list = [];
11850
- for (var key in data) {
11851
- if (Number(key) >= 0) {
11852
- list.push({
11853
- label: data[key],
11854
- value: Number(key)
11855
- });
11856
- }
11857
- }
11858
- return list;
11859
- }
11860
-
11861
- var MessagesEnum;
11862
- (function (MessagesEnum) {
11863
- MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
11864
- MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
11865
- MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
11866
- })(MessagesEnum || (MessagesEnum = {}));
11867
-
11868
- /**
11869
- * Service for transactions business logic
11870
- */
11871
- var TransactionService = /** @class */ (function (_super) {
11872
- __extends(TransactionService, _super);
11873
- function TransactionService() {
11874
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11875
- // url part for Transaction API
11876
- _this.url = 'transactions';
11877
- _this.modelClass = Transaction;
11878
- _this.transactionDeleted = new i0.EventEmitter();
11879
- return _this;
11880
- }
11881
- /**
11882
- * Listen events from Event Dispatcher services
11883
- */
11884
- TransactionService.prototype.listenEvents = function () {
11885
- this.listenDepreciationChange();
11886
- this.listenPropertyShareUpdate();
11887
- };
11888
- /**
11889
- * get list of all user's TaxTank transactions
11890
- */
11891
- TransactionService.prototype.get = function () {
11892
- var _this = this;
11893
- if (!this.cache) {
11894
- // set cache as default empty array to avoid multiple backend requests
11895
- this.cache = [];
11896
- this.fetch()
11897
- .subscribe(function (transactions) {
11898
- _this.cache = transactions;
11899
- _this.updateCache();
11900
- });
11901
- }
11902
- return this.cacheSubject.asObservable().pipe(
11903
- // assign child transactions (fees) to parent transactions
11904
- operators.map(function (transactions) {
11905
- transactions.forEach(function (transaction) {
11906
- transaction.transactions = transactions
11907
- // get list of child transactions
11908
- .filter(function (t) { return t.parentTransaction && t.parentTransaction.id === transaction.id; });
11909
- });
11910
- sort(transactions, 'date', false);
11911
- return transactions;
11912
- }));
11913
- };
11914
- /**
11915
- * Add single new transaction
11916
- * @param model New Transaction instance for saving
11917
- */
11918
- TransactionService.prototype.add = function (model) {
11919
- var _this = this;
11920
- // we don't have POST API endpoint for single transaction
11921
- return this.addBatch([model])
11922
- .pipe(operators.map(function (newTransactions) {
11923
- // @TODO alex
11924
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_CREATED, newTransactions[0]));
11925
- return newTransactions[0];
11926
- }));
11927
- };
11928
- /**
11929
- * get transactions related with property
11930
- */
11931
- TransactionService.prototype.getByPropertyId = function (propertyId) {
11932
- return this.get()
11933
- .pipe(operators.map(function (transactions) {
11934
- return transactions.filter(function (transaction) {
11935
- var _a;
11936
- return ((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id) === propertyId;
11937
- });
11938
- }));
11939
- };
11940
- /**
11941
- * get list of transactions with tank type 'Work'
11942
- */
11943
- TransactionService.prototype.getWorkTransactions = function () {
11944
- return this.get()
11945
- .pipe(operators.map(function (transactions) {
11946
- return transactions.filter(function (transaction) { return transaction.isWorkTank(); });
11947
- }));
11948
- };
11949
- /**
11950
- * Get list of property holding costs (transactions related to vacant land property)
11951
- */
11952
- TransactionService.prototype.getPropertyHoldingCosts = function (propertyId) {
11953
- return this.http.get(this.environment.apiV2 + "/" + this.url + "?propertyId=" + propertyId + "&propertyCategoryId=" + exports.PropertyCategoryListEnum.VACANT_LAND)
11954
- .pipe(operators.map(function (transactionsBase) {
11955
- return transactionsBase.map(function (transactionBase) { return classTransformer.plainToClass(Transaction, transactionBase); });
11956
- }));
11957
- };
11958
- /**
11959
- * get list of taxable transactions with tank type 'Work'
11960
- */
11961
- TransactionService.prototype.getTaxableWorkTransactions = function () {
11962
- return this.getWorkTransactions()
11963
- .pipe(operators.map(function (transactions) {
11964
- return transactions.filter(function (transaction) { return !!transaction.chartAccounts.taxReturnItem; });
11965
- }));
11966
- };
11967
- /**
11968
- * add multiple transactions
11969
- * @param transactions List of new Transaction instances for saving
11970
- */
11971
- TransactionService.prototype.addBatch = function (transactions) {
11972
- var _this = this;
11973
- transactions = ___default["default"].cloneDeep(transactions);
11974
- return this.http.post(this.environment.apiV2 + "/" + this.url, transactions)
11975
- .pipe(operators.map(function (response) {
11976
- var _c;
11977
- var addedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
11978
- transactions.forEach(function (transaction, index) {
11979
- // @TODO backend: need to upload file in the same backend endpoint with transaction add/update
11980
- // check if passed receipt and upload file
11981
- if (transaction.file) {
11982
- transaction.id = response[index].id;
11983
- addedTransactions[index].file = transaction.file;
11984
- _this.uploadReceipt(addedTransactions[index]);
11985
- }
11986
- // @TODO Viktor: implement API for saving of nested transactions
11987
- // add child transactions if exist
11988
- if (transaction.transactions.length) {
11989
- transaction.transactions.forEach(function (childTransaction) {
11990
- childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: addedTransactions[index].id });
11991
- });
11992
- _this.addBatch(transaction.transactions).subscribe();
11993
- }
11994
- // add transfer transaction to cache
11995
- if (transaction.operation === exports.TransactionOperationEnum.TRANSFER) {
11996
- addedTransactions.push(addedTransactions[0].transfer);
11997
- }
11998
- });
11999
- if (_this.cache) {
12000
- (_c = _this.cache).push.apply(_c, __spreadArray([], __read(addedTransactions)));
12001
- _this.updateCache();
12002
- }
12003
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
12004
- _this.toastService.success(MessagesEnum.CREATED_MESSAGE);
12005
- return addedTransactions;
12006
- }));
12007
- };
12008
- /**
12009
- * update existing transaction
12010
- * @param transaction Transaction instance for updating
12011
- */
12012
- TransactionService.prototype.update = function (transaction) {
12013
- var _this = this;
12014
- return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + transaction.id, transaction)
12015
- .pipe(operators.map(function (response) {
12016
- var updatedTransaction = classTransformer.plainToClass(Transaction, response);
12017
- // @TODO need to upload file in the same backend endpoint with transaction add/update
12018
- // check if passed new receipt and upload file
12019
- if (transaction.file) {
12020
- updatedTransaction.file = transaction.file;
12021
- _this.uploadReceipt(updatedTransaction);
12022
- }
12023
- // @TODO Viktor: implement API for saving of nested transactions
12024
- if (transaction.transactions.length) {
12025
- // add parent transaction to child transactions
12026
- transaction.transactions.forEach(function (childTransaction) {
12027
- childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: updatedTransaction.id });
12028
- });
12029
- // separate child transactions by id existing to define add or update action.
12030
- var childTransactionsToUpdate = transaction.transactions.filter(function (t) { return t.id; });
12031
- var childTransactionsToAdd = transaction.transactions.filter(function (t) { return !t.id; });
12032
- // update child transactions
12033
- if (childTransactionsToUpdate.length) {
12034
- _this.updateBatch(childTransactionsToUpdate).subscribe();
12035
- }
12036
- // add child transactions
12037
- if (childTransactionsToAdd.length) {
12038
- _this.addBatch(childTransactionsToAdd).subscribe();
12039
- }
12040
- }
12041
- _this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
12042
- replace(_this.cache, updatedTransaction);
12043
- _this.updateCache();
12044
- return updatedTransaction;
12045
- }));
12046
- };
12047
- /**
12048
- * update multiple transactions
12049
- * @param transactions list of transactions for updating
12050
- */
12051
- TransactionService.prototype.updateBatch = function (transactions) {
12052
- var _this = this;
12053
- return this.http.put(this.environment.apiV2 + "/" + this.url, transactions)
12054
- .pipe(operators.map(function (response) {
12055
- var updatedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
12056
- updatedTransactions.forEach(function (updatedTransaction) {
12057
- replace(_this.cache, updatedTransaction);
12058
- });
12059
- _this.updateCache();
12060
- return updatedTransactions;
12061
- }));
12062
- };
12063
- /**
12064
- * delete transaction and related transactions
12065
- * @param model
12066
- */
12067
- TransactionService.prototype.delete = function (model) {
12068
- var _this = this;
12069
- return this.http.delete(this.environment.apiV2 + "/" + this.url + "/" + model.id)
12070
- .pipe(operators.map(function () {
12071
- _this.cache = _this.cache.filter(function (transaction) {
12072
- var _a;
12073
- // when delete transfer we delete actually 2 transactions
12074
- if (model.isTransfer) {
12075
- var ids = [model.id];
12076
- // get id of related transfer transaction
12077
- if (model.transfer) {
12078
- // just take id if we delete source transaction
12079
- ids.push(model.transfer.id);
12080
- }
12081
- else {
12082
- // find source transaction id if we delete destination transaction
12083
- ids.push(_this.cache.find(function (t) { return t.transfer.id === model.id; }).id);
12084
- }
12085
- return !ids.includes(transaction.id);
12086
- }
12087
- return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
12088
- });
12089
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_DELETED, model));
12090
- _this.toastService.success(MessagesEnum.DELETED_MESSAGE);
12091
- _this.updateCache();
12092
- _this.transactionDeleted.emit(model);
12093
- }));
12094
- };
12095
- /**
12096
- * upload transaction receipt image
12097
- * @param transaction Еhe transaction for which the receipt will be imported
12098
- */
12099
- TransactionService.prototype.uploadReceipt = function (transaction) {
12100
- var _this = this;
12101
- var formData = new FormData();
12102
- formData.append('file', transaction.file);
12103
- transaction.receipt = null;
12104
- this.http.post(this.environment.apiV2 + "/" + this.url + "/" + transaction.id + "/receipts", formData)
12105
- .subscribe(function (receiptResponse) {
12106
- // we don't need to keep file after save
12107
- transaction.file = null;
12108
- transaction.receipt = classTransformer.plainToClass(TransactionReceipt, receiptResponse);
12109
- replace(_this.cache, transaction);
12110
- _this.updateCache();
12111
- });
12112
- };
12113
- /**
12114
- * calculate gross income amount based on transaction amount and taxes (fees)
12115
- * @param transaction Transaction instance for calculation
12116
- */
12117
- TransactionService.prototype.calculateGrossAmount = function (transaction) {
12118
- var amount = transaction.amount || 0;
12119
- // gross income amount includes amount of fees for property tank and tax for work tank
12120
- if (transaction.isPropertyTank()) {
12121
- amount += transaction.transactions.reduce(function (sum, item) { return sum + item.amount; }, 0);
12122
- }
12123
- else {
12124
- // @TODO Alex: fix logic after TT-641 ready
12125
- amount += (transaction.tax || 0);
12126
- }
12127
- return amount;
12128
- };
12129
- /**
12130
- * get label for transaction tax field depended of selected chart account.
12131
- * tax type depends of chart account heading or category.
12132
- */
12133
- TransactionService.prototype.getTaxLabel = function (chartAccounts) {
12134
- var _a, _b;
12135
- // get simple array of ids from enum with taxable chart accounts headings
12136
- var taxableCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxableEnum)
12137
- .map(function (item) { return item.value; });
12138
- // get simple array of ids from enum with tax deductible chart accounts headings
12139
- var deductibleCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxDeductibleEnum)
12140
- .map(function (item) { return item.value; });
12141
- // check if one of ids arrays includes current chart accounts heading id and set tax label
12142
- // otherwise label is empty for this class
12143
- switch (true) {
12144
- case taxableCAHeadingsIds.includes((_a = chartAccounts.heading) === null || _a === void 0 ? void 0 : _a.id):
12145
- return exports.ChartAccountsTaxLabelsEnum.TAX_PAID;
12146
- case deductibleCAHeadingsIds.includes((_b = chartAccounts.heading) === null || _b === void 0 ? void 0 : _b.id):
12147
- return exports.ChartAccountsTaxLabelsEnum.TAX_DEDUCTED;
12148
- case CHART_ACCOUNTS_CATEGORIES.workIncome.includes(chartAccounts.category):
12149
- return exports.ChartAccountsTaxLabelsEnum.TAX_WITHHELD;
12150
- default:
12151
- return null;
12152
- }
12153
- };
12154
- /**
12155
- * Listen to EventDispatcherService event related to Depreciation changing
12156
- */
12157
- TransactionService.prototype.listenDepreciationChange = function () {
12158
- var _this = this;
12159
- this.eventDispatcherService.on(exports.AppEventTypeEnum.DEPRECIATION_DELETED).subscribe(function () {
12160
- _this.fetch()
12161
- .subscribe(function (transactions) {
12162
- _this.cache = transactions;
12163
- _this.updateCache();
12164
- });
12165
- });
12166
- };
12167
- /**
12168
- * Listen to EventDispatcherService event related to Property Share changing
12169
- */
12170
- TransactionService.prototype.listenPropertyShareUpdate = function () {
12171
- var _this = this;
12172
- this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED).subscribe(function () { return _this.resetCache(); });
12173
- };
12174
- return TransactionService;
12175
- }(RestService));
12176
- TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
12177
- TransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, providedIn: 'root' });
12178
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, decorators: [{
12179
- type: i0.Injectable,
12180
- args: [{
12181
- providedIn: 'root'
12182
- }]
12183
- }] });
12184
-
12185
12258
  /**
12186
12259
  * Service to handle Property transactions report items data (get income / expense report items, e.t.c.)
12187
12260
  */
@@ -14079,6 +14152,8 @@
14079
14152
  exports.VehicleClaimForm = VehicleClaimForm;
14080
14153
  exports.VehicleClaimService = VehicleClaimService;
14081
14154
  exports.VehicleCollection = VehicleCollection;
14155
+ exports.VehicleExpense = VehicleExpense;
14156
+ exports.VehicleExpenseCollection = VehicleExpenseCollection;
14082
14157
  exports.VehicleForm = VehicleForm;
14083
14158
  exports.VehicleLogbook = VehicleLogbook;
14084
14159
  exports.VehicleLogbookCollection = VehicleLogbookCollection;