use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.
the class ResolveRepaymentBean method resolveUnit.
@Override
public ResolveResult resolveUnit(String identifier, TradeName contractor, String arranger, String comment) throws UserInfoException {
// search with refurbishid and serial number.
List<SimpleReportLine> reportLines = reportLineEao.findReportLinesByIdentifiers(identifier.trim());
List<ReportLine> repaymentLines = getRepaymentLines(contractor);
ReportLine line = null;
List<Long> repaymentIds = repaymentLines.stream().map((l) -> l.getId()).collect(Collectors.toList());
for (SimpleReportLine reportLine : reportLines) {
if (repaymentIds.contains(reportLine.getId())) {
line = reportLineEao.findById(reportLine.getId());
}
}
if (line == null)
throw new UserInfoException("Es konnte keine ReportLine mit diesem Identifier gefunden werden");
if (!line.getReports().isEmpty())
throw new UserInfoException("ReportLine ist schon in einem Report.\nReports:" + line.getReports());
ReportLine reference = line.getReference(SingleReferenceType.WARRANTY);
// Rolling out the unit if still in Stock.
StockUnit stockUnit = // Saftynet, e.g. unit annex shoud not clear units.
line.getPositionType() == UNIT ? stockUnitEao.findByRefurbishId(line.getRefurbishId()) : null;
if (stockUnit != null && stockUnit.isInTransaction())
throw new UserInfoException("Unit is in einer StockTransaction. ID:" + stockUnit.getTransaction().getId());
ResolveResult msgs = new ResolveResult();
if (stockUnit == null) {
msgs.stockMessage = "Es existiert keine Stock Unit (mehr) zu dem Gerät";
msgs.redTapeMessage = "Keine StockUnit, Kein Vorgang";
} else {
LogicTransaction lt = stockUnit.getLogicTransaction();
long dossierId = lt.getDossierId();
Dossier dossier = dossierEao.findById(dossierId);
if (!repaymentCustomers.get(contractor).isPresent() || !repaymentCustomers.get(contractor).get().equals(dossier.getCustomerId())) {
throw new UserInfoException("Unit is nicht auf einem Auftrag eines Repayment Customers. DossierId:" + dossier.getId());
}
List<Document> activeDocuments = dossier.getActiveDocuments(DocumentType.BLOCK);
if (activeDocuments.size() != 1) {
throw new UserInfoException("Der Gutschriftsvorgang " + dossier.toSimpleLine() + " ist fehlerhaft, entweder kein oder zu viele akive Blocker");
}
Position pos = activeDocuments.get(0).getPositionByUniqueUnitId(stockUnit.getUniqueUnitId());
if (pos == null) {
throw new UserInfoException("Auf Gutschriftsvorgang " + dossier.toSimpleLine() + " ist das Gerät " + stockUnit.toSimple() + " nicht auffindbar");
}
msgs.redTapeMessage = "Kid: " + dossier.getCustomerId() + ", Vorgang:" + dossier.getIdentifier() + " wurde Gerät entfernt";
convertToComment(pos, arranger, comment);
lt.remove(stockUnit);
StockTransaction st = stEmo.requestRollOutPrepared(stockUnit.getStock().getId(), arranger, "Resolved Repayment");
st.addUnit(stockUnit);
msgs.stockMessage = stockUnit.toSimple() + " aus Lager ausgerollt auf StockTransaction(id=" + st.getId() + ")";
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Resolved Repayment", arranger));
stEmo.completeRollOut(arranger, Arrays.asList(st));
stockEm.flush();
if (lt.getUnits().isEmpty()) {
msgs.stockMessage += ", LogicTransaction " + lt.getId() + " ist jetzt leer, wird gelöscht";
stockEm.remove(lt);
}
}
Date startOfYear = Date.from(LocalDate.of(LocalDate.now().getYear(), 1, 1).atStartOfDay(systemDefault()).toInstant());
Date endOfYear = Date.from(LocalDate.of(LocalDate.now().getYear(), 12, 31).atStartOfDay(systemDefault()).toInstant());
Report report = reportEmo.request(toReportName(contractor), contractor, startOfYear, endOfYear);
line.setComment(comment);
report.add(line);
msgs.reportMessage = "Repayment Unit " + line.getRefurbishId() + " line " + line.getId() + " resolved in " + report.getName();
if (reference != null) {
L.info("Warrenty Reference exist. Putted also into the report. ReportLine ID of Warrenty:{}", reference.getId());
reference.setComment(comment);
report.add(reference);
msgs.reportMessage += ", including warranty " + reference.getId();
}
return msgs;
}
use of eu.ggnet.dwoss.report.ee.entity.ReportLine 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;
}
use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.
the class ResolveRepaymentController method initialize.
@Override
public void initialize(URL url, ResourceBundle rb) {
TableColumn<ReportLine, Long> id = new TableColumn<>("Id");
id.setCellValueFactory((p) -> new SimpleObjectProperty<>(p.getValue().getId()));
TableColumn<ReportLine, String> refurbishId = new TableColumn<>("RefurbishId");
refurbishId.setCellValueFactory(new PropertyValueFactory("refurbishId"));
refurbishId.setMinWidth(110);
TableColumn<ReportLine, Date> reportingDate = new TableColumn<>("Reported");
reportingDate.setCellValueFactory(new PropertyValueFactory("reportingDate"));
reportingDate.setMinWidth(110);
TableColumn<ReportLine, Long> unqiueUnitId = new TableColumn<>("UniqueUnit Id");
unqiueUnitId.setCellValueFactory(new PropertyValueFactory("uniqueUnitId"));
TableColumn<ReportLine, TradeName> contractorColumn = new TableColumn<>("contractor");
contractorColumn.setCellValueFactory(new PropertyValueFactory("contractor"));
TableColumn<ReportLine, String> partNo = new TableColumn<>("PartNo");
partNo.setCellValueFactory(new PropertyValueFactory("partNo"));
partNo.setMinWidth(110);
TableColumn<ReportLine, String> productName = new TableColumn<>("productName");
productName.setCellValueFactory(new PropertyValueFactory("productName"));
TableColumn<ReportLine, Double> amount = new TableColumn<>("amount");
amount.setCellValueFactory(new PropertyValueFactory("amount"));
TableColumn<ReportLine, Double> price = new TableColumn<>("price");
price.setCellValueFactory(new PropertyValueFactory("price"));
TableColumn<ReportLine, Double> purchasePrice = new TableColumn<>("purchasePrice");
purchasePrice.setCellValueFactory(new PropertyValueFactory("purchasePrice"));
TableColumn<ReportLine, Double> contractorReferencePrice = new TableColumn<>("Ref.Price");
contractorReferencePrice.setCellValueFactory(new PropertyValueFactory("contractorReferencePrice"));
TableColumn<ReportLine, DocumentType> documentType = new TableColumn<>("documentType");
documentType.setCellValueFactory(new PropertyValueFactory("documentType"));
TableColumn<ReportLine, PositionType> positionType = new TableColumn<>("positionType");
positionType.setCellValueFactory(new PropertyValueFactory("positionType"));
reportLineTable.getColumns().addAll(reportingDate, refurbishId, partNo, productName, contractorColumn, amount, contractorReferencePrice, price, purchasePrice, documentType, positionType, unqiueUnitId, id);
reportLineTable.getSelectionModel().setSelectionMode(MULTIPLE);
reportLineTable.getSelectionModel().selectedIndexProperty().addListener((ov, o, n) -> {
double ref = reportLineTable.getSelectionModel().getSelectedItems().stream().map((srl) -> srl.getContractorReferencePrice()).reduce(0., (interimResult, elem) -> interimResult + elem);
referencePriceProperty.set(ref);
});
reportLineTable.setOnMouseClicked((MouseEvent mouseEvent) -> {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY) && mouseEvent.getClickCount() == 2) {
String refurbishId1 = reportLineTable.getSelectionModel().getSelectedItem().getRefurbishId();
sopoField.setText(refurbishId1);
}
});
}
use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.
the class ReportController method buildSummary.
/**
* Builds the TableSummary for a TableView.
* <p>
* @param lines the TableView a TableSummary is built for.
* @return the TableSummary for a TableView
*/
private TableSummary buildSummary(TableView<ReportLine> lines) {
TableSummary sum = tableSummarys.get(lines) == null ? new TableSummary() : tableSummarys.get(lines);
sum.clear();
for (ReportLine line : lines.getItems()) {
if (!line.isAddedToReport())
continue;
sum.referencePrice += line.getManufacturerCostPrice();
sum.purchasePrice += line.getPurchasePrice();
sum.margin += (line.getPrice() - line.getPurchasePrice());
sum.price += line.getPrice();
}
if (sum.price != 0 && sum.referencePrice != 0)
sum.referencePricePercentage = formatPercentage(sum.price / sum.referencePrice);
if (sum.margin != 0 && sum.purchasePrice != 0)
sum.marginPercentage = formatPercentage(sum.margin / sum.purchasePrice);
sum.update();
return sum;
}
use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.
the class XlsExporter method toLucidModel.
private static List<Object[]> toLucidModel(Collection<ReportLine> newLines) {
TreeSet<ReportLine> resorted = new TreeSet<>(Comparator.comparing(ReportLine::getRefurbishId));
resorted.addAll(newLines == null ? new ArrayList<>() : newLines);
List<Object[]> newLinesData = new ArrayList<>();
for (ReportLine line : resorted) {
Object[] data = new Object[] { line.getActual(), line.getRefurbishId(), line.getPartNo(), line.toName(), line.getSerial(), line.getManufacturerCostPrice(), line.getPrice(), new SFormula(SR(6), "/", SR(5)), line.getPurchasePrice(), new SFormula(SR(6), "-", SR(8)), line.getMarginPercentage(), line.getMfgDate(), line.getCustomerId(), line.getCustomerCompany(), line.getCustomerName(), line.getPositionType().getName(), line.getDocumentType().getName(), line.getWorkflowStatus(), line.getComment() };
newLinesData.add(data);
}
return newLinesData;
}
Aggregations