int AD_PrintFormat_ID = rs.getInt(4);
int copies = rs.getInt(5);
if (copies == 0)
copies = 1;
int AD_User_ID = rs.getInt(6);
MUser to = new MUser (getCtx(), AD_User_ID, get_TrxName());
String DocumentNo = rs.getString(7);
C_BPartner_ID = rs.getInt(8);
//
String documentDir = client.getDocumentDir();
if (documentDir == null || documentDir.length() == 0)
documentDir = ".";
//
if (p_EMailPDF && (to.get_ID() == 0 || to.getEMail() == null || to.getEMail().length() == 0))
{
addLog (C_Invoice_ID, null, null, DocumentNo + " @RequestActionEMailNoTo@");
errors++;
continue;
}
if (AD_PrintFormat_ID == 0)
{
addLog (C_Invoice_ID, null, null, DocumentNo + " No Print Format");
errors++;
continue;
}
// Get Format & Data
if (AD_PrintFormat_ID != old_AD_PrintFormat_ID)
{
format = MPrintFormat.get (getCtx(), AD_PrintFormat_ID, false);
old_AD_PrintFormat_ID = AD_PrintFormat_ID;
}
format.setLanguage(language);
format.setTranslationLanguage(language);
// query
MQuery query = new MQuery("C_Invoice_Header_v");
query.addRestriction("C_Invoice_ID", MQuery.EQUAL, new Integer(C_Invoice_ID));
// Engine
PrintInfo info = new PrintInfo(
DocumentNo,
X_C_Invoice.Table_ID,
C_Invoice_ID,
C_BPartner_ID);
info.setCopies(copies);
ReportEngine re = new ReportEngine(getCtx(), format, query, info);
boolean printed = false;
if (p_EMailPDF)
{
String subject = mText.getMailHeader() + " - " + DocumentNo;
EMail email = client.createEMail(to.getEMail(), subject, null);
if (!email.isValid())
{
addLog (C_Invoice_ID, null, null,
DocumentNo + " @RequestActionEMailError@ Invalid EMail: " + to);
errors++;
continue;
}
mText.setUser(to); // Context
mText.setBPartner(C_BPartner_ID); // Context
mText.setPO(new MInvoice(getCtx(), C_Invoice_ID, get_TrxName()));
String message = mText.getMailText(true);
if (mText.isHtml())
email.setMessageHTML(subject, message);
else
{
email.setSubject (subject);
email.setMessageText (message);
}
//
File invoice = null;
if (!Ini.isClient())
invoice = new File(MInvoice.getPDFFileName(documentDir, C_Invoice_ID));
File attachment = re.getPDF(invoice);
log.fine(to + " - " + attachment);
email.addAttachment(attachment);
//
String msg = email.send();
MUserMail um = new MUserMail(mText, getAD_User_ID(), email);
um.save();
if (msg.equals(EMail.SENT_OK))
{
addLog (C_Invoice_ID, null, null,
DocumentNo + " @RequestActionEMailOK@ - " + to.getEMail());
count++;
printed = true;
}
else
{
addLog (C_Invoice_ID, null, null,
DocumentNo + " @RequestActionEMailError@ " + msg
+ " - " + to.getEMail());
errors++;
}
}
else
{