use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class ReceiptGeneratorOperation method makeProductSpecs.
/**
* Generates an amount of ProductSpecs and receipts them.
* Persists entities in spec and uniqueunit.
*
* @param amount the amount to generate.
* @param generateCostPrice
* @return the generated and receipted specs.
*/
public List<ProductSpec> makeProductSpecs(int amount, boolean generateCostPrice) {
L.info("Generating {} Products", amount);
SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Products", amount);
m.start();
List<ProductSpec> specs = new ArrayList<>();
for (int i = 0; i < amount; i++) {
ProductSpec spec = makeProductSpec(generateCostPrice);
specs.add(spec);
m.worked(1, spec.getPartNo());
}
m.finish();
return specs;
}
use of eu.ggnet.dwoss.progress.SubMonitor 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.progress.SubMonitor 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.progress.SubMonitor in project dwoss by gg-net.
the class PriceCoreOperation method store.
/**
* Stores the supplied Prices to units and the manufacturerPartNoPriceFixeds
*
* @param pers results to store
* @param comment a comment for the price history
* @param arranger a arranger for the price history
* @param monitor an optional monitor
*/
public void store(final List<PriceEngineResult> pers, String comment, String arranger, IMonitor monitor) {
final SubMonitor m = SubMonitor.convert(monitor, pers.size() + 27);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
ProductEao productEao = new ProductEao(uuEm);
// preload sopo and unique units
m.message("Preloading UniqueUnits");
NavigableMap<String, UniqueUnit> uniqueUnits = UniqueUnit.asMapByRefurbishId(uniqueUnitEao.findByIdentifiers(REFURBISHED_ID, PriceEngineResult.toRefurbishIds(pers)));
m.worked(5);
for (PriceEngineResult per : pers) {
String msg = "Storing Unit " + per.getRefurbishedId() + " HP:" + per.getRetailerPrice() + " EP:" + per.getCustomerPrice() + " UnitFix:" + per.getUnitPriceFixed() + " ProductFix:" + per.getManufacturerPartPriceFixed();
L.info(msg);
m.worked(1, msg);
update(uniqueUnits.get(per.getRefurbishedId()), per, arranger, comment);
}
// Inferenced filtering for fixprices
Map<String, PriceEngineResult> fixPriceImports = new HashMap<>();
for (PriceEngineResult per : pers) {
if (per.getManufacturerPartPriceFixed() == NO_CHANGE)
continue;
fixPriceImports.put(per.getManufacturerPartNo(), per);
}
m.worked(1, "Perloading Products");
NavigableMap<String, Product> products = Product.asMapByPartNos(productEao.findByPartNos(PriceEngineResult.toPartNos(pers)));
m.worked(3);
m.setWorkRemaining(fixPriceImports.size());
for (PriceEngineResult per : fixPriceImports.values()) {
update(products.get(per.getManufacturerPartNo()), per, arranger, comment);
String msg = "Storing ProductDescription Fixed Price " + per.getProductName() + " Retailer:" + per.getRetailerPrice() + " Customer:" + per.getCustomerPrice() + " Manual:" + per.getManufacturerPartPriceFixed();
L.info(msg);
m.worked(1, msg);
}
m.finish();
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class PriceCoreOperation method loadAndCalculate.
/**
* Loads all AVAILABLE SopoUnits from the Sopodb an puts them trough the PriceEngine
*
* @param monitor
* @return
*/
public List<PriceEngineResult> loadAndCalculate(IMonitor monitor) {
L.info("Starting loadAndCalculate()");
final SubMonitor m = SubMonitor.convert(monitor, 100);
m.start();
final StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
m.message("loading Units");
List<Integer> uuids = stockUnitEao.findByNoLogicTransactionAsUniqueUnitId();
List<UniqueUnit> uus = uniqueUnitEao.findByIds(uuids);
m.worked(10, "updating Eols");
updateEols(uus);
m.worked(5, "loading ProductSpecs");
Set<Product> products = toProducts(uus);
List<ProductSpec> productSpecs = productSpecEao.findByProductIds(toProductIds(products));
Map<Product, ProductSpec> productToSpecs = toProductProductSpec(products, productSpecs);
m.worked(10);
final List<PriceEngineResult> pers = new ArrayList<>();
m.setWorkRemaining(uus.size() + 5);
for (UniqueUnit uu : uus) {
m.worked(1, "Calculating RefurbishId(" + uu.getRefurbishId() + ")");
StockUnit su = stockUnitEao.findByUniqueUnitId(uu.getId());
pers.add(priceEngine.estimate(uu, productToSpecs.get(uu.getProduct()), su.getStock() != null ? su.getStock().getName() : "kein Lager"));
}
m.finish();
L.info("Finished loadAndCalculate(), estimated {} Units", pers.size());
return pers;
}
Aggregations