@esolve/ng-esolve-connect 0.26.3 → 0.27.0

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 +22 -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/cart/esolve-cart.service.mjs +16 -5
  24. package/esm2020/lib/coupons/classes/esolve-coupon.model.mjs +29 -0
  25. package/esm2020/lib/coupons/classes/index.mjs +2 -0
  26. package/esm2020/lib/coupons/esolve-coupons.service.mjs +183 -0
  27. package/esm2020/lib/coupons/index.mjs +9 -0
  28. package/esm2020/lib/coupons/interfaces/esolve-coupon-record.interface.mjs +2 -0
  29. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation-error.interface.mjs +2 -0
  30. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation-result.interface.mjs +3 -0
  31. package/esm2020/lib/coupons/interfaces/esolve-coupon-validation.interface.mjs +2 -0
  32. package/esm2020/lib/coupons/interfaces/index.mjs +5 -0
  33. package/esm2020/lib/coupons/types/esolve-coupons-cache.type.mjs +2 -0
  34. package/esm2020/lib/coupons/types/index.mjs +2 -0
  35. package/esm2020/lib/esolve-connect.config.mjs +1 -1
  36. package/esm2020/lib/stock/classes/esolve-stock-item-base.model.mjs +7 -1
  37. package/esm2020/lib/stock/classes/esolve-stock-transaction-history.model.mjs +7 -0
  38. package/esm2020/lib/stock/esolve-stock.service.mjs +59 -2
  39. package/esm2020/lib/stock/interfaces/esolve-stock-base-record.interface.mjs +1 -1
  40. package/esm2020/public-api.mjs +3 -1
  41. package/fesm2015/esolve-ng-esolve-connect.mjs +433 -87
  42. package/fesm2015/esolve-ng-esolve-connect.mjs.map +1 -1
  43. package/fesm2020/esolve-ng-esolve-connect.mjs +417 -83
  44. package/fesm2020/esolve-ng-esolve-connect.mjs.map +1 -1
  45. package/lib/account/esolve-account.service.d.ts +1 -2
  46. package/lib/account/user-account/classes/esolve-statement-ageing.model.d.ts +6 -0
  47. package/lib/account/user-account/classes/esolve-statement-balances.model.d.ts +7 -0
  48. package/lib/account/user-account/classes/esolve-statement-transaction.model.d.ts +12 -0
  49. package/lib/account/user-account/classes/esolve-statement.model.d.ts +8 -0
  50. package/lib/account/user-account/classes/esolve-user-account-business.model.d.ts +8 -0
  51. package/lib/account/user-account/classes/esolve-user-account-contact.model.d.ts +7 -0
  52. package/lib/account/user-account/{esolve-user-account-result.model.d.ts → classes/esolve-user-account-result.model.d.ts} +1 -1
  53. package/lib/account/user-account/classes/esolve-user-account.model.d.ts +19 -0
  54. package/lib/account/user-account/{esolve-user-client-account-balances.model.d.ts → classes/esolve-user-client-account-balances.model.d.ts} +1 -1
  55. package/lib/account/user-account/classes/esolve-user-client-account.model.d.ts +43 -0
  56. package/lib/account/user-account/classes/index.d.ts +6 -0
  57. package/lib/account/user-account/index.d.ts +2 -10
  58. package/lib/account/user-account/interfaces/esolve-statement-ageing-record.interface.d.ts +4 -0
  59. package/lib/account/user-account/interfaces/esolve-statement-balances-record.interface.d.ts +5 -0
  60. package/lib/account/user-account/interfaces/esolve-statement-record.interface.d.ts +6 -0
  61. package/lib/account/user-account/interfaces/esolve-statement-transaction-record.interface.d.ts +10 -0
  62. package/lib/account/user-account/{esolve-user-account-data.interface.d.ts → interfaces/esolve-user-account-data.interface.d.ts} +0 -0
  63. package/lib/account/user-account/{esolve-user-account-record.interface.d.ts → interfaces/esolve-user-account-record.interface.d.ts} +0 -0
  64. 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
  65. package/lib/account/user-account/{esolve-user-client-account-record.interface.d.ts → interfaces/esolve-user-client-account-record.interface.d.ts} +2 -0
  66. package/lib/account/user-account/interfaces/index.d.ts +8 -0
  67. package/lib/cart/esolve-cart.service.d.ts +5 -1
  68. package/lib/coupons/classes/esolve-coupon.model.d.ts +20 -0
  69. package/lib/coupons/classes/index.d.ts +1 -0
  70. package/lib/coupons/esolve-coupons.service.d.ts +35 -0
  71. package/lib/coupons/index.d.ts +4 -0
  72. package/lib/coupons/interfaces/esolve-coupon-record.interface.d.ts +8 -0
  73. package/lib/coupons/interfaces/esolve-coupon-validation-error.interface.d.ts +4 -0
  74. package/lib/coupons/interfaces/esolve-coupon-validation-result.interface.d.ts +4 -0
  75. package/lib/coupons/interfaces/esolve-coupon-validation.interface.d.ts +6 -0
  76. package/lib/coupons/interfaces/index.d.ts +4 -0
  77. package/lib/coupons/types/esolve-coupons-cache.type.d.ts +1 -0
  78. package/lib/coupons/types/index.d.ts +1 -0
  79. package/lib/esolve-connect.config.d.ts +4 -0
  80. package/lib/stock/classes/esolve-stock-item-base.model.d.ts +5 -0
  81. package/lib/stock/classes/esolve-stock-transaction-history.model.d.ts +5 -0
  82. package/lib/stock/esolve-stock.service.d.ts +11 -0
  83. package/lib/stock/interfaces/esolve-stock-base-record.interface.d.ts +2 -0
  84. package/package.json +1 -1
  85. package/public-api.d.ts +1 -0
  86. package/esm2020/lib/account/user-account/esolve-user-account-business.model.mjs +0 -9
  87. package/esm2020/lib/account/user-account/esolve-user-account-contact.model.mjs +0 -8
  88. package/esm2020/lib/account/user-account/esolve-user-account-data.interface.mjs +0 -2
  89. package/esm2020/lib/account/user-account/esolve-user-account-record.interface.mjs +0 -2
  90. package/esm2020/lib/account/user-account/esolve-user-account-result.model.mjs +0 -9
  91. package/esm2020/lib/account/user-account/esolve-user-account.model.mjs +0 -14
  92. package/esm2020/lib/account/user-account/esolve-user-client-account-balances-record.interface.mjs +0 -2
  93. package/esm2020/lib/account/user-account/esolve-user-client-account-balances.model.mjs +0 -13
  94. package/esm2020/lib/account/user-account/esolve-user-client-account-record.interface.mjs +0 -2
  95. package/esm2020/lib/account/user-account/esolve-user-client-account.model.mjs +0 -42
  96. package/lib/account/user-account/esolve-user-account-business.model.d.ts +0 -7
  97. package/lib/account/user-account/esolve-user-account-contact.model.d.ts +0 -6
  98. package/lib/account/user-account/esolve-user-account.model.d.ts +0 -20
  99. package/lib/account/user-account/esolve-user-client-account.model.d.ts +0 -40
@@ -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
 
@@ -1841,17 +1841,24 @@ class EsolveAddressResult extends EsolveResponseResult {
1841
1841
  }
1842
1842
  }
1843
1843
 
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;
1844
+ class EsolveUserAccountBusiness {
1845
+ constructor(record) {
1846
+ if (record) {
1847
+ this.name = record.busname ?? '';
1848
+ this.vat_number = record.vatnum ?? '';
1849
+ this.description = record.busdescript ?? '';
1850
+ this.type = record.business_type ?? '';
1851
+ }
1852
+ }
1853
+ }
1854
+
1855
+ class EsolveUserAccountContact {
1856
+ constructor(record) {
1857
+ if (record) {
1858
+ this.tel_number = record.telnumber ?? '';
1859
+ this.cell_number = record.cellnumber ?? '';
1860
+ this.fax_number = record.fax ?? '';
1861
+ }
1855
1862
  }
1856
1863
  }
1857
1864
 
@@ -1863,62 +1870,24 @@ class EsolveUserAccountResult extends EsolveResponseResult {
1863
1870
  }
1864
1871
  }
1865
1872
 
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;
1872
- }
1873
- }
1874
-
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;
1880
- }
1881
- }
1882
-
1883
- 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) {
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;
1873
+ class EsolveUserAccount {
1874
+ constructor(record) {
1875
+ if (record) {
1876
+ this.esolve_id = +(record.userid ?? 0);
1877
+ this.email = record.email ?? '';
1878
+ this.registration_type = record.registration_type ?? '';
1879
+ this.title = record.title ?? '';
1880
+ this.first_name = record.firstname ?? '';
1881
+ this.last_name = record.surname ?? '';
1882
+ this.initials = record.initials ?? '';
1883
+ this.gender = record.gender ?? '';
1884
+ this.identification_number = record.idnumber ?? '';
1885
+ this.contact_details = new EsolveUserAccountContact(record);
1886
+ this.business_details = new EsolveUserAccountBusiness(record);
1887
+ if (record.client_details && (record.client_details.account !== '')) {
1888
+ this.client_details = new EsolveUserClientAccount(record.client_details);
1889
+ }
1890
+ }
1922
1891
  }
1923
1892
  }
1924
1893
 
@@ -1935,6 +1904,93 @@ class EsolveUserClientAccountBalances {
1935
1904
  }
1936
1905
  }
1937
1906
 
1907
+ class EsolveStatementAgeing {
1908
+ constructor(record) {
1909
+ if (record) {
1910
+ this.days = +(record.days ?? 0);
1911
+ this.amount = +(record.amount ?? 0);
1912
+ }
1913
+ }
1914
+ }
1915
+
1916
+ class EsolveStatementBalances {
1917
+ constructor(record) {
1918
+ if (record) {
1919
+ this.total = +(record.total ?? 0);
1920
+ this.ageing = record.ageing?.map((e) => new EsolveStatementAgeing(e)) ?? [];
1921
+ }
1922
+ }
1923
+ }
1924
+
1925
+ class EsolveStatementTransaction {
1926
+ constructor(record) {
1927
+ if (record) {
1928
+ this.order_date = record.order_date ?? '';
1929
+ this.order_number = record.order_number ?? '';
1930
+ this.comment = record.comment ?? '';
1931
+ this.account = record.account ?? '';
1932
+ this.iq_reference = record.iq_reference ?? '';
1933
+ this.total = +(record.total ?? 0);
1934
+ this.amount_due = +(record.amount_due ?? 0);
1935
+ this.is_debit = !!+(record.is_debit ?? true);
1936
+ }
1937
+ }
1938
+ }
1939
+
1940
+ class EsolveStatement {
1941
+ constructor(record) {
1942
+ if (record) {
1943
+ this.balances = new EsolveStatementBalances(record.balances);
1944
+ this.transactions = record.transactions?.map((e) => new EsolveStatementTransaction(e)) ?? [];
1945
+ }
1946
+ }
1947
+ }
1948
+
1949
+ class EsolveUserClientAccount {
1950
+ constructor(record) {
1951
+ if (record) {
1952
+ this.account = record.account ?? '';
1953
+ this.branch_code = record.branch_code ?? '';
1954
+ this.account_group = record.account_group ?? '';
1955
+ this.pricing_group = record.pricing_group ?? '';
1956
+ this.company_name = record.company_name ?? '';
1957
+ this.client_contact_person = record.client_contact_person ?? '';
1958
+ this.client_firstname = record.client_firstname ?? '';
1959
+ this.client_surname = record.client_surname ?? '';
1960
+ this.client_email = record.client_email ?? '';
1961
+ this.client_contact_number = record.client_contact_number ?? '';
1962
+ this.client_fax_number = record.client_fax_number ?? '';
1963
+ this.client_cellphone_number = record.client_cellphone_number ?? '';
1964
+ this.client_id_number = record.client_id_number ?? '';
1965
+ this.address_description = record.address_description ?? '';
1966
+ this.street = record.street ?? '';
1967
+ this.suburb = record.suburb;
1968
+ this.city = record.city ?? '';
1969
+ this.province = record.province ?? '';
1970
+ this.country = record.country ?? '';
1971
+ this.postal_code = record.postal_code ?? '';
1972
+ this.postal_address = record.postal_address ?? '';
1973
+ this.delivery_address = record.delivery_address ?? '';
1974
+ this.vat_number = record.vat_number ?? '';
1975
+ this.ageing = record.ageing ?? '';
1976
+ this.balance_last_updated = record.balance_last_updated ?? '';
1977
+ this.client_classification = record.client_classification ?? '';
1978
+ this.override_stock_listing_identifiers = record.override_stock_listing_identifiers ?? '';
1979
+ this.requires_transaction_approval = record.requires_transaction_approval ?? '';
1980
+ this.latitude = +(record.latitude ?? 0);
1981
+ this.longitude = +(record.longitude ?? 0);
1982
+ this.price_list = +(record.price_list ?? 0);
1983
+ this.loyalty_classification_id = +(record.loyalty_classification_id ?? 0);
1984
+ this.credit_limit = +(record.credit_limit ?? 0);
1985
+ this.pending_invoice_balance = +(record.pending_invoice_balance ?? 0);
1986
+ this.external_account_balance = +(record.external_account_balance ?? 0);
1987
+ this.default_sellprice = +(record.default_sellprice ?? 0);
1988
+ this.is_active = !!+(record.is_active ?? false);
1989
+ this.external_statement = new EsolveStatement(record.external_statement);
1990
+ }
1991
+ }
1992
+ }
1993
+
1938
1994
  class EsolveTransactionAddress {
1939
1995
  constructor(recipient, address_type, address_description, street_number, street, suburb, city, province, country, postal_code, pobox) {
1940
1996
  this.recipient = recipient;
@@ -2454,12 +2510,221 @@ class EsolveTransactionAnalyticsData {
2454
2510
  }
2455
2511
  }
2456
2512
 
2513
+ class EsolveCoupon {
2514
+ constructor(record) {
2515
+ this.id = 0;
2516
+ this.identifier = '';
2517
+ this.discount = 0;
2518
+ /**
2519
+ * Shows either the short code or the coupon key (if short code is not set)
2520
+ */
2521
+ this.coupon_code = '';
2522
+ /**
2523
+ * Limit of the number of items it can apply to
2524
+ */
2525
+ this.apply_on = 0;
2526
+ /**
2527
+ * Indicates if the discount does not apply to specified products, meaning
2528
+ * all items get the discount
2529
+ */
2530
+ this.apply_to_full_cart = false;
2531
+ if (record) {
2532
+ this.id = +record.id;
2533
+ this.identifier = record.identifier;
2534
+ this.discount = +record.discount;
2535
+ this.coupon_code = record.coupon_code;
2536
+ this.apply_on = +record.apply_on;
2537
+ this.apply_to_full_cart = record.apply_to_full_cart;
2538
+ }
2539
+ }
2540
+ }
2541
+
2542
+ ;
2543
+
2544
+ class EsolveCouponsService {
2545
+ constructor(config, http, cookieService) {
2546
+ this.config = config;
2547
+ this.http = http;
2548
+ this.cookieService = cookieService;
2549
+ this.storage_key = '_ng_eslv_coupons';
2550
+ this.coupons_cache = new Map();
2551
+ this.applied = new BehaviorSubject(undefined);
2552
+ this.validation_error = new Subject();
2553
+ this.setStorageKey();
2554
+ this.coupons_cache = this.retrieveCache();
2555
+ }
2556
+ onValidationError() {
2557
+ return this.validation_error.asObservable();
2558
+ }
2559
+ onApplied() {
2560
+ return this.applied.asObservable();
2561
+ }
2562
+ validate(coupon_key) {
2563
+ return this.http
2564
+ .get(`${this.config.api_url}/get-validate-coupon.php`, {
2565
+ params: {
2566
+ coupon_key,
2567
+ },
2568
+ })
2569
+ .pipe(map((response) => {
2570
+ if (response.records === undefined) {
2571
+ throw response;
2572
+ }
2573
+ const valid = response.records.valid;
2574
+ const error = response.records.error;
2575
+ const result = {
2576
+ valid,
2577
+ };
2578
+ if (!valid && error) {
2579
+ this.validation_error.next(error);
2580
+ }
2581
+ else if (valid) {
2582
+ result.id = response.records.id;
2583
+ }
2584
+ return result;
2585
+ }), catchError(() => of({ valid: false })));
2586
+ }
2587
+ async applyCoupon(coupon_key) {
2588
+ try {
2589
+ if (coupon_key.trim() === '') {
2590
+ return false;
2591
+ }
2592
+ const result = await firstValueFrom(this.validate(coupon_key));
2593
+ if (result.valid && result.id) {
2594
+ this.addCoupon(result.id, coupon_key);
2595
+ }
2596
+ return result.valid;
2597
+ }
2598
+ catch (error) {
2599
+ return false;
2600
+ }
2601
+ }
2602
+ removeCoupon(id) {
2603
+ this.coupons_cache.delete(id);
2604
+ this.cacheCoupons();
2605
+ this.applied.next();
2606
+ }
2607
+ getAppliedCouponKeys() {
2608
+ return [...this.coupons_cache.values()];
2609
+ }
2610
+ getAppliedCoupons() {
2611
+ const coupon_ids = [...this.coupons_cache.keys()];
2612
+ return this.http
2613
+ .get(`${this.config.api_url}/get-applied-coupons.php`, {
2614
+ params: {
2615
+ coupons: coupon_ids.join(','),
2616
+ },
2617
+ })
2618
+ .pipe(map((response) => {
2619
+ if (response.records === undefined) {
2620
+ throw response;
2621
+ }
2622
+ return this.processCoupons(response.records);
2623
+ }));
2624
+ }
2625
+ reset() {
2626
+ this.deleteCoupons();
2627
+ }
2628
+ retrieveCache() {
2629
+ if (this.cookieService.check(this.storage_key)) {
2630
+ const coupons_json = this.cookieService.get(this.storage_key);
2631
+ try {
2632
+ return this.jsonDecodeMap(coupons_json);
2633
+ }
2634
+ catch (error) {
2635
+ // soft error
2636
+ }
2637
+ }
2638
+ return new Map();
2639
+ }
2640
+ cacheCoupons() {
2641
+ if (this.coupons_cache.size > 0) {
2642
+ const coupons_json = this.jsonEncodeMap(this.coupons_cache);
2643
+ this.cookieService.set(this.storage_key, coupons_json, undefined, '/');
2644
+ }
2645
+ else {
2646
+ this.deleteCoupons();
2647
+ }
2648
+ }
2649
+ deleteCoupons() {
2650
+ this.coupons_cache.clear();
2651
+ this.cookieService.delete(this.storage_key, '/');
2652
+ }
2653
+ addCoupon(id, key) {
2654
+ if (!this.coupons_cache.has(id)) {
2655
+ this.coupons_cache.set(id, key);
2656
+ this.cacheCoupons();
2657
+ }
2658
+ this.applied.next();
2659
+ }
2660
+ setStorageKey() {
2661
+ if (typeof this.config.coupon_storage_key === 'string' &&
2662
+ this.config.coupon_storage_key !== '') {
2663
+ this.storage_key = this.config.coupon_storage_key;
2664
+ }
2665
+ }
2666
+ jsonEncodeMap(data) {
2667
+ if (!(data instanceof Map)) {
2668
+ throw new Error('Invalid map type');
2669
+ }
2670
+ return JSON.stringify(data, (key, value) => {
2671
+ if (value instanceof Map) {
2672
+ return {
2673
+ dataType: 'Map',
2674
+ value: [...value],
2675
+ };
2676
+ }
2677
+ else {
2678
+ return value;
2679
+ }
2680
+ });
2681
+ }
2682
+ jsonDecodeMap(json_data) {
2683
+ const data = JSON.parse(json_data, (key, value) => {
2684
+ if (typeof value === 'object' && value !== null) {
2685
+ if (value.dataType === 'Map') {
2686
+ return new Map(value.value);
2687
+ }
2688
+ }
2689
+ return value;
2690
+ });
2691
+ if (data instanceof Map) {
2692
+ return data;
2693
+ }
2694
+ throw new Error('Invalid map type');
2695
+ }
2696
+ processCoupons(records) {
2697
+ const coupons = [];
2698
+ if (records) {
2699
+ for (const record of records) {
2700
+ const coupon = new EsolveCoupon(record);
2701
+ coupons.push(coupon);
2702
+ }
2703
+ }
2704
+ return coupons;
2705
+ }
2706
+ }
2707
+ 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 });
2708
+ EsolveCouponsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCouponsService, providedIn: 'root' });
2709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCouponsService, decorators: [{
2710
+ type: Injectable,
2711
+ args: [{
2712
+ providedIn: 'root',
2713
+ }]
2714
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2715
+ type: Inject,
2716
+ args: [ESOLVE_CONNECT_CONFIG]
2717
+ }] }, { type: i1$2.HttpClient }, { type: EsolveCookieService }]; } });
2718
+
2719
+ // Classes
2720
+
2457
2721
  class EsolveCartService {
2458
- constructor(config, http, errorHandler, responseHandler) {
2722
+ constructor(config, http, errorHandler, responseHandler, coupons) {
2459
2723
  this.config = config;
2460
2724
  this.http = http;
2461
2725
  this.errorHandler = errorHandler;
2462
2726
  this.responseHandler = responseHandler;
2727
+ this.coupons = coupons;
2463
2728
  this._cached_tracking = 0;
2464
2729
  }
2465
2730
  /**
@@ -2468,8 +2733,13 @@ class EsolveCartService {
2468
2733
  * @returns An `Observable` with an array of cart items
2469
2734
  */
2470
2735
  getCart() {
2736
+ let params = new HttpParams();
2737
+ const coupons = this.coupons.getAppliedCouponKeys();
2738
+ if (coupons.length > 0) {
2739
+ params = params.set('coupons', coupons.join(','));
2740
+ }
2471
2741
  return this.http
2472
- .get(`${this.config.api_url}/get-cart.php`)
2742
+ .get(`${this.config.api_url}/get-cart.php`, { params })
2473
2743
  .pipe(map((response) => {
2474
2744
  if (response.records === undefined) {
2475
2745
  throw response;
@@ -2482,6 +2752,7 @@ class EsolveCartService {
2482
2752
  *
2483
2753
  * @param items An array of options to update the cart
2484
2754
  * @param action The default action to preform
2755
+ *
2485
2756
  * @returns An `Observable` with an array of responses that gives feedback on the requested changes
2486
2757
  */
2487
2758
  setCart(items, action = 'add') {
@@ -2589,6 +2860,7 @@ class EsolveCartService {
2589
2860
  * @param payment_method_id The ID of the selected payment method
2590
2861
  * @param location_id The ID of the selected branch from with shipping needs to be calculated
2591
2862
  * @param comments Additional comments on the cart
2863
+ *
2592
2864
  * @returns An `Observable` with the transaction ID
2593
2865
  */
2594
2866
  checkout(type, addresses_id, shipping_id, payment_method_id = 0, location_id = 0, comments = '') {
@@ -2616,6 +2888,7 @@ class EsolveCartService {
2616
2888
  })
2617
2889
  .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2618
2890
  this._cached_tracking = 0;
2891
+ this.coupons.reset();
2619
2892
  return new EsolveCheckoutResult(response);
2620
2893
  })), catchError((errorRes) => {
2621
2894
  return this.errorHandler.handleHttpPostError('set-checkout', errorRes);
@@ -2649,7 +2922,7 @@ class EsolveCartService {
2649
2922
  return cart_totals;
2650
2923
  }
2651
2924
  }
2652
- 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 });
2925
+ 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 });
2653
2926
  EsolveCartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, providedIn: 'root' });
2654
2927
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, decorators: [{
2655
2928
  type: Injectable,
@@ -2659,7 +2932,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
2659
2932
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2660
2933
  type: Inject,
2661
2934
  args: [ESOLVE_CONNECT_CONFIG]
2662
- }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }]; } });
2935
+ }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }, { type: EsolveCouponsService }]; } });
2663
2936
 
2664
2937
  class EsolveAccountService {
2665
2938
  constructor(config, http, sessionService, errorHandler, responseHandler) {
@@ -2962,15 +3235,7 @@ class EsolveAccountService {
2962
3235
  if (+record.userid !== this._user_id) {
2963
3236
  throw new Error('Invalid user account retrieved');
2964
3237
  }
2965
- const user_account = new EsolveUserAccount(+record.userid, record.email, record.registration_type, record.title, record.firstname, record.surname, record.initials, record.gender, record.idnumber);
2966
- user_account.contact_details = new EsolveUserAccountContact(record.telnumber, record.cellnumber, record.fax);
2967
- user_account.business_details = new EsolveUserAccountBusiness(record.busname, record.vatnum, record.busdescript, record.business_type);
2968
- if (record.client_details != undefined) {
2969
- if (record.client_details?.account !== '') {
2970
- 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);
2971
- }
2972
- }
2973
- return user_account;
3238
+ return new EsolveUserAccount(record);
2974
3239
  }
2975
3240
  processUserAddress(records) {
2976
3241
  const user_addresses = [];
@@ -3494,6 +3759,13 @@ class EsolveStockLeadTimes {
3494
3759
  }
3495
3760
  }
3496
3761
 
3762
+ class EsolveStockTransactionHistory {
3763
+ constructor(total_order_qty = 0, total_quote_qty = 0) {
3764
+ this.total_order_qty = total_order_qty;
3765
+ this.total_quote_qty = total_quote_qty;
3766
+ }
3767
+ }
3768
+
3497
3769
  class EsolveStockItemBase {
3498
3770
  constructor(record = {}) {
3499
3771
  /**
@@ -3696,6 +3968,11 @@ class EsolveStockItemBase {
3696
3968
  if (record.custom_fields) {
3697
3969
  this.custom_fields = record.custom_fields;
3698
3970
  }
3971
+ if ((record.total_order_qty) || ((record.total_quote_qty))) {
3972
+ const total_order_qty = +(record.total_order_qty ?? 0);
3973
+ const total_quote_qty = +(record.total_quote_qty ?? 0);
3974
+ this.history = new EsolveStockTransactionHistory(total_order_qty, total_quote_qty);
3975
+ }
3699
3976
  seo_title = record.seo_page_title ?? '';
3700
3977
  seo_keywords = record.seo_keywords ?? '';
3701
3978
  }
@@ -3975,6 +4252,56 @@ class EsolveStockService {
3975
4252
  * @param options Stock filter options
3976
4253
  */
3977
4254
  getStockItems(options) {
4255
+ let params = new HttpParams();
4256
+ if (options.page) {
4257
+ params = params.set('page', options.page);
4258
+ }
4259
+ if (options.rows) {
4260
+ params = params.set('rows', options.rows);
4261
+ }
4262
+ if (options.sort) {
4263
+ const sort = options.sort;
4264
+ if (sort.field) {
4265
+ params = params.set('sort', sort.field);
4266
+ }
4267
+ if (sort.order) {
4268
+ params = params.set('order', sort.order);
4269
+ }
4270
+ }
4271
+ if (options.search_phrase) {
4272
+ params = params.set('search_phrase', options.search_phrase);
4273
+ }
4274
+ if (options.display_only) {
4275
+ params = params.set('display_only', options.display_only);
4276
+ }
4277
+ if (options.is_active) {
4278
+ params = params.set('is_active', options.is_active);
4279
+ }
4280
+ if (options.filters) {
4281
+ let filters = options.filters;
4282
+ if (!Array.isArray(filters)) {
4283
+ filters = EsolveFilterFactory.covertFromObj(filters);
4284
+ }
4285
+ params = EsolveFilterFactory.convertToHttpParams(filters, params);
4286
+ }
4287
+ return this.getStockRecords(params).pipe(map((response) => {
4288
+ if ((response.records === undefined) ||
4289
+ (response.records.length <= 0)) {
4290
+ throw response;
4291
+ }
4292
+ const stockItems = [];
4293
+ response.records.forEach((stockRecord) => {
4294
+ stockItems.push(this.processStockItem(stockRecord));
4295
+ });
4296
+ return new EsolveStockItemList(stockItems, +response.additional_data.total_records, options.page ?? 0);
4297
+ }));
4298
+ }
4299
+ /**
4300
+ * Retrieves list of stock from the eSolve instance using info provided
4301
+ *
4302
+ * @param options Stock filter options
4303
+ */
4304
+ getStockItemsTransactionHistory(options) {
3978
4305
  let params = new HttpParams();
3979
4306
  if (options.page) {
3980
4307
  params = params.set('page', options.page);
@@ -4028,7 +4355,7 @@ class EsolveStockService {
4028
4355
  }
4029
4356
  params = EsolveFilterFactory.convertToHttpParams(filters, params);
4030
4357
  }
4031
- return this.getStockRecords(params).pipe(map((response) => {
4358
+ return this.getStockHistoryRecords(params).pipe(map((response) => {
4032
4359
  if ((response.records === undefined) ||
4033
4360
  (response.records.length <= 0)) {
4034
4361
  throw response;
@@ -4240,6 +4567,13 @@ class EsolveStockService {
4240
4567
  getStockRecords(params) {
4241
4568
  return this.http.get(`${this.config.api_url}/get-items.php`, { params });
4242
4569
  }
4570
+ /**
4571
+ * Retrieves stock transaction history records from HTTP params.
4572
+ * @param params HTTP client parameters
4573
+ */
4574
+ getStockHistoryRecords(params) {
4575
+ return this.http.get(`${this.config.api_url}/get-items-transaction-history.php`, { params });
4576
+ }
4243
4577
  }
4244
4578
  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 });
4245
4579
  EsolveStockService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveStockService, providedIn: 'root' });
@@ -5164,5 +5498,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
5164
5498
  * Generated bundle index. Do not edit.
5165
5499
  */
5166
5500
 
5167
- 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 };
5501
+ 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 };
5168
5502
  //# sourceMappingURL=esolve-ng-esolve-connect.mjs.map