Search in sources :

Example 1 with CommandReceiver

use of org.adempiere.pos.command.CommandReceiver in project adempiere by adempiere.

the class POSActionMenu method executeCommand.

private void executeCommand(Command command) {
    Waiting waiting = new Waiting(pos.getFrame(), Msg.parseTranslation(pos.getCtx(), "@Processing@"), false, 120);
    try {
        CommandReceiver receiver = commandManager.getCommandReceivers(command.getEvent());
        if (command.getCommand() == CommandManager.GENERATE_IMMEDIATE_INVOICE && pos.getC_Order_ID() > 0 && pos.isCompleted() && !pos.isVoided()) {
            receiver.setCtx(pos.getCtx());
            receiver.setPartnerId(queryPartner.getRecord_ID());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            MBPartner partner = MBPartner.get(pos.getCtx(), receiver.getPartnerId());
            Optional<String> taxId = Optional.ofNullable(partner.getTaxID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + partner.getName() + " @TaxID@ : " + taxId.orElse("");
            if (ADialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                AEnv.showCenterScreen(waiting);
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.setVisible(false);
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    if (processInfo != null)
                        pos.setOrder(processInfo.getRecord_ID());
                    pos.refreshHeader();
                    //	Print Ticket
                    pos.printTicket();
                }
            }
        } else //Reverse The Sales Transaction
        if (command.getCommand() == CommandManager.GENERATE_REVERSE_SALES && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && !pos.isVoided() && !pos.isClosed()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @order.no@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (ADialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                AEnv.showCenterScreen(waiting);
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.setVisible(false);
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                }
                pos.printTicket();
            }
        } else //Return product
        if (command.getCommand() == CommandManager.GENERATE_RETURN && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && pos.isCompleted()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (ADialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                AEnv.showCenterScreen(waiting);
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.setVisible(false);
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    //execute out transaction
                    if (processInfo != null && processInfo.getRecord_ID() > 0) {
                        pos.setOrder(processInfo.getRecord_ID());
                        pos.refreshHeader();
                    }
                }
            }
        } else if (command.getCommand() == CommandManager.GENERATE_WITHDRAWAL) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            Dimension size = new Dimension(1024, 768);
            FormFrame ff = new FormFrame(pos.getWindowNo());
            ff.setSize(size);
            MBrowse browse = new MBrowse(Env.getCtx(), 50056, null);
            new VBrowser(ff, true, pos.getWindowNo(), "", browse, "", true, "", true);
            ff.pack();
            AEnv.showCenterScreen(ff);
        } else if (command.getCommand() == CommandManager.CLOSE_STATEMENT) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            Dimension size = new Dimension(1024, 768);
            FormFrame ff = new FormFrame(pos.getWindowNo());
            ff.setSize(size);
            MBrowse browse = new MBrowse(Env.getCtx(), 50057, null);
            new VBrowser(ff, true, pos.getWindowNo(), "", browse, "", true, "", true);
            ff.pack();
            AEnv.showCenterScreen(ff);
        }
    } catch (Exception exception) {
        waiting.setVisible(false);
        ADialog.error(pos.getWindowNo(), pos.getFrame(), exception.getLocalizedMessage());
    } finally {
        waiting.setVisible(false);
        waiting = null;
    }
}
Also used : CommandReceiver(org.adempiere.pos.command.CommandReceiver) FormFrame(org.compiere.apps.form.FormFrame) MBPartner(org.compiere.model.MBPartner) ProcessInfo(org.compiere.process.ProcessInfo) Dimension(java.awt.Dimension) MBrowse(org.adempiere.model.MBrowse) VBrowser(org.eevolution.form.VBrowser) AdempiereException(org.adempiere.exceptions.AdempiereException) Waiting(org.compiere.apps.Waiting)

Example 2 with CommandReceiver

use of org.adempiere.pos.command.CommandReceiver in project adempiere by adempiere.

the class WPOSActionMenu method executeCommand.

private void executeCommand(Command command) {
    BusyDialog waiting = new BusyDialog();
    try {
        CommandReceiver receiver = commandManager.getCommandReceivers(command.getEvent());
        if (command.getCommand() == CommandManager.GENERATE_IMMEDIATE_INVOICE && pos.getC_Order_ID() > 0 && pos.isCompleted() && !pos.isVoided()) {
            receiver.setCtx(pos.getCtx());
            receiver.setPartnerId(queryPartner.getRecord_ID());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            MBPartner partner = MBPartner.get(pos.getCtx(), receiver.getPartnerId());
            Optional<String> taxId = Optional.ofNullable(partner.getTaxID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + partner.getName() + " @TaxID@ : " + taxId.orElse("");
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    if (processInfo != null)
                        pos.setOrder(processInfo.getRecord_ID());
                    pos.refreshHeader();
                    //	Print Ticket
                    pos.printTicket();
                }
            }
        } else //Reverse The Sales Transaction
        if (command.getCommand() == CommandManager.GENERATE_REVERSE_SALES && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && !pos.isVoided() && !pos.isClosed()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @order.no@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                }
                pos.printTicket();
            }
        } else //Return product
        if (command.getCommand() == CommandManager.GENERATE_RETURN && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && pos.isCompleted()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    //execute out transaction
                    if (processInfo != null && processInfo.getRecord_ID() > 0) {
                        pos.setOrder(processInfo.getRecord_ID());
                        pos.refreshHeader();
                    }
                }
            }
        } else if (command.getCommand() == CommandManager.GENERATE_WITHDRAWAL) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            MBrowse browse = new MBrowse(Env.getCtx(), 50056, null);
            WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
            CustomForm ff = browser.getForm();
            ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
            ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
            ff.setTitle(browse.getTitle());
            SessionManager.getAppDesktop().showWindow(ff);
        } else if (command.getCommand() == CommandManager.CLOSE_STATEMENT) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            MBrowse browse = new MBrowse(Env.getCtx(), 50057, null);
            WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
            CustomForm ff = browser.getForm();
            ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
            ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
            ff.setTitle(browse.getTitle());
            SessionManager.getAppDesktop().showWindow(ff);
        }
    } catch (Exception exception) {
        waiting.dispose();
        FDialog.error(pos.getWindowNo(), pos.getForm(), exception.getLocalizedMessage());
    } finally {
        waiting.dispose();
        waiting = null;
    }
}
Also used : CustomForm(org.adempiere.webui.panel.CustomForm) CommandReceiver(org.adempiere.pos.command.CommandReceiver) MBPartner(org.compiere.model.MBPartner) ProcessInfo(org.compiere.process.ProcessInfo) BusyDialog(org.adempiere.webui.apps.BusyDialog) MBrowse(org.adempiere.model.MBrowse) AdempiereException(org.adempiere.exceptions.AdempiereException) WBrowser(org.eevolution.form.WBrowser)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)2 MBrowse (org.adempiere.model.MBrowse)2 CommandReceiver (org.adempiere.pos.command.CommandReceiver)2 MBPartner (org.compiere.model.MBPartner)2 ProcessInfo (org.compiere.process.ProcessInfo)2 Dimension (java.awt.Dimension)1 BusyDialog (org.adempiere.webui.apps.BusyDialog)1 CustomForm (org.adempiere.webui.panel.CustomForm)1 Waiting (org.compiere.apps.Waiting)1 FormFrame (org.compiere.apps.form.FormFrame)1 VBrowser (org.eevolution.form.VBrowser)1 WBrowser (org.eevolution.form.WBrowser)1