Compare commits
43 Commits
Author | SHA1 | Date |
---|---|---|
Skylar Grant | 1a7f2cf322 | |
Skylar Grant | 58d6da3908 | |
Skylar Grant | e606dc060c | |
Skylar Grant | 69d288eb26 | |
Skylar Grant | 97438078fa | |
Skylar Grant | 7ef2c64bc4 | |
Skylar Grant | d04ab004b1 | |
Skylar Grant | 16ed02c6f7 | |
Skylar Grant | c1afc06e89 | |
Skylar Grant | 708aa34181 | |
Skylar Grant | b80b6ec918 | |
Skylar Grant | 73a0d5a1be | |
Skylar Grant | 79219ef3ee | |
Skylar Grant | 75874a6040 | |
Skylar Grant | ede4b8593d | |
Skylar Grant | a870a7119f | |
Skylar Grant | 9363333b5a | |
Skylar Grant | a5799c2091 | |
Skylar Grant | ab14d44900 | |
Skylar Grant | 1d49e9cff4 | |
Skylar Grant | 4d17f80c00 | |
Skylar Grant | 7cc0c363ff | |
Skylar Grant | 5f1e3b1215 | |
Skylar Grant | 25dbbfc088 | |
Skylar Grant | 95f0b9edc3 | |
Skylar Grant | 81e05a1ecd | |
Skylar Grant | 9352b92d2d | |
Skylar Grant | 186beb6a58 | |
Skylar Grant | 20da340bf7 | |
Skylar Grant | 8581027340 | |
Skylar Grant | 665f1fe563 | |
Skylar Grant | 6a6bb1c99d | |
Skylar Grant | 73db7c0e65 | |
Skylar Grant | 0c39826505 | |
Skylar Grant | 65e327c83d | |
Skylar Grant | f6a5ec5a77 | |
Skylar Grant | d50cdae095 | |
Skylar Grant | 709cc83fec | |
Skylar Grant | b50d1052aa | |
Skylar Grant | 63e0e34cb7 | |
Skylar Grant | cf14224a8e | |
Skylar Grant | 3c9e41bd8d | |
Skylar Grant | 4c8fb156ee |
|
@ -2,7 +2,7 @@ const express = require('express');
|
||||||
const Thermal = require('./modules/Thermal.js');
|
const Thermal = require('./modules/Thermal.js');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 80;
|
const port = 3000;
|
||||||
|
|
||||||
// Middleware to serve static files (HTML)
|
// Middleware to serve static files (HTML)
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
@ -10,20 +10,91 @@ app.use(express.static('public'));
|
||||||
// Middleware to parse JSON request bodies
|
// Middleware to parse JSON request bodies
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// Test print function
|
// Print credentials
|
||||||
app.post('/print', async (req, res) => {
|
app.post('/print-credentials', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { username, studentId } = req.body;
|
const { username, studentId } = req.body;
|
||||||
if (!username || !studentId) {
|
if (!username || !studentId) {
|
||||||
return res.status(400).json({ message: 'Username and Student ID are required.' });
|
return res.status(400).json({ message: 'Username and Student ID are required.' });
|
||||||
}
|
}
|
||||||
await Thermal.printCredentials(username, studentId, req, res);
|
// Generate the information string
|
||||||
|
const infoArray = Thermal.generateInfo.credentials(username, studentId);
|
||||||
|
|
||||||
|
// Generate the PDF, saved to disk
|
||||||
|
Thermal.generatePdf(infoArray).then((result) => {
|
||||||
|
res.send('PDF file written successfully.');
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Print Error:', e);
|
||||||
|
res.status(500).json({ message: 'Print Error', error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Print temp password
|
||||||
|
app.post('/print-temp-pw', async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Grab the password from the request body
|
||||||
|
const { password } = req.body;
|
||||||
|
|
||||||
|
// Check that the password is actually there
|
||||||
|
if (!password) {
|
||||||
|
return res.status(400).json({ message: 'Password is required.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate the information string
|
||||||
|
const infoArray = Thermal.generateInfo.tempPassword(password);
|
||||||
|
|
||||||
|
// Generate the PDF, saved to disk
|
||||||
|
Thermal.generatePdf(infoArray).then((result) => {
|
||||||
|
res.send('PDF file written successfully.');
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
res.status(500).json({ message: 'Error writing PDF file', error: err.message });
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Print Error:', error);
|
console.error('Print Error:', error);
|
||||||
res.status(500).json({ message: 'Print Error', error: error.message });
|
res.status(500).json({ message: 'Print Error', error: error.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Print Student MaineCC Info
|
||||||
|
app.post('/print-mcc', async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Generate the information string
|
||||||
|
const infoArray = Thermal.generateInfo.maineCC();
|
||||||
|
|
||||||
|
// Generate the PDF, saved to disk
|
||||||
|
Thermal.generatePdf(infoArray).then((result) => {
|
||||||
|
res.send('PDF file written successfully.');
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Print Error:', e);
|
||||||
|
res.status(500).json({ message: 'Print Error', error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Print Student MaineCC Info
|
||||||
|
app.post('/print', async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Print the document
|
||||||
|
Thermal.print().then(result => {
|
||||||
|
res.send('PDF sent to printer successfully.');
|
||||||
|
}).catch(e => {
|
||||||
|
console.error('Failed to start printing process:', err);
|
||||||
|
res.status(500).json({ message: 'Failed to start printing process', error: err.message });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Print Error:', e);
|
||||||
|
res.status(500).json({ message: 'Print Error', error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server running at http://localhost:${port}`);
|
console.log(`Server running at http://localhost:${port}`);
|
||||||
|
|
|
@ -3,24 +3,60 @@ const fs = require('fs');
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
const info = {
|
||||||
printCredentials(username, studentId, req, res) {
|
deptName: "IT Support",
|
||||||
// Create the output text
|
supportEmail: "ITHelp@MaineCC.edu",
|
||||||
const infoArray = [
|
supportPhone: "(207) 453-5079"
|
||||||
`Username: ${username}`,
|
}
|
||||||
'',
|
|
||||||
'Email:',
|
|
||||||
`${username}@kvcc.me.edu`,
|
|
||||||
'',
|
|
||||||
`Student ID: ${studentId}`,
|
|
||||||
'',
|
|
||||||
'Note: the MyKV Portal uses your username to sign in, not email.',
|
|
||||||
'For technical support contact IT Support at ITHelp@MaineCC.edu or (207)453-5079'
|
|
||||||
];
|
|
||||||
const infoString = infoArray.join('\n');
|
|
||||||
|
|
||||||
|
const receiptFooter = `For other technical assistance, contact ${info.deptName}:\n${info.supportEmail}\nor ${info.supportPhone}.`;
|
||||||
|
|
||||||
|
const mccContractor = {
|
||||||
|
name: "Contracting Company",
|
||||||
|
email: "helpme@contractor.com",
|
||||||
|
phone: "1 (800) 234-5678",
|
||||||
|
site: "www.google.com"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generateInfo: {
|
||||||
|
credentials(username, studentId) {
|
||||||
|
// Create the output text
|
||||||
|
return [
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: `Username:`, moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${username}`, moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'Email:', moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${username}@kvcc.me.edu`, moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: `Student ID:`, moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${studentId}`, moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'Note: the MyKV Portal uses your username to sign in, not email.', moveDownAfter: true },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
maineCC() {
|
||||||
|
// Create the output text
|
||||||
|
return [
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'Kennebec Valley Community College is migrating email domains from @kvcc.me.edu to @mainecc.edu.', moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: `For support with this transition, please contact:`, moveDownAfter: true },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${mccContractor.name}`, moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${mccContractor.phone}`, moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${mccContractor.email}`, moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${mccContractor.site}`, moveDownAfter: true }
|
||||||
|
];
|
||||||
|
},
|
||||||
|
tempPassword(password) {
|
||||||
|
// Create the output text
|
||||||
|
return [
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'We have changed your password to a temporary password, shown below. Next time you log into Microsoft you will be prompted to change your password.\n', moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'Temporary Password:', moveDownAfter: false },
|
||||||
|
{ font: 'public/RobotoMono-SemiBold.ttf', text: `${password}\n`, moveDownAfter: true },
|
||||||
|
{ font: 'public/Outfit-Regular.ttf', text: 'Password requirements:\n8+ characters\n1+ Uppercase\n1+ Lowercase\n1+ Special (!/_=.,?)\n', moveDownAfter: true }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
generatePdf(infoArray) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
// Define the path for the PDF file
|
// Define the path for the PDF file
|
||||||
const pdfFilePath = path.join(__dirname, 'output.pdf');
|
const pdfFilePath = path.join(__dirname, '../public/output.pdf');
|
||||||
|
|
||||||
// Create a new PDF document
|
// Create a new PDF document
|
||||||
const doc = new PDFDocument({
|
const doc = new PDFDocument({
|
||||||
|
@ -39,6 +75,7 @@ module.exports = {
|
||||||
valign: 'top',
|
valign: 'top',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Move down below the Logo/Banner image
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
|
@ -46,7 +83,23 @@ module.exports = {
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
doc.moveDown();
|
doc.moveDown();
|
||||||
doc.fontSize(12).text(infoString, {
|
|
||||||
|
// Write the text from infoString
|
||||||
|
doc.fontSize(12)
|
||||||
|
// doc.font('public/Outfit-Regular.ttf').text(infoString, {
|
||||||
|
// align: 'left',
|
||||||
|
// });
|
||||||
|
|
||||||
|
for (row of infoArray) {
|
||||||
|
doc.font(row.font).text(row.text, {
|
||||||
|
align: 'left',
|
||||||
|
});
|
||||||
|
if (row.moveDownAfter) {
|
||||||
|
doc.moveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.font('public/Outfit-Regular.ttf').text(receiptFooter, {
|
||||||
align: 'left',
|
align: 'left',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,29 +107,35 @@ module.exports = {
|
||||||
doc.end();
|
doc.end();
|
||||||
|
|
||||||
writeStream.on('finish', () => {
|
writeStream.on('finish', () => {
|
||||||
// PDF file has been saved, now print it using lp command
|
resolve();
|
||||||
const printer = spawn('lp', ['-d', 'ITThermal', pdfFilePath]); // Replace 'ITThermal' with your actual printer name
|
});
|
||||||
|
|
||||||
|
// Handle any errors during file writing
|
||||||
|
writeStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
|
print() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// Define the path for the PDF file
|
||||||
|
const pdfFilePath = path.join(__dirname, '../public/output.pdf');
|
||||||
|
// Start the print command
|
||||||
|
const printer = spawn('lp', ['-d', 'ITThermal', pdfFilePath]);
|
||||||
|
|
||||||
// Handle error if the printing process fails
|
// Handle error if the printing process fails
|
||||||
printer.on('error', (err) => {
|
printer.on('error', (err) => {
|
||||||
console.error('Failed to start printing process:', err);
|
reject(err);
|
||||||
res.status(500).json({ message: 'Failed to start printing process', error: err.message });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle the process exit event
|
// Handle the process exit event
|
||||||
printer.on('close', (code) => {
|
printer.on('close', (code) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
res.send('PDF sent to printer successfully.');
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
res.status(500).json({ message: 'Failed to print PDF' });
|
reject("lp process exited with non-zero result.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
|
||||||
// Handle any errors during file writing
|
|
||||||
writeStream.on('error', (err) => {
|
|
||||||
console.error('Error writing PDF file:', err);
|
|
||||||
res.status(500).json({ message: 'Error writing PDF file', error: err.message });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "thermal",
|
"name": "thermal",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"description": "Web portal to print to a TSP100 thermal printer.",
|
"description": "Web portal to print to a TSP100 thermal printer.",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -3,44 +3,170 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Credential Printer</title>
|
<title>ITS Thermal Printer</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
|
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
|
||||||
<div class="max-w-lg mx-auto mt-10 bg-white p-8 rounded-lg shadow-lg">
|
<!-- Parent container to hold two columns -->
|
||||||
|
<div class="flex justify-center mt-10 space-x-4">
|
||||||
|
<!-- Left column containing the three original sections -->
|
||||||
|
<div class="flex flex-col space-y-4 max-w-lg">
|
||||||
|
<!-- ITS Thermal Printer Panel -->
|
||||||
|
<div class="bg-white p-8 rounded-lg shadow-lg">
|
||||||
<div class="flex justify-center mb-6">
|
<div class="flex justify-center mb-6">
|
||||||
<img src="./itslogo_color.png" alt="ITS Logo" class="h-24 w-auto">
|
<img src="./itslogo_color.png" alt="ITS Logo" class="h-24 w-auto">
|
||||||
</div>
|
</div>
|
||||||
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">ITS Credential Printer</h1>
|
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">ITS Thermal Printer Panel</h1>
|
||||||
<p class="text-center text-gray-600 mb-6">
|
<p class="text-center text-gray-600 mb-6">
|
||||||
Provide the username and student ID in the fields below, then click the Print button.
|
Provide the username and student ID in the fields below, then click the Generate button.<br>
|
||||||
A pre-formatted receipt will print with the information from the thermal printer.
|
A pre-formatted receipt will generate with the information. Click Print at the bottom of the page to print it.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form id="printForm" class="space-y-4">
|
<form id="printForm" class="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label for="username" class="block text-sm font-medium text-gray-700">Username:</label>
|
<label for="username" class="block text-sm font-medium text-gray-700">Username:</label>
|
||||||
<input type="text" id="username" name="username" required
|
<input type="text" id="username" name="username" required
|
||||||
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="studentId" class="block text-sm font-medium text-gray-700">Student ID:</label>
|
<label for="studentId" class="block text-sm font-medium text-gray-700">Student ID:</label>
|
||||||
<input type="text" id="studentId" name="studentId" required
|
<input type="text" id="studentId" name="studentId" required
|
||||||
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button type="submit"
|
<button type="submit" style="background-color: #1F3C70;"
|
||||||
style="background-color: #1F3C70;"
|
|
||||||
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
|
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
|
||||||
Print
|
Generate Receipt
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Temporary Password Printer -->
|
||||||
|
<div class="bg-white p-8 rounded-lg shadow-lg">
|
||||||
|
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">Temporary Password Printer</h1>
|
||||||
|
<p class="text-center text-gray-600 mb-6">
|
||||||
|
Provide the temporary password in the field below, then click the Generate button.<br>
|
||||||
|
A pre-formatted receipt will generate with the information. Click Print at the bottom of the page to print it.
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<label for="password" class="block text-sm font-medium text-gray-700">Temp Password:</label>
|
||||||
|
<input type="text" id="password" name="password" required
|
||||||
|
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="submit" id="printTempPw" style="background-color: #1F3C70;"
|
||||||
|
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-4">
|
||||||
|
Generate Receipt
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Right column containing the PDF Viewer -->
|
||||||
|
<div class="flex flex-col space-y-4 max-w-lg">
|
||||||
|
<div id="pdfContainer" class="max-w-lg bg-white p-8 rounded-lg shadow-lg text-center">
|
||||||
|
<h1 class="text-2xl font-bold mb-4" style="color: #1F3C70;">Receipt Preview</h1>
|
||||||
|
|
||||||
|
<!-- Refresh Button -->
|
||||||
|
<button id="refreshPdf"
|
||||||
|
class="bg-blue-200 hover:bg-blue-700 hover:text-white text-black font-bold py-2 px-4 rounded mb-4">
|
||||||
|
Refresh PDF
|
||||||
|
</button>
|
||||||
|
<!-- Print Button -->
|
||||||
|
<button id="print"
|
||||||
|
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded mb-4">
|
||||||
|
Print Receipt
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- PDF Viewer -->
|
||||||
|
<div id="pdfViewer" class="border border-gray-300 p-4 rounded-md"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Quick Prints -->
|
||||||
|
<div class="bg-white p-8 rounded-lg shadow-lg">
|
||||||
|
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">Quick Prints</h1>
|
||||||
|
<p class="text-center text-gray-600 mb-6">
|
||||||
|
Click the button to generate the relevant receipt.<br>
|
||||||
|
Click Print at the bottom of the page to print it.
|
||||||
|
</p>
|
||||||
|
<button id="print-mcc" class="w-full bg-gray-200 text-black py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
||||||
|
Contractor Information
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
function loadPDF() {
|
||||||
|
fetch('./output.pdf')
|
||||||
|
.then(response => {
|
||||||
|
const pdfViewer = document.getElementById('pdfViewer');
|
||||||
|
pdfViewer.innerHTML = ''; // Clear any previous content
|
||||||
|
console.log('Emptied PDF Viewer');
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
// If the PDF exists, reload the iframe
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
iframe.src = './output.pdf?' + new Date().getTime(); // Add timestamp to avoid caching
|
||||||
|
iframe.width = '100%';
|
||||||
|
iframe.height = '500px'; // Set the height as needed
|
||||||
|
iframe.classList.add('rounded-md');
|
||||||
|
pdfViewer.appendChild(iframe);
|
||||||
|
} else {
|
||||||
|
// If the PDF does not exist, display a message
|
||||||
|
pdfViewer.textContent = 'No PDF available';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// Handle errors, such as network issues
|
||||||
|
document.getElementById('pdfViewer').textContent = 'Error loading PDF';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the PDF when the page loads
|
||||||
|
window.onload = loadPDF;
|
||||||
|
|
||||||
|
// Add event listener for the "Refresh PDF" button
|
||||||
|
document.getElementById('refreshPdf').addEventListener('click', loadPDF);
|
||||||
|
|
||||||
|
document.getElementById('print-mcc').addEventListener('click', (event) => {
|
||||||
|
// Send a POST request with the form data to the server
|
||||||
|
fetch('/print-mcc', {
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.text(); // or .json() if your server returns JSON
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to send print request');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => alert('Error: ' + error));
|
||||||
|
setTimeout(loadPDF, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('print').addEventListener('click', (event) => {
|
||||||
|
// Send a POST request with the form data to the server
|
||||||
|
fetch('/print', {
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.text(); // or .json() if your server returns JSON
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to send print request');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(message => alert(message))
|
||||||
|
.catch(error => alert('Error: ' + error));
|
||||||
|
setTimeout(loadPDF, 100);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('printForm').addEventListener('submit', (event) => {
|
document.getElementById('printForm').addEventListener('submit', (event) => {
|
||||||
event.preventDefault(); // Prevent the form from submitting normally
|
event.preventDefault(); // Prevent the form from submitting normally
|
||||||
|
|
||||||
|
@ -50,7 +176,7 @@
|
||||||
const studentId = formData.get('studentId');
|
const studentId = formData.get('studentId');
|
||||||
|
|
||||||
// Send a POST request with the form data to the server
|
// Send a POST request with the form data to the server
|
||||||
fetch('/print', {
|
fetch('/print-credentials', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -67,8 +193,25 @@
|
||||||
throw new Error('Failed to send print request');
|
throw new Error('Failed to send print request');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(message => alert(message))
|
|
||||||
.catch(error => alert('Error: ' + error));
|
.catch(error => alert('Error: ' + error));
|
||||||
|
setTimeout(loadPDF, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('printTempPw').addEventListener('click', (event) => {
|
||||||
|
const password = document.getElementById('password').value;
|
||||||
|
|
||||||
|
// Send a POST request with the form data to the server
|
||||||
|
fetch('/print-temp-pw', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
password: password
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.catch(error => alert('Error: ' + error));
|
||||||
|
setTimeout(loadPDF, 100);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
@font-face {
|
||||||
|
font-family: Outfit;
|
||||||
|
src: url('Outfit-Regular.ttf');
|
||||||
|
}
|
||||||
|
|
||||||
|
body{
|
||||||
|
font-family: 'Outfit';
|
||||||
|
}
|
Loading…
Reference in New Issue