use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class UnitDestroyerOperation method scrapDelete.
private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
Dossier dos = doc.getDossier();
doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
// Implicit removes it from an existing LogicTransaction
lt.add(stockUnit);
StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
st.addUnit(stockUnit);
stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
uu.addHistory(operation + " of Unit via " + st);
uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
uu.setSalesChannel(UNKNOWN);
L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class UnitDestroyerOperation method verifyScarpOrDeleteAble.
/**
* Validates if a unit identified by refurbishedId is scrapable.
* Throws Exception if:
* <ul>
* <li>No UniqueUnit,SopoUnit or StockUnit exists.</li>
* <li>StockUnit is inTransaction</li>
* <li>SopoUnit is in Auftrag or Balanced.</li>
* </ul>
*
* @param refurbishId the refurbishedId
* @return
* @throws UserInfoException if not scrapable.
*/
@Override
public UniqueUnit verifyScarpOrDeleteAble(String refurbishId) throws UserInfoException {
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
if (uniqueUnit == null)
throw new UserInfoException("Keine Gerät mit SopoNr " + refurbishId + " gefunden");
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uniqueUnit.getId());
if (stockUnit == null)
throw new UserInfoException("Keine Lagergerät für SopoNr " + refurbishId + " gefunden, Verschrottung/Löschung unnötig");
if (stockUnit.isInTransaction())
throw new UserInfoException("StockUnit ist auf einer Transaktion, Verschrottung/Löschung unzulässig");
uniqueUnit.fetchEager();
return uniqueUnit;
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class UnitProcessorOperation method receiptUniqueUnit.
private UniqueUnit receiptUniqueUnit(UniqueUnit recieptUnit, Product product, Shipment shipment) {
UniqueUnit uniqueUnit = new UniqueUnitEao(uuEm).findByIdentifier(UniqueUnit.Identifier.SERIAL, recieptUnit.getIdentifier(UniqueUnit.Identifier.SERIAL));
product = new ProductEao(uuEm).findById(product.getId());
if (uniqueUnit == null) {
recieptUnit.setProduct(product);
L.debug("persisting {}", recieptUnit);
// TODO: Update in UI.
recieptUnit.setShipmentId(shipment.getId());
recieptUnit.setShipmentLabel(shipment.getShipmentId());
recieptUnit.setInputDate(new Date());
uuEm.persist(recieptUnit);
uniqueUnit = recieptUnit;
} else {
uniqueUnit.setIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, recieptUnit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
uniqueUnit.setComment(recieptUnit.getComment());
uniqueUnit.setComments(recieptUnit.getComments());
uniqueUnit.setCondition(recieptUnit.getCondition());
uniqueUnit.setInternalComment(recieptUnit.getInternalComment());
uniqueUnit.setInternalComments(recieptUnit.getInternalComments());
uniqueUnit.setEquipments(recieptUnit.getEquipments());
uniqueUnit.setProduct(product);
uniqueUnit.setContractor(shipment.getContractor());
uniqueUnit.setShipmentId(shipment.getId());
uniqueUnit.setShipmentLabel(shipment.getShipmentId());
uniqueUnit.setWarranty(recieptUnit.getWarranty());
uniqueUnit.setWarrentyValid(recieptUnit.getWarrentyValid());
// Allways set the InputDate on receipt.
uniqueUnit.setInputDate(new Date());
L.debug("updating {}", recieptUnit);
}
return uniqueUnit;
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class UnitProcessorOperation method findEditableUnit.
/**
* Returns a editable UniqueUnit.
* An Exception is thrown if:
* <ul>
* <li>No UniqueUnit with refurbishedId</li>
* <li>No StockUnit for UniqueUnit</li>
* <li>StockUnit is on Transaction</li>
* <li>No SopoUnit with refurbishedId</li>
* <li>No SopoUnit UniqueUnit miss match</li>
* </ul>
* The Operation is discovert via:
* <ul>
* <li>If on an AlphaAcount, and operation is allowed, returns appropriated operation</li>
* <li>If on no Auftrag, returns Sales</li>
* <li>If on any other Auftrag, returns null</li>
* </ul>
*
* @param refurbishedIdOrSerial the refurbishedId or the serial, both are tried
* @return a EditableUnit with, the editable UniqueUnit, the refrencing StockUnit, the Operation it is in, and the PartNo
* @throws UserInfoException if refurbishedId is not ok.
*/
@Override
public EditableUnit findEditableUnit(String refurbishedIdOrSerial) throws UserInfoException {
if (StringUtils.isBlank(refurbishedIdOrSerial))
throw new UserInfoException("Keine SopoNr/Seriennummer eingegeben");
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(REFURBISHED_ID, refurbishedIdOrSerial);
if (uniqueUnit == null)
uniqueUnit = uniqueUnitEao.findByIdentifier(SERIAL, refurbishedIdOrSerial);
if (uniqueUnit == null)
throw new UserInfoException("Keine Gerät mit SopoNr/Seriennummer " + refurbishedIdOrSerial + " gefunden");
StockUnit stockUnit;
ReceiptOperation operation = ReceiptOperation.SALEABLE;
stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
if (stockUnit == null)
throw new UserInfoException("Keine Lagergerät für SopoNr " + uniqueUnit.getIdentifier(REFURBISHED_ID) + " gefunden, bearbeitung unzulässig");
LogicTransaction lt = new LogicTransactionEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
if (lt != null) {
operation = receiptCustomers.getOperation(new DossierEao(redTapeEm).findById(lt.getDossierId()).getCustomerId()).orElse(ReceiptOperation.IN_SALE);
}
// Lazyinit
uniqueUnit.fetchEager();
return new EditableUnit(uniqueUnit, stockUnit, operation, uniqueUnit.getProduct() == null ? "" : uniqueUnit.getProduct().getPartNo());
}
use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.
the class UnitProcessorOperation method receipt.
/**
* Receipts a new Unit.
* Multiphase Process:
* <ol>
* <li>Validation and throw IllegalArgumentException if
* <ul>
* <li>Supplied UniqueUnit is already persistent</li>
* <li>RefurbishedId is already taken</li>
* <li>Serial is already taken and Unit is in Stock [UniqueUnit & Stock]</li>
* </ul>
* </li>
* <li>If serial is taken update existing Unit else persist Unit[UniqueUnit]<br />
* (At this point it implies that the Unit is not in Stock)</li>
* <li>Create, weak reference StockUnit and prepare for rollIn [Stock]</li>
* </ol>
* <p/>
* @param shipment the shipment
* @param receiptUnit the UniqueUnit to be receipt, must not be null
* @param operation the Operation to do
* @param transaction
* @param arranger
* @param operationComment
* @throws IllegalArgumentException if validation fails
*/
@Override
public void receipt(UniqueUnit receiptUnit, Product product, Shipment shipment, StockTransaction transaction, ReceiptOperation operation, String operationComment, String arranger) throws IllegalArgumentException {
L.info("Receiping Unit(id={},refurbishId={},name={}) on StockTransaction(id={}) with {} by {}", receiptUnit.getId(), receiptUnit.getRefurbishId(), ProductFormater.toNameWithPartNo(product), transaction.getId(), operation, arranger);
validateReceipt(receiptUnit);
UniqueUnit uniqueUnit = receiptUniqueUnit(receiptUnit, Objects.requireNonNull(product, "Product == null, not allowed"), shipment);
StockUnit stockUnit = receiptAndAddStockUnit(uniqueUnit, transaction);
// Nothing to do
if (operation == ReceiptOperation.SALEABLE)
return;
executeOperation(uniqueUnit, stockUnit, operation, operationComment, arranger);
}
Aggregations