use of org.compiere.model.MClient in project adempiere by adempiere.
the class ReplenishReport method createMovements.
// createRequisition
/**
* Create Inventory Movements
*/
private void createMovements() {
int noMoves = 0;
String info = "";
//
MClient client = null;
MMovement move = null;
int M_Warehouse_ID = 0;
int M_WarehouseSource_ID = 0;
MWarehouse whSource = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
client = MClient.get(getCtx(), whSource.getAD_Client_ID());
//
if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
M_Warehouse_ID = replenish.getM_Warehouse_ID();
move = new MMovement(getCtx(), 0, get_TrxName());
move.setC_DocType_ID(p_C_DocType_ID);
move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
// Set Org
move.setAD_Org_ID(whSource.getAD_Org_ID());
if (!move.save())
return;
log.fine(move.toString());
noMoves++;
info += " - " + move.getDocumentNo();
}
// To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
// From: Look-up Storage
MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
//
BigDecimal target = replenish.getQtyToOrder();
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
if (storage.getQtyOnHand().signum() <= 0)
continue;
BigDecimal moveQty = target;
if (storage.getQtyOnHand().compareTo(moveQty) < 0)
moveQty = storage.getQtyOnHand();
//
MMovementLine line = new MMovementLine(move);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setMovementQty(moveQty);
if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
// from
line.setM_Locator_ID(storage.getM_Locator_ID());
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
// to
line.setM_LocatorTo_ID(M_LocatorTo_ID);
line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
line.saveEx();
//
target = target.subtract(moveQty);
if (target.signum() == 0)
break;
}
}
if (replenishs.length == 0) {
m_info = "No Source Warehouse";
log.warning(m_info);
} else {
m_info = "#" + noMoves + info;
log.info(m_info);
}
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class PayrollViaEMail method sendIndividualMail.
// sendBPGroup
/**
* Send Individual Mail
* @param bPartnerId user
* @param unSubscribe unsubscribe message
* @return true if mail has been sent
*/
private Boolean sendIndividualMail(int bPartnerId, String unSubscribe) {
try {
MBPartner employee = new MBPartner(getCtx(), bPartnerId, null);
String message = mailText.getMailText(true);
if (unSubscribe != null)
message += unSubscribe;
StringBuffer whereClause = new StringBuffer();
whereClause.append(MBPartnerLocation.COLUMNNAME_C_BPartner_ID).append(" = ? AND ").append(MBPartnerLocation.COLUMNNAME_ContactType).append("=?");
MBPartnerLocation location = new Query(getCtx(), MBPartnerLocation.Table_Name, whereClause.toString(), get_TrxName()).setOnlyActiveRecords(true).setParameters(bPartnerId, MBPartnerLocation.CONTACTTYPE_Primary).first();
if (location == null) {
addLog(0, null, null, employee.getName() + " @Email@ @NotFound@");
return false;
}
MClient client = MClient.get(getCtx());
String eMailFrom = client.getRequestEMail();
String emailFrom = location.get_ValueAsString("EMail");
String userMailFrom = client.getRequestUser();
String password = client.getRequestUserPW();
// FR [ 402 ]
// Add support to new send mail
EMail email = new EMail(client, eMailFrom, emailFrom, mailText.getMailHeader(), message);
if (mailText.isHtml())
email.setMessageHTML(mailText.getMailHeader(), message);
else {
email.setSubject(mailText.getMailHeader());
email.setMessageText(message);
}
email.addAttachment(CreatePDF(bPartnerId));
if (!email.isValid() && !email.isValid(true)) {
log.warning("NOT VALID - " + email);
employee.setIsActive(false);
employee.save();
return Boolean.FALSE;
}
email.createAuthenticator(userMailFrom, password);
boolean OK = EMail.SENT_OK.equals(email.send());
if (OK) {
addLog(0, null, null, employee.getName() + " @Email@ @OK@");
log.fine(employee.getURL());
} else
log.warning("FAILURE - " + employee.getURL());
addLog(0, null, null, (OK ? "@OK@" : "@ERROR@") + " - " + emailFrom);
return OK;
} catch (Exception e) {
return Boolean.FALSE;
}
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class AdempiereMonitor method createLogMgtPage.
// createSummaryPage
/**
* Add Log Management to page
* @param bb body
*/
private void createLogMgtPage(body bb) {
bb.addElement(new hr());
// Ini Parameters
table table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
Properties ctx = new Properties();
MSystem system = MSystem.get(ctx);
tr line = new tr();
line.addElement(new th().addElement(system.getDBAddress()));
line.addElement(new td().addElement(Ini.getAdempiereHome()));
table.addElement(line);
// OS + Name
line = new tr();
String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
String s = System.getProperty("sun.os.patch.level");
if (s != null && s.length() > 0)
info += " (" + s + ")";
line.addElement(new th().addElement(info));
info = system.getName();
if (system.getCustomPrefix() != null)
info += " (" + system.getCustomPrefix() + ")";
line.addElement(new td().addElement(info));
table.addElement(line);
// Java + email
line = new tr();
info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(system.getUserName()));
table.addElement(line);
// DB + Instance
line = new tr();
CConnection cc = CConnection.get();
AdempiereDatabase db = cc.getDatabase();
info = db.getDescription();
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(cc.getConnectionURL()));
// line.addElement(new td().addElement(system.getDBInstance()));
table.addElement(line);
// Processors/Support
line = new tr();
line.addElement(new th().addElement("Processor/Support"));
line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
table.addElement(line);
// Memory
line = new tr();
MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
line.addElement(new th().addElement("VM Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
table.addElement(line);
line = new tr();
line.addElement(new th().addElement("Heap Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
table.addElement(line);
// Runtime
line = new tr();
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
line.addElement(new th().addElement("Runtime " + rt.getName()));
line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
table.addElement(line);
// Threads
line = new tr();
ThreadMXBean th = ManagementFactory.getThreadMXBean();
line.addElement(new th().addElement("Threads " + th.getThreadCount()));
line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
table.addElement(line);
//Transactions
Trx[] trxs = Trx.getActiveTransactions();
for (Trx trx : trxs) {
if (trx != null && trx.isActive()) {
line = new tr();
line.addElement(new th().addElement("Active Transaction "));
line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
table.addElement(line);
}
}
// Cache Reset
line = new tr();
line.addElement(new th().addElement(CacheMgt.get().toStringX()));
line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
table.addElement(line);
// Trace Level
line = new tr();
line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
// LogLevel Selection
option[] options = new option[CLogMgt.LEVELS.length];
for (int i = 0; i < options.length; i++) {
options[i] = new option(CLogMgt.LEVELS[i].getName());
options[i].addElement(CLogMgt.LEVELS[i].getName());
if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
options[i].setSelected(true);
}
select sel = new select("TraceLevel", options);
myForm.addElement(sel);
myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
line.addElement(new td().addElement(myForm));
table.addElement(line);
//
line = new tr();
CLogFile fileHandler = CLogFile.get(true, null, false);
line.addElement(new th().addElement("Trace File"));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
table.addElement(line);
//
line = new tr();
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
table.addElement(line);
//
bb.addElement(table);
// List Log Files
p p = new p();
p.addElement(new b("All Log Files: "));
// All in dir
File logDir = fileHandler.getLogDirectory();
if (logDir != null && logDir.isDirectory()) {
File[] logs = logDir.listFiles();
for (int i = 0; i < logs.length; i++) {
// Skip if is not a file - teo_sarca [ 1726066 ]
if (!logs[i].isFile())
continue;
if (i != 0)
p.addElement(" - ");
String fileName = logs[i].getAbsolutePath();
a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
p.addElement(link);
int size = (int) (logs[i].length() / 1024);
if (size < 1024)
p.addElement(" (" + size + "k)");
else
p.addElement(" (" + size / 1024 + "M)");
}
}
bb.addElement(p);
// Clients and Web Stores
table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
line = new tr();
MClient[] clients = MClient.getAll(ctx);
line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
p = new p();
for (int i = 0; i < clients.length; i++) {
MClient client = clients[i];
if (i > 0)
p.addElement(" - ");
p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
}
if (clients.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
line = new tr();
MStore[] wstores = MStore.getActive();
line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
p = new p();
for (int i = 0; i < wstores.length; i++) {
MStore store = wstores[i];
if (i > 0)
p.addElement(" - ");
a a = new a(store.getWebContext(), store.getName());
a.setTarget("t" + i);
p.addElement(a);
}
if (wstores.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
bb.addElement(table);
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class AdempiereMonitor method processEMailParameter.
// processTraceParameter
/**
* Process EMail Parameter
* @param request request
* @param response response
* @return true if it was a email request with output
* @throws ServletException
* @throws IOException
*/
private boolean processEMailParameter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = WebUtil.getParameter(request, "EMail");
if (email == null || email.length() == 0)
return false;
int AD_Client_ID = -1;
try {
AD_Client_ID = Integer.parseInt(email);
} catch (Exception e) {
log.warning("Parsing: " + email + " - " + e.toString());
}
if (AD_Client_ID < 0) {
m_message = new p();
m_message.addElement("No EMail: " + email);
return false;
}
// log.info ("Test EMail: " + AD_Client_ID);
MClient client = MClient.get(new Properties(), AD_Client_ID);
log.info("Test: " + client);
m_message = new p();
m_message.addElement(client.getName() + ": " + client.testEMail());
return false;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class SequenceCheck method checkClientSequences.
// checkTableID
/**
* Check/Initialize DocumentNo/Value Sequences for all Clients
* @param ctx context
* @param sp server process or null
*/
private static void checkClientSequences(Properties ctx, SvrProcess sp) {
String trxName = null;
if (sp != null)
trxName = sp.get_TrxName();
// CarlosRuiz - globalqss - [ 1887608 ] SequenceCheck deadlock
// Commit previous work on AD_Sequence
// previously could update a sequence record needed now that is going to create new ones
Trx trx = Trx.get(trxName, false);
trx.commit();
// Sequence for DocumentNo/Value
MClient[] clients = MClient.getAll(ctx);
for (int i = 0; i < clients.length; i++) {
MClient client = clients[i];
if (!client.isActive())
continue;
MSequence.checkClientSequences(ctx, client.getAD_Client_ID(), trxName);
}
// for all clients
}
Aggregations