From: Vincent Vanwaelscappel Date: Mon, 15 Nov 2021 13:32:18 +0000 (+0100) Subject: wait #4682 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=88268fce7d4aa58ba933376ab39a8ef4c9425c9c;p=fluidbook-html5.git wait #4682 @2 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma.js b/js/libs/fluidbook/cart/fluidbook.cart.puma.js index e317206f..7254be2a 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.puma.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.puma.js @@ -23,6 +23,14 @@ FluidbookCartPuma.prototype = { } return false; }); + $(document).on(this.fluidbook.input.clickEvent, '.exportEANXLS', function () { + try { + $this.exportEANXLS(); + } catch (err) { + console.log(err); + } + return false; + }); $(document).on(this.fluidbook.input.clickEvent, '.emptyCart', function () { $.confirm({ @@ -82,12 +90,15 @@ FluidbookCartPuma.prototype = { this.fluidbook.cache.set('cart', this.getItems()); this.fluidbook.cart.updateLinks(); }, + getItemsReferences: function () { return this.getItems(); }, + getItemsNumbers: function () { return this.getItems().length; }, + getAllQuantities: function () { return this.getItemsNumbers(); }, @@ -121,7 +132,6 @@ FluidbookCartPuma.prototype = { return ['Image', 'Catalogue', 'Catégorie', 'Ligne', 'Sexe', 'Modèle', 'Couleur', 'Désignation', 'Tailles', 'Tarif', 'PVC', 'PACK']; }, - getItems: function () { var res = []; var $this = this; @@ -183,12 +193,17 @@ FluidbookCartPuma.prototype = { content += ''; content += ''; content += ''; return content; }, + exportPDF: function () { var element = $('#pumacarttable').get(0); @@ -209,9 +224,60 @@ FluidbookCartPuma.prototype = { }, 2000); }, - getExportFileName: function () { + getExportFileName: function (label) { + if (label === undefined) { + label = 'Cart'; + } var date = new Date(); - return this.fluidbook.settings.title + ' - Cart - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate(); + return this.fluidbook.settings.title + ' - ' + label + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate(); + }, + + exportEANXLS: function () { + var $this = this; + const workbook = new ExcelJS.Workbook(); + const sheet = workbook.addWorksheet(this.fluidbook.settings.title); + sheet.views = [ + {state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'} + ]; + sheet.properties.defaultRowHeight = 15; + var columnsLabels = ['Reference', 'Size Description', 'EAN13', 'Season Description', 'Rbu', 'Family', 'Article', 'Model Id', 'Color Id']; + var columns = []; + + $.each(columnsLabels, function (k, v) { + columns.push({ + header: v, + key: v, + numFmt: '@', + style: {numFmt: '@', alignment: {vertical: 'middle', horizontal: 'left'}}, + width: 25, + }); + }); + + sheet.columns = columns; + $.each(this.getItems(), function (i, ref) { + $.each($this.fluidbook.settings.eanReferences, function (k, v) { + if (v.Reference === ref) { + var row = {}; + $.each(columnsLabels, function (kk, vv) { + row[vv] = v[vv]; + }); + sheet.addRow(row); + } + }); + }); + $.each(columnsLabels, function (k, v) { + sheet.getColumn(k + 1).numFmt = '@'; + }); + + workbook.xlsx.writeBuffer().then(function (data) { + var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); + const url = window.URL.createObjectURL(blob); + const anchor = document.createElement('a'); + anchor.href = url; + anchor.download = $this.getExportFileName('EAN') + '.xlsx'; + anchor.click(); + window.URL.revokeObjectURL(url); + }); }, exportXLS: function () {