@esolve/ng-esolve-connect 0.26.4 → 0.27.2

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 (99) hide show
  1. package/esm2020/lib/account/esolve-account.service.mjs +3 -12
  2. package/esm2020/lib/account/user-account/classes/esolve-statement-ageing.model.mjs +9 -0
  3. package/esm2020/lib/account/user-account/classes/esolve-statement-balances.model.mjs +10 -0
  4. package/esm2020/lib/account/user-account/classes/esolve-statement-transaction.model.mjs +15 -0
  5. package/esm2020/lib/account/user-account/classes/esolve-statement.model.mjs +11 -0
  6. package/esm2020/lib/account/user-account/classes/esolve-user-account-business.model.mjs +11 -0
  7. package/esm2020/lib/account/user-account/classes/esolve-user-account-contact.model.mjs +10 -0
  8. package/esm2020/lib/account/user-account/classes/esolve-user-account-result.model.mjs +9 -0
  9. package/esm2020/lib/account/user-account/classes/esolve-user-account.model.mjs +24 -0
  10. package/esm2020/lib/account/user-account/classes/esolve-user-client-account-balances.model.mjs +13 -0
  11. package/esm2020/lib/account/user-account/classes/esolve-user-client-account.model.mjs +46 -0
  12. package/esm2020/lib/account/user-account/classes/index.mjs +7 -0
  13. package/esm2020/lib/account/user-account/index.mjs +3 -11
  14. package/esm2020/lib/account/user-account/interfaces/esolve-statement-ageing-record.interface.mjs +2 -0
  15. package/esm2020/lib/account/user-account/interfaces/esolve-statement-balances-record.interface.mjs +2 -0
  16. package/esm2020/lib/account/user-account/interfaces/esolve-statement-record.interface.mjs +2 -0
  17. package/esm2020/lib/account/user-account/interfaces/esolve-statement-transaction-record.interface.mjs +2 -0
  18. package/esm2020/lib/account/user-account/interfaces/esolve-user-account-data.interface.mjs +2 -0
  19. package/esm2020/lib/account/user-account/interfaces/esolve-user-account-record.interface.mjs +2 -0
  20. package/esm2020/lib/account/user-account/interfaces/esolve-user-client-account-balances-record.interface.mjs +2 -0
  21. package/esm2020/lib/account/user-account/interfaces/esolve-user-client-account-record.interface.mjs +2 -0
  22. package/esm2020/lib/account/user-account/interfaces/index.mjs +9 -0
  23. package/esm2020/lib/auth/esolve-auth-interceptor.service.mjs +6 -1
  24. package/esm2020/lib/cart/esolve-cart.service.mjs +16 -5
  25. package/esm2020/lib/coupons/classes/esolve-coupon.model.mjs +29 -0
  26. package/esm2020/lib/coupons/classes/index.mjs +2 -0
  27. package/esm2020/lib/coupons/esolve-coupons.service.mjs +186 -0
  28. package/esm2020/lib/coupons/index.mjs +9 -0
  29. package/esm2020/lib/coupons/interfaces/esolve-coupon-record.interface.mjs +2 -0
  30. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation-error.interface.mjs +2 -0
  31. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation-result.interface.mjs +3 -0
  32. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation.interface.mjs +2 -0
  33. package/esm2020/lib/coupons/interfaces/index.mjs +5 -0
  34. package/esm2020/lib/coupons/types/esolve-coupons-cache.type.mjs +2 -0
  35. package/esm2020/lib/coupons/types/index.mjs +2 -0
  36. package/esm2020/lib/esolve-connect.config.mjs +1 -1
  37. package/esm2020/lib/stock/classes/esolve-stock-item-base.model.mjs +7 -1
  38. package/esm2020/lib/stock/classes/esolve-stock-transaction-history.model.mjs +7 -0
  39. package/esm2020/lib/stock/esolve-stock.service.mjs +59 -2
  40. package/esm2020/lib/stock/interfaces/esolve-stock-base-record.interface.mjs +1 -1
  41. package/esm2020/public-api.mjs +3 -1
  42. package/fesm2015/esolve-ng-esolve-connect.mjs +434 -81
  43. package/fesm2015/esolve-ng-esolve-connect.mjs.map +1 -1
  44. package/fesm2020/esolve-ng-esolve-connect.mjs +418 -77
  45. package/fesm2020/esolve-ng-esolve-connect.mjs.map +1 -1
  46. package/lib/account/esolve-account.service.d.ts +1 -2
  47. package/lib/account/user-account/classes/esolve-statement-ageing.model.d.ts +6 -0
  48. package/lib/account/user-account/classes/esolve-statement-balances.model.d.ts +7 -0
  49. package/lib/account/user-account/classes/esolve-statement-transaction.model.d.ts +12 -0
  50. package/lib/account/user-account/classes/esolve-statement.model.d.ts +8 -0
  51. package/lib/account/user-account/classes/esolve-user-account-business.model.d.ts +8 -0
  52. package/lib/account/user-account/classes/esolve-user-account-contact.model.d.ts +7 -0
  53. package/lib/account/user-account/{esolve-user-account-result.model.d.ts → classes/esolve-user-account-result.model.d.ts} +1 -1
  54. package/lib/account/user-account/{esolve-user-account.model.d.ts → classes/esolve-user-account.model.d.ts} +11 -10
  55. package/lib/account/user-account/{esolve-user-client-account-balances.model.d.ts → classes/esolve-user-client-account-balances.model.d.ts} +1 -1
  56. package/lib/account/user-account/classes/esolve-user-client-account.model.d.ts +43 -0
  57. package/lib/account/user-account/classes/index.d.ts +6 -0
  58. package/lib/account/user-account/index.d.ts +2 -10
  59. package/lib/account/user-account/interfaces/esolve-statement-ageing-record.interface.d.ts +4 -0
  60. package/lib/account/user-account/interfaces/esolve-statement-balances-record.interface.d.ts +5 -0
  61. package/lib/account/user-account/interfaces/esolve-statement-record.interface.d.ts +6 -0
  62. package/lib/account/user-account/interfaces/esolve-statement-transaction-record.interface.d.ts +10 -0
  63. package/lib/account/user-account/{esolve-user-account-data.interface.d.ts → interfaces/esolve-user-account-data.interface.d.ts} +0 -0
  64. package/lib/account/user-account/{esolve-user-account-record.interface.d.ts → interfaces/esolve-user-account-record.interface.d.ts} +0 -0
  65. package/lib/account/user-account/{esolve-user-client-account-balances-record.interface.d.ts → interfaces/esolve-user-client-account-balances-record.interface.d.ts} +1 -1
  66. package/lib/account/user-account/{esolve-user-client-account-record.interface.d.ts → interfaces/esolve-user-client-account-record.interface.d.ts} +2 -1
  67. package/lib/account/user-account/interfaces/index.d.ts +8 -0
  68. package/lib/cart/esolve-cart.service.d.ts +5 -1
  69. package/lib/coupons/classes/esolve-coupon.model.d.ts +20 -0
  70. package/lib/coupons/classes/index.d.ts +1 -0
  71. package/lib/coupons/esolve-coupons.service.d.ts +35 -0
  72. package/lib/coupons/index.d.ts +4 -0
  73. package/lib/coupons/interfaces/esolve-coupon-record.interface.d.ts +8 -0
  74. package/lib/coupons/interfaces/esolve-coupon-validation-error.interface.d.ts +4 -0
  75. package/lib/coupons/interfaces/esolve-coupon-validation-result.interface.d.ts +4 -0
  76. package/lib/coupons/interfaces/esolve-coupon-validation.interface.d.ts +6 -0
  77. package/lib/coupons/interfaces/index.d.ts +4 -0
  78. package/lib/coupons/types/esolve-coupons-cache.type.d.ts +1 -0
  79. package/lib/coupons/types/index.d.ts +1 -0
  80. package/lib/esolve-connect.config.d.ts +14 -0
  81. package/lib/stock/classes/esolve-stock-item-base.model.d.ts +5 -0
  82. package/lib/stock/classes/esolve-stock-transaction-history.model.d.ts +5 -0
  83. package/lib/stock/esolve-stock.service.d.ts +11 -0
  84. package/lib/stock/interfaces/esolve-stock-base-record.interface.d.ts +2 -0
  85. package/package.json +1 -1
  86. package/public-api.d.ts +1 -0
  87. package/esm2020/lib/account/user-account/esolve-user-account-business.model.mjs +0 -9
  88. package/esm2020/lib/account/user-account/esolve-user-account-contact.model.mjs +0 -8
  89. package/esm2020/lib/account/user-account/esolve-user-account-data.interface.mjs +0 -2
  90. package/esm2020/lib/account/user-account/esolve-user-account-record.interface.mjs +0 -2
  91. package/esm2020/lib/account/user-account/esolve-user-account-result.model.mjs +0 -9
  92. package/esm2020/lib/account/user-account/esolve-user-account.model.mjs +0 -14
  93. package/esm2020/lib/account/user-account/esolve-user-client-account-balances-record.interface.mjs +0 -2
  94. package/esm2020/lib/account/user-account/esolve-user-client-account-balances.model.mjs +0 -13
  95. package/esm2020/lib/account/user-account/esolve-user-client-account-record.interface.mjs +0 -2
  96. package/esm2020/lib/account/user-account/esolve-user-client-account.model.mjs +0 -43
  97. package/lib/account/user-account/esolve-user-account-business.model.d.ts +0 -7
  98. package/lib/account/user-account/esolve-user-account-contact.model.d.ts +0 -6
  99. package/lib/account/user-account/esolve-user-client-account.model.d.ts +0 -41
@@ -5,7 +5,7 @@ import * as i1$2 from '@angular/common/http';
5
5
  import { HTTP_INTERCEPTORS, HttpClientModule, HttpErrorResponse, HttpParams, HttpHeaders } from '@angular/common/http';
6
6
  import * as i1 from 'ngx-cookie-service';
7
7
  import { CookieService } from 'ngx-cookie-service';
8
- import { BehaviorSubject, throwError, of, iif } from 'rxjs';
8
+ import { BehaviorSubject, throwError, of, Subject, firstValueFrom, iif } from 'rxjs';
9
9
  import * as i1$1 from '@angular/platform-browser';
10
10
  import { map, catchError, tap, switchMap } from 'rxjs/operators';
11
11
 
@@ -239,6 +239,7 @@ class EsolveAuthInterceptorService {
239
239
  const service_identifier = req.url.replace(`${this.config.api_url}/`, '');
240
240
  const modified_url = req.url;
241
241
  let params = req.params;
242
+ let headers = req.headers;
242
243
  const session = this.session.currentSession;
243
244
  if (session.valid) {
244
245
  if (service_identifier !== 'get-access-token.php') {
@@ -246,9 +247,13 @@ class EsolveAuthInterceptorService {
246
247
  }
247
248
  }
248
249
  params = params.set('ws_id', this.config.wsid);
250
+ if (this.config.native && this.config.device_designation) {
251
+ headers = headers.set('X-Device-Designation', this.config.device_designation);
252
+ }
249
253
  const modified_req = req.clone({
250
254
  url: modified_url,
251
255
  params,
256
+ headers,
252
257
  });
253
258
  return next.handle(modified_req);
254
259
  }
@@ -1841,17 +1846,24 @@ class EsolveAddressResult extends EsolveResponseResult {
1841
1846
  }
1842
1847
  }
1843
1848
 
1844
- class EsolveUserAccount {
1845
- constructor(esolve_id, email, registration_type, title, first_name, last_name, initials, gender, identification_number) {
1846
- this.esolve_id = esolve_id;
1847
- this.email = email;
1848
- this.registration_type = registration_type;
1849
- this.title = title;
1850
- this.first_name = first_name;
1851
- this.last_name = last_name;
1852
- this.initials = initials;
1853
- this.gender = gender;
1854
- this.identification_number = identification_number;
1849
+ class EsolveUserAccountBusiness {
1850
+ constructor(record) {
1851
+ if (record) {
1852
+ this.name = record.busname ?? '';
1853
+ this.vat_number = record.vatnum ?? '';
1854
+ this.description = record.busdescript ?? '';
1855
+ this.type = record.business_type ?? '';
1856
+ }
1857
+ }
1858
+ }
1859
+
1860
+ class EsolveUserAccountContact {
1861
+ constructor(record) {
1862
+ if (record) {
1863
+ this.tel_number = record.telnumber ?? '';
1864
+ this.cell_number = record.cellnumber ?? '';
1865
+ this.fax_number = record.fax ?? '';
1866
+ }
1855
1867
  }
1856
1868
  }
1857
1869
 
@@ -1863,63 +1875,111 @@ class EsolveUserAccountResult extends EsolveResponseResult {
1863
1875
  }
1864
1876
  }
1865
1877
 
1866
- class EsolveUserAccountBusiness {
1867
- constructor(name, vat_number, description, type) {
1868
- this.name = name;
1869
- this.vat_number = vat_number;
1870
- this.description = description;
1871
- this.type = type;
1878
+ class EsolveStatementAgeing {
1879
+ constructor(record) {
1880
+ if (record) {
1881
+ this.days = +(record.days ?? 0);
1882
+ this.amount = +(record.amount ?? 0);
1883
+ }
1872
1884
  }
1873
1885
  }
1874
1886
 
1875
- class EsolveUserAccountContact {
1876
- constructor(tel_number, cell_number, fax_number) {
1877
- this.tel_number = tel_number;
1878
- this.cell_number = cell_number;
1879
- this.fax_number = fax_number;
1887
+ class EsolveStatementBalances {
1888
+ constructor(record) {
1889
+ if (record) {
1890
+ this.total = +(record.total ?? 0);
1891
+ this.ageing = record.ageing?.map((e) => new EsolveStatementAgeing(e)) ?? [];
1892
+ }
1893
+ }
1894
+ }
1895
+
1896
+ class EsolveStatementTransaction {
1897
+ constructor(record) {
1898
+ if (record) {
1899
+ this.order_date = record.order_date ?? '';
1900
+ this.order_number = record.order_number ?? '';
1901
+ this.comment = record.comment ?? '';
1902
+ this.account = record.account ?? '';
1903
+ this.iq_reference = record.iq_reference ?? '';
1904
+ this.total = +(record.total ?? 0);
1905
+ this.amount_due = +(record.amount_due ?? 0);
1906
+ this.is_debit = !!+(record.is_debit ?? true);
1907
+ }
1908
+ }
1909
+ }
1910
+
1911
+ class EsolveStatement {
1912
+ constructor(record) {
1913
+ if (record) {
1914
+ this.balances = new EsolveStatementBalances(record.balances);
1915
+ this.transactions = record.transactions?.map((e) => new EsolveStatementTransaction(e)) ?? [];
1916
+ }
1880
1917
  }
1881
1918
  }
1882
1919
 
1883
1920
  class EsolveUserClientAccount {
1884
- constructor(account, branch_code, account_group, pricing_group, price_list, loyalty_classification_id, company_name, client_contact_person, client_firstname, client_surname, client_email, client_contact_number, client_fax_number, client_cellphone_number, client_id_number, address_description, street, suburb, city, province, country, postal_code, postal_address, delivery_address, latitude, longitude, vat_number, credit_limit, pending_invoice_balance, external_account_balance, ageing, balance_last_updated, default_sellprice, client_classification, override_stock_listing_identifiers, requires_transaction_approval, is_active, external_statement) {
1885
- this.account = account;
1886
- this.branch_code = branch_code;
1887
- this.account_group = account_group;
1888
- this.pricing_group = pricing_group;
1889
- this.price_list = price_list;
1890
- this.loyalty_classification_id = loyalty_classification_id;
1891
- this.company_name = company_name;
1892
- this.client_contact_person = client_contact_person;
1893
- this.client_firstname = client_firstname;
1894
- this.client_surname = client_surname;
1895
- this.client_email = client_email;
1896
- this.client_contact_number = client_contact_number;
1897
- this.client_fax_number = client_fax_number;
1898
- this.client_cellphone_number = client_cellphone_number;
1899
- this.client_id_number = client_id_number;
1900
- this.address_description = address_description;
1901
- this.street = street;
1902
- this.suburb = suburb;
1903
- this.city = city;
1904
- this.province = province;
1905
- this.country = country;
1906
- this.postal_code = postal_code;
1907
- this.postal_address = postal_address;
1908
- this.delivery_address = delivery_address;
1909
- this.latitude = latitude;
1910
- this.longitude = longitude;
1911
- this.vat_number = vat_number;
1912
- this.credit_limit = credit_limit;
1913
- this.pending_invoice_balance = pending_invoice_balance;
1914
- this.external_account_balance = external_account_balance;
1915
- this.ageing = ageing;
1916
- this.balance_last_updated = balance_last_updated;
1917
- this.default_sellprice = default_sellprice;
1918
- this.client_classification = client_classification;
1919
- this.override_stock_listing_identifiers = override_stock_listing_identifiers;
1920
- this.requires_transaction_approval = requires_transaction_approval;
1921
- this.is_active = is_active;
1922
- this.external_statement = external_statement;
1921
+ constructor(record) {
1922
+ if (record) {
1923
+ this.account = record.account ?? '';
1924
+ this.branch_code = record.branch_code ?? '';
1925
+ this.account_group = record.account_group ?? '';
1926
+ this.pricing_group = record.pricing_group ?? '';
1927
+ this.company_name = record.company_name ?? '';
1928
+ this.client_contact_person = record.client_contact_person ?? '';
1929
+ this.client_firstname = record.client_firstname ?? '';
1930
+ this.client_surname = record.client_surname ?? '';
1931
+ this.client_email = record.client_email ?? '';
1932
+ this.client_contact_number = record.client_contact_number ?? '';
1933
+ this.client_fax_number = record.client_fax_number ?? '';
1934
+ this.client_cellphone_number = record.client_cellphone_number ?? '';
1935
+ this.client_id_number = record.client_id_number ?? '';
1936
+ this.address_description = record.address_description ?? '';
1937
+ this.street = record.street ?? '';
1938
+ this.suburb = record.suburb;
1939
+ this.city = record.city ?? '';
1940
+ this.province = record.province ?? '';
1941
+ this.country = record.country ?? '';
1942
+ this.postal_code = record.postal_code ?? '';
1943
+ this.postal_address = record.postal_address ?? '';
1944
+ this.delivery_address = record.delivery_address ?? '';
1945
+ this.vat_number = record.vat_number ?? '';
1946
+ this.ageing = record.ageing ?? '';
1947
+ this.balance_last_updated = record.balance_last_updated ?? '';
1948
+ this.client_classification = record.client_classification ?? '';
1949
+ this.override_stock_listing_identifiers = record.override_stock_listing_identifiers ?? '';
1950
+ this.requires_transaction_approval = record.requires_transaction_approval ?? '';
1951
+ this.latitude = +(record.latitude ?? 0);
1952
+ this.longitude = +(record.longitude ?? 0);
1953
+ this.price_list = +(record.price_list ?? 0);
1954
+ this.loyalty_classification_id = +(record.loyalty_classification_id ?? 0);
1955
+ this.credit_limit = +(record.credit_limit ?? 0);
1956
+ this.pending_invoice_balance = +(record.pending_invoice_balance ?? 0);
1957
+ this.external_account_balance = +(record.external_account_balance ?? 0);
1958
+ this.default_sellprice = +(record.default_sellprice ?? 0);
1959
+ this.is_active = !!+(record.is_active ?? false);
1960
+ this.external_statement = new EsolveStatement(record.external_statement);
1961
+ }
1962
+ }
1963
+ }
1964
+
1965
+ class EsolveUserAccount {
1966
+ constructor(record) {
1967
+ if (record) {
1968
+ this.esolve_id = +(record.userid ?? 0);
1969
+ this.email = record.email ?? '';
1970
+ this.registration_type = record.registration_type ?? '';
1971
+ this.title = record.title ?? '';
1972
+ this.first_name = record.firstname ?? '';
1973
+ this.last_name = record.surname ?? '';
1974
+ this.initials = record.initials ?? '';
1975
+ this.gender = record.gender ?? '';
1976
+ this.identification_number = record.idnumber ?? '';
1977
+ this.contact_details = new EsolveUserAccountContact(record);
1978
+ this.business_details = new EsolveUserAccountBusiness(record);
1979
+ if (record.client_details && (record.client_details.account !== '')) {
1980
+ this.client_details = new EsolveUserClientAccount(record.client_details);
1981
+ }
1982
+ }
1923
1983
  }
1924
1984
  }
1925
1985
 
@@ -2455,12 +2515,224 @@ class EsolveTransactionAnalyticsData {
2455
2515
  }
2456
2516
  }
2457
2517
 
2518
+ class EsolveCoupon {
2519
+ constructor(record) {
2520
+ this.id = 0;
2521
+ this.identifier = '';
2522
+ this.discount = 0;
2523
+ /**
2524
+ * Shows either the short code or the coupon key (if short code is not set)
2525
+ */
2526
+ this.coupon_code = '';
2527
+ /**
2528
+ * Limit of the number of items it can apply to
2529
+ */
2530
+ this.apply_on = 0;
2531
+ /**
2532
+ * Indicates if the discount does not apply to specified products, meaning
2533
+ * all items get the discount
2534
+ */
2535
+ this.apply_to_full_cart = false;
2536
+ if (record) {
2537
+ this.id = +record.id;
2538
+ this.identifier = record.identifier;
2539
+ this.discount = +record.discount;
2540
+ this.coupon_code = record.coupon_code;
2541
+ this.apply_on = +record.apply_on;
2542
+ this.apply_to_full_cart = record.apply_to_full_cart;
2543
+ }
2544
+ }
2545
+ }
2546
+
2547
+ ;
2548
+
2549
+ class EsolveCouponsService {
2550
+ constructor(config, http, cookieService) {
2551
+ this.config = config;
2552
+ this.http = http;
2553
+ this.cookieService = cookieService;
2554
+ this.storage_key = '_ng_eslv_coupons';
2555
+ this.coupons_cache = new Map();
2556
+ this.applied = new BehaviorSubject(undefined);
2557
+ this.validation_error = new Subject();
2558
+ this.setStorageKey();
2559
+ this.coupons_cache = this.retrieveCache();
2560
+ }
2561
+ onValidationError() {
2562
+ return this.validation_error.asObservable();
2563
+ }
2564
+ onApplied() {
2565
+ return this.applied.asObservable();
2566
+ }
2567
+ validate(coupon_key) {
2568
+ return this.http
2569
+ .get(`${this.config.api_url}/get-validate-coupon.php`, {
2570
+ params: {
2571
+ coupon_key,
2572
+ },
2573
+ })
2574
+ .pipe(map((response) => {
2575
+ if (response.records === undefined) {
2576
+ throw response;
2577
+ }
2578
+ const valid = response.records.valid;
2579
+ const result = {
2580
+ valid,
2581
+ };
2582
+ if (!valid) {
2583
+ const error = response.records.error;
2584
+ this.validation_error.next(error);
2585
+ }
2586
+ else if (valid) {
2587
+ result.id = response.records.id;
2588
+ }
2589
+ return result;
2590
+ }), catchError(() => {
2591
+ this.validation_error.next(undefined);
2592
+ return of({ valid: false });
2593
+ }));
2594
+ }
2595
+ async applyCoupon(coupon_key) {
2596
+ try {
2597
+ if (coupon_key.trim() === '') {
2598
+ return false;
2599
+ }
2600
+ const result = await firstValueFrom(this.validate(coupon_key));
2601
+ if (result.valid && result.id) {
2602
+ this.addCoupon(result.id, coupon_key);
2603
+ }
2604
+ return result.valid;
2605
+ }
2606
+ catch (error) {
2607
+ return false;
2608
+ }
2609
+ }
2610
+ removeCoupon(id) {
2611
+ this.coupons_cache.delete(id);
2612
+ this.cacheCoupons();
2613
+ this.applied.next();
2614
+ }
2615
+ getAppliedCouponKeys() {
2616
+ return [...this.coupons_cache.values()];
2617
+ }
2618
+ getAppliedCoupons() {
2619
+ const coupon_ids = [...this.coupons_cache.keys()];
2620
+ return this.http
2621
+ .get(`${this.config.api_url}/get-applied-coupons.php`, {
2622
+ params: {
2623
+ coupons: coupon_ids.join(','),
2624
+ },
2625
+ })
2626
+ .pipe(map((response) => {
2627
+ if (response.records === undefined) {
2628
+ throw response;
2629
+ }
2630
+ return this.processCoupons(response.records);
2631
+ }));
2632
+ }
2633
+ reset() {
2634
+ this.deleteCoupons();
2635
+ }
2636
+ retrieveCache() {
2637
+ if (this.cookieService.check(this.storage_key)) {
2638
+ const coupons_json = this.cookieService.get(this.storage_key);
2639
+ try {
2640
+ return this.jsonDecodeMap(coupons_json);
2641
+ }
2642
+ catch (error) {
2643
+ // soft error
2644
+ }
2645
+ }
2646
+ return new Map();
2647
+ }
2648
+ cacheCoupons() {
2649
+ if (this.coupons_cache.size > 0) {
2650
+ const coupons_json = this.jsonEncodeMap(this.coupons_cache);
2651
+ this.cookieService.set(this.storage_key, coupons_json, undefined, '/');
2652
+ }
2653
+ else {
2654
+ this.deleteCoupons();
2655
+ }
2656
+ }
2657
+ deleteCoupons() {
2658
+ this.coupons_cache.clear();
2659
+ this.cookieService.delete(this.storage_key, '/');
2660
+ }
2661
+ addCoupon(id, key) {
2662
+ if (!this.coupons_cache.has(id)) {
2663
+ this.coupons_cache.set(id, key);
2664
+ this.cacheCoupons();
2665
+ }
2666
+ this.applied.next();
2667
+ }
2668
+ setStorageKey() {
2669
+ if (typeof this.config.coupon_storage_key === 'string' &&
2670
+ this.config.coupon_storage_key !== '') {
2671
+ this.storage_key = this.config.coupon_storage_key;
2672
+ }
2673
+ }
2674
+ jsonEncodeMap(data) {
2675
+ if (!(data instanceof Map)) {
2676
+ throw new Error('Invalid map type');
2677
+ }
2678
+ return JSON.stringify(data, (key, value) => {
2679
+ if (value instanceof Map) {
2680
+ return {
2681
+ dataType: 'Map',
2682
+ value: [...value],
2683
+ };
2684
+ }
2685
+ else {
2686
+ return value;
2687
+ }
2688
+ });
2689
+ }
2690
+ jsonDecodeMap(json_data) {
2691
+ const data = JSON.parse(json_data, (key, value) => {
2692
+ if (typeof value === 'object' && value !== null) {
2693
+ if (value.dataType === 'Map') {
2694
+ return new Map(value.value);
2695
+ }
2696
+ }
2697
+ return value;
2698
+ });
2699
+ if (data instanceof Map) {
2700
+ return data;
2701
+ }
2702
+ throw new Error('Invalid map type');
2703
+ }
2704
+ processCoupons(records) {
2705
+ const coupons = [];
2706
+ if (records) {
2707
+ for (const record of records) {
2708
+ const coupon = new EsolveCoupon(record);
2709
+ coupons.push(coupon);
2710
+ }
2711
+ }
2712
+ return coupons;
2713
+ }
2714
+ }
2715
+ EsolveCouponsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCouponsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveCookieService }], target: i0.ɵɵFactoryTarget.Injectable });
2716
+ EsolveCouponsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCouponsService, providedIn: 'root' });
2717
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCouponsService, decorators: [{
2718
+ type: Injectable,
2719
+ args: [{
2720
+ providedIn: 'root',
2721
+ }]
2722
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2723
+ type: Inject,
2724
+ args: [ESOLVE_CONNECT_CONFIG]
2725
+ }] }, { type: i1$2.HttpClient }, { type: EsolveCookieService }]; } });
2726
+
2727
+ // Classes
2728
+
2458
2729
  class EsolveCartService {
2459
- constructor(config, http, errorHandler, responseHandler) {
2730
+ constructor(config, http, errorHandler, responseHandler, coupons) {
2460
2731
  this.config = config;
2461
2732
  this.http = http;
2462
2733
  this.errorHandler = errorHandler;
2463
2734
  this.responseHandler = responseHandler;
2735
+ this.coupons = coupons;
2464
2736
  this._cached_tracking = 0;
2465
2737
  }
2466
2738
  /**
@@ -2469,8 +2741,13 @@ class EsolveCartService {
2469
2741
  * @returns An `Observable` with an array of cart items
2470
2742
  */
2471
2743
  getCart() {
2744
+ let params = new HttpParams();
2745
+ const coupons = this.coupons.getAppliedCouponKeys();
2746
+ if (coupons.length > 0) {
2747
+ params = params.set('coupons', coupons.join(','));
2748
+ }
2472
2749
  return this.http
2473
- .get(`${this.config.api_url}/get-cart.php`)
2750
+ .get(`${this.config.api_url}/get-cart.php`, { params })
2474
2751
  .pipe(map((response) => {
2475
2752
  if (response.records === undefined) {
2476
2753
  throw response;
@@ -2483,6 +2760,7 @@ class EsolveCartService {
2483
2760
  *
2484
2761
  * @param items An array of options to update the cart
2485
2762
  * @param action The default action to preform
2763
+ *
2486
2764
  * @returns An `Observable` with an array of responses that gives feedback on the requested changes
2487
2765
  */
2488
2766
  setCart(items, action = 'add') {
@@ -2590,6 +2868,7 @@ class EsolveCartService {
2590
2868
  * @param payment_method_id The ID of the selected payment method
2591
2869
  * @param location_id The ID of the selected branch from with shipping needs to be calculated
2592
2870
  * @param comments Additional comments on the cart
2871
+ *
2593
2872
  * @returns An `Observable` with the transaction ID
2594
2873
  */
2595
2874
  checkout(type, addresses_id, shipping_id, payment_method_id = 0, location_id = 0, comments = '') {
@@ -2617,6 +2896,7 @@ class EsolveCartService {
2617
2896
  })
2618
2897
  .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2619
2898
  this._cached_tracking = 0;
2899
+ this.coupons.reset();
2620
2900
  return new EsolveCheckoutResult(response);
2621
2901
  })), catchError((errorRes) => {
2622
2902
  return this.errorHandler.handleHttpPostError('set-checkout', errorRes);
@@ -2650,7 +2930,7 @@ class EsolveCartService {
2650
2930
  return cart_totals;
2651
2931
  }
2652
2932
  }
2653
- EsolveCartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveErrorHandlerService }, { token: EsolveResponseHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
2933
+ EsolveCartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveErrorHandlerService }, { token: EsolveResponseHandlerService }, { token: EsolveCouponsService }], target: i0.ɵɵFactoryTarget.Injectable });
2654
2934
  EsolveCartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, providedIn: 'root' });
2655
2935
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, decorators: [{
2656
2936
  type: Injectable,
@@ -2660,7 +2940,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
2660
2940
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2661
2941
  type: Inject,
2662
2942
  args: [ESOLVE_CONNECT_CONFIG]
2663
- }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }]; } });
2943
+ }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }, { type: EsolveCouponsService }]; } });
2664
2944
 
2665
2945
  class EsolveAccountService {
2666
2946
  constructor(config, http, sessionService, errorHandler, responseHandler) {
@@ -2963,15 +3243,7 @@ class EsolveAccountService {
2963
3243
  if (+record.userid !== this._user_id) {
2964
3244
  throw new Error('Invalid user account retrieved');
2965
3245
  }
2966
- const user_account = new EsolveUserAccount(+record.userid, record.email, record.registration_type, record.title, record.firstname, record.surname, record.initials, record.gender, record.idnumber);
2967
- user_account.contact_details = new EsolveUserAccountContact(record.telnumber, record.cellnumber, record.fax);
2968
- user_account.business_details = new EsolveUserAccountBusiness(record.busname, record.vatnum, record.busdescript, record.business_type);
2969
- if (record.client_details != undefined) {
2970
- if (record.client_details?.account !== '') {
2971
- user_account.client_details = new EsolveUserClientAccount(record.client_details.account, record.client_details.branch_code, record.client_details.account_group, record.client_details.pricing_group, +record.client_details.price_list, +record.client_details.loyalty_classification_id, record.client_details.company_name, record.client_details.client_contact_person, record.client_details.client_firstname, record.client_details.client_surname, record.client_details.client_email, record.client_details.client_contact_number, record.client_details.client_fax_number, record.client_details.client_cellphone_number, record.client_details.client_id_number, record.client_details.address_description, record.client_details.street, record.client_details.suburb, record.client_details.city, record.client_details.province, record.client_details.country, record.client_details.postal_code, record.client_details.postal_address, record.client_details.delivery_address, +record.client_details.latitude, +record.client_details.longitude, record.client_details.vat_number, +record.client_details.credit_limit, +record.client_details.pending_invoice_balance, +record.client_details.external_account_balance, record.client_details.ageing, record.client_details.balance_last_updated, +record.client_details.default_sellprice, record.client_details.client_classification, record.client_details.override_stock_listing_identifiers, record.client_details.requires_transaction_approval, record.client_details.is_active, record.client_details.external_statement);
2972
- }
2973
- }
2974
- return user_account;
3246
+ return new EsolveUserAccount(record);
2975
3247
  }
2976
3248
  processUserAddress(records) {
2977
3249
  const user_addresses = [];
@@ -3495,6 +3767,13 @@ class EsolveStockLeadTimes {
3495
3767
  }
3496
3768
  }
3497
3769
 
3770
+ class EsolveStockTransactionHistory {
3771
+ constructor(total_order_qty = 0, total_quote_qty = 0) {
3772
+ this.total_order_qty = total_order_qty;
3773
+ this.total_quote_qty = total_quote_qty;
3774
+ }
3775
+ }
3776
+
3498
3777
  class EsolveStockItemBase {
3499
3778
  constructor(record = {}) {
3500
3779
  /**
@@ -3697,6 +3976,11 @@ class EsolveStockItemBase {
3697
3976
  if (record.custom_fields) {
3698
3977
  this.custom_fields = record.custom_fields;
3699
3978
  }
3979
+ if ((record.total_order_qty) || ((record.total_quote_qty))) {
3980
+ const total_order_qty = +(record.total_order_qty ?? 0);
3981
+ const total_quote_qty = +(record.total_quote_qty ?? 0);
3982
+ this.history = new EsolveStockTransactionHistory(total_order_qty, total_quote_qty);
3983
+ }
3700
3984
  seo_title = record.seo_page_title ?? '';
3701
3985
  seo_keywords = record.seo_keywords ?? '';
3702
3986
  }
@@ -3976,6 +4260,56 @@ class EsolveStockService {
3976
4260
  * @param options Stock filter options
3977
4261
  */
3978
4262
  getStockItems(options) {
4263
+ let params = new HttpParams();
4264
+ if (options.page) {
4265
+ params = params.set('page', options.page);
4266
+ }
4267
+ if (options.rows) {
4268
+ params = params.set('rows', options.rows);
4269
+ }
4270
+ if (options.sort) {
4271
+ const sort = options.sort;
4272
+ if (sort.field) {
4273
+ params = params.set('sort', sort.field);
4274
+ }
4275
+ if (sort.order) {
4276
+ params = params.set('order', sort.order);
4277
+ }
4278
+ }
4279
+ if (options.search_phrase) {
4280
+ params = params.set('search_phrase', options.search_phrase);
4281
+ }
4282
+ if (options.display_only) {
4283
+ params = params.set('display_only', options.display_only);
4284
+ }
4285
+ if (options.is_active) {
4286
+ params = params.set('is_active', options.is_active);
4287
+ }
4288
+ if (options.filters) {
4289
+ let filters = options.filters;
4290
+ if (!Array.isArray(filters)) {
4291
+ filters = EsolveFilterFactory.covertFromObj(filters);
4292
+ }
4293
+ params = EsolveFilterFactory.convertToHttpParams(filters, params);
4294
+ }
4295
+ return this.getStockRecords(params).pipe(map((response) => {
4296
+ if ((response.records === undefined) ||
4297
+ (response.records.length <= 0)) {
4298
+ throw response;
4299
+ }
4300
+ const stockItems = [];
4301
+ response.records.forEach((stockRecord) => {
4302
+ stockItems.push(this.processStockItem(stockRecord));
4303
+ });
4304
+ return new EsolveStockItemList(stockItems, +response.additional_data.total_records, options.page ?? 0);
4305
+ }));
4306
+ }
4307
+ /**
4308
+ * Retrieves list of stock from the eSolve instance using info provided
4309
+ *
4310
+ * @param options Stock filter options
4311
+ */
4312
+ getStockItemsTransactionHistory(options) {
3979
4313
  let params = new HttpParams();
3980
4314
  if (options.page) {
3981
4315
  params = params.set('page', options.page);
@@ -4029,7 +4363,7 @@ class EsolveStockService {
4029
4363
  }
4030
4364
  params = EsolveFilterFactory.convertToHttpParams(filters, params);
4031
4365
  }
4032
- return this.getStockRecords(params).pipe(map((response) => {
4366
+ return this.getStockHistoryRecords(params).pipe(map((response) => {
4033
4367
  if ((response.records === undefined) ||
4034
4368
  (response.records.length <= 0)) {
4035
4369
  throw response;
@@ -4241,6 +4575,13 @@ class EsolveStockService {
4241
4575
  getStockRecords(params) {
4242
4576
  return this.http.get(`${this.config.api_url}/get-items.php`, { params });
4243
4577
  }
4578
+ /**
4579
+ * Retrieves stock transaction history records from HTTP params.
4580
+ * @param params HTTP client parameters
4581
+ */
4582
+ getStockHistoryRecords(params) {
4583
+ return this.http.get(`${this.config.api_url}/get-items-transaction-history.php`, { params });
4584
+ }
4244
4585
  }
4245
4586
  EsolveStockService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveStockService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
4246
4587
  EsolveStockService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveStockService, providedIn: 'root' });
@@ -5165,5 +5506,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
5165
5506
  * Generated bundle index. Do not edit.
5166
5507
  */
5167
5508
 
5168
- export { ESOLVE_CONNECT_CONFIG, EsolveAccountConfirmationResult, EsolveAccountService, EsolveAdditionalStockImage, EsolveAddress, EsolveAddressResult, EsolveAsset, EsolveAssetsService, EsolveAuthService, EsolveBankingDetails, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartStockItem, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveChangePasswordResult, EsolveCheckoutResult, EsolveColour, EsolveCookieService, EsolveDependantItem, EsolveEmptyCartResult, EsolveEmptyWishlistResult, EsolveEnquiryResult, EsolveEnquiryService, EsolveErrorHandlerService, EsolveFilterFactory, EsolveGeocodeAddressResult, EsolveGeocodeCoordsResult, EsolveGeocodeResult, EsolveGeocoderService, EsolveHttpError, EsolveLinkedAsset, EsolveLinkedStockItem, EsolveList, EsolveLocation, EsolveLocationAddress, EsolveLocationContactInfo, EsolveLocationGEO, EsolveLocationPOBoxAddress, EsolveLocationTradingDay, EsolveLocationTradingTimes, EsolveLocationsService, EsolveManufacturer, EsolveManufacturersService, EsolveMediaStockItem, EsolveMenuItem, EsolveMenuService, EsolveMultipleSelectFilter, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolvePaymentResult, EsolvePaymentService, EsolveRange, EsolveRangeFilter, EsolveRangesService, EsolveRecipeStockItem, EsolveRegistrationResult, EsolveResetPasswordResult, EsolveResponseHandlerService, EsolveResponseResult, EsolveResult, EsolveSeoInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveShippingService, EsolveShippingTotals, EsolveSingleSelectFilter, EsolveSpecial, EsolveSpecialDates, EsolveSpecialImage, EsolveSpecialImageCollection, EsolveSpecialsService, EsolveStockBadge, EsolveStockGroup, EsolveStockGroupItem, EsolveStockImage, EsolveStockImageCollection, EsolveStockItem, EsolveStockItemBase, EsolveStockItemList, EsolveStockLeadTimes, EsolveStockPrice, EsolveStockService, EsolveSupplier, EsolveSuppliersService, EsolveTag, EsolveTagsService, EsolveTopic, EsolveTopicService, EsolveTransaction, EsolveTransactionAddress, EsolveTransactionAnalyticsData, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveUserClientAccount, EsolveUserClientAccountBalances, EsolveVaultItem, EsolveVaultItemResult, EsolveWishlistItem, EsolveWishlistService, NgEsolveConnectModule };
5509
+ export { ESOLVE_CONNECT_CONFIG, EsolveAccountConfirmationResult, EsolveAccountService, EsolveAdditionalStockImage, EsolveAddress, EsolveAddressResult, EsolveAsset, EsolveAssetsService, EsolveAuthService, EsolveBankingDetails, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartStockItem, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveChangePasswordResult, EsolveCheckoutResult, EsolveColour, EsolveCookieService, EsolveCoupon, EsolveCouponsService, EsolveDependantItem, EsolveEmptyCartResult, EsolveEmptyWishlistResult, EsolveEnquiryResult, EsolveEnquiryService, EsolveErrorHandlerService, EsolveFilterFactory, EsolveGeocodeAddressResult, EsolveGeocodeCoordsResult, EsolveGeocodeResult, EsolveGeocoderService, EsolveHttpError, EsolveLinkedAsset, EsolveLinkedStockItem, EsolveList, EsolveLocation, EsolveLocationAddress, EsolveLocationContactInfo, EsolveLocationGEO, EsolveLocationPOBoxAddress, EsolveLocationTradingDay, EsolveLocationTradingTimes, EsolveLocationsService, EsolveManufacturer, EsolveManufacturersService, EsolveMediaStockItem, EsolveMenuItem, EsolveMenuService, EsolveMultipleSelectFilter, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolvePaymentResult, EsolvePaymentService, EsolveRange, EsolveRangeFilter, EsolveRangesService, EsolveRecipeStockItem, EsolveRegistrationResult, EsolveResetPasswordResult, EsolveResponseHandlerService, EsolveResponseResult, EsolveResult, EsolveSeoInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveShippingService, EsolveShippingTotals, EsolveSingleSelectFilter, EsolveSpecial, EsolveSpecialDates, EsolveSpecialImage, EsolveSpecialImageCollection, EsolveSpecialsService, EsolveStockBadge, EsolveStockGroup, EsolveStockGroupItem, EsolveStockImage, EsolveStockImageCollection, EsolveStockItem, EsolveStockItemBase, EsolveStockItemList, EsolveStockLeadTimes, EsolveStockPrice, EsolveStockService, EsolveSupplier, EsolveSuppliersService, EsolveTag, EsolveTagsService, EsolveTopic, EsolveTopicService, EsolveTransaction, EsolveTransactionAddress, EsolveTransactionAnalyticsData, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveUserClientAccount, EsolveUserClientAccountBalances, EsolveVaultItem, EsolveVaultItemResult, EsolveWishlistItem, EsolveWishlistService, NgEsolveConnectModule };
5169
5510
  //# sourceMappingURL=esolve-ng-esolve-connect.mjs.map