use of org.compiere.print.MPrintFormat in project adempiere by adempiere.
the class FinReport method doIt.
// setPeriods
/**************************************************************************
* Perform process.
* @return Message to be translated
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("AD_PInstance_ID=" + getAD_PInstance_ID());
if (p_PA_ReportCube_ID > 0) {
MReportCube cube = new MReportCube(getCtx(), p_PA_ReportCube_ID, get_TrxName());
String result = cube.update(false, false);
log.log(Level.FINE, result);
}
// ** Create Temporary and empty Report Lines from PA_ReportLine
// - AD_PInstance_ID, PA_ReportLine_ID, 0, 0
int PA_ReportLineSet_ID = m_report.getLineSet().getPA_ReportLineSet_ID();
StringBuffer sql = new StringBuffer("INSERT INTO T_Report " + "(AD_PInstance_ID, PA_ReportLine_ID, Record_ID,Fact_Acct_ID, SeqNo,LevelNo, Name,Description,TabLevel, ReportLineStyle, FixedPercentage) " + "SELECT ").append(getAD_PInstance_ID()).append(", PA_ReportLine_ID, 0,0, SeqNo,0, Name,Description,TabLevel,ReportLineStyle,FixedPercentage " + "FROM PA_ReportLine " + "WHERE IsActive='Y' AND PA_ReportLineSet_ID=").append(PA_ReportLineSet_ID);
int no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Report Lines = " + no);
// ** Get Data ** Segment Values
m_columns = m_report.getColumnSet().getColumns();
if (m_columns.length == 0)
throw new AdempiereUserError("@No@ @PA_ReportColumn_ID@");
m_lines = m_report.getLineSet().getLiness();
if (m_lines.length == 0)
throw new AdempiereUserError("@No@ @PA_ReportLine_ID@");
// for all lines
for (int line = 0; line < m_lines.length; line++) {
// Line Segment Value (i.e. not calculation)
if (m_lines[line].isLineTypeSegmentValue())
insertLine(line);
}
// for all lines
insertLineDetail();
doCalculations();
deleteUnprintedLines();
scaleResults();
// Create Report
if (Ini.isClient())
getProcessInfo().setTransientObject(getPrintFormat());
else
getProcessInfo().setSerializableObject(getPrintFormat());
MPrintFormat pf = getPrintFormat();
log.fine((System.currentTimeMillis() - m_start) + " ms");
return "";
}
use of org.compiere.print.MPrintFormat in project adempiere by adempiere.
the class FinReport method getPrintFormat.
/**************************************************************************
* Get/Create PrintFormat
* @return print format
*/
private MPrintFormat getPrintFormat() {
int AD_PrintFormat_ID = m_report.getAD_PrintFormat_ID();
log.info("AD_PrintFormat_ID=" + AD_PrintFormat_ID);
MPrintFormat pf = null;
boolean createNew = AD_PrintFormat_ID == 0;
// Create New
if (createNew) {
// T_Report
int AD_Table_ID = 544;
pf = MPrintFormat.createFromTable(Env.getCtx(), AD_Table_ID);
AD_PrintFormat_ID = pf.getAD_PrintFormat_ID();
m_report.setAD_PrintFormat_ID(AD_PrintFormat_ID);
m_report.saveEx();
} else
// use Cache
pf = MPrintFormat.get(getCtx(), AD_PrintFormat_ID, false);
// Print Format Sync
if (!m_report.getName().equals(pf.getName()))
pf.setName(m_report.getName());
if (m_report.getDescription() == null) {
if (pf.getDescription() != null)
pf.setDescription(null);
} else if (!m_report.getDescription().equals(pf.getDescription()))
pf.setDescription(m_report.getDescription());
pf.saveEx();
log.fine(pf + " - #" + pf.getItemCount());
// Print Format Item Sync
int count = pf.getItemCount();
for (int i = 0; i < count; i++) {
MPrintFormatItem pfi = pf.getItem(i);
String ColumnName = pfi.getColumnName();
//
if (ColumnName == null) {
log.log(Level.SEVERE, "No ColumnName for #" + i + " - " + pfi);
if (pfi.isPrinted())
pfi.setIsPrinted(false);
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
} else if (ColumnName.startsWith("Col")) {
int index = Integer.parseInt(ColumnName.substring(4));
if (index < m_columns.length) {
pfi.setIsPrinted(m_columns[index].isPrinted());
String s = m_columns[index].getName();
if (m_columns[index].isColumnTypeRelativePeriod()) {
BigDecimal relativeOffset = m_columns[index].getRelativePeriod();
FinReportPeriod frp = getPeriod(relativeOffset);
if (s.contains("@Period@"))
s = s.replace("@Period@", frp.getName());
}
if (!pfi.getName().equals(s)) {
pfi.setName(s);
pfi.setPrintName(s);
}
int seq = 50 + index;
if (pfi.getSeqNo() != seq)
pfi.setSeqNo(seq);
s = m_columns[index].getFormatPattern();
pfi.setFormatPattern(s);
} else // not printed
{
if (pfi.isPrinted())
pfi.setIsPrinted(false);
}
// Not Sorted
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
} else if (ColumnName.equals("SeqNo")) {
if (pfi.isPrinted())
pfi.setIsPrinted(false);
if (!pfi.isOrderBy())
pfi.setIsOrderBy(true);
if (pfi.getSortNo() != 10)
pfi.setSortNo(10);
} else if (ColumnName.equals("LevelNo")) {
if (pfi.isPrinted())
pfi.setIsPrinted(false);
if (!pfi.isOrderBy())
pfi.setIsOrderBy(true);
if (pfi.getSortNo() != 20)
pfi.setSortNo(20);
} else if (ColumnName.equals("Name")) {
if (pfi.getSeqNo() != 10)
pfi.setSeqNo(10);
if (!pfi.isPrinted())
pfi.setIsPrinted(true);
if (!pfi.isOrderBy())
pfi.setIsOrderBy(true);
if (pfi.getSortNo() != 30)
pfi.setSortNo(30);
} else if (ColumnName.equals("Description")) {
if (pfi.getSeqNo() != 20)
pfi.setSeqNo(20);
if (!pfi.isPrinted())
pfi.setIsPrinted(true);
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
} else if (ColumnName.equals("AccountType")) {
if (pfi.getSeqNo() != 30)
pfi.setSeqNo(30);
if (!pfi.isPrinted())
pfi.setIsPrinted(true);
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
} else if (ColumnName.equalsIgnoreCase("Ax_Case")) {
if (pfi.getSeqNo() != 40)
pfi.setSeqNo(40);
if (!pfi.isPrinted())
pfi.setIsPrinted(true);
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
} else // Not Printed, No Sort
{
if (pfi.isPrinted())
pfi.setIsPrinted(false);
if (pfi.isOrderBy())
pfi.setIsOrderBy(false);
if (pfi.getSortNo() != 0)
pfi.setSortNo(0);
}
pfi.saveEx();
log.fine(pfi.toString());
}
// set translated to original
pf.setTranslation();
// Reload to pick up changed pfi
// no cache
pf = MPrintFormat.get(getCtx(), AD_PrintFormat_ID, true);
return pf;
}
use of org.compiere.print.MPrintFormat 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.print.MPrintFormat in project adempiere by adempiere.
the class GenerateReplenishPlanProductionReport method doIt.
@Override
protected String doIt() throws Exception {
int Table_ID = MTable.getTable_ID("RV_M_ReplenishPlan_Production");
String sql = "UPDATE AD_ReportView SET WhereClause='M_ReplenishPlan_ID=" + getRecord_ID() + "' WHERE ad_table_ID = ? ";
DB.executeUpdate(sql, Table_ID, get_TrxName());
Trx.get(get_TrxName(), false).commit();
MPrintFormat pf = MPrintFormat.get(getCtx(), 0, Table_ID);
pf.setTranslation();
pf = MPrintFormat.get(getCtx(), pf.getAD_PrintFormat_ID(), true);
if (Ini.isClient())
getProcessInfo().setTransientObject(pf);
else
getProcessInfo().setSerializableObject(pf);
return null;
}
use of org.compiere.print.MPrintFormat in project adempiere by adempiere.
the class GenerateReplenishPlanRequisitionReport method doIt.
@Override
protected String doIt() throws Exception {
int Table_ID = MTable.getTable_ID("RV_M_ReplenishPlan_Requisition");
String sql = "UPDATE AD_ReportView SET WhereClause='M_ReplenishPlan_ID=" + getRecord_ID() + "' WHERE ad_table_ID = ? ";
DB.executeUpdate(sql, Table_ID, get_TrxName());
Trx.get(get_TrxName(), false).commit();
MPrintFormat pf = MPrintFormat.get(getCtx(), 0, Table_ID);
pf.setTranslation();
pf = MPrintFormat.get(getCtx(), pf.getAD_PrintFormat_ID(), true);
if (Ini.isClient())
getProcessInfo().setTransientObject(pf);
else
getProcessInfo().setSerializableObject(pf);
return null;
}
Aggregations