update pdf params
This commit is contained in:
parent
8590d577bd
commit
7c84803b36
@ -4,16 +4,16 @@ import {useState} from "react";
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
|
||||||
|
const PDF_Y_START = 40;
|
||||||
function drawItem(doc: JsPDF, item: {
|
function drawItem(doc: JsPDF, item: {
|
||||||
title: string;
|
title: string;
|
||||||
content?: string
|
content?: string
|
||||||
}, y: number, align: 'left' | 'right' = 'left', fontSize: number = 13) {
|
}, y: number, align: 'left' | 'right' = 'left', fontSize: number = 13) {
|
||||||
doc.setFontSize(fontSize);
|
doc.setFontSize(fontSize);
|
||||||
// const width = doc.internal.pageSize.getWidth();
|
// const width = doc.internal.pageSize.getWidth();
|
||||||
doc.text(item.title, align == 'left' ? 20 : 180, y);
|
doc.text(item.title, align == 'left' ? 30 : 170, y);
|
||||||
if (item.content && item.content.length > 0) doc.text(item.content, align == 'left' ? 65 : 230, y, {maxWidth: 150});
|
if (item.content && item.content.length > 0) doc.text(item.content, align == 'left' ? 75 : 220, y, {maxWidth: 150});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GeneratePdf(bill: BillModel,save = true) {
|
export function GeneratePdf(bill: BillModel,save = true) {
|
||||||
const doc = new JsPDF({
|
const doc = new JsPDF({
|
||||||
orientation: 'landscape',
|
orientation: 'landscape',
|
||||||
@ -23,27 +23,29 @@ export function GeneratePdf(bill: BillModel,save = true) {
|
|||||||
// const height = doc.internal.pageSize.getHeight();
|
// const height = doc.internal.pageSize.getHeight();
|
||||||
doc.setFont('Helvetica', 'normal', 'bold');
|
doc.setFont('Helvetica', 'normal', 'bold');
|
||||||
doc.setFontSize(20);
|
doc.setFontSize(20);
|
||||||
doc.text('ACKNOWLEDGEMENT RECEIPT', 100, 20, {});
|
doc.text('ACKNOWLEDGEMENT RECEIPT', 100, PDF_Y_START, {});
|
||||||
|
|
||||||
doc.setFont('Helvetica', 'normal', 'normal');
|
doc.setFont('Helvetica', 'normal', 'normal');
|
||||||
drawItem(doc, {title: 'Student Name:', content: bill.student_english_name || bill.student_chinese_name || 'N/A'}, 40)
|
drawItem(doc, {title: 'Student Name:', content: bill.student_english_name || bill.student_chinese_name || 'N/A'}, PDF_Y_START + 10)
|
||||||
drawItem(doc, {title: 'Reference Number:', content: `${bill.id}`}, 40, "right")
|
drawItem(doc, {title: 'Reference Number:', content: `${bill.id}`}, PDF_Y_START + 10, "right")
|
||||||
drawItem(doc, {title: `${bill.student_number?"Student":"Bill"} Number:`, content: `${bill.student_number || bill.application_number}`}, 48)
|
drawItem(doc, {title: `${bill.student_number?"Student":"Bill"} Number:`, content: `${bill.student_number || bill.application_number}`}, PDF_Y_START + 18)
|
||||||
drawItem(doc, {title: 'Print Date:', content: dayjs().format('YYYY-MM-DD')}, 48, "right")
|
drawItem(doc, {title: 'Print Date:', content: dayjs().format('YYYY-MM-DD')}, PDF_Y_START + 18, "right")
|
||||||
|
|
||||||
|
const programme_english_name = bill.programme_english_name || ''
|
||||||
drawItem(doc, {
|
drawItem(doc, {
|
||||||
title: 'Programme:',
|
title: 'Programme:',
|
||||||
content: bill.programme_english_name || 'N/A'
|
content: programme_english_name || 'N/A'
|
||||||
}, 56)
|
}, PDF_Y_START + 26)
|
||||||
if(bill.programme_english_name && bill.programme_english_name.length > 0){
|
|
||||||
drawItem(doc, {title: 'Mode of Study:', content: bill.attendance_mode == 'FT' ? 'FULL-TIME': bill.attendance_mode}, bill.programme_english_name.length > 70?70:64)
|
const programme_limit = programme_english_name.length > 76 ;
|
||||||
|
if(programme_english_name.length > 0){
|
||||||
|
drawItem(doc, {title: 'Mode of Study:', content: bill.attendance_mode == 'FT' ? 'FULL-TIME': bill.attendance_mode}, programme_limit? PDF_Y_START + 38 : PDF_Y_START + 34)
|
||||||
}
|
}
|
||||||
// draw table
|
// draw table
|
||||||
autoTable(doc, {
|
autoTable(doc, {
|
||||||
startY: 80,
|
startY: programme_limit ? PDF_Y_START + 44 : PDF_Y_START + 40,
|
||||||
theme: 'grid',
|
theme: 'grid',
|
||||||
|
margin: {top: 37, left: 30, right: 30},
|
||||||
margin: {top: 37, left: 20, right: 20},
|
|
||||||
styles: {
|
styles: {
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fillColor: [255, 255, 255],
|
fillColor: [255, 255, 255],
|
||||||
@ -56,7 +58,7 @@ export function GeneratePdf(bill: BillModel,save = true) {
|
|||||||
headStyles: {
|
headStyles: {
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
},
|
},
|
||||||
head: [['No.', 'Transaction Date', 'Payment Type', 'Payment Method', 'HK$']],
|
head: [['No.', 'Transaction Date', 'Payment Type', 'Payment Method', {content:'HK$',styles:{minCellWidth:30,halign:'right'}}]],
|
||||||
body: [
|
body: [
|
||||||
...(bill.details.map(it=>{
|
...(bill.details.map(it=>{
|
||||||
return [
|
return [
|
||||||
@ -64,14 +66,17 @@ export function GeneratePdf(bill: BillModel,save = true) {
|
|||||||
bill.paid_at?dayjs(bill.initiated_paid_at).format('YYYY-MM-DD'):'',
|
bill.paid_at?dayjs(bill.initiated_paid_at).format('YYYY-MM-DD'):'',
|
||||||
it.bill_type,
|
it.bill_type,
|
||||||
`${bill.payment_channel}` + (bill.payment_method && bill.payment_channel != bill.payment_method ? `(${bill.payment_method})` : ''),
|
`${bill.payment_channel}` + (bill.payment_method && bill.payment_channel != bill.payment_method ? `(${bill.payment_method})` : ''),
|
||||||
`${it.amount}`
|
{content:`${it.amount}`,styles:{halign:'right'}} as any
|
||||||
];
|
];
|
||||||
})),
|
})),
|
||||||
[{
|
[{
|
||||||
colSpan: 4,
|
colSpan: 4,
|
||||||
content: 'TOTAL:',
|
content: 'TOTAL:',
|
||||||
styles: {valign: 'middle', halign: 'right'},
|
styles: {valign: 'middle', halign: 'right',fontStyle: 'bold'},
|
||||||
}, `${bill.amount}`],
|
}, {
|
||||||
|
content:`${bill.amount}`,
|
||||||
|
styles:{halign:'right'}
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
// draw foot
|
// draw foot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user