📄 postransaction.java
字号:
// attach the party ID to the cart cart.setOrderPartyId(partyId); // validate payment methods output.print(UtilProperties.getMessage("pos","Validating",defaultLocale)); Map valRes = ch.validatePaymentMethods(); if (valRes != null && ServiceUtil.isError(valRes)) { throw new GeneralException(ServiceUtil.getErrorMessage(valRes)); } // store the "order" output.print(UtilProperties.getMessage("pos","Saving",defaultLocale)); Map orderRes = ch.createOrder(session.getUserLogin()); Debug.log("Create Order Resp : " + orderRes, module); if (orderRes != null && ServiceUtil.isError(orderRes)) { throw new GeneralException(ServiceUtil.getErrorMessage(orderRes)); } else if (orderRes != null) { this.orderId = (String) orderRes.get("orderId"); } // process the payment(s) output.print(UtilProperties.getMessage("pos","Processing",defaultLocale)); Map payRes = null; try { payRes = ch.processPayment(ProductStoreWorker.getProductStore(productStoreId, session.getDelegator()), session.getUserLogin(), true); } catch (GeneralException e) { Debug.logError(e, module); throw e; } if (payRes != null && ServiceUtil.isError(payRes)) { throw new GeneralException(ServiceUtil.getErrorMessage(payRes)); } // get the change due double change = (grandTotal - paymentAmt); // notify the change due output.print(UtilProperties.getMessage("pos","CHANGE",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue() * -1)); // threaded drawer/receipt printing final PosTransaction currentTrans = this; final SwingWorker worker = new SwingWorker() { public Object construct() { // open the drawer currentTrans.popDrawer(); // print the receipt DeviceLoader.receipt.printReceipt(currentTrans, true); return null; } }; worker.start(); // save the TX Log txLog.set("statusId", "POSTX_SOLD"); txLog.set("orderId", orderId); txLog.set("itemCount", new Long(cart.size())); txLog.set("logEndDateTime", UtilDateTime.nowTimestamp()); try { txLog.store(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to store TX log - not fatal", module); } // clear the tx currentTx = null; return change; } private synchronized GenericValue getStoreOrgAddress() { if (this.shipAddress == null) { // locate the store's physical address - use this for tax GenericValue facility = (GenericValue) session.getAttribute("facility"); if (facility == null) { return null; } List fcp = null; try { fcp = facility.getRelatedByAnd("FacilityContactMechPurpose", UtilMisc.toMap("contactMechPurposeTypeId", "SHIP_ORIG_LOCATION")); } catch (GenericEntityException e) { Debug.logError(e, module); } fcp = EntityUtil.filterByDate(fcp); GenericValue purp = EntityUtil.getFirst(fcp); if (purp != null) { try { this.shipAddress = session.getDelegator().findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", purp.getString("contactMechId"))); } catch (GenericEntityException e) { Debug.logError(e, module); } } } return this.shipAddress; } public void saveTx() { savedTx.push(this); currentTx = null; trace("transaction saved"); } public void appendItemDataModel(XModel model) { if (cart != null) { Iterator i = cart.iterator(); while (i.hasNext()) { ShoppingCartItem item = (ShoppingCartItem) i.next(); double quantity = item.getQuantity(); double unitPrice = item.getBasePrice(); double subTotal = unitPrice * quantity; double adjustment = item.getOtherAdjustments(); XModel line = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(line, "td", "sku", item.getProductId()); Journal.appendNode(line, "td", "desc", item.getName()); Journal.appendNode(line, "td", "qty", UtilFormatOut.formatQuantity(quantity)); Journal.appendNode(line, "td", "price", UtilFormatOut.formatPrice(subTotal)); Journal.appendNode(line, "td", "index", new Integer(cart.getItemIndex(item)).toString()); if (adjustment != 0) { // append the promo info XModel promo = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(promo, "td", "sku", ""); Journal.appendNode(promo, "td", "desc", "(adjustment)"); Journal.appendNode(promo, "td", "qty", "-"); Journal.appendNode(promo, "td", "price", UtilFormatOut.formatPrice(adjustment)); } } } } public void appendTotalDataModel(XModel model) { if (cart != null) { double taxAmount = cart.getTotalSalesTax(); double total = cart.getGrandTotal(); XModel taxLine = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(taxLine, "td", "sku", ""); Journal.appendNode(taxLine, "td", "desc", UtilProperties.getMessage("pos","Sales_Tax",defaultLocale)); Journal.appendNode(taxLine, "td", "qty", "-"); Journal.appendNode(taxLine, "td", "price", UtilFormatOut.formatPrice(taxAmount)); XModel totalLine = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(totalLine, "td", "sku", ""); Journal.appendNode(totalLine, "td", "desc", UtilProperties.getMessage("pos","Grand_Total",defaultLocale)); Journal.appendNode(totalLine, "td", "qty", "-"); Journal.appendNode(totalLine, "td", "price", UtilFormatOut.formatPrice(total)); } } public void appendPaymentDataModel(XModel model) { if (cart != null) { int paymentInfoSize = cart.selectedPayments(); for (int i = 0; i < paymentInfoSize; i++) { ShoppingCart.CartPaymentInfo inf = (ShoppingCart.CartPaymentInfo) cart.getPaymentInfo(i); GenericValue paymentInfoObj = inf.getValueObject(session.getDelegator()); GenericValue paymentMethodType = null; GenericValue paymentMethod = null; if ("PaymentMethod".equals(paymentInfoObj.getEntityName())) { paymentMethod = paymentInfoObj; try { paymentMethodType = paymentMethod.getRelatedOne("PaymentMethodType"); } catch (GenericEntityException e) { Debug.logError(e, module); } } else { paymentMethodType = paymentInfoObj; } Object desc = paymentMethodType != null ? paymentMethodType.get("description",defaultLocale) : "??"; String descString = desc.toString(); double amount = 0; if (inf.amount == null) { amount = cart.getGrandTotal() - cart.getPaymentTotal(); } else { amount = inf.amount.doubleValue(); } XModel paymentLine = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(paymentLine, "td", "sku", ""); Journal.appendNode(paymentLine, "td", "desc", descString); Journal.appendNode(paymentLine, "td", "qty", "-"); Journal.appendNode(paymentLine, "td", "price", UtilFormatOut.formatPrice(-1 * amount)); Journal.appendNode(paymentLine, "td", "index", new Integer(i).toString()); } } } public void appendChangeDataModel(XModel model) { if (cart != null) { double changeDue = (-1 * this.getTotalDue()); if (changeDue >= 0) { XModel changeLine = Journal.appendNode(model, "tr", "", ""); Journal.appendNode(changeLine, "td", "sku", ""); Journal.appendNode(changeLine, "td", "desc", "Change"); Journal.appendNode(changeLine, "td", "qty", "-"); Journal.appendNode(changeLine, "td", "price", UtilFormatOut.formatPrice(changeDue)); } } } public String makeCreditCardVo(String cardNumber, String expDate, String firstName, String lastName) { LocalDispatcher dispatcher = session.getDispatcher(); String expMonth = expDate.substring(0, 2); String expYear = expDate.substring(2); // two digit year check -- may want to re-think this if (expYear.length() == 2) { expYear = "20" + expYear; } Map svcCtx = new HashMap(); svcCtx.put("userLogin", session.getUserLogin()); svcCtx.put("partyId", partyId); svcCtx.put("cardNumber", cardNumber); svcCtx.put("firstNameOnCard", firstName == null ? "" : firstName); svcCtx.put("lastNameOnCard", lastName == null ? "" : lastName); svcCtx.put("expMonth", expMonth); svcCtx.put("expYear", expYear); svcCtx.put("cardType", UtilValidate.getCardType(cardNumber)); Debug.log("Create CC : " + svcCtx, module); Map svcRes = null; try { svcRes = dispatcher.runSync("createCreditCard", svcCtx); } catch (GenericServiceException e) { Debug.logError(e, module); return null; } if (ServiceUtil.isError(svcRes)) { Debug.logError(ServiceUtil.getErrorMessage(svcRes) + " - " + svcRes, module); return null; } else { return (String) svcRes.get("paymentMethodId"); } } public GenericValue getTerminalState() { GenericDelegator delegator = session.getDelegator(); List states = null; try { states = delegator.findByAnd("PosTerminalState", UtilMisc.toMap("posTerminalId", this.getTerminalId())); } catch (GenericEntityException e) { Debug.logError(e, module); } states = EntityUtil.filterByDate(states, UtilDateTime.nowTimestamp(), "openedDate", "closedDate", true); return EntityUtil.getFirst(states); } public void setPrintWriter(PrintWriter writer) { this.trace = writer; } private void trace(String s) { trace(s, null, null); } private void trace(String s, Throwable t) { trace(s, null, t); } private void trace(String s1, String s2) { trace(s1, s2, null); } private void trace(String s1, String s2, Throwable t) { if (trace != null) { String msg = s1; if (UtilValidate.isNotEmpty(s2)) { msg = msg + "(" + s2 + ")"; } if (t != null) { msg = msg + " : " + t.getMessage(); } // print the trace line trace.println("[POS @ " + terminalId + " TX:" + transactionId + "] - " + msg); trace.flush(); } } public static synchronized PosTransaction getCurrentTx(XuiSession session) { if (currentTx == null) { if (session.getUserLogin() != null) { currentTx = new PosTransaction(session); } } return currentTx; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -