@appcorp/fusion-storybook 0.3.49 → 0.3.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-modules/admission/context/use-admission-module.js +2 -2
- package/base-modules/admission/filter.js +1 -1
- package/base-modules/admission/form.js +1 -1
- package/base-modules/attendance/form.js +1 -1
- package/base-modules/enrollment/form.js +1 -1
- package/base-modules/expense/form.js +1 -1
- package/base-modules/family-member/form.js +1 -1
- package/base-modules/student-fee/form.js +1 -1
- package/base-modules/student-fee/single-entry-form.js +1 -1
- package/package.json +3 -7
- package/pdf-templates/admission-form-template.d.ts +37 -0
- package/pdf-templates/admission-form-template.js +321 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/admission-pdf.d.ts +3 -78
- package/utils/admission-pdf.js +6 -68
- package/utils/print-html.d.ts +1 -0
- package/utils/print-html.js +31 -0
- package/utils/pdf-generator.d.ts +0 -41
- package/utils/pdf-generator.js +0 -107
package/utils/admission-pdf.d.ts
CHANGED
|
@@ -1,78 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Specialized functions for generating admission-related PDFs.
|
|
6
|
-
*/
|
|
7
|
-
export interface AdmissionPDFData extends PDFTemplateData {
|
|
8
|
-
firstName: string;
|
|
9
|
-
lastName: string;
|
|
10
|
-
studentIdNumber: string;
|
|
11
|
-
gender: string;
|
|
12
|
-
dob: string;
|
|
13
|
-
registrationCode: string;
|
|
14
|
-
discountCode?: string;
|
|
15
|
-
fatherFirstName: string;
|
|
16
|
-
fatherLastName: string;
|
|
17
|
-
fatherIdNumber: string;
|
|
18
|
-
fatherMobile: string;
|
|
19
|
-
fatherOccupation?: string;
|
|
20
|
-
fatherOrganization?: string;
|
|
21
|
-
motherFirstName: string;
|
|
22
|
-
motherLastName: string;
|
|
23
|
-
motherIdNumber: string;
|
|
24
|
-
motherMobile: string;
|
|
25
|
-
address: string;
|
|
26
|
-
city: string;
|
|
27
|
-
state: string;
|
|
28
|
-
country: string;
|
|
29
|
-
classForAdmission: string;
|
|
30
|
-
previousSchool?: string;
|
|
31
|
-
siblings?: string;
|
|
32
|
-
notes?: string;
|
|
33
|
-
admissionNotes?: string;
|
|
34
|
-
schoolName?: string;
|
|
35
|
-
schoolAddress?: string;
|
|
36
|
-
schoolPhone?: string;
|
|
37
|
-
schoolEmail?: string;
|
|
38
|
-
submissionDate?: string;
|
|
39
|
-
admissionStatus?: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Generate admission form PDF
|
|
43
|
-
*
|
|
44
|
-
* @param admissionData - Admission form data
|
|
45
|
-
* @param options - Additional PDF options
|
|
46
|
-
* @returns Promise<Buffer> - PDF buffer
|
|
47
|
-
*/
|
|
48
|
-
export declare function generateAdmissionPDF(admissionData: AdmissionPDFData, options?: {
|
|
49
|
-
filename?: string;
|
|
50
|
-
orientation?: "portrait" | "landscape";
|
|
51
|
-
format?: "a4" | "letter" | "legal";
|
|
52
|
-
}): Promise<Uint8Array>;
|
|
53
|
-
/**
|
|
54
|
-
* Download admission form PDF
|
|
55
|
-
*
|
|
56
|
-
* @param admissionData - Admission form data
|
|
57
|
-
* @param options - Additional PDF options
|
|
58
|
-
*/
|
|
59
|
-
export declare function downloadAdmissionPDF(admissionData: AdmissionPDFData, options?: {
|
|
60
|
-
filename?: string;
|
|
61
|
-
orientation?: "portrait" | "landscape";
|
|
62
|
-
format?: "a4" | "letter" | "legal";
|
|
63
|
-
}): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Print admission form PDF
|
|
66
|
-
*
|
|
67
|
-
* @param admissionData - Admission form data
|
|
68
|
-
* @param printerOptions - Printer options
|
|
69
|
-
*/
|
|
70
|
-
export declare function printAdmissionPDF(admissionData: AdmissionPDFData): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Generate admission receipt PDF
|
|
73
|
-
*
|
|
74
|
-
* @param admissionData - Admission form data with payment info
|
|
75
|
-
* @param paymentData - Payment information
|
|
76
|
-
* @returns Promise<Buffer> - PDF buffer
|
|
77
|
-
*/
|
|
78
|
-
export declare function generateAdmissionReceiptPDF(admissionData: AdmissionPDFData): Promise<void>;
|
|
1
|
+
import { AdmissionPDFData } from "../pdf-templates/admission-form-template";
|
|
2
|
+
export type { AdmissionPDFData };
|
|
3
|
+
export declare function downloadAdmissionFormPDF(data: AdmissionPDFData): Promise<void>;
|
package/utils/admission-pdf.js
CHANGED
|
@@ -1,69 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { schoolAdmissionTemplateV1 } from "@appcorp/app-corp-vista/pdf-templates/school-admission-template-v1";
|
|
13
|
-
import { convertUrlToBase64 } from "@react-pakistan/util-functions/general/convert-url-to-base64";
|
|
14
|
-
import { generatePDF, downloadPDF, printPDF, } from "./pdf-generator";
|
|
15
|
-
/**
|
|
16
|
-
* Generate admission form PDF
|
|
17
|
-
*
|
|
18
|
-
* @param admissionData - Admission form data
|
|
19
|
-
* @param options - Additional PDF options
|
|
20
|
-
* @returns Promise<Buffer> - PDF buffer
|
|
21
|
-
*/
|
|
22
|
-
export async function generateAdmissionPDF(admissionData, options) {
|
|
23
|
-
const _a = options || {}, { filename = `admission-${admissionData.registrationCode}.pdf` } = _a, pdfOptions = __rest(_a, ["filename"]);
|
|
24
|
-
return generatePDF(Object.assign({ template: schoolAdmissionTemplateV1, data: Object.assign(Object.assign({}, admissionData), { submissionDate: admissionData.submissionDate || new Date().toLocaleDateString(),
|
|
25
|
-
// Map admission data to template fields
|
|
26
|
-
heading: "Admission Form", studentName: `${admissionData.firstName} ${admissionData.lastName}`, bForm: admissionData.studentIdNumber, fatherName: `${admissionData.fatherFirstName} ${admissionData.fatherLastName}`, motherName: `${admissionData.motherFirstName} ${admissionData.motherLastName}`, address: admissionData.address, class: admissionData.classForAdmission }), filename }, pdfOptions));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Download admission form PDF
|
|
30
|
-
*
|
|
31
|
-
* @param admissionData - Admission form data
|
|
32
|
-
* @param options - Additional PDF options
|
|
33
|
-
*/
|
|
34
|
-
export async function downloadAdmissionPDF(admissionData, options) {
|
|
35
|
-
const _a = options || {}, { filename = `admission-${admissionData.registrationCode}.pdf` } = _a, pdfOptions = __rest(_a, ["filename"]);
|
|
36
|
-
return downloadPDF(Object.assign({ template: schoolAdmissionTemplateV1, data: Object.assign(Object.assign({}, admissionData), { submissionDate: admissionData.submissionDate || new Date().toLocaleDateString(),
|
|
37
|
-
// Map admission data to template fields
|
|
38
|
-
heading: "Admission Form", studentName: `${admissionData.firstName} ${admissionData.lastName}`, bForm: admissionData.studentIdNumber, fatherName: `${admissionData.fatherFirstName} ${admissionData.fatherLastName}`, motherName: `${admissionData.motherFirstName} ${admissionData.motherLastName}`, address: admissionData.address, class: admissionData.classForAdmission }), filename }, pdfOptions));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Print admission form PDF
|
|
42
|
-
*
|
|
43
|
-
* @param admissionData - Admission form data
|
|
44
|
-
* @param printerOptions - Printer options
|
|
45
|
-
*/
|
|
46
|
-
export async function printAdmissionPDF(admissionData) {
|
|
47
|
-
return printPDF({
|
|
48
|
-
template: schoolAdmissionTemplateV1,
|
|
49
|
-
data: Object.assign(Object.assign({}, admissionData), { submissionDate: admissionData.submissionDate || new Date().toLocaleDateString(),
|
|
50
|
-
// Map admission data to template fields
|
|
51
|
-
formHeading: "Admission Form", schoolName: "Lahore Garrison Grammar School", date: `Date: ${new Date().toLocaleDateString()}`, studentName: `Student Name: ${admissionData.firstName} ${admissionData.lastName}`, bForm: `Government ID: ${admissionData.studentIdNumber}`, fatherName: `Father's Name: ${admissionData.fatherFirstName} ${admissionData.fatherLastName}`, classToBeAdmitted: `Class for Admission: ${admissionData.classForAdmission}`, motherName: `Mother's Name: ${admissionData.motherFirstName} ${admissionData.motherLastName}`, address: `Address: ${admissionData.address}`, class: `Class for Admission: ${admissionData.classForAdmission}`, schoolAddress: "123 Main Street, Lahore", registration: `Registration Code: ${admissionData.registrationCode}`, logo: await convertUrlToBase64(admissionData.schoolLogoUrl), gender: `Gender: ${admissionData.gender}`, dob: `DoB: ${admissionData.dob}`, fatherCNIC: `Father's ID: ${admissionData.fatherIdNumber}`, fatherMobile: `Father's Mobile: ${admissionData.fatherMobile}`, fatherOccupation: `Father's Occupation: ${admissionData.fatherOccupation || "N/A"}`, fatherOrganization: `Father's Organization: ${admissionData.fatherOrganization || "N/A"}`, motherCNIC: `Mother's ID: ${admissionData.motherIdNumber}`, motherMobile: `Mother's Mobile: ${admissionData.motherMobile}`, homeAddress: `Home Address: ${admissionData.address}, ${admissionData.city}, ${admissionData.state}, ${admissionData.country}`, relation: `Who to contact: ${admissionData.emergencyContact === "Mother" ? "Mother" : "Father"}`, notes: `Additional Notes: ${admissionData.notes || "N/A"}`, student: "Student:", startDate: "Start Date:", section: "Section:" }),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Generate admission receipt PDF
|
|
56
|
-
*
|
|
57
|
-
* @param admissionData - Admission form data with payment info
|
|
58
|
-
* @param paymentData - Payment information
|
|
59
|
-
* @returns Promise<Buffer> - PDF buffer
|
|
60
|
-
*/
|
|
61
|
-
export async function generateAdmissionReceiptPDF(admissionData) {
|
|
62
|
-
await downloadPDF({
|
|
63
|
-
template: schoolAdmissionTemplateV1,
|
|
64
|
-
data: Object.assign(Object.assign({}, admissionData), { submissionDate: admissionData.submissionDate || new Date().toLocaleDateString(),
|
|
65
|
-
// Map admission data to template fields
|
|
66
|
-
formHeading: "Admission Form", schoolName: "Lahore Garrison Grammar School", date: `Date: ${new Date().toLocaleDateString()}`, studentName: `Student Name: ${admissionData.firstName} ${admissionData.lastName}`, bForm: `Government ID: ${admissionData.studentIdNumber}`, fatherName: `Father's Name: ${admissionData.fatherFirstName} ${admissionData.fatherLastName}`, classToBeAdmitted: `Class for Admission: ${admissionData.classForAdmission}`, motherName: `Mother's Name: ${admissionData.motherFirstName} ${admissionData.motherLastName}`, address: `Address: ${admissionData.address}`, class: `Class for Admission: ${admissionData.classForAdmission}`, schoolAddress: "123 Main Street, Lahore", registration: `Registration Code: ${admissionData.registrationCode}`, gender: `Gender: ${admissionData.gender}`, dob: `DoB: ${admissionData.dob}`, fatherCNIC: `Father's ID: ${admissionData.fatherIdNumber}`, fatherMobile: `Father's Mobile: ${admissionData.fatherMobile}`, fatherOccupation: `Father's Occupation: ${admissionData.fatherOccupation || "N/A"}`, fatherOrganization: `Father's Organization: ${admissionData.fatherOrganization || "N/A"}`, motherCNIC: `Mother's ID: ${admissionData.motherIdNumber}`, motherMobile: `Mother's Mobile: ${admissionData.motherMobile}`, homeAddress: `Home Address: ${admissionData.address}, ${admissionData.city}, ${admissionData.state}, ${admissionData.country}`, relation: `Who to contact: ${admissionData.emergencyContact === "Mother" ? "Mother" : "Father"}`, notes: `Additional Notes: ${admissionData.notes || "N/A"}`, student: "Student:", startDate: "Start Date:", section: "Section:", logo: admissionData.logo }),
|
|
67
|
-
filename: `admission-${admissionData.registrationCode}.pdf`,
|
|
68
|
-
});
|
|
1
|
+
import { buildAdmissionFormHtml, } from "../pdf-templates/admission-form-template";
|
|
2
|
+
import { printHtml } from "./print-html";
|
|
3
|
+
export async function downloadAdmissionFormPDF(data) {
|
|
4
|
+
const html = buildAdmissionFormHtml(data);
|
|
5
|
+
const filename = `admission-${data.registrationCode}.pdf`;
|
|
6
|
+
await printHtml(html, filename);
|
|
69
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printHtml(html: string, filename?: string): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export async function printHtml(html, filename) {
|
|
2
|
+
const iframe = document.createElement("iframe");
|
|
3
|
+
iframe.style.position = "fixed";
|
|
4
|
+
iframe.style.top = "-9999px";
|
|
5
|
+
iframe.style.left = "-9999px";
|
|
6
|
+
iframe.style.width = "0";
|
|
7
|
+
iframe.style.height = "0";
|
|
8
|
+
iframe.style.border = "none";
|
|
9
|
+
document.body.appendChild(iframe);
|
|
10
|
+
const iframeWin = iframe.contentWindow;
|
|
11
|
+
const iframeDoc = iframeWin === null || iframeWin === void 0 ? void 0 : iframeWin.document;
|
|
12
|
+
if (!iframeDoc || !iframeWin) {
|
|
13
|
+
document.body.removeChild(iframe);
|
|
14
|
+
throw new Error("Could not create iframe document for printing");
|
|
15
|
+
}
|
|
16
|
+
iframeDoc.open();
|
|
17
|
+
iframeDoc.write(html);
|
|
18
|
+
iframeDoc.close();
|
|
19
|
+
const prevTitle = document.title;
|
|
20
|
+
if (filename) {
|
|
21
|
+
document.title = filename;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
await iframeDoc.fonts.ready;
|
|
25
|
+
iframeWin.print();
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
document.title = prevTitle;
|
|
29
|
+
document.body.removeChild(iframe);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/utils/pdf-generator.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Template } from "@pdfme/common";
|
|
2
|
-
/**
|
|
3
|
-
* PDF Generation Utility using Vista Templates
|
|
4
|
-
*
|
|
5
|
-
* Provides functions to generate PDFs using Vista templates with @pdfme.
|
|
6
|
-
*/
|
|
7
|
-
export interface PDFTemplateData {
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
}
|
|
10
|
-
export interface PDFOptions {
|
|
11
|
-
template: Template;
|
|
12
|
-
data: PDFTemplateData;
|
|
13
|
-
filename?: string;
|
|
14
|
-
orientation?: "portrait" | "landscape";
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generate a PDF using a Vista template
|
|
18
|
-
*
|
|
19
|
-
* @param options - PDF generation options
|
|
20
|
-
* @returns Promise<Uint8Array> - PDF as Uint8Array
|
|
21
|
-
*/
|
|
22
|
-
export declare function generatePDF(options: PDFOptions): Promise<Uint8Array>;
|
|
23
|
-
/**
|
|
24
|
-
* Generate and download a PDF using a Vista template
|
|
25
|
-
*
|
|
26
|
-
* @param options - PDF generation options
|
|
27
|
-
*/
|
|
28
|
-
export declare function downloadPDF(options: PDFOptions): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Generate a PDF and return as base64 string
|
|
31
|
-
*
|
|
32
|
-
* @param options - PDF generation options
|
|
33
|
-
* @returns Promise<string> - Base64 encoded PDF
|
|
34
|
-
*/
|
|
35
|
-
export declare function generatePDFBase64(options: PDFOptions): Promise<string>;
|
|
36
|
-
/**
|
|
37
|
-
* Print a PDF directly to printer (client-side printing)
|
|
38
|
-
*
|
|
39
|
-
* @param options - PDF generation options
|
|
40
|
-
*/
|
|
41
|
-
export declare function printPDF(options: PDFOptions): Promise<void>;
|
package/utils/pdf-generator.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { generate } from "@pdfme/generator";
|
|
2
|
-
import { text, table, image, line } from "@pdfme/schemas";
|
|
3
|
-
/**
|
|
4
|
-
* Generate a PDF using a Vista template
|
|
5
|
-
*
|
|
6
|
-
* @param options - PDF generation options
|
|
7
|
-
* @returns Promise<Uint8Array> - PDF as Uint8Array
|
|
8
|
-
*/
|
|
9
|
-
export async function generatePDF(options) {
|
|
10
|
-
try {
|
|
11
|
-
const { template, data } = options;
|
|
12
|
-
// Generate PDF using @pdfme/generator
|
|
13
|
-
const pdf = await generate({
|
|
14
|
-
template,
|
|
15
|
-
inputs: [data], // @pdfme expects an array of inputs
|
|
16
|
-
plugins: {
|
|
17
|
-
text,
|
|
18
|
-
table,
|
|
19
|
-
image,
|
|
20
|
-
line,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
return pdf;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error("Error generating PDF:", error);
|
|
27
|
-
throw new Error(`Failed to generate PDF: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Generate and download a PDF using a Vista template
|
|
32
|
-
*
|
|
33
|
-
* @param options - PDF generation options
|
|
34
|
-
*/
|
|
35
|
-
export async function downloadPDF(options) {
|
|
36
|
-
try {
|
|
37
|
-
const pdf = await generatePDF(options);
|
|
38
|
-
const { filename = "document.pdf" } = options;
|
|
39
|
-
// Create blob and download
|
|
40
|
-
const blob = new Blob([pdf], { type: "application/pdf" });
|
|
41
|
-
const url = URL.createObjectURL(blob);
|
|
42
|
-
const link = document.createElement("a");
|
|
43
|
-
link.href = url;
|
|
44
|
-
link.download = filename;
|
|
45
|
-
document.body.appendChild(link);
|
|
46
|
-
link.click();
|
|
47
|
-
document.body.removeChild(link);
|
|
48
|
-
// Clean up
|
|
49
|
-
URL.revokeObjectURL(url);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.error("Error downloading PDF:", error);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Generate a PDF and return as base64 string
|
|
58
|
-
*
|
|
59
|
-
* @param options - PDF generation options
|
|
60
|
-
* @returns Promise<string> - Base64 encoded PDF
|
|
61
|
-
*/
|
|
62
|
-
export async function generatePDFBase64(options) {
|
|
63
|
-
try {
|
|
64
|
-
const pdf = await generatePDF(options);
|
|
65
|
-
// Convert Uint8Array to base64
|
|
66
|
-
const binaryString = Array.from(pdf, (byte) => String.fromCharCode(byte)).join("");
|
|
67
|
-
return btoa(binaryString);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("Error generating PDF base64:", error);
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Print a PDF directly to printer (client-side printing)
|
|
76
|
-
*
|
|
77
|
-
* @param options - PDF generation options
|
|
78
|
-
*/
|
|
79
|
-
export async function printPDF(options) {
|
|
80
|
-
try {
|
|
81
|
-
const pdf = await generatePDF(options);
|
|
82
|
-
// Create blob and open in new window for printing
|
|
83
|
-
const blob = new Blob([pdf], { type: "application/pdf" });
|
|
84
|
-
const url = URL.createObjectURL(blob);
|
|
85
|
-
const printWindow = window.open(url, "_blank");
|
|
86
|
-
if (printWindow) {
|
|
87
|
-
printWindow.onload = () => {
|
|
88
|
-
printWindow.print();
|
|
89
|
-
URL.revokeObjectURL(url);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Fallback: download if popup blocked
|
|
94
|
-
const link = document.createElement("a");
|
|
95
|
-
link.href = url;
|
|
96
|
-
link.download = options.filename || "document.pdf";
|
|
97
|
-
document.body.appendChild(link);
|
|
98
|
-
link.click();
|
|
99
|
-
document.body.removeChild(link);
|
|
100
|
-
URL.revokeObjectURL(url);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.error("Error printing PDF:", error);
|
|
105
|
-
throw new Error(`Failed to print PDF: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
106
|
-
}
|
|
107
|
-
}
|