⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receipt.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: Receipt.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.pos.device.impl;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Map;import jpos.JposException;import jpos.POSPrinter;import jpos.POSPrinterConst;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilURL;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.pos.PosTransaction;import org.ofbiz.pos.device.GenericDevice;import org.ofbiz.pos.screen.DialogCallback;import org.ofbiz.pos.screen.PosDialog;import org.ofbiz.pos.screen.PosScreen;import org.apache.commons.collections.map.LinkedMap;/** *  * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 5462 $ * @since      3.2 */public class Receipt extends GenericDevice implements DialogCallback {    public static final String module = Receipt.class.getName();    protected static final String ESC = ((char) 0x1b) + "";    protected static final String LF = ((char) 0x0a) + "";    protected static final String ALIGN_CENTER = ESC + "|cA";    protected static final String ALIGN_RIGHT = ESC + "|rA";    protected static final String TEXT_DOUBLE_HEIGHT = ESC + "|4C";    protected static final String TEXT_UNDERLINE = ESC + "|uC";    protected static final String TEXT_BOLD = ESC + "|bC";    protected static final String PAPER_CUT = ESC + "|100fP";    protected SimpleDateFormat[] dateFormat = null;    protected String[] storeReceiptTmpl = null;    protected String[] custReceiptTmpl = null;    protected LinkedMap reportTmpl = new LinkedMap();    protected String[] dateFmtStr = { "EEE, d MMM yyyy HH:mm:ss z", "EEE, d MMM yyyy HH:mm:ss z", "EEE, d MMM yyyy HH:mm:ss z" };    protected int[] priceLength = { 7, 7, 7 };    protected int[] qtyLength = { 5, 5, 5 };    protected int[] descLength = { 25, 25, 0 };    protected int[] pridLength = { 25, 25, 0 };    protected int[] infoLength = { 34, 34, 0 };    protected PosTransaction lastTransaction = null;    public Receipt(String deviceName, int timeout) {        super(deviceName, timeout);        this.control = new jpos.POSPrinter();    }    protected void initialize() throws JposException {        Debug.logInfo("Receipt [" + control.getPhysicalDeviceName() + "] Claimed : " + control.getClaimed(), module);        // set map mode to metric - all dimensions specified in 1/100mm units        // unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units        ((jpos.POSPrinter) control).setMapMode(POSPrinterConst.PTR_MM_METRIC);    }    public void println() {        this.println("");    }    public void println(String p) {        try {            ((POSPrinter) control).printNormal(POSPrinterConst.PTR_S_RECEIPT, p + LF);        } catch (jpos.JposException e) {            Debug.logError(e, module);        }    }    public void printBarcode(String barcode) {        // print the orderId bar code (Code 3 of 9) centered (1cm tall, 6cm wide)        try {            ((POSPrinter) control).printBarCode(POSPrinterConst.PTR_S_RECEIPT, barcode, POSPrinterConst.PTR_BCS_Code39,                    10 * 100, 60 * 100, POSPrinterConst.PTR_BC_CENTER, POSPrinterConst.PTR_BC_TEXT_NONE);        } catch (JposException e) {            Debug.logError(e, module);        }    }    public void printReport(PosTransaction trans, String resource, Map context) {        Debug.log("Print Report Requested", module);        String[] report = this.readReportTemplate(resource);        if (report != null) {            for (int i = 0; i < report.length; i++) {                if (report[i] != null) {                    this.printInfo(report[i], context, trans, 2);                }            }            this.println();            this.println();            this.println(PAPER_CUT);        }    }    public void reprintReceipt() {        this.reprintReceipt(false);    }    public void reprintReceipt(boolean reprintStoreCopy) {        if (lastTransaction != null) {            this.printReceipt(lastTransaction, reprintStoreCopy);        }    }    public void printReceipt(PosTransaction trans, boolean printStoreCopy) {        Debug.log("Print Receipt Requested : " + trans.getTransactionId(), module);        POSPrinter printer = (POSPrinter) control;        this.lastTransaction = trans;        try {            if (!checkState(printer)) {                return;            }        } catch (JposException e) {            Debug.logError(e, module);        }        if (printStoreCopy) {            String[] storeReceipt = this.readStoreTemplate();            int payments = trans.getNumberOfPayments();            for (int i = 0; i < payments; i++) {                Map info = trans.getPaymentInfo(i);                if (info.containsKey("cardNumber")) {                    this.printReceipt(trans, storeReceipt, 1, info);                }                try {                    Thread.sleep(3000);                } catch (Exception e) {                }            }                                }        // print the customer receipt        String[] custReceipt = this.readCustomerTemplate();        this.printReceipt(trans, custReceipt, 0, null);    }    private void printReceipt(PosTransaction trans, String[] template, int type, Map payInfo) {        if (template != null) {            for (int i = 0; i < template.length; i++) {                if (template[i] != null) {                    if ("[ORDER_BARCODE]".equals(template[i])) {                        this.printBarcode(trans.getOrderId());                    } else if (template[i].startsWith("[DLOOP]")) {                        this.printDetail(template[i], trans, type);                    } else if (template[i].startsWith("[PLOOP]")) {                        this.printPayInfo(template[i], trans, type);                    } else if (payInfo != null) {                        this.printPayInfo(template[i], trans, type, payInfo);                    } else {                        this.printInfo(template[i], trans, type);                    }                }            }            this.println();            this.println();            this.println(PAPER_CUT);        }    }    private synchronized String[] readStoreTemplate() {        if (this.storeReceiptTmpl == null) {            this.storeReceiptTmpl = new String[7];            this.readTemplate(storeReceiptTmpl, "storereceipt.txt", 1);        }        return this.storeReceiptTmpl;    }    private synchronized String[] readCustomerTemplate() {        if (this.custReceiptTmpl == null) {            this.custReceiptTmpl = new String[7];            this.readTemplate(custReceiptTmpl, "custreceipt.txt", 0);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -