use of org.compiere.model.MDocType in project adempiere by adempiere.
the class DistributionRunOrders method executeDistribution.
/**
* Execute Distribution Run
* @return
* @throws Exception
*/
public boolean executeDistribution() throws Exception {
int M_DocType_ID = 0;
MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder);
if (doc == null || doc.length == 0) {
log.severe("Not found default document type for docbasetype " + MDocType.DOCBASETYPE_DistributionOrder);
throw new Exception(Msg.getMsg(getCtx(), "SequenceDocNotFound"), CLogger.retrieveException());
} else
M_DocType_ID = doc[0].getC_DocType_ID();
String trxName = Trx.createTrxName("Run Distribution to DRP");
//trx needs to be committed too
Trx trx = Trx.get(trxName, true);
//Prepare Process
int AD_Process_ID = 271;
AD_Process_ID = MProcess.getProcess_ID("M_DistributionRun Create", get_TrxName());
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) {
throw new Exception(Msg.getMsg(getCtx(), "ProcessNoInstance"), CLogger.retrieveException());
}
//call process
ProcessInfo pi = new ProcessInfo("M_DistributionRun Orders", AD_Process_ID);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
pi.setRecord_ID(m_run.getM_DistributionRun_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
ip.setParameter("C_DocType_ID", M_DocType_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - DatePromised
ip = new MPInstancePara(instance, 20);
ip.setParameter("DatePromised", "");
ip.setP_Date(p_DatePromised);
//ip.setP_Date_To(p_DatePromised_To);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - M_Warehouse_ID
ip = new MPInstancePara(instance, 30);
ip.setParameter("M_Warehouse_ID", p_M_Warehouse_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - CreateDO
ip = new MPInstancePara(instance, 40);
ip.setParameter("ConsolidateDocument", p_ConsolidateDocument);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - IsTest=Y
ip = new MPInstancePara(instance, 50);
ip.setParameter("IsTest", p_IsTest);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
//Distribution List
ip = new MPInstancePara(instance, 60);
ip.setParameter("M_DistributionList_ID", p_M_DistributionList_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
//Based in DRP Demand
ip = new MPInstancePara(instance, 70);
ip.setParameter("IsRequiredDRP", p_BasedInDamnd);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Execute Process
MProcess worker = new MProcess(getCtx(), AD_Process_ID, get_TrxName());
worker.processIt(pi, Trx.get(get_TrxName(), true));
m_run.delete(true);
return true;
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class CreateDocType method createDocType.
// createGLCategory
/**
* Create Document Types with Sequence
* @param Name name
* @param PrintName print name
* @param DocBaseType document base type
* @param DocSubTypeSO sales order sub type
* @param C_DocTypeShipment_ID shipment doc
* @param C_DocTypeInvoice_ID invoice doc
* @param StartNo start doc no
* @param GL_Category_ID gl category
* @return C_DocType_ID doc type or 0 for error
*/
private int createDocType(String Name, String PrintName, String DocBaseType, String DocSubTypeSO, int C_DocTypeShipment_ID, int C_DocTypeInvoice_ID, int StartNo, int GL_Category_ID) {
log.fine("In createDocType");
log.fine("docBaseType: " + DocBaseType);
log.fine("GL_Category_ID: " + GL_Category_ID);
MSequence sequence = null;
if (StartNo != 0) {
sequence = new MSequence(Env.getCtx(), getAD_Client_ID(), Name, StartNo, trxname);
if (!sequence.save()) {
log.log(Level.SEVERE, "Sequence NOT created - " + Name);
return 0;
}
}
//MDocType dt = new MDocType (Env.getCtx(), DocBaseType, Name, trxname);
MDocType dt = new MDocType(Env.getCtx(), 0, trxname);
dt.setAD_Org_ID(0);
dt.set_CustomColumn("DocBaseType", (Object) DocBaseType);
dt.setName(Name);
dt.setPrintName(Name);
if (DocSubTypeSO != null)
dt.setDocSubTypeSO(DocSubTypeSO);
if (C_DocTypeShipment_ID != 0)
dt.setC_DocTypeShipment_ID(C_DocTypeShipment_ID);
if (C_DocTypeInvoice_ID != 0)
dt.setC_DocTypeInvoice_ID(C_DocTypeInvoice_ID);
if (GL_Category_ID != 0)
dt.setGL_Category_ID(GL_Category_ID);
if (sequence == null)
dt.setIsDocNoControlled(false);
else {
dt.setIsDocNoControlled(true);
dt.setDocNoSequence_ID(sequence.getAD_Sequence_ID());
}
dt.setIsSOTrx(false);
if (!dt.save()) {
log.log(Level.SEVERE, "DocType NOT created - " + Name);
return 0;
}
//
return dt.getC_DocType_ID();
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class InvoiceNGL method createGLJournal.
// doIt
/**
* Create GL Journal
* @return document info
*/
private String createGLJournal() {
//FR: [ 2214883 ] Remove SQL code and Replace for Query
final String whereClause = "AD_PInstance_ID=?";
List<X_T_InvoiceGL> list = new Query(getCtx(), X_T_InvoiceGL.Table_Name, whereClause, get_TrxName()).setParameters(getAD_PInstance_ID()).setOrderBy("AD_Org_ID").list();
if (list.size() == 0)
return " - No Records found";
//
MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
MAcctSchemaDefault asDefaultAccts = MAcctSchemaDefault.get(getCtx(), p_C_AcctSchema_ID);
MGLCategory cat = MGLCategory.getDefaultSystem(getCtx());
if (cat == null) {
MDocType docType = MDocType.get(getCtx(), p_C_DocTypeReval_ID);
cat = MGLCategory.get(getCtx(), docType.getGL_Category_ID());
}
//
MJournalBatch batch = new MJournalBatch(getCtx(), 0, get_TrxName());
batch.setDescription(getName());
batch.setC_DocType_ID(p_C_DocTypeReval_ID);
batch.setDateDoc(new Timestamp(System.currentTimeMillis()));
batch.setDateAcct(p_DateReval);
batch.setC_Currency_ID(as.getC_Currency_ID());
if (!batch.save())
return " - Could not create Batch";
//
MJournal journal = null;
BigDecimal drTotal = Env.ZERO;
BigDecimal crTotal = Env.ZERO;
int AD_Org_ID = 0;
for (int i = 0; i < list.size(); i++) {
X_T_InvoiceGL gl = list.get(i);
if (gl.getAmtRevalDrDiff().signum() == 0 && gl.getAmtRevalCrDiff().signum() == 0)
continue;
MInvoice invoice = new MInvoice(getCtx(), gl.getC_Invoice_ID(), null);
if (invoice.getC_Currency_ID() == as.getC_Currency_ID())
continue;
//
if (journal == null) {
journal = new MJournal(batch);
journal.setC_AcctSchema_ID(as.getC_AcctSchema_ID());
journal.setC_Currency_ID(as.getC_Currency_ID());
journal.setC_ConversionType_ID(p_C_ConversionTypeReval_ID);
MOrg org = MOrg.get(getCtx(), gl.getAD_Org_ID());
journal.setDescription(getName() + " - " + org.getName());
journal.setGL_Category_ID(cat.getGL_Category_ID());
if (!journal.save())
return " - Could not create Journal";
}
//
MJournalLine line = new MJournalLine(journal);
line.setLine((i + 1) * 10);
line.setDescription(invoice.getSummary());
//
MFactAcct fa = new MFactAcct(getCtx(), gl.getFact_Acct_ID(), null);
line.setC_ValidCombination_ID(MAccount.get(fa));
BigDecimal dr = gl.getAmtRevalDrDiff();
BigDecimal cr = gl.getAmtRevalCrDiff();
drTotal = drTotal.add(dr);
crTotal = crTotal.add(cr);
line.setAmtSourceDr(dr);
line.setAmtAcctDr(dr);
line.setAmtSourceCr(cr);
line.setAmtAcctCr(cr);
line.saveEx();
//
if (// invoice org id
AD_Org_ID == 0)
AD_Org_ID = gl.getAD_Org_ID();
// Change in Org
if (AD_Org_ID != gl.getAD_Org_ID()) {
createBalancing(asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (i + 1) * 10);
//
AD_Org_ID = gl.getAD_Org_ID();
drTotal = Env.ZERO;
crTotal = Env.ZERO;
journal = null;
}
}
createBalancing(asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (list.size() + 1) * 10);
return " - " + batch.getDocumentNo() + " #" + list.size();
}
use of org.compiere.model.MDocType in project adempiere by adempiere.
the class MPPMRP method C_OrderLine.
/**
* Create MRP record based in Order Line
* @param MOrderLine
*/
public static void C_OrderLine(MOrderLine ol) {
if (ol.isConsumesForecast())
return;
MPPMRP mrp = getQuery(ol, null, null).firstOnly();
if (mrp == null) {
mrp = new MPPMRP(ol.getCtx(), 0, ol.get_TrxName());
mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID());
}
mrp.setAD_Org_ID(ol.getAD_Org_ID());
mrp.setC_Order(ol.getParent());
mrp.setDescription(ol.getDescription());
mrp.setName("MRP");
mrp.setDatePromised(ol.getDatePromised());
mrp.setDateStartSchedule(ol.getDatePromised());
mrp.setDateFinishSchedule(ol.getDatePromised());
mrp.setDateOrdered(ol.getDateOrdered());
mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID());
mrp.setM_Product_ID(ol.getM_Product_ID());
mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
mrp.saveEx();
MOrder o = ol.getParent();
MDocType dt = MDocType.get(o.getCtx(), o.getC_DocTypeTarget_ID());
String DocSubTypeSO = dt.getDocSubTypeSO();
MProduct product = (MProduct) ol.getM_Product();
if ((MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_WarehouseOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_OnCreditOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_POSOrder.equals(DocSubTypeSO)) && product.isBOM() && !product.isPurchased() && MPPProductBOM.isProductMakeToOrder(ol.getCtx(), ol.getM_Product_ID(), ol.get_TrxName())) {
MPPMRP.createMOMakeTo(ol, ol.getQtyOrdered());
}
return;
}
Aggregations