use of eu.ggnet.dwoss.redtape.ee.entity.Document in project dwoss by gg-net.
the class RedTapeCloserOperation method closeing.
/**
* The closing selects and closes all dossiers and documents in a closable state. This includes production of appropriated values for report.
* <p/>
* The workflow:
* <ol>
* <li>Load all open {@link Dossiers}, and filter them by the closing states of the associated {@link Documents}.See
* {@link #findReportable(de.dw.progress.IMonitor)}</li>
* <li>Filter out all Document, which have {@link StockUnit}'s on open {@link StockTransaction}.</li>
* <li>Create the resulting {@link ReportLine}'s and persist them in the report database. See
* {@link #poluteReporting(java.util.Set, java.util.Date, de.dw.progress.IMonitor)} </li>
* <li>Close the selected {@link Dossier}'s and {@link Document}'s in redTape. See {@link #closeRedTape(java.util.Set, de.dw.progress.IMonitor)}</li>
* <li>Find all associated {@link StockUnit}'s and roll them out. See
* {@link #closeStock(java.util.Set, java.lang.String, java.lang.String, de.dw.progress.IMonitor)}</li>
* </ol>
* <p>
* <p/>
* @param arranger the arranger
* @param manual is this called manual or automatic
*/
private void closeing(String arranger, boolean manual) {
Date now = new Date();
String msg = (manual ? "Manueller" : "Automatischer") + " (Tages)abschluss vom " + DateFormats.ISO.format(now) + " ausgeführt durch " + arranger;
L.info("closing:{}", msg);
SubMonitor m = monitorFactory.newSubMonitor((manual ? "Manueller" : "Automatischer") + " (Tages)abschluss", 100);
m.start();
L.info("closing:week persisted");
Set<Document> reportable = findReportable(m.newChild(30));
L.info("closing:documents selected");
reportable = filterOpenStockTransactions(reportable, m.newChild(5));
L.info("closing:documents filtered");
poluteReporting(reportable, DateUtils.truncate(new Date(), Calendar.DATE), m.newChild(15));
L.info("closing:repoting poluted");
closeRedTape(reportable, m.newChild(10));
L.info("closed:redTape:reportables");
closeRedTape(findCloseableBlocker(), m.newChild(10));
L.info("closed:redTape:nonreportables");
closeStock(reportable.stream().map(Document::getDossier).map(Dossier::getId).collect(Collectors.toSet()), "Rollout by " + (manual ? "manuel" : "automatic") + " closing on " + DateFormats.ISO.format(now), arranger, m);
L.info("closed:stock");
m.finish();
}
use of eu.ggnet.dwoss.redtape.ee.entity.Document in project dwoss by gg-net.
the class ResolveRepaymentBeanIT method testResolve.
@Test
public void testResolve() throws UserInfoException {
List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
assertThat(allStocks).isNotEmpty().hasSize(2);
Stock activeStock = allStocks.get(0);
assertThat(customerGenerator.makeCustomers(10)).isNotEmpty();
assertThat(receiptGenerator.makeUniqueUnits(200, true, true)).isNotEmpty();
assertThat(redTapeGenerator.makeSalesDossiers(30)).isNotEmpty();
final TradeName TRADE_NAME = ACER;
assertThat(TRADE_NAME.isManufacturer()).isTrue();
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(1, true, true);
UniqueUnit uu = uus.get(0);
uu = helper.changeContractors(uu.getId(), TRADE_NAME);
String refurbishId = uu.getRefurbishId();
Dossier dos = redTapeWorker.create(customerId, true, "Me");
// order oder direct invoice
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
// Create Positions
doc.append(Position.builder().type(UNIT).amount(1).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(uu.getPrice(CUSTOMER)).tax(doc.getSingleTax()).name(uu.getProduct().getName() + " | SN:" + uu.getSerial()).description(uu.getProduct().getDescription()).refurbishedId(refurbishId).build());
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu.getRefurbishId());
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
// Now create an annulation Invoice
doc.setType(ANNULATION_INVOICE);
// ArrayList<Position> positions = new ArrayList<>();
for (Position value : doc.getPositions().values()) {
// if ( value.getType() == UNIT ) positions.add(value);
value.setPrice(value.getPrice() * -1);
}
redTapeWorker.update(doc, activeStock.getId(), "JUnit Test");
// Closing the Day. Creating report lines.
redTapeCloser.executeManual("JUnitTest");
// Ensure, that we have a Mirror Dossier on the repaymentcustomers.
List<Dossier> repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
assertThat(repaymentDossiers).as("RepaymentDossiers").isNotEmpty();
Dossier repaymentDossier = repaymentDossiers.get(0);
List<Document> activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
assertThat(activeDocuments).isNotEmpty();
assertThat(activeDocuments.get(0).getPositions(UNIT)).isNotEmpty();
Report report = new Report("Test", TRADE_NAME, new Date(), new Date());
List<ReportLine> reportLines = reportLineEao.findAll();
List<Storeable> arrayList = new ArrayList<>();
reportLines.stream().filter((line) -> (line.getDocumentType() == INVOICE)).forEach((line) -> {
arrayList.add(line.toStorable());
});
report = reportAgent.store(report, arrayList);
assertThat(report).isNotNull();
assertThat(report.getLines()).isNotEmpty();
List<ReportLine> notReported = report.getLines().stream().filter((l) -> reportLines.contains(l)).collect(Collectors.toList());
final int uuId = uu.getId();
ReportLine lineToUniqueUnit = notReported.stream().filter((line) -> line.getUniqueUnitId() == uuId).collect(Collectors.toList()).get(0);
assertThat(lineToUniqueUnit).isNotNull();
List<ReportLine> repaymentLines = bean.getRepaymentLines(lineToUniqueUnit.getContractor());
ReportLine repaymentLine = repaymentLines.stream().filter((l) -> l.getRefurbishId().equals(refurbishId)).collect(Collectors.toList()).get(0);
assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNotEmpty();
// Resolving of the Unit.
bean.resolveUnit(refurbishId, TRADE_NAME, "JUnit", "JUnit");
List<Report> reports = reportAgent.findAll(Report.class);
assertThat(reports).hasSize(2);
Report repaymentReport = null;
// Try to get Report with the Name that is generated in a Static method inside the ResolveRepaymentBean.
if (reports.get(0).getName().equals(ResolveRepaymentBean.toReportName(TRADE_NAME)))
repaymentReport = reports.get(0);
else
repaymentReport = reports.get(1);
repaymentReport = reportAgent.findByIdEager(Report.class, repaymentReport.getId());
assertThat(repaymentReport.getLines()).hasSize(1);
assertThat(repaymentLines).contains(repaymentLine);
// Ensure, that we the mirror Dossier has be cleared of the unit
repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
assertThat(repaymentDossiers).isNotEmpty();
repaymentDossier = repaymentDossiers.get(0);
activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
assertThat(activeDocuments).isNotEmpty();
assertThat(activeDocuments.get(0).getPositions(UNIT)).isEmpty();
// We still should have comments there.
assertThat(activeDocuments.get(0).getPositions(PositionType.COMMENT)).isNotEmpty();
assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNullOrEmpty();
}
use of eu.ggnet.dwoss.redtape.ee.entity.Document in project dwoss by gg-net.
the class RedTapeCreateDossierWorkflow method createDossier.
/**
* Creates the Dossier.
*
* @param customer the customer
* @return the Dossier.
*/
Dossier createDossier(long customerId, boolean dispatch, DocumentType type, PaymentMethod paymentMethod, Directive directive, String arranger) {
if (specialSystemCustomers.get(customerId).map(x -> x != type).orElse(false)) {
throw new IllegalStateException(type + " is not allowed for Customer " + customerId);
}
Dossier dos = new Dossier();
dos.setPaymentMethod(paymentMethod);
dos.setDispatch(dispatch);
dos.setCustomerId(customerId);
Document doc = new Document();
doc.setType(type);
doc.setActive(true);
doc.setDirective(directive);
doc.setHistory(new DocumentHistory(arranger, "Automatische Erstellung eines leeren Dokuments"));
AddressEmo adEmo = new AddressEmo(redTapeEm);
doc.setInvoiceAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.INVOICE)));
doc.setShippingAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.SHIPPING)));
dos.add(doc);
redTapeEm.persist(dos);
// Make sure the dos.id is generated an stored in the database.
redTapeEm.flush();
dos.setIdentifier(mandator.getDossierPrefix() + _00000_.format(dos.getId()));
// Force store Identifier
redTapeEm.flush();
L.info("Created {} by {}", DossierFormater.toSimpleLine(dos), arranger);
return dos;
}
use of eu.ggnet.dwoss.redtape.ee.entity.Document in project dwoss by gg-net.
the class DocumentSupporterIT method testCreate.
/**
* Test of create method, of class RedTapeOperation.
*/
@Test
public void testCreate() {
Dossier dos = new Dossier();
dos.setPaymentMethod(PaymentMethod.ADVANCE_PAYMENT);
dos.setDispatch(true);
dos.setCustomerId(1);
Document doc = new Document();
doc.setType(DocumentType.ORDER);
doc.setActive(true);
doc.setDirective(Document.Directive.WAIT_FOR_MONEY);
doc.setHistory(new DocumentHistory("JUnit", "Automatische Erstellung eines leeren Dokuments"));
Address a = new Address("Herr Muh\nMuhstrasse 7\n12345 Muhstadt");
doc.setInvoiceAddress(a);
doc.setShippingAddress(a);
dos.add(doc);
doc.append(NaivBuilderUtil.comment());
doc.append(NaivBuilderUtil.service());
doc.append(NaivBuilderUtil.shippingcost());
JasperPrint print = documentSupporter.render(doc, DocumentViewType.DEFAULT);
assertNotNull("A JasperPrint should not be null", print);
}
use of eu.ggnet.dwoss.redtape.ee.entity.Document in project dwoss by gg-net.
the class RedTapeOperationCapitalAssetUpdateIT method testUpdate.
@Test
public void testUpdate() throws UserInfoException {
UniqueUnit uu = receiptGenerator.makeUniqueUnit();
uu.setPrice(CUSTOMER, 50., "JunitTestPrice");
// Generate Dossier
Dossier dos = redTapeWorker.create(capitalAssestCustomer, false, "Me");
assertThat(dos.getActiveDocuments()).isNotEmpty();
assertThat(dos.getActiveDocuments(CAPITAL_ASSET)).overridingErrorMessage("Expected a capital Asset Document but has " + dos.getActiveDocuments()).isNotEmpty();
Document doc = dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0);
assertTrue(doc.equalsContent(dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0)));
// Commit explicit date to document for assertion
doc = supportBean.changeActual(doc, new GregorianCalendar(2012, 3, 15).getTime());
Position pos = NaivBuilderUtil.unit(uu);
// Create Positions
doc.append(pos);
doc.append(NaivBuilderUtil.comment("Comment", "A nice comment"));
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
// update document
Date date = doc.getActual();
doc = redTapeWorker.update(doc, null, "Me");
assertEquals("Same actual dates expected", date, doc.getActual());
assertEquals("Only one Active Document expected", 1, doc.getDossier().getActiveDocuments().size());
assertTrue(stockAgent.findAllEager(LogicTransaction.class).get(0).getUnits().size() == 1);
assertEquals("Ammount of Documents", 2, redTapeAgent.findAll(Document.class).size());
}
Aggregations