Miscellaneous latest changes

This commit is contained in:
2025-01-22 14:34:20 +00:00
parent 3d3448a099
commit c51898b86a
6 changed files with 208 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ import React, { useRef, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import imageLogo from '../content/images/Logo.png';
import * as shared from '../scripts/shared.js';
import { jsPDF } from "jspdf";
const PageInvoiceOrEstimate = () => {
const canvasRefs = useRef([]);
@@ -58,7 +59,7 @@ const PageInvoiceOrEstimate = () => {
const heightBankMyBusiness = 420;
const heightBillToSite = 560;
const heightHeadTable = 800;
const heightRowMax = 1050; // update this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const heightRowMax = 1200; // update this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const maxRows = Math.floor((heightRowMax - heightHeadTable - heightLine) / (heightLine + spacingLabel));
console.log("maxRows:", maxRows);
const xPositionTableColumns = [120, 420, 520, 620];
@@ -77,18 +78,34 @@ const PageInvoiceOrEstimate = () => {
const countPages = Math.ceil(props["quantityServices" + typeForm] / maxRows);
console.log("countPages:", countPages);
const nameFont = "Arial";
const downloadPdf = (canvas, index) => {
const pdf = new jsPDF();
pdf.addImage(canvas.toDataURL("image/png"), "PNG", 0, 0);
pdf.save(`canvas${index}.pdf`);
};
const renderCanvases = () => {
const canvases = [];
for (let indexCanvas = 0; indexCanvas < countPages; indexCanvas++) {
canvases.push(
<canvas
key={indexCanvas}
ref={(ref) => (canvasRefs.current[indexCanvas] = ref)}
width={widthA4}
height={heightA4}
style={{ border: '1px solid black', margin: '10px' }}
/>
<div>
<canvas
key={indexCanvas}
ref={(ref) => (canvasRefs.current[indexCanvas] = ref)}
width={widthA4}
height={heightA4}
style={{ border: '1px solid black', margin: '10px' }}
/>
<button
onClick={() =>
downloadPdf(canvasRefs.current[indexCanvas], indexCanvas)
}
>
Download as PDF
</button>
</div>
);
}
return canvases;
@@ -124,10 +141,10 @@ const PageInvoiceOrEstimate = () => {
description: props["descriptionGood" + typeForm + (indexGoodOrService + 1)],
quantity: props["quantityGood" + typeForm + (indexGoodOrService + 1)],
rate: props["rateGood" + typeForm + (indexGoodOrService + 1)],
subtotal: props["subtotalGood" + typeForm + (indexGoodOrService + 1)],
};
good["subtotal"] = (good.quantity * good.rate).toFixed(2);
page.goods.push(good);
page.total += good.subtotal;
page.total += Number(good.subtotal);
}
if (hasServices) {
indexSubservice++;
@@ -141,9 +158,9 @@ const PageInvoiceOrEstimate = () => {
quantity: props["quantityRatePeriodsIncrementService" + typeForm + (indexGoodOrService + 1) + "s" + (indexSubservice + 1)],
rate: props["rateService" + typeForm + (indexGoodOrService + 1)],
};
service["subtotal"] = service.quantity * service.rate;
service["subtotal"] = (service.quantity * service.rate).toFixed(2);
page.services.push(service);
page.total += service.subtotal;
page.total += Number(service.subtotal);
}
}
if (indexRow >= maxRows) {
@@ -213,7 +230,7 @@ const PageInvoiceOrEstimate = () => {
context.font = '12px ' + nameFont;
let heightRowTotal = heightHeadTable + (1 + (page.hasGoods ? page.goods.length : page.services.length)) * heightLine;
console.log("page total: ", page.total);
context.fillText(currency + page.total, xPositionTableColumns[3] - 10, heightRowTotal);
context.fillText(currency + page.total.toFixed(2), xPositionTableColumns[3] - 10, heightRowTotal);
context.fillText('TOTAL:', xPositionTableColumns[3] - borderPage - 10, heightRowTotal);
}
}