use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class UnitOverseerBean method internalFind.
private UnitShard internalFind(String refurbishId) {
L.debug("find({})", refurbishId);
UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
UniqueUnit uu = uuEao.findByIdentifier(Identifier.REFURBISHED_ID, refurbishId);
String oldRefurbishedOd = null;
L.debug("find({}) uniqueUnit={}", refurbishId, uu);
if (uu == null) {
uu = uuEao.findByRefurbishedIdInHistory(refurbishId);
if (uu == null) {
if (!bridgeInstance.isUnsatisfied() && !bridgeInstance.get().isUnitIdentifierAvailable(refurbishId)) {
return new UnitShard(refurbishId, 0, toHtmlDescription(refurbishId, null, "Nicht Verfügbar", "", "(Auskunft aus Sopo)"), false, null);
} else {
return new UnitShard(refurbishId, 0, "<html>SopoNr.:<b>" + refurbishId + "<u> existiert nicht.</u><br /><br /></b></html>", null, null);
}
} else {
oldRefurbishedOd = "(Frühere SopoNr: " + refurbishId + ")";
refurbishId = uu.getIdentifier(REFURBISHED_ID);
}
}
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
L.debug("find({}) stockUnit={}", refurbishId, stockUnit);
Integer stockId = null;
if (stockUnit != null && stockUnit.isInStock())
stockId = stockUnit.getStock().getId();
if (stockUnit == null) {
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", "", null), false, null);
}
if (stockUnit.getLogicTransaction() != null) {
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, null), false, stockId);
}
// If the Database is clean, the Unit is available, but we make some safty checks here.
if (new DossierEao(redTapeEm).isUnitBlocked(uu.getId())) {
L.warn("find({}) Database Error RedTape sanity check", refurbishId);
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, "(Datenbankfehler, RedTape sanity check!)"), false, stockId);
}
// Now we are shure.
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Verfügbar", stockUnit, null), true, stockId);
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class UnitOverseerBean method toDetailedHtml.
/**
* Find a Unit and its representative and return a html formated String representing it.
* Ensure to add the html start/end tags manually
* <p/>
* @param uniqueUnitId the uniqueUnitId
* @param username
* @return a html formated String representing a Unit.
*/
@Override
public String toDetailedHtml(int uniqueUnitId, String username) {
UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
UniqueUnit uniqueUnit = uuEao.findById(uniqueUnitId);
if (uniqueUnit != null)
return toDetailedHtmlUnit(uniqueUnit, hasRight(username, AtomicRight.VIEW_COST_AND_REFERENCE_PRICES));
// Unique Unit is null, optional fallback to legacy system.
return "<h1>Keine Informationen zu UniqueUnitId " + uniqueUnitId + "</h1>";
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class CreditMemoReporterOperation method toOptimizedXls.
@Override
public FileJacket toOptimizedXls(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
m.message("Loading Credit Memos");
UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
List<Object[]> rows = new ArrayList<>();
List<Document> documents = new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE);
m.setWorkRemaining(documents.size());
for (Document document : documents) {
String salesDate = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMANY).format(document.getActual());
UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
double price = 0;
double afterTaxPrice = 0;
boolean full = true;
String sopos = "";
for (Position position : document.getPositions().values()) {
if (position.getType() == PositionType.COMMENT)
continue;
if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
full = position.getType() == PositionType.UNIT;
String refurbishId = unitEao.findById(position.getUniqueUnitId()).getRefurbishId();
sopos += (sopos.isEmpty()) ? refurbishId : " ," + refurbishId;
} else if (position.getType() == PositionType.SHIPPING_COST) {
Document invoice = document.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
SortedMap<Integer, Position> positions = invoice.getPositions(PositionType.SHIPPING_COST);
if (positions.size() > 0) {
Position get = positions.get(positions.firstKey());
if (Math.abs(Math.abs(get.getPrice()) - Math.abs(position.getPrice())) > 0.001)
full = false;
}
}
price += position.getPrice();
afterTaxPrice += position.toAfterTaxPrice();
}
rows.add(new Object[] { document.getDossier().getIdentifier(), customer.getId(), salesDate, document.getIdentifier(), (full) ? "V" : "T", price, afterTaxPrice, customer.getCompany(), customer.toNameLine(), sopos });
m.worked(1);
}
m.message("Generating Document");
m.setWorkRemaining(10);
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
table.add(new STableColumn("DossierId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Belegdatum", 10));
table.add(new STableColumn("DokumentId", 15)).add(new STableColumn("Voll/Teil", 10));
table.add(new STableColumn("Netto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
table.add(new STableColumn("Brutto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
table.add(new STableColumn("Firma", 25)).add(new STableColumn("Name", 25)).add(new STableColumn("SopoNr.", 10));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
cdoc.add(new CSheet("Sheet1", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
m.finish();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class CreditMemoReporterOperation method toXls.
@Override
public FileJacket toXls(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
m.message("Loading Credit Memos");
List<Position> creditMemoPositions = new ArrayList<>();
for (Document document : new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.COMPLAINT, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE)) {
for (Position position : document.getPositions().values()) {
creditMemoPositions.add(position);
}
}
m.setWorkRemaining(creditMemoPositions.size() * 2);
UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
m.message(null);
List<Object[]> rows = new ArrayList<>();
for (Position position : creditMemoPositions) {
if (position.getType() == PositionType.COMMENT)
continue;
Document doc = position.getDocument();
UiCustomer customer = customerService.asUiCustomer(position.getDocument().getDossier().getCustomerId());
UniqueUnit unit = unitEao.findById(position.getUniqueUnitId());
String error = "ERROR FINDING UNIT";
String sopoNr = "-";
String serial = "-";
String contractor = "-";
String fullOrPartial = "-";
double customerPrice = 0;
double retailerPrice = 0;
if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
if (unit == null) {
sopoNr = error;
serial = error;
contractor = error;
} else {
sopoNr = unit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
serial = unit.getIdentifier(UniqueUnit.Identifier.SERIAL);
contractor = unit.getContractor().getName();
customerPrice = unit.getPrice(PriceType.CUSTOMER);
retailerPrice = unit.getPrice(PriceType.RETAILER);
fullOrPartial = (position.getType() == PositionType.UNIT ? "V" : "T");
if (position.getDocument().getType() == DocumentType.COMPLAINT)
fullOrPartial = "Rekla";
}
}
rows.add(new Object[] { sopoNr, serial, position.getName(), contractor, fullOrPartial, position.getPrice(), position.toAfterTaxPrice(), position.getDocument().getDossier().getIdentifier(), doc.getActual(), position.getDocument().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), customerPrice, retailerPrice });
m.worked(5);
}
Collections.sort(rows, comperator);
m.message("Generating Document");
m.setWorkRemaining(10);
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
table.add(new STableColumn("SopoNr", 15)).add(new STableColumn("Seriennummer", 30)).add(new STableColumn("Name", 50)).add(new STableColumn("Contractor", 15)).add(new STableColumn("Voll/Teil", 10)).add(new STableColumn("Netto", 10, EURO)).add(new STableColumn("Brutto", 10, EURO)).add(new STableColumn("DossierId", 15)).add(new STableColumn("Belegdatum", 10, new CFormat(SHORT_DATE))).add(new STableColumn("DokumentId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Kunde", 50)).add(new STableColumn("Endkundenpreis(Netto)", 25, EURO)).add(new STableColumn("Händlerpreis(Netto)", 25, EURO));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
cdoc.add(new CSheet("Sheet1", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
m.finish();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class RedTapeCloserOperation method poluteReporting.
/**
* Actually creating reportLines from the reportable documents.
* For each position of a {@link Document} a {@link ReportLine} is created with all information supplied.
* <p>
* Exceptions are:
* <ul>
* <li>A {@link Document} with a {@link Condition#CANCELED} which is silently ignored</li>
* <li>A {@link Document} with a {@link DocumentType#COMPLAINT} which sets all prices on the {@link ReportLine} to 0 and
* <ul>
* <li>If the {@link Document} has the {@link Condition#WITHDRAWN} or {@link Condition#REJECTED}, set {@link ReportLine#workflowStatus} to
* {@link ReportLine.WorkflowStatus#DISCHARGED}</li>
* <li>If the {@link Document} has the {@link Condition#ACCEPTED}, set {@link ReportLine#workflowStatus} to
* {@link ReportLine.WorkflowStatus#CHARGED}</li>
* <li>Otherwise set {@link ReportLine#workflowStatus} to {@link ReportLine.WorkflowStatus#UNDER_PROGRESS}</li>
* </ul>
* </li>
* <li>A {@link Document} with a {@link DocumentType#CREDIT_MEMO} gets its prices inverted</li>
* </ul>
* <p/>
* @param reportable the documents to create lines from
* @param monitor a optional monitor.
* @return the amount of created lines.
*/
private int poluteReporting(Set<Document> reportable, Date reporting, IMonitor monitor) {
WarrantyService warrantyService = null;
if (!warrantyServiceInstance.isUnsatisfied()) {
warrantyService = warrantyServiceInstance.get();
}
SubMonitor m = SubMonitor.convert(monitor, reportable.size() + 10);
m.start();
ReportLineEao reportLineEao = new ReportLineEao(reportEm);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
ProductEao productEao = new ProductEao(uuEm);
int amountCreate = 0;
List<ReportLine> newLines = new ArrayList<>(reportable.size());
for (Document document : reportable) {
m.worked(1, "reported " + document.getIdentifier());
// A canceled document must be closed, but must not create a reportline.
if (document.getConditions().contains(Condition.CANCELED))
continue;
ReportLine l;
for (Position position : document.getPositions().values()) {
amountCreate++;
l = new ReportLine();
l.setActual(document.getActual());
l.setAmount(position.getAmount());
l.setBookingAccount(position.getBookingAccount().map(Ledger::getValue).orElse(-1));
l.setCustomerId(document.getDossier().getCustomerId());
l.setDescription(normalizeSpace(position.getDescription()));
l.setDocumentId(document.getId());
l.setDocumentIdentifier(document.getIdentifier());
l.setDocumentType(document.getType());
l.setDossierId(document.getDossier().getId());
l.setDossierIdentifier(document.getDossier().getIdentifier());
// TODO: We could use something else for a separator, but keep in mind that we want to avoid name, , , something.
l.setInvoiceAddress(normalizeSpace(document.getInvoiceAddress().getDescription()));
l.setName(normalizeSpace(position.getName()));
l.setPositionType(position.getType());
l.setPrice(position.getPrice());
l.setReportingDate(reporting);
l.setTax(position.getTax());
// Set via Report afterwards
l.setMarginPercentage(0);
// Set via Report afterwards
l.setPurchasePrice(0);
UiCustomer c = customerService.asUiCustomer(document.getDossier().getCustomerId());
if (c != null) {
l.setCustomerCompany(c.getCompany());
l.setCustomerName(c.toTitleNameLine());
l.setCustomerEmail(c.getEmail());
}
// A Credit Memo gets its prices inverted
if (document.getType() == DocumentType.CREDIT_MEMO) {
l.setPrice(position.getPrice() * (-1));
}
// Special handling of complaints.
if (document.getType() == DocumentType.COMPLAINT) {
// A Complaint position has "tagging" effect, but shall never result in a plus or minus.
l.setPrice(0);
if (document.getConditions().contains(Condition.REJECTED) || document.getConditions().contains(Condition.WITHDRAWN)) {
l.setWorkflowStatus(ReportLine.WorkflowStatus.DISCHARGED);
} else if (document.getConditions().contains(Condition.ACCEPTED)) {
l.setWorkflowStatus(ReportLine.WorkflowStatus.CHARGED);
} else {
l.setWorkflowStatus(ReportLine.WorkflowStatus.UNDER_PROGRESS);
}
}
// Extra information for Type Position
if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
UniqueUnit uu = Objects.requireNonNull(uniqueUnitEao.findById(position.getUniqueUnitId()), "No UniqueUnit with id=" + position.getUniqueUnitId());
Product p = uu.getProduct();
if (uu.getContractor() == p.getTradeName().getManufacturer()) {
l.setContractorPartNo(p.getPartNo());
l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
} else {
l.setContractorPartNo(p.getAdditionalPartNo(uu.getContractor()));
l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
}
l.setManufacturerCostPrice(p.getPrice(MANUFACTURER_COST));
l.setContractor(uu.getContractor());
l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
if (Math.abs(l.getContractorReferencePrice()) < 0.001)
l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
l.setMfgDate(uu.getMfgDate());
l.setRefurbishId(uu.getRefurbishId());
l.setSerial(uu.getSerial());
l.setUniqueUnitId(uu.getId());
l.setSalesChannel(uu.getSalesChannel());
l.setPartNo(p.getPartNo());
l.setProductBrand(p.getTradeName());
l.setProductName(p.getName());
l.setProductGroup(p.getGroup());
l.setProductId(p.getId());
l.setGtin(p.getGtin());
// Extra Information for Type Product Batch
} else if (position.getType() == PositionType.PRODUCT_BATCH) {
Product p = Objects.requireNonNull(productEao.findById(position.getUniqueUnitProductId()), "No Product for id=" + position.getUniqueUnitProductId());
l.setPartNo(p.getPartNo());
l.setProductBrand(p.getTradeName());
l.setProductGroup(p.getGroup());
l.setProductName(p.getName());
l.setProductId(p.getId());
l.setGtin(p.getGtin());
l.setUniqueUnitId(position.getUniqueUnitId());
l.setSerial(position.getSerial());
l.setRefurbishId(position.getRefurbishedId());
if (warrantyService != null) {
// If this is no warranty Partno, this will return null ;-)
l.setContractor(warrantyService.warrantyContractor(p.getPartNo()));
}
}
reportEm.persist(l);
newLines.add(l);
}
}
reportEm.flush();
m.message("Updateing References");
for (ReportLine newLine : newLines) {
// Not Refs for Product_Batches or Versandkosten jet.
if (newLine.getUniqueUnitId() < 1)
continue;
if (newLine.getPositionType() == PositionType.PRODUCT_BATCH) {
// TODO: also evaluate the productId.
newLine.addAll(reportLineEao.findBySerialAndPositionTypeAndDossierId(newLine.getSerial(), newLine.getPositionType(), newLine.getDossierId()));
} else {
newLine.addAll(reportLineEao.findUnitsAlike(newLine.getUniqueUnitId(), newLine.getDossierId()));
}
}
updateSingleReferences(newLines);
m.worked(5);
m.finish();
return amountCreate;
}
Aggregations