PageSourceSearch

https://www.touchstonetonewoods.co.uk/common/js/intactajax.js?v=255

js touchstonetonewoods.co.uk collected 2026-10-04 03:08:05 UTC 27,982 bytes, 688 lines download raw bytes

1webshop.service = {
2    getProducts: {
3        eachItem: function (index, obj) {
4            var nval = index.toString();
5            quick_intact_cache[nval] = obj;
6            quick_intact_cache[nval].StockWarning = '';
7
8            $('.intact-get-name[title="' + nval + '"]').text(obj.Description);
9            $('.intact-category[title="' + nval + '"]').text(obj.Category);
10            $('.intact-status[title="' + nval + '"]').text(obj.Status);
11
12
13            if (!obj.NonPriced && obj.GrossPrice == '0.00') {
14                $('.currency_symbol').hide();
15                $('.intact-price[title="' + nval + '"]').html(webshop._.webshop.unavailable);
16                $('.intact-stock[title="' + nval + '"]').hide();
17                $('.intact-VAT[title="' + nval + '"]').hide();
18            } else {
19
20                if (obj.SellingUnits) {
21                    $('.intact-sellingunits[title="' + nval + '"]').text(obj.SellingUnits);
22                }
23
24                $('.intact-sellmessage[data-product-code="' + nval + '"]').html(obj.SellMessage);
25
26                if (obj.BatchesHtml) {
27                    $('.intact-batches[data-product-code="' + nval + '"]').html(obj.BatchesHtml);
28                }
29
30                if (obj.StockLocationsHTML) {
31                    $('.intact-stock-locations[data-product-code="' + nval + '"]').html(obj.StockLocationsHTML);
32                }
33
34                var breakSet = $('.intact-qtybreaks[data-product-code="' + nval + '"]');
35                if (breakSet.is('*') && !breakSet.is('.do-not-remove')) {
36                    breakSet.html(obj.QtyBreaksHtml);
37                }
38
39                const UoMsTable = $('.intact-units-of-measure-table[data-product-code="' + nval + '"]');
40                if (UoMsTable.is('*') && !UoMsTable.is('.do-not-remove')) {
41                    UoMsTable.html(obj.UnitsOfMeasureTable);
42                }
43
44                var stockDecimalPattern = /(\d*\.?\d+)/g;
45                var matches = stockDecimalPattern.exec(obj.Stock);
46
47                if (matches) {
48                    obj.Stock = obj.Stock.replace('.' + matches[0].split('.')[1], '');
49                }
50
51
52                $('.intact-stock[title="' + nval + '"]').html(obj.Stock);
53                $('.intact-VAT[title="' + nval + '"]').text('VAT: ' + obj.VATRate + '%');
54                //Set cheapest price
55                if (typeof options_matrix != 'undefined') {
56                    for (var po in options_matrix) {
57                        if (options_matrix[po].SKU === obj.Code) {
58                            var price_float = parseFloat(obj.PriceFloat);
59                            if (price_float < cheapest_product || cheapest_product == 0) {
60                                cheapest_product = price_float;
61                            }
62                        }
63                    }
64                }
65
66                //$('.intact-price[title="' + nval + '"]').text(shopconfig.currency + '' + obj[shopconfig.price] + shopconfig.postprice);
67                $('.intact-price[title="' + nval + '"]').html(obj[shopconfig.price]);
68                $('.intact-unitprice[title="' + nval + '"]').text(shopconfig.currency + '' + obj.Price);
69                $('.intact-soldin[title="' + nval + '"]').text(obj.Stock);
70                $('.intact-department[title="' + nval + '"]').text(obj.Dept);
71                $('.addbtn[title="' + nval + '"]').removeClass('hide');
72
73                $('.intact-peritem[title="' + nval + '"]').text(shopconfig.currency + '' + obj.PerItemPrice + shopconfig.postprice + ' ' + shopconfig.postpriceperitem);
74
75                if (obj.batchMatchCheckbox && !obj.StockAmount) {
76                    setTimeout(function () {
77                        $('.addtocart-ref').css('display', 'none');
78                        $('.batch-match').removeClass('hide');
79                    }, 0);
80                }
81
82                if (typeof webshop.service.getProducts.eachItemAdditional === 'function') {
83                    webshop.service.getProducts.eachItemAdditional(index, obj);
84                }
85
86                if ($('.addtocartgroup').hasClass('products__add-wait-for-price')) {
87                    $('.addtocartgroup').removeClass('products__add-wait-for-price');
88                }
89
90                // Find the correct object to attach the UoMs and update price
91                try {
92                    const { addToCart } = webshop.cart;
93                    for (const productId in addToCart._PackSizeOptions) { // Iterate IDs
94                        const hasSameUoMCode = addToCart._PackSizeOptions[productId].filter(pso => pso.code === obj.UnitsOfMeasure[0].code); // See if this ID has the same UoM codes (aka is same product)
95                        if (hasSameUoMCode.length) {
96                            addToCart.setPackSizeOptions(productId, obj.UnitsOfMeasure);
97                            // If the user selected a UoM before this call, trigger the click on the selected UoM again to keep values
98                            if (addToCart._selectedUnitsForProducts[productId]) {
99                                addToCart.selectPackSizeOption(productId, addToCart._selectedUnitsForProducts[productId].code);
100                            }
101                        }
102                    }
103                } catch (error) {
104                    // console.error('Unable to set UoMs', error);
105                }
106            }
107        },
108        // this function is called after ajax query and can be redefined
109        onSuccess: function (data) {
110        }
111    }
112};
113
114var intact_get_products = ['get-name', 'category', 'price', 'unitprice', 'status', 'stock', 'vat', 'message'];
115var intact_get_customer = {
116    'name': 'Name',
117    'email': 'EMail',
118    'credit-limit': 'CreditLimit',
119    'address': 'Address',
120    'hocode': 'HoCode'
121};
122var intact_get_orders = {
123    'number': 'Number',
124    'orderdate': 'OrderDate',
125    'duedate': 'DueDate',
126    'orderlines_html': 'orderlines_html'
127};
128var intact_get_purchase_orders = {
129    'number': 'OrderReference',
130    'orderdate': 'TransactionDate',
131    'duedate': 'TransactionDueDate',
132    'orderlines_html': 'orderlines_html'
133}
134var intact_get_purchase_order_quotations = {
135    'number': 'OrderReference',
136    'orderdate': 'TransactionDate',
137    'duedate': 'TransactionDueDate',
138    'orderlines_html': 'orderlines_html'
139}
140var intact_my_account = {
141    'name': 'Name',
142    'email': 'EMail',
143    'credit': 'CreditLimit',
144    'balance': 'Balance',
145    'overdue-balance': 'OverdueBalance',
146    'address': 'Address',
147    'phone': 'Phone1',
148    'discount': 'DiscountPcnt',
149    'creditRemains': 'CreditRemains',
150    'onOrder': 'OnOrder',
151};
152var quick_intact_cache = {};
153var prefix_customer = 'intact-customer';
154var prefix_order = 'intact-order';
155var prefix_purchaseorder = 'intact-po-order';
156var prefix_purchaseorderquotation = 'intact-po-order-quotation';
157
158
159var myaccountajax = false;
160var get_product_price = false;
161
162$(document).ready(function () {
163    intact_products();
164
165    /**
166     * Customer Information
167     */
168    var customer_codes = [];
169    $.each(intact_get_customer, function (i, val) {
170        $.each($('.intact-customer-' + i), function () {
171            var code = $(this).attr('title');
172            if ($.inArray(code, customer_codes) == '-1') {
173                customer_codes.push(code);
174            }
175        });
176    });
177
178    if (customer_codes.length > 0) {
179        $.each(customer_codes, function (i, val) {
180            var nval = val;
181            $.ajax({
182                url: '/system/intact/getcustomer.html',
183                data: 'code=' + flood_code + '&sku=' + val,
184                success: function (data) {
185                    data = JSON.parse(data);
186                    if (!data.error && data.data) {
187                        $.each(data.data, function (index, obj) {
188                            $.each(intact_get_customer, function (fix, map) {
189                                $('.' + prefix_customer + '-' + fix + '[title="' + nval + '"]').text(obj[map]);
190                            });
191                        });
192                    }
193                    if (!data.error && data.dataContacts) {
194                        // found erp contacts
195
196                        var options = {};
197                        $.each(data.dataContacts, function (customerCode, set) {
198                            options[customerCode] = {};
199                            $.each(set, function (i, contact) {
200                                if (contact.Email != '') {
201                                    options[customerCode][contact.Email] = contact.Email + ' (' + contact.FirstName + ' ' + contact.LastName + ')';
202                                }
203                            });
204                        });
205
206                        var selects = $('#erp-contacts'); // support more than one at a time.
207                        $.each(selects, function (i, selectInput) {
208                            var selectBox = $(selectInput);
209                            var code = selectBox.attr('data-id');
210                            var optionHtml = '';
211                            if (options[code]) {
212                                selectBox.attr('disabled', false);
213                                optionHtml += '<option value="">Use existing contact</option>';
214                                for (var email in options[code]) {
215                                    optionHtml += '<option value="' + email + '">' + options[code][email] + '</option>';
216                                }
217                            } else {
218                                // none found
219                                selectBox.attr('disabled', true);
220                                optionHtml = '<option value="">No contacts with email addresses from your ERP</option>';
221
222                            }
223                            selectBox.html(optionHtml);
224                        });
225                    }
226                }
227            });
228        });
229    }
230
231    /**
232     * Order Details
233     */
234    var order_refs = [];
235    $.each(intact_get_orders, function (i, val) {
236        $.each($('.' + prefix_order + '-' + i), function () {
237            var code = $(this).attr('title');
238            if ($.inArray(code, order_refs) == '-1') {
239                order_refs.push(code);
240            }
241        });
242    });
243
244    if (order_refs.length > 0) {
245        $.each(order_refs, function (i, val) {
246            var nval = val;
247            $.ajax({
248                url: '/system/intact/getorder.html',
249                data: 'code=' + flood_code + '&ref=' + val,
250                success: function (data) {
251                    data = JSON.parse(data);
252                    if (!data.error && data.data) {
253                        $.each(data.data, function (index, obj) {
254                            $.each(intact_get_orders, function (fix, map) {
255                                if (fix == 'duedate' && obj[map] == '') {
256                                    $('#due-date').hide();
257                                } else {
258                                    $('.' + prefix_order + '-' + fix + '[title="' + nval + '"]').html(obj[map]);
259                                }
260                            });
261
262                            //Reorder btn
263                            if ($('.reorder[title="' + nval + '"]').is('*')) {
264                                if(index !='comments') {
265                                    $('.reorder[title="' + nval + '"]').attr('href', '/checkout.html?addmulti=' + obj.addmulti);
266                                    $('.reorder[title="' + nval + '"]').show();
267
268                                    if (obj.unable_to_order) {
269                                        $('.reorder[title="' + nval + '"]').click(function () {
270                                            return confirm(obj.unable_to_order);
271                                        });
272                                    }
273                                    $('.reorder[title="' + nval + '"]').click(function () {
274                                        $('#loadReorder').removeClass("hidden");
275                                        $('.order-history-area').hide();
276                                    });
277                                }
278                            }
279
280                            // Spreadsheet + Images Download
281                            if ($('.download-spreadsheet').is('*')) {
282                                $('.download-spreadsheet').show();
283                            }
284                        });
285
286                        if (data.data.comments != undefined) {
287                            $('.order-notes').show();
288
289                            if (Object.keys(data.data.comments).length > 0) {
290                             $('.order-notes_list').html('');
291
292                            $.each(data.data.comments, function (index, obj) {
293                                $('.order-notes_list').append(obj);
294                            });
295                            }
296                        }
297                    }
298                }
299            });
300        });
301    }
302
303    /**
304     * Purchase Order Details
305     */
306    var purchase_order_refs = [];
307    $.each(intact_get_purchase_orders, function (i, val) {
308        $.each($('.' + prefix_purchaseorder + '-' + i), function () {
309            var code = $(this).attr('title');
310            if ($.inArray(code, purchase_order_refs) == '-1') {
311                purchase_order_refs.push(code);
312            }
313        });
314    });
315
316    if (purchase_order_refs.length > 0) {
317        $.each(purchase_order_refs, function (i, val) {
318            var nval = val;
319            $.ajax({
320                url: '/system/intact/purchaseorder.html',
321                data: 'code=' + flood_code + '&ref=' + val,
322                success: function (data) {
323                    data = JSON.parse(data);
324                    if (!data.error && data.data) {
325                        $.each(data.data, function (index, obj) {
326                            $.each(intact_get_purchase_orders, function (fix, map) {
327                                if (fix == 'duedate' && obj[map] == '') {
328                                    $('#due-date').hide();
329                                } else {
330                                    $('.' + prefix_purchaseorder + '-' + fix + '[title="' + nval + '"]').html(obj[map]);
331                                }
332                            });
333                        });
334                    }
335                }
336            });
337        });
338    }
339
340    /**
341     * Purchase Order Quotation Details
342     */
343    var purchase_order_quotation_refs = [];
344    $.each(intact_get_purchase_order_quotations, function (i, val) {
345        $.each($('.' + prefix_purchaseorderquotation + '-' + i), function () {
346            var code = $(this).attr('title');
347            if ($.inArray(code, purchase_order_quotation_refs) == '-1') {
348                purchase_order_quotation_refs.push(code);
349            }
350        });
351    });
352
353    if (purchase_order_quotation_refs.length > 0) {
354        $.each(purchase_order_quotation_refs, function (i, val) {
355            var nval = val;
356            $.ajax({
357                url: '/system/intact/purchaseorderquotation.html',
358                data: 'code=' + flood_code + '&ref=' + val,
359                success: function (data) {
360                    data = JSON.parse(data);
361                    if (!data.error && data.data) {
362                        $.each(data.data, function (index, obj) {
363                            $.each(intact_get_purchase_order_quotations, function (fix, map) {
364                                if (fix == 'duedate' && obj[map] == '') {
365                                    $('#due-date').hide();
366                                } else {
367                                    $('.' + prefix_purchaseorderquotation + '-' + fix + '[title="' + nval + '"]').html(obj[map]);
368                                }
369                            });
370                        });
371                    }
372                }
373            });
374        });
375    }
376
377    /*
378     * My Account
379     */
380    if ($('[class^=myaccount]').is('*')) {
381        myaccountajax = $.ajax({
382            url: '/system/intact/myaccount.html',
383            data: 'code=' + flood_code,
384            success: function (data, l, e) {
385                data = JSON.parse(data);
386                if (!data.error && data.data) {
387                    $.each(data.data, function (index, obj) {
388                        $.each(intact_my_account, function (fix, map) {
389                            if (fix == 'address' && obj[map]) {
390                                var splitaddress = obj[map].split(/,/g);
391                                // add in post code
392                                splitaddress.push(obj.PostCode)
393                                obj[map] = splitaddress.join('<br />');
394                            }
395                            $('.myaccount-' + fix).html(obj[map]);
396                            if (['creditRemains', 'onOrder'].includes(fix)) {
397                                // Get the class names for the span element and table row element on the dashboard.
398                                const spanClassName = `.myaccount-${fix}`;
399
400                                const tableRowClassName = `.hide${map}`;
401
402                                // Get the elements for the span class and table row class.
403                                const spanElement = document.querySelector(spanClassName);
404
405                                const tableRowElement = document.querySelector(tableRowClassName);
406
407                                // Check if the element exists and its text is "Loading..."
408                                if (spanElement && (spanElement.textContent.trim() === webshop._.webshop.loading.text || spanElement.textContent.trim() === '')) {
409                                    // Hide the element
410                                    tableRowElement.style.display = "none";
411                                }
412                            }
413                        });
414                    });
415                } else {
416                    $.each(intact_my_account, function (fix, map) {
417                        $('.myaccount-' + fix).html(webshop._.webshop.unavailable);
418                    });
419                }
420            }
421        });
422    }
423
424    /*
425     * Aged balance
426     */
427    if ($('[class^=mybalance]').is('*')) {
428        $.ajax({
429            url: '/system/intact/mybalance.html',
430            data: 'code=' + flood_code,
431            success: function (data) {
432                data = JSON.parse(data);
433                if (!data.error && data.data) {
434                    $.each(data.data, function (index, obj) {
435
436                    });
437                }
438            }
439        });
440    }
441
442    /*
443     * Ledger
444     */
445    if ($('[class^=myledger]').is('*')) {
446        $.ajax({
447            url: '/system/intact/myledger.html',
448            data: 'code=' + flood_code,
449            success: function (data) {
450                data = JSON.parse(data);
451                if (!data.error && data.data) {
452                    $('.myledger-list').html(data.data);
453                    if (data.pagination) {
454                        $('.invoice-history-pagination').html(data.pagination);
455                    }
456
457                    $('.erp-statements').statements({
458                        payments: shopconfig.invoicePayments,
459                        checkedFn: function (refs) {
460                            var $pay = $('.btn-statements-pay');
461                            var $input = $('.statements-actions input[type=hidden]');
462
463                            if (refs.length > 0) {
464                                $pay.val('Pay ' + refs.length + ' invoices');
465                                $pay.removeClass('hidden');
466                            } else {
467                                $pay.addClass('hidden');
468                            }
469
470                            $input.val(refs);
471                        },
472                    });
473
474                    var $actions = $('.statements-actions');
475
476                    if ($actions.is('*')) {
477                        var $filters = $actions.find('.filters');
478
479                        var $select = $('<select></select>');
480
481                        $select.append('<option value="">View All</option>');
482
483                        var types = [];
484
485                        $('.erp-statements tbody tr').each(function (i, row) {
486                            var type = $(row).attr('data-type');
487
488                            if (!types.includes(type)) {
489                                $select.append('<option value="' + type + '">' + type + '</option>');
490                                types.push(type);
491                            }
492                        });
493
494                        $select.on('change', function () {
495                            if (this.value === '') {
496                                $('.erp-statements tbody tr').removeClass('hidden');
497                            } else {
498                                $('.erp-statements tbody tr').addClass('hidden');
499                                $('.erp-statements tbody tr[data-type="' + this.value + '"]').removeClass('hidden');
500                            }
501                        });
502
503                        $filters.append($select);
504                    }
505                }
506            }
507        });
508    }
509
510    /*
511     * Ledger Outstanding
512     */
513    if ($('[class^=myosledger]').is('*')) {
514        $.ajax({
515            url: '/system/intact/myosledger.html',
516            data: 'code=' + flood_code,
517            success: function (data) {
518                data = JSON.parse(data);
519                if (!data.error && data.data) {
520                    $('.myosledger-list').html(data.data);
521                }
522            }
523        });
524    }
525});
526
527function orderhistory(page, orderStatus, searchCriteria = {}) {
528    var page = page || 0;
529    var orderStatus = orderStatus || '';
530
531    if ($('.intact-my-orderhistory').is('*')) {
532        $('.intact-my-orderhistory tbody').html('<tr><td colspan="7">' + webshop._.webshop.loadingorderhistory + '</td></tr>');
533        $.ajax({
534            url: '/system/intact/orderhistory.html',
535            data: {
536                status: orderStatus,
537                page: page,
538                ...searchCriteria
539            },
540            success: function (data) {
541                if (!data.error && data.orders) {
542                    $('.intact-my-orderhistory tbody').html(data.orders);
543                    $('.order-history-pagination').html(data.pagination);
544                } else {
545                    $('.intact-my-orderhistory tbody').html('<tr><td colspan="7">' + webshop._.webshop.unabletogetorders + '</td></tr>');
546                }
547            }
548        });
549    }
550}
551
552var cheapest_product = 0.00;
553
554function intact_products() {
555    /**
556     * Product Information
557     */
558    var codes = [];
559    const productsInCache = {};
560    $.each(intact_get_products, function (i, val) {
561        $.each($('.intact-' + val), function () {
562            var code = $(this).attr('title');
563            if (code) {
564                // we have to de-encode, then re-encode it when we send to add support for # and like characters
565                code = decodeURIComponent(code);
566                if ($.inArray(code, codes) == '-1') {
567                    if (quick_intact_cache[code]) {
568                        productsInCache[code] = quick_intact_cache[code];
569                    } else {
570                        codes.push(code);
571                    }
572                }
573                $(this).attr('title', code);
574            }
575        });
576    });
577
578    // Fill the products already in cache
579    // Needs to be outside the if otherwise if all products are cached, none are filled
580    $.each(productsInCache, webshop.service.getProducts.eachItem);
581
582    if (codes.length > 0) {
583
584        var index = 0;
585        var chunk_size = 50;
586        var arrayLength = codes.length;
587
588        for (index = 0; index < arrayLength; index += chunk_size) {
589            var chunk = codes.slice(index, index + chunk_size);
590
591            var SKUs = chunk.join(',');
592            get_product_price = $.ajax({
593                url: '/system/intact/getproducts.html',
594                data: 'code=' + flood_code + '&SKU=' + encodeURIComponent(SKUs),
595                success: function (data) {
596                    if (!data.error && data.data) {
597                        $.each(data.data, webshop.service.getProducts.eachItem);
598
599                        //Call Function for Product Option Prices
600                        if (typeof options_matrix != "undefined" && typeof select_product_options != "undefined") {
601                            options_prices_loaded();
602                        }
603
604                        // callback
605                        webshop.service.getProducts.onSuccess(data.data);
606                    } else {
607                        $('.currency_symbol').hide();
608                        $('#sidebar-featured .add').hide();
609                        $('.intact-price').html(webshop.cart.addToCart.loginToSeePrice(window.location));
610                        $('.intact-stock').text('');
611                        $('.intact-VAT').text('');
612                    }
613                }
614            });
615        }
616    }
617}
618
619function disableSubmitBtn(formEl) {
620    var $btn = $(formEl).find('input[type="submit"]');
621    $btn.attr('disabled', 'disabled').val(webshop._.global.button.please_wait);
622}
623
624/**
625 * Handles fetching and displaying quotations, including those from CPQ
626 * Ensure that both pages are checked if changes are made to this method
627 *
628 * @param {Number} page - The current page number for pagination. Default is 0.
629 * @param {Object}
629 searchCriteria - An object containing criteria for filtering the quotations, such as search parameters.
630 * @param {String} url - The API endpoint URL to fetch the quotation data from. Defaults to '/system/intact/quotations.html'.
631 */
632function quotationList(page, searchCriteria = {}, url = '/system/intact/quotations.html')
633{
634    const pageNum = page || 0;
635    const $quotationTable = $('.intact-my-quotations');
636
637    /**
638     * Handles API error by displaying an error message in the table and showing a toast notification if available.
639     *
640     * @param {*} $tableBody - jQuery element - The table body where the error message will be displayed.
641     * @param {String} [errorMessage] - Optional custom error message to display instead of the default one.
642     */
643    const handleApiError = ($tableBody, errorMessage = null) => {
644        const errorMessageWithFallback = errorMessage || webshop._.webshop.quote.list.error.message;
645
646        $tableBody.html(`<tr><td colspan="6">${errorMessageWithFallback}</td></tr>`);
647
648        if (typeof $.toast === 'function') {
649            try {
650                $.toast({
651                    heading: webshop._.webshop.quote.list.error.header,
652                    text: errorMessageWithFallback,
653                    showHideTransition: 'slide',
654                    icon: 'error',
655                    position: {
656                        right: 70,
657                        top: 70
658                    },
659                    hideAfter: 5000,
660                });
661            } catch (error) {
662                console.error('Toast error:', error);
663            }
664        }
665    }
666
667    if ($quotationTable.length > 0) {
668        const $tableBody = $quotationTable.find('tbody');
669        $.ajax({
670            url,
671            data: {
672                page: pageNum,
673                ...searchCriteria
674            },
675            success: function (data) {
676                if (!data.error && data.data) {
677                    $tableBody.html(data.data);
678                    $('.quote-history-pagination').html(data.pagination);
679                    return;
680                }
681                handleApiError($tableBody, data.error);
682            },
683            error: function() {
684                handleApiError($tableBody);
685            }
686        });
687    }
688}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.