Generate Landed cost in Invoice
This commit is contained in:
parent
835ff26f95
commit
34c2f9db0a
|
|
@ -0,0 +1,88 @@
|
|||
package andromedia.midsuit.factory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.adempiere.base.IModelFactory;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
import andromedia.midsuit.model.MID_Aging;
|
||||
import andromedia.midsuit.model.MID_MRequisitionTrx;
|
||||
import andromedia.midsuit.model.MID_MRequisitionTrxLine;
|
||||
import andromedia.midsuit.model.MID_PPO;
|
||||
import andromedia.midsuit.model.X_zpos_Cashier;
|
||||
|
||||
public class MID_ModelFactory implements IModelFactory{
|
||||
private static HashMap<String, String> mapTableModels = new HashMap<String, String>();
|
||||
static {
|
||||
//Ex mapTableModels.put(MOrderLine.Table_Name, "org.semeru.project.model.SMT_MOrderLine");
|
||||
mapTableModels.put(MID_MRequisitionTrx.Table_Name, "andromedia.midsuit.model.MID_MRequisitionTrx");
|
||||
mapTableModels.put(MID_MRequisitionTrxLine.Table_Name, "andromedia.midsuit.model.MID_MRequisitionTrxLine");
|
||||
mapTableModels.put(X_zpos_Cashier.Table_Name, "andromedia.midsuit.model.X_zpos_Cashier");
|
||||
<<<<<<< working copy
|
||||
mapTableModels.put(MID_Aging.Table_Name, "andromedia.midsuit.model.MID_Aging");
|
||||
=======
|
||||
// mapTableModels.put(MID_Aging.Table_Name, "andromedia.midsuit.model.MID_Aging");
|
||||
mapTableModels.put(MID_PPO.Table_Name, "andromedia.midsuit.model.MID_PPO");
|
||||
>>>>>>> merge rev
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getClass(String tableName) {
|
||||
if (mapTableModels.containsKey(tableName)) {
|
||||
Class<?> act = null;
|
||||
try {
|
||||
act = Class.forName(mapTableModels.get(tableName));
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return act;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PO getPO(String tableName, int Record_ID, String trxName) {
|
||||
if (mapTableModels.containsKey(tableName)) {
|
||||
Class<?> clazz = null;
|
||||
Constructor<?> ctor = null;
|
||||
PO object = null;
|
||||
try {
|
||||
clazz = Class.forName(mapTableModels.get(tableName));
|
||||
ctor = clazz.getConstructor(Properties.class, int.class, String.class);
|
||||
object = (PO) ctor.newInstance(new Object[] { Env.getCtx(), Record_ID, trxName });
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return object;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PO getPO(String tableName, ResultSet rs, String trxName) {
|
||||
if (mapTableModels.containsKey(tableName)) {
|
||||
Class<?> clazz = null;
|
||||
Constructor<?> ctor = null;
|
||||
PO object = null;
|
||||
try {
|
||||
clazz = Class.forName(mapTableModels.get(tableName));
|
||||
ctor = clazz.getConstructor(Properties.class, ResultSet.class, String.class);
|
||||
object = (PO) ctor.newInstance(new Object[] { Env.getCtx(), rs, trxName });
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return object;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -707,7 +707,8 @@ public abstract class MID_CreateFromShipment extends CreateFrom
|
|||
inout.setC_Activity_ID(p_order.getC_Activity_ID());
|
||||
inout.setUser1_ID(p_order.getUser1_ID());
|
||||
inout.setUser2_ID(p_order.getUser2_ID());
|
||||
|
||||
inout.setDateOrdered(p_order.getDateOrdered());
|
||||
|
||||
if ( p_order.isDropShip() )
|
||||
{
|
||||
inout.setM_Warehouse_ID( p_order.getM_Warehouse_ID() );
|
||||
|
|
|
|||
|
|
@ -0,0 +1,317 @@
|
|||
/******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.ClientInfo;
|
||||
import org.adempiere.webui.LayoutUtils;
|
||||
import org.adempiere.webui.apps.form.WGenForm;
|
||||
import org.adempiere.webui.component.Column;
|
||||
import org.adempiere.webui.component.Columns;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.ListboxFactory;
|
||||
import org.adempiere.webui.component.Row;
|
||||
import org.adempiere.webui.editor.WDateEditor;
|
||||
import org.adempiere.webui.editor.WSearchEditor;
|
||||
import org.adempiere.webui.editor.WTableDirEditor;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.event.ValueChangeListener;
|
||||
import org.adempiere.webui.panel.ADForm;
|
||||
import org.adempiere.webui.panel.IFormController;
|
||||
import org.adempiere.webui.util.ZKUpdateUtil;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MLookupFactory;
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MRMA;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zul.North;
|
||||
|
||||
import andromedia.midsuit.grid.InvoiceLandedCost;
|
||||
|
||||
/**
|
||||
* Generate Shipment (manual) view class
|
||||
*
|
||||
*/
|
||||
public class WInvoiceLandedCost extends InvoiceLandedCost implements IFormController, EventListener<Event>, ValueChangeListener
|
||||
{
|
||||
private WGenForm form;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WInvoiceLandedCost.class);
|
||||
|
||||
// Adding C_OrderDate -- Rizky
|
||||
private Label lOrderDate = new Label();
|
||||
private WDateEditor fOrderDate = new WDateEditor();
|
||||
|
||||
private Label lBPartner = new Label();
|
||||
private WSearchEditor fBPartner;
|
||||
private Label lDocType = new Label();
|
||||
private Listbox cmbDocType = ListboxFactory.newDropdownListbox();
|
||||
private Label lDocAction = new Label();
|
||||
private WTableDirEditor docAction;
|
||||
|
||||
private int noOfColumn;
|
||||
|
||||
public WInvoiceLandedCost()
|
||||
{
|
||||
log.info("");
|
||||
|
||||
form = new WGenForm(this);
|
||||
Env.setContext(Env.getCtx(), form.getWindowNo(), "IsSOTrx", "Y");
|
||||
|
||||
try
|
||||
{
|
||||
super.dynInit();
|
||||
dynInit();
|
||||
zkInit();
|
||||
|
||||
form.postQueryEvent();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "init", ex);
|
||||
}
|
||||
|
||||
ClientInfo.onClientInfo(form, this::onClientInfo);
|
||||
} // init
|
||||
|
||||
/**
|
||||
* Static Init.
|
||||
* <pre>
|
||||
* selPanel (tabbed)
|
||||
* fOrg, fBPartner
|
||||
* scrollPane & miniTable
|
||||
* genPanel
|
||||
* info
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
*/
|
||||
void zkInit() throws Exception
|
||||
{
|
||||
setupColumns();
|
||||
lOrderDate.setText("Order Date");
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
|
||||
Row row = form.getParameterPanel().newRows().newRow();
|
||||
row.appendCellChild(lOrderDate.rightAlign());
|
||||
ZKUpdateUtil.setHflex(fOrderDate.getComponent(), "true");
|
||||
row.appendCellChild(fOrderDate.getComponent());
|
||||
row.appendCellChild(lBPartner.rightAlign());
|
||||
ZKUpdateUtil.setHflex(fBPartner.getComponent(), "true");
|
||||
row.appendCellChild(fBPartner.getComponent());
|
||||
|
||||
row = new Row();
|
||||
form.getParameterPanel().getRows().appendChild(row);
|
||||
row.appendCellChild(lDocType.rightAlign());
|
||||
ZKUpdateUtil.setHflex(cmbDocType, "true");
|
||||
row.appendCellChild(cmbDocType);
|
||||
row.appendCellChild(lDocAction.rightAlign());
|
||||
ZKUpdateUtil.setHflex(docAction.getComponent(), "true");
|
||||
row.appendCellChild(docAction.getComponent());
|
||||
if (noOfColumn < 6)
|
||||
LayoutUtils.compactTo(form.getParameterPanel(), noOfColumn);
|
||||
else
|
||||
LayoutUtils.expandTo(form.getParameterPanel(), noOfColumn, true);
|
||||
} // jbInit
|
||||
|
||||
protected void setupColumns() {
|
||||
noOfColumn = 6;
|
||||
if (ClientInfo.maxWidth(ClientInfo.MEDIUM_WIDTH-1))
|
||||
{
|
||||
if (ClientInfo.maxWidth(ClientInfo.SMALL_WIDTH-1))
|
||||
noOfColumn = 2;
|
||||
else
|
||||
noOfColumn = 4;
|
||||
}
|
||||
if (noOfColumn == 2)
|
||||
{
|
||||
Columns columns = new Columns();
|
||||
Column column = new Column();
|
||||
column.setWidth("65%");
|
||||
columns.appendChild(column);
|
||||
column = new Column();
|
||||
column.setWidth("35%");
|
||||
columns.appendChild(column);
|
||||
form.getParameterPanel().appendChild(columns);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill Picks.
|
||||
* Column_ID from C_Order
|
||||
* @throws Exception if Lookups cannot be initialized
|
||||
*/
|
||||
public void dynInit() throws Exception
|
||||
{
|
||||
// C_OrderLine.M_Warehouse_ID
|
||||
// MLookup orgL = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, 11474 /* M_Requisition.M_Warehouse_ID */, DisplayType.TableDir);
|
||||
// fWarehouse = new WTableDirEditor ("M_Warehouse_ID", true, false, true, orgL);
|
||||
// lWarehouse.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));
|
||||
// fWarehouse.addValueChangeListener(this);
|
||||
// fWarehouse.setValue(Env.getContextAsInt(Env.getCtx(), "#M_Warehouse_ID"));
|
||||
// setM_Warehouse_ID(fWarehouse.getValue());
|
||||
// Document Action Prepared/ Completed
|
||||
lDocAction.setText(Msg.translate(Env.getCtx(), "DocAction"));
|
||||
MLookup docActionL = MLookupFactory.get(Env.getCtx(), form.getWindowNo(), 4324 /* M_InOut.DocAction */,
|
||||
DisplayType.List, Env.getLanguage(Env.getCtx()), "DocAction", 135 /* _Document Action */,
|
||||
false, "AD_Ref_List.Value IN ('PR','CO')");
|
||||
docAction = new WTableDirEditor("DocAction", true, false, true,docActionL);
|
||||
// docAction.setValue(DocAction.ACTION_Complete);
|
||||
docAction.setValue(DocAction.ACTION_Prepare);
|
||||
// docAction.addValueChangeListener(this); // IDEMPIERE-768
|
||||
// C_Order.C_BPartner_ID
|
||||
MLookup bpL = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, 2762, DisplayType.Search);
|
||||
fBPartner = new WSearchEditor("C_BPartner_ID", false, false, true, bpL);
|
||||
lBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
|
||||
fBPartner.addValueChangeListener(this);
|
||||
//Document Type Sales Order/Vendor RMA
|
||||
lDocType.setText(Msg.translate(Env.getCtx(), "C_DocType_ID"));
|
||||
cmbDocType.addItem(new KeyNamePair(MOrder.Table_ID, Msg.translate(Env.getCtx(), "Order")));
|
||||
cmbDocType.addItem(new KeyNamePair(MRMA.Table_ID, Msg.translate(Env.getCtx(), "VendorRMA")));
|
||||
cmbDocType.addActionListener(this);
|
||||
cmbDocType.setSelectedIndex(0);
|
||||
|
||||
form.getStatusBar().setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateSel"));//@@
|
||||
} // fillPicks
|
||||
|
||||
/**
|
||||
* Query Info
|
||||
*/
|
||||
public void executeQuery()
|
||||
{
|
||||
KeyNamePair docTypeKNPair = cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
executeQuery(docTypeKNPair, form.getMiniTable());
|
||||
if (ClientInfo.maxHeight(ClientInfo.SMALL_HEIGHT-1))
|
||||
{
|
||||
Component comp = form.getParameterPanel().getParent();
|
||||
if (comp instanceof North)
|
||||
((North)comp).setOpen(false);
|
||||
}
|
||||
form.getMiniTable().repaint();
|
||||
form.invalidate();
|
||||
} // executeQuery
|
||||
|
||||
protected void onClientInfo()
|
||||
{
|
||||
if (ClientInfo.isMobile() && form.getPage() != null)
|
||||
{
|
||||
if (noOfColumn > 0 && form.getParameterPanel().getRows() != null)
|
||||
{
|
||||
int t = 6;
|
||||
if (ClientInfo.maxWidth(ClientInfo.MEDIUM_WIDTH-1))
|
||||
{
|
||||
if (ClientInfo.maxWidth(ClientInfo.SMALL_WIDTH-1))
|
||||
t = 2;
|
||||
else
|
||||
t = 4;
|
||||
}
|
||||
if (t != noOfColumn)
|
||||
{
|
||||
form.getParameterPanel().getRows().detach();
|
||||
if (form.getParameterPanel().getColumns() != null)
|
||||
form.getParameterPanel().getColumns().detach();
|
||||
try {
|
||||
zkInit();
|
||||
form.invalidate();
|
||||
} catch (Exception e1) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void onEvent(Event e)
|
||||
{
|
||||
if (log.isLoggable(Level.INFO)) log.info("Cmd=" + e.getTarget().getId());
|
||||
//
|
||||
if(cmbDocType.equals(e.getTarget()))
|
||||
{
|
||||
form.postQueryEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
validate();
|
||||
} // actionPerformed
|
||||
|
||||
public void validate()
|
||||
{
|
||||
// if (isSelectionActive() && getM_Warehouse_ID() <= 0)
|
||||
// {
|
||||
// throw new WrongValueException(fWarehouse.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
|
||||
// }
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
if ( docActionSelected==null || docActionSelected.isEmpty() )
|
||||
throw new WrongValueException(docAction.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
|
||||
|
||||
form.saveSelection();
|
||||
|
||||
ArrayList<Integer> selection = getSelection();
|
||||
if (selection != null
|
||||
&& selection.size() > 0
|
||||
&& isSelectionActive() ) // on selection tab
|
||||
{
|
||||
form.generate();
|
||||
}
|
||||
else
|
||||
{
|
||||
form.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Value Change Listener - requery
|
||||
* @param e event
|
||||
*/
|
||||
public void valueChange(ValueChangeEvent e)
|
||||
{
|
||||
if (log.isLoggable(Level.INFO)) log.info(e.getPropertyName() + "=" + e.getNewValue());
|
||||
if (e.getPropertyName().equals("C_BPartner_ID"))
|
||||
{
|
||||
m_C_BPartner_ID = e.getNewValue();
|
||||
fBPartner.setValue(m_C_BPartner_ID); // display value
|
||||
}
|
||||
form.postQueryEvent();
|
||||
} // vetoableChange
|
||||
|
||||
/**************************************************************************
|
||||
* Generate LandedCost
|
||||
*/
|
||||
public String generate()
|
||||
{
|
||||
KeyNamePair docTypeKNPair = (KeyNamePair)cmbDocType.getSelectedItem().toKeyNamePair();
|
||||
String docActionSelected = (String)docAction.getValue();
|
||||
return generate(form.getStatusBar(), docTypeKNPair, docActionSelected);
|
||||
} // generateLandedCost
|
||||
|
||||
public ADForm getForm()
|
||||
{
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,321 @@
|
|||
/******************************************************************************
|
||||
* 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.grid;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.apps.IStatusBar;
|
||||
import org.compiere.apps.form.GenForm;
|
||||
import org.compiere.minigrid.IDColumn;
|
||||
import org.compiere.minigrid.IMiniTable;
|
||||
import org.compiere.model.MPInstance;
|
||||
import org.compiere.model.MPInstancePara;
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trx;
|
||||
|
||||
/**
|
||||
* Generate Shipment (manual) controller class
|
||||
*
|
||||
*/
|
||||
public class InvoiceLandedCost extends GenForm {
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(InvoiceLandedCost.class);
|
||||
//
|
||||
|
||||
public Object m_OrderDate = null;
|
||||
public Object m_C_BPartner_ID = null;
|
||||
|
||||
public void dynInit() throws Exception {
|
||||
setTitle("GenerateLandedCost");
|
||||
setReportEngineType(ReportEngine.INVOICE);
|
||||
setAskPrintMsg("PrintInvoice");
|
||||
}
|
||||
|
||||
public void configureMiniTable(IMiniTable miniTable) {
|
||||
// create Columns
|
||||
miniTable.addColumn("C_OrderLandedCost_ID");
|
||||
miniTable.addColumn("DocumentNo");
|
||||
miniTable.addColumn("Name");
|
||||
miniTable.addColumn("Amt");
|
||||
//
|
||||
miniTable.setMultiSelection(true);
|
||||
|
||||
// set details
|
||||
miniTable.setColumnClass(0, IDColumn.class, false, " ");
|
||||
miniTable.setColumnClass(1, String.class, true, "Document No");
|
||||
miniTable.setColumnClass(2, String.class, true, "Landed Cost Component");
|
||||
miniTable.setColumnClass(3, BigDecimal.class, true, "Amount");
|
||||
//
|
||||
miniTable.autoSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQL for Orders that needs to be shipped
|
||||
*
|
||||
* @return sql
|
||||
*/
|
||||
private String getOrderSQL() {
|
||||
// Create SQL
|
||||
StringBuilder sql = new StringBuilder("SELECT "
|
||||
+ "ilc.C_OrderLandedCost_ID , "
|
||||
+ "ic.DocumentNo, "
|
||||
+ "icc.Name, "
|
||||
+ "ilc.Amt "
|
||||
+ "FROM C_Order ic, AD_Org o, C_BPartner bp, C_DocType dt, C_OrderLandedCost ilc, C_LandedCostComponent icc "
|
||||
+ "WHERE ic.AD_Org_ID=o.AD_Org_ID"
|
||||
+ " AND icc.C_LandedCostComponent_ID = ilc.C_LandedCostComponent_ID"
|
||||
+ " AND ic.C_Order_ID = ilc.C_Order_ID"
|
||||
+ " AND ic.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND ic.C_DocType_ID=dt.C_DocType_ID"
|
||||
+ " AND ic.AD_Client_ID=?");
|
||||
|
||||
sql= new StringBuilder(
|
||||
"select olc.c_orderlandedcost_id, o.documentno, o.dateordered, lcc.name, olc.amt, coalesce(il.total, 0), olc.amt-coalesce(il.total,0) oustanding "
|
||||
+ " from c_orderlandedcost olc "
|
||||
+ " left join (select iil.c_orderlandedcost_id, sum(linenetamt) total from c_invoiceline iil join c_invoice i on iil.c_invoice_id=i.c_invoice_Id where i.docstatus IN ('CO','CL') group by iil.c_orderlandedcost_id) il "
|
||||
+ " on olc.c_orderlandedcost_id = il.c_orderlandedcost_Id "
|
||||
+ " left join c_landedcostcomponent lcc on lcc.c_landedcostcomponent_id = olc.c_landedcostcomponent_id "
|
||||
+ " left join c_order o on o.c_order_Id = olc.c_order_id "
|
||||
+ " where o.docstatus='CO' AND o.AD_Client_ID =?");
|
||||
// StringBuilder sql = new StringBuilder("SELECT ");
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query Info
|
||||
*/
|
||||
public void executeQuery(KeyNamePair docTypeKNPair, IMiniTable miniTable) {
|
||||
log.info("");
|
||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||
|
||||
String sql = "";
|
||||
|
||||
sql = getOrderSQL();
|
||||
|
||||
log.fine(sql);
|
||||
// reset table
|
||||
int row = 0;
|
||||
miniTable.setRowCount(row);
|
||||
// Execute
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, AD_Client_ID);
|
||||
rs = pstmt.executeQuery();
|
||||
//
|
||||
while (rs.next()) {
|
||||
// extend table
|
||||
miniTable.setRowCount(row + 1);
|
||||
// set values
|
||||
miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); // C_OrderLandedCost_ID
|
||||
miniTable.setValueAt(rs.getString(2), row, 1); // DocumentNo
|
||||
miniTable.setValueAt(rs.getString(3), row, 2); // Name
|
||||
miniTable.setValueAt(rs.getBigDecimal(4), row, 3); // Amt
|
||||
// prepare next
|
||||
row++;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
} finally {
|
||||
DB.close(rs, pstmt);
|
||||
rs = null;
|
||||
pstmt = null;
|
||||
}
|
||||
//
|
||||
miniTable.autoSize();
|
||||
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
* Save Selection & return selection Query or ""
|
||||
*
|
||||
* @return where clause like C_Order_ID IN (...)
|
||||
*/
|
||||
public void saveSelection(IMiniTable miniTable) {
|
||||
log.info("");
|
||||
// Array of Integers
|
||||
ArrayList<Integer> results = new ArrayList<Integer>();
|
||||
setSelection(null);
|
||||
|
||||
// Get selected entries
|
||||
int rows = miniTable.getRowCount();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
IDColumn id = (IDColumn) miniTable.getValueAt(i, 0); // ID in column
|
||||
// 0
|
||||
// log.fine( "Row=" + i + " - " + id);
|
||||
if (id != null && id.isSelected())
|
||||
results.add(id.getRecord_ID());
|
||||
}
|
||||
|
||||
if (results.size() == 0)
|
||||
return;
|
||||
if (log.isLoggable(Level.CONFIG))
|
||||
log.config("Selected #" + results.size());
|
||||
setSelection(results);
|
||||
} // saveSelection
|
||||
|
||||
/**************************************************************************
|
||||
* Generate Invoice Landed Cost
|
||||
*/
|
||||
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected) {
|
||||
String info = "";
|
||||
String trxName = Trx.createTrxName("LCG");
|
||||
Trx trx = Trx.get(trxName, true); // trx needs to be committed too
|
||||
trx.setDisplayName(getClass().getName() + "_generate");
|
||||
|
||||
setSelectionActive(false); // prevents from being called twice
|
||||
statusBar.setStatusLine("GenerateLandedCost");
|
||||
statusBar.setStatusDB(String.valueOf(getSelection().size()));
|
||||
|
||||
// Prepare Process
|
||||
int AD_Process_ID = 1000018; // GenerateLandedCost -- Rizky
|
||||
|
||||
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
|
||||
if (!instance.save()) {
|
||||
info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
|
||||
return info;
|
||||
}
|
||||
|
||||
// insert selection
|
||||
StringBuilder insert = new StringBuilder();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
int counter = 0;
|
||||
for (Integer selectedId : getSelection()) {
|
||||
counter++;
|
||||
if (counter > 1)
|
||||
insert.append(" UNION ");
|
||||
insert.append("SELECT ");
|
||||
insert.append(instance.getAD_PInstance_ID());
|
||||
insert.append(", ");
|
||||
insert.append(selectedId);
|
||||
insert.append(" FROM DUAL ");
|
||||
|
||||
if (counter == 1000) {
|
||||
if (DB.executeUpdate(insert.toString(), trxName) < 0) {
|
||||
String msg = "No Invoice Landed Cost"; // not translated!
|
||||
log.config(msg);
|
||||
info = msg;
|
||||
trx.rollback();
|
||||
return info;
|
||||
}
|
||||
insert = new StringBuilder();
|
||||
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (counter > 0) {
|
||||
if (DB.executeUpdate(insert.toString(), trxName) < 0) {
|
||||
String msg = "No Invoice Landed Cost"; // not translated!
|
||||
log.config(msg);
|
||||
info = msg;
|
||||
trx.rollback();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
// call process
|
||||
ProcessInfo pi = new ProcessInfo("WInvoiceLandedCostGen", AD_Process_ID);
|
||||
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
|
||||
|
||||
// Add Parameter - Selection=Y
|
||||
MPInstancePara ip = new MPInstancePara(instance, 10);
|
||||
ip.setParameter("Selection", "Y");
|
||||
if (!ip.save()) {
|
||||
String msg = "No Parameter added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
// Add Document action parameter
|
||||
ip = new MPInstancePara(instance, 20);
|
||||
// String docActionSelected = (String)docAction.getValue();
|
||||
ip.setParameter("DocAction", docActionSelected);
|
||||
if (!ip.save()) {
|
||||
String msg = "No DocACtion Parameter added";
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
// Add OrderDate Parameter
|
||||
ip = new MPInstancePara(instance, 30);
|
||||
ip.setParameter("OrderDate", getOrderDate());
|
||||
if (!ip.save()) {
|
||||
String msg = "No OrderDate added"; // not translated
|
||||
info = msg;
|
||||
log.log(Level.SEVERE, msg);
|
||||
return info;
|
||||
}
|
||||
|
||||
setTrx(trx);
|
||||
setProcessInfo(pi);
|
||||
|
||||
return info;
|
||||
} // generateShipments
|
||||
|
||||
public void setOrderDate(Object value) {
|
||||
this.m_OrderDate = value;
|
||||
}
|
||||
|
||||
public String getOrderDate() {
|
||||
return (String)this.m_OrderDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get C_Order Document Type Return List
|
||||
*/
|
||||
protected Vector<Vector<Object>> getOrderDocSQL() {
|
||||
Vector<Vector<Object>> list = new Vector<Vector<Object>>();
|
||||
Vector<Object> n = null;
|
||||
ResultSet rs = null;
|
||||
PreparedStatement pstmt = null;
|
||||
String SQL = "SELECT C_DocType_ID, NAME FROM C_DocType WHERE DocBaseType=? AND AD_Client_ID=?";
|
||||
try {
|
||||
pstmt = DB.prepareStatement(SQL, null);
|
||||
pstmt.setString(1, "SOO");
|
||||
pstmt.setInt(2, Env.getAD_Client_ID(Env.getCtx()));
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
n = new Vector<Object>();
|
||||
n.add(rs.getInt(1));
|
||||
n.add(rs.getString(2));
|
||||
list.add(n);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
log.severe(e.getMessage());
|
||||
} finally {
|
||||
DB.close(rs, pstmt);
|
||||
rs = null;
|
||||
pstmt = null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue