From 1fcbd5ea079d041c3eb812549998d60d530ffd94 Mon Sep 17 00:00:00 2001 From: hengsin Date: Thu, 4 Aug 2022 18:42:53 +0800 Subject: [PATCH] IDEMPIERE-5358 Refactor CreateFrom (#1413) * IDEMPIERE-5358 Refactor CreateFrom * IDEMPIERE-5358 Refactor CreateFrom - Fix java doc * IDEMPIERE-5358 Refactor CreateFrom - Fix SQL error for Oracle (SELECT without FROM only works for PostgreSQL). * IDEMPIERE-5358 Refactor CreateFrom - revert change of protected method name. --- .../src/org/compiere/model/GridTable.java | 71 ++- .../src/org/compiere/model/SystemIDs.java | 9 +- .../apps/form/WCreateFromDepositBatchUI.java | 34 +- .../webui/apps/form/WCreateFromForm.java | 43 +- .../webui/apps/form/WCreateFromInvoiceUI.java | 57 ++- .../form/WCreateFromPackageShipmentUI.java | 17 +- .../webui/apps/form/WCreateFromRMAUI.java | 34 +- .../apps/form/WCreateFromShipmentUI.java | 77 ++- .../apps/form/WCreateFromStatementUI.java | 34 +- .../webui/apps/form/WCreateFromWindow.java | 49 ++ .../apps/form/WStatementCreateFromBatch.java | 37 +- .../adempiere/webui/editor/WNumberEditor.java | 2 +- .../compiere/apps/form/CreateFromForm.java | 33 +- .../apps/form/StatementCreateFromBatch.java | 143 ++++-- .../src/org/compiere/grid/CreateFrom.java | 103 +++- .../org/compiere/grid/CreateFromBatch.java | 150 ++++-- .../compiere/grid/CreateFromDepositBatch.java | 35 +- .../org/compiere/grid/CreateFromInvoice.java | 92 ++-- .../grid/CreateFromPackageShipment.java | 48 +- .../src/org/compiere/grid/CreateFromRMA.java | 44 +- .../org/compiere/grid/CreateFromShipment.java | 117 ++--- .../compiere/grid/CreateFromStatement.java | 31 +- .../src/org/compiere/grid/ICreateFrom.java | 19 + .../org/compiere/grid/ICreateFromFactory.java | 5 + .../src/org/idempiere/test/DictionaryIDs.java | 12 + .../form/CreateFromDepositBatchFormTest.java | 180 +++++++ .../test/form/CreateFromInvoiceFormTest.java | 333 +++++++++++++ .../CreateFromPackageShipmentFormTest.java | 231 +++++++++ .../test/form/CreateFromRMAFormTest.java | 202 ++++++++ .../test/form/CreateFromShipmentFormTest.java | 446 ++++++++++++++++++ .../form/CreateFromStatementFormTest.java | 180 +++++++ 31 files changed, 2493 insertions(+), 375 deletions(-) create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromDepositBatchFormTest.java create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromInvoiceFormTest.java create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromPackageShipmentFormTest.java create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromRMAFormTest.java create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromShipmentFormTest.java create mode 100644 org.idempiere.test/src/org/idempiere/test/form/CreateFromStatementFormTest.java diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index 216daf9a48..28274c39e4 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -589,7 +589,7 @@ public class GridTable extends AbstractTableModel /** * Get all Fields - * @return GridFields + * @return GridField[] */ public GridField[] getFields () { @@ -599,8 +599,8 @@ public class GridTable extends AbstractTableModel } // getField /************************************************************************** - * Open Database. - * if already opened, data is refreshed + * Open connection to db and load data from table. + * If already opened, data is refreshed * @param maxRows maximum number of rows or 0 for all * @return true if success */ @@ -710,7 +710,7 @@ public class GridTable extends AbstractTableModel /** * Is Loading - * @return true if loading + * @return true if loading is in progress */ public boolean isLoading() { @@ -1084,7 +1084,7 @@ public class GridTable extends AbstractTableModel /************************************************************************** - * Get Value in Resultset + * Get Value at row and column * @param row row * @param col col * @return Object of that row/column @@ -1114,6 +1114,10 @@ public class GridTable extends AbstractTableModel return rowData[col]; } // getValueAt + /** + * wait for loading of row + * @param row + */ public void waitLoadingForRow(int row) { // need to wait for data read into buffer int loops = 0; @@ -2887,7 +2891,7 @@ public class GridTable extends AbstractTableModel /************************************************************************** - * Ignore changes + * Ignore/Undo changes */ public void dataIgnore() { @@ -3127,6 +3131,13 @@ public class GridTable extends AbstractTableModel return true; } // dataRequery + /** + * + * @param whereClause + * @param onlyCurrentRows + * @param onlyCurrentDays + * @return true if success + */ public boolean dataRequery (String whereClause, boolean onlyCurrentRows, int onlyCurrentDays) { return dataRequery (whereClause, onlyCurrentRows, onlyCurrentDays, true); @@ -3562,6 +3573,10 @@ public class GridTable extends AbstractTableModel .append(",Tab=").append(m_TabNo).append("]").toString(); } // toString + /** + * + * @return new row added + */ public int getNewRow() { return m_newRow; @@ -3612,7 +3627,7 @@ public class GridTable extends AbstractTableModel ResultSet rs = null; try { - pstmt = DB.prepareStatement(m_SQL_Count, null); + pstmt = DB.prepareStatement(m_SQL_Count, get_TrxName()); setParameter (pstmt, true); int timeout = MSysConfig.getIntValue(MSysConfig.GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS, DEFAULT_GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS, Env.getAD_Client_ID(Env.getCtx())); if (timeout > 0) @@ -3646,12 +3661,15 @@ public class GridTable extends AbstractTableModel } // open private void openResultSet() { + String trxName = get_TrxName(); //postgresql need trx to use cursor based resultset //https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor - String trxName = m_virtual ? Trx.createTrxName("Loader") : null; - trx = trxName != null ? Trx.get(trxName, true) : null; - if (trx != null) - trx.setDisplayName(getClass().getName()+"_openResultSet"); + if (trxName == null) { + trxName = m_virtual ? Trx.createTrxName("Loader") : null; + trx = trxName != null ? Trx.get(trxName, true) : null; + if (trx != null) + trx.setDisplayName(getClass().getName()+"_openResultSet"); + } // open Statement (closed by Loader.close) try { @@ -3685,7 +3703,10 @@ public class GridTable extends AbstractTableModel m_rs = null; m_pstmt = null; if (trx != null) + { trx.close(); + trx = null; + } } // close /** @@ -3848,7 +3869,11 @@ public class GridTable extends AbstractTableModel } } // setFieldVFormat - // verify if the current record has changed + /** + * verify if the record at row has changed + * @param row + * @return true if has changes + */ public boolean hasChanged(int row) { // not so aggressive (it can has still concurrency problems) // compare Updated, IsProcessed @@ -4063,6 +4088,11 @@ public class GridTable extends AbstractTableModel return bChanged; } + /** + * Load PO for row + * @param row + * @return PO + */ public PO getPO(int row) { MTable table = MTable.get (m_ctx, m_AD_Table_ID); PO po = null; @@ -4074,15 +4104,28 @@ public class GridTable extends AbstractTableModel return po; } + /** + * + * @param importing import mode + * @param trxName optional trx name + */ public void setImportingMode(boolean importing, String trxName) { m_importing = importing; m_trxName = trxName; } + /** + * + * @return true if it is in import mode + */ public boolean isImporting() { return m_importing; } + /** + * + * @return trx name + */ public String get_TrxName() { return m_trxName; } @@ -4095,6 +4138,10 @@ public class GridTable extends AbstractTableModel m_lastSortedAscending = true; } + /** + * + * @return index of primary key column + */ public int getKeyColumnIndex() { return m_indexKeyColumn; } diff --git a/org.adempiere.base/src/org/compiere/model/SystemIDs.java b/org.adempiere.base/src/org/compiere/model/SystemIDs.java index b0301875e0..93c70848b6 100644 --- a/org.adempiere.base/src/org/compiere/model/SystemIDs.java +++ b/org.adempiere.base/src/org/compiere/model/SystemIDs.java @@ -196,25 +196,32 @@ public class SystemIDs public final static int WINDOW_ACCOUNTCOMBINATION = 153; public final static int WINDOW_ATTRIBUTESETINSTANCE = 358; + public final static int WINDOW_BANK_STATEMENT = 194; public final static int WINDOW_BUSINESS_PARTNER = 123; public static final int WINDOW_CHART = 53124; public final static int WINDOW_CUSTOMERRETURN = 53097; + public final static int WINDOW_CUSTOMER_RMA = 320; public final static int WINDOW_IMAGE = 227; public final static int WINDOW_INVOICE_CUSTOMER = 167; + public final static int WINDOW_INVOICE_VENDOR = 183; public final static int WINDOW_LOCATION = 121; public final static int WINDOW_LOCATOR = 139; public final static int WINDOW_LOT = 257; + public final static int WINDOW_MATERIAL_RECEIPT = 184; public final static int WINDOW_MATERIALTRANSACTIONS_INDIRECTUSER = 223; public final static int WINDOW_MY_REQUESTS = 237; public final static int WINDOW_NOTICE = 193; + public final static int WINDOW_PAYMENTS_INTO_BATCH = 200031; public final static int WINDOW_REQUEST = 201; public final static int WINDOW_REQUESTS_ALL = 232; public final static int WINDOW_RESOURCE = 236; public final static int WINDOW_RETURNTOVENDOR = 53098; public final static int WINDOW_SALES_ORDER = 143; + public final static int WINDOW_SHIPMENT_CUSTOMER = 169; + public final static int WINDOW_VENDOR_RMA = 53099; public final static int WINDOW_WAREHOUSE_LOCATOR = 139; public final static int WINDOW_WINDOW_TAB_FIELD = 102; - public final static int WINDOW_WORKFLOW_ACTIVITIES = 298; + public final static int WINDOW_WORKFLOW_ACTIVITIES = 298; public final static int TAB_TAB = 106; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromDepositBatchUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromDepositBatchUI.java index ffd00ef16c..e3fe15be8a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromDepositBatchUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromDepositBatchUI.java @@ -67,10 +67,14 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements { private WCreateFromWindow window; + /** + * + * @param tab + */ public WCreateFromDepositBatchUI(GridTab tab) { super(tab); - log.info(getGridTab().toString()); + if (log.isLoggable(Level.INFO)) log.info(getGridTab().toString()); window = new WCreateFromWindow(this, getGridTab().getWindowNo()); @@ -125,14 +129,10 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements protected Label dateToLabel = new Label("-"); protected WDateEditor dateToField = new WDateEditor("DateTo", false, false, true, Msg.translate(Env.getCtx(), "DateTo")); - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); super.dynInit(); @@ -157,17 +157,14 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements bankAccountField.setValue(Integer.valueOf(C_BankAccount_ID)); // initial Loading authorizationField = new WStringEditor ("authorization", false, false, true, 10, 30, null, null); -// authorizationField.getComponent().addEventListener(Events.ON_CHANGE, this); lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir); documentTypeField = new WTableDirEditor (MPayment.COLUMNNAME_C_DocType_ID,false,false,true,lookup); int C_DocType_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_DocType_ID"); documentTypeField.setValue(Integer.valueOf(C_DocType_ID)); -// documentTypeField.getComponent().addEventListener(Events.ON_CHANGE, this); lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List); tenderTypeField = new WTableDirEditor (MPayment.COLUMNNAME_TenderType,false,false,true,lookup); -// tenderTypeField.getComponent().addEventListener(Events.ON_CHANGE, this); lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search); bPartnerLookup = new WSearchEditor ("C_BPartner_ID", false, false, true, lookup); @@ -269,7 +266,7 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements /** * Action Listener * @param e event - * @throws Exception + * @throws Exception */ public void onEvent(Event e) throws Exception { @@ -281,14 +278,21 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements } } + /** + * load payments for selected bank account + */ protected void loadBankAccount() { - loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), + loadTableOIS(getBankAccountData((Integer)bankAccountField.getValue(), (Integer)bPartnerLookup.getValue(), documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString())); + (Integer)documentTypeField.getValue(), (String)tenderTypeField.getValue(), authorizationField.getValue().toString())); } + /** + * load data into list box + * @param data + */ protected void loadTableOIS (Vector data) { window.getWListbox().clear(); @@ -304,11 +308,13 @@ public class WCreateFromDepositBatchUI extends CreateFromDepositBatch implements configureMiniTable(window.getWListbox()); } + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java index d0612839a5..d80554c373 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromForm.java @@ -68,6 +68,10 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa public static final String SELECT_ALL = "SelectAll"; + /** + * + * @param createFrom + */ public WCreateFromForm(CreateFromForm createFrom) { super(); @@ -78,7 +82,8 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa setBorder("normal"); setSclass("create-from-form"); } - + + @Override protected void initForm() { try @@ -91,7 +96,7 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa } catch(Exception e) { - + e.printStackTrace(); } } @@ -144,6 +149,7 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa ZKUpdateUtil.setHeight(contentPane, "100%"); } + @Override public void onEvent(Event e) throws Exception { // OK - Save @@ -191,6 +197,7 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa } } + @Override public void tableChanged (WTableModelEvent e) { int type = -1; @@ -203,6 +210,11 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa info(); } + /** + * + * @param trxName + * @return true if save success + */ public boolean save(String trxName) { ListModelTable model = dataTable.getModel(); @@ -213,6 +225,9 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa return form.save(dataTable, trxName, getGridTab()); } + /** + * update status bar + */ public void info() { ListModelTable model = dataTable.getModel(); @@ -228,6 +243,11 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa form.info(dataTable, statusBar); } + /** + * set status bar text + * @param selectedRowCount + * @param text + */ public void setStatusLine(int selectedRowCount, String text) { StringBuilder sb = new StringBuilder(String.valueOf(selectedRowCount)); @@ -239,26 +259,45 @@ public class WCreateFromForm extends ADForm implements EventListener, WTa confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); } + /** + * + * @return {@link WListbox} + */ public WListbox getWListbox() { return dataTable; } + /** + * + * @return {@link Panel} + */ public Panel getParameterPanel() { return parameterPanel; } + /** + * + * @return {@link ConfirmPanel} + */ public ConfirmPanel getConfirmPanel() { return confirmPanel; } + /** + * + * @return true if cancel by user + */ public boolean isCancel() { return isCancel; } + /** + * post execute query event + */ public void postQueryEvent() { Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing")); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java index 302cd32c57..906b44db9a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java @@ -55,10 +55,19 @@ import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zul.Space; +/** + * + * @author hengsin + * + */ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventListener, ValueChangeListener { private WCreateFromWindow window; + /** + * + * @param tab + */ public WCreateFromInvoiceUI(GridTab tab) { super(tab); @@ -107,14 +116,10 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList private boolean isCreditMemo = false; - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ + @Override public boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); super.dynInit(); @@ -220,11 +225,7 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList private int noOfParameterColumn; - /** - * Action Listener - * @param e event - * @throws Exception - */ + @Override public void onEvent(Event e) throws Exception { if (m_actionActive) @@ -270,10 +271,7 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList m_actionActive = false; } - /** - * Change Listener - * @param e event - */ + @Override public void valueChange (ValueChangeEvent e) { if (log.isLoggable(Level.CONFIG)) log.config(e.getPropertyName() + "=" + e.getNewValue()); @@ -308,7 +306,7 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList } // initBPartner /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner dependent Order/Shipment/RMA Field. * @param C_BPartner_ID BPartner * @param forInvoice for invoice */ @@ -331,14 +329,14 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList initBPDetails(C_BPartner_ID); } // initBPartnerOIS - public void initBPDetails(int C_BPartner_ID) + private void initBPDetails(int C_BPartner_ID) { initBPShipmentDetails(C_BPartner_ID); initBPRMADetails(C_BPartner_ID); } /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load PBartner dependent Shipment Field. * @param C_BPartner_ID */ private void initBPShipmentDetails(int C_BPartner_ID) @@ -361,7 +359,7 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList } /** - * Load RMA that are candidates for shipment + * Load RMA that are candidates for billing * @param C_BPartner_ID BPartner */ private void initBPRMADetails(int C_BPartner_ID) @@ -381,7 +379,7 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList } /** - * Load Data - Order + * Load Order Line records * @param C_Order_ID Order * @param forInvoice true if for invoice vs. delivery qty */ @@ -390,18 +388,26 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList loadTableOIS(getOrderData(C_Order_ID, forInvoice, isCreditMemo)); } // LoadOrder + /** + * load RMA Line records + * @param M_RMA_ID + */ protected void loadRMA (int M_RMA_ID) { loadTableOIS(getRMAData(M_RMA_ID)); } + /** + * load shipment line records + * @param M_InOut_ID + */ protected void loadShipment (int M_InOut_ID) { loadTableOIS(getShipmentData(M_InOut_ID)); } /** - * Load Order/Invoice/Shipment data into Table + * Load datas into list box * @param data data */ protected void loadTableOIS (Vector data) @@ -419,11 +425,13 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList configureMiniTable(window.getWListbox()); } // loadOrder + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); @@ -434,6 +442,10 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList return window; } + /** + * configure layout of parameter grid + * @param parameterGrid + */ protected void setupColumns(Grid parameterGrid) { noOfParameterColumn = ClientInfo.maxWidth((ClientInfo.EXTRA_SMALL_WIDTH+ClientInfo.SMALL_WIDTH)/2) ? 2 : 4; Columns columns = new Columns(); @@ -464,6 +476,9 @@ public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventList } } + /** + * handle onClientInfo event + */ protected void onClientInfo() { if (ClientInfo.isMobile() && parameterStdLayout != null && parameterStdLayout.getRows() != null) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromPackageShipmentUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromPackageShipmentUI.java index f83c517659..1a2e09d52f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromPackageShipmentUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromPackageShipmentUI.java @@ -34,10 +34,14 @@ public class WCreateFromPackageShipmentUI extends CreateFromPackageShipment { private WCreateFromWindow window; + /** + * + * @param mTab + */ public WCreateFromPackageShipmentUI(GridTab mTab) { super(mTab); - log.info(mTab.toString()); + if (log.isLoggable(Level.INFO)) log.info(mTab.toString()); window = new WCreateFromWindow(this, getGridTab().getWindowNo()); @@ -58,9 +62,10 @@ public class WCreateFromPackageShipmentUI extends CreateFromPackageShipment /** Logger */ private static final CLogger log = CLogger.getCLogger(WCreateFromPackageShipmentUI.class); - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); super.dynInit(); @@ -74,6 +79,10 @@ public class WCreateFromPackageShipmentUI extends CreateFromPackageShipment return true; } + /** + * load data into list box + * @param data + */ protected void loadTableOIS (Vector data) { window.getWListbox().clear(); @@ -89,11 +98,13 @@ public class WCreateFromPackageShipmentUI extends CreateFromPackageShipment configureMiniTable(window.getWListbox()); } + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java index 53cda1e60f..ab45208538 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java @@ -42,14 +42,23 @@ import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; +/** + * + * @author hengsin + * + */ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListener { private WCreateFromWindow window; + /** + * + * @param tab + */ public WCreateFromRMAUI(GridTab tab) { super(tab); - log.info(getGridTab().toString()); + if (log.isLoggable(Level.INFO)) log.info(getGridTab().toString()); window = new WCreateFromWindow(this, getGridTab().getWindowNo()); @@ -79,12 +88,8 @@ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListen protected Label bPartnerLabel = new Label(); protected WEditor bPartnerField; - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { log.config(""); @@ -124,10 +129,7 @@ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListen } } - /** - * Change Listener - * @param e event - */ + @Override public void valueChange (ValueChangeEvent e) { if (log.isLoggable(Level.CONFIG)) log.config(e.getPropertyName() + "=" + e.getNewValue()); @@ -156,13 +158,16 @@ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListen bPartnerField.setValue(Integer.valueOf(C_BPartner_ID)); } // initBPartner + /** + * load RMA lines + */ protected void loadRMA() { loadTableOIS(getRMAData()); } /** - * Load Order/Invoice/Shipment data into Table + * Load data into list box * @param data data */ protected void loadTableOIS (Vector data) @@ -180,11 +185,13 @@ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListen configureMiniTable(window.getWListbox()); } // loadOrder + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); @@ -195,6 +202,9 @@ public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListen return window; } + /** + * handle onClientInfo event + */ protected void onClientInfo() { ZKUpdateUtil.setCSSHeight(window); ZKUpdateUtil.setCSSWidth(window); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java index 50212e6455..865889250b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java @@ -63,15 +63,24 @@ import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Space; import org.zkoss.zul.Vlayout; +/** + * + * @author hengsin + * + */ public class WCreateFromShipmentUI extends CreateFromShipment implements EventListener, ValueChangeListener { private WCreateFromWindow window; + /** + * + * @param tab + */ public WCreateFromShipmentUI(GridTab tab) { super(tab); - log.info(getGridTab().toString()); + if (log.isLoggable(Level.INFO)) log.info(getGridTab().toString()); window = new WCreateFromWindow(this, getGridTab().getWindowNo()); @@ -122,14 +131,10 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi private int noOfParameterColumn; - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); super.dynInit(); @@ -222,11 +227,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi private boolean m_actionActive = false; - /** - * Action Listener - * @param e event - * @throws Exception - */ + @Override public void onEvent(Event e) throws Exception { if (m_actionActive) @@ -333,10 +334,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi return(-1); } - /** - * Change Listener - * @param e event - */ + @Override public void valueChange (ValueChangeEvent e) { if (log.isLoggable(Level.CONFIG)) log.config(e.getPropertyName() + "=" + e.getNewValue()); @@ -398,7 +396,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner dependent Order Field. * @param C_BPartner_ID BPartner * @param forInvoice for invoice */ @@ -431,7 +429,11 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi initBPDetails(C_BPartner_ID); } // initBPOrderDetails - public void initBPDetails(int C_BPartner_ID) + /** + * load bpartner related details + * @param C_BPartner_ID + */ + protected void initBPDetails(int C_BPartner_ID) { initBPInvoiceDetails(C_BPartner_ID); initBPRMADetails(C_BPartner_ID); @@ -459,27 +461,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } /** - * Load Data - Order - * @param C_Order_ID Order - * @param forInvoice true if for invoice vs. delivery qty - */ -/* protected void loadOrder (int C_Order_ID, boolean forInvoice) - { - loadTableOIS(getOrderData(C_Order_ID, forInvoice)); - } // LoadOrder - - protected void loadRMA (int M_RMA_ID) - { - loadTableOIS(getRMAData(M_RMA_ID)); - } - - protected void loadShipment (int M_InOut_ID) - { - loadTableOIS(getShipmentData(M_InOut_ID)); - }*/ - - /** - * Load Data - Order + * Load Order lines * @param C_Order_ID Order * @param forInvoice true if for invoice vs. delivery qty * @param M_Locator_ID @@ -490,7 +472,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } // LoadOrder /** - * Load Data - RMA + * Load RMA lines * @param M_RMA_ID RMA * @param M_Locator_ID */ @@ -500,7 +482,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } /** - * Load Data - Invoice + * Load Invoice Lines * @param C_Invoice_ID Invoice * @param M_Locator_ID */ @@ -510,7 +492,7 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } /** - * Load Order/Invoice/Shipment data into Table + * Load data into list box * @param data data */ protected void loadTableOIS (Vector data) @@ -528,11 +510,13 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi configureMiniTable(window.getWListbox()); } // loadOrder + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); @@ -543,6 +527,10 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi return window; } + /** + * Configure layout of parameter grid + * @param parameterGrid + */ protected void setupColumns(Grid parameterGrid) { noOfParameterColumn = ClientInfo.maxWidth((ClientInfo.EXTRA_SMALL_WIDTH+ClientInfo.SMALL_WIDTH)/2) ? 2 : 4; Columns columns = new Columns(); @@ -573,6 +561,9 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } } + /** + * handle onClientInfo event + */ protected void onClientInfo() { if (ClientInfo.isMobile() && parameterStdLayout != null && parameterStdLayout.getRows() != null) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java index e3a2974154..c3214b3d92 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatementUI.java @@ -66,10 +66,14 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event { private WCreateFromWindow window; + /** + * + * @param tab + */ public WCreateFromStatementUI(GridTab tab) { super(tab); - log.info(getGridTab().toString()); + if (log.isLoggable(Level.INFO)) log.info(getGridTab().toString()); window = new WCreateFromWindow(this, getGridTab().getWindowNo()); @@ -126,12 +130,8 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event protected Grid parameterBankLayout; - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { log.config(""); @@ -245,6 +245,10 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event } } + /** + * Configure layout of parameter grid + * @param parameterBankLayout + */ protected void setupColumns(Grid parameterBankLayout) { Columns columns = new Columns(); parameterBankLayout.appendChild(columns); @@ -277,8 +281,9 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event /** * Action Listener * @param e event - * @throws Exception + * @throws Exception */ + @Override public void onEvent(Event e) throws Exception { if (log.isLoggable(Level.CONFIG)) log.config("Action=" + e.getTarget().getId()); @@ -289,14 +294,21 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event } } + /** + * load bank account transactions + */ protected void loadBankAccount() { - loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), + loadTableOIS(getBankAccountData((Integer)bankAccountField.getValue(), (Integer)bPartnerLookup.getValue(), documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString())); + (Integer)documentTypeField.getValue(), (String)tenderTypeField.getValue(), authorizationField.getValue().toString())); } + /** + * load data into listbox + * @param data + */ protected void loadTableOIS (Vector data) { window.getWListbox().clear(); @@ -312,11 +324,13 @@ public class WCreateFromStatementUI extends CreateFromStatement implements Event configureMiniTable(window.getWListbox()); } + @Override public void showWindow() { window.setVisible(true); } + @Override public void closeWindow() { window.dispose(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java index fb4436aa50..d1580b0941 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java @@ -40,6 +40,11 @@ import org.zkoss.zul.North; import org.zkoss.zul.Separator; import org.zkoss.zul.South; +/** + * + * @author hengsin + * + */ public class WCreateFromWindow extends Window implements EventListener, WTableModelListener, DialogEvents { /** @@ -60,6 +65,11 @@ public class WCreateFromWindow extends Window implements EventListener, W public static final String SELECT_DESELECT_ALL = "SelectAll"; private boolean checkAllSelected = true; + /** + * + * @param createFrom + * @param windowNo + */ public WCreateFromWindow(CreateFrom createFrom, int windowNo) { super(); @@ -135,6 +145,7 @@ public class WCreateFromWindow extends Window implements EventListener, W ZKUpdateUtil.setHeight(contentPane, "100%"); } + @Override public void onEvent(Event e) throws Exception { // OK - Save @@ -185,6 +196,7 @@ public class WCreateFromWindow extends Window implements EventListener, W } } + @Override public void tableChanged (WTableModelEvent e) { int type = -1; @@ -210,6 +222,11 @@ public class WCreateFromWindow extends Window implements EventListener, W info(); } + /** + * + * @param trxName + * @return true if save successfully + */ public boolean save(String trxName) { ListModelTable model = dataTable.getModel(); @@ -220,6 +237,9 @@ public class WCreateFromWindow extends Window implements EventListener, W return createFrom.save(dataTable, trxName); } + /** + * update status + */ public void info() { ListModelTable model = dataTable.getModel(); @@ -235,6 +255,11 @@ public class WCreateFromWindow extends Window implements EventListener, W createFrom.info(dataTable, statusBar); } + /** + * + * @param selectedRowCount + * @param text + */ public void setStatusLine(int selectedRowCount, String text) { StringBuilder sb = new StringBuilder(String.valueOf(selectedRowCount)); @@ -246,31 +271,55 @@ public class WCreateFromWindow extends Window implements EventListener, W confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); } + /** + * + * @return {@link StatusBarPanel} + */ public StatusBarPanel getStatusBar() { return statusBar; } + /** + * + * @param statusBar + */ public void setStatusBar(StatusBarPanel statusBar) { this.statusBar = statusBar; } + /** + * + * @return {@link WListbox} + */ public WListbox getWListbox() { return dataTable; } + /** + * + * @return {@link Panel} + */ public Panel getParameterPanel() { return parameterPanel; } + /** + * + * @return {@link ConfirmPanel} + */ public ConfirmPanel getConfirmPanel() { return confirmPanel; } + /** + * + * @return true if dialog cancel by user + */ public boolean isCancel() { return isCancel; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java index 21b128c333..72caa278f9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WStatementCreateFromBatch.java @@ -67,11 +67,15 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen { private WCreateFromForm form; + /** + * default constructor + */ public WStatementCreateFromBatch() { form = new WCreateFromForm(this); } + @Override public void initForm() { try @@ -127,16 +131,12 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen protected Grid parameterBankLayout; - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { super.dynInit(); - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); //Refresh button Button refreshButton = form.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH); @@ -180,6 +180,9 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen return true; } // dynInit + /** + * handle onClientInfo event + */ protected void onClientInfo() { if (ClientInfo.isMobile() && parameterBankLayout != null && parameterBankLayout.getColumns() != null) @@ -269,6 +272,10 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen } } + /** + * Configure layout of parameter grid + * @param parameterBankLayout + */ protected void setupColumns(Grid parameterBankLayout) { Columns columns = new Columns(); parameterBankLayout.appendChild(columns); @@ -298,11 +305,7 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen } } - /** - * Action Listener - * @param e event - * @throws Exception - */ + @Override public void onEvent(Event e) throws Exception { if (log.isLoggable(Level.CONFIG)) log.config("Action=" + e.getTarget().getId()); @@ -313,15 +316,20 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen } } + @Override public void executeQuery() { - loadTableOIS(getBankAccountData(bankAccountField.getValue(), bPartnerLookup.getValue(), + loadTableOIS(getBankAccountData((Integer)bankAccountField.getValue(), (Integer)bPartnerLookup.getValue(), documentNoField.getValue().toString(), dateFromField.getValue(), dateToField.getValue(), amtFromField.getValue(), amtToField.getValue(), - documentTypeField.getValue(), tenderTypeField.getValue(), authorizationField.getValue().toString(), + (Integer)documentTypeField.getValue(), (String)tenderTypeField.getValue(), authorizationField.getValue().toString(), form.getGridTab())); } + /** + * load data into list box + * @param data + */ protected void loadTableOIS (Vector data) { form.getWListbox().clear(); @@ -337,6 +345,7 @@ public class WStatementCreateFromBatch extends StatementCreateFromBatch implemen configureMiniTable(form.getWListbox()); } + @Override public ADForm getForm() { return form; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java index 45540080e9..43c2aae6e9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java @@ -268,7 +268,7 @@ public class WNumberEditor extends WEditor implements ContextMenuListener } @Override - public Object getValue() + public BigDecimal getValue() { return getComponent().getValue(); } diff --git a/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java b/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java index cb0e3a858e..99139e8f32 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/CreateFromForm.java @@ -30,21 +30,52 @@ public abstract class CreateFromForm private String title; + /** + * initialize form + */ public abstract void initForm(); - public abstract boolean dynInit() throws Exception; + /** + * dynamic initialization, usually for loading of data + * @return true if initialization is ok + * @throws Exception + */ + protected abstract boolean dynInit() throws Exception; + /** + * update status bar with info from miniTable + * @param miniTable + * @param statusBar + */ public abstract void info(IMiniTable miniTable, IStatusBar statusBar); + /** + * save changes + * @param miniTable + * @param trxName + * @param gridTab + * @return true if save succeed + */ public abstract boolean save(IMiniTable miniTable, String trxName, GridTab gridTab); + /** + * + * @return title + */ public String getTitle() { return title; } + /** + * + * @param title + */ public void setTitle(String title) { this.title = title; } + /** + * execute query + */ public abstract void executeQuery(); } diff --git a/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java b/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java index fcdf90b6e2..b35bb900b3 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/StatementCreateFromBatch.java @@ -45,7 +45,8 @@ public abstract class StatementCreateFromBatch extends CreateFromForm /** Logger */ protected transient CLogger log = CLogger.getCLogger(getClass()); - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { log.config(""); setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.getElement(Env.getCtx(), "X_CreateFromBatch")); @@ -53,8 +54,29 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return true; } + @Deprecated public String getSQLWhere(Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + { + return getSQLWhere((Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode); + } + + /** + * + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @return where clause + */ + public String getSQLWhere(Integer BPartner, String DocumentNo, Timestamp DateFrom, Timestamp DateTo, + BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode) { StringBuilder sql = new StringBuilder(); sql.append("WHERE p.Processed='Y' AND p.IsReconciled='N'"); @@ -76,25 +98,21 @@ public abstract class StatementCreateFromBatch extends CreateFromForm if(AmtFrom != null || AmtTo != null) { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - if(from == null && to != null) + if(AmtFrom == null && AmtTo != null) sql.append(" AND p.PayAmt <= ?"); - else if(from != null && to == null) + else if(AmtFrom != null && AmtTo == null) sql.append(" AND p.PayAmt >= ?"); - else if(from != null && to != null) + else if(AmtFrom != null && AmtTo != null) sql.append(" AND p.PayAmt BETWEEN ? AND ?"); } if(DateFrom != null || DateTo != null) { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - if(from == null && to != null) + if(DateFrom == null && DateTo != null) sql.append(" AND TRUNC(p.DateTrx) <= ?"); - else if(from != null && to == null) + else if(DateFrom != null && DateTo == null) sql.append(" AND TRUNC(p.DateTrx) >= ?"); - else if(from != null && to != null) + else if(DateFrom != null && DateTo != null) sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?"); } @@ -102,22 +120,47 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return sql.toString(); } + @Deprecated void setParameters(PreparedStatement pstmt, Object BankAccount, Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode, GridTab gridTab) throws SQLException + { + setParameters(pstmt, (Integer)BankAccount, (Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode, gridTab); + } + + /** + * + * @param pstmt + * @param BankAccount + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @param gridTab + * @throws SQLException + */ + protected void setParameters(PreparedStatement pstmt, Integer BankAccount, Integer BPartner, String DocumentNo, Timestamp DateFrom, Timestamp DateTo, + BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode, GridTab gridTab) + throws SQLException { int index = 1; - pstmt.setInt(index++, BankAccount != null ? (Integer) BankAccount : (Integer) gridTab.getValue("C_BankAccount_ID")); + pstmt.setInt(index++, BankAccount != null ? BankAccount : (Integer) gridTab.getValue("C_BankAccount_ID")); if(DocType != null) - pstmt.setInt(index++, (Integer) DocType); + pstmt.setInt(index++, DocType); if(TenderType != null && TenderType.toString().length() > 0) - pstmt.setString(index++, (String) TenderType); + pstmt.setString(index++, TenderType); if(BPartner != null) - pstmt.setInt(index++, (Integer) BPartner); + pstmt.setInt(index++, BPartner); if(DocumentNo.length() > 0) pstmt.setString(index++, getSQLText(DocumentNo)); @@ -127,33 +170,29 @@ public abstract class StatementCreateFromBatch extends CreateFromForm if(AmtFrom != null || AmtTo != null) { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - if (log.isLoggable(Level.FINE)) log.fine("Amt From=" + from + ", To=" + to); - if(from == null && to != null) - pstmt.setBigDecimal(index++, to); - else if(from != null && to == null) - pstmt.setBigDecimal(index++, from); - else if(from != null && to != null) + if (log.isLoggable(Level.FINE)) log.fine("Amt From=" + AmtFrom + ", To=" + AmtTo); + if(AmtFrom == null && AmtTo != null) + pstmt.setBigDecimal(index++, AmtTo); + else if(AmtFrom != null && AmtTo == null) + pstmt.setBigDecimal(index++, AmtFrom); + else if(AmtFrom != null && AmtTo != null) { - pstmt.setBigDecimal(index++, from); - pstmt.setBigDecimal(index++, to); + pstmt.setBigDecimal(index++, AmtFrom); + pstmt.setBigDecimal(index++, AmtTo); } } if(DateFrom != null || DateTo != null) { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - if (log.isLoggable(Level.FINE)) log.fine("Date From=" + from + ", To=" + to); - if(from == null && to != null) - pstmt.setTimestamp(index++, to); - else if(from != null && to == null) - pstmt.setTimestamp(index++, from); - else if(from != null && to != null) + if (log.isLoggable(Level.FINE)) log.fine("Date From=" + DateFrom + ", To=" + DateTo); + if(DateFrom == null && DateTo != null) + pstmt.setTimestamp(index++, DateTo); + else if(DateFrom != null && DateTo == null) + pstmt.setTimestamp(index++, DateFrom); + else if(DateFrom != null && DateTo != null) { - pstmt.setTimestamp(index++, from); - pstmt.setTimestamp(index++, to); + pstmt.setTimestamp(index++, DateFrom); + pstmt.setTimestamp(index++, DateTo); } } } @@ -167,9 +206,33 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return s; } + @Deprecated protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode, GridTab gridTab) + { + return getBankAccountData((Integer)BankAccount, (Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode, gridTab); + } + + /** + * + * @param BankAccount + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @param gridTab + * @return list of bank account records + */ + protected Vector> getBankAccountData(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode, + GridTab gridTab) { if (log.isLoggable(Level.CONFIG)) log.config ("C_BankAccount_ID=" + BankAccount); @@ -224,6 +287,10 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return data; } + /** + * + * @param miniTable + */ protected void configureMiniTable (IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection @@ -236,6 +303,7 @@ public abstract class StatementCreateFromBatch extends CreateFromForm miniTable.autoSize(); } + @Override public boolean save(IMiniTable miniTable, String trxName, GridTab gridTab) { // fixed values @@ -314,6 +382,10 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return true; } + /** + * + * @return column names + */ protected Vector getOISColumnNames() { // Header Info @@ -328,6 +400,7 @@ public abstract class StatementCreateFromBatch extends CreateFromForm return columnNames; } + @Override public void info(IMiniTable miniTable, IStatusBar statusBar) { DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount); diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java b/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java index d612287407..7bd20d51e1 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFrom.java @@ -33,6 +33,11 @@ import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.KeyNamePair; +/** + * + * @author hengsin + * + */ public abstract class CreateFrom implements ICreateFrom { /** Logger */ @@ -52,6 +57,13 @@ public abstract class CreateFrom implements ICreateFrom protected boolean isSOTrx = false; + /** optional db trx name **/ + private String m_trxName; + + /** + * + * @param gridTab + */ public CreateFrom(GridTab gridTab) { this.gridTab = gridTab; @@ -62,36 +74,63 @@ public abstract class CreateFrom implements ICreateFrom isSOTrx = "Y".equals(Env.getContext(Env.getCtx(), gridTab.getWindowNo(), "IsSOTrx")); } - public abstract boolean dynInit() throws Exception; - - public abstract void info(IMiniTable miniTable, IStatusBar statusBar); - - public abstract boolean save(IMiniTable miniTable, String trxName); + /** + * dynamic initialization, usually for loading of data + * @return true if initialization success + * @throws Exception + */ + protected abstract boolean dynInit() throws Exception; /** - * Init OK to be able to make changes? - * @return on if initialized + * update status bar with info from miniTable + * @param miniTable + * @param statusBar */ + public abstract void info(IMiniTable miniTable, IStatusBar statusBar); + + /** + * save changes + * @param miniTable + * @param trxName + * @return true if save successfully + */ + public abstract boolean save(IMiniTable miniTable, String trxName); + + @Override public boolean isInitOK() { return initOK; } + /** + * + * @param initOK + */ public void setInitOK(boolean initOK) { this.initOK = initOK; } /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner related Orders. * @param C_BPartner_ID BPartner * @param forInvoice for invoice + * @param sameWarehouseOnly + * @return list of order records */ protected ArrayList loadOrderData (int C_BPartner_ID, boolean forInvoice, boolean sameWarehouseOnly) { return loadOrderData(C_BPartner_ID, forInvoice, sameWarehouseOnly, false); } + /** + * load order records + * @param C_BPartner_ID + * @param forInvoice + * @param sameWarehouseOnly + * @param forCreditMemo + * @return list of order records + */ protected ArrayList loadOrderData (int C_BPartner_ID, boolean forInvoice, boolean sameWarehouseOnly, boolean forCreditMemo) { ArrayList list = new ArrayList(); @@ -133,7 +172,7 @@ public abstract class CreateFrom implements ICreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), m_trxName); pstmt.setInt(1, C_BPartner_ID); pstmt.setString(2, isSOTrxParam); if(sameWarehouseOnly) @@ -161,15 +200,23 @@ public abstract class CreateFrom implements ICreateFrom } // initBPartnerOIS /** - * Load Data - Order + * Load Order Line records * @param C_Order_ID Order * @param forInvoice true if for invoice vs. delivery qty + * @return list of order line records */ protected Vector> getOrderData (int C_Order_ID, boolean forInvoice) { return getOrderData (C_Order_ID, forInvoice, false); } + /** + * Get order line records + * @param C_Order_ID + * @param forInvoice + * @param forCreditMemo + * @return list of order line records + */ protected Vector> getOrderData (int C_Order_ID, boolean forInvoice, boolean forCreditMemo) { /** @@ -183,7 +230,7 @@ public abstract class CreateFrom implements ICreateFrom * InvoiceLine - 7 */ if (log.isLoggable(Level.CONFIG)) log.config("C_Order_ID=" + C_Order_ID); - p_order = new MOrder (Env.getCtx(), C_Order_ID, null); + p_order = new MOrder (Env.getCtx(), C_Order_ID, getTrxName()); Vector> data = new Vector>(); StringBuilder sql = new StringBuilder("SELECT "); @@ -216,7 +263,7 @@ public abstract class CreateFrom implements ICreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, C_Order_ID); rs = pstmt.executeQuery(); while (rs.next()) @@ -231,7 +278,7 @@ public abstract class CreateFrom implements ICreateFrom line.add(pp); // 2-UOM pp = new KeyNamePair(rs.getInt(5), rs.getString(6)); line.add(pp); // 3-Product - line.add(rs.getString(7)); // 4-VendorProductNo + line.add(rs.getString(7)); // 4-VendorProductNo pp = new KeyNamePair(rs.getInt(8), rs.getString(9)); line.add(pp); // 5-OrderLine line.add(null); // 6-Ship @@ -252,16 +299,22 @@ public abstract class CreateFrom implements ICreateFrom return data; } // LoadOrder + @Override public void showWindow() { } + @Override public void closeWindow() { } + /** + * + * @return {@link GridTab} + */ public GridTab getGridTab() { return gridTab; @@ -276,11 +329,35 @@ public abstract class CreateFrom implements ICreateFrom return Env.getContextAsInt(Env.getCtx(), gridTab.getWindowNo(), "M_Warehouse_ID"); } + /** + * + * @return title + */ public String getTitle() { return title; } + /** + * + * @param title + */ public void setTitle(String title) { this.title = title; } + + /** + * + * @return trx name + */ + public String getTrxName() { + return m_trxName; + } + + /** + * set optional trx name + * @param trxName + */ + public void setTrxName(String trxName) { + m_trxName = trxName; + } } diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromBatch.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromBatch.java index 75ba8e3ac4..b7eea677f1 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromBatch.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromBatch.java @@ -35,13 +35,38 @@ import org.compiere.util.Msg; */ public abstract class CreateFromBatch extends CreateFrom { + /** + * + * @param gridTab + */ public CreateFromBatch(GridTab gridTab) { super(gridTab); } + @Deprecated public String getSQLWhere(Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + { + return getSQLWhere((Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode); + } + + /** + * + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @return where clause + */ + protected String getSQLWhere(Integer BPartner, String DocumentNo, Timestamp DateFrom, Timestamp DateTo, + BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode) { StringBuilder sql = new StringBuilder(); sql.append("WHERE p.Processed='Y' AND p.IsReconciled='N'"); @@ -56,32 +81,28 @@ public abstract class CreateFromBatch extends CreateFrom if(BPartner != null) sql.append(" AND p.C_BPartner_ID=?"); - if(DocumentNo.length() > 0) + if(DocumentNo != null && DocumentNo.length() > 0) sql.append(" AND UPPER(p.DocumentNo) LIKE ?"); - if(AuthCode.length() > 0) + if(AuthCode != null && AuthCode.length() > 0) sql.append(" AND p.R_AuthCode LIKE ?"); if(AmtFrom != null || AmtTo != null) { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - if(from == null && to != null) + if(AmtFrom == null && AmtTo != null) sql.append(" AND p.PayAmt <= ?"); - else if(from != null && to == null) + else if(AmtFrom != null && AmtTo == null) sql.append(" AND p.PayAmt >= ?"); - else if(from != null && to != null) + else if(AmtFrom != null && AmtTo != null) sql.append(" AND p.PayAmt BETWEEN ? AND ?"); } if(DateFrom != null || DateTo != null) { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - if(from == null && to != null) + if(DateFrom == null && DateTo != null) sql.append(" AND TRUNC(p.DateTrx) <= ?"); - else if(from != null && to == null) + else if(DateFrom != null && DateTo == null) sql.append(" AND TRUNC(p.DateTrx) >= ?"); - else if(from != null && to != null) + else if(DateFrom != null && DateTo != null) sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?"); } @@ -89,64 +110,78 @@ public abstract class CreateFromBatch extends CreateFrom return sql.toString(); } + @Deprecated void setParameters(PreparedStatement pstmt, Object BankAccount, Object BPartner, String DocumentNo, Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) throws SQLException { - // Get StatementDate - //Timestamp ts = (Timestamp) getGridTab().getValue("StatementDate"); - //if (ts == null) - //ts = new Timestamp(System.currentTimeMillis()); - + setParameters(pstmt, (Integer)BankAccount, (Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode); + } + + /** + * + * @param pstmt + * @param BankAccount + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @throws SQLException + */ + protected void setParameters(PreparedStatement pstmt, Integer BankAccount, Integer BPartner, String DocumentNo, Timestamp DateFrom, Timestamp DateTo, + BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode) + throws SQLException + { int index = 1; - //pstmt.setTimestamp(index++, ts); - pstmt.setInt(index++, BankAccount != null ? (Integer) BankAccount : (Integer) getGridTab().getValue("C_BankAccount_ID")); + pstmt.setInt(index++, BankAccount != null ? BankAccount : (Integer) getGridTab().getValue("C_BankAccount_ID")); if(DocType != null) - pstmt.setInt(index++, (Integer) DocType); + pstmt.setInt(index++, DocType); if(TenderType != null && TenderType.toString().length() > 0) - pstmt.setString(index++, (String) TenderType); + pstmt.setString(index++, TenderType); if(BPartner != null) - pstmt.setInt(index++, (Integer) BPartner); + pstmt.setInt(index++, BPartner); - if(DocumentNo.length() > 0) + if(DocumentNo != null && DocumentNo.length() > 0) pstmt.setString(index++, getSQLText(DocumentNo)); - if(AuthCode.length() > 0) + if(AuthCode != null && AuthCode.length() > 0) pstmt.setString(index++, getSQLText(AuthCode)); if(AmtFrom != null || AmtTo != null) { - BigDecimal from = (BigDecimal) AmtFrom; - BigDecimal to = (BigDecimal) AmtTo; - if (log.isLoggable(Level.FINE)) log.fine("Amt From=" + from + ", To=" + to); - if(from == null && to != null) - pstmt.setBigDecimal(index++, to); - else if(from != null && to == null) - pstmt.setBigDecimal(index++, from); - else if(from != null && to != null) + if (log.isLoggable(Level.FINE)) log.fine("Amt From=" + AmtFrom + ", To=" + AmtTo); + if(AmtFrom == null && AmtTo != null) + pstmt.setBigDecimal(index++, AmtTo); + else if(AmtFrom != null && AmtTo == null) + pstmt.setBigDecimal(index++, AmtFrom); + else if(AmtFrom != null && AmtTo != null) { - pstmt.setBigDecimal(index++, from); - pstmt.setBigDecimal(index++, to); + pstmt.setBigDecimal(index++, AmtFrom); + pstmt.setBigDecimal(index++, AmtTo); } } if(DateFrom != null || DateTo != null) { - Timestamp from = (Timestamp) DateFrom; - Timestamp to = (Timestamp) DateTo; - if (log.isLoggable(Level.FINE)) log.fine("Date From=" + from + ", To=" + to); - if(from == null && to != null) - pstmt.setTimestamp(index++, to); - else if(from != null && to == null) - pstmt.setTimestamp(index++, from); - else if(from != null && to != null) + if (log.isLoggable(Level.FINE)) log.fine("Date From=" + DateFrom + ", To=" + DateTo); + if(DateFrom == null && DateTo != null) + pstmt.setTimestamp(index++, DateTo); + else if(DateFrom != null && DateTo == null) + pstmt.setTimestamp(index++, DateFrom); + else if(DateFrom != null && DateTo != null) { - pstmt.setTimestamp(index++, from); - pstmt.setTimestamp(index++, to); + pstmt.setTimestamp(index++, DateFrom); + pstmt.setTimestamp(index++, DateTo); } } } @@ -160,9 +195,32 @@ public abstract class CreateFromBatch extends CreateFrom return s; } - protected abstract Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, - Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode); + @Deprecated + protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, + Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + { + return getBankAccountData((Integer)BankAccount, (Integer)BPartner, DocumentNo, (Timestamp)DateFrom, (Timestamp)DateTo, + (BigDecimal)AmtFrom, (BigDecimal)AmtTo, (Integer)DocType, (String)TenderType, AuthCode); + } + /** + * + * @param BankAccount + * @param BPartner + * @param DocumentNo + * @param DateFrom + * @param DateTo + * @param AmtFrom + * @param AmtTo + * @param DocType + * @param TenderType + * @param AuthCode + * @return list of transaction records (usually payments) for bank account + */ + protected abstract Vector> getBankAccountData(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode); + + @Override public void info(IMiniTable miniTable, IStatusBar statusBar) { DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount); diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromDepositBatch.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromDepositBatch.java index ba3baafba8..88ce022916 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromDepositBatch.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromDepositBatch.java @@ -32,28 +32,37 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * + * Create C_DepositBatchLine for C_DepositBatch from C_Payment * @author Elaine * */ public abstract class CreateFromDepositBatch extends CreateFromBatch { + /** + * + * @param mTab + */ public CreateFromDepositBatch(GridTab mTab) { super(mTab); if (log.isLoggable(Level.INFO)) log.info(mTab.toString()); } - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); setTitle(Msg.getElement(Env.getCtx(), "C_DepositBatch_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); return true; } - protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, - Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + /** + * @return transaction records (selection,datetrx,[c_payment_id,documentno],[c_currency_id,iso_code],payamt,converted amt,bp name) + */ + @Override + protected Vector> getBankAccountData(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode) { Vector> data = new Vector>(); @@ -77,7 +86,7 @@ public abstract class CreateFromDepositBatch extends CreateFromBatch ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); rs = pstmt.executeQuery(); while(rs.next()) @@ -108,6 +117,10 @@ public abstract class CreateFromDepositBatch extends CreateFromBatch return data; } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable(IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection @@ -121,6 +134,10 @@ public abstract class CreateFromDepositBatch extends CreateFromBatch miniTable.autoSize(); } + /** + * Create C_DepositBatchLine + */ + @Override public boolean save(IMiniTable miniTable, String trxName) { // fixed values @@ -139,12 +156,10 @@ public abstract class CreateFromDepositBatch extends CreateFromBatch pp = (KeyNamePair) miniTable.getValueAt(i, 3); // 3-Currency int C_Currency_ID = pp.getKey(); BigDecimal TrxAmt = (BigDecimal) miniTable.getValueAt(i, 4); // 4-PayAmt - // BigDecimal StmtAmt = (BigDecimal) miniTable.getValueAt(i, 5);// 5-Conv Amt // if (log.isLoggable(Level.FINE)) log.fine("Line Date=" + trxDate + ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt); // MDepositBatchLine dbl = new MDepositBatchLine(db); - // dbl.setStatementLineDate(trxDate); dbl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName)); if(!dbl.save()) log.log(Level.SEVERE, "Line not created #" + i); @@ -153,6 +168,10 @@ public abstract class CreateFromDepositBatch extends CreateFromBatch return true; } + /** + * + * @return column header names (select,date,c_payment_id,c_currency_id,amount,converted amount,c_bpartner_id) + */ protected Vector getOISColumnNames() { // Header Info diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java index 2e832640bf..5ab89a40b4 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java @@ -48,7 +48,7 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * Create Invoice Transactions from PO Orders or Receipt + * Create Invoice Lines from Purchase Order, Material Receipt or Vendor RMA * * @author Jorg Janke * @version $Id: VCreateFromInvoice.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ @@ -60,20 +60,17 @@ import org.compiere.util.Msg; public abstract class CreateFromInvoice extends CreateFrom { /** - * Protected Constructor + * Constructor * @param mTab MTab */ public CreateFromInvoice(GridTab mTab) { super(mTab); if (log.isLoggable(Level.INFO)) log.info(mTab.toString()); - } // VCreateFromInvoice + } // CreateFromInvoice - /** - * Dynamic Init - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { log.config(""); setTitle(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); @@ -82,8 +79,9 @@ public abstract class CreateFromInvoice extends CreateFrom } // dynInit /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner related Shipment records. * @param C_BPartner_ID + * @return list of shipment records */ protected ArrayList loadShipmentData (int C_BPartner_ID) { @@ -117,7 +115,7 @@ public abstract class CreateFromInvoice extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, C_BPartner_ID); pstmt.setString(2, isSOTrxParam); pstmt.setInt(3, C_BPartner_ID); @@ -143,8 +141,9 @@ public abstract class CreateFromInvoice extends CreateFrom } /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner related RMA records * @param C_BPartner_ID BPartner + * @return list of RMA records */ protected ArrayList loadRMAData(int C_BPartner_ID) { ArrayList list = new ArrayList(); @@ -158,7 +157,7 @@ public abstract class CreateFromInvoice extends CreateFrom PreparedStatement pstmt = null; ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt, null); + pstmt = DB.prepareStatement(sqlStmt, getTrxName()); pstmt.setInt(1, C_BPartner_ID); rs = pstmt.executeQuery(); while (rs.next()) { @@ -176,21 +175,21 @@ public abstract class CreateFromInvoice extends CreateFrom } /** - * Load Data - Shipment not invoiced + * Load Shipment Lines not invoiced * @param M_InOut_ID InOut + * @return shipment lines (selection,qty,[c_uom_id,uomSymbol/name],[m_product_id,name],vendorProductNo,[c_orderline_id,.],[m_inoutline_id,line],null) */ protected Vector> getShipmentData(int M_InOut_ID) { if (log.isLoggable(Level.CONFIG)) log.config("M_InOut_ID=" + M_InOut_ID); - MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null); + MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, getTrxName()); p_order = null; if (inout.getC_Order_ID() != 0) - p_order = new MOrder (Env.getCtx(), inout.getC_Order_ID(), null); + p_order = new MOrder (Env.getCtx(), inout.getC_Order_ID(), getTrxName()); m_rma = null; if (inout.getM_RMA_ID() != 0) - m_rma = new MRMA (Env.getCtx(), inout.getM_RMA_ID(), null); - + m_rma = new MRMA (Env.getCtx(), inout.getM_RMA_ID(), getTrxName()); // Vector> data = new Vector>(); StringBuilder sql = new StringBuilder("SELECT "); // QtyEntered @@ -231,7 +230,7 @@ public abstract class CreateFromInvoice extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, M_InOut_ID); rs = pstmt.executeQuery(); while (rs.next()) @@ -270,18 +269,17 @@ public abstract class CreateFromInvoice extends CreateFrom } return data; - } // loadShipment + } // getShipmentData /** - * Load RMA details + * Load RMA line records * @param M_RMA_ID RMA + * @return RMA lines (selection,qty,[c_uom_id,uomSymbol/name],[m_product_id,name],null,null,null,[m_rmaline_id,line]) */ protected Vector> getRMAData(int M_RMA_ID) { p_order = null; -// MRMA m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); - Vector> data = new Vector>(); StringBuilder sqlStmt = new StringBuilder(); sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - COALESCE(rl.QtyInvoiced, 0), iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); @@ -320,7 +318,7 @@ public abstract class CreateFromInvoice extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), getTrxName()); pstmt.setInt(1, M_RMA_ID); pstmt.setInt(2, M_RMA_ID); rs = pstmt.executeQuery(); @@ -355,18 +353,20 @@ public abstract class CreateFromInvoice extends CreateFrom return data; } - /** - * List number of rows selected - */ + @Override public void info(IMiniTable miniTable, IStatusBar statusBar) { - } // infoInvoice + } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable (IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection - miniTable.setColumnClass(1, BigDecimal.class, false); // 1-Qty + miniTable.setColumnClass(1, BigDecimal.class, false); // 1-Qty miniTable.setColumnClass(2, String.class, true); // 2-UOM miniTable.setColumnClass(3, String.class, true); // 3-Product miniTable.setColumnClass(4, String.class, true); // 4-VendorProductNo @@ -381,6 +381,7 @@ public abstract class CreateFromInvoice extends CreateFrom * Save - Create Invoice Lines * @return true if saved */ + @Override public boolean save(IMiniTable miniTable, String trxName) { // Invoice @@ -400,18 +401,6 @@ public abstract class CreateFromInvoice extends CreateFrom invoice.saveEx(); } -// MInOut inout = null; -// if (m_M_InOut_ID > 0) -// { -// inout = new MInOut(Env.getCtx(), m_M_InOut_ID, trxName); -// } -// if (inout != null && inout.getM_InOut_ID() != 0 -// && inout.getC_Invoice_ID() == 0) // only first time -// { -// inout.setC_Invoice_ID(C_Invoice_ID); -// inout.saveEx(); -// } - // Lines for (int i = 0; i < miniTable.getRowCount(); i++) { @@ -475,7 +464,7 @@ public abstract class CreateFromInvoice extends CreateFrom // MRMALine rmaLine = null; if (M_RMALine_ID > 0) - rmaLine = new MRMALine (Env.getCtx(), M_RMALine_ID, null); + rmaLine = new MRMALine (Env.getCtx(), M_RMALine_ID, trxName); // MInOutLine inoutLine = null; if (M_InOutLine_ID != 0) @@ -510,17 +499,12 @@ public abstract class CreateFromInvoice extends CreateFrom break; } } -// if (inoutLine == null) -// { -// inoutLine = lines[0]; // first as default -// M_InOutLine_ID = inoutLine.getM_InOutLine_ID(); -// } } } else if (M_RMALine_ID != 0) { String whereClause = "EXISTS (SELECT 1 FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('CO','CL'))"; - MInOutLine[] lines = MInOutLine.getOfRMALine(Env.getCtx(), M_RMALine_ID, whereClause, null); + MInOutLine[] lines = MInOutLine.getOfRMALine(Env.getCtx(), M_RMALine_ID, whereClause, trxName); if (log.isLoggable(Level.FINE)) log.fine ("Receipt Lines with RMALine = #" + lines.length); if (lines.length > 0) { @@ -559,7 +543,7 @@ public abstract class CreateFromInvoice extends CreateFrom } } else { - log.fine("No Receipt Line"); + if (log.isLoggable(Level.FINE)) log.fine("No Receipt Line"); // Order Info if (orderLine != null) { @@ -567,7 +551,7 @@ public abstract class CreateFromInvoice extends CreateFrom } else { - log.fine("No Order Line"); + if (log.isLoggable(Level.FINE)) log.fine("No Order Line"); invoiceLine.setPrice(); invoiceLine.setTax(); } @@ -578,7 +562,9 @@ public abstract class CreateFromInvoice extends CreateFrom invoiceLine.setRMALine(rmaLine); // overwrites } else - log.fine("No RMA Line"); + { + if (log.isLoggable(Level.FINE)) log.fine("No RMA Line"); + } } invoiceLine.saveEx(); } // if selected @@ -622,8 +608,12 @@ public abstract class CreateFromInvoice extends CreateFrom } return true; - } // saveInvoice + } // save + /** + * + * @return column header names (select,quantity,uom,product,vendorProductNo,order,shipment,rma) + */ protected Vector getOISColumnNames() { // Header Info diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java index 6f968a0ccd..dab43d9e2d 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java @@ -35,26 +35,36 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * + * Create M_PackageLine for M_PackageMPS from shipment lines * @author Elaine * */ public abstract class CreateFromPackageShipment extends CreateFrom { + /** + * + * @param gridTab + */ public CreateFromPackageShipment(GridTab gridTab) { super(gridTab); if (log.isLoggable(Level.INFO)) log.info(gridTab.toString()); } - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); setTitle(Msg.getElement(Env.getCtx(), "M_PackageMPS_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); return true; } + /** + * + * @param M_InOut_ID + * @return shipment lines (selection,[m_inoutline_id,line],qty,[m_product_id,name],uom) + */ protected Vector> getShipmentData(int M_InOut_ID) { if (log.isLoggable(Level.CONFIG)) log.config("M_InOut_ID=" + M_InOut_ID); @@ -69,7 +79,7 @@ public abstract class CreateFromPackageShipment extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), getTrxName()); pstmt.setInt(1, M_InOut_ID); rs = pstmt.executeQuery(); while (rs.next()) @@ -78,10 +88,9 @@ public abstract class CreateFromPackageShipment extends CreateFrom line.add(Boolean.FALSE); // 0-Selection KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // M_InOutLine_ID, Line line.add(lineKNPair); - line.add(rs.getBigDecimal(3)); //Qty + line.add(rs.getBigDecimal(3)); //Qty KeyNamePair productKNPair = new KeyNamePair(rs.getInt(4), rs.getString(5)); // ProductID, Product Name line.add(productKNPair); //Product - //line.add(rs.getString(5)); line.add(rs.getString(6)); //UOM data.add(line); @@ -101,11 +110,16 @@ public abstract class CreateFromPackageShipment extends CreateFrom return data; } + @Override public void info(IMiniTable miniTable, IStatusBar statusBar) { } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable (IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection @@ -117,13 +131,17 @@ public abstract class CreateFromPackageShipment extends CreateFrom miniTable.autoSize(); } + /** + * Create M_PackageLine + */ + @Override public boolean save(IMiniTable miniTable, String trxName) { int M_PackageMPS_ID = (Integer) getGridTab().getValue(MPackageMPS.COLUMNNAME_M_PackageMPS_ID); - MPackageMPS packageMPS = new MPackageMPS(Env.getCtx(), M_PackageMPS_ID, null); + MPackageMPS packageMPS = new MPackageMPS(Env.getCtx(), M_PackageMPS_ID, trxName); - MPackage mPackage = new MPackage(Env.getCtx(), packageMPS.getM_Package_ID(), null); - MInOut shipment = new MInOut(Env.getCtx(), mPackage.getM_InOut_ID(), null); + MPackage mPackage = new MPackage(Env.getCtx(), packageMPS.getM_Package_ID(), trxName); + MInOut shipment = new MInOut(Env.getCtx(), mPackage.getM_InOut_ID(), trxName); MInOutLine[] shipmentLines = shipment.getLines(false); HashMap lineMap = new HashMap(); @@ -148,18 +166,18 @@ public abstract class CreateFromPackageShipment extends CreateFrom packageLine.setInOutLine((MInOutLine)lineMap.get(inOutLineId)); packageLine.setM_Product_ID(productId); packageLine.setQty(qty); - packageLine.setM_PackageMPS_ID(M_PackageMPS_ID); - - if (!packageLine.save(mPackage.get_TrxName())) - { - throw new IllegalStateException("Could not create Package Line"); - } + packageLine.setM_PackageMPS_ID(M_PackageMPS_ID); + packageLine.saveEx(mPackage.get_TrxName()); } } return true; } + /** + * + * @return column header names (select,line,quantity,product,uom) + */ protected Vector getOISColumnNames() { Vector columnNames = new Vector(5); diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java index cbd7f490be..926eaa7d44 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java @@ -31,13 +31,17 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * Create Transactions for RMA + * Create M_RMALine for M_RMA from shipment lines * @author ashley * @author Teo Sarca, www.arhipac.ro *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx */ public abstract class CreateFromRMA extends CreateFrom { + /** + * + * @param mTab + */ public CreateFromRMA(GridTab mTab) { super(mTab); @@ -45,7 +49,7 @@ public abstract class CreateFromRMA extends CreateFrom { } @Override - public boolean dynInit() throws Exception + protected boolean dynInit() throws Exception { log.config(""); setTitle(Msg.getElement(Env.getCtx(), "M_RMA_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); @@ -53,6 +57,10 @@ public abstract class CreateFromRMA extends CreateFrom { return true; } + /** + * Get shipment lines + * @return shipment lines (selection,[m_inoutline_id,line],productName,serialNo,qtyEntered,movementQty,lineDescription) + */ protected Vector> getRMAData() { int M_InOut_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "InOut_ID"); @@ -62,18 +70,19 @@ public abstract class CreateFromRMA extends CreateFrom { /** * 1 M_InOutLine_ID - * 2 Line + * 2 Line No * 3 Product Name * 4 Qty Entered * 5 Movement Qty * 6 ASI + * 7 Line Description */ StringBuilder sqlStmt = new StringBuilder(); sqlStmt.append("SELECT iol.M_InOutLine_ID, iol.Line, "); sqlStmt.append("COALESCE(p.Name, c.Name) AS ProductName, "); sqlStmt.append("iol.QtyEntered, "); - sqlStmt.append("iol.movementQty-(SELECT COALESCE((SELECT SUM(rmal.qty) FROM M_RMALine rmal JOIN M_RMA rma ON rma.M_RMA_ID=rmal.M_RMA_ID WHERE rmal.M_InOutLine_ID=iol.M_InOutLine_ID AND rma.DocStatus IN ('CO','CL')),0)) AS MovementQty, "); + sqlStmt.append("iol.movementQty-(COALESCE((SELECT SUM(rmal.qty) FROM M_RMALine rmal JOIN M_RMA rma ON rma.M_RMA_ID=rmal.M_RMA_ID WHERE rmal.M_InOutLine_ID=iol.M_InOutLine_ID AND rma.DocStatus IN ('CO','CL')),0)) AS MovementQty, "); sqlStmt.append("CASE WHEN iol.M_AttributeSetInstance_ID IS NOT NULL THEN (SELECT SerNo FROM M_AttributeSetInstance asi WHERE asi.M_AttributeSetInstance_ID=iol.M_AttributeSetInstance_ID) END as ASI, "); sqlStmt.append("iol.Description " ); sqlStmt.append("FROM M_InOutLine iol "); @@ -87,7 +96,7 @@ public abstract class CreateFromRMA extends CreateFrom { ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), getTrxName()); pstmt.setInt(1, M_InOut_ID); pstmt.setInt(2, M_RMA_ID); rs = pstmt.executeQuery(); @@ -131,6 +140,10 @@ public abstract class CreateFromRMA extends CreateFrom { } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable (IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection @@ -145,23 +158,23 @@ public abstract class CreateFromRMA extends CreateFrom { miniTable.autoSize(); } + /** + * Create M_RMALine + */ @Override public boolean save(IMiniTable miniTable, String trxName) { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); int M_RMA_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "M_RMA_ID"); -// Integer bpId = (Integer)bPartnerField.getValue(); MRMA rma = new MRMA(Env.getCtx(), M_RMA_ID, trxName); - //update BP -// rma.setC_BPartner_ID(bpId); for (int i = 0; i < miniTable.getRowCount(); i++) { if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) { - BigDecimal d = (BigDecimal)miniTable.getValueAt(i, 5); // 5-Movement Qty - KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 1); // 1-Line + BigDecimal d = (BigDecimal)miniTable.getValueAt(i, 5); // 5-Movement Qty + KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 1); // 1-Line (M_InOutLine_ID, Line) int inOutLineId = pp.getKey(); @@ -171,16 +184,17 @@ public abstract class CreateFromRMA extends CreateFrom { rmaLine.setQty(d); rmaLine.setAD_Org_ID(rma.getAD_Org_ID()); rmaLine.setDescription((String)miniTable.getValueAt(i, 6)); - if (!rmaLine.save()) - { - throw new IllegalStateException("Could not create RMA Line"); - } + rmaLine.saveEx(); } } rma.saveEx(); return true; } + /** + * + * @return column header names (select,line,product,serialNo,quantity,qtyDelivered,description) + */ protected Vector getOISColumnNames() { // Header Info diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java index d66e2387f3..6ee6537674 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java @@ -44,7 +44,7 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * Create Invoice Transactions from PO Orders or Receipt + * Create M_InOutLine for M_InOut from Purchase Orders, Vendor Invoice or Customer RMA * * @author Jorg Janke * @version $Id: VCreateFromShipment.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ @@ -62,22 +62,19 @@ public abstract class CreateFromShipment extends CreateFrom private int defaultLocator_ID=0; /** - * Protected Constructor + * Constructor * @param mTab MTab */ public CreateFromShipment(GridTab mTab) { super(mTab); if (log.isLoggable(Level.INFO)) log.info(mTab.toString()); - } // VCreateFromShipment + } // CreateFromShipment - /** - * Dynamic Init - * @return true if initialized - */ - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { - log.config(""); + if (log.isLoggable(Level.CONFIG)) log.config(""); setTitle(Msg.getElement(Env.getCtx(), "M_InOut_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); return true; @@ -85,8 +82,9 @@ public abstract class CreateFromShipment extends CreateFrom /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner related RMA records. * @param C_BPartner_ID BPartner + * @return list of RMA records */ protected ArrayList loadRMAData(int C_BPartner_ID) { ArrayList list = new ArrayList(); @@ -101,7 +99,7 @@ public abstract class CreateFromShipment extends CreateFrom PreparedStatement pstmt = null; ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt, null); + pstmt = DB.prepareStatement(sqlStmt, getTrxName()); pstmt.setInt(1, C_BPartner_ID); rs = pstmt.executeQuery(); while (rs.next()) { @@ -119,8 +117,9 @@ public abstract class CreateFromShipment extends CreateFrom } /** - * Load PBartner dependent Order/Invoice/Shipment Field. + * Load BPartner related Invoices * @param C_BPartner_ID + * @return list of invoice records */ protected ArrayList loadInvoiceData (int C_BPartner_ID) { @@ -148,7 +147,7 @@ public abstract class CreateFromShipment extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, C_BPartner_ID); pstmt.setInt(2, C_BPartner_ID); rs = pstmt.executeQuery(); @@ -160,7 +159,8 @@ public abstract class CreateFromShipment extends CreateFrom catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); - }finally + } + finally { DB.close(rs, pstmt); rs = null; @@ -171,9 +171,10 @@ public abstract class CreateFromShipment extends CreateFrom } /** - * Load Data - Order + * Load Order Lines * @param C_Order_ID Order * @param forInvoice true if for invoice vs. delivery qty + * @return Order lines (selection,qty,[c_uom_id,uomSymbol/name],[m_locator_id,value][m_product_id,name],vendorProductNo,[c_orderline_id,line],null,null) */ protected Vector> getOrderData (int C_Order_ID, boolean forInvoice) { @@ -189,14 +190,14 @@ public abstract class CreateFromShipment extends CreateFrom * InvoiceLine - 8 */ if (log.isLoggable(Level.CONFIG)) log.config("C_Order_ID=" + C_Order_ID); - p_order = new MOrder (Env.getCtx(), C_Order_ID, null); // save + p_order = new MOrder (Env.getCtx(), C_Order_ID, getTrxName()); // save Vector> data = new Vector>(); StringBuilder sql = new StringBuilder("SELECT " - + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))" // subtract drafted lines from this or other orders IDEMPIERE-2889 - + "-COALESCE((SELECT SUM(MovementQty) FROM M_InOutLine iol JOIN M_InOut io ON iol.M_InOut_ID=io.M_InOut_ID WHERE l.C_OrderLine_ID=iol.C_OrderLine_ID AND io.Processed='N'),0)," // 1 - + "CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2 + + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))" // 1 + + "-COALESCE((SELECT SUM(MovementQty) FROM M_InOutLine iol JOIN M_InOut io ON iol.M_InOut_ID=io.M_InOut_ID WHERE l.C_OrderLine_ID=iol.C_OrderLine_ID AND io.Processed='N'),0)," + + " CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2 + " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4 + " p.M_Locator_ID, loc.Value, " // 5..6 + " COALESCE(l.M_Product_ID,0),COALESCE(p.Name,c.Name), " // 7..8 @@ -227,7 +228,7 @@ public abstract class CreateFromShipment extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, C_Order_ID); rs = pstmt.executeQuery(); while (rs.next()) @@ -241,11 +242,11 @@ public abstract class CreateFromShipment extends CreateFrom KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim()); line.add(pp); // 2-UOM // Add locator - line.add(getLocatorKeyNamePair(rs.getInt(5)));// 3-Locator + line.add(getLocatorKeyNamePair(rs.getInt(5))); // 3-Locator // Add product pp = new KeyNamePair(rs.getInt(7), rs.getString(8)); line.add(pp); // 4-Product - line.add(rs.getString(9)); // 5-VendorProductNo + line.add(rs.getString(9)); // 5-VendorProductNo pp = new KeyNamePair(rs.getInt(10), rs.getString(11)); line.add(pp); // 6-OrderLine line.add(null); // 7-Ship @@ -256,7 +257,6 @@ public abstract class CreateFromShipment extends CreateFrom catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); - //throw new DBException(e, sql.toString()); } finally { @@ -267,14 +267,15 @@ public abstract class CreateFromShipment extends CreateFrom } // LoadOrder /** - * Load RMA details + * Load RMA lines * @param M_RMA_ID RMA + * @return RMA lines (selection,qty,[c_uom_id,uomSymbol/name],[m_locator_id,value],[m_product_id,name],null,null,[m_rmaline_id,line],null) */ protected Vector> getRMAData(int M_RMA_ID) { m_invoice = null; p_order = null; - m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); + m_rma = new MRMA(Env.getCtx(), M_RMA_ID, getTrxName()); Vector> data = new Vector>(); StringBuilder sqlStmt = new StringBuilder(); @@ -332,7 +333,7 @@ public abstract class CreateFromShipment extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), getTrxName()); pstmt.setInt(1, M_RMA_ID); pstmt.setInt(2, M_RMA_ID); pstmt.setInt(3, M_RMA_ID); @@ -370,12 +371,13 @@ public abstract class CreateFromShipment extends CreateFrom } /** - * Load Invoice details + * Load Invoice lines * @param C_Invoice_ID Invoice + * @return Invoice lines (selection,qty,[c_uom_id,uomSymbol/name],[m_locator_id,value],[m_product_id,name],vendorProductNo,[c_orderline_id,.],null,[c_invoiceline_id,line]) */ protected Vector> getInvoiceData(int C_Invoice_ID) { - m_invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, null); // save + m_invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, getTrxName()); // save p_order = null; m_rma = null; @@ -409,7 +411,7 @@ public abstract class CreateFromShipment extends CreateFrom ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); pstmt.setInt(1, C_Invoice_ID); rs = pstmt.executeQuery(); while (rs.next()) @@ -441,7 +443,6 @@ public abstract class CreateFromShipment extends CreateFrom catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); - //throw new DBException(e, sql); } finally { @@ -456,7 +457,7 @@ public abstract class CreateFromShipment extends CreateFrom * If no locator specified or the specified locator is not valid (e.g. warehouse not match), * a default one will be used. * @param M_Locator_ID - * @return KeyNamePair + * @return KeyNamePair (m_locator_id,value) */ protected KeyNamePair getLocatorKeyNamePair(int M_Locator_ID) { @@ -504,14 +505,16 @@ public abstract class CreateFromShipment extends CreateFrom return pp; } - /** - * List number of rows selected - */ + @Override public void info(IMiniTable miniTable, IStatusBar statusBar) { - } // infoInvoice + } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable (IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // Selection @@ -525,30 +528,16 @@ public abstract class CreateFromShipment extends CreateFrom miniTable.setColumnClass(8, String.class, true); // Invoice // Table UI - miniTable.autoSize(); - + miniTable.autoSize(); } /** - * Save - Create Invoice Lines + * Create M_InOutLine * @return true if saved */ + @Override public boolean save(IMiniTable miniTable, String trxName) { - /* - dataTable.stopEditor(true); - log.config(""); - TableModel model = dataTable.getModel(); - int rows = model.getRowCount(); - if (rows == 0) - return false; - // - Integer defaultLoc = (Integer) locatorField.getValue(); - if (defaultLoc == null || defaultLoc.intValue() == 0) { - locatorField.setBackground(AdempierePLAF.getFieldBackground_Error()); - return false; - } - */ int M_Locator_ID = defaultLocator_ID; if (M_Locator_ID == 0) { return false; @@ -588,7 +577,6 @@ public abstract class CreateFromShipment extends CreateFrom C_InvoiceLine_ID = pp.getKey(); if (C_InvoiceLine_ID != 0) il = new MInvoiceLine (Env.getCtx(), C_InvoiceLine_ID, trxName); - //boolean isInvoiced = (C_InvoiceLine_ID != 0); // Precision of Qty UOM int precision = 2; if (M_Product_ID != 0) @@ -753,6 +741,10 @@ public abstract class CreateFromShipment extends CreateFrom } // saveInvoice + /** + * + * @return column header names (select,quantity,uom,locator,product,vendorProductNo,order,rma,invoice) + */ protected Vector getOISColumnNames() { // Header Info @@ -770,18 +762,37 @@ public abstract class CreateFromShipment extends CreateFrom return columnNames; } + /** + * Load order lines + * @param C_Order_ID + * @param forInvoice + * @param M_Locator_ID + * @return order lines + */ protected Vector> getOrderData (int C_Order_ID, boolean forInvoice, int M_Locator_ID) { defaultLocator_ID = M_Locator_ID; return getOrderData (C_Order_ID, forInvoice); } + /** + * + * @param M_RMA_ID + * @param M_Locator_ID + * @return RMA lines + */ protected Vector> getRMAData (int M_RMA_ID, int M_Locator_ID) { defaultLocator_ID = M_Locator_ID; return getRMAData (M_RMA_ID); } + /** + * + * @param C_Invoice_ID + * @param M_Locator_ID + * @return Invoice lines + */ protected Vector> getInvoiceData (int C_Invoice_ID, int M_Locator_ID) { defaultLocator_ID = M_Locator_ID; diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java index 9321fa557c..d681a57e55 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromStatement.java @@ -32,19 +32,24 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * + * Create C_BankStatementLine for C_BankStatement * @author Elaine * */ public abstract class CreateFromStatement extends CreateFromBatch { + /** + * + * @param mTab + */ public CreateFromStatement(GridTab mTab) { super(mTab); if (log.isLoggable(Level.INFO)) log.info(mTab.toString()); } - public boolean dynInit() throws Exception + @Override + protected boolean dynInit() throws Exception { log.config(""); setTitle(Msg.getElement(Env.getCtx(), "C_BankStatement_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); @@ -52,8 +57,12 @@ public abstract class CreateFromStatement extends CreateFromBatch return true; } - protected Vector> getBankAccountData(Object BankAccount, Object BPartner, String DocumentNo, - Object DateFrom, Object DateTo, Object AmtFrom, Object AmtTo, Object DocType, Object TenderType, String AuthCode) + /** + * @return transactions (selection,dateTrx,[c_payment_id,documentNo],[c_currency_id,iso_code],payamt,convertedAmt,bpName) + */ + @Override + protected Vector> getBankAccountData(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, String TenderType, String AuthCode) { Vector> data = new Vector>(); @@ -71,7 +80,7 @@ public abstract class CreateFromStatement extends CreateFromBatch ResultSet rs = null; try { - pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), getTrxName()); setParameters(pstmt, BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, TenderType, AuthCode); rs = pstmt.executeQuery(); while(rs.next()) @@ -102,6 +111,10 @@ public abstract class CreateFromStatement extends CreateFromBatch return data; } + /** + * set class/type of columns + * @param miniTable + */ protected void configureMiniTable(IMiniTable miniTable) { miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection @@ -115,6 +128,10 @@ public abstract class CreateFromStatement extends CreateFromBatch miniTable.autoSize(); } + /** + * Create C_BankStatementLine + */ + @Override public boolean save(IMiniTable miniTable, String trxName) { // fixed values @@ -152,6 +169,10 @@ public abstract class CreateFromStatement extends CreateFromBatch return true; } // save + /** + * + * @return column header names (select,date,payment,currency,amount,convertedAmount,bpartner) + */ protected Vector getOISColumnNames() { // Header Info diff --git a/org.adempiere.ui/src/org/compiere/grid/ICreateFrom.java b/org.adempiere.ui/src/org/compiere/grid/ICreateFrom.java index 362e258d97..53a623de12 100644 --- a/org.adempiere.ui/src/org/compiere/grid/ICreateFrom.java +++ b/org.adempiere.ui/src/org/compiere/grid/ICreateFrom.java @@ -13,13 +13,32 @@ *****************************************************************************/ package org.compiere.grid; +/** + * + * @author hengsin + * + */ public interface ICreateFrom { + /** + * + * @return true if initialization success + */ public boolean isInitOK(); + /** + * show dialog + */ public void showWindow(); + /** + * close dialog + */ public void closeWindow(); + /** + * + * @return dialog object + */ public Object getWindow(); } diff --git a/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java b/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java index 28796205e7..88cc3bb554 100644 --- a/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java +++ b/org.adempiere.ui/src/org/compiere/grid/ICreateFromFactory.java @@ -22,6 +22,11 @@ import org.compiere.model.GridTab; */ public interface ICreateFromFactory { + /** + * Create new ICreateFrom instance + * @param mTab + * @return {@link ICreateFrom} + */ public ICreateFrom create(GridTab mTab); } diff --git a/org.idempiere.test/src/org/idempiere/test/DictionaryIDs.java b/org.idempiere.test/src/org/idempiere/test/DictionaryIDs.java index 0b68c1eac8..283e3a8afd 100644 --- a/org.idempiere.test/src/org/idempiere/test/DictionaryIDs.java +++ b/org.idempiere.test/src/org/idempiere/test/DictionaryIDs.java @@ -429,6 +429,18 @@ public final class DictionaryIDs { } } + public enum M_Shipper { + UPS(100), + FERTILIZER_INTERNAL_SHIPPER(50001), + FURNITURE_INTERNAL_SHIPPER(50002); + + public final int id; + + private M_Shipper(int id) { + this.id = id; + } + } + public enum M_Warehouse { HQ(103), STORE_CENTRAL(104), diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromDepositBatchFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromDepositBatchFormTest.java new file mode 100644 index 0000000000..0855606a29 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromDepositBatchFormTest.java @@ -0,0 +1,180 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Vector; + +import org.compiere.grid.CreateFromDepositBatch; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MDepositBatch; +import org.compiere.model.MDepositBatchLine; +import org.compiere.model.MPayment; +import org.compiere.model.MQuery; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * + * @author hengsin + * + */ +public class CreateFromDepositBatchFormTest extends AbstractTestCase { + + public CreateFromDepositBatchFormTest() { + } + + @Test + public void testCreateFromDepositBatch() { + MPayment payment = new MPayment(Env.getCtx(), 0, getTrxName()); + payment.setC_DocType_ID(true); + payment.setC_BPartner_ID(DictionaryIDs.C_BPartner.JOE_BLOCK.id); + payment.setTenderType(MPayment.TENDERTYPE_DirectDebit); + int C_BankAccount_ID = DB.getSQLValueEx(getTrxName(), "SELECT C_BankAccount_ID FROM C_BankAccount WHERE IsActive='Y' AND AD_Client_ID=? " + + "AND IsDefault='Y' ORDER BY C_BankAccount_ID", getAD_Client_ID()); + payment.setC_BankAccount_ID(C_BankAccount_ID); + payment.setC_Currency_ID(Env.getContextAsInt(Env.getCtx(), Env.C_CURRENCY_ID)); + payment.setPayAmt(new BigDecimal("10.00")); + payment.saveEx(); + + ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(payment, DocAction.ACTION_Complete); + assertFalse(pi.isError(), pi.getSummary()); + + payment.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, payment.getDocStatus(), "Unexpected document status"); + + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + MDepositBatch batch = new MDepositBatch(Env.getCtx(), 0, getTrxName()); + batch.setC_BankAccount_ID(C_BankAccount_ID); + batch.setC_DocType_ID(payment.getC_DocType_ID()); + batch.setDateDeposit(today); + batch.setDateAcct(today); + batch.setDateDoc(today); + batch.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_PAYMENTS_INTO_BATCH); + assertNotNull(gridWindow, "Failed to load grid window of Payments into batch"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MDepositBatch.Table_Name); + query.addRestriction(MDepositBatch.COLUMNNAME_C_DepositBatch_ID, "=", batch.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(batch.get_ID(), gridTab.getRecord_ID(), "Wrong record id"); + + CreateFromDepositBatchImpl form = new CreateFromDepositBatchImpl(gridTab); + form.setTrxName(getTrxName()); + Timestamp dateFrom = TimeUtil.addDays(today, -1); + Timestamp dateTo = TimeUtil.addDays(today, 1); + form.loadPayments(C_BankAccount_ID, null, null, dateFrom, dateTo, null, null, payment.getC_DocType_ID(), null, null); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 2); + if (pp.getKey() == payment.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find payment record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + batch.load(getTrxName()); + MDepositBatchLine[] lines = batch.getLines(); + assertNotNull(lines, "Null deposit batch line"); + assertEquals(1, lines.length, "Unexpected number of batch lines"); + assertEquals(payment.get_ID(), lines[0].getC_Payment_ID()); + } + + private static class CreateFromDepositBatchImpl extends CreateFromDepositBatch { + + private MiniTableImpl minitable = null; + + public CreateFromDepositBatchImpl(GridTab mTab) { + super(mTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return this; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public void loadPayments(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, + String TenderType, String AuthCode) { + Vector> datas = super.getBankAccountData(BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, + TenderType, AuthCode); + + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromInvoiceFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromInvoiceFormTest.java new file mode 100644 index 0000000000..541312722f --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromInvoiceFormTest.java @@ -0,0 +1,333 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Vector; + +import org.compiere.grid.CreateFromInvoice; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MBPartner; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MProduct; +import org.compiere.model.MQuery; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * @author hengsin + * + */ +public class CreateFromInvoiceFormTest extends AbstractTestCase { + + /** + * default constructor + */ + public CreateFromInvoiceFormTest() { + } + + @Test + public void testCreateFromPurchaseOrder() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id); + order.setIsSOTrx(false); + order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInvoice invoice = new MInvoice(Env.getCtx(), 0, getTrxName()); + invoice.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + invoice.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.AP_INVOICE.id); + invoice.setIsSOTrx(false); + invoice.setSalesRep_ID(order.getSalesRep_ID()); + invoice.setC_Currency_ID(order.getC_Currency_ID()); + invoice.setDateInvoiced(today); + invoice.setDateAcct(today); + invoice.setDocAction(DocAction.ACTION_Complete); + invoice.setDocStatus(DocAction.STATUS_Drafted); + invoice.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_INVOICE_VENDOR); + assertNotNull(gridWindow, "Failed to load grid window of Invoice (Vendor)"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MInvoice.Table_Name); + query.addRestriction(MInvoice.COLUMNNAME_C_Invoice_ID, "=", invoice.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(invoice.get_ID(), gridTab.getRecord_ID(), "Wrong record id"); + + CreateFromInvoiceImpl form = new CreateFromInvoiceImpl(gridTab); + form.setTrxName(getTrxName()); + ArrayList POs = form.getOrders(order.getC_BPartner_ID()); + assertNotNull(POs, "Can't load POs for BP"); + assertTrue(POs.size() > 0, "Can't load POs for BP"); + boolean found = false; + for(KeyNamePair knp : POs) { + if (knp.getKey() == order.get_ID()) { + found = true; + break; + } + } + assertTrue(found, "Fail to load PO"); + form.loadOrderLines(order.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 5); + if (pp.getKey() == line1.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find order line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + invoice.load(getTrxName()); + MInvoiceLine[] lines = invoice.getLines(true); + assertEquals(1, lines.length, "Unexpected number of invoice lines "); + assertEquals(lines[0].getM_Product_ID(), line1.getM_Product_ID()); + assertEquals(lines[0].getQtyInvoiced().setScale(2, RoundingMode.HALF_UP), line1.getQtyOrdered().setScale(2, RoundingMode.HALF_UP)); + + info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete); + assertFalse(info.isError()); + invoice.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus()); + } + + @Test + public void testCreateFromMaterialReceipt() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id); + order.setIsSOTrx(false); + order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered()); + receipt.setDocStatus(DocAction.STATUS_Drafted); + receipt.setDocAction(DocAction.ACTION_Complete); + receipt.saveEx(); + + MInOutLine receiptLine1 = new MInOutLine(receipt); + receiptLine1.setOrderLine(line1, 0, new BigDecimal("1")); + receiptLine1.setQty(new BigDecimal("1")); + receiptLine1.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete); + assertFalse(info.isError()); + receipt.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus()); + + MInvoice invoice = new MInvoice(Env.getCtx(), 0, getTrxName()); + invoice.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + invoice.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.AP_INVOICE.id); + invoice.setIsSOTrx(false); + invoice.setSalesRep_ID(order.getSalesRep_ID()); + invoice.setC_Currency_ID(order.getC_Currency_ID()); + invoice.setDateInvoiced(today); + invoice.setDateAcct(today); + invoice.setDocAction(DocAction.ACTION_Complete); + invoice.setDocStatus(DocAction.STATUS_Drafted); + invoice.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_INVOICE_VENDOR); + assertNotNull(gridWindow, "Failed to load grid window of Invoice (Vendor)"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MInvoice.Table_Name); + query.addRestriction(MInvoice.COLUMNNAME_C_Invoice_ID, "=", invoice.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(invoice.get_ID(), gridTab.getRecord_ID(), "Wrong record id"); + + CreateFromInvoiceImpl form = new CreateFromInvoiceImpl(gridTab); + form.setTrxName(getTrxName()); + ArrayList MRs = form.getShipments(order.getC_BPartner_ID()); + assertNotNull(MRs, "Can't load MRs for BP"); + assertTrue(MRs.size() > 0, "Can't load MRs for BP"); + boolean found = false; + for(KeyNamePair knp : MRs) { + if (knp.getKey() == receipt.get_ID()) { + found = true; + break; + } + } + assertTrue(found, "Fail to load MR"); + form.loadShipmentLines(receipt.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 6); + if (pp.getKey() == receiptLine1.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find receipt line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + invoice.load(getTrxName()); + MInvoiceLine[] lines = invoice.getLines(true); + assertEquals(1, lines.length, "Unexpected number of invoice lines "); + assertEquals(lines[0].getM_Product_ID(), line1.getM_Product_ID()); + assertEquals(lines[0].getQtyInvoiced().setScale(2, RoundingMode.HALF_UP), line1.getQtyOrdered().setScale(2, RoundingMode.HALF_UP)); + + info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete); + assertFalse(info.isError()); + invoice.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus()); + } + + private static class CreateFromInvoiceImpl extends CreateFromInvoice { + + private MiniTableImpl minitable = null; + + public CreateFromInvoiceImpl(GridTab mTab) { + super(mTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return this; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public ArrayList getOrders (int C_BPartner_ID) { + return super.loadOrderData(C_BPartner_ID, true, true, false); + } + + public void loadOrderLines (int C_Order_ID) { + Vector> datas = super.getOrderData(C_Order_ID, true, false); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + + public ArrayList getShipments(int C_BPartner_ID) { + return super.loadShipmentData(C_BPartner_ID); + } + + public void loadShipmentLines(int M_InOut_ID) { + Vector> datas = super.getShipmentData(M_InOut_ID); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromPackageShipmentFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromPackageShipmentFormTest.java new file mode 100644 index 0000000000..eb46d69481 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromPackageShipmentFormTest.java @@ -0,0 +1,231 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import org.compiere.grid.CreateFromPackageShipment; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MBPartner; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MPackage; +import org.compiere.model.MPackageLine; +import org.compiere.model.MPackageMPS; +import org.compiere.model.MProduct; +import org.compiere.model.MQuery; +import org.compiere.model.MShipper; +import org.compiere.model.Query; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * @author hengsin + * + */ +public class CreateFromPackageShipmentFormTest extends AbstractTestCase { + + /** + * default constructor + */ + public CreateFromPackageShipmentFormTest() { + } + + @Test + public void testCreateFromShipmentLine() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine orderLine = new MOrderLine(order); + orderLine.setLine(10); + orderLine.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id)); + orderLine.setQty(new BigDecimal("1")); + orderLine.setDatePromised(today); + orderLine.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + order.load(getTrxName()); + assertFalse(info.isError(), info.getSummary()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInOut shipment = new MInOut(order, DictionaryIDs.C_DocType.MM_SHIPMENT.id, order.getDateOrdered()); + shipment.setDocStatus(DocAction.STATUS_Drafted); + shipment.setDocAction(DocAction.ACTION_Complete); + shipment.saveEx(); + + //shipment + MInOutLine shipmentLine = new MInOutLine(shipment); + shipmentLine.setOrderLine(orderLine, 0, new BigDecimal("1")); + shipmentLine.setQty(new BigDecimal("1")); + shipmentLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(shipment, DocAction.ACTION_Complete); + assertFalse(info.isError()); + shipment.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, shipment.getDocStatus()); + + MShipper shipper = new MShipper(Env.getCtx(), DictionaryIDs.M_Shipper.UPS.id, getTrxName()); + //package + MPackage mPackage = new MPackage(shipment, shipper); + mPackage.setBoxCount(1); + mPackage.saveEx(); + + Query q = new Query(Env.getCtx(), MPackageMPS.Table_Name, MPackageMPS.COLUMNNAME_M_Package_ID+"=?", getTrxName()); + MPackageMPS mps = q.setParameters(mPackage.getM_Package_ID()).first(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_SHIPMENT_CUSTOMER); + assertNotNull(gridWindow, "Failed to load grid window of Shipment (Customer)"); + int index = -1; + for(int i = 0; i < gridWindow.getTabCount(); i++) { + gridWindow.initTab(i); + GridTab gt = gridWindow.getTab(i); + if (gt.getAD_Table_ID() == MPackageMPS.Table_ID) { + index = i; + break; + } + } + + assertTrue(index > 0, "Failed to find Grid Tab for MPackageMPS"); + MQuery query = new MQuery(MInOut.Table_Name); + query.addRestriction(MInOut.COLUMNNAME_M_InOut_ID, "=", shipment.get_ID()); + gridWindow.getTab(0).setQuery(query); + gridWindow.getTab(0).getTableModel().setImportingMode(false, getTrxName()); + gridWindow.getTab(0).query(false); + + assertEquals(1, gridWindow.getTab(0).getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(shipment.get_ID(), gridWindow.getTab(0).getRecord_ID(), "Wrong shipment record id"); + + List gtabs = new ArrayList<>(); + gtabs.add(gridWindow.getTab(index)); + int currentLevel = gridWindow.getTab(index).getTabLevel(); + for(int i = index - 1 ; i > 0; i--) { + int level = gridWindow.getTab(i).getTabLevel(); + if (level > currentLevel) + break; + else if (level == currentLevel) + continue; + currentLevel = level; + gtabs.add(gridWindow.getTab(i)); + } + for (int i = gtabs.size()-1; i>= 0; i--) { + gtabs.get(i).getTableModel().setImportingMode(false, getTrxName()); + gtabs.get(i).query(false); + } + + assertEquals(mps.get_ID(), gridWindow.getTab(index).getValue(MPackageMPS.COLUMNNAME_M_PackageMPS_ID), "Wrong MPackageMPS record id"); + + CreateFromPackageShipmentImpl form = new CreateFromPackageShipmentImpl(gridWindow.getTab(index)); + form.setTrxName(getTrxName()); + form.loadShipmentLines(shipment.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 1); + if (pp.getKey() == shipmentLine.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find shipment line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + q = new Query(Env.getCtx(), MPackageLine.Table_Name, MPackageLine.COLUMNNAME_M_PackageMPS_ID+"=?", getTrxName()); + List pls = q.setParameters(mps.get_ID()).list(); + assertTrue(pls.size() > 0, "Failed to create new MPackageLine record"); + } + + private static class CreateFromPackageShipmentImpl extends CreateFromPackageShipment { + + private MiniTableImpl minitable = null; + + public CreateFromPackageShipmentImpl(GridTab gridTab) { + super(gridTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return this; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public void loadShipmentLines(int M_InOut_ID) { + Vector> datas = super.getShipmentData(M_InOut_ID); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromRMAFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromRMAFormTest.java new file mode 100644 index 0000000000..8239d1caf6 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromRMAFormTest.java @@ -0,0 +1,202 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Vector; + +import org.compiere.grid.CreateFromRMA; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MBPartner; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MProduct; +import org.compiere.model.MQuery; +import org.compiere.model.MRMA; +import org.compiere.model.MRMALine; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * @author hengsin + * + */ +public class CreateFromRMAFormTest extends AbstractTestCase { + + /** + * default constructor + */ + public CreateFromRMAFormTest() { + } + + @Test + public void testCreateFromShipmentLine() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id); + order.setIsSOTrx(false); + order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine orderLine = new MOrderLine(order); + orderLine.setLine(10); + orderLine.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id)); + orderLine.setQty(new BigDecimal("1")); + orderLine.setDatePromised(today); + orderLine.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered()); + receipt.setDocStatus(DocAction.STATUS_Drafted); + receipt.setDocAction(DocAction.ACTION_Complete); + receipt.saveEx(); + + MInOutLine receiptLine = new MInOutLine(receipt); + receiptLine.setOrderLine(orderLine, 0, new BigDecimal("1")); + receiptLine.setQty(new BigDecimal("1")); + receiptLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete); + assertFalse(info.isError()); + receipt.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus()); + + MRMA rma = new MRMA(Env.getCtx(), 0, getTrxName()); + rma.setM_InOut_ID(receipt.getM_InOut_ID()); + rma.setC_BPartner_ID(receipt.getC_BPartner_ID()); + rma.setC_Currency_ID(order.getC_Currency_ID()); + rma.setIsSOTrx(false); + rma.setName("testVendorRMA"); + rma.setC_DocType_ID(DictionaryIDs.C_DocType.VENDOR_RETURN_MATERIAL.id); + rma.setSalesRep_ID(order.getSalesRep_ID()); + rma.setM_RMAType_ID(DictionaryIDs.M_RMAType.DAMAGE_ON_ARRIVAL.id); + rma.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_VENDOR_RMA); + assertNotNull(gridWindow, "Failed to load grid window of Vendor RMA"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MRMA.Table_Name); + query.addRestriction(MRMA.COLUMNNAME_M_RMA_ID, "=", rma.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(rma.get_ID(), gridTab.getRecord_ID(), "Wrong RMA record id"); + + CreateFromRMAImpl form = new CreateFromRMAImpl(gridTab); + form.setTrxName(getTrxName()); + form.loadShipmentLines(); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 1); + if (pp.getKey() == receiptLine.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find receipt line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + rma.load(getTrxName()); + MRMALine[] rmaLines = rma.getLines(true); + assertEquals(1, rmaLines.length, "Unexpected number of RMA Line records"); + assertEquals(receiptLine.get_ID(), rmaLines[0].getM_InOutLine_ID(), "Materia receipt line not match to RMA line"); + } + + private static class CreateFromRMAImpl extends CreateFromRMA { + + private MiniTableImpl minitable = null; + + public CreateFromRMAImpl(GridTab mTab) { + super(mTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return null; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public void loadShipmentLines() { + Vector> datas = super.getRMAData(); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromShipmentFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromShipmentFormTest.java new file mode 100644 index 0000000000..bf86195ee8 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromShipmentFormTest.java @@ -0,0 +1,446 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Vector; + +import org.compiere.grid.CreateFromShipment; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MBPartner; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MLocator; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MProduct; +import org.compiere.model.MQuery; +import org.compiere.model.MRMA; +import org.compiere.model.MRMALine; +import org.compiere.model.MWarehouse; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * @author hengsin + * + */ +public class CreateFromShipmentFormTest extends AbstractTestCase { + + /** + * default constructor + */ + public CreateFromShipmentFormTest() { + } + + @Test + public void testCreateFromOrderLine() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id); + order.setIsSOTrx(false); + order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine orderLine = new MOrderLine(order); + orderLine.setLine(10); + orderLine.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id)); + orderLine.setQty(new BigDecimal("1")); + orderLine.setDatePromised(today); + orderLine.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered()); + receipt.setDocStatus(DocAction.STATUS_Drafted); + receipt.setDocAction(DocAction.ACTION_Complete); + receipt.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_MATERIAL_RECEIPT); + assertNotNull(gridWindow, "Failed to load grid window of Material Receipt"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MInOut.Table_Name); + query.addRestriction(MInOut.COLUMNNAME_M_InOut_ID, "=", receipt.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(receipt.get_ID(), gridTab.getRecord_ID(), "Wrong Material Receipt record id"); + + CreateFromShipmentImpl form = new CreateFromShipmentImpl(gridTab); + form.setTrxName(getTrxName()); + ArrayList orders = form.getOrders(order.getC_BPartner_ID()); + assertNotNull(orders, "Can't load Orders for BP"); + assertTrue(orders.size() > 0, "Can't load Orders for BP"); + boolean found = false; + for(KeyNamePair knp : orders) { + if (knp.getKey() == order.get_ID()) { + found = true; + break; + } + } + assertTrue(found, "Fail to load Order"); + + form.loadOrderLines(order.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 6); + if (pp.getKey() == orderLine.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find order line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + receipt.load(getTrxName()); + MInOutLine[] receiptLines = receipt.getLines(true); + assertEquals(1, receiptLines.length, "Unexpected number of Material Receipt Line records"); + assertEquals(orderLine.get_ID(), receiptLines[0].getC_OrderLine_ID(), "Order line not match to material receipt line"); + } + + @Test + public void testCreateFromInvoiceLine() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id)); + order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id); + order.setIsSOTrx(false); + order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine orderLine = new MOrderLine(order); + orderLine.setLine(10); + orderLine.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id)); + orderLine.setQty(new BigDecimal("1")); + orderLine.setDatePromised(today); + orderLine.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, today); + invoice.saveEx(); + MInvoiceLine invoiceLine = new MInvoiceLine(invoice); + invoiceLine.setOrderLine(orderLine); + invoiceLine.setQty(new BigDecimal("1")); + invoiceLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + invoice.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus()); + + MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered()); + receipt.setDocStatus(DocAction.STATUS_Drafted); + receipt.setDocAction(DocAction.ACTION_Complete); + receipt.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_MATERIAL_RECEIPT); + assertNotNull(gridWindow, "Failed to load grid window of Material Receipt"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MInOut.Table_Name); + query.addRestriction(MInOut.COLUMNNAME_M_InOut_ID, "=", receipt.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(receipt.get_ID(), gridTab.getRecord_ID(), "Wrong Material Receipt record id"); + + CreateFromShipmentImpl form = new CreateFromShipmentImpl(gridTab); + form.setTrxName(getTrxName()); + ArrayList invoices = form.getInvoices(order.getC_BPartner_ID()); + assertNotNull(invoices, "Can't load Invoices for BP"); + assertTrue(invoices.size() > 0, "Can't load Invoices for BP"); + boolean found = false; + for(KeyNamePair knp : invoices) { + if (knp.getKey() == invoice.get_ID()) { + found = true; + break; + } + } + assertTrue(found, "Fail to load Invoice"); + + form.loadInvoiceLines(invoice.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 8); + if (pp.getKey() == invoiceLine.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find invoice line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + receipt.load(getTrxName()); + MInOutLine[] receiptLines = receipt.getLines(true); + assertEquals(1, receiptLines.length, "Unexpected number of Material Receipt Line records"); + invoiceLine.load(getTrxName()); + assertEquals(invoiceLine.getM_InOutLine_ID(), receiptLines[0].get_ID(), "Invoice line not match to material receipt line"); + } + + @Test + public void testCreateFromCustomerRMALines() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.setSalesRep_ID(getAD_User_ID()); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus(), "Unexpected Document Status"); + line1.load(getTrxName()); + assertEquals(1, line1.getQtyReserved().intValue()); + + MInOut shipment = new MInOut(order, DictionaryIDs.C_DocType.MM_SHIPMENT.id, order.getDateOrdered()); + shipment.setDocStatus(DocAction.STATUS_Drafted); + shipment.setDocAction(DocAction.ACTION_Complete); + shipment.saveEx(); + + MInOutLine shipmentLine = new MInOutLine(shipment); + shipmentLine.setOrderLine(line1, 0, new BigDecimal("1")); + shipmentLine.setQty(new BigDecimal("1")); + shipmentLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(shipment, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + shipment.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, shipment.getDocStatus(), "Unexpected Document Status"); + + MRMA rma = new MRMA(Env.getCtx(), 0, getTrxName()); + rma.setC_BPartner_ID(order.getC_BPartner_ID()); + rma.setM_InOut_ID(shipment.getM_InOut_ID()); + rma.setC_DocType_ID(DictionaryIDs.C_DocType.CUSTOMER_RETURN_MATERIAL.id); + rma.setC_Currency_ID(order.getC_Currency_ID()); + rma.setName("testCreateFromCustomerRMALines"); + rma.setIsSOTrx(true); + rma.setSalesRep_ID(order.getSalesRep_ID()); + rma.setM_RMAType_ID(DictionaryIDs.M_RMAType.DAMAGE_ON_ARRIVAL.id); + rma.saveEx(); + + MRMALine rmaLine = new MRMALine(Env.getCtx(), 0, getTrxName()); + rmaLine.setM_RMA_ID(rma.get_ID()); + rmaLine.setM_InOutLine_ID(shipmentLine.get_ID()); + rmaLine.setM_Product_ID(shipmentLine.getM_Product_ID()); + rmaLine.setQty(new BigDecimal("1")); + rmaLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(rma, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + rma.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, rma.getDocStatus(), "Unexpected Document Status"); + + MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered()); + receipt.setDocStatus(DocAction.STATUS_Drafted); + receipt.setDocAction(DocAction.ACTION_Complete); + receipt.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_MATERIAL_RECEIPT); + assertNotNull(gridWindow, "Failed to load grid window of Material Receipt"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MInOut.Table_Name); + query.addRestriction(MInOut.COLUMNNAME_M_InOut_ID, "=", receipt.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(receipt.get_ID(), gridTab.getRecord_ID(), "Wrong Material Receipt record id"); + + CreateFromShipmentImpl form = new CreateFromShipmentImpl(gridTab); + form.setTrxName(getTrxName()); + ArrayList RMAs = form.getRMAs(order.getC_BPartner_ID()); + assertNotNull(RMAs, "Can't load RMAs for BP"); + assertTrue(RMAs.size() > 0, "Can't load RMAsfor BP"); + boolean found = false; + for(KeyNamePair knp : RMAs) { + if (knp.getKey() == rma.get_ID()) { + found = true; + break; + } + } + assertTrue(found, "Fail to load RMA"); + + form.loadRMALines(rma.get_ID()); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 7); + if (pp.getKey() == rmaLine.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find RMA line record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + receipt.load(getTrxName()); + MInOutLine[] receiptLines = receipt.getLines(true); + assertEquals(1, receiptLines.length, "Unexpected number of Material Receipt Line records"); + rmaLine.load(getTrxName()); + assertEquals(rmaLine.get_ID(), receiptLines[0].getM_RMALine_ID(), "RMA line not match to material receipt line"); + } + + private static class CreateFromShipmentImpl extends CreateFromShipment { + + private MiniTableImpl minitable = null; + + public CreateFromShipmentImpl(GridTab mTab) { + super(mTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return null; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public ArrayList getOrders(int C_BPartner_ID) { + return super.loadOrderData(C_BPartner_ID, false, true, false); + } + + public void loadOrderLines(int C_Order_ID) { + Vector> datas = super.getOrderData(C_Order_ID, false, MLocator.getDefault(MWarehouse.get(getM_Warehouse_ID())).getM_Locator_ID()); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + + public ArrayList getInvoices(int C_BPartner_ID) { + return super.loadInvoiceData(C_BPartner_ID); + } + + public void loadInvoiceLines(int C_Invoice_ID) { + Vector> datas = super.getInvoiceData(C_Invoice_ID, MLocator.getDefault(MWarehouse.get(getM_Warehouse_ID())).getM_Locator_ID()); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + + public ArrayList getRMAs(int C_BPartner_ID) { + return super.loadRMAData(C_BPartner_ID); + } + + public void loadRMALines(int M_RMA_ID) { + Vector> datas = super.getRMAData(M_RMA_ID, MLocator.getDefault(MWarehouse.get(getM_Warehouse_ID())).getM_Locator_ID()); + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/form/CreateFromStatementFormTest.java b/org.idempiere.test/src/org/idempiere/test/form/CreateFromStatementFormTest.java new file mode 100644 index 0000000000..4db6436b6a --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/form/CreateFromStatementFormTest.java @@ -0,0 +1,180 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.form; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Vector; + +import org.compiere.grid.CreateFromStatement; +import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.MBankStatement; +import org.compiere.model.MBankStatementLine; +import org.compiere.model.MPayment; +import org.compiere.model.MQuery; +import org.compiere.model.SystemIDs; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.idempiere.test.DictionaryIDs; +import org.idempiere.test.ui.MiniTableImpl; +import org.junit.jupiter.api.Test; + +/** + * @author hengsin + * + */ +public class CreateFromStatementFormTest extends AbstractTestCase { + + /** + * default constructor + */ + public CreateFromStatementFormTest() { + } + + @Test + public void testCreateFromPayments() { + MPayment payment = new MPayment(Env.getCtx(), 0, getTrxName()); + payment.setC_DocType_ID(true); + payment.setC_BPartner_ID(DictionaryIDs.C_BPartner.JOE_BLOCK.id); + payment.setTenderType(MPayment.TENDERTYPE_DirectDebit); + int C_BankAccount_ID = DB.getSQLValueEx(getTrxName(), "SELECT C_BankAccount_ID FROM C_BankAccount WHERE IsActive='Y' AND AD_Client_ID=? " + + "AND IsDefault='Y' ORDER BY C_BankAccount_ID", getAD_Client_ID()); + payment.setC_BankAccount_ID(C_BankAccount_ID); + payment.setC_Currency_ID(Env.getContextAsInt(Env.getCtx(), Env.C_CURRENCY_ID)); + payment.setPayAmt(new BigDecimal("10.00")); + payment.saveEx(); + + ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(payment, DocAction.ACTION_Complete); + assertFalse(pi.isError(), pi.getSummary()); + payment.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, payment.getDocStatus(), "Unexpected document status"); + + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + MBankStatement stmt = new MBankStatement(Env.getCtx(), 0, getTrxName()); + stmt.setC_BankAccount_ID(C_BankAccount_ID); + stmt.setDateAcct(today); + stmt.setName("testCreateFromPayments"); + stmt.setStatementDate(today); + stmt.saveEx(); + + GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_BANK_STATEMENT); + assertNotNull(gridWindow, "Failed to load grid window of Bank Statement"); + gridWindow.initTab(0); + GridTab gridTab = gridWindow.getTab(0); + MQuery query = new MQuery(MBankStatement.Table_Name); + query.addRestriction(MBankStatement.COLUMNNAME_C_BankStatement_ID, "=", stmt.get_ID()); + gridTab.setQuery(query); + gridTab.getTableModel().setImportingMode(false, getTrxName()); + gridTab.query(false); + + assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB"); + assertEquals(stmt.get_ID(), gridTab.getRecord_ID(), "Wrong Bank Statement record id"); + + CreateFromStatementImpl form = new CreateFromStatementImpl(gridTab); + form.setTrxName(getTrxName()); + + Timestamp dateFrom = TimeUtil.addDays(today, -1); + Timestamp dateTo = TimeUtil.addDays(today, 1); + form.loadPayments(C_BankAccount_ID, null, null, dateFrom, dateTo, null, null, payment.getC_DocType_ID(), null, null); + assertTrue(form.minitable.getRowCount() > 0, "Failed to load data from DB"); + + form.minitable.setSelectedRow(-1); + for (int i = 0; i < form.minitable.getRowCount(); i++) { + KeyNamePair pp = (KeyNamePair) form.minitable.getValueAt(i, 2); + if (pp.getKey() == payment.get_ID()) { + form.minitable.setValueAt(Boolean.TRUE, i, 0); + form.minitable.setSelectedRow(i); + break; + } + } + + assertTrue(form.minitable.getSelectedRow() >= 0, "Failed to find payment record"); + assertTrue(form.save(form.minitable, getTrxName()), "Failed to save changes"); + + stmt.load(getTrxName()); + MBankStatementLine[] lines = stmt.getLines(true); + assertNotNull(lines, "Null bank statement line"); + assertEquals(1, lines.length, "Unexpected number of bank statement line records"); + assertEquals(payment.get_ID(), lines[0].getC_Payment_ID()); + } + + private static class CreateFromStatementImpl extends CreateFromStatement { + + private MiniTableImpl minitable = null; + + public CreateFromStatementImpl(GridTab mTab) { + super(mTab); + + try { + dynInit(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public Object getWindow() { + return null; + } + + @Override + protected boolean dynInit() throws Exception { + super.dynInit(); + minitable = new MiniTableImpl(); + for(String column : getOISColumnNames()) { + minitable.addColumn(column); + } + configureMiniTable(minitable); + return true; + } + + public void loadPayments(Integer BankAccount, Integer BPartner, String DocumentNo, + Timestamp DateFrom, Timestamp DateTo, BigDecimal AmtFrom, BigDecimal AmtTo, Integer DocType, + String TenderType, String AuthCode) { + Vector> datas = super.getBankAccountData(BankAccount, BPartner, DocumentNo, DateFrom, DateTo, AmtFrom, AmtTo, DocType, + TenderType, AuthCode); + + for(int i = 0; i < datas.size(); i++) { + minitable.setRowCount(i+1); + Vector data = datas.get(i); + for(int j = 0; j < data.size(); j++) { + minitable.setValueAt(data.get(j), i, j); + } + } + } + } +}