Package org.ofbiz.pos.component

Examples of org.ofbiz.pos.component.Input


        }
    }

    public static synchronized void addItem(PosScreen pos, AWTEvent event) {
        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        Input input = pos.getInput();
        String[] func = input.getFunction("QTY");
        String value = input.value();

        // no value; just return
        if (event != null && UtilValidate.isEmpty(value)) {
            String buttonName = ButtonEventConfig.getButtonName(event);
            if (UtilValidate.isNotEmpty(buttonName)) {
                if (buttonName.startsWith("SKU.")) {
                    value = buttonName.substring(4);
                }
            }
            if (UtilValidate.isEmpty(value)) {
                return;
            }
        }

        if (!trans.isOpen()) {
            pos.showDialog("dialog/error/terminalclosed");
        } else {

            // check for quantity
            BigDecimal quantity = BigDecimal.ONE;
            if (func != null && "QTY".equals(func[0])) {
                try {
                    quantity = new BigDecimal(func[1]);
                } catch (NumberFormatException e) {
                    quantity = BigDecimal.ONE;
                }
            }

            // locate the product ID
            String productId = null;
            try {
                List items = trans.lookupItem(value);
                if (items != null) {
                    ListIterator it = items.listIterator();
                    if (it.hasNext()) {
                        GenericValue product = (GenericValue) it.next();
                        productId = product.getString("productId");
                        Hashtable productsMap = new Hashtable();
                        productsMap.put(product.getString("productId"), product.get("internalName"));
                        while (it.hasNext()) {
                            product = (GenericValue) it.next();
                            if (!productId.equals(product.getString("productId"))) {
                                productsMap.put(product.getString("productId"), product.get("internalName"));
                            }
                        }
                        if (productsMap.size() > 1 && ButtonEventConfig.getButtonName(event).equals("menuSku")) {
                            SelectProduct SelectProduct = new SelectProduct(productsMap, trans, pos);
                            productId = SelectProduct.openDlg();
                        }
                    }
                }
            } catch (GeneralException e) {
                Debug.logError(e, module);
                pos.showDialog("dialog/error/producterror");
            }

            // Check for Aggregated item
            boolean aggregatedItem = false;
            ProductConfigWrapper pcw = null;
            try {
                aggregatedItem = trans.isAggregatedItem(productId);
                if (aggregatedItem) {
                    pcw = trans.getProductConfigWrapper(productId);
                    pcw.setDefaultConfig();
                    ConfigureItem configureItem = new ConfigureItem(pcw, trans, pos);
                    pcw = configureItem.openDlg();
                    configureItem = null;
                }
            } catch (Exception e) {
                Debug.logError(e, module);
                pos.showDialog("dialog/error/producterror");
            }

            // add the item to the cart; report any errors to the user
            if (productId != null) {
                try {
                    if (!aggregatedItem) {
                        trans.addItem(productId, quantity);
                    } else {
                        trans.addItem(productId, pcw);
                    }
                } catch (CartItemModifyException e) {
                    Debug.logError(e, module);
                    pos.showDialog("dialog/error/producterror");
                } catch (ItemNotFoundException e) {
                    pos.showDialog("dialog/error/productnotfound");
                }
            } else {
                pos.showDialog("dialog/error/productnotfound");
            }
        }

        // clear the qty flag
        input.clearFunction("QTY");

        // re-calc tax
        trans.calcTax();

        // refresh the others
View Full Code Here


            pos.getOutput().print("Invalid Selection!");
            pos.getJournal().refresh(pos);
            pos.getInput().clear();
        }

        Input input = pos.getInput();
        String value = input.value();

        boolean increment = true;
        BigDecimal quantity = BigDecimal.ONE;
        if (UtilValidate.isNotEmpty(value)) {
            try {
                quantity = new BigDecimal(value);
            } catch (NumberFormatException e) {
                quantity = BigDecimal.ONE;
            }
        } else {
            String[] func = input.getLastFunction();
            if (func != null && "QTY".equals(func[0])) {
                increment = false;
                try {
                    quantity = new BigDecimal(func[1]);
                } catch (NumberFormatException e) {
                    quantity = trans.getItemQuantity(sku);
                }
            }
        }

        // adjust the quantity
        quantity = (increment ? trans.getItemQuantity(sku).add(quantity) : quantity);

        try {
            trans.modifyQty(sku, quantity);
        } catch (CartItemModifyException e) {
            Debug.logError(e, module);
            pos.showDialog("dialog/error/producterror");
        }

        // clear the qty flag
        input.clearFunction("QTY");

        // re-calc tax
        trans.calcTax();

        // refresh the others
View Full Code Here

    public static synchronized void saleDiscount(PosScreen pos) {
        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        if (!trans.isOpen()) {
            pos.showDialog("dialog/error/terminalclosed");
        } else {
            Input input = pos.getInput();
            String value = input.value();
            if (UtilValidate.isNotEmpty(value)) {
                BigDecimal amount = ZERO;
                boolean percent = false;
                if (value.endsWith("%")) {
                    percent = true;
View Full Code Here

                pos.getOutput().print("Invalid Selection!");
                pos.getJournal().refresh(pos);
                pos.getInput().clear();
            }

            Input input = pos.getInput();
            String value = input.value();
            if (UtilValidate.isNotEmpty(value)) {
                BigDecimal amount = ZERO;
                boolean percent = false;
                if (value.endsWith("%")) {
                    percent = true;
View Full Code Here

        pos.refresh();
    }

    public static synchronized void payCheck(PosScreen pos) {
        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        Input input = pos.getInput();
        String[] ckInfo = input.getFunction("CHECK");

        // check for no/external payment processing
        int paymentCheck = trans.checkPaymentMethodType("PERSONAL_CHECK");
        if (paymentCheck == PosTransaction.NO_PAYMENT) {
            trans.clearPayment("PERSONAL_CHECK");
            processNoPayment(pos, "PERSONAL_CHECK");
            return;
        } else if (paymentCheck == PosTransaction.EXTERNAL_PAYMENT) {
            if (ckInfo == null) {
                input.setFunction("CHECK");
                pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosRefNum",Locale.getDefault()));
                return;
            } else {
                processExternalPayment(pos, "PERSONAL_CHECK", ckInfo[1]);
                return;
View Full Code Here

        pos.showDialog("dialog/error/notyetsupported");
    }

    public static synchronized void payGiftCard(PosScreen pos) {
        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        Input input = pos.getInput();
        String[] gcInfo = input.getFunction("GIFTCARD");

        // check for no/external payment processing
        int paymentCheck = trans.checkPaymentMethodType("GIFT_CARD");
        if (paymentCheck == PosTransaction.NO_PAYMENT) {
            processNoPayment(pos, "GIFT_CARD");
            return;
        } else if (paymentCheck == PosTransaction.EXTERNAL_PAYMENT) {
            if (gcInfo == null) {
                input.setFunction("GIFTCARD");
                pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosRefNum",Locale.getDefault()));
                clearInputPaymentFunctions(pos);
                return;
            } else {
                processExternalPayment(pos, "GIFT_CARD", gcInfo[1]);
View Full Code Here

        clearInputPaymentFunctions(pos);
    }

    public static synchronized void payCredit(PosScreen pos) {
        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        Input input = pos.getInput();
        String[] msrInfo = input.getFunction("MSRINFO");
        String[] crtInfo = input.getFunction("CREDIT");
        String[] track2Info = input.getFunction("TRACK2");
        String[] securityCodeInfo = input.getFunction("SECURITYCODE");
        String[] postalCodeInfo = input.getFunction("POSTALCODE");
        String[] creditExpirationInfo = input.getFunction("CREDITEXP");

        // check for no/external payment processing
        int paymentCheck = trans.checkPaymentMethodType("CREDIT_CARD");
        if (paymentCheck == PosTransaction.NO_PAYMENT) {
            processNoPayment(pos, "CREDIT_CARD");
            return;
        } else if (paymentCheck == PosTransaction.EXTERNAL_PAYMENT) {
            if (crtInfo == null) {
                input.setFunction("CREDIT");
                pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosRefNum",Locale.getDefault()));
                return;
            } else {
                processExternalPayment(pos, "CREDIT_CARD", crtInfo[1]);
                return;
            }
        }

        // now for internal payment processing
        if (crtInfo == null) {
            // set total, if entered
            input.clearLastFunction();
            input.setFunction("TOTAL");
            input.setFunction("CREDIT");
            pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosCredNo",Locale.getDefault()));
        } else {
            Debug.log("Credit Func Info : " + crtInfo[1], module);
            if (msrInfo == null && (creditExpirationInfo == null))  {
                //test credit card
                if (UtilValidate.isNotEmpty(input.value()) && UtilValidate.isCreditCard(input.value())) {
                    input.clearLastFunction();
                    input.setFunction("CREDIT");
                    input.setFunction("CREDITEXP");
                    pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosCredex",Locale.getDefault()));
                } else {
                    Debug.log("Invalid card number - " + input.value(), module);
                    clearInputPaymentFunctions(pos);
                    input.clearInput();
                    pos.showDialog("dialog/error/invalidcardnumber");
                }
            } else if (msrInfo == null && (securityCodeInfo == null) ) {
                // test expiration date
                if (UtilValidate.isNotEmpty(input.value()) && (input.value().length() == 4)) {
                    // ask for Security Code, put in SECURITYCODE
                    input.clearLastFunction();
                    input.setFunction("CREDITEXP");
                    input.setFunction("SECURITYCODE");
                    pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosSecurityCode",Locale.getDefault()));
                } else {
                    Debug.log("Invalid expiration date", module);
                    clearInputPaymentFunctions(pos);
                    input.clearInput();
                    pos.showDialog("dialog/error/invalidexpirationdate");
                }
            } else if (msrInfo == null && (postalCodeInfo == null) ) {
                // test security code - allow blank for illegible cards
                if (UtilValidate.isEmpty(input.value()) ||
                        (UtilValidate.isNotEmpty(input.value()) && (input.value().length() <= 4))) {
                    // ask for Security Code, put in SECURITYCODE
                    input.clearLastFunction();
                    input.setFunction("SECURITYCODE");
                    input.setFunction("POSTALCODE");
                    pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosPostalCode",Locale.getDefault()));
                } else {
                    clearInputPaymentFunctions(pos);
                    input.clearInput();
                    pos.showDialog("dialog/error/invalidsecuritycode");
                }
            } else {
                String msrInfoStr = null;
                if (msrInfo == null) {
                    input.clearLastFunction();
                    input.setFunction("POSTALCODE");
                    postalCodeInfo = input.getFunction("POSTALCODE");
                    if (UtilValidate.isNotEmpty(crtInfo[1])) {
                        if (UtilValidate.isNotEmpty(creditExpirationInfo[1])) {
                            // setup keyed transaction
                            msrInfoStr = crtInfo[1] + "|" + creditExpirationInfo[1];
                        } else {
                            msrInfoStr = crtInfo[1];
                        }
                    }
                } else // is swiped
                    // grab total from input, if available
                    input.setFunction("TOTAL");
                    msrInfoStr = msrInfo[1];
                }
                input.clearFunction("MSRINFO");
                input.setFunction("MSRINFO", msrInfoStr);
                String[] msrInfoArr = msrInfoStr.split("\\|");
                int allInfo = msrInfoArr.length;
                String firstName = null;
                String lastName = null;
                switch (allInfo) {
                    case 4:
                        lastName = msrInfoArr[3];
                    case 3:
                        firstName = msrInfoArr[2];
                    case 2: // card number & exp date found
                        BigDecimal amount = BigDecimal.ZERO;
                        try {
                            String[] totalInfo = input.getFunction("TOTAL");
                            amount = processAmount(trans, pos, totalInfo[1]);
                            Debug.log("Processing Credit Card Amount : " + amount, module);
                        } catch (GeneralException e) {
                            Debug.logError("Exception caught calling processAmount.", module);
                            Debug.logError(e.getMessage(), module);
                        }

                        String cardNumber = msrInfoArr[0];
                        String expDate = msrInfoArr[1];
                        String pmId = trans.makeCreditCardVo(cardNumber, expDate, firstName, lastName);
                        if (pmId != null) {
                            trans.addPayment(pmId, amount);
                        }
                        if (track2Info != null && UtilValidate.isNotEmpty(track2Info[1])) {
                            // if swiped
                            trans.setPaymentTrack2(pmId, null, track2Info[1]);
                        } else { //keyed
                            if (securityCodeInfo != null && UtilValidate.isNotEmpty(securityCodeInfo[1])) {
                                trans.setPaymentSecurityCode(pmId, null, securityCodeInfo[1]);
                            }
                            if (postalCodeInfo != null && UtilValidate.isNotEmpty(postalCodeInfo[1])) {
                                trans.setPaymentPostalCode(pmId, null, postalCodeInfo[1]);
                            }
                        }
                        clearInputPaymentFunctions(pos);
                        pos.refresh();
                        break;
                    case 1: // card number only found
                        pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosCredex",Locale.getDefault()));
                        break;
                    default:
                        Debug.log("Hit the default switch case [" + allInfo + "] refreshing.", module);
                        input.clearFunction("MSRINFO");
                        pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosCredNo",Locale.getDefault()));
                        break;
                }
            }
        }
View Full Code Here

            pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosInvalidSelection",Locale.getDefault()));
            pos.getJournal().refresh(pos);
            pos.getInput().clear();
        }

        Input input = pos.getInput();
        String value = input.value();
        if (UtilValidate.isNotEmpty(value)) {
            BigDecimal price = ZERO;
            boolean parsed = false;
            try {
                price = new BigDecimal(value);
View Full Code Here

            pos.showDialog("dialog/error/mgrnotloggedin");
            return;
        }

        PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
        Input input = pos.getInput();
        if (!trans.isOpen()) {
            if (input.isFunctionSet("OPEN")) {
                BigDecimal amt = ZERO;
                String amountStr = input.value();
                if (UtilValidate.isNotEmpty(amountStr)) {
                    try {
                        amt = new BigDecimal(amountStr);
                        amt = amt.movePointLeft(2);
                    } catch (NumberFormatException e)
                    {
                        Debug.logError(e, module);
                    }
                }
                GenericValue state = pos.getSession().getDelegator().makeValue("PosTerminalState");
                state.set("posTerminalId", pos.getSession().getId());
                state.set("openedDate", UtilDateTime.nowTimestamp());
                state.set("openedByUserLoginId", pos.getSession().getUserId());
                state.set("startingTxId", trans.getTransactionId());
                state.set("startingDrawerAmount", amt);
                try {
                    state.create();
                } catch (GenericEntityException e) {
                    Debug.logError(e, module);
                    pos.showDialog("dialog/error/exception", e.getMessage());
                }
                NavagationEvents.showPosScreen(pos);
            } else {
                input.clear();
                input.setFunction("OPEN");
                pos.getOutput().print(UtilProperties.getMessage(PosTransaction.resource,"PosOpDrAm",Locale.getDefault()));
                return;
            }
        } else {
            pos.showPage("pospanel");
View Full Code Here

            pos.showDialog("dialog/error/terminalclosed");
            return;
        }

        Output output = pos.getOutput();
        Input input = pos.getInput();
        if (input.isFunctionSet("CLOSE")) {
            String[] func = input.getFunction("CLOSE");
            String lastValue = input.value();
            if (UtilValidate.isNotEmpty(lastValue)) {

                try {
                    BigDecimal amt = new BigDecimal(lastValue);
                    amt = amt.movePointLeft(2);
                    lastValue = amt.toString();
                } catch (NumberFormatException e) {
                    Debug.logError(e, module);
                }
                if (UtilValidate.isNotEmpty(func[1])) {
                    func[1] = func[1] + "|";
                }
                func[1] = func[1] + lastValue;
                input.setFunction("CLOSE", func[1]);
            }

            String[] closeInfo = new String[0];
            if (UtilValidate.isNotEmpty(func[1])) {
                closeInfo = func[1].split("\\|");
            }
            switch (closeInfo.length) {
                case 0:
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCas",Locale.getDefault()));
                    break;
                case 1:
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntChk",Locale.getDefault()));
                    break;
                case 2:
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCrc",Locale.getDefault()));
                    break;
                case 3:
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntGfc",Locale.getDefault()));
                    break;
                case 4:
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntOth",Locale.getDefault()));
                    break;
                case 5:
                    GenericValue state = trans.getTerminalState();
                    state.set("closedDate", UtilDateTime.nowTimestamp());
                    state.set("closedByUserLoginId", pos.getSession().getUserId());
                    state.set("actualEndingCash", new BigDecimal(closeInfo[0]));
                    state.set("actualEndingCheck", new BigDecimal(closeInfo[1]));
                    state.set("actualEndingCc", new BigDecimal(closeInfo[2]));
                    state.set("actualEndingGc", new BigDecimal(closeInfo[3]));
                    state.set("actualEndingOther", new BigDecimal(closeInfo[4]));
                    state.set("endingTxId", trans.getTransactionId());
                    Debug.log("Updated State - " + state, module);
                    try {
                        state.store();
                        state.refresh();
                    } catch (GenericEntityException e) {
                        Debug.logError(e, module);
                        pos.showDialog("dialog/error/exception", e.getMessage());
                    }

                    // print the totals report
                    output.print(UtilProperties.getMessage(PosTransaction.resource,"PosWaitingFinalSales",Locale.getDefault()));
                    //pos.showDialog("dialog/error/terminalclosed"); JLR 14/11/06 : Pb with that don't know why, useless => commented out
                    printTotals(pos, state, true);

                    // lock the terminal for the moment
                    pos.getInput().setLock(true);
                    pos.getButtons().setLock(true);
                    pos.refresh(false);

                    // transmit final data to server
                    GenericValue terminal = null;
                    try {
                        terminal = state.getRelatedOne("PosTerminal");
                    } catch (GenericEntityException e) {
                        Debug.logError(e, module);
                        pos.showDialog("dialog/error/exception", e.getMessage());
                    }
                    if (terminal != null && terminal.get("pushEntitySyncId") != null) {
                        String syncId = terminal.getString("pushEntitySyncId");
                        SyncCallbackAdaptor cb = new SyncCallbackAdaptor(pos, syncId, state.getTimestamp("lastUpdatedTxStamp"));
                        pos.getSession().getDispatcher().registerCallback("runEntitySync", cb);
                    } else {
                        // no sync setting; just logout
                        SecurityEvents.logout(pos);
                    }
                    // unlock the terminal
                    pos.getInput().setLock(false);
                    pos.getButtons().setLock(false);
                    pos.refresh(true);

            }
        } else {
            trans.popDrawer();
            input.clear();
            input.setFunction("CLOSE");
            output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCas",Locale.getDefault()));
        }
    }
View Full Code Here

TOP

Related Classes of org.ofbiz.pos.component.Input

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.