use of eu.ggnet.dwoss.util.FileJacket 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.util.FileJacket 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);
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class DirectDebitReporterOperation method toXls.
/**
* Creates the Report
* <p/>
* @return a ByteArray represeting the content of an xls file.
*/
@Override
public FileJacket toXls() {
SubMonitor m = monitorFactory.newSubMonitor("Lastschriften", 25);
m.worked(10);
DocumentEao docEao = new DocumentEao(redTapeEm);
List<Document> documents = docEao.findInvoiceUnpaid(DIRECT_DEBIT);
Set<Long> customers = new HashSet<>();
for (Document document : documents) {
customers.add(document.getDossier().getCustomerId());
}
for (Long customerId : customers) {
documents.addAll(docEao.findUnBalancedAnulation(customerId, DIRECT_DEBIT));
}
List<Object[]> rows = new ArrayList<>();
for (Document doc : documents) {
UiCustomer customer = customerService.asUiCustomer(doc.getDossier().getCustomerId());
rows.add(new Object[] { doc.getDossier().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), doc.getDirective().getName(), DocumentFormater.toConditions(doc), doc.getIdentifier(), doc.getActual(), doc.getPrice(), doc.toAfterTaxPrice(), doc.getDossier().getComment(), customerService.asCustomerMetaData(customer.getId()).getEmail() });
}
m.worked(10);
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
table.add(new STableColumn("Vorgang", 10)).add(new STableColumn("KID", 8)).add(new STableColumn("Kunde", 40));
table.add(new STableColumn("Anweisung", 35)).add(new STableColumn("Status", 20)).add(new STableColumn("Dokument", 15)).add(new STableColumn("Datum", 15, new CFormat(SHORT_DATE)));
table.add(new STableColumn("Netto", 15, new CFormat(RIGHT, CURRENCY_EURO))).add(new STableColumn("Brutto", 15, new CFormat(RIGHT, CURRENCY_EURO)));
table.add(new STableColumn("Bemerkung", 50)).add(new STableColumn("eMail", 50));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Lastschriften");
cdoc.add(new CSheet("Sheet1", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
FileJacket result = new FileJacket("Lastschriften", ".xls", file);
m.finish();
return result;
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class SageExporterOperation method toXml.
/**
* Exports the all Documents in the Range as the specified XML lines.
* <p/>
* @param start the starting date
* @param end the ending date
* @return an Xml document, ready for import in GS Office.
*/
@Override
@AutoLogger
public FileJacket toXml(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("GS Buchhalter Export", 100);
m.start();
m.message("Loading Invoices");
DocumentEao documentEao = new DocumentEao(redTapeEm);
List<Document> documents = new ArrayList<>();
documents.addAll(documentEao.findDocumentsBetweenDates(start, end, INVOICE, CREDIT_MEMO, ANNULATION_INVOICE));
L.info("Loaded {} amount of documents", documents.size());
m.worked(10);
Map<Document, UiCustomer> customerInvoices = new HashMap<>();
m.setWorkRemaining(documents.size() * 2);
for (Document document : documents) {
m.worked(1, "Handling Invoice " + document.getIdentifier());
customerInvoices.put(document, customerService.asUiCustomer(document.getDossier().getCustomerId()));
}
m.message("Generating Outfile");
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
SageExporterEngine exporter = new SageExporterEngine(out, customerInvoices, config);
exporter.execute(m);
m.finish();
return new FileJacket("Buchungsaetze DW " + mandator.getCompany().getName() + " von " + DATE_FORMAT.format(start) + " bis " + DATE_FORMAT.format(end), ".xml", out.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class CreditMemoReportIT method testCreditMemoReportOperation.
@Test
public void testCreditMemoReportOperation() throws IOException, InterruptedException {
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
UniqueUnit uu1 = uus.get(0);
UniqueUnit uu2 = uus.get(1);
UniqueUnit uu3 = uus.get(2);
UniqueUnit uu4 = uus.get(3);
Product uuProduct1 = uu1.getProduct();
assertThat(uu1).describedAs("First generated UniqueUnit").isNotNull();
StockUnit su1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
assertThat(su1).describedAs("StockUnit of generated UniqueUnit").isNotNull();
assertThat(su1.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
int stockIdOfUU1 = su1.getStock().getId();
Dossier dos = redTapeWorker.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
doc.append(unit(uu1));
doc.append(unit(uu2));
doc.append(unit(uu3));
doc.append(comment());
doc.append(service());
doc.append(batch(uuProduct1));
doc.append(shippingcost());
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeWorker.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
LogicTransaction lt = support.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
// A CreditMemo for Unit1, negate prices on Annulation Invoice.
for (Position pos : new ArrayList<>(doc.getPositions().values())) {
if (pos.getUniqueUnitId() == uu1.getId() || pos.getType() == PRODUCT_BATCH || pos.getType() == SHIPPING_COST) {
pos.setPrice(pos.getPrice() * -1);
} else {
doc.remove(pos);
}
}
assertEquals("Document should have exactly one possition", 3, doc.getPositions().size());
doc.setType(DocumentType.ANNULATION_INVOICE);
doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
Collection<Position> positions = doc.getPositions().values();
// Report somethere in the past till now.
FileJacket jacket = reportOperation.toXls(new Date(1352115909), new Date());
assertNotNull(jacket);
assertEquals(".xls", jacket.getSuffix());
assertTrue(jacket.getContent().length > 0);
List<LoadContainer> read = new JExcelLucidCalcReader().addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, String.class).addColumn(4, String.class).addColumn(5, Double.class).addColumn(6, Double.class).read(jacket.toTemporaryFile(), LoadContainer.class);
// HINT: Not a complete test, but some fileds at least.
assertThat(positions.stream().map(Position::getPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.netto).toArray((v) -> new Double[v]));
assertThat(positions.stream().map(Position::toAfterTaxPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.brutto).toArray((v) -> new Double[v]));
assertThat(positions.stream().map(Position::getName).collect(toSet())).containsOnly(read.stream().map(l -> l.name).toArray((v) -> new String[v]));
}
Aggregations