Flutter财政打印机集成插件yjy_fiscal_printer的使用
为了方便与不同品牌的财政打印机进行交互,并使用它们的功能,该模块定义了一个统一的交互数据结构和接口。通过实现这些接口来与特定品牌的财政打印机进行交互。
交互数据结构
Fiscal.Receipt
名称 |
描述 |
operator |
识别操作员 |
sales |
销售项目或取消销售 |
lottery |
国家彩票唯一客户代码 |
personalTaxCode |
个人税码 |
refunds |
退款项目或取消退款 |
subtotals |
小计 |
payments |
支付 |
barCode |
条形码 |
qrCode |
二维码 |
graphicCoupon |
图形优惠券 |
openDrawer |
打开抽屉 |
Fiscal.Report
名称 |
描述 |
type |
报告类型:每日财务报告或每日财政结账或两者兼有 |
operator |
操作员 |
timeout |
超时 |
openDrawer |
打开抽屉 |
Fiscal.Cancel
名称 |
描述 |
type |
空操作或冗余 |
zRepNum |
每日财政结账报告编号 |
docNum |
文档编号 |
date |
日期 |
fiscalNum |
打印机的财政序列号 |
operator |
操作员 |
Fiscal.Command
名称 |
描述 |
code |
命令类型 |
data |
命令所需的数据 |
Commands
命令名称 |
描述 |
支持情况 |
OPEN_DRAWER |
值:0,打开抽屉 |
Epson / 自定义 |
QUERY_PRINTER_STATUS |
值 1,查询打印机状态 |
Epson / 自定义 |
RESET_PRINTER |
值 2,重置打印机 |
Epson / 自定义 |
GET_NATIVE_CODE_FUNCTION |
值 3,使用打印机原生命令 |
Epson / 自定义 |
GET_INFO |
值 4,获取打印机设备信息 |
仅自定义 |
接口
Epson |
自定义 |
printFiscalReceipt(receipt: Fiscal.Receipt) |
printFiscalReceipt(receipt: FPrinterCustom.Receipt) |
printFiscalReport(report: Fiscal.Report) |
printFiscalReport(report: FPrinterCustom.Report) |
printCancel(cancel: Fiscal.Cancel) |
printCancel(cancel: FPrinterCustom.Cancel) |
executeCommand(...commands: Fiscal.Command[]) |
executeCommand(...commands: FPrinterCustom.Command[]) |
使用
Epson Fiscal ePOS-Print XML 示例
// 创建客户端
final fprinter = new EpsonXmlHttpClient(epson.Config(
host: '192.168.1.1',
deviceId: 'local_printer',
timeout: 10000
));
// 财政收据
await fprinter.printFiscalReceipt(epson.Receipt(
sales: [
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'A',
quantity: 1,
unitPrice: 5
),
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'B',
quantity: 2,
unitPrice: 2.5
),
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'C',
quantity: 3,
unitPrice: 3
),
],
payments: [
epson.Payment(
description: 'Payment in cash',
payment: 19
)
]
));
// 财政报告
await fprinter.printFiscalReport(epson.Report(
type: Fiscal.ReportType.DAILY_FISCAL_CLOUSE,
));
自定义协议示例
注意:单位数量乘以1000,单位价格乘以1000,包括折扣和支付
// 创建客户端
const fprinter = new CustomXmlHttpClient(custom.Config(
host: '192.168.1.1',
fiscalId: 'STMTE500432', // 11位数字
));
// 财政收据
await fprinter.printFiscalReceipt(custom.Receipt(
sales: [
custom.Sale(
type: Fiscal.ItemType.HOLD,
description: 'A',
quantity: 1 * 1000,
unitPrice: 5 * 100
),
custom.Sale(
type: Fiscal.ItemType.HOLD,
description: 'B',
quantity: 2 * 1000,
unitPrice: 2.5 * 100
),
custom.Sale(
type: Fiscal.ItemType.HOLD,
description: 'C',
quantity: 3 * 1000,
unitPrice: 3 * 100
),
],
payments: [
custom.Payment(
description: 'Payment in cash',
payment: 19 * 100,
paymentType: 1
)
]
));
// 财政退款
// 步骤1:请求确认是否可以作废,如果responseBuf === 1则执行步骤2
await fprinter.printCancel(custom.Cancel(
docRefZ: '0021',
docRefNumber: '0034',
docDate: '011022', // DDMMYY
printPreview: CustomProtocol.EnableType.DISABLE,
fiscalSerial: 'STMTE500432',
checkOnly: CustomProtocol.EnableType.ABLE,
codLottery: 'ASDSFES7',
));
// 步骤2:执行实际的作废请求
await fprinter.printCancel(custom.Cancel(
docRefZ: '0021',
docRefNumber: '0034',
docDate: '011022', // DDMMYY
printPreview: CustomProtocol.EnableType.DISABLE,
fiscalSerial: 'STMTE500432',
checkOnly: CustomProtocol.EnableType.DISABLE,
codLottery: 'ASDSFES7',
));
// 财政报告
await fprinter.printFiscalReport(custom.Report(
type: CustomProtocol.ReportType.DAILY_FISCAL_CLOUSE,
));
// 财政命令
await fprinter.executeCommand([custom.Command(
code: CustomProtocol.CommandCode.OPEN_DRAWER
)]);
已实现功能
Epson |
自定义 |
Fiscal ePOS-Print XML |
|
### 示例代码
```dart
// example/example.dart
void main(List<String> args) {
// 创建客户端
final fprinter = new EpsonXmlHttpClient(epson.Config(
host: '192.168.1.1',
deviceId: 'local_printer',
timeout: 10000
));
// 财政收据
fprinter.printFiscalReceipt(epson.Receipt(
sales: [
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'A',
quantity: 1,
unitPrice: 5
),
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'B',
quantity: 2,
unitPrice: 2.5
),
epson.Sale(
type: Fiscal.ItemType.HOLD,
description: 'C',
quantity: 3,
unitPrice: 3
),
],
payments: [
epson.Payment(
description: 'Payment in cash',
payment: 19
)
]
)).then((_) {
// 财政报告
fprinter.printFiscalReport(epson.Report(
type: Fiscal.ReportType.DAILY_FISCAL_CLOUSE,
));
});
}