@rsc-labs/medusa-store-analytics
Version:
Get analytics data about your store
66 lines (65 loc) • 2.53 kB
JavaScript
;
/*
* Copyright 2024 RSC-Labs, https://rsoftcon.com/
*
* MIT License
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const hr_1 = require("./hr");
const currency_1 = require("../utils/currency");
const common_1 = require("./common");
class PdfSalesTemplate {
static generateTableRow(doc, date, currencyCode, sales) {
const startY = doc.y;
doc
.fontSize(10)
.text(date, 70, startY, { align: "left" })
.text(currencyCode, 200, startY, { align: "left" })
.text(sales, 320, startY, { width: 90, align: "right" });
}
static generateTableTitle(doc, region) {
doc
.fontSize(14);
(0, common_1.moveDown)(doc);
doc
.text(`${region.name}`, 70, doc.y, { align: "left" });
doc
.fontSize(12);
(0, common_1.moveDown)(doc);
}
static generateTable(doc, salesHistoryResult) {
doc.font("Helvetica-Bold");
this.generateTableRow(doc, "Date", "Currency code", "Sales");
(0, common_1.moveDown)(doc);
(0, hr_1.generateHr)(doc);
(0, common_1.moveDown)(doc);
doc.font("Helvetica");
let totalCurrent = 0;
for (const currentSalesResult of salesHistoryResult.current) {
totalCurrent += Number(currentSalesResult.total);
this.generateTableRow(doc, currentSalesResult.date.toLocaleDateString(), salesHistoryResult.currencyCode.toUpperCase(), (0, currency_1.amountToDisplay)(Number(currentSalesResult.total), salesHistoryResult.currencyCode));
(0, common_1.moveDown)(doc);
(0, hr_1.generateHr)(doc);
(0, common_1.moveDown)(doc);
}
this.generateTableRow(doc, "Total", "", (0, currency_1.amountToDisplay)(totalCurrent, salesHistoryResult.currencyCode));
(0, common_1.moveDown)(doc);
}
static generateHeader(doc) {
doc
.fontSize(18);
(0, common_1.moveDown)(doc);
doc
.text('Sales by region', 70, doc.y, { align: "left" });
doc
.fontSize(12);
(0, common_1.moveDown)(doc);
}
}
exports.default = PdfSalesTemplate;