use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class SalesChannelHandlerOperation method findAvailableUnits.
/**
* Returns all units, which are in a stock. Units which are on a transaction, are not displayed.
*
* TODO: Turn it around. Fist take all StockUnits, which are not in a transaction. Then filter them against the SopoUnit information
* <p/>
* @return all units, which are in a stock
*/
@Override
public List<SalesChannelLine> findAvailableUnits() {
SubMonitor m = monitorFactory.newSubMonitor("Verkaufskanalmanager vorbereiten", 100);
m.setLogger(L);
m.start();
final UniqueUnitEao uniqueUnitService = new UniqueUnitEao(uuEm);
List<SalesChannelLine> lines = new ArrayList<>();
m.message("Loading all available units.");
List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoTransaction();
m.worked(10);
m.setWorkRemaining(stockUnits.size() + 5);
for (StockUnit stockUnit : stockUnits) {
m.worked(1, "Handling SopoNr " + stockUnit.getRefurbishId());
UniqueUnit uniqueUnit = uniqueUnitService.findById(stockUnit.getUniqueUnitId());
if (uniqueUnit == null)
throw new RuntimeException("StockUnit(id=" + stockUnit.getId() + ",uniqueUnitId=" + stockUnit.getUniqueUnitId() + ") has no uniqueUnit");
if (uniqueUnit.getProduct() == null)
L.warn("UniqueUnit(id=" + uniqueUnit.getId() + ").product==null");
lines.add(SalesChannelLine.builder().unitId(stockUnit.getId()).refurbishedId(uniqueUnit.getRefurbishId()).description(ProductFormater.toName(uniqueUnit.getProduct())).comment((uniqueUnit.getEquipments().contains(Equipment.ORIGINAL_BOXED) ? "Originalkarton, " : "") + (uniqueUnit.getCondition().getNote())).retailerPrice(uniqueUnit.getPrice(RETAILER)).customerPrice(uniqueUnit.getPrice(CUSTOMER)).stockName(stockUnit.getStock().getName()).salesChannel(uniqueUnit.getSalesChannel()).originalSalesChannel(uniqueUnit.getSalesChannel()).stockId(stockUnit.getStock().getId()).build());
m.worked(1);
}
m.finish();
return lines;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class SalesListingProducerOperation method toSortedMap.
private SortedMap<UniqueUnit, StockUnit> toSortedMap(List<UniqueUnit> uniqueUnits, List<StockUnit> stockUnits, Comparator<UniqueUnit> comparator) {
Map<Integer, UniqueUnit> uuIdMs = new HashMap<>(uniqueUnits.size());
for (UniqueUnit uniqueUnit : uniqueUnits) {
uuIdMs.put(uniqueUnit.getId(), uniqueUnit);
}
SortedMap<UniqueUnit, StockUnit> uusu = new TreeMap<>(comparator);
for (StockUnit stockUnit : stockUnits) {
uusu.put(uuIdMs.get(stockUnit.getUniqueUnitId()), stockUnit);
}
return uusu;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class SalesListingProducerOperation method generatePdfListings.
/**
* Generates PDF files for units in a specific sales channel.
* The lists are seperated by brand.
* <p>
* @param channel the saleschannel
* @return PDF files for units in a specific sales channel.
*/
private Map<TradeName, Collection<FileJacket>> generatePdfListings(SalesChannel channel) throws UserInfoException {
SubMonitor m = monitorFactory.newSubMonitor("Endkundenlisten erstellen", 10);
m.message("lade Gerätedaten");
m.start();
List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransaction();
List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits));
PriceType priceType = (channel == SalesChannel.CUSTOMER ? PriceType.CUSTOMER : PriceType.RETAILER);
m.worked(2, "prüfe und filtere Geräte");
SortedMap<UniqueUnit, StockUnit> uusus = toSortedMap(uniqueUnits, stockUnits, new UniqueUnitComparator());
for (Iterator<Map.Entry<UniqueUnit, StockUnit>> it = uusus.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<UniqueUnit, StockUnit> entry = it.next();
UniqueUnit uu = entry.getKey();
StockUnit su = entry.getValue();
if (uu == null)
throw new NullPointerException(su + " has no UniqueUnit, Database Error");
if (uu.getSalesChannel() != channel || !uu.hasPrice(priceType) || su.isInTransaction()) {
it.remove();
}
}
L.info("Selected {} Units for the Lists", uusus.size());
m.worked(1, "sortiere und bereite Geräte vor");
Map<Product, Set<UniqueUnit>> stackedUnits = new HashMap<>();
for (Map.Entry<UniqueUnit, StockUnit> entry : uusus.entrySet()) {
Product p = entry.getKey().getProduct();
if (!stackedUnits.containsKey(p))
stackedUnits.put(p, new HashSet<>());
stackedUnits.get(p).add(entry.getKey());
}
List<StackedLine> stackedLines = new ArrayList<>(stackedUnits.size());
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
df.applyPattern("#,###,##0.00");
for (Map.Entry<Product, Set<UniqueUnit>> entry : stackedUnits.entrySet()) {
Product p = entry.getKey();
StackedLine line = new StackedLine();
line.setBrand(p.getTradeName());
line.setGroup(p.getGroup());
line.setCommodityGroupName(p.getGroup().getNote());
line.setDescription(p.getDescription());
line.setManufacturerName(p.getTradeName().getName());
line.setManufacturerPartNo(p.getPartNo());
line.setName(p.getName());
line.setImageUrl(imageFinder.findImageUrl(p.getImageId()));
boolean priceChanged = false;
double customerPrice = 0;
for (UniqueUnit uu : entry.getValue()) {
StackedLineUnit elem = new StackedLineUnit();
elem.setAccessories(UniqueUnitFormater.toSingleLineAccessories(uu));
elem.setComment(UniqueUnitFormater.toSingleLineComment(uu));
elem.setConditionLevelDescription(uu.getCondition().getNote());
elem.setMfgDate(uu.getMfgDate());
elem.setRefurbishedId(uu.getRefurbishId());
elem.setSerial(uu.getSerial());
elem.setWarranty(uu.getWarranty().getName());
if (uu.getWarranty().equals(Warranty.WARRANTY_TILL_DATE))
elem.setWarrentyTill(uu.getWarrentyValid());
double uuPrice = uu.getPrice(priceType);
elem.setCustomerPrice(uuPrice);
elem.setRoundedTaxedCustomerPrice(TwoDigits.roundedApply(uuPrice, GlobalConfig.DEFAULT_TAX.getTax(), 0.02));
// For the "ab € XXX" handler
if (customerPrice == 0) {
customerPrice = uuPrice;
} else if (customerPrice > uuPrice) {
customerPrice = uuPrice;
priceChanged = true;
} else if (customerPrice < uuPrice) {
priceChanged = true;
}
elem.normaize();
line.add(elem);
}
line.setAmount(line.getUnits().size());
line.setCustomerPriceLabel((priceChanged ? "ab €" : "€") + df.format(TwoDigits.roundedApply(customerPrice, GlobalConfig.DEFAULT_TAX.getTax(), 0.02)));
line.normaize();
stackedLines.add(line);
}
L.info("Created {} Lines for the Lists", stackedLines.size());
m.worked(1, "erzeuge listen");
Set<ListingConfiguration> configs = new HashSet<>();
if (listingService.isAmbiguous() || listingService.isUnsatisfied()) {
for (TradeName brand : TradeName.values()) {
for (ProductGroup value : ProductGroup.values()) {
configs.add(ListingConfiguration.builder().filePrefix("Geräteliste ").name(brand.getName() + " " + value.getName()).brand(brand).groups(EnumSet.of(value)).headLeft("Beispieltext Links\nZeile 2").headCenter("Beispieltext Mitte\nZeile 2").headRight("Beispieltext Rechts\nZeile 2").footer("Fusszeilentext").build());
}
}
} else {
configs.addAll(listingService.get().listingConfigurations());
}
m.setWorkRemaining(configs.size() + 1);
Map<TradeName, Collection<FileJacket>> jackets = new HashMap<>();
for (ListingConfiguration config : configs) {
m.worked(1, "erstelle Liste " + config.getName());
if (StringUtils.isBlank(config.getJasperTemplateFile()))
config.setJasperTemplateFile(compileReportToTempFile("CustomerSalesListing"));
if (StringUtils.isBlank(config.getJasperTempleteUnitsFile()))
config.setJasperTempleteUnitsFile(compileReportToTempFile("CustomerSalesListingUnits"));
FileJacket fj = createListing(config, stackedLines);
if (fj != null) {
if (!jackets.containsKey(config.getBrand()))
jackets.put(config.getBrand(), new HashSet<>());
jackets.get(config.getBrand()).add(fj);
}
}
m.finish();
return jackets;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class SalesListingProducerOperation method generateXlsListings.
/**
* Generates XLS files for units in a specific sales channel.
* The lists are seperated by brand.
* <p>
* @param channel the saleschannel
* @return XLS files for units in a specific sales channel.
*/
private Map<TradeName, Collection<FileJacket>> generateXlsListings(SalesChannel channel) {
SubMonitor m = monitorFactory.newSubMonitor("Listen für " + channel.getName() + " erstellen", 100);
m.start();
List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransactionAndPresentStock();
List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits));
Map<TradeName, List<UniqueUnit>> units = uniqueUnits.stream().collect(Collectors.groupingBy(uu -> uu.getProduct().getTradeName()));
m.worked(2, "prüfe und filtere Geräte");
Map<TradeName, Collection<FileJacket>> files = new HashMap<>();
for (TradeName k : units.keySet()) {
List<UniqueUnit> uus = units.get(k);
Collections.sort(uus, new UniqueUnitComparator());
List<Object[]> rows = new ArrayList<>();
for (UniqueUnit get : uus) {
UniqueUnit uu = get;
Product p = uu.getProduct();
// Cases to filter out.
if (uu.getSalesChannel() != channel)
continue;
if (!uu.hasPrice((channel == SalesChannel.CUSTOMER ? PriceType.CUSTOMER : PriceType.RETAILER)))
continue;
Object[] row = { uu.getRefurbishId(), p.getPartNo(), p.getGroup().getNote(), p.getTradeName().getName(), p.getName(), p.getDescription(), uu.getWarranty().getName(), uu.getWarrentyValid(), UniqueUnitFormater.toSingleLineAccessories(uu), uu.getCondition().getNote(), UniqueUnitFormater.toSingleLineComment(uu), uu.getPrice(PriceType.RETAILER), uu.getPrice(PriceType.CUSTOMER), (!uu.hasPrice(PriceType.CUSTOMER) ? null : TwoDigits.roundedApply(uu.getPrice(PriceType.CUSTOMER), GlobalConfig.DEFAULT_TAX.getTax(), 0)) };
rows.add(row);
}
if (rows.isEmpty())
continue;
m.worked(5, "creating File, Geräte: " + rows.size());
STable unitTable = new STable();
unitTable.setTableFormat(new CFormat(CENTER, TOP, new CBorder(Color.GRAY, CBorder.LineStyle.THIN), true));
unitTable.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.LIGHT_GRAY, CENTER, MIDDLE));
unitTable.setRowHeight(1000);
unitTable.add(new STableColumn("SopoNr", 12));
unitTable.add(new STableColumn("ArtikelNr", 15));
unitTable.add(new STableColumn("Warengruppe", 18));
unitTable.add(new STableColumn("Hersteller", 15));
unitTable.add(new STableColumn("Bezeichnung", 30));
unitTable.add(new STableColumn("Beschreibung", 60, LFT));
unitTable.add(new STableColumn("Garantie", 18, LFT));
unitTable.add(new STableColumn("Garantie bis", 18, new CFormat(Representation.SHORT_DATE)));
unitTable.add(new STableColumn("Zubehör", 30, LFT));
unitTable.add(new STableColumn("optische Bewertung", 25));
unitTable.add(new STableColumn("Bemerkung", 50, LFT));
unitTable.add(new STableColumn("Händler", 15, EURO));
unitTable.add(new STableColumn("Endkunde", 15, EURO));
unitTable.add(new STableColumn("E.inc.Mwst", 15, EURO));
unitTable.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument();
cdoc.add(new CSheet("Sonderposten", unitTable));
files.put(k, Arrays.asList(new FileJacket(k.getName() + " Liste", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc))));
}
m.finish();
return files;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class PersistenceValidatorOperation method validateLogicTransaction.
/**
* This Method Validate all LogicTransaction that will be given.
* First it checks if all UUIds from the Document are in the Logictransaction.
* Then check its in the opposite way.
* <p/>
* @param transactions
* @param dossiers
* @param m
* @return
*/
private void validateLogicTransaction(List<Vm> vms, List<LogicTransaction> transactions, List<Dossier> dossiers, SubMonitor m) {
Map<Long, Dossier> dossierMap = new HashMap<>();
m.setWorkRemaining(transactions.size());
for (Dossier dossier : dossiers) {
dossierMap.put(dossier.getId(), dossier);
}
for (LogicTransaction logicTransaction : transactions) {
m.worked(1, "Validate: LogicTransaction:" + logicTransaction.getId());
Dossier dossier = dossierMap.get(logicTransaction.getDossierId());
DocumentType type = getMostImportandDocument(dossierMap.get(logicTransaction.getDossierId())).getType();
// TODO: Here you discard cases, not good.
if (type != DocumentType.INVOICE && type != DocumentType.ORDER) {
continue;
}
List<Integer> stockUuIds = toUniqueUnitIds(logicTransaction);
if (!stockUuIds.containsAll(dossier.getRelevantUniqueUnitIds())) {
error(vms, "Stock asynchron zu Dossier. LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ") ->" + "Dossier( id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ", relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ")");
}
if (!dossier.getRelevantUniqueUnitIds().containsAll(stockUuIds)) {
error(vms, "Dossier asynchron zu Stock." + "Dossier(id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ",relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ") -> LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ")");
}
for (StockUnit stockUnit : logicTransaction.getUnits()) {
Set<ConstraintViolation<StockUnit>> validateError = validator.validate(stockUnit);
if (!validateError.isEmpty()) {
error(vms, ConstraintViolationFormater.toSingleLine(validateError));
}
}
}
m.finish();
}
Aggregations