parent
c19c0db2e0
commit
af724af2fd
|
|
@ -3,14 +3,14 @@ package andromedia.midsuit.factory;
|
|||
import org.compiere.grid.ICreateFrom;
|
||||
import org.compiere.grid.ICreateFromFactory;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MInOut;
|
||||
import org.compiere.model.MInvoice;
|
||||
import org.compiere.model.X_C_Invoice;
|
||||
import org.compiere.model.X_C_Order;
|
||||
import org.compiere.model.X_M_InOut;
|
||||
import org.compiere.model.X_M_RMA;
|
||||
|
||||
import andromedia.midsuit.form.MID_WCreateFromInvoice;
|
||||
import andromedia.midsuit.form.MID_WCreateFromOrder;
|
||||
import andromedia.midsuit.form.MID_WCreateFromRMA;
|
||||
import andromedia.midsuit.form.MID_WCreateFromShipment;
|
||||
|
||||
public class MID_CreateFromFactory implements ICreateFromFactory{
|
||||
|
|
@ -23,7 +23,8 @@ public class MID_CreateFromFactory implements ICreateFromFactory{
|
|||
return new MID_WCreateFromShipment(mTab);
|
||||
if (tableName.equals(X_C_Invoice.Table_Name))
|
||||
return new MID_WCreateFromInvoice(mTab);
|
||||
|
||||
if (tableName.equals(X_M_RMA.Table_Name))
|
||||
return new MID_WCreateFromRMA(mTab);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package andromedia.midsuit.form;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.apps.IStatusBar;
|
||||
import org.compiere.grid.CreateFrom;
|
||||
import org.compiere.minigrid.IMiniTable;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MInOutLine;
|
||||
import org.compiere.model.MInOutLineMA;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.model.MRMALine;
|
||||
import org.compiere.model.MStorageOnHand;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_M_InOutLineMA;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
import andromedia.midsuit.model.X_C_OrderLineMA;
|
||||
import andromedia.midsuit.model.X_M_RMAMA;
|
||||
|
||||
/**
|
||||
* Create Transactions for RMA
|
||||
* @author ashley
|
||||
* @author Teo Sarca, www.arhipac.ro
|
||||
* <li>BF [ 2007837 ] VCreateFrom.save() should run in trx
|
||||
*/
|
||||
public abstract class MID_CreateFromRMA extends CreateFrom {
|
||||
|
||||
public MID_CreateFromRMA(GridTab mTab)
|
||||
{
|
||||
super(mTab);
|
||||
if (log.isLoggable(Level.INFO)) log.info(mTab.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dynInit() throws Exception
|
||||
{
|
||||
log.config("");
|
||||
setTitle(Msg.getElement(Env.getCtx(), "M_RMA_ID") + " .. " + Msg.translate(Env.getCtx(), "CreateFrom"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Vector<Vector<Object>> getRMAData()
|
||||
{
|
||||
int M_InOut_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "InOut_ID");
|
||||
int M_RMA_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "M_RMA_ID");
|
||||
|
||||
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
|
||||
|
||||
/**
|
||||
* 1 M_InOutLine_ID
|
||||
* 2 Line
|
||||
* 3 Product Name
|
||||
* 4 Qty Entered
|
||||
* 5 Movement Qty
|
||||
* 6 ASI
|
||||
*/
|
||||
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("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 ");
|
||||
sqlStmt.append("LEFT JOIN M_Product p ON p.M_Product_ID = iol.M_Product_ID ");
|
||||
sqlStmt.append("LEFT JOIN C_Charge c ON c.C_Charge_ID = iol.C_Charge_ID ");
|
||||
sqlStmt.append("WHERE M_InOut_ID=? ");
|
||||
sqlStmt.append("AND iol.M_InOutLine_ID NOT IN (SELECT rmal.M_InOutLine_ID FROM M_RMALine rmal WHERE rmal.M_RMA_ID=?)");
|
||||
sqlStmt.append(" ORDER BY iol.Line " );
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sqlStmt.toString(), null);
|
||||
pstmt.setInt(1, M_InOut_ID);
|
||||
pstmt.setInt(2, M_RMA_ID);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
Vector<Object> line = new Vector<Object>(8);
|
||||
line.add(new Boolean(false)); // 0-Selection
|
||||
|
||||
KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // 1-Line
|
||||
line.add(lineKNPair);
|
||||
line.add(rs.getString(3)); //2-Product
|
||||
line.add(rs.getString(6)); //3-ASI
|
||||
|
||||
BigDecimal qtyEntered = rs.getBigDecimal(4);
|
||||
BigDecimal movementQty = rs.getBigDecimal(5);
|
||||
|
||||
line.add(qtyEntered); //4-Qty
|
||||
line.add(movementQty); //5-Movement Qty
|
||||
|
||||
line.add(rs.getString(7)); // 6 - Description
|
||||
data.add(line);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sqlStmt.toString(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null;
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(IMiniTable miniTable, IStatusBar statusBar)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void configureMiniTable (IMiniTable miniTable)
|
||||
{
|
||||
miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection
|
||||
miniTable.setColumnClass(1, String.class, true); // 1-Line
|
||||
miniTable.setColumnClass(2, String.class, true); // 2-Product
|
||||
miniTable.setColumnClass(3, String.class, true); // 3-ASI
|
||||
miniTable.setColumnClass(4, BigDecimal.class, true); // 4-Qty
|
||||
miniTable.setColumnClass(5, BigDecimal.class, false); // 5-Delivered Qty
|
||||
miniTable.setColumnClass(6, String.class, true); // 6-Description
|
||||
|
||||
// Table UI
|
||||
miniTable.autoSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(IMiniTable miniTable, String trxName)
|
||||
{
|
||||
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
|
||||
|
||||
int inOutLineId = pp.getKey();
|
||||
MInOutLine iol = new MInOutLine(rma.getCtx(), inOutLineId, rma.get_TrxName());
|
||||
MRMALine rmaLine = new MRMALine(rma.getCtx(), 0, rma.get_TrxName());
|
||||
rmaLine.setM_RMA_ID(M_RMA_ID);
|
||||
rmaLine.setM_InOutLine_ID(inOutLineId);
|
||||
rmaLine.setQty(d);
|
||||
rmaLine.setAD_Org_ID(rma.getAD_Org_ID());
|
||||
rmaLine.setDescription((String)miniTable.getValueAt(i, 6));
|
||||
List<X_M_InOutLineMA> attLines = new Query(Env.getCtx(), X_M_InOutLineMA.Table_Name, "M_InOutLine_ID =?", trxName)
|
||||
.setParameters(new Object[] { inOutLineId })
|
||||
.setOnlyActiveRecords(true)
|
||||
.list();
|
||||
log.severe(iol.getM_AttributeSetInstance_ID()+" ");
|
||||
if(attLines.size()<=0)
|
||||
rmaLine.set_ValueNoCheck("M_AttributeSetInstance_ID", iol.getM_AttributeSetInstance_ID());
|
||||
else {
|
||||
for(X_M_InOutLineMA attLine : attLines) {
|
||||
X_M_RMAMA inoutAtt = new X_M_RMAMA(rma.getCtx(), 0, rma.get_TrxName());
|
||||
inoutAtt.setAD_Org_ID(attLine.getAD_Org_ID());
|
||||
inoutAtt.setM_InOutLine_ID(iol.getM_InOutLine_ID());
|
||||
inoutAtt.setIsAutoGenerated(false);
|
||||
inoutAtt.setM_AttributeSetInstance_ID(attLine.getM_AttributeSetInstance_ID());
|
||||
inoutAtt.setMovementQty(attLine.getMovementQty());
|
||||
inoutAtt.setDateMaterialPolicy(attLine.getDateMaterialPolicy());
|
||||
inoutAtt.saveEx();
|
||||
}
|
||||
}
|
||||
|
||||
if (!rmaLine.save())
|
||||
{
|
||||
throw new IllegalStateException("Could not create RMA Line");
|
||||
}
|
||||
}
|
||||
}
|
||||
rma.saveEx();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Vector<String> getOISColumnNames()
|
||||
{
|
||||
// Header Info
|
||||
Vector<String> columnNames = new Vector<String>(7);
|
||||
columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "Line"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "SerNo"));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "Quantity"));
|
||||
columnNames.add(Msg.getElement(Env.getCtx(), "QtyDelivered", false));
|
||||
columnNames.add(Msg.translate(Env.getCtx(), "Description"));
|
||||
|
||||
return columnNames;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2009 Low Heng Sin *
|
||||
* Copyright (C) 2009 Idalica Corporation *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package andromedia.midsuit.form;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.ClientInfo;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.apps.form.WCreateFromWindow;
|
||||
import org.adempiere.webui.component.Grid;
|
||||
import org.adempiere.webui.component.GridFactory;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.ListModelTable;
|
||||
import org.adempiere.webui.component.Panel;
|
||||
import org.adempiere.webui.component.Row;
|
||||
import org.adempiere.webui.component.Rows;
|
||||
import org.adempiere.webui.editor.WEditor;
|
||||
import org.adempiere.webui.editor.WSearchEditor;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.event.ValueChangeListener;
|
||||
import org.adempiere.webui.util.ZKUpdateUtil;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
|
||||
import static org.compiere.model.SystemIDs.*;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
public class MID_WCreateFromRMA extends MID_CreateFromRMA implements ValueChangeListener
|
||||
{
|
||||
private WCreateFromWindow window;
|
||||
|
||||
public MID_WCreateFromRMA(GridTab tab)
|
||||
{
|
||||
super(tab);
|
||||
log.info(getGridTab().toString());
|
||||
|
||||
window = new WCreateFromWindow(this, getGridTab().getWindowNo());
|
||||
|
||||
p_WindowNo = getGridTab().getWindowNo();
|
||||
|
||||
try
|
||||
{
|
||||
if (!dynInit())
|
||||
return;
|
||||
zkInit();
|
||||
setInitOK(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
setInitOK(false);
|
||||
}
|
||||
AEnv.showWindow(window);
|
||||
}
|
||||
|
||||
/** Window No */
|
||||
private int p_WindowNo;
|
||||
|
||||
/** Logger */
|
||||
private CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
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
|
||||
{
|
||||
log.config("");
|
||||
|
||||
super.dynInit();
|
||||
|
||||
window.setTitle(getTitle());
|
||||
|
||||
initBPartner(true);
|
||||
bPartnerField.addValueChangeListener(this);
|
||||
|
||||
loadRMA();
|
||||
|
||||
return true;
|
||||
} // dynInit
|
||||
|
||||
protected void zkInit() throws Exception
|
||||
{
|
||||
bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID"));
|
||||
|
||||
Panel parameterPanel = window.getParameterPanel();
|
||||
|
||||
Grid parameterStdLayout = GridFactory.newGridLayout();
|
||||
Panel parameterStdPanel = new Panel();
|
||||
parameterStdPanel.appendChild(parameterStdLayout);
|
||||
|
||||
parameterPanel.appendChild(parameterStdPanel);
|
||||
ZKUpdateUtil.setVflex(parameterStdLayout, "min");
|
||||
|
||||
Rows rows = (Rows) parameterStdLayout.newRows();
|
||||
Row row = rows.newRow();
|
||||
row.appendChild(bPartnerLabel.rightAlign());
|
||||
if (bPartnerField != null)
|
||||
row.appendChild(bPartnerField.getComponent());
|
||||
|
||||
if (ClientInfo.isMobile()) {
|
||||
ClientInfo.onClientInfo(window, this::onClientInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void valueChange (ValueChangeEvent e)
|
||||
{
|
||||
if (log.isLoggable(Level.CONFIG)) log.config(e.getPropertyName() + "=" + e.getNewValue());
|
||||
|
||||
// BPartner - load Order/Invoice/Shipment
|
||||
if (e.getPropertyName().equals("C_BPartner_ID"))
|
||||
{
|
||||
loadRMA();
|
||||
}
|
||||
window.tableChanged(null);
|
||||
} // vetoableChange
|
||||
|
||||
/**************************************************************************
|
||||
* Load BPartner Field
|
||||
* @param forInvoice true if Invoices are to be created, false receipts
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
protected void initBPartner (boolean forInvoice) throws Exception
|
||||
{
|
||||
// load BPartner
|
||||
int AD_Column_ID = COLUMN_C_INVOICE_C_BPARTNER_ID; // C_Invoice.C_BPartner_ID
|
||||
MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.Search);
|
||||
bPartnerField = new WSearchEditor ("C_BPartner_ID", true, false, true, lookup);
|
||||
//
|
||||
int C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BPartner_ID");
|
||||
bPartnerField.setValue(new Integer(C_BPartner_ID));
|
||||
} // initBPartner
|
||||
|
||||
protected void loadRMA()
|
||||
{
|
||||
loadTableOIS(getRMAData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Order/Invoice/Shipment data into Table
|
||||
* @param data data
|
||||
*/
|
||||
protected void loadTableOIS (Vector<?> data)
|
||||
{
|
||||
window.getWListbox().clear();
|
||||
|
||||
// Remove previous listeners
|
||||
window.getWListbox().getModel().removeTableModelListener(window);
|
||||
// Set Model
|
||||
ListModelTable model = new ListModelTable(data);
|
||||
model.addTableModelListener(window);
|
||||
window.getWListbox().setData(model, getOISColumnNames());
|
||||
//
|
||||
|
||||
configureMiniTable(window.getWListbox());
|
||||
} // loadOrder
|
||||
|
||||
public void showWindow()
|
||||
{
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
public void closeWindow()
|
||||
{
|
||||
window.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
protected void onClientInfo() {
|
||||
ZKUpdateUtil.setCSSHeight(window);
|
||||
ZKUpdateUtil.setCSSWidth(window);
|
||||
window.invalidate();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue