use of eu.ggnet.dwoss.event.UnitHistory 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.event.UnitHistory in project dwoss by gg-net.
the class RedTapeCloserOperation method closeStock.
/**
* Rolling out the units from the stocks. For this, a {@link StockTransaction} with {@link StockTransactionType#ROLL_OUT} is created,
* all {@link StockUnit}<code>s</code> which are on a {@link LogicTransaction} with matching dossierId are added to this {@link StockTransaction} and
* it gets {@link StockTransactionStatusType#COMPLETED}.
* <p/>
* @param dossierIds the dossierId as reference.
* @param msg a msg for the stocktransaction.
* @param arranger the arranger.
* @param monitor a optional monitor.
* @return the amount of rolled out units.
*/
private int closeStock(Set<Long> dossierIds, String msg, String arranger, IMonitor monitor) {
SubMonitor m = SubMonitor.convert(monitor, 100);
final String h = "Stock:";
m.message(h + "lade logische Transaktionen");
// Rolling out
List<LogicTransaction> lts = ltEao.findByDossierIds(dossierIds);
m.worked(3, h + "sortiere Geräte nach Lager");
stockEao.findAll();
Map<Stock, List<StockUnit>> unitsByStock = lts.stream().flatMap((t) -> t.getUnits().stream()).collect(Collectors.groupingBy(StockUnit::getStock));
validateStockUnits(unitsByStock);
m.setWorkRemaining((int) unitsByStock.values().stream().count());
List<StockTransaction> stockTransactions = new ArrayList<>();
for (Entry<Stock, List<StockUnit>> entry : unitsByStock.entrySet()) {
StockTransaction st = stEmo.requestRollOutPrepared(entry.getKey().getId(), arranger, msg);
for (StockUnit stockUnit : entry.getValue()) {
m.worked(1, h + "verbuche (refurbishId=" + stockUnit.getRefurbishId() + ",uniqueUnitId=" + stockUnit.getUniqueUnitId() + ")");
st.addUnit(stockUnit);
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), msg, arranger));
}
stockTransactions.add(st);
}
m.message(h + "auslagern");
if (!stockTransactions.isEmpty())
stEmo.completeRollOut(arranger, stockTransactions);
m.finish();
return (int) unitsByStock.values().stream().count();
}
use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.
the class StockTransactionProcessorOperation method removeFromPreparedTransaction.
/**
* Remove the stockUnit represented by the refurbishId from a stock transaction, if that transaction exists and is in state prepared.
* <p/>
* @param refurbishId the refurbishId
* @param arranger the arranger
* @param comment a optional comment
* @throws UserInfoException if no unit exists, the unit is not on a transaction or the transaction has another state then prepared.
*/
@Override
public void removeFromPreparedTransaction(final String refurbishId, final String arranger, final String comment) throws UserInfoException {
StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(refurbishId);
if (stockUnit == null)
throw new UserInfoException("SopoNr: " + refurbishId + " existiert nicht.");
if (!stockUnit.isInTransaction())
throw new UserInfoException("SopoNr: " + refurbishId + " nicht in Transaction.");
StockTransaction transaction = stockUnit.getTransaction();
if (transaction.getStatus().getType() != PREPARED) {
throw new UserInfoException("SopoNr: " + refurbishId + " auf Transaction, aber Transaction(" + transaction.getId() + ") not in Status prepared");
}
// The one case we remove the position as well, but dont need to set the stock because of beeing in status prepared
StockTransactionPosition position = stockUnit.getPosition();
stockEm.remove(position);
transaction.setComment(transaction.getComment() + ", Unit " + stockUnit.getRefurbishId() + " removed by " + arranger + ", cause=" + comment);
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit returned to Stock(" + transaction.getSource().getId() + ") " + transaction.getSource().getName() + ", removed from Transaction, cause: " + comment, arranger));
L.info("{} removed from {}", stockUnit, transaction);
}
use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.
the class StockTransactionProcessorOperation method receive.
/**
* Receive a list of transactions in the destination stock.
* <p/>
* @param transactions the transactions to receive.
* @param deliverer the deliverer
* @param reciever the receiver
*/
@Override
public void receive(List<StockTransaction> transactions, String deliverer, String reciever) {
StockLocationDiscoverer discoverer = new StockLocationDiscoverer(stockEm);
for (StockTransaction transaction : transactions) {
transaction = stockEm.find(StockTransaction.class, transaction.getId());
transaction.addStatus(RECEIVED, DELIVERER, deliverer, RECEIVER, reciever);
L.info("Receiving {} in {}", transaction, transaction.getDestination());
Stock destination = transaction.getDestination();
for (StockUnit stockUnit : transaction.getUnits()) {
stockUnit.setPosition(null);
discoverer.discoverAndSetLocation(stockUnit, destination);
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit received in Stock(" + destination.getId() + ") " + destination.getName(), reciever));
}
}
}
use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.
the class StockTransactionProcessorOperation method rollIn.
/**
* Rolls all StockTransaction in, completing them and setting the Stock.
*
* @param detachtedTransactions the transactions
* @param arranger the arranger
*/
@Override
public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
SubMonitor m = monitorFactory.newSubMonitor("RollIn", detachtedTransactions.size() * 2);
StockTransactionEao stockTransactionEao = new StockTransactionEao(stockEm);
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
List<StockTransaction> transactions = new ArrayList<>();
m.message("loading Transactions");
for (StockTransaction detachedTransaction : detachtedTransactions) {
transactions.add(stockTransactionEao.findById(detachedTransaction.getId()));
m.worked(1);
}
m.setWorkRemaining(3);
m.message("rolling in");
List<StockUnit> stockUnits = stockTransactionEmo.completeRollIn(arranger, transactions);
m.worked(2, "adding History");
for (StockUnit stockUnit : stockUnits) {
if (mandator.isApplyDefaultChannelOnRollIn()) {
SalesChannel channel = stockUnit.getStock().getPrimaryChannel();
channelChanger.fire(new SalesChannelChange(stockUnit.getUniqueUnitId(), channel));
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName() + " with " + channel.getName(), arranger));
} else {
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName(), arranger));
}
}
m.finish();
return stockUnits.stream().map(x -> x.getId()).collect(Collectors.toList());
}
Aggregations