use of eu.ggnet.dwoss.redtape.ee.eao.DocumentEao 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.redtape.ee.eao.DocumentEao in project dwoss by gg-net.
the class DossierEmo method requestActiveDocumentBlock.
/**
* Requests an active Block for the supplied customerId, if none found creates one with the supplied parameters.
*
* @param customerId the customerId to find, or used.
* @param address address as string, only used on creation
* @param comment comment, only used on creation.
* @param arranger arranger, only used on creation.
* @return an active Block for the supplied customerId, if none found creates one with the supplied parameters.
*/
public Document requestActiveDocumentBlock(long customerId, String address, String comment, String arranger) {
Document doc = new DocumentEao(em).findActiveAndOpenByCustomerId(DocumentType.BLOCK, customerId);
if (doc != null)
return doc;
Dossier dossier = new Dossier();
dossier.setPaymentMethod(PaymentMethod.INVOICE);
dossier.setDispatch(false);
dossier.setCustomerId(customerId);
doc = new Document();
doc.setType(DocumentType.BLOCK);
doc.setActive(true);
doc.setDirective(Directive.NONE);
doc.setHistory(new DocumentHistory(arranger, comment));
Address addressEntity = new AddressEmo(em).request(address);
doc.setInvoiceAddress(addressEntity);
doc.setShippingAddress(addressEntity);
dossier.add(doc);
em.persist(dossier);
dossier.setIdentifier("DW" + _00000_.format(dossier.getId()));
return doc;
}
use of eu.ggnet.dwoss.redtape.ee.eao.DocumentEao in project dwoss by gg-net.
the class DocumentEaoIT method testfindInvoiceUnpaidAndfindUnBalancedAnulation.
@Test
public void testfindInvoiceUnpaidAndfindUnBalancedAnulation() throws Exception {
utx.begin();
em.joinTransaction();
Address address = new AddressEmo(em).request("A Test Address");
Document doc = RedTapeHelper.makeOrderDossier(PaymentMethod.DIRECT_DEBIT, address);
long customerId = doc.getDossier().getCustomerId();
RedTapeHelper.addUnitServiceAndComment(doc);
em.persist(doc.getDossier());
doc = RedTapeHelper.transitionTo(doc, INVOICE);
doc.setActive(true);
doc = RedTapeHelper.transitionTo(doc, ANNULATION_INVOICE);
doc.setActive(true);
doc.setDirective(BALANCE_REPAYMENT);
utx.commit();
utx.begin();
em.joinTransaction();
DocumentEao documentEao = new DocumentEao(em);
List<Document> docs = documentEao.findInvoiceUnpaid(PaymentMethod.DIRECT_DEBIT);
assertThat(docs).as("Found InvoiceUnpaid").hasSize(1);
docs = documentEao.findUnBalancedAnulation(customerId, PaymentMethod.DIRECT_DEBIT);
assertThat(docs).as("Found UnBalancedAnulation").hasSize(1);
utx.commit();
}
use of eu.ggnet.dwoss.redtape.ee.eao.DocumentEao in project dwoss by gg-net.
the class DocumentEaoIT method testFindDocumentsBetweenDates.
@Test
public void testFindDocumentsBetweenDates() throws Exception {
utx.begin();
em.joinTransaction();
makeAnAmountOfDocuments(3, 5, 2, true);
makeAnAmountOfDocuments(3, 5, 2, true);
makeAnAmountOfDocuments(3, 5, 2, true);
utx.commit();
utx.begin();
em.joinTransaction();
DocumentEao documentEao = new DocumentEao(em);
List<Document> docs = documentEao.findDocumentsBetweenDates(new Date(1234567891), new Date(), INVOICE, CREDIT_MEMO, ANNULATION_INVOICE);
assertThat(docs).describedAs("All Documents in Database").hasSize(6);
utx.commit();
}
use of eu.ggnet.dwoss.redtape.ee.eao.DocumentEao in project dwoss by gg-net.
the class MovementListingProducerOperation method generateList.
@Override
public JasperPrint generateList(ListType listType, Stock stock) {
SubMonitor m = monitorFactory.newSubMonitor("Versand und Abholung", 100);
m.message("lade Vorgänge");
m.start();
LogicTransactionEao ltEao = new LogicTransactionEao(stockEm);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
List<Document> documents = new DocumentEao(redTapeEm).findActiveByDirective(listType.getDirective());
m.worked(5);
m.setWorkRemaining(documents.size() + 2);
List<MovementLine> lines = new ArrayList<>();
List<String> dossierids = new ArrayList<>();
List<Long> systemCustomers = customerService.allSystemCustomerIds();
for (Document document : documents) {
if (systemCustomers.contains(document.getDossier().getCustomerId()))
continue;
m.worked(1, "verarbeite " + document.getDossier().getIdentifier());
LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
// Filter by stock
if (!hasUnitOnStock(lt, stock))
continue;
MovementLine line = new MovementLine();
line.setCustomerId(document.getDossier().getCustomerId());
line.setCustomerComment(customerService.findComment(document.getDossier().getCustomerId()));
line.setComment(document.getDossier().getComment());
line.setInvoiceAddress(document.getInvoiceAddress().getDescription());
line.setDeliveryAddress(document.getShippingAddress().getDescription());
line.setDossierIdentifier(document.getDossier().getIdentifier());
dossierids.add(document.getDossier().getIdentifier());
line.setPaymentMethod(document.getDossier().getPaymentMethod().getNote());
for (StockUnit stockUnit : lt.getUnits()) {
UniqueUnit uniqueUnit = uniqueUnitEao.findById(stockUnit.getUniqueUnitId());
Product p = uniqueUnit.getProduct();
MovementSubline elem = new MovementSubline(1, (p == null ? "Kein Produkt" : ProductFormater.toName(p) + " (" + p.getGroup().getNote() + ")"), uniqueUnit.getRefurbishId(), (stockUnit.getStock() == null ? stockUnit.getTransaction().toString() : stockUnit.getStock().getName()), uniqueUnit.getInternalComments().contains(UniqueUnit.StaticInternalComment.PREPARED_SHIPMENT));
line.addMovementSubline(elem);
}
lines.add(line);
}
String title = listType.getName() + " - " + stock.getName();
L.info("generateList {} containing {}", title, dossierids);
m.message("erzeuge Report");
Map<String, Object> reportParameter = new HashMap<>();
reportParameter.put("TITLE", title);
JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(lines);
String name = "MovementList.jrxml";
URL url = Objects.requireNonNull(getClass().getResource(name), "The Resource " + getClass().getPackage() + "/" + name + " not found.");
try (InputStream is = url.openStream()) {
JasperReport jasperReport = JasperCompileManager.compileReport(is);
JasperPrint result = JasperFillManager.fillReport(jasperReport, reportParameter, datasource);
return result;
} catch (IOException | JRException e) {
L.error("Exception during movementList", e);
throw new RuntimeException(e);
} finally {
m.finish();
}
}
Aggregations