use of org.compiere.model.MDocType in project adempiere by adempiere.
the class VPAttributeDialog method cmd_select.
// actionPerformed
/**
* Instance Selection Button
* @return true if selected
*/
private boolean cmd_select() {
log.config("");
int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_Warehouse_ID");
int C_DocType_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "C_DocType_ID");
if (C_DocType_ID > 0) {
MDocType doctype = new MDocType(Env.getCtx(), C_DocType_ID, null);
String docbase = doctype.getDocBaseType();
// consider also old lot numbers at inventory
if (docbase.equals(MDocType.DOCBASETYPE_MaterialReceipt) || docbase.equals(MDocType.DOCBASETYPE_MaterialPhysicalInventory))
M_Warehouse_ID = 0;
}
// teo_sarca [ 1564520 ] Inventory Move: can't select existing attributes
// Trifon - Always read Locator from Context. There are too many windows to read explicitly one by one.
int M_Locator_ID = 0;
// only window
M_Locator_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, X_M_MovementLine.COLUMNNAME_M_Locator_ID, true);
String title = "";
// Get Text
String sql = "SELECT p.Name, w.Name, w.M_Warehouse_ID FROM M_Product p, M_Warehouse w " + "WHERE p.M_Product_ID=? AND w.M_Warehouse_ID" + // teo_sarca [ 1564520 ]
(M_Locator_ID <= 0 ? "=?" : " IN (SELECT M_Warehouse_ID FROM M_Locator where M_Locator_ID=?)");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, M_Locator_ID <= 0 ? M_Warehouse_ID : M_Locator_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
title = ": " + rs.getString(1) + " - " + rs.getString(2);
// fetch the actual warehouse - teo_sarca [ 1564520 ]
M_Warehouse_ID = rs.getInt(3);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
PAttributeInstance pai = new PAttributeInstance(this, title, M_Warehouse_ID, M_Locator_ID, m_M_Product_ID, m_C_BPartner_ID);
//
if (m_M_AttributeSetInstance_ID != pai.getM_AttributeSetInstance_ID() || !(m_M_AttributeSetInstance_ID == 0 && pai.getM_AttributeSetInstance_ID() == -1)) {
m_changed = true;
//
if (pai.getM_AttributeSetInstance_ID() != -1) {
m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
m_M_AttributeSetInstanceName = pai.getM_AttributeSetInstanceName();
m_M_Locator_ID = pai.getM_Locator_ID();
} else {
m_M_AttributeSetInstance_ID = 0;
m_M_AttributeSetInstanceName = "";
// Leave the locator alone
}
}
return m_changed;
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class WPAttributeDialog method cmd_select.
// actionPerformed
/**
* Instance Selection Button
* @return true if selected
*/
private boolean cmd_select() {
log.config("");
int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_Warehouse_ID");
int C_DocType_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "C_DocType_ID");
if (C_DocType_ID > 0) {
MDocType doctype = new MDocType(Env.getCtx(), C_DocType_ID, null);
String docbase = doctype.getDocBaseType();
if (docbase.equals(MDocType.DOCBASETYPE_MaterialReceipt))
M_Warehouse_ID = 0;
}
// teo_sarca [ 1564520 ] Inventory Move: can't select existing attributes
// Trifon - Always read Locator from Context. There are too many windows to read explicitly one by one.
int M_Locator_ID = 0;
// only window
M_Locator_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, X_M_MovementLine.COLUMNNAME_M_Locator_ID, true);
String title = "";
// Get Text
String sql = "SELECT p.Name, w.Name, w.M_Warehouse_ID FROM M_Product p, M_Warehouse w " + "WHERE p.M_Product_ID=? AND w.M_Warehouse_ID" + // teo_sarca [ 1564520 ]
(M_Locator_ID <= 0 ? "=?" : " IN (SELECT M_Warehouse_ID FROM M_Locator where M_Locator_ID=?)");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, M_Locator_ID <= 0 ? M_Warehouse_ID : M_Locator_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
title = ": " + rs.getString(1) + " - " + rs.getString(2);
// fetch the actual warehouse - teo_sarca [ 1564520 ]
M_Warehouse_ID = rs.getInt(3);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
InfoPAttributeInstancePanel pai = new InfoPAttributeInstancePanel(this, title, M_Warehouse_ID, M_Locator_ID, m_M_Product_ID, m_C_BPartner_ID);
//
if (m_M_AttributeSetInstance_ID != pai.getM_AttributeSetInstance_ID() || !(m_M_AttributeSetInstance_ID == 0 && pai.getM_AttributeSetInstance_ID() == -1)) {
m_changed = true;
//
if (pai.getM_AttributeSetInstance_ID() != -1) {
m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
m_M_AttributeSetInstanceName = pai.getM_AttributeSetInstanceName();
m_M_Locator_ID = pai.getM_Locator_ID();
} else {
m_M_AttributeSetInstance_ID = 0;
m_M_AttributeSetInstanceName = "";
// Leave the locator alone
}
}
return m_changed;
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class DistributionRun method doIt.
// prepare
/**
* Perform process.
* @return Message (text with variables)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("M_DistributionRun_ID=" + p_M_DistributionRun_ID + ", C_DocType_ID=" + p_C_DocType_ID + ", DatePromised=" + p_DatePromised + ", Test=" + p_IsTest);
// Distribution Run
if (p_M_DistributionRun_ID == 0)
throw new IllegalArgumentException("No Distribution Run ID");
m_run = new MDistributionRun(getCtx(), p_M_DistributionRun_ID, get_TrxName());
if (m_run.get_ID() == 0)
throw new Exception("Distribution Run not found - M_DistributionRun_ID=" + p_M_DistributionRun_ID);
m_runLines = m_run.getLines(true);
if (m_runLines == null || m_runLines.length == 0)
throw new Exception("No active, non-zero Distribution Run Lines found");
// Document Type
if (p_C_DocType_ID == 0)
throw new IllegalArgumentException("No Document Type ID");
// outside trx
m_docType = new MDocType(getCtx(), p_C_DocType_ID, null);
if (m_docType.get_ID() == 0)
throw new Exception("Document Type not found - C_DocType_ID=" + p_C_DocType_ID);
//
m_DateOrdered = new Timestamp(System.currentTimeMillis());
if (p_DatePromised == null)
p_DatePromised = m_DateOrdered;
if (m_docType.getDocBaseType().equals(MDocType.DOCBASETYPE_DistributionOrder) & p_M_Warehouse_ID > 0) {
if (p_BasedInDamnd) {
if (insertDetailsDistributionDemand() == 0)
throw new Exception("No Lines");
} else //Create Temp Lines
{
if (insertDetailsDistribution() == 0)
throw new Exception("No Lines");
}
} else {
// Create Temp Lines
if (insertDetails() == 0)
throw new Exception("No Lines");
}
// Order By Distribution Run Line
m_details = MDistributionRunDetail.get(getCtx(), p_M_DistributionRun_ID, false, get_TrxName());
// First Run -- Add & Round
addAllocations();
// Do Allocation
int loops = 0;
while (!isAllocationEqTotal()) {
adjustAllocation();
addAllocations();
if (++loops > 10)
throw new Exception("Loop detected - more than 10 Allocation attempts");
}
// Order By Business Partner
m_details = MDistributionRunDetail.get(getCtx(), p_M_DistributionRun_ID, true, get_TrxName());
//Implement Distribution Order
if (m_docType.getDocBaseType().equals(MDocType.DOCBASETYPE_DistributionOrder)) {
distributionOrders();
} else {
// Create Orders
createOrders();
}
return "@Created@ #" + m_counter;
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class DocumentTypeVerify method createDocumentTypes.
// doIt
/**************************************************************************
* Create Missing Document Types
* @param ctx context
* @param AD_Client_ID client
* @param sp server process
* @param trxName transaction
*/
public static void createDocumentTypes(Properties ctx, int AD_Client_ID, SvrProcess sp, String trxName) {
s_log.info("AD_Client_ID=" + AD_Client_ID);
String sql = "SELECT rl.Value, rl.Name " + "FROM AD_Ref_List rl " + "WHERE rl.AD_Reference_ID=183" + " AND rl.IsActive='Y' AND NOT EXISTS " + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString(2);
String value = rs.getString(1);
s_log.config(name + "=" + value);
MDocType dt = new MDocType(ctx, value, name, trxName);
if (dt.save()) {
if (sp != null)
sp.addLog(0, null, null, name);
else
s_log.fine(name);
} else {
if (sp != null)
sp.addLog(0, null, null, "Not created: " + name);
else
s_log.warning("Not created: " + name);
}
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
s_log.log(Level.SEVERE, sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class ReplenishReportProduction method doIt.
// prepare
/**
* Perform process.
* @return Message
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("M_Warehouse_ID=" + p_M_Warehouse_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + " - ReplenishmentCreate=" + p_ReplenishmentCreate + ", C_DocType_ID=" + p_C_DocType_ID);
if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0 && !p_ReplenishmentCreate.equals("PRD"))
throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
MWarehouse wh = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
if (wh.get_ID() == 0)
throw new AdempiereSystemError("@FillMandatory@ @M_Warehouse_ID@");
//
prepareTable();
fillTable(wh);
//
if (p_ReplenishmentCreate == null)
return "OK";
//
MDocType dt = MDocType.get(getCtx(), p_C_DocType_ID);
if (!p_ReplenishmentCreate.equals("PRD") && !dt.getDocBaseType().equals(p_ReplenishmentCreate))
throw new AdempiereSystemError("@C_DocType_ID@=" + dt.getName() + " <> " + p_ReplenishmentCreate);
//
if (p_ReplenishmentCreate.equals("POO"))
createPO();
else if (p_ReplenishmentCreate.equals("POR"))
createRequisition();
else if (p_ReplenishmentCreate.equals("MMM"))
createMovements();
else if (p_ReplenishmentCreate.equals("DOO"))
createDO();
else if (p_ReplenishmentCreate.equals("PRD"))
createProduction();
return m_info;
}
Aggregations