18 package org.turro.financials.document;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import net.sf.jasperreports.engine.JRException;
27 import org.turro.string.Strings;
28 import org.turro.action.Contacts;
29 import org.turro.attach.search.AttachCollection;
30 import org.turro.auth.Authentication;
31 import org.turro.command.Command;
32 import org.turro.command.Context;
33 import org.turro.contacts.Contact;
34 import org.turro.contacts.util.MailRecipients;
35 import org.turro.elephant.context.Application;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.impl.util.StringParser;
38 import org.turro.elephant.security.IUser;
39 import org.turro.elephant.util.DateFormats;
40 import org.turro.elephant.util.DecimalFormats;
41 import org.turro.elephant.util.Messages;
42 import org.turro.financials.db.FinancialsPU;
43 import org.turro.financials.entity.Company;
44 import org.turro.financials.entity.Document;
45 import org.turro.financials.entity.DocumentLine;
46 import org.turro.financials.model.business.CompanyWrapper;
47 import org.turro.i18n.I_;
48 import org.turro.log.SystemLogType;
49 import org.turro.log.SystemLogger;
50 import org.turro.plugin.contacts.IContact;
51 import org.turro.util.PhraseBuilder;
52 import org.turro.zkoss.print.ReportPrint;
53 import org.turro.zkoss.print.ReportToolbarbutton;
63 private boolean sendToParticipants =
false, sendToCurrent =
false, askBeforeSend =
true;
66 this.document = document;
74 this.sendToParticipants = sendToParticipants;
78 this.sendToCurrent = sendToCurrent;
82 this.askBeforeSend = askBeforeSend;
86 protected void print(
final String type) {
87 final Collection<DocumentLine> lines = getLines();
89 if(lines !=
null && lines.size() > 0) {
91 int fractionDigits = doc.
getCurrency().getDefaultFractionDigits();
92 final Map parameters =
new HashMap();
95 parameters.put(
"company", company);
96 parameters.put(
"companyContact", companyContact);
99 parameters.put(
"showDescendants", Boolean.TRUE);
101 parameters.put(
"contractor", contractor);
102 parameters.put(
"exportFormat", type);
110 parameters.put(
"SUBREPORT_DIR",
"../_reports/financials/document/");
116 if(sendToParticipants) {
119 public Object execute(Context context) {
122 doPrint(emails, doc, lines, parameters, file, type);
130 public Object execute(Context context) {
133 doPrint(emails, doc, lines, parameters, file, type);
139 if(sendToParticipants) {
141 doPrint(emails, doc, lines, parameters, file, type);
145 doPrint(emails, doc, lines, parameters, file, type);
148 if(!(sendToParticipants || sendToCurrent)) {
150 lines, parameters, file,
"/WEB-INF/_reports/financials/document/Document" +
154 }
catch (JRException ex) {
160 private void doPrint(Collection<IContact> emails,
final Document doc,
final Collection<DocumentLine> lines,
final Map parameters,
final String file,
final String type) {
162 String mailString = getMailString(emails);
163 if(!Strings.isBlank(mailString)) {
169 lines, parameters, file,
"/WEB-INF/_reports/financials/document/Document" +
173 SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, doc,
"sent", mailString);
174 amc.removeAttachments();
179 }
catch (JRException ex) {
180 Logger.getLogger(DocumentReport.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
186 private Collection<DocumentLine> getLines() {
189 }
else if(document !=
null) {
195 private Document getDocument() {
203 private String getMailString(Collection<IContact> iParticipantsEmail) {
204 PhraseBuilder pb =
new PhraseBuilder();
205 for(IContact c : iParticipantsEmail) {
206 String email = c.getConnector(IUser.CONNECTOR_EMAIL);
207 if(Contacts.isValidEmail(email)) {
208 pb.addWord(c.getName() +
": " + email);
209 pb.addPendingSeparator(
",");
212 return pb.toString();
void loadAttachments(String path, boolean publicOnly)
Collection< MailAttachment > getAttachments()
static boolean isAdministrator()
static IContact getIContact()
static ResourceBundle getBundle(String bundle, Locale locale, String configured)
static String getRealPath(String path)
static String logMsg(String msg)
static String getSiteLocales()
static String toHTML(String value)
Messages add(String word)
static String getObjectPath(Object object)
void setDocument(Document document)
void setSendToCurrent(boolean sendToCurrent)
void setGrid(DocumentLinesGrid grid)
void print(final String type)
void setSendToParticipants(boolean sendToParticipants)
void setAskBeforeSend(boolean askBeforeSend)
Collection< IContact > getIParticipantsEmail()
IContact getIContractor()
String getDocDescription()
Set< DocumentLine > getDocumentLines()
DocumentDefinition getDocumentDefinition()
static Company getCompanyFrom(DocumentLine line)
static String get(String msg)
static void print(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore)
static void send(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore, Collection< IContact > contacts, String comment, Collection< MailAttachment > attachments, Consumer onFinish)