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]));
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class RefurbishmentReporterOperation method toXls.
/**
* Generates the report between two dates for the contractor.
*
* @param contractor the contractor to report about.
* @param start the starting date
* @param end the end date
* @return an XLS document as FileJacket
*/
@Override
public FileJacket toXls(TradeName contractor, Date start, Date end) {
// TODO: Init me from contractor
double singleRefurbishPrice = 0.;
// TODO: Init me from contractor.
double singleRefillPrice = 0.;
double refurbishedPriceSum = 0.;
double refilledPriceSum = 0.;
SubMonitor m = monitorFactory.newSubMonitor("Refurbishment Abrechnung", 100);
m.message("Loading Units");
List<Object[]> refurbishedSopoUnits = new ArrayList<>();
List<Object[]> refilledSopoUnits = new ArrayList<>();
List<UniqueUnit> units = new UniqueUnitEao(uuem).findBetweenInputDatesAndContractor(start, end, contractor);
m.worked(10);
m.setWorkRemaining(units.size() + 10);
for (UniqueUnit uu : units) {
if (uu.getInternalComments().contains(StaticInternalComment.REFILLED)) {
refilledSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
refilledPriceSum += singleRefillPrice;
} else if (uu.getInternalComments().contains(StaticInternalComment.RECOVERT)) {
refurbishedSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
refurbishedPriceSum += singleRefurbishPrice;
}
}
double tax = (refilledPriceSum + refurbishedPriceSum) * GlobalConfig.DEFAULT_TAX.getTax();
CSheet summary = new CSheet("Summery", 5, 30, 15, 15, 15);
SBlock headerAndDate = new SBlock();
SBlock data = new SBlock();
SBlock prices = new SBlock();
headerAndDate.setFormat(new CFormat(BOLD, Color.BLACK, Color.WHITE, LEFT, new CBorder(Color.LIGHT_GRAY, CBorder.LineStyle.HAIR)));
headerAndDate.add("Report über recoverte und wiederaufgefüllte Geräte");
headerAndDate.add("Reportzeitraum:", DATE_FORMAT.format(start) + " - " + DATE_FORMAT.format(end));
summary.addBelow(1, 1, headerAndDate);
data.add("", "Anzahl", "Einzelpreis", "Summe");
data.add("Recoverte Geräte", refurbishedSopoUnits.size(), singleRefurbishPrice, EURO_FORMAT, refurbishedPriceSum, EURO_FORMAT);
data.add("Wiederaufgefüllte Geräte", refilledSopoUnits.size(), singleRefillPrice, EURO_FORMAT, refilledPriceSum, EURO_FORMAT);
summary.addBelow(1, 1, data);
prices.add("", "", "netto", refilledPriceSum + refurbishedPriceSum, EURO_FORMAT);
prices.add("", "", "Mwst", tax, EURO_FORMAT);
prices.add("", "", "Mwst", refilledPriceSum + refurbishedPriceSum + tax, EURO_FORMAT);
summary.addBelow(1, 1, prices);
STable refurbishedTable = new STable();
refurbishedTable.setHeadlineFormat(new CFormat(BOLD, Color.BLACK, Color.YELLOW, RIGHT, new CBorder(Color.BLACK)));
refurbishedTable.add(new STableColumn("Seriennummer", 22)).add(new STableColumn("Bezeichnnung", 40));
refurbishedTable.setModel(new STableModelList(refurbishedSopoUnits));
STable refilledTable = new STable(refurbishedTable);
refilledTable.setModel(new STableModelList(refilledSopoUnits));
CCalcDocument cdoc = new TempCalcDocument("RefurbishedReport_" + contractor);
cdoc.add(summary);
cdoc.add(new CSheet("Refurbished", refurbishedTable));
cdoc.add(new CSheet("Aufgefüllt", refilledTable));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
FileJacket result = new FileJacket("RefurbishedReport_" + contractor, ".xls", file);
m.finish();
return result;
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class ExporterOperation method toXls.
/**
* Creates a price compare sheet, expects a list of partNos and returns a xls File with last sales and estimated generated price
*
* @param partNos the partNos to inspect
* @return the xls file with informations
*/
private FileJacket toXls(String... partNos) {
// Create a Produkt with the part no;
SubMonitor m = monitorFactory.newSubMonitor("Auswertung über PartNos", partNos.length + 10);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
StockUnitEao suEao = new StockUnitEao(stockEm);
DocumentEao documentEao = new DocumentEao(redTapeEm);
List<List<Object>> model = new ArrayList<>();
for (String partNo : partNos) {
m.worked(1, "loading: " + partNo);
List<Object> line = new ArrayList<>();
model.add(line);
partNo = partNo.trim();
line.add(partNo);
List<UniqueUnit> uus = uniqueUnitEao.findByProductPartNo(partNo);
if (uus.isEmpty()) {
line.add("Keine Geräte oder Produkte im System.");
for (int i = 0; i < 14; i++) line.add(null);
continue;
}
Product product = uus.get(0).getProduct();
line.add(ProductFormater.toName(product));
line.add(uus.size());
line.add(maxPrice(uus, PriceType.CUSTOMER));
line.add(minPrice(uus, PriceType.RETAILER));
List<Document> documents = documentEao.findInvoiceWithProdcutId(product.getId());
for (int i = 0; i < 3; i++) {
if (documents.size() > i) {
// TODO: Was balancingId
line.add(documents.get(i).getActual());
line.add(priceByProductId(documents.get(i), product.getId()));
} else {
line.add(null);
line.add(null);
}
}
PriceEngineResult per = priceEngine.estimate(uus.get(0), productSpecEao.findByProductId(product.getId()), suEao.findByUniqueUnitId(uus.get(0).getId()).getStock().getName());
line.add(per.getCostPrice());
line.add(per.getRetailerPrice());
line.add(per.getCustomerPrice());
line.add(per.getRulesLog());
}
m.message("creating File");
STable table = new STable();
CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
CFormat date = new CFormat(CENTER, SHORT_DATE);
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("PartNo", 15)).add(new STableColumn("Name", 30));
table.add(new STableColumn("Menge im System", 12));
table.add(new STableColumn("VP(Min)", 12, euro)).add(new STableColumn("VP(Max)", 12, euro));
table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
table.add(new STableColumn("Cp", 12, euro)).add(new STableColumn("Hp", 12, euro)).add(new STableColumn("Ep", 12, euro));
table.add(new STableColumn("Rules", 40));
table.setModel(new STableModelList(model));
CCalcDocument cdoc = new TempCalcDocument("PartNoPrice_");
cdoc.add(new CSheet("PartNoPrice", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
FileJacket result = new FileJacket("PartNoPrice", ".xls", file);
m.finish();
return result;
}
use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.
the class ContractorPricePartNoExporterOperation method toManufacturerMissingXls.
@Override
public FileJacket toManufacturerMissingXls(TradeName contractorManufacturer) {
if (!contractorManufacturer.isManufacturer())
throw new RuntimeException(contractorManufacturer + " is not a Manufacturer, wrong exporter");
SubMonitor m = monitorFactory.newSubMonitor("Lieferanten und Hersteller Exporter");
m.message("Loading Units").start();
List<Object[]> rows = productEao.findByTradeNames(contractorManufacturer.getBrands()).stream().filter(p -> p.getPrice(MANUFACTURER_COST) <= 0.01).sorted().map(p -> new Object[] { p.getPartNo(), 0.0, ProductFormater.toName(p) }).collect(Collectors.toList());
m.setWorkRemaining(rows.size() + 10).message("Filtering");
m.message("Generating Document");
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE));
table.setHeadlineFormat(new CFormat(BOLD_ITALIC));
table.add(new STableColumn("Artikelnummer", 18)).add(new STableColumn("Kostpreis", 12, new CFormat(CURRENCY_EURO))).add(new STableColumn("Name", 45));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument();
cdoc.add(new CSheet("Kostpreise", table));
FileJacket result = new FileJacket("Fehlende " + contractorManufacturer.getName() + " Kostpreise vom " + ISO.format(new Date()), ".xls", new JExcelLucidCalcWriter().write(cdoc));
m.finish();
return result;
}
Aggregations