use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class DistributionVerify method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("doIt - GL_Distribution_ID=" + getRecord_ID());
MDistribution distribution = new MDistribution(getCtx(), getRecord_ID(), get_TrxName());
if (distribution.get_ID() == 0)
throw new AdempiereUserError("Not found GL_Distribution_ID=" + getRecord_ID());
String error = distribution.validate();
boolean saved = distribution.save();
if (error != null)
throw new AdempiereUserError(error);
if (!saved)
throw new AdempiereSystemError("@NotSaved@");
return "@OK@";
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class DunningPrint method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_DunningRun_ID=" + p_C_DunningRun_ID + ",R_MailText_ID=" + p_R_MailText_ID + ", EmailPDF=" + p_EMailPDF + ",IsOnlyIfBPBalance=" + p_IsOnlyIfBPBalance + ",PrintUnprocessedOnly=" + p_PrintUnprocessedOnly);
// Need to have Template
if (p_EMailPDF && p_R_MailText_ID == 0)
throw new AdempiereUserError("@NotFound@: @R_MailText_ID@");
// String subject = "";
MMailText mText = null;
if (p_EMailPDF) {
mText = new MMailText(getCtx(), p_R_MailText_ID, get_TrxName());
if (p_EMailPDF && mText.get_ID() == 0)
throw new AdempiereUserError("@NotFound@: @R_MailText_ID@ - " + p_R_MailText_ID);
// subject = mText.getMailHeader();
}
//
MDunningRun run = new MDunningRun(getCtx(), p_C_DunningRun_ID, get_TrxName());
if (run.get_ID() == 0)
throw new AdempiereUserError("@NotFound@: @C_DunningRun_ID@ - " + p_C_DunningRun_ID);
MClient client = MClient.get(getCtx());
int count = 0;
int errors = 0;
MDunningRunEntry[] entries = run.getEntries(false);
for (int i = 0; i < entries.length; i++) {
MDunningRunEntry entry = entries[i];
// Print Format on Dunning Level
MDunningLevel level = new MDunningLevel(getCtx(), entry.getC_DunningLevel_ID(), get_TrxName());
MPrintFormat format = null;
if (level.getDunning_PrintFormat_ID() > 0)
format = MPrintFormat.get(getCtx(), level.getDunning_PrintFormat_ID(), false);
if (p_IsOnlyIfBPBalance && entry.getAmt().signum() <= 0)
continue;
if (p_PrintUnprocessedOnly && entry.isProcessed())
continue;
// To BPartner
MBPartner bp = new MBPartner(getCtx(), entry.getC_BPartner_ID(), get_TrxName());
if (bp.get_ID() == 0) {
addLog(entry.get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.getC_BPartner_ID());
errors++;
continue;
}
// To User
MUser to = new MUser(getCtx(), entry.getAD_User_ID(), get_TrxName());
if (p_EMailPDF) {
if (to.get_ID() == 0) {
addLog(entry.get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.getName());
errors++;
continue;
} else if (to.getEMail() == null || to.getEMail().length() == 0) {
addLog(entry.get_ID(), null, null, "@NotFound@: @EMail@ - " + to.getName());
errors++;
continue;
}
}
// query
MQuery query = new MQuery("C_Dunning_Header_v");
query.addRestriction("C_DunningRunEntry_ID", MQuery.EQUAL, new Integer(entry.getC_DunningRunEntry_ID()));
// Engine
PrintInfo info = new PrintInfo(bp.getName(), MDunningRunEntry.Table_ID, entry.getC_DunningRunEntry_ID(), entry.getC_BPartner_ID());
info.setDescription(bp.getName() + ", Amt=" + entry.getAmt());
ReportEngine re = null;
if (format != null)
re = new ReportEngine(getCtx(), format, query, info);
boolean printed = false;
if (p_EMailPDF) {
EMail email = client.createEMail(to.getEMail(), null, null);
if (!email.isValid()) {
addLog(entry.get_ID(), null, null, "@RequestActionEMailError@ Invalid EMail: " + to);
errors++;
continue;
}
// variable context
mText.setUser(to);
mText.setBPartner(bp);
mText.setPO(entry);
String message = mText.getMailText(true);
if (mText.isHtml())
email.setMessageHTML(mText.getMailHeader(), message);
else {
email.setSubject(mText.getMailHeader());
email.setMessageText(message);
}
//
if (re != null) {
File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf"));
log.fine(to + " - " + attachment);
email.addAttachment(attachment);
}
//
String msg = email.send();
MUserMail um = new MUserMail(mText, entry.getAD_User_ID(), email);
um.saveEx();
if (msg.equals(EMail.SENT_OK)) {
addLog(entry.get_ID(), null, null, bp.getName() + " @RequestActionEMailOK@");
count++;
printed = true;
} else {
addLog(entry.get_ID(), null, null, bp.getName() + " @RequestActionEMailError@ " + msg);
errors++;
}
} else {
if (re != null) {
re.print();
count++;
printed = true;
}
}
if (printed) {
entry.setProcessed(true);
entry.save();
}
}
// for all dunning letters
if (errors == 0) {
run.setProcessed(true);
run.saveEx();
}
if (p_EMailPDF)
return "@Sent@=" + count + " - @Errors@=" + errors;
return "@Printed@=" + count;
}
use of org.compiere.util.AdempiereUserError 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;
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class ReplenishReportProduction method fillTable.
// prepareTable
/**
* Fill Table
* @param wh warehouse
*/
private void fillTable(MWarehouse wh) throws Exception {
String sql = "INSERT INTO T_Replenish " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," + " ReplenishType, Level_Min, Level_Max," + " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " + "SELECT " + getAD_PInstance_ID() + ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," + " r.ReplenishType, r.Level_Min, r.Level_Max," + " po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, ";
if (p_ReplenishmentCreate == null)
sql += "null";
else
sql += "'" + p_ReplenishmentCreate + "'";
sql += " FROM M_Replenish r" + " INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) " + " INNER JOIN M_Product p ON (p.M_Product_ID=po.M_Product_ID) " + // Only Current Vendor
"WHERE po.IsCurrentVendor='Y'" + " AND r.ReplenishType<>'0'" + " AND po.IsActive='Y' AND r.IsActive='Y'" + " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID;
if (p_C_BPartner_ID != 0)
sql += " AND po.C_BPartner_ID=" + p_C_BPartner_ID;
if (p_M_Product_Category_ID != 0)
sql += " AND p.M_Product_Category_ID=" + p_M_Product_Category_ID;
if (isKanban != null)
sql += " AND p.IsKanban = '" + isKanban + "' ";
int no = DB.executeUpdate(sql, get_TrxName());
log.finest(sql);
log.fine("Insert (1) #" + no);
if (p_C_BPartner_ID == 0) {
sql = "INSERT INTO T_Replenish " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," + " ReplenishType, Level_Min, Level_Max," + " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " + "SELECT " + getAD_PInstance_ID() + ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," + " r.ReplenishType, r.Level_Min, r.Level_Max," + " 0, 1, 1, 0, ";
if (p_ReplenishmentCreate == null)
sql += "null";
else
sql += "'" + p_ReplenishmentCreate + "'";
sql += " FROM M_Replenish r " + " INNER JOIN M_Product p ON (p.M_Product_ID=r.M_Product_ID) " + "WHERE r.ReplenishType<>'0' AND r.IsActive='Y'" + " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID + " AND NOT EXISTS (SELECT * FROM T_Replenish t " + "WHERE r.M_Product_ID=t.M_Product_ID" + " AND AD_PInstance_ID=" + getAD_PInstance_ID() + ")";
if (p_M_Product_Category_ID != 0)
sql += " AND p.M_Product_Category_ID=" + p_M_Product_Category_ID;
if (isKanban != null)
sql += " AND p.IsKanban = '" + isKanban + "' ";
no = DB.executeUpdate(sql, get_TrxName());
log.fine("Insert (BP) #" + no);
}
sql = "UPDATE T_Replenish t SET " + "QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," + "QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," + "QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)";
if (p_C_DocType_ID != 0)
sql += ", C_DocType_ID=" + p_C_DocType_ID;
sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Update #" + no);
// add production lines
sql = "UPDATE T_Replenish t SET " + "QtyReserved = QtyReserved - COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID" + " AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty < 0 AND p.Processed = 'N'),0)," + "QtyOrdered = QtyOrdered + COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID" + " AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty > 0 AND p.Processed = 'N'),0)";
if (p_C_DocType_ID != 0)
sql += ", C_DocType_ID=" + p_C_DocType_ID;
sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Update #" + no);
// Delete inactive products and replenishments
sql = "DELETE T_Replenish r " + "WHERE (EXISTS (SELECT * FROM M_Product p " + "WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')" + " OR EXISTS (SELECT * FROM M_Replenish rr " + " WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'" + " AND rr.M_Warehouse_ID=" + p_M_Warehouse_ID + " ))" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Delete Inactive=" + no);
// Ensure Data consistency
sql = "UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL";
no = DB.executeUpdate(sql, get_TrxName());
sql = "UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL";
no = DB.executeUpdate(sql, get_TrxName());
sql = "UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL";
no = DB.executeUpdate(sql, get_TrxName());
// Set Minimum / Maximum Maintain Level
// X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel
sql = "UPDATE T_Replenish" + " SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min " + " THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered " + " ELSE 0 END " + "WHERE ReplenishType='1'" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Update Type-1=" + no);
//
// X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel
sql = "UPDATE T_Replenish" + " SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered " + "WHERE ReplenishType='2'" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Update Type-2=" + no);
// Minimum Order Quantity
sql = "UPDATE T_Replenish" + " SET QtyToOrder = Order_Min " + "WHERE QtyToOrder < Order_Min" + " AND QtyToOrder > 0" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Set MinOrderQty=" + no);
// Even dividable by Pack
sql = "UPDATE T_Replenish" + " SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack " + "WHERE MOD(QtyToOrder, Order_Pack) <> 0" + " AND QtyToOrder > 0" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Set OrderPackQty=" + no);
// Source from other warehouse
if (wh.getM_WarehouseSource_ID() != 0) {
sql = "UPDATE T_Replenish" + " SET M_WarehouseSource_ID=" + wh.getM_WarehouseSource_ID() + " WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Set Source Warehouse=" + no);
}
// Check Source Warehouse
sql = "UPDATE T_Replenish" + " SET M_WarehouseSource_ID = NULL " + "WHERE M_Warehouse_ID=M_WarehouseSource_ID" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Set same Source Warehouse=" + no);
// Custom Replenishment
String className = wh.getReplenishmentClass();
if (className != null && className.length() > 0) {
// Get Replenishment Class
ReplenishInterface custom = null;
try {
Class<?> clazz = Class.forName(className);
custom = (ReplenishInterface) clazz.newInstance();
} catch (Exception e) {
throw new AdempiereUserError("No custom Replenishment class " + className + " - " + e.toString());
}
X_T_Replenish[] replenishs = getReplenish("ReplenishType='9'");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (replenish.getReplenishType().equals(X_T_Replenish.REPLENISHTYPE_Custom)) {
BigDecimal qto = null;
try {
qto = custom.getQtyToOrder(wh, replenish);
} catch (Exception e) {
log.log(Level.SEVERE, custom.toString(), e);
}
if (qto == null)
qto = Env.ZERO;
replenish.setQtyToOrder(qto);
replenish.save();
}
}
}
// Delete rows where nothing to order
sql = "DELETE T_Replenish " + "WHERE QtyToOrder < 1" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Delete No QtyToOrder=" + no);
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class AllocationReset method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_BP_Group_ID=" + p_C_BP_Group_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + ", DateAcct= " + p_DateAcct_From + " - " + p_DateAcct_To + ", C_AllocationHdr_ID=" + p_C_AllocationHdr_ID + ", AllAllocations=" + p_AllAllocations);
if (p_C_AllocationHdr_ID == 0 && !p_AllAllocations)
throw new AdempiereUserError(Msg.parseTranslation(getCtx(), "@Mandatory@: @C_AllocationHdr_ID@"));
m_trx = Trx.get(Trx.createTrxName("AllocReset"), true);
int count = 0;
if (p_C_AllocationHdr_ID != 0) {
MAllocationHdr hdr = new MAllocationHdr(getCtx(), p_C_AllocationHdr_ID, m_trx.getTrxName());
if (delete(hdr))
count++;
m_trx.close();
return "@Deleted@ #" + count;
}
// Selection
StringBuffer sql = new StringBuffer("SELECT * FROM C_AllocationHdr ah " + "WHERE EXISTS (SELECT * FROM C_AllocationLine al " + "WHERE ah.C_AllocationHdr_ID=al.C_AllocationHdr_ID");
if (p_C_BPartner_ID != 0)
sql.append(" AND al.C_BPartner_ID=?");
else if (p_C_BP_Group_ID != 0)
sql.append(" AND EXISTS (SELECT * FROM C_BPartner bp " + "WHERE bp.C_BPartner_ID=al.C_BPartner_ID AND bp.C_BP_Group_ID=?)");
else
sql.append(" AND AD_Client_ID=?");
if (p_DateAcct_From != null)
sql.append(" AND TRIM(ah.DateAcct) >= ?");
if (p_DateAcct_To != null)
sql.append(" AND TRIM(ah.DateAcct) <= ?");
// Do not delete Cash Trx
sql.append(" AND al.C_CashLine_ID IS NULL)");
// Open Period
sql.append(" AND EXISTS (SELECT * FROM C_Period p" + " INNER JOIN C_PeriodControl pc ON (p.C_Period_ID=pc.C_Period_ID AND pc.DocBaseType='CMA') " + "WHERE ah.DateAcct BETWEEN p.StartDate AND p.EndDate)");
//
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(), m_trx.getTrxName());
int index = 1;
if (p_C_BPartner_ID != 0)
pstmt.setInt(index++, p_C_BPartner_ID);
else if (p_C_BP_Group_ID != 0)
pstmt.setInt(index++, p_C_BP_Group_ID);
else
pstmt.setInt(index++, Env.getAD_Client_ID(getCtx()));
if (p_DateAcct_From != null)
pstmt.setTimestamp(index++, p_DateAcct_From);
if (p_DateAcct_To != null)
pstmt.setTimestamp(index++, p_DateAcct_To);
rs = pstmt.executeQuery();
while (rs.next()) {
MAllocationHdr hdr = new MAllocationHdr(getCtx(), rs, m_trx.getTrxName());
if (delete(hdr))
count++;
}
} catch (Exception e) {
log.log(Level.SEVERE, sql.toString(), e);
m_trx.rollback();
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
m_trx.close();
return "@Deleted@ #" + count;
}
Aggregations