@esolve/ng-esolve-connect 0.24.2 → 0.25.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 (21) hide show
  1. package/esm2020/lib/account/esolve-account.service.mjs +35 -2
  2. package/esm2020/lib/account/user-account/esolve-user-account-record.interface.mjs +1 -1
  3. package/esm2020/lib/account/user-account/esolve-user-account.model.mjs +1 -1
  4. package/esm2020/lib/account/user-account/esolve-user-client-account-balances-record.interface.mjs +2 -0
  5. package/esm2020/lib/account/user-account/esolve-user-client-account-balances.model.mjs +13 -0
  6. package/esm2020/lib/account/user-account/esolve-user-client-account-record.interface.mjs +2 -0
  7. package/esm2020/lib/account/user-account/esolve-user-client-account.model.mjs +42 -0
  8. package/esm2020/lib/account/user-account/index.mjs +5 -1
  9. package/fesm2015/esolve-ng-esolve-connect.mjs +465 -378
  10. package/fesm2015/esolve-ng-esolve-connect.mjs.map +1 -1
  11. package/fesm2020/esolve-ng-esolve-connect.mjs +462 -376
  12. package/fesm2020/esolve-ng-esolve-connect.mjs.map +1 -1
  13. package/lib/account/esolve-account.service.d.ts +3 -0
  14. package/lib/account/user-account/esolve-user-account-record.interface.d.ts +2 -0
  15. package/lib/account/user-account/esolve-user-account.model.d.ts +2 -0
  16. package/lib/account/user-account/esolve-user-client-account-balances-record.interface.d.ts +11 -0
  17. package/lib/account/user-account/esolve-user-client-account-balances.model.d.ts +12 -0
  18. package/lib/account/user-account/esolve-user-client-account-record.interface.d.ts +39 -0
  19. package/lib/account/user-account/esolve-user-client-account.model.d.ts +40 -0
  20. package/lib/account/user-account/index.d.ts +4 -0
  21. package/package.json +1 -1
@@ -1873,6 +1873,61 @@ class EsolveUserAccountContact {
1873
1873
  }
1874
1874
  }
1875
1875
 
1876
+ class EsolveUserClientAccount {
1877
+ 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) {
1878
+ this.account = account;
1879
+ this.branch_code = branch_code;
1880
+ this.account_group = account_group;
1881
+ this.pricing_group = pricing_group;
1882
+ this.price_list = price_list;
1883
+ this.loyalty_classification_id = loyalty_classification_id;
1884
+ this.company_name = company_name;
1885
+ this.client_contact_person = client_contact_person;
1886
+ this.client_firstname = client_firstname;
1887
+ this.client_surname = client_surname;
1888
+ this.client_email = client_email;
1889
+ this.client_contact_number = client_contact_number;
1890
+ this.client_fax_number = client_fax_number;
1891
+ this.client_cellphone_number = client_cellphone_number;
1892
+ this.client_id_number = client_id_number;
1893
+ this.address_description = address_description;
1894
+ this.street = street;
1895
+ this.suburb = suburb;
1896
+ this.city = city;
1897
+ this.province = province;
1898
+ this.country = country;
1899
+ this.postal_code = postal_code;
1900
+ this.postal_address = postal_address;
1901
+ this.delivery_address = delivery_address;
1902
+ this.latitude = latitude;
1903
+ this.longitude = longitude;
1904
+ this.vat_number = vat_number;
1905
+ this.credit_limit = credit_limit;
1906
+ this.pending_invoice_balance = pending_invoice_balance;
1907
+ this.external_account_balance = external_account_balance;
1908
+ this.ageing = ageing;
1909
+ this.balance_last_updated = balance_last_updated;
1910
+ this.default_sellprice = default_sellprice;
1911
+ this.client_classification = client_classification;
1912
+ this.override_stock_listing_identifiers = override_stock_listing_identifiers;
1913
+ this.requires_transaction_approval = requires_transaction_approval;
1914
+ this.is_active = is_active;
1915
+ }
1916
+ }
1917
+
1918
+ class EsolveUserClientAccountBalances {
1919
+ constructor(clients_id, account, cart_totals, credit_limit, external_account_balance, external_available_balance, new_external_available_balance, credit_limit_okay) {
1920
+ this.clients_id = clients_id;
1921
+ this.account = account;
1922
+ this.cart_totals = cart_totals;
1923
+ this.credit_limit = credit_limit;
1924
+ this.external_account_balance = external_account_balance;
1925
+ this.external_available_balance = external_available_balance;
1926
+ this.new_external_available_balance = new_external_available_balance;
1927
+ this.credit_limit_okay = credit_limit_okay;
1928
+ }
1929
+ }
1930
+
1876
1931
  class EsolveTransactionAddress {
1877
1932
  constructor(recipient, address_type, address_description, street_number, street, suburb, city, province, country, postal_code, pobox) {
1878
1933
  this.recipient = recipient;
@@ -2252,100 +2307,414 @@ class EsolveLocationUpdateResult extends EsolveResponseResult {
2252
2307
  }
2253
2308
  }
2254
2309
 
2255
- class EsolveAccountService {
2256
- constructor(config, http, sessionService, errorHandler, responseHandler) {
2310
+ class EsolveCheckoutResult extends EsolveResponseResult {
2311
+ constructor(response) {
2312
+ super(response);
2313
+ this.id = 0;
2314
+ this.id = +response.esolve_id;
2315
+ this.process_payment = response.process_payment ?? false;
2316
+ }
2317
+ }
2318
+
2319
+ class EsolveCartItem {
2320
+ constructor(id, stock_item, qty, delivery_category, type, price, discount, discount_interval, vat_rate, allow_quotes, allow_orders, must_collect, requested_assembly, price_incl, discount_price, discount_price_incl, discount_total, vat_total, total, total_incl) {
2321
+ this.id = id;
2322
+ this.stock_item = stock_item;
2323
+ this.qty = qty;
2324
+ this.delivery_category = delivery_category;
2325
+ this.type = type;
2326
+ this.price = price;
2327
+ this.discount = discount;
2328
+ this.discount_interval = discount_interval;
2329
+ this.vat_rate = vat_rate;
2330
+ this.allow_quotes = allow_quotes;
2331
+ this.allow_orders = allow_orders;
2332
+ this.must_collect = must_collect;
2333
+ this.requested_assembly = requested_assembly;
2334
+ this.price_incl = price_incl;
2335
+ this.discount_price = discount_price;
2336
+ this.discount_price_incl = discount_price_incl;
2337
+ this.discount_total = discount_total;
2338
+ this.vat_total = vat_total;
2339
+ this.total = total;
2340
+ this.total_incl = total_incl;
2341
+ }
2342
+ }
2343
+
2344
+ class EsolveCartStockItem {
2345
+ constructor(code, name, sef_name, description, active, items_in_pack, delivery_category, onhand, image_name) {
2346
+ this.code = code;
2347
+ this.name = name;
2348
+ this.sef_name = sef_name;
2349
+ this.description = description;
2350
+ this.active = active;
2351
+ this.items_in_pack = items_in_pack;
2352
+ this.delivery_category = delivery_category;
2353
+ this.onhand = onhand;
2354
+ this.image_name = image_name;
2355
+ }
2356
+ /**
2357
+ * Path to tiny stock image
2358
+ */
2359
+ get tiny_image_src() {
2360
+ return this.getImagePath('tiny');
2361
+ }
2362
+ /**
2363
+ * Path to thumbnail stock image
2364
+ */
2365
+ get thumbnail_image_src() {
2366
+ return this.getImagePath('thumb');
2367
+ }
2368
+ /**
2369
+ * Path to small stock image
2370
+ */
2371
+ get small_image_src() {
2372
+ return this.getImagePath('small');
2373
+ }
2374
+ /**
2375
+ * Path to big stock image
2376
+ */
2377
+ get big_image_src() {
2378
+ return this.getImagePath('big');
2379
+ }
2380
+ /**
2381
+ * Path to original stock image
2382
+ */
2383
+ get original_image_src() {
2384
+ return this.getImagePath('original');
2385
+ }
2386
+ getImagePath(image_size) {
2387
+ if (this.image_name !== '') {
2388
+ return `/images/stock/${image_size}/${this.image_name}`;
2389
+ }
2390
+ return '';
2391
+ }
2392
+ }
2393
+
2394
+ /**
2395
+ * Totals in cart
2396
+ */
2397
+ class EsolveCartTotals {
2398
+ constructor(
2399
+ /**
2400
+ * Number of unique records in cart
2401
+ */
2402
+ records = 0,
2403
+ /**
2404
+ * Total quantity of all items in a cart
2405
+ */
2406
+ items = 0,
2407
+ /**
2408
+ * Total in cart before discount and VAT is added
2409
+ */
2410
+ sub_total = 0,
2411
+ /**
2412
+ * Total VAT of all the items in the cart
2413
+ */
2414
+ vat_total = 0,
2415
+ /**
2416
+ * Total discount of all the item in the cart
2417
+ */
2418
+ discount_total = 0) {
2419
+ this.records = records;
2420
+ this.items = items;
2421
+ this.sub_total = sub_total;
2422
+ this.vat_total = vat_total;
2423
+ this.discount_total = discount_total;
2424
+ }
2425
+ /**
2426
+ * Grand total of cart which includes discount and VAT (NOTE: shipping and insurance is not included)
2427
+ */
2428
+ get total() {
2429
+ return this.sub_total + this.vat_total - this.discount_total;
2430
+ }
2431
+ }
2432
+
2433
+ class EsolveEmptyCartResult extends EsolveResponseResult {
2434
+ }
2435
+
2436
+ class EsolveCartService {
2437
+ constructor(config, http, errorHandler, responseHandler) {
2257
2438
  this.config = config;
2258
2439
  this.http = http;
2259
- this.sessionService = sessionService;
2260
2440
  this.errorHandler = errorHandler;
2261
2441
  this.responseHandler = responseHandler;
2262
- this._user_id = 0;
2263
- this.sessionService.session.subscribe((session) => {
2264
- if (session.key !== '') {
2265
- this.user_id = session.id;
2266
- }
2267
- });
2268
- }
2269
- get user_id() {
2270
- return this._user_id;
2442
+ this._cached_tracking = 0;
2271
2443
  }
2272
- set user_id(value) {
2273
- value = ((value > 0) ? value : 0);
2274
- if (this._user_id !== value) {
2275
- this._user_id = value;
2276
- }
2444
+ /**
2445
+ * Retrieves the current cart
2446
+ *
2447
+ * @returns An `Observable` with an array of cart items
2448
+ */
2449
+ getCart() {
2450
+ return this.http
2451
+ .get(`${this.config.api_url}/get-cart.php`)
2452
+ .pipe(map((response) => {
2453
+ if (response.records === undefined) {
2454
+ throw response;
2455
+ }
2456
+ return this.processCart(response.records);
2457
+ }));
2277
2458
  }
2278
- updateUserAccount(user_account_data) {
2459
+ /**
2460
+ * Updates the cart by preforming various actions, such as adding, editing or removing items from the cart.
2461
+ *
2462
+ * @param items An array of options to update the cart
2463
+ * @param action The default action to preform
2464
+ * @returns An `Observable` with an array of responses that gives feedback on the requested changes
2465
+ */
2466
+ setCart(items, action = 'add') {
2279
2467
  const body = {
2280
- account: user_account_data,
2468
+ items,
2469
+ action,
2281
2470
  };
2282
2471
  return this.http
2283
- .post(`${this.config.api_url}/set-user-account.php`, body, {
2472
+ .post(`${this.config.api_url}/set-cart-item.php`, body, {
2284
2473
  headers: {
2285
2474
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2286
2475
  },
2287
2476
  responseType: 'json',
2288
2477
  observe: 'body',
2289
2478
  })
2290
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveUserAccountResult(response))), catchError((errorRes) => {
2291
- return this.errorHandler.handleHttpPostError('set-user-account', errorRes);
2292
- }));
2293
- }
2294
- getUserAccount() {
2295
- return this.http
2296
- .get(`${this.config.api_url}/get-account.php`)
2297
2479
  .pipe(map((response) => {
2298
- if ((response.records === undefined) ||
2299
- (response.records.length === 0)) {
2480
+ if (response.responses === undefined) {
2300
2481
  throw response;
2301
2482
  }
2302
- const record = response.records[0];
2303
- return this.processUserAccount(record);
2483
+ return response.responses;
2304
2484
  }));
2305
2485
  }
2306
- setAddress(address_post_data) {
2486
+ setCartEmpty(type, additional_where) {
2307
2487
  const body = {
2308
- address: address_post_data,
2488
+ type,
2489
+ additional_where,
2309
2490
  };
2310
2491
  return this.http
2311
- .post(`${this.config.api_url}/set-address.php`, body, {
2492
+ .post(`${this.config.api_url}/set-cart-empty.php`, body, {
2312
2493
  headers: {
2313
2494
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2314
2495
  },
2315
2496
  responseType: 'json',
2316
2497
  observe: 'body',
2317
2498
  })
2318
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveAddressResult(response))), catchError((errorRes) => {
2319
- return this.errorHandler.handleHttpPostError('set-registration', errorRes);
2499
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2500
+ this._cached_tracking = 0;
2501
+ return new EsolveEmptyCartResult(response);
2502
+ })), catchError((errorRes) => {
2503
+ return this.errorHandler.handleHttpPostError('set-cart-empty', errorRes);
2320
2504
  }));
2321
2505
  }
2322
- getAddresses() {
2323
- try {
2324
- this.loginGuard();
2325
- return this.http
2326
- .get(`${this.config.api_url}/get-addresses.php`, {
2327
- params: { user_id: this.user_id },
2328
- })
2329
- .pipe(map((response) => {
2330
- if (response.records === undefined) {
2331
- throw response;
2332
- }
2333
- return this.processUserAddress(response.records);
2334
- }));
2335
- }
2336
- catch (error) {
2337
- return throwError(() => error);
2338
- }
2339
- }
2340
- deleteAddress(id) {
2506
+ /**
2507
+ * Retrieves the totals of the cart with all the totals calculated
2508
+ *
2509
+ * @returns An `Observable` with an object containing cart totals
2510
+ */
2511
+ getTotals(type) {
2341
2512
  return this.http
2342
- .delete(`${this.config.api_url}/delete-address.php`, {
2343
- params: { id },
2344
- responseType: 'json',
2345
- observe: 'body',
2513
+ .get(`${this.config.api_url}/get-cart-totals.php`, {
2514
+ params: {
2515
+ type: type ?? '',
2516
+ },
2346
2517
  })
2347
- .pipe(map((http_response) => {
2348
- if ((http_response.result === undefined) ||
2518
+ .pipe(map((response) => {
2519
+ if (response.records === undefined) {
2520
+ throw response;
2521
+ }
2522
+ return this.processCartTotals(response.records);
2523
+ }));
2524
+ }
2525
+ /**
2526
+ * Retrieves a tracking code for the cart
2527
+ *
2528
+ * @returns An `Observable` with the cart tracking code
2529
+ */
2530
+ getTrackingCode() {
2531
+ return iif(() => this._cached_tracking > 0, of(this._cached_tracking), this.http
2532
+ .get(`${this.config.api_url}/get-checkout-tracking.php`)
2533
+ .pipe(map((response) => {
2534
+ if (response.records === undefined) {
2535
+ throw response;
2536
+ }
2537
+ this._cached_tracking = response.records.tracking;
2538
+ return response.records.tracking;
2539
+ })));
2540
+ }
2541
+ /**
2542
+ * Initiates checkout of the cart items
2543
+ *
2544
+ * @param type The cart type that needs to be checked out
2545
+ * @param addresses_id The ID of the delivery address
2546
+ * @param shipping_id The ID of the shipping method
2547
+ * @param payment_method_id The ID of the selected payment method
2548
+ * @param location_id The ID of the selected branch from with shipping needs to be calculated
2549
+ * @param comments Additional comments on the cart
2550
+ * @returns An `Observable` with the transaction ID
2551
+ */
2552
+ checkout(type, addresses_id, shipping_id, payment_method_id = 0, location_id = 0, comments = '') {
2553
+ const body = {
2554
+ type,
2555
+ addresses_id,
2556
+ shipping_id,
2557
+ payment_method_id,
2558
+ location_id,
2559
+ comments,
2560
+ tracking: 0,
2561
+ };
2562
+ return this.getTrackingCode().pipe(switchMap((tracking) => {
2563
+ if (tracking <= 0) {
2564
+ throw tracking;
2565
+ }
2566
+ body.tracking = tracking;
2567
+ return this.http
2568
+ .post(`${this.config.api_url}/set-checkout.php`, body, {
2569
+ headers: {
2570
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2571
+ },
2572
+ responseType: 'json',
2573
+ observe: 'body',
2574
+ })
2575
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2576
+ this._cached_tracking = 0;
2577
+ return new EsolveCheckoutResult(response);
2578
+ })), catchError((errorRes) => {
2579
+ return this.errorHandler.handleHttpPostError('set-checkout', errorRes);
2580
+ }));
2581
+ }));
2582
+ }
2583
+ /**
2584
+ * Processes the eSolve tree records
2585
+ *
2586
+ * @param cart_item_records Records to process
2587
+ * @returns An array of processed cart items
2588
+ */
2589
+ processCart(cart_item_records) {
2590
+ const cart_items = [];
2591
+ if (cart_item_records) {
2592
+ for (const cart_item_record of cart_item_records) {
2593
+ const cart_stock_item = new EsolveCartStockItem(cart_item_record.code, cart_item_record.name, cart_item_record.sef_name, cart_item_record.description, cart_item_record.is_active, +cart_item_record.items_in_pack, cart_item_record.delivery_category, +cart_item_record.onhand, cart_item_record.image_name);
2594
+ cart_items.push(new EsolveCartItem(+cart_item_record.id, cart_stock_item, +cart_item_record.qty, cart_item_record.delivery_category, cart_item_record.type, +cart_item_record.price, +cart_item_record.discount, +cart_item_record.discount_interval, cart_item_record.vat_rate, cart_item_record.allow_quotes, cart_item_record.allow_orders, cart_item_record.must_collect, cart_item_record.requested_assembly, +cart_item_record.price_incl, +cart_item_record.discount_price, +cart_item_record.discount_price_incl, +cart_item_record.discount_total, +cart_item_record.vat_total, +cart_item_record.line_total, +cart_item_record.line_total_incl));
2595
+ }
2596
+ }
2597
+ return cart_items;
2598
+ }
2599
+ /**
2600
+ * Processes the eSolve cart totals
2601
+ *
2602
+ * @param record Data to process
2603
+ * @returns Processed cart totals
2604
+ */
2605
+ processCartTotals(record) {
2606
+ const cart_totals = new EsolveCartTotals(+record.records, +record.items, +record.total, +record.vat, +record.discount);
2607
+ return cart_totals;
2608
+ }
2609
+ }
2610
+ 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 });
2611
+ EsolveCartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, providedIn: 'root' });
2612
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, decorators: [{
2613
+ type: Injectable,
2614
+ args: [{
2615
+ providedIn: 'root',
2616
+ }]
2617
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2618
+ type: Inject,
2619
+ args: [ESOLVE_CONNECT_CONFIG]
2620
+ }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }]; } });
2621
+
2622
+ // TODO: Spilt folder to file types
2623
+
2624
+ class EsolveAccountService {
2625
+ constructor(config, http, sessionService, errorHandler, responseHandler) {
2626
+ this.config = config;
2627
+ this.http = http;
2628
+ this.sessionService = sessionService;
2629
+ this.errorHandler = errorHandler;
2630
+ this.responseHandler = responseHandler;
2631
+ this._user_id = 0;
2632
+ this.sessionService.session.subscribe((session) => {
2633
+ if (session.key !== '') {
2634
+ this.user_id = session.id;
2635
+ }
2636
+ });
2637
+ }
2638
+ get user_id() {
2639
+ return this._user_id;
2640
+ }
2641
+ set user_id(value) {
2642
+ value = ((value > 0) ? value : 0);
2643
+ if (this._user_id !== value) {
2644
+ this._user_id = value;
2645
+ }
2646
+ }
2647
+ updateUserAccount(user_account_data) {
2648
+ const body = {
2649
+ account: user_account_data,
2650
+ };
2651
+ return this.http
2652
+ .post(`${this.config.api_url}/set-user-account.php`, body, {
2653
+ headers: {
2654
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2655
+ },
2656
+ responseType: 'json',
2657
+ observe: 'body',
2658
+ })
2659
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveUserAccountResult(response))), catchError((errorRes) => {
2660
+ return this.errorHandler.handleHttpPostError('set-user-account', errorRes);
2661
+ }));
2662
+ }
2663
+ getUserAccount() {
2664
+ return this.http
2665
+ .get(`${this.config.api_url}/get-account.php`)
2666
+ .pipe(map((response) => {
2667
+ if ((response.records === undefined) ||
2668
+ (response.records.length === 0)) {
2669
+ throw response;
2670
+ }
2671
+ const record = response.records[0];
2672
+ return this.processUserAccount(record);
2673
+ }));
2674
+ }
2675
+ setAddress(address_post_data) {
2676
+ const body = {
2677
+ address: address_post_data,
2678
+ };
2679
+ return this.http
2680
+ .post(`${this.config.api_url}/set-address.php`, body, {
2681
+ headers: {
2682
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2683
+ },
2684
+ responseType: 'json',
2685
+ observe: 'body',
2686
+ })
2687
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveAddressResult(response))), catchError((errorRes) => {
2688
+ return this.errorHandler.handleHttpPostError('set-registration', errorRes);
2689
+ }));
2690
+ }
2691
+ getAddresses() {
2692
+ try {
2693
+ this.loginGuard();
2694
+ return this.http
2695
+ .get(`${this.config.api_url}/get-addresses.php`, {
2696
+ params: { user_id: this.user_id },
2697
+ })
2698
+ .pipe(map((response) => {
2699
+ if (response.records === undefined) {
2700
+ throw response;
2701
+ }
2702
+ return this.processUserAddress(response.records);
2703
+ }));
2704
+ }
2705
+ catch (error) {
2706
+ return throwError(() => error);
2707
+ }
2708
+ }
2709
+ deleteAddress(id) {
2710
+ return this.http
2711
+ .delete(`${this.config.api_url}/delete-address.php`, {
2712
+ params: { id },
2713
+ responseType: 'json',
2714
+ observe: 'body',
2715
+ })
2716
+ .pipe(map((http_response) => {
2717
+ if ((http_response.result === undefined) ||
2349
2718
  (http_response.result === null) ||
2350
2719
  (http_response.result.status !== 'success')) {
2351
2720
  throw http_response;
@@ -2530,6 +2899,22 @@ class EsolveAccountService {
2530
2899
  return throwError(() => error);
2531
2900
  }
2532
2901
  }
2902
+ getClientAccountBalances() {
2903
+ try {
2904
+ this.loginGuard();
2905
+ return this.http
2906
+ .get(`${this.config.api_url}/get-client-account-balances.php`)
2907
+ .pipe(map((response) => {
2908
+ if (response.records === undefined) {
2909
+ throw response;
2910
+ }
2911
+ return this.processClientBalances(response.records);
2912
+ }));
2913
+ }
2914
+ catch (error) {
2915
+ return throwError(() => error);
2916
+ }
2917
+ }
2533
2918
  processUserAccount(record) {
2534
2919
  if (!record) {
2535
2920
  throw new Error('Invalid record');
@@ -2540,6 +2925,11 @@ class EsolveAccountService {
2540
2925
  const user_account = new EsolveUserAccount(+record.userid, record.email, record.registration_type, record.title, record.firstname, record.surname, record.initials, record.gender, record.idnumber);
2541
2926
  user_account.contact_details = new EsolveUserAccountContact(record.telnumber, record.cellnumber, record.fax);
2542
2927
  user_account.business_details = new EsolveUserAccountBusiness(record.busname, record.vatnum, record.busdescript, record.business_type);
2928
+ if (record.client_details != undefined) {
2929
+ if (record.client_details?.account !== '') {
2930
+ 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);
2931
+ }
2932
+ }
2543
2933
  return user_account;
2544
2934
  }
2545
2935
  processUserAddress(records) {
@@ -2565,6 +2955,16 @@ class EsolveAccountService {
2565
2955
  }
2566
2956
  return transactions;
2567
2957
  }
2958
+ processClientBalances(records) {
2959
+ for (const record of records) {
2960
+ if (!(+record.clients_id > 0)) {
2961
+ return undefined;
2962
+ }
2963
+ const cart_totals = new EsolveCartTotals(record.cart_totals.records, +record.cart_totals.items, +record.cart_totals.total, +record.cart_totals.vat, +record.cart_totals.discount);
2964
+ return new EsolveUserClientAccountBalances(+record.clients_id, record.account, cart_totals, +record.credit_limit, +record.external_account_balance, +record.external_available_balance, +record.new_external_available_balance, record.credit_limit_okay);
2965
+ }
2966
+ return undefined;
2967
+ }
2568
2968
  loginGuard() {
2569
2969
  if (this.user_id <= 0) {
2570
2970
  this.errorHandler.throwError('login_required', 'Login is required');
@@ -3949,320 +4349,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
3949
4349
  args: [ESOLVE_CONNECT_CONFIG]
3950
4350
  }] }, { type: i1$2.HttpClient }]; } });
3951
4351
 
3952
- class EsolveCheckoutResult extends EsolveResponseResult {
3953
- constructor(response) {
3954
- super(response);
3955
- this.id = 0;
3956
- this.id = +response.esolve_id;
3957
- this.process_payment = response.process_payment ?? false;
3958
- }
3959
- }
3960
-
3961
- class EsolveCartItem {
3962
- constructor(id, stock_item, qty, delivery_category, type, price, discount, discount_interval, vat_rate, allow_quotes, allow_orders, must_collect, requested_assembly, price_incl, discount_price, discount_price_incl, discount_total, vat_total, total, total_incl) {
3963
- this.id = id;
3964
- this.stock_item = stock_item;
3965
- this.qty = qty;
3966
- this.delivery_category = delivery_category;
3967
- this.type = type;
3968
- this.price = price;
3969
- this.discount = discount;
3970
- this.discount_interval = discount_interval;
3971
- this.vat_rate = vat_rate;
3972
- this.allow_quotes = allow_quotes;
3973
- this.allow_orders = allow_orders;
3974
- this.must_collect = must_collect;
3975
- this.requested_assembly = requested_assembly;
3976
- this.price_incl = price_incl;
3977
- this.discount_price = discount_price;
3978
- this.discount_price_incl = discount_price_incl;
3979
- this.discount_total = discount_total;
3980
- this.vat_total = vat_total;
3981
- this.total = total;
3982
- this.total_incl = total_incl;
3983
- }
3984
- }
3985
-
3986
- class EsolveCartStockItem {
3987
- constructor(code, name, sef_name, description, active, items_in_pack, delivery_category, onhand, image_name) {
3988
- this.code = code;
3989
- this.name = name;
3990
- this.sef_name = sef_name;
3991
- this.description = description;
3992
- this.active = active;
3993
- this.items_in_pack = items_in_pack;
3994
- this.delivery_category = delivery_category;
3995
- this.onhand = onhand;
3996
- this.image_name = image_name;
3997
- }
3998
- /**
3999
- * Path to tiny stock image
4000
- */
4001
- get tiny_image_src() {
4002
- return this.getImagePath('tiny');
4003
- }
4004
- /**
4005
- * Path to thumbnail stock image
4006
- */
4007
- get thumbnail_image_src() {
4008
- return this.getImagePath('thumb');
4009
- }
4010
- /**
4011
- * Path to small stock image
4012
- */
4013
- get small_image_src() {
4014
- return this.getImagePath('small');
4015
- }
4016
- /**
4017
- * Path to big stock image
4018
- */
4019
- get big_image_src() {
4020
- return this.getImagePath('big');
4021
- }
4022
- /**
4023
- * Path to original stock image
4024
- */
4025
- get original_image_src() {
4026
- return this.getImagePath('original');
4027
- }
4028
- getImagePath(image_size) {
4029
- if (this.image_name !== '') {
4030
- return `/images/stock/${image_size}/${this.image_name}`;
4031
- }
4032
- return '';
4033
- }
4034
- }
4035
-
4036
- /**
4037
- * Totals in cart
4038
- */
4039
- class EsolveCartTotals {
4040
- constructor(
4041
- /**
4042
- * Number of unique records in cart
4043
- */
4044
- records = 0,
4045
- /**
4046
- * Total quantity of all items in a cart
4047
- */
4048
- items = 0,
4049
- /**
4050
- * Total in cart before discount and VAT is added
4051
- */
4052
- sub_total = 0,
4053
- /**
4054
- * Total VAT of all the items in the cart
4055
- */
4056
- vat_total = 0,
4057
- /**
4058
- * Total discount of all the item in the cart
4059
- */
4060
- discount_total = 0) {
4061
- this.records = records;
4062
- this.items = items;
4063
- this.sub_total = sub_total;
4064
- this.vat_total = vat_total;
4065
- this.discount_total = discount_total;
4066
- }
4067
- /**
4068
- * Grand total of cart which includes discount and VAT (NOTE: shipping and insurance is not included)
4069
- */
4070
- get total() {
4071
- return this.sub_total + this.vat_total - this.discount_total;
4072
- }
4073
- }
4074
-
4075
- class EsolveEmptyCartResult extends EsolveResponseResult {
4076
- }
4077
-
4078
- class EsolveCartService {
4079
- constructor(config, http, errorHandler, responseHandler) {
4080
- this.config = config;
4081
- this.http = http;
4082
- this.errorHandler = errorHandler;
4083
- this.responseHandler = responseHandler;
4084
- this._cached_tracking = 0;
4085
- }
4086
- /**
4087
- * Retrieves the current cart
4088
- *
4089
- * @returns An `Observable` with an array of cart items
4090
- */
4091
- getCart() {
4092
- return this.http
4093
- .get(`${this.config.api_url}/get-cart.php`)
4094
- .pipe(map((response) => {
4095
- if (response.records === undefined) {
4096
- throw response;
4097
- }
4098
- return this.processCart(response.records);
4099
- }));
4100
- }
4101
- /**
4102
- * Updates the cart by preforming various actions, such as adding, editing or removing items from the cart.
4103
- *
4104
- * @param items An array of options to update the cart
4105
- * @param action The default action to preform
4106
- * @returns An `Observable` with an array of responses that gives feedback on the requested changes
4107
- */
4108
- setCart(items, action = 'add') {
4109
- const body = {
4110
- items,
4111
- action,
4112
- };
4113
- return this.http
4114
- .post(`${this.config.api_url}/set-cart-item.php`, body, {
4115
- headers: {
4116
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
4117
- },
4118
- responseType: 'json',
4119
- observe: 'body',
4120
- })
4121
- .pipe(map((response) => {
4122
- if (response.responses === undefined) {
4123
- throw response;
4124
- }
4125
- return response.responses;
4126
- }));
4127
- }
4128
- setCartEmpty(type, additional_where) {
4129
- const body = {
4130
- type,
4131
- additional_where,
4132
- };
4133
- return this.http
4134
- .post(`${this.config.api_url}/set-cart-empty.php`, body, {
4135
- headers: {
4136
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
4137
- },
4138
- responseType: 'json',
4139
- observe: 'body',
4140
- })
4141
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
4142
- this._cached_tracking = 0;
4143
- return new EsolveEmptyCartResult(response);
4144
- })), catchError((errorRes) => {
4145
- return this.errorHandler.handleHttpPostError('set-cart-empty', errorRes);
4146
- }));
4147
- }
4148
- /**
4149
- * Retrieves the totals of the cart with all the totals calculated
4150
- *
4151
- * @returns An `Observable` with an object containing cart totals
4152
- */
4153
- getTotals(type) {
4154
- return this.http
4155
- .get(`${this.config.api_url}/get-cart-totals.php`, {
4156
- params: {
4157
- type: type ?? '',
4158
- },
4159
- })
4160
- .pipe(map((response) => {
4161
- if (response.records === undefined) {
4162
- throw response;
4163
- }
4164
- return this.processCartTotals(response.records);
4165
- }));
4166
- }
4167
- /**
4168
- * Retrieves a tracking code for the cart
4169
- *
4170
- * @returns An `Observable` with the cart tracking code
4171
- */
4172
- getTrackingCode() {
4173
- return iif(() => this._cached_tracking > 0, of(this._cached_tracking), this.http
4174
- .get(`${this.config.api_url}/get-checkout-tracking.php`)
4175
- .pipe(map((response) => {
4176
- if (response.records === undefined) {
4177
- throw response;
4178
- }
4179
- this._cached_tracking = response.records.tracking;
4180
- return response.records.tracking;
4181
- })));
4182
- }
4183
- /**
4184
- * Initiates checkout of the cart items
4185
- *
4186
- * @param type The cart type that needs to be checked out
4187
- * @param addresses_id The ID of the delivery address
4188
- * @param shipping_id The ID of the shipping method
4189
- * @param payment_method_id The ID of the selected payment method
4190
- * @param location_id The ID of the selected branch from with shipping needs to be calculated
4191
- * @param comments Additional comments on the cart
4192
- * @returns An `Observable` with the transaction ID
4193
- */
4194
- checkout(type, addresses_id, shipping_id, payment_method_id = 0, location_id = 0, comments = '') {
4195
- const body = {
4196
- type,
4197
- addresses_id,
4198
- shipping_id,
4199
- payment_method_id,
4200
- location_id,
4201
- comments,
4202
- tracking: 0,
4203
- };
4204
- return this.getTrackingCode().pipe(switchMap((tracking) => {
4205
- if (tracking <= 0) {
4206
- throw tracking;
4207
- }
4208
- body.tracking = tracking;
4209
- return this.http
4210
- .post(`${this.config.api_url}/set-checkout.php`, body, {
4211
- headers: {
4212
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
4213
- },
4214
- responseType: 'json',
4215
- observe: 'body',
4216
- })
4217
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
4218
- this._cached_tracking = 0;
4219
- return new EsolveCheckoutResult(response);
4220
- })), catchError((errorRes) => {
4221
- return this.errorHandler.handleHttpPostError('set-checkout', errorRes);
4222
- }));
4223
- }));
4224
- }
4225
- /**
4226
- * Processes the eSolve tree records
4227
- *
4228
- * @param cart_item_records Records to process
4229
- * @returns An array of processed cart items
4230
- */
4231
- processCart(cart_item_records) {
4232
- const cart_items = [];
4233
- if (cart_item_records) {
4234
- for (const cart_item_record of cart_item_records) {
4235
- const cart_stock_item = new EsolveCartStockItem(cart_item_record.code, cart_item_record.name, cart_item_record.sef_name, cart_item_record.description, cart_item_record.is_active, +cart_item_record.items_in_pack, cart_item_record.delivery_category, +cart_item_record.onhand, cart_item_record.image_name);
4236
- cart_items.push(new EsolveCartItem(+cart_item_record.id, cart_stock_item, +cart_item_record.qty, cart_item_record.delivery_category, cart_item_record.type, +cart_item_record.price, +cart_item_record.discount, +cart_item_record.discount_interval, cart_item_record.vat_rate, cart_item_record.allow_quotes, cart_item_record.allow_orders, cart_item_record.must_collect, cart_item_record.requested_assembly, +cart_item_record.price_incl, +cart_item_record.discount_price, +cart_item_record.discount_price_incl, +cart_item_record.discount_total, +cart_item_record.vat_total, +cart_item_record.line_total, +cart_item_record.line_total_incl));
4237
- }
4238
- }
4239
- return cart_items;
4240
- }
4241
- /**
4242
- * Processes the eSolve cart totals
4243
- *
4244
- * @param record Data to process
4245
- * @returns Processed cart totals
4246
- */
4247
- processCartTotals(record) {
4248
- const cart_totals = new EsolveCartTotals(+record.records, +record.items, +record.total, +record.vat, +record.discount);
4249
- return cart_totals;
4250
- }
4251
- }
4252
- 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 });
4253
- EsolveCartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, providedIn: 'root' });
4254
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: EsolveCartService, decorators: [{
4255
- type: Injectable,
4256
- args: [{
4257
- providedIn: 'root',
4258
- }]
4259
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
4260
- type: Inject,
4261
- args: [ESOLVE_CONNECT_CONFIG]
4262
- }] }, { type: i1$2.HttpClient }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }]; } });
4263
-
4264
- // TODO: Spilt folder to file types
4265
-
4266
4352
  // Only export the types that are accessible to the public API
4267
4353
 
4268
4354
  class EsolveBankingDetails {
@@ -5022,5 +5108,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
5022
5108
  * Generated bundle index. Do not edit.
5023
5109
  */
5024
5110
 
5025
- 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, 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, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveVaultItem, EsolveVaultItemResult, EsolveWishlistItem, EsolveWishlistService, NgEsolveConnectModule };
5111
+ 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, 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, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveUserClientAccount, EsolveUserClientAccountBalances, EsolveVaultItem, EsolveVaultItemResult, EsolveWishlistItem, EsolveWishlistService, NgEsolveConnectModule };
5026
5112
  //# sourceMappingURL=esolve-ng-esolve-connect.mjs.map