taxtank-core 0.28.36 → 0.28.38

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.
Files changed (30) hide show
  1. package/bundles/taxtank-core.umd.js +313 -118
  2. package/bundles/taxtank-core.umd.js.map +1 -1
  3. package/esm2015/lib/collections/transaction/transaction-base.collection.js +2 -2
  4. package/esm2015/lib/forms/address/address.form.js +149 -0
  5. package/esm2015/lib/forms/address/index.js +2 -0
  6. package/esm2015/lib/forms/index.js +3 -1
  7. package/esm2015/lib/forms/phone/index.js +2 -0
  8. package/esm2015/lib/forms/phone/phone.form.js +15 -0
  9. package/esm2015/lib/forms/sole/sole-contact.form.js +7 -5
  10. package/esm2015/lib/interceptors/corelogic-interceptor.js +19 -20
  11. package/esm2015/lib/models/address/address.js +2 -2
  12. package/esm2015/lib/models/address/country.js +3 -1
  13. package/esm2015/lib/models/endpoint/endpoints.const.js +2 -1
  14. package/esm2015/lib/models/phone/phone.js +8 -1
  15. package/esm2015/lib/models/report/my-tax/my-tax-estimate/my-tax-estimate.js +3 -3
  16. package/esm2015/lib/validators/address-corelogic.validator.js +17 -0
  17. package/esm2015/lib/validators/phone-number.validator.js +11 -0
  18. package/fesm2015/taxtank-core.js +288 -110
  19. package/fesm2015/taxtank-core.js.map +1 -1
  20. package/lib/forms/address/address.form.d.ts +58 -0
  21. package/lib/forms/address/index.d.ts +1 -0
  22. package/lib/forms/index.d.ts +2 -0
  23. package/lib/forms/phone/index.d.ts +1 -0
  24. package/lib/forms/phone/phone.form.d.ts +5 -0
  25. package/lib/interceptors/corelogic-interceptor.d.ts +1 -5
  26. package/lib/models/address/country.d.ts +1 -0
  27. package/lib/models/phone/phone.d.ts +2 -0
  28. package/lib/validators/address-corelogic.validator.d.ts +5 -0
  29. package/lib/validators/phone-number.validator.d.ts +6 -0
  30. package/package.json +1 -1
@@ -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('rxjs/internal/observable/throwError'), require('moment'), require('moment-range'), require('lodash/cloneDeep'), require('event-source-polyfill/src/eventsource.min.js'), require('lodash/compact'), require('lodash/differenceBy'), require('@angular/forms'), require('lodash/merge'), require('lodash/isEqual'), require('lodash/fromPairs'), require('lodash'), require('@angular/router'), require('lodash/clone'), require('html2pdf.js'), 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', 'rxjs/internal/observable/throwError', 'moment', 'moment-range', 'lodash/cloneDeep', 'event-source-polyfill/src/eventsource.min.js', 'lodash/compact', 'lodash/differenceBy', '@angular/forms', 'lodash/merge', 'lodash/isEqual', 'lodash/fromPairs', 'lodash', '@angular/router', 'lodash/clone', 'html2pdf.js', '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.rxjs["internal/observable/throwError"], global.moment$1, global.momentRange, global.cloneDeep$1, global.eventsource_min_js, global.compact, global.differenceBy, global.ng.forms, global.merge, global.isEqual, global.fromPairs, global._, global.ng.router, global.clone, global.html2pdf, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
- })(this, (function (exports, i0, i1$1, i1, rxjs, operators, classTransformer, angularJwt, get, flatten, hasIn, first, last, uniqBy, concat, throwError, moment$1, momentRange, cloneDeep$1, eventsource_min_js, compact, differenceBy, forms, merge, isEqual, fromPairs, _, i1$2, clone, html2pdf, 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/operators'), require('rxjs'), 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('rxjs/internal/observable/throwError'), require('moment'), require('moment-range'), require('lodash/cloneDeep'), require('event-source-polyfill/src/eventsource.min.js'), require('lodash/compact'), require('lodash/differenceBy'), require('@angular/forms'), require('lodash/merge'), require('lodash/isEqual'), require('lodash/fromPairs'), require('lodash'), require('@angular/router'), require('lodash/clone'), require('html2pdf.js'), 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/operators', 'rxjs', 'class-transformer', '@auth0/angular-jwt', 'lodash/get', 'lodash/flatten', 'lodash/hasIn', 'lodash/first', 'lodash/last', 'lodash/uniqBy', 'lodash/concat', 'rxjs/internal/observable/throwError', 'moment', 'moment-range', 'lodash/cloneDeep', 'event-source-polyfill/src/eventsource.min.js', 'lodash/compact', 'lodash/differenceBy', '@angular/forms', 'lodash/merge', 'lodash/isEqual', 'lodash/fromPairs', 'lodash', '@angular/router', 'lodash/clone', 'html2pdf.js', '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.operators, global.rxjs, global.classTransformer, global.angularJwt, global.get, global.flatten, global.hasIn, global.first, global.last, global.uniqBy, global.concat, global.rxjs["internal/observable/throwError"], global.moment$1, global.momentRange, global.cloneDeep$1, global.eventsource_min_js, global.compact, global.differenceBy, global.ng.forms, global.merge, global.isEqual, global.fromPairs, global._, global.ng.router, global.clone, global.html2pdf, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
+ })(this, (function (exports, i0, i1$1, i1, operators, rxjs, classTransformer, angularJwt, get, flatten, hasIn, first, last, uniqBy, concat, throwError, moment$1, momentRange, cloneDeep$1, eventsource_min_js, compact, differenceBy, forms, merge, isEqual, fromPairs, _, i1$2, clone, html2pdf, 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
 
@@ -113,28 +113,27 @@
113
113
  this.corelogicService = corelogicService;
114
114
  this.environment = environment;
115
115
  }
116
- /**
117
- * Check if requested url requested core logic, but not core logic auth api
118
- * @param req
119
- */
120
- CorelogicInterceptor.prototype.addToken = function (req) {
121
- // don't need token for this endpoint
122
- if (req.url.includes(this.environment.coreLogicUrl + "/access/oauth/token")) {
123
- return req;
116
+ CorelogicInterceptor.prototype.intercept = function (request, next) {
117
+ var _this = this;
118
+ // skip non-corelogic requests
119
+ if (!request.url.includes(this.environment.coreLogicUrl)) {
120
+ return next.handle(request);
124
121
  }
125
- // add core logic token to request headers
126
- if (req.url.includes(this.environment.coreLogicUrl)) {
127
- return req.clone({
128
- setHeaders: {
129
- Authorization: 'Bearer ' + this.corelogicService._accessToken
130
- }
131
- });
122
+ // don't need token for this endpoint
123
+ if (request.url.includes(this.environment.coreLogicUrl + "/access/oauth/token")) {
124
+ return next.handle(request);
132
125
  }
133
- // return request without changes if url not related with core logic
134
- return req;
126
+ return this.corelogicService.getAccessToken()
127
+ .pipe(operators.mergeMap(function (token) {
128
+ return next.handle(_this.addToken(request, token));
129
+ }));
135
130
  };
136
- CorelogicInterceptor.prototype.intercept = function (request, next) {
137
- return next.handle(this.addToken(request));
131
+ CorelogicInterceptor.prototype.addToken = function (request, token) {
132
+ return request.clone({
133
+ setHeaders: {
134
+ Authorization: 'Bearer ' + token
135
+ }
136
+ });
138
137
  };
139
138
  return CorelogicInterceptor;
140
139
  }());
@@ -984,6 +983,7 @@
984
983
  CLIENT_MOVEMENTS_GET: new Endpoint('GET', '\\/client-movements'),
985
984
  CLIENT_MOVEMENTS_POST: new Endpoint('POST', '\\/client-movements'),
986
985
  COUNTRIES_GET: new Endpoint('GET', '\\/countries'),
986
+ CORELOGIC_TOKEN_GET: new Endpoint('GET', '/access\\/oauth\\/token.*$'),
987
987
  DEPRECIATIONS_OPENING_GET: new Endpoint('GET', '\\/depreciations\\/\\opening-balance\.\*'),
988
988
  DEPRECIATIONS_GET: new Endpoint('GET', '\\/depreciations'),
989
989
  DEPRECIATIONS_POST: new Endpoint('POST', '\\/depreciations'),
@@ -2563,6 +2563,7 @@
2563
2563
  };
2564
2564
  return Country;
2565
2565
  }(Country$1));
2566
+ Country.australia = classTransformer.plainToClass(Country, { id: 14, name: 'Australia', callingCode: '61' });
2566
2567
 
2567
2568
  exports.AddressTypeEnum = void 0;
2568
2569
  (function (AddressTypeEnum) {
@@ -2589,7 +2590,7 @@
2589
2590
  });
2590
2591
  Object.defineProperty(Address.prototype, "nameLong", {
2591
2592
  get: function () {
2592
- return this.name + ", " + this.city + ", " + this.state;
2593
+ return this.name + " " + this.city + " " + this.state + " " + this.postcode;
2593
2594
  },
2594
2595
  enumerable: false,
2595
2596
  configurable: true
@@ -2657,6 +2658,7 @@
2657
2658
  __extends(Phone, _super);
2658
2659
  function Phone() {
2659
2660
  var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2661
+ _this.country = Country.australia;
2660
2662
  _this.type = exports.PhoneTypeEnum.MOBILE;
2661
2663
  return _this;
2662
2664
  }
@@ -2665,6 +2667,9 @@
2665
2667
  };
2666
2668
  return Phone;
2667
2669
  }(Phone$1));
2670
+ __decorate([
2671
+ classTransformer.Type(function () { return Country; })
2672
+ ], Phone.prototype, "country", void 0);
2668
2673
 
2669
2674
  var Firm = /** @class */ (function (_super) {
2670
2675
  __extends(Firm, _super);
@@ -7848,7 +7853,7 @@
7848
7853
  return _super !== null && _super.apply(this, arguments) || this;
7849
7854
  }
7850
7855
  TransactionBaseCollection.prototype.getClaimAmountByBusiness = function (business) {
7851
- return +this.filterBy('business.id', business.id).items.map(function (transaction) { return transaction instanceof Depreciation ? -transaction.claimAmount : transaction['claimAmount']; }).reduce(function (sum, claimAmount) { return sum + claimAmount; }).toFixed(2);
7856
+ return +this.filterBy('business.id', business.id).items.map(function (transaction) { return transaction instanceof Depreciation ? -transaction.claimAmount : transaction['claimAmount']; }).reduce(function (sum, claimAmount) { return sum + claimAmount; }, 0).toFixed(2);
7852
7857
  };
7853
7858
  return TransactionBaseCollection;
7854
7859
  }(Collection));
@@ -11243,8 +11248,8 @@
11243
11248
  });
11244
11249
  };
11245
11250
  MyTaxEstimate.getLowMiddleIncomeTaxOffsets = function (taxOffsetsReportItem) {
11246
- var taxOffsetLowIncome = taxOffsetsReportItem.details.findBy('name', 'Tax Offset Low Income');
11247
- var taxOffsetLowMiddleIncome = taxOffsetsReportItem.details.findBy('name', 'Tax Offset Low and Middle Income');
11251
+ var taxOffsetLowIncome = taxOffsetsReportItem.items.findBy('title', 'Tax Offset Low Income');
11252
+ var taxOffsetLowMiddleIncome = taxOffsetsReportItem.items.findBy('title', 'Tax Offset Low and Middle Income');
11248
11253
  return taxOffsetLowIncome.amount + taxOffsetLowMiddleIncome.amount;
11249
11254
  };
11250
11255
  MyTaxEstimate.getTaxOffsets = function (taxOffsetsReportItemAmount, lowMiddleIncomeTaxOffsets) {
@@ -17546,93 +17551,6 @@
17546
17551
  return AbstractForm;
17547
17552
  }(forms.FormGroup));
17548
17553
 
17549
- /**
17550
- * Form with loan details.
17551
- * Loan could be created from bank account (Bank Loan) or directly from loan page (Vehicle Loan)
17552
- */
17553
- var LoanForm = /** @class */ (function (_super) {
17554
- __extends(LoanForm, _super);
17555
- function LoanForm(loan) {
17556
- if (loan === void 0) { loan = classTransformer.plainToClass(Loan, {}); }
17557
- var _this = _super.call(this, {
17558
- type: new forms.FormControl(loan.type, forms.Validators.required),
17559
- amount: new forms.FormControl(loan.amount, forms.Validators.required),
17560
- interestRate: new forms.FormControl(loan.interestRate, [forms.Validators.required, forms.Validators.min(0), forms.Validators.max(100)]),
17561
- commencementDate: new forms.FormControl(loan.commencementDate, forms.Validators.required),
17562
- repaymentAmount: new forms.FormControl(loan.repaymentAmount, forms.Validators.required),
17563
- repaymentFrequency: new forms.FormControl(loan.repaymentFrequency, forms.Validators.required),
17564
- term: new forms.FormControl(loan.term, forms.Validators.required),
17565
- // interestType is predefined for vehicle loans
17566
- interestType: new forms.FormControl({ value: loan.interestType, disabled: !loan.bankAccount }, forms.Validators.required),
17567
- // availableRedraw is predefined for vehicle loans
17568
- availableRedraw: new forms.FormControl({ value: loan.availableRedraw, disabled: !loan.bankAccount }, forms.Validators.required),
17569
- // repaymentType is predefined for vehicle loans
17570
- repaymentType: new forms.FormControl({ value: loan.repaymentType, disabled: !loan.bankAccount }, forms.Validators.required),
17571
- }, loan) || this;
17572
- _this.loan = loan;
17573
- // Set data which always the same for vehicle loans
17574
- if (!loan.bankAccount) {
17575
- Object.assign(_this.model, {
17576
- repaymentType: exports.LoanRepaymentTypeEnum.PRINCIPAL_AND_INTEREST,
17577
- availableRedraw: 0,
17578
- interestType: exports.LoanInterestTypeEnum.FIXED_RATE
17579
- });
17580
- }
17581
- _this.updateTermValidation();
17582
- _this.listenEvents();
17583
- return _this;
17584
- }
17585
- LoanForm.prototype.listenEvents = function () {
17586
- // We need to set term automatically only for bank loans.
17587
- // For vehicle loans user should fill it manually with validation depended of frequency
17588
- if (!!this.loan.bankAccount) {
17589
- this.listenTypeChanges();
17590
- }
17591
- else {
17592
- this.listenRepaymentFrequencyChanges();
17593
- }
17594
- };
17595
- /**
17596
- * Set term automatically by loan type changes
17597
- */
17598
- LoanForm.prototype.listenTypeChanges = function () {
17599
- var _this = this;
17600
- this.get('type').valueChanges.subscribe(function (type) {
17601
- _this.get('term').setValue(LoanForm.mortgageLoanTypes.includes(type) ? Loan.mortgageDefaultTerm : Loan.loanDefaultTerm);
17602
- });
17603
- };
17604
- /**
17605
- * term validation depends on selected repaymentFrequency
17606
- */
17607
- LoanForm.prototype.listenRepaymentFrequencyChanges = function () {
17608
- var _this = this;
17609
- this.get('repaymentFrequency').valueChanges.subscribe(function () {
17610
- _this.updateTermValidation();
17611
- });
17612
- };
17613
- /**
17614
- * For vehicle loans term has a maximum value depended of repayment frequency
17615
- */
17616
- LoanForm.prototype.updateTermValidation = function () {
17617
- // no need terms for bank loans
17618
- if (!!this.loan.bankAccount) {
17619
- return;
17620
- }
17621
- var currentRepaymentFrequency = this.get('repaymentFrequency').value;
17622
- // term validation depends on selected repayment frequency, so can not validate when frequency is empty
17623
- // repaymentType is required field, so we don't need to clear validation
17624
- if (!currentRepaymentFrequency) {
17625
- return;
17626
- }
17627
- var termControl = this.get('term');
17628
- var maxTermValue = exports.LoanMaxNumberOfPaymentsEnum[exports.LoanRepaymentFrequencyEnum[currentRepaymentFrequency]];
17629
- termControl.setValidators([forms.Validators.max(maxTermValue)]);
17630
- termControl.updateValueAndValidity();
17631
- };
17632
- return LoanForm;
17633
- }(AbstractForm));
17634
- LoanForm.mortgageLoanTypes = [exports.LoanTypeEnum.MORTGAGE, exports.LoanTypeEnum.HOME_EQUITY_LINE_OF_CREDIT, exports.LoanTypeEnum.HOME_LOAN];
17635
-
17636
17554
  /**
17637
17555
  * Check if at least one form field is true, otherwise form is invalid.
17638
17556
  * Use with groups of boolean form controls (checkbox, toggle, etc.)
@@ -17766,6 +17684,259 @@
17766
17684
  };
17767
17685
  }
17768
17686
 
17687
+ /**
17688
+ * Validator for address, check if corelogic suggestion selected correctly
17689
+ */
17690
+ function addressCorelogicValidator() {
17691
+ return function (form) {
17692
+ if (form.isCorelogicRequired) {
17693
+ if (form.get('corelogicLocId').hasError('required')) {
17694
+ return { address: 'Street, city, state or postal code not specified' };
17695
+ }
17696
+ if (form.get('corelogicRefId').hasError('required')) {
17697
+ return { address: 'Unit/House number not specified' };
17698
+ }
17699
+ }
17700
+ return null;
17701
+ };
17702
+ }
17703
+
17704
+ /**
17705
+ * Address form. Works with corelogic or manual address
17706
+ */
17707
+ var AddressForm = /** @class */ (function (_super) {
17708
+ __extends(AddressForm, _super);
17709
+ /**
17710
+ * @param address instance which should be created/edited
17711
+ * @param isCorelogicRequired for example, for property we need corelogic location even for manual address,
17712
+ * so we have to search corelogic location based on manual fields values
17713
+ */
17714
+ function AddressForm(address, isCorelogicRequired) {
17715
+ if (address === void 0) { address = classTransformer.plainToClass(Address, {}); }
17716
+ if (isCorelogicRequired === void 0) { isCorelogicRequired = false; }
17717
+ var _this = _super.call(this, {
17718
+ // prefill search input with address string for edit case
17719
+ searchQuery: new forms.FormControl(address.address ? address.nameLong : null, forms.Validators.required),
17720
+ type: new forms.FormControl(address.type | exports.AddressTypeEnum.STREET, forms.Validators.required),
17721
+ // Corelogic fields
17722
+ corelogicLocId: new forms.FormControl(address.corelogicLocId, conditionalValidator(function () { return isCorelogicRequired; }, forms.Validators.required)),
17723
+ corelogicRefId: new forms.FormControl(address.corelogicRefId, conditionalValidator(function () { return isCorelogicRequired; }, forms.Validators.required)),
17724
+ // manual fields
17725
+ unitNumber: new forms.FormControl({ value: address.unitNumber, disabled: true }),
17726
+ address: new forms.FormControl({ value: address.address, disabled: true }, forms.Validators.required),
17727
+ city: new forms.FormControl({ value: address.city, disabled: true }, forms.Validators.required),
17728
+ state: new forms.FormControl({ value: address.state, disabled: true }, forms.Validators.required),
17729
+ postcode: new forms.FormControl({ value: address.postcode, disabled: true }, forms.Validators.required),
17730
+ country: new forms.FormControl({ value: address.country || Country.australia, disabled: true }, conditionalValidator(function () { return !isCorelogicRequired; }, forms.Validators.required))
17731
+ }, address, addressCorelogicValidator()) || this;
17732
+ _this.isCorelogicRequired = isCorelogicRequired;
17733
+ /**
17734
+ * Emit event to search address in corelogic when user filled enough data for corelogic
17735
+ */
17736
+ _this.onSearch = new i0.EventEmitter();
17737
+ _this.listenEvents();
17738
+ return _this;
17739
+ }
17740
+ Object.defineProperty(AddressForm.prototype, "manualSearchQuery", {
17741
+ /**
17742
+ * Get search query for corelogic location search based on manual fields values
17743
+ */
17744
+ get: function () {
17745
+ if (!this.isManualSearchAvailable()) {
17746
+ return '';
17747
+ }
17748
+ return this.currentValue.nameLong;
17749
+ },
17750
+ enumerable: false,
17751
+ configurable: true
17752
+ });
17753
+ AddressForm.prototype.listenEvents = function () {
17754
+ this.listenSearchQueryChanges();
17755
+ // no need to search corelogic locality when corelogic is not required
17756
+ if (this.isCorelogicRequired) {
17757
+ this.listenManualFieldsChanges();
17758
+ }
17759
+ };
17760
+ /**
17761
+ * Handle corelogic suggestion select
17762
+ */
17763
+ AddressForm.prototype.onSelectSuggestion = function (suggestion) {
17764
+ // if no suggestion then 'Add manually' option selected
17765
+ if (!suggestion) {
17766
+ this.switchToManual();
17767
+ return;
17768
+ }
17769
+ this.patchValue({
17770
+ corelogicLocId: suggestion.localityId,
17771
+ corelogicRefId: suggestion.propertyId
17772
+ });
17773
+ };
17774
+ /**
17775
+ * Enable manual mode
17776
+ */
17777
+ AddressForm.prototype.switchToManual = function () {
17778
+ this.isManual = true;
17779
+ this.get('searchQuery').disable();
17780
+ this.get('address').enable();
17781
+ this.get('unitNumber').enable();
17782
+ this.get('city').enable();
17783
+ this.get('state').enable();
17784
+ this.get('postcode').enable();
17785
+ if (!this.isCorelogicRequired) {
17786
+ this.get('country').enable();
17787
+ this.get('corelogicLocId').disable();
17788
+ this.get('corelogicRefId').disable();
17789
+ }
17790
+ };
17791
+ /**
17792
+ * Emit event to search address in corelogic when search field changes
17793
+ */
17794
+ AddressForm.prototype.listenSearchQueryChanges = function () {
17795
+ var _this = this;
17796
+ this.get('searchQuery').valueChanges
17797
+ .pipe(
17798
+ // delay to avoid search request for each value change
17799
+ operators.debounceTime(AddressForm.searchDelay),
17800
+ // skip when value not changed
17801
+ operators.distinctUntilChanged(),
17802
+ // value could be a string when user search and suggestion when user select option from autocomplete
17803
+ operators.map(function (value) {
17804
+ // no need to search when value is not actually search string
17805
+ if (!value || value instanceof CorelogicSuggestion) {
17806
+ return '';
17807
+ }
17808
+ // trim to avoid spaces in searchQuery, we should not send request started or finished with spaces
17809
+ // uppercase to make search string similar to corelogic format
17810
+ return value.trim();
17811
+ }),
17812
+ // do nothing when query is too short
17813
+ operators.filter(function (searchQuery) { return searchQuery.length >= AddressForm.minSearchLength; }))
17814
+ .subscribe(function (searchQuery) {
17815
+ _this.onSearch.emit(searchQuery);
17816
+ });
17817
+ };
17818
+ /**
17819
+ * Check if all fields required for manual corelogic search are filled before request sending
17820
+ */
17821
+ AddressForm.prototype.isManualSearchAvailable = function () {
17822
+ return this.get('address').valid && this.get('city').valid && this.get('state').valid && this.get('postcode').valid;
17823
+ };
17824
+ /**
17825
+ * When corelogic is required we have to search address even for manual address
17826
+ */
17827
+ AddressForm.prototype.listenManualFieldsChanges = function () {
17828
+ var _this = this;
17829
+ // subscribe to whole form because no other fields may be changed in this case except manual address fields we need
17830
+ this.valueChanges
17831
+ .pipe(
17832
+ // delay to avoid search request for each value change
17833
+ operators.debounceTime(AddressForm.searchDelay),
17834
+ // do nothing when not all required fields filled
17835
+ operators.filter(function () { return _this.isManualSearchAvailable(); }), operators.map(function () { return _this.manualSearchQuery; }),
17836
+ // skip when value not changed
17837
+ operators.distinctUntilChanged())
17838
+ .subscribe(function () {
17839
+ _this.onSearch.emit(_this.manualSearchQuery);
17840
+ });
17841
+ };
17842
+ return AddressForm;
17843
+ }(AbstractForm));
17844
+ /**
17845
+ * Min search query required length
17846
+ */
17847
+ AddressForm.minSearchLength = 3;
17848
+ /**
17849
+ * Delay before corelogic request
17850
+ */
17851
+ AddressForm.searchDelay = 500;
17852
+
17853
+ /**
17854
+ * Form with loan details.
17855
+ * Loan could be created from bank account (Bank Loan) or directly from loan page (Vehicle Loan)
17856
+ */
17857
+ var LoanForm = /** @class */ (function (_super) {
17858
+ __extends(LoanForm, _super);
17859
+ function LoanForm(loan) {
17860
+ if (loan === void 0) { loan = classTransformer.plainToClass(Loan, {}); }
17861
+ var _this = _super.call(this, {
17862
+ type: new forms.FormControl(loan.type, forms.Validators.required),
17863
+ amount: new forms.FormControl(loan.amount, forms.Validators.required),
17864
+ interestRate: new forms.FormControl(loan.interestRate, [forms.Validators.required, forms.Validators.min(0), forms.Validators.max(100)]),
17865
+ commencementDate: new forms.FormControl(loan.commencementDate, forms.Validators.required),
17866
+ repaymentAmount: new forms.FormControl(loan.repaymentAmount, forms.Validators.required),
17867
+ repaymentFrequency: new forms.FormControl(loan.repaymentFrequency, forms.Validators.required),
17868
+ term: new forms.FormControl(loan.term, forms.Validators.required),
17869
+ // interestType is predefined for vehicle loans
17870
+ interestType: new forms.FormControl({ value: loan.interestType, disabled: !loan.bankAccount }, forms.Validators.required),
17871
+ // availableRedraw is predefined for vehicle loans
17872
+ availableRedraw: new forms.FormControl({ value: loan.availableRedraw, disabled: !loan.bankAccount }, forms.Validators.required),
17873
+ // repaymentType is predefined for vehicle loans
17874
+ repaymentType: new forms.FormControl({ value: loan.repaymentType, disabled: !loan.bankAccount }, forms.Validators.required),
17875
+ }, loan) || this;
17876
+ _this.loan = loan;
17877
+ // Set data which always the same for vehicle loans
17878
+ if (!loan.bankAccount) {
17879
+ Object.assign(_this.model, {
17880
+ repaymentType: exports.LoanRepaymentTypeEnum.PRINCIPAL_AND_INTEREST,
17881
+ availableRedraw: 0,
17882
+ interestType: exports.LoanInterestTypeEnum.FIXED_RATE
17883
+ });
17884
+ }
17885
+ _this.updateTermValidation();
17886
+ _this.listenEvents();
17887
+ return _this;
17888
+ }
17889
+ LoanForm.prototype.listenEvents = function () {
17890
+ // We need to set term automatically only for bank loans.
17891
+ // For vehicle loans user should fill it manually with validation depended of frequency
17892
+ if (!!this.loan.bankAccount) {
17893
+ this.listenTypeChanges();
17894
+ }
17895
+ else {
17896
+ this.listenRepaymentFrequencyChanges();
17897
+ }
17898
+ };
17899
+ /**
17900
+ * Set term automatically by loan type changes
17901
+ */
17902
+ LoanForm.prototype.listenTypeChanges = function () {
17903
+ var _this = this;
17904
+ this.get('type').valueChanges.subscribe(function (type) {
17905
+ _this.get('term').setValue(LoanForm.mortgageLoanTypes.includes(type) ? Loan.mortgageDefaultTerm : Loan.loanDefaultTerm);
17906
+ });
17907
+ };
17908
+ /**
17909
+ * term validation depends on selected repaymentFrequency
17910
+ */
17911
+ LoanForm.prototype.listenRepaymentFrequencyChanges = function () {
17912
+ var _this = this;
17913
+ this.get('repaymentFrequency').valueChanges.subscribe(function () {
17914
+ _this.updateTermValidation();
17915
+ });
17916
+ };
17917
+ /**
17918
+ * For vehicle loans term has a maximum value depended of repayment frequency
17919
+ */
17920
+ LoanForm.prototype.updateTermValidation = function () {
17921
+ // no need terms for bank loans
17922
+ if (!!this.loan.bankAccount) {
17923
+ return;
17924
+ }
17925
+ var currentRepaymentFrequency = this.get('repaymentFrequency').value;
17926
+ // term validation depends on selected repayment frequency, so can not validate when frequency is empty
17927
+ // repaymentType is required field, so we don't need to clear validation
17928
+ if (!currentRepaymentFrequency) {
17929
+ return;
17930
+ }
17931
+ var termControl = this.get('term');
17932
+ var maxTermValue = exports.LoanMaxNumberOfPaymentsEnum[exports.LoanRepaymentFrequencyEnum[currentRepaymentFrequency]];
17933
+ termControl.setValidators([forms.Validators.max(maxTermValue)]);
17934
+ termControl.updateValueAndValidity();
17935
+ };
17936
+ return LoanForm;
17937
+ }(AbstractForm));
17938
+ LoanForm.mortgageLoanTypes = [exports.LoanTypeEnum.MORTGAGE, exports.LoanTypeEnum.HOME_EQUITY_LINE_OF_CREDIT, exports.LoanTypeEnum.HOME_LOAN];
17939
+
17769
17940
  /**
17770
17941
  * Form array with bank account properties
17771
17942
  * @TODO create AbstractFormArray
@@ -17994,6 +18165,30 @@
17994
18165
  return SoleBusinessLossForm;
17995
18166
  }(AbstractForm));
17996
18167
 
18168
+ var phonePattern = /^(((\s*)?([- ()]?\d[- ()]?){0,30}(\s*)?)|)$/;
18169
+ /**
18170
+ * Validator for phone number
18171
+ * Allowed special symbols"-", "(", ")"
18172
+ */
18173
+ function phoneNumberValidator() {
18174
+ return function (control) {
18175
+ return phonePattern.test(control.value) ? null : { phoneInvalid: true };
18176
+ };
18177
+ }
18178
+
18179
+ var PhoneForm = /** @class */ (function (_super) {
18180
+ __extends(PhoneForm, _super);
18181
+ function PhoneForm(phone) {
18182
+ if (phone === void 0) { phone = classTransformer.plainToClass(Phone, {}); }
18183
+ return _super.call(this, {
18184
+ type: new forms.FormControl(phone.type, forms.Validators.required),
18185
+ country: new forms.FormControl(phone.country, forms.Validators.required),
18186
+ number: new forms.FormControl(phone.number, [forms.Validators.required, phoneNumberValidator()])
18187
+ }, phone) || this;
18188
+ }
18189
+ return PhoneForm;
18190
+ }(AbstractForm));
18191
+
17997
18192
  var SoleContactForm = /** @class */ (function (_super) {
17998
18193
  __extends(SoleContactForm, _super);
17999
18194
  function SoleContactForm(contact) {
@@ -18004,10 +18199,8 @@
18004
18199
  firstName: new forms.FormControl(contact.firstName, forms.Validators.required),
18005
18200
  lastName: new forms.FormControl(contact.lastName, forms.Validators.required),
18006
18201
  email: new forms.FormControl(contact.email, [forms.Validators.required, forms.Validators.email]),
18007
- // @TODO Alex: create phone form and phone form control
18008
- phone: new forms.FormControl(contact.phone),
18009
- // @TODO Alex: create address form and address form control
18010
- address: new forms.FormControl(contact.address)
18202
+ phone: new PhoneForm(contact.phone || classTransformer.plainToClass(Phone, {})),
18203
+ address: new AddressForm(contact.address || classTransformer.plainToClass(Address, {}))
18011
18204
  }, contact) || this;
18012
18205
  }
18013
18206
  return SoleContactForm;
@@ -19273,6 +19466,7 @@
19273
19466
  exports.AccountSetupItemCollection = AccountSetupItemCollection;
19274
19467
  exports.AccountSetupService = AccountSetupService;
19275
19468
  exports.Address = Address;
19469
+ exports.AddressForm = AddressForm;
19276
19470
  exports.AddressService = AddressService;
19277
19471
  exports.AppEvent = AppEvent;
19278
19472
  exports.AssetsService = AssetsService;
@@ -19458,6 +19652,7 @@
19458
19652
  exports.PdfFromHtmlTableService = PdfFromHtmlTableService;
19459
19653
  exports.PdfSettings = PdfSettings;
19460
19654
  exports.Phone = Phone;
19655
+ exports.PhoneForm = PhoneForm;
19461
19656
  exports.PreloaderService = PreloaderService;
19462
19657
  exports.Property = Property;
19463
19658
  exports.PropertyCalculationService = PropertyCalculationService;