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

📄 postransaction.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: PosTransaction.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;import java.io.PrintWriter;import java.io.Serializable;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.HashMap;import net.xoetrope.xui.data.XModel;import net.xoetrope.xui.helper.SwingWorker;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.Log4jLoggerWriter;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.collections.LifoSet;import org.ofbiz.guiapp.xui.XuiSession; import org.ofbiz.order.shoppingcart.CartItemModifyException;import org.ofbiz.order.shoppingcart.ShoppingCart;import org.ofbiz.order.shoppingcart.ShoppingCartItem;import org.ofbiz.order.shoppingcart.CheckOutHelper;import org.ofbiz.order.shoppingcart.ItemNotFoundException;import org.ofbiz.pos.component.Journal;import org.ofbiz.pos.component.Output;import org.ofbiz.pos.device.DeviceLoader;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.service.ServiceUtil;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.GenericServiceException;import org.ofbiz.accounting.payment.PaymentGatewayServices;import org.ofbiz.base.util.UtilProperties;/** *  * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 5462 $ * @since      3.1 */public class PosTransaction implements Serializable {    public static final String module = PosTransaction.class.getName();    public static final int NO_PAYMENT = 0;    public static final int INTERNAL_PAYMENT = 1;    public static final int EXTERNAL_PAYMENT = 2;    private static PrintWriter defaultPrintWriter = new Log4jLoggerWriter(Debug.getLogger(module));    private static PosTransaction currentTx = null;    private static LifoSet savedTx = new LifoSet();    private Locale defaultLocale = Locale.getDefault();    protected XuiSession session = null;    protected ShoppingCart cart = null;    protected CheckOutHelper ch = null;    protected PrintWriter trace = null;    protected GenericValue txLog = null;    protected String productStoreId = null;    protected String transactionId = null;    protected String facilityId = null;    protected String terminalId = null;    protected String currency = null;    protected String orderId = null;    protected String partyId = null;    protected Locale locale = null;    protected boolean isOpen = false;    protected int drawerIdx = 0;    private GenericValue shipAddress = null;    private Map skuDiscounts = new HashMap();    private int cartDiscount = -1;    public PosTransaction(XuiSession session) {        this.session = session;        this.terminalId = session.getId();        this.partyId = "_NA_";        this.trace = defaultPrintWriter;        this.productStoreId = (String) session.getAttribute("productStoreId");        this.facilityId = (String) session.getAttribute("facilityId");        this.currency = (String) session.getAttribute("currency");        this.locale = (Locale) session.getAttribute("locale");        this.cart = new ShoppingCart(session.getDelegator(), productStoreId, locale, currency);        this.transactionId = session.getDelegator().getNextSeqId("PosTransaction");        this.ch = new CheckOutHelper(session.getDispatcher(), session.getDelegator(), cart);        cart.setChannelType("POS_SALES_CHANNEL");        cart.setTransactionId(transactionId);        cart.setFacilityId(facilityId);        cart.setTerminalId(terminalId);        if (session.getUserLogin() != null) {            cart.addAdditionalPartyRole(session.getUserLogin().getString("partyId"), "SALES_REP");        }        // setup the TX log        String txLogId = session.getDelegator().getNextSeqId("PosTerminalLog");        txLog = session.getDelegator().makeValue("PosTerminalLog", null);        txLog.set("posTerminalLogId", txLogId);        txLog.set("posTerminalId", terminalId);        txLog.set("transactionId", transactionId);        txLog.set("userLoginId", session.getUserId());        txLog.set("statusId", "POSTX_ACTIVE");        txLog.set("logStartDateTime", UtilDateTime.nowTimestamp());        try {            txLog.create();        } catch (GenericEntityException e) {            Debug.logError(e, "Unable to create TX log - not fatal", module);        }        currentTx = this;        trace("transaction created");    }    public String getUserId() {        return session.getUserId();    }    public int getDrawerNumber() {        return drawerIdx + 1;    }    public void popDrawer() {        DeviceLoader.drawer[drawerIdx].openDrawer();    }    public String getTransactionId() {        return this.transactionId;    }    public String getTerminalId() {        return this.terminalId;    }    public String getFacilityId() {        return this.facilityId;    }    public boolean isOpen() {        if (!this.isOpen) {            GenericValue terminalState = this.getTerminalState();            if (terminalState != null) {                this.isOpen = true;            } else {                this.isOpen = false;            }        }        return this.isOpen;    }    public boolean isEmpty() {        return (cart == null || cart.size() == 0);    }    public List lookupItem(String sku) throws GeneralException {        // first check for the product        GenericValue product = session.getDelegator().findByPrimaryKey("Product", UtilMisc.toMap("productId", sku));        if (product != null) {            return UtilMisc.toList(product);        } else {            // not found; so we move on to GoodIdentification           return session.getDelegator().findByAnd("GoodIdentificationAndProduct",                   UtilMisc.toMap("idValue", sku), UtilMisc.toList("productId"));        }    }    public String getOrderId() {        return this.orderId;    }    public double getTaxTotal() {        return cart.getTotalSalesTax();    }        public double getGrandTotal() {        return UtilFormatOut.formatPriceNumber(cart.getGrandTotal()).doubleValue();    }    public int getNumberOfPayments() {        return cart.selectedPayments();    }    public double getPaymentTotal() {        return UtilFormatOut.formatPriceNumber(cart.getPaymentTotal()).doubleValue();    }    public double getTotalDue() {        double grandTotal = this.getGrandTotal();        double paymentAmt = this.getPaymentTotal();        return (grandTotal - paymentAmt);    }    public int size() {        return cart.size();    }    public Map getItemInfo(int index) {        ShoppingCartItem item = cart.findCartItem(index);        Map itemInfo = new HashMap();        itemInfo.put("productId", item.getProductId());        itemInfo.put("description", item.getDescription());        itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity()));        itemInfo.put("basePrice", UtilFormatOut.formatPrice(item.getBasePrice()));        itemInfo.put("subtotal", UtilFormatOut.formatPrice(item.getItemSubTotal()));        itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");        itemInfo.put("adjustments", item.getOtherAdjustments() > 0 ?                UtilFormatOut.formatPrice(item.getOtherAdjustments()) : "");        return itemInfo;    }    public Map getPaymentInfo(int index) {        ShoppingCart.CartPaymentInfo inf = cart.getPaymentInfo(index);                GenericValue infValue = inf.getValueObject(session.getDelegator());        GenericValue paymentPref = null;        try {            Map fields = new HashMap();            fields.put("paymentMethodTypeId", inf.paymentMethodTypeId);            if (inf.paymentMethodId != null) {                fields.put("paymentMethodId", inf.paymentMethodId);            }            fields.put("maxAmount", inf.amount);            fields.put("orderId", this.getOrderId());            List paymentPrefs = session.getDelegator().findByAnd("OrderPaymentPreference", fields);            if (paymentPrefs != null && paymentPrefs.size() > 0) {                Debug.log("Found some prefs - " + paymentPrefs.size(), module);                if (paymentPrefs.size() > 1) {                    Debug.logError("Multiple OrderPaymentPreferences found for the same payment method!", module);                } else {                    paymentPref = EntityUtil.getFirst(paymentPrefs);                    Debug.log("Got the first pref - " + paymentPref, module);                }            } else {                Debug.logError("No OrderPaymentPreference found - " + fields, module);            }        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        Debug.log("PaymentPref - " + paymentPref, module);        Map payInfo = new HashMap();        // locate the auth info        GenericValue authTrans = null;        if (paymentPref != null) {            authTrans = PaymentGatewayServices.getAuthTransaction(paymentPref);            if (authTrans != null) {                payInfo.putAll(authTrans);                String authInfoString = "Ref: " + authTrans.getString("referenceNum") + " Auth: " + authTrans.getString("gatewayCode");                payInfo.put("authInfoString", authInfoString);            } else {                Debug.logError("No Authorization transaction found for payment preference - " + paymentPref, module);            }        } else {            Debug.logError("Payment preference is empty!", module);            return payInfo;        }        Debug.log("AuthTrans - " + authTrans, module);        if ("PaymentMethodType".equals(infValue.getEntityName())) {            payInfo.put("description", infValue.getString("description"));

⌨️ 快捷键说明

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