Skip to content

Commit

Permalink
Merge pull request #1244 from RafaelTaranto/backport/collection-receipts
Browse files Browse the repository at this point in the history
LAM-230 backport: collection receipts
  • Loading branch information
RafaelTaranto authored Nov 29, 2024
2 parents 7e0a48c + 0d37a3b commit 6f7826c
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,7 @@ Brain.prototype._billsEnabled = function _billsEnabled () {

Brain.prototype._stackerOpen = function _stackerOpen () {
return this.trader.notifyCashboxRemoval()
.then(this._printCashboxReceipt)
}

Brain.prototype._uiCredit = function _uiCredit () {
Expand Down Expand Up @@ -3526,6 +3527,20 @@ Brain.prototype._printReceipt = function _printReceipt () {
})
}

Brain.prototype._printCashboxReceipt = function (data) {
if (!this.printer) {
console.log('[ERROR]: The kiosk printer is not loaded')
return
}

return this.printer.checkStatus(deviceConfig.kioskPrinter, STATUS_QUERY_TIMEOUT)
.then(() => this.printer.printCashboxReceipt(data, deviceConfig.kioskPrinter))
.catch((err) => {
console.log('[ERROR]: The kiosk printer is in an invalid state.', err)
throw err
})
}

Brain.prototype._verifyTransaction = function _verifyTransaction () {
if (!this.idVerify.inProgress()) return

Expand Down
93 changes: 93 additions & 0 deletions lib/printer/nippon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash/fp')
const { SerialPort } = require('serialport')
const zplHelper = require('./zpl-helper')

const lineFeed = [0x0a]
const finalLineFeed = [0x1b, 0x64, 0x05]
Expand Down Expand Up @@ -166,6 +167,97 @@ const printReceipt = (data, { address }, receiptConfig) =>
})
)

const printCashboxReceipt = (data, { address }) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
.then((port) => {
const cmd = []

// disable and enable to get rid of previous buffer
// useful because of possible comm failure
cmd.push(disable)
cmd.push(enable)

// set manual ejection mode
cmd.push(manualEjectionMode)

cmd.push('CASH COLLECTION RECEIPT')
cmd.push(lineFeed)
cmd.push(lineFeed)

if (data.batch) {
if (data.batch.created) {
cmd.push('Date and time: ')
cmd.push(data.batch.created)
cmd.push(lineFeed)
}

if (data.batch.id && data.batch.operationType) {
cmd.push(`Batch creation mode: automatic`)
cmd.push(`Batch ID: ${data.batch.id}`)
cmd.push(lineFeed)
} else {
cmd.push(`Batch creation mode: manual`)
cmd.push(lineFeed)
}

if (data.batch.deviceId) {
cmd.push(`Machine ID: ${data.batch.deviceId}`)
cmd.push(lineFeed)
}

if (data.batch.machineName) {
cmd.push(`Machine name: ${data.batch.machineName}`)
cmd.push(lineFeed)
}

if (data.batch.billCount) {
cmd.push(lineFeed)
cmd.push(`Bill count: ${data.batch.billCount}`)
cmd.push(lineFeed)
}

if (data.batch.fiatTotals) {
cmd.push(lineFeed)
cmd.push(`Total amount per fiat: `)
cmd.push(lineFeed)
cmd.push(`---------------------`)
cmd.push(lineFeed)
cmd.push(_.join(' | ', _.map(it => `${it}: ${data.batch.fiatTotals[it]}`, _.keys(data.batch.fiatTotals))))
cmd.push(lineFeed)
}

if (data.batch.billsByDenomination) {
cmd.push(lineFeed)
cmd.push(`Bills by denomination: `)
cmd.push(lineFeed)
cmd.push(`---------------------`)
cmd.push(lineFeed)
_.forEach(
it => {
cmd.push(`${it}: ${data.batch.billsByDenomination[it]}`)
cmd.push(lineFeed)
},
_.keys(data.batch.billsByDenomination)
)
cmd.push(lineFeed)
}
}

cmd.push(finalLineFeed)
cmd.push(fullCut)

cmd.push(presenterEjection)

port.write(Buffer.concat(cmd.map(Buffer.from)), err => {
if (err) reject(err)

port.close()
resolve()
})
})
)

const printWallet = (wallet, { address }, code) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
Expand Down Expand Up @@ -217,5 +309,6 @@ const checkStatus = () =>
module.exports = {
printReceipt,
printWallet,
printCashboxReceipt,
checkStatus
}
83 changes: 83 additions & 0 deletions lib/printer/zebra.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,88 @@ const printReceipt = (data, { address }, receiptConfig) =>
})
)

const printCashboxReceipt = (data, printerCfg) =>
new Promise((resolve, reject) =>
openSerialPort(printerCfg, portOptions)
.then((port) => {
let cmd = zplHelper.start()
let yPosition = 250

cmd += zplHelper.header('CASH COLLECTION RECEIPT', yPosition)
yPosition += 80

if (data.batch) {
if (data.batch.created) {
cmd += zplHelper.subheader(`Date and time: ${data.batch.created}`, yPosition)
yPosition += Math.ceil(SPACER * 1.3)
}

if (data.batch.id && data.batch.operationType) {
cmd += zplHelper.text(`Batch creation mode: automatic`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`Batch ID: ${data.batch.id}`, yPosition)
} else {
cmd += zplHelper.text(`Batch creation mode: manual`, yPosition)
}
yPosition += Math.ceil(SPACER * 1.3)

if (data.batch.deviceId) {
cmd += zplHelper.text(`Machine ID: ${data.batch.deviceId}`, yPosition)
yPosition += SPACER
}

if (data.batch.machineName) {
cmd += zplHelper.text(`Machine name: ${data.batch.machineName}`, yPosition)
yPosition += SPACER
}

if (data.batch.billCount) {
yPosition += SPACER
cmd += zplHelper.text(`Bill count: ${data.batch.billCount}`, yPosition)
yPosition += SPACER
}

if (data.batch.fiatTotals) {
yPosition += SPACER
cmd += zplHelper.text(`Total amount per fiat`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`---------------------`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(_.join(' | ', _.map(it => `${it}: ${data.batch.fiatTotals[it]}`, _.keys(data.batch.fiatTotals))), yPosition)
yPosition += SPACER
}

if (data.batch.billsByDenomination) {
yPosition += SPACER
cmd += zplHelper.text(`Bills by denomination`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`---------------------`, yPosition)
yPosition += SPACER
_.forEach(
it => {
cmd += zplHelper.text(`${it}: ${data.batch.billsByDenomination[it]}`, yPosition)
yPosition += SPACER
},
_.keys(data.batch.billsByDenomination)
)
yPosition += SPACER
}
}

cmd += zplHelper.end()

port.write(cmd, 'utf8', (err) => {
if (err) return reject(err)

port.close()
return resolve()
})
})
.catch((err) => {
reject(err)
})
)

const printWallet = (wallet, { address }, code) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
Expand Down Expand Up @@ -292,5 +374,6 @@ function readStatusCode (statusCode) {
module.exports = {
printReceipt,
printWallet,
printCashboxReceipt,
checkStatus
}

0 comments on commit 6f7826c

Please sign in to comment.