Skip to content

Commit

Permalink
Updated 'Voucher' log information. Implemented missing custom voucher…
Browse files Browse the repository at this point in the history
… log output. Implemented PRINTER_TYPE variable to prepare for future printers. Disabled printer function by default. Updated README.md
  • Loading branch information
glenndehaan committed Aug 25, 2024
1 parent 10b1eaa commit af3322c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ services:
SERVICE_WEB: 'true'
# Enable/disable the API
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_FROM: ''
# SMTP Mail server hostname/ip (optional)
Expand Down Expand Up @@ -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.

### Configuration

To enable the print feature, you need to set the following environment variables:

```env
PRINTER_TYPE: ''
```

Here’s what each variable represents:

- **`PRINTER_TYPE`**: Sets the printer type used by UniFi Voucher Site. Currently supported options: pdf

### 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.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
VOUCHER_CUSTOM: 'true'
SERVICE_WEB: 'true'
SERVICE_API: 'false'
PRINTER_TYPE: ''
SMTP_FROM: ''
SMTP_HOST: ''
SMTP_PORT: ''
Expand Down
12 changes: 10 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 apiService = config('service_api') || (process.env.SERVICE_API === '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 smtpHost = config('smtp_host') || process.env.SMTP_HOST || '';
const smtpPort = config('smtp_port') || process.env.SMTP_PORT || 25;
Expand Down Expand Up @@ -87,16 +88,22 @@ log.info(`[Service][Api] ${apiService ? 'Enabled!' : 'Disabled!'}`);
/**
* Log voucher types
*/
log.info('[VoucherType] Loaded the following types:');
log.info('[Voucher] Loaded the following types:');
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.info(`[Auth] ${authDisabled ? 'Disabled!' : 'Enabled!'}`);

/**
* Log printer status
*/
log.info(`[Printer] ${printerType !== '' ? `Enabled! Type: ${printerType}` : 'Disabled!'}`);

/**
* Log email status
*/
Expand Down Expand Up @@ -474,6 +481,7 @@ if(webService) {
timeConvert: time,
bytesConvert: bytes,
email_enabled: smtpFrom !== '' && smtpHost !== '' && smtpPort !== '',
printer_enabled: printerType !== '',
voucher_types: voucherTypes,
voucher_custom: voucherCustom,
vouchers: cache.vouchers,
Expand Down
2 changes: 1 addition & 1 deletion template/voucher.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</svg>
</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="sr-only">Print Voucher Code</span>
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
Expand Down

0 comments on commit af3322c

Please sign in to comment.