use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.
the class DocumentSupporterOperation method mail.
/**
* This method send document to the e-Mail address that is in the customer set.
* <p/>
* @param document This is the Document that will be send.
* @throws UserInfoException if the sending of the Mail is not successful.
* @throws RuntimeException if problems exist in the JasperExporter
*/
@Override
public void mail(Document document, DocumentViewType jtype) throws UserInfoException, RuntimeException {
UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
String customerMailAddress = customerService.asCustomerMetaData(document.getDossier().getCustomerId()).getEmail();
if (customerMailAddress == null) {
throw new UserInfoException("Kunde hat keine E-Mail Hinterlegt! Senden einer E-Mail ist nicht Möglich!");
}
String doctype = (jtype == DocumentViewType.DEFAULT ? document.getType().getName() : jtype.getName());
try (InputStream is = mandator.getMailTemplateLocation().toURL().openStream();
InputStreamReader templateReader = new InputStreamReader(is)) {
String text = new MailDocumentParameter(customer.toTitleNameLine(), doctype).eval(IOUtils.toString(templateReader));
MultiPartEmail email = mandator.prepareDirectMail();
email.setCharset("UTF-8");
email.addTo(customerMailAddress);
email.setSubject(document.getType().getName() + " | " + document.getDossier().getIdentifier());
email.setMsg(text + mandator.getDefaultMailSignature());
email.attach(new ByteArrayDataSource(JasperExportManager.exportReportToPdf(jasper(document, jtype)), "application/pdf"), "Dokument.pdf", "Das ist das Dokument zu Ihrem Aufrag als PDF.");
for (MandatorMailAttachment mma : mandator.getDefaultMailAttachment()) {
email.attach(mma.getAttachmentData().toURL(), mma.getAttachmentName(), mma.getAttachmentDescription());
}
email.send();
} catch (EmailException ex) {
L.error("Error on Mail sending", ex);
throw new UserInfoException("Das senden der Mail war nicht erfolgreich!\n" + ex.getMessage());
} catch (IOException | JRException e) {
throw new RuntimeException(e);
}
}
use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.
the class UnitOverseerBean method throwNotAvailable.
/**
* Build and throw an exception for a not available unit.
* <p>
* @param refurbishId the refurbished id of the unit
* @param us the unit shard
* @throws UserInfoException
*/
private void throwNotAvailable(String refurbishId, UnitShard us) throws UserInfoException {
// <- auch in di auslagerung...
if (us.getAvailable() == null)
throw new UserInfoException("SopoNr " + refurbishId + " existiert nicht");
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(us.getUniqueUnitId());
if (stockUnit != null && stockUnit.getLogicTransaction() != null) {
Dossier dos = new DossierEao(redTapeEm).findById(stockUnit.getLogicTransaction().getDossierId());
if (dos == null)
throw new UserInfoException("SopoNr " + refurbishId + " is on a LogicTransaction, but there is no Dossier, inform Team Software");
UiCustomer customer = customerService.asUiCustomer(dos.getCustomerId());
if (customer == null)
throw new UserInfoException("SopoNr " + refurbishId + " is on Dossier " + dos.getIdentifier() + ", but Customer " + dos.getCustomerId() + " does not exist.");
throw new UserInfoException("SopoNr " + refurbishId + " ist schon vergeben" + "\nKID = " + customer.getId() + "\nKunde = " + customer.toTitleNameLine() + "\n\nVorgang = " + dos.getIdentifier());
}
}
use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.
the class UniversalSearcherOperation method findCustomers.
/**
* Returns a List of short descriptions of Customers in Html.
* Ensure to add the html start/end tags manually
* <p/>
* @param firma the firma or null
* @param vorname the vorname or null
* @param nachname the nachname or null
* @param email the email or null
* @return a List of short descriptions of Customers in Html.
*/
// RedTape createCustomer Contorller.
@Override
public List<Tuple2<Long, String>> findCustomers(String firma, String vorname, String nachname, String email) {
List<UiCustomer> customers = customerService.asUiCustomers(firma, vorname, nachname, email, true);
List<Tuple2<Long, String>> result = new ArrayList<>(customers.size());
for (UiCustomer customer : customers) {
result.add(new Tuple2(customer.getId(), customer.getSimpleHtml()));
}
return result;
}
use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.
the class CreditMemoReporterOperation method toOptimizedXls.
@Override
public FileJacket toOptimizedXls(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
m.message("Loading Credit Memos");
UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
List<Object[]> rows = new ArrayList<>();
List<Document> documents = new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE);
m.setWorkRemaining(documents.size());
for (Document document : documents) {
String salesDate = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMANY).format(document.getActual());
UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
double price = 0;
double afterTaxPrice = 0;
boolean full = true;
String sopos = "";
for (Position position : document.getPositions().values()) {
if (position.getType() == PositionType.COMMENT)
continue;
if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
full = position.getType() == PositionType.UNIT;
String refurbishId = unitEao.findById(position.getUniqueUnitId()).getRefurbishId();
sopos += (sopos.isEmpty()) ? refurbishId : " ," + refurbishId;
} else if (position.getType() == PositionType.SHIPPING_COST) {
Document invoice = document.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
SortedMap<Integer, Position> positions = invoice.getPositions(PositionType.SHIPPING_COST);
if (positions.size() > 0) {
Position get = positions.get(positions.firstKey());
if (Math.abs(Math.abs(get.getPrice()) - Math.abs(position.getPrice())) > 0.001)
full = false;
}
}
price += position.getPrice();
afterTaxPrice += position.toAfterTaxPrice();
}
rows.add(new Object[] { document.getDossier().getIdentifier(), customer.getId(), salesDate, document.getIdentifier(), (full) ? "V" : "T", price, afterTaxPrice, customer.getCompany(), customer.toNameLine(), sopos });
m.worked(1);
}
m.message("Generating Document");
m.setWorkRemaining(10);
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
table.add(new STableColumn("DossierId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Belegdatum", 10));
table.add(new STableColumn("DokumentId", 15)).add(new STableColumn("Voll/Teil", 10));
table.add(new STableColumn("Netto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
table.add(new STableColumn("Brutto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
table.add(new STableColumn("Firma", 25)).add(new STableColumn("Name", 25)).add(new STableColumn("SopoNr.", 10));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
cdoc.add(new CSheet("Sheet1", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
m.finish();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.
the class CreditMemoReporterOperation method toXls.
@Override
public FileJacket toXls(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
m.message("Loading Credit Memos");
List<Position> creditMemoPositions = new ArrayList<>();
for (Document document : new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.COMPLAINT, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE)) {
for (Position position : document.getPositions().values()) {
creditMemoPositions.add(position);
}
}
m.setWorkRemaining(creditMemoPositions.size() * 2);
UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
m.message(null);
List<Object[]> rows = new ArrayList<>();
for (Position position : creditMemoPositions) {
if (position.getType() == PositionType.COMMENT)
continue;
Document doc = position.getDocument();
UiCustomer customer = customerService.asUiCustomer(position.getDocument().getDossier().getCustomerId());
UniqueUnit unit = unitEao.findById(position.getUniqueUnitId());
String error = "ERROR FINDING UNIT";
String sopoNr = "-";
String serial = "-";
String contractor = "-";
String fullOrPartial = "-";
double customerPrice = 0;
double retailerPrice = 0;
if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
if (unit == null) {
sopoNr = error;
serial = error;
contractor = error;
} else {
sopoNr = unit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
serial = unit.getIdentifier(UniqueUnit.Identifier.SERIAL);
contractor = unit.getContractor().getName();
customerPrice = unit.getPrice(PriceType.CUSTOMER);
retailerPrice = unit.getPrice(PriceType.RETAILER);
fullOrPartial = (position.getType() == PositionType.UNIT ? "V" : "T");
if (position.getDocument().getType() == DocumentType.COMPLAINT)
fullOrPartial = "Rekla";
}
}
rows.add(new Object[] { sopoNr, serial, position.getName(), contractor, fullOrPartial, position.getPrice(), position.toAfterTaxPrice(), position.getDocument().getDossier().getIdentifier(), doc.getActual(), position.getDocument().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), customerPrice, retailerPrice });
m.worked(5);
}
Collections.sort(rows, comperator);
m.message("Generating Document");
m.setWorkRemaining(10);
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
table.add(new STableColumn("SopoNr", 15)).add(new STableColumn("Seriennummer", 30)).add(new STableColumn("Name", 50)).add(new STableColumn("Contractor", 15)).add(new STableColumn("Voll/Teil", 10)).add(new STableColumn("Netto", 10, EURO)).add(new STableColumn("Brutto", 10, EURO)).add(new STableColumn("DossierId", 15)).add(new STableColumn("Belegdatum", 10, new CFormat(SHORT_DATE))).add(new STableColumn("DokumentId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Kunde", 50)).add(new STableColumn("Endkundenpreis(Netto)", 25, EURO)).add(new STableColumn("Händlerpreis(Netto)", 25, EURO));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
cdoc.add(new CSheet("Sheet1", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
m.finish();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
Aggregations