use of org.compiere.model.MOrgInfo in project adempiere by adempiere.
the class DistributionRun method createOrders.
// adjustAllocation
/**************************************************************************
* Create Orders
* @return true if created
*/
private boolean createOrders() {
// Get Counter Org/BP
int runAD_Org_ID = m_run.getAD_Org_ID();
if (runAD_Org_ID == 0)
runAD_Org_ID = Env.getAD_Org_ID(getCtx());
MOrg runOrg = MOrg.get(getCtx(), runAD_Org_ID);
int runC_BPartner_ID = runOrg.getLinkedC_BPartner_ID(get_TrxName());
boolean counter = // no single Order
!m_run.isCreateSingleOrder() && // Org linked to BP
runC_BPartner_ID > 0 && // PO
!m_docType.isSOTrx();
MBPartner runBPartner = counter ? new MBPartner(getCtx(), runC_BPartner_ID, get_TrxName()) : null;
if (!counter || runBPartner == null || runBPartner.get_ID() != runC_BPartner_ID)
counter = false;
if (counter)
log.info("RunBP=" + runBPartner + " - " + m_docType);
log.info("Single=" + m_run.isCreateSingleOrder() + " - " + m_docType + ",SO=" + m_docType.isSOTrx());
log.fine("Counter=" + counter + ",C_BPartner_ID=" + runC_BPartner_ID + "," + runBPartner);
//
MBPartner bp = null;
MOrder singleOrder = null;
MProduct product = null;
// Consolidated Order
if (m_run.isCreateSingleOrder()) {
bp = new MBPartner(getCtx(), m_run.getC_BPartner_ID(), get_TrxName());
if (bp.get_ID() == 0)
throw new IllegalArgumentException("Business Partner not found - C_BPartner_ID=" + m_run.getC_BPartner_ID());
//
if (!p_IsTest) {
singleOrder = new MOrder(getCtx(), 0, get_TrxName());
singleOrder.setC_DocTypeTarget_ID(m_docType.getC_DocType_ID());
singleOrder.setC_DocType_ID(m_docType.getC_DocType_ID());
singleOrder.setIsSOTrx(m_docType.isSOTrx());
singleOrder.setBPartner(bp);
if (m_run.getC_BPartner_Location_ID() != 0)
singleOrder.setC_BPartner_Location_ID(m_run.getC_BPartner_Location_ID());
singleOrder.setDateOrdered(m_DateOrdered);
singleOrder.setDatePromised(p_DatePromised);
if (!singleOrder.save()) {
log.log(Level.SEVERE, "Order not saved");
return false;
}
m_counter++;
}
}
int lastC_BPartner_ID = 0;
int lastC_BPartner_Location_ID = 0;
MOrder order = null;
// For all lines
for (int i = 0; i < m_details.length; i++) {
MDistributionRunDetail detail = m_details[i];
// Create Order Header
if (m_run.isCreateSingleOrder())
order = singleOrder;
else // New Business Partner
if (lastC_BPartner_ID != detail.getC_BPartner_ID() || lastC_BPartner_Location_ID != detail.getC_BPartner_Location_ID()) {
// finish order
order = null;
}
lastC_BPartner_ID = detail.getC_BPartner_ID();
lastC_BPartner_Location_ID = detail.getC_BPartner_Location_ID();
// New Order
if (order == null) {
bp = new MBPartner(getCtx(), detail.getC_BPartner_ID(), get_TrxName());
if (!p_IsTest) {
order = new MOrder(getCtx(), 0, get_TrxName());
order.setC_DocTypeTarget_ID(m_docType.getC_DocType_ID());
order.setC_DocType_ID(m_docType.getC_DocType_ID());
order.setIsSOTrx(m_docType.isSOTrx());
// Counter Doc
if (counter && bp.getAD_OrgBP_ID_Int() > 0) {
log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID_Int() + "-" + bp + ", To_BP=" + runBPartner);
order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
MOrgInfo oi = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID_Int(), get_TrxName());
if (oi.getM_Warehouse_ID() > 0)
order.setM_Warehouse_ID(oi.getM_Warehouse_ID());
order.setBPartner(runBPartner);
} else // normal
{
log.fine("From_Org=" + runAD_Org_ID + ", To_BP=" + bp);
order.setAD_Org_ID(runAD_Org_ID);
order.setBPartner(bp);
if (detail.getC_BPartner_Location_ID() != 0)
order.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID());
}
order.setDateOrdered(m_DateOrdered);
order.setDatePromised(p_DatePromised);
if (!order.save()) {
log.log(Level.SEVERE, "Order not saved");
return false;
}
}
}
// Line
if (product == null || product.getM_Product_ID() != detail.getM_Product_ID())
product = MProduct.get(getCtx(), detail.getM_Product_ID());
if (p_IsTest) {
addLog(0, null, detail.getActualAllocation(), bp.getName() + " - " + product.getName());
continue;
}
// Create Order Line
MOrderLine line = new MOrderLine(order);
if (counter && bp.getAD_OrgBP_ID_Int() > 0)
// don't overwrite counter doc
;
else // normal - optionally overwrite
{
line.setC_BPartner_ID(detail.getC_BPartner_ID());
if (detail.getC_BPartner_Location_ID() != 0)
line.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID());
}
//
line.setProduct(product);
line.setQty(detail.getActualAllocation());
line.setPrice();
if (!line.save()) {
log.log(Level.SEVERE, "OrderLine not saved");
return false;
}
addLog(0, null, detail.getActualAllocation(), order.getDocumentNo() + ": " + bp.getName() + " - " + product.getName());
}
// finish order
order = null;
return true;
}
use of org.compiere.model.MOrgInfo in project adempiere by adempiere.
the class Scheduler method doWork.
/**
* Work
*/
protected void doWork() {
m_summary = new StringBuffer(m_model.toString()).append(" - ");
// Prepare a ctx for the report/process - BF [1966880]
m_schedulerctx.clear();
MClient schedclient = MClient.get(getCtx(), m_model.getAD_Client_ID());
Env.setContext(m_schedulerctx, "#AD_Client_ID", schedclient.getAD_Client_ID());
Env.setContext(m_schedulerctx, "#AD_Language", schedclient.getAD_Language());
Env.setContext(m_schedulerctx, "#AD_Org_ID", m_model.getAD_Org_ID());
if (m_model.getAD_Org_ID() != 0) {
MOrgInfo schedorg = MOrgInfo.get(getCtx(), m_model.getAD_Org_ID(), null);
if (schedorg.getM_Warehouse_ID() > 0)
Env.setContext(m_schedulerctx, "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
}
Env.setContext(m_schedulerctx, "#AD_User_ID", getAD_User_ID());
Env.setContext(m_schedulerctx, "#SalesRep_ID", getAD_User_ID());
// TODO: It can be convenient to add AD_Scheduler.AD_Role_ID
MUser scheduser = MUser.get(getCtx(), getAD_User_ID());
MRole[] schedroles = scheduser.getRoles(m_model.getAD_Org_ID());
if (schedroles != null && schedroles.length > 0)
// first role, ordered by AD_Role_ID
Env.setContext(m_schedulerctx, "#AD_Role_ID", schedroles[0].getAD_Role_ID());
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd");
// JDBC format
Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts) + " 00:00:00");
Properties currentctx = Env.getCtx();
Env.setCtx(m_schedulerctx);
MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null);
try {
m_trx = Trx.get(Trx.createTrxName("Scheduler"), true);
m_summary.append(runProcess(process));
m_trx.commit(true);
} catch (Exception e) {
if (m_trx != null)
m_trx.rollback();
log.log(Level.WARNING, process.toString(), e);
m_summary.append(e.toString());
} finally {
if (m_trx != null)
m_trx.close();
}
// Restore system context
Env.setCtx(currentctx);
//
int no = m_model.deleteLog();
m_summary.append(" Logs deleted=").append(no);
//
MSchedulerLog pLog = new MSchedulerLog(m_model, m_summary.toString());
pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
pLog.saveEx();
}
use of org.compiere.model.MOrgInfo in project adempiere by adempiere.
the class SMJReportViewer method dynInit.
//renderReport
/**
* Dynamic Init
*/
private void dynInit() {
SmjReportLogic logic = new SmjReportLogic();
data = logic.getDataReport(m_AD_PInstance_ID, trxName);
generalTitle = logic.getGeneralTitle(reportId, trxName);
clientName = logic.getOrgName(trxName);
// if (clientName.equals("") || clientName.length()<=0){
// clientName = logic.getClientName(trxName);
// }
clientNIT = logic.getOrgNIT(trxName);
periodName = logic.getPeriodName(p_C_Period_ID, trxName);
currencyName = logic.getCurrency(trxName);
codeFont = logic.getCodeFont(trxName, p_AD_PrintFont_ID);
city = logic.getClientCity(trxName);
//logo
Properties prop = Env.getCtx();
MOrgInfo oi = MOrgInfo.get(prop, Env.getAD_Org_ID(prop), null);
logoId = oi.getLogo_ID();
if (logoId <= 0) {
MClientInfo ci = MClientInfo.get(prop);
logoId = ci.getLogoReport_ID();
if (logoId <= 0)
logoId = ci.getLogo_ID();
}
SmjPdfReport pdf = new SmjPdfReport();
baosPDF = pdf.generate(data, trxName, generalTitle, clientName, clientNIT, periodName, currencyName, m_columns, codeFont, city, logoId);
filePdf = pdf.tofile(baosPDF.toByteArray(), generalTitle);
revalidate();
}
Aggregations