use of eu.ggnet.dwoss.price.engine.PriceEngineResult 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.price.engine.PriceEngineResult 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.price.engine.PriceEngineResult 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;
}
use of eu.ggnet.dwoss.price.engine.PriceEngineResult in project dwoss by gg-net.
the class PriceCoreOperationIT method testStore.
@Test
public void testStore() {
stockGenerator.makeStocksAndLocations(2);
receiptGenerator.makeUniqueUnits(20, true, false);
// Estimate all Units
List<PriceEngineResult> pers = priceCore.loadAndCalculate(null);
final double fixedUnitPrice = 100;
final double fixedProductPrice = 50;
String fixedPriceRefurbishId = pers.get(0).getRefurbishedId();
pers.get(0).setCustomerPrice(100);
pers.get(0).setRetailerPrice(100);
pers.get(0).setUnitPriceFixed(PriceEngineResult.Change.SET);
String fixedPartNo = pers.get(3).getManufacturerPartNo();
pers.get(3).setCustomerPrice(50);
pers.get(3).setRetailerPrice(50);
pers.get(3).setManufacturerPartPriceFixed(PriceEngineResult.Change.SET);
priceCore.store(pers, "via test", "testuser", null);
UniqueUnit uniqueUnit = uniqueUnitAgent.findUnitByIdentifierEager(Identifier.REFURBISHED_ID, fixedPriceRefurbishId);
assertEquals(fixedUnitPrice, uniqueUnit.getPrice(PriceType.CUSTOMER), 0.001);
assertEquals(fixedUnitPrice, uniqueUnit.getPrice(PriceType.RETAILER), 0.001);
assertTrue("Unit should contain Flage PriceFixed" + uniqueUnit.getFlags(), uniqueUnit.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED));
for (PriceHistory priceHistory : uniqueUnit.getPriceHistory()) {
assertTrue(priceHistory.getComment().contains("unitfix"));
assertEquals(fixedUnitPrice, priceHistory.getPrice(), 0.001);
assertTrue(priceHistory.getType() == PriceType.CUSTOMER || priceHistory.getType() == PriceType.RETAILER);
}
Product product = uniqueUnitAgent.findProductByPartNoEager(fixedPartNo);
assertEquals(fixedProductPrice, product.getPrice(PriceType.CUSTOMER), 0.001);
assertEquals(fixedProductPrice, product.getPrice(PriceType.RETAILER), 0.001);
assertTrue(product.getFlags().contains(Product.Flag.PRICE_FIXED));
for (PriceHistory priceHistory : product.getPriceHistory()) {
assertTrue(priceHistory.getComment().contains("productfix"));
assertEquals(fixedProductPrice, priceHistory.getPrice(), 0.001);
assertTrue(priceHistory.getType() == PriceType.CUSTOMER || priceHistory.getType() == PriceType.RETAILER);
}
}
use of eu.ggnet.dwoss.price.engine.PriceEngineResult in project dwoss by gg-net.
the class ImportPriceManagementLogicTest method testFromXls.
@Test
public void testFromXls() throws UserInfoException {
PriceCoreOperation core = mock(PriceCoreOperation.class);
ImporterOperation importer = new ImporterOperation(core, new ProgressProducerForTests());
FileJacket jacket = new FileJacket("Sample", "xls", new File("target/test-classes/ImportPriceManagementLogicSamples.xls"));
importer.fromXls(jacket, "testuser");
List<PriceEngineResult> expected = new ArrayList<>();
expected.add(new PriceEngineResult("1", "A", 1.0, 1.0, 0, 1, 0));
expected.add(new PriceEngineResult("2", "A", 2.0, 2.0, 1, 0, 0));
expected.add(new PriceEngineResult("3", "B", 3.0, 3.0, 0, -1, 0));
expected.add(new PriceEngineResult("4", "B", 4.0, 4.0, 1, 0, 0));
expected.add(new PriceEngineResult("5", "C", 5.0, 5.0, 0, 0, 1));
verify(core).store(eq(expected), eq("ImportPriceManagementOperation.fromXls()"), anyString(), any(IMonitor.class));
}
Aggregations