Updated 'Voucher' log information. Implemented missing custom voucher log output. Implemented PRINTER_TYPE variable to prepare for future printers. Disabled printer function by default. Updated README.md

This commit is contained in:
Glenn de Haan
2024-08-25 10:18:37 +02:00
parent 10b1eaaa47
commit af3322cb7b
4 changed files with 26 additions and 3 deletions

View File

@@ -76,6 +76,8 @@ services:
SERVICE_WEB: 'true' SERVICE_WEB: 'true'
# Enable/disable the API # Enable/disable the API
SERVICE_API: 'false' SERVICE_API: 'false'
# Enabled/disable the printer and set the preferred type, currently supported types: pdf
PRINTER_TYPE: ''
# SMTP Mail from email address (optional) # SMTP Mail from email address (optional)
SMTP_FROM: '' SMTP_FROM: ''
# SMTP Mail server hostname/ip (optional) # SMTP Mail server hostname/ip (optional)
@@ -251,6 +253,18 @@ The UniFi Voucher Site application includes built-in support for printing vouche
The print functionality is compatible with most 80mm thermal receipt printers commonly used in various industries. These printers typically use thermal printing technology, eliminating the need for ink cartridges and ensuring efficient and cost-effective voucher printing. The print functionality is compatible with most 80mm thermal receipt printers commonly used in various industries. These printers typically use thermal printing technology, eliminating the need for ink cartridges and ensuring efficient and cost-effective voucher printing.
### Configuration
To enable the print feature, you need to set the following environment variables:
```env
PRINTER_TYPE: ''
```
Heres what each variable represents:
- **`PRINTER_TYPE`**: Sets the printer type used by UniFi Voucher Site. Currently supported options: pdf
### Usage ### Usage
Once your 80mm receipt printer is configured and connected, you can easily print vouchers directly from the UniFi Voucher Site application. Simply navigate to the voucher within the interface and click on the "Print" button. Once your 80mm receipt printer is configured and connected, you can easily print vouchers directly from the UniFi Voucher Site application. Simply navigate to the voucher within the interface and click on the "Print" button.

View File

@@ -17,6 +17,7 @@ services:
VOUCHER_CUSTOM: 'true' VOUCHER_CUSTOM: 'true'
SERVICE_WEB: 'true' SERVICE_WEB: 'true'
SERVICE_API: 'false' SERVICE_API: 'false'
PRINTER_TYPE: ''
SMTP_FROM: '' SMTP_FROM: ''
SMTP_HOST: '' SMTP_HOST: ''
SMTP_PORT: '' SMTP_PORT: ''

View File

@@ -47,6 +47,7 @@ const voucherCustom = config('voucher_custom') !== null ? config('voucher_custom
const webService = process.env.SERVICE_WEB ? process.env.SERVICE_WEB !== 'false' : true; const webService = process.env.SERVICE_WEB ? process.env.SERVICE_WEB !== 'false' : true;
const apiService = config('service_api') || (process.env.SERVICE_API === 'true') || false; const apiService = config('service_api') || (process.env.SERVICE_API === 'true') || false;
const authDisabled = (process.env.AUTH_DISABLE === 'true') || false; const authDisabled = (process.env.AUTH_DISABLE === 'true') || false;
const printerType = config('printer_type') || process.env.PRINTER_TYPE || '';
const smtpFrom = config('smtp_from') || process.env.SMTP_FROM || ''; const smtpFrom = config('smtp_from') || process.env.SMTP_FROM || '';
const smtpHost = config('smtp_host') || process.env.SMTP_HOST || ''; const smtpHost = config('smtp_host') || process.env.SMTP_HOST || '';
const smtpPort = config('smtp_port') || process.env.SMTP_PORT || 25; const smtpPort = config('smtp_port') || process.env.SMTP_PORT || 25;
@@ -87,16 +88,22 @@ log.info(`[Service][Api] ${apiService ? 'Enabled!' : 'Disabled!'}`);
/** /**
* Log voucher types * Log voucher types
*/ */
log.info('[VoucherType] Loaded the following types:'); log.info('[Voucher] Loaded the following types:');
voucherTypes.forEach((type, key) => { voucherTypes.forEach((type, key) => {
log.info(`[VoucherType][${key}] ${time(type.expiration)}, ${type.usage === '1' ? 'single-use' : 'multi-use'}${typeof type.upload === "undefined" && typeof type.download === "undefined" && typeof type.megabytes === "undefined" ? ', no limits' : `${typeof type.upload !== "undefined" ? `, upload bandwidth limit: ${type.upload} kb/s` : ''}${typeof type.download !== "undefined" ? `, download bandwidth limit: ${type.download} kb/s` : ''}${typeof type.megabytes !== "undefined" ? `, quota limit: ${type.megabytes} mb` : ''}`}`); log.info(`[Voucher][Type][${key}] ${time(type.expiration)}, ${type.usage === '1' ? 'single-use' : 'multi-use'}${typeof type.upload === "undefined" && typeof type.download === "undefined" && typeof type.megabytes === "undefined" ? ', no limits' : `${typeof type.upload !== "undefined" ? `, upload bandwidth limit: ${type.upload} kb/s` : ''}${typeof type.download !== "undefined" ? `, download bandwidth limit: ${type.download} kb/s` : ''}${typeof type.megabytes !== "undefined" ? `, quota limit: ${type.megabytes} mb` : ''}`}`);
}); });
log.info(`[Voucher][Custom] ${voucherCustom ? 'Enabled!' : 'Disabled!'}`);
/** /**
* Log auth status * Log auth status
*/ */
log.info(`[Auth] ${authDisabled ? 'Disabled!' : 'Enabled!'}`); log.info(`[Auth] ${authDisabled ? 'Disabled!' : 'Enabled!'}`);
/**
* Log printer status
*/
log.info(`[Printer] ${printerType !== '' ? `Enabled! Type: ${printerType}` : 'Disabled!'}`);
/** /**
* Log email status * Log email status
*/ */
@@ -474,6 +481,7 @@ if(webService) {
timeConvert: time, timeConvert: time,
bytesConvert: bytes, bytesConvert: bytes,
email_enabled: smtpFrom !== '' && smtpHost !== '' && smtpPort !== '', email_enabled: smtpFrom !== '' && smtpHost !== '' && smtpPort !== '',
printer_enabled: printerType !== '',
voucher_types: voucherTypes, voucher_types: voucherTypes,
voucher_custom: voucherCustom, voucher_custom: voucherCustom,
vouchers: cache.vouchers, vouchers: cache.vouchers,

View File

@@ -195,7 +195,7 @@
<path d="M22.5 6.908V6.75a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3v.158l9.714 5.978a1.5 1.5 0 0 0 1.572 0L22.5 6.908Z" /> <path d="M22.5 6.908V6.75a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3v.158l9.714 5.978a1.5 1.5 0 0 0 1.572 0L22.5 6.908Z" />
</svg> </svg>
</button> </button>
<a href="<%= baseUrl %>/voucher/<%= voucher._id %>/print" type="button" class="relative rounded-full p-1 text-gray-500 dark:text-gray-400 hover:text-black dark:hover:text-white"> <a href="<%= baseUrl %>/voucher/<%= voucher._id %>/print" type="button" class="relative rounded-full p-1 text-gray-500 dark:text-gray-400 hover:text-black dark:hover:text-white<%= !printer_enabled ? ' hidden' : '' %>">
<span class="absolute -inset-1.5"></span> <span class="absolute -inset-1.5"></span>
<span class="sr-only">Print Voucher Code</span> <span class="sr-only">Print Voucher Code</span>
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> <svg class="h-5 w-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">