Search in sources :

Example 41 with Dossier

use of eu.ggnet.dwoss.redtape.ee.entity.Dossier 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();
}
Also used : Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 42 with Dossier

use of eu.ggnet.dwoss.redtape.ee.entity.Dossier 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();
}
Also used : java.util(java.util) StockGeneratorOperation(eu.ggnet.dwoss.stock.ee.assist.gen.StockGeneratorOperation) Arquillian(org.jboss.arquillian.junit.Arquillian) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) CustomerGeneratorOperation(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) CUSTOMER(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CUSTOMER) RedTapeCloser(eu.ggnet.dwoss.redtapext.ee.reporting.RedTapeCloser) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) ResolveRepayment(eu.ggnet.dwoss.misc.ee.ResolveRepayment) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DocumentType(eu.ggnet.dwoss.rules.DocumentType) Report(eu.ggnet.dwoss.report.ee.entity.Report) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) RedTapeGeneratorOperation(eu.ggnet.dwoss.redtapext.ee.gen.RedTapeGeneratorOperation) EJB(javax.ejb.EJB) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) RepaymentCustomers(eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ReportAgent(eu.ggnet.dwoss.report.ee.ReportAgent) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) ACER(eu.ggnet.dwoss.rules.TradeName.ACER) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) RedTapeAgent(eu.ggnet.dwoss.redtape.ee.RedTapeAgent) ResolveRepaymentBean(eu.ggnet.dwoss.misc.ee.ResolveRepaymentBean) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Report(eu.ggnet.dwoss.report.ee.entity.Report) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 43 with Dossier

use of eu.ggnet.dwoss.redtape.ee.entity.Dossier 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;
}
Also used : AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) Stateless(javax.ejb.Stateless) CustomerServiceBean(eu.ggnet.dwoss.customer.ee.CustomerServiceBean) Logger(org.slf4j.Logger) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) DecimalFormat(java.text.DecimalFormat) LoggerFactory(org.slf4j.LoggerFactory) BLOCK(eu.ggnet.dwoss.rules.DocumentType.BLOCK) Set(java.util.Set) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) SpecialSystemCustomers(eu.ggnet.dwoss.mandator.api.value.SpecialSystemCustomers) EntityManager(javax.persistence.EntityManager) Mandator(eu.ggnet.dwoss.mandator.api.value.Mandator) NumberFormat(java.text.NumberFormat) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) Inject(javax.inject.Inject) Directive(eu.ggnet.dwoss.redtape.ee.entity.Document.Directive) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) RedTapes(eu.ggnet.dwoss.redtape.ee.assist.RedTapes) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DossierFormater(eu.ggnet.dwoss.redtape.ee.format.DossierFormater) AddressServiceBean(eu.ggnet.dwoss.customer.ee.AddressServiceBean) AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 44 with Dossier

use of eu.ggnet.dwoss.redtape.ee.entity.Dossier 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);
}
Also used : Address(eu.ggnet.dwoss.redtape.ee.entity.Address) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) JasperPrint(net.sf.jasperreports.engine.JasperPrint) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Test(org.junit.Test)

Example 45 with Dossier

use of eu.ggnet.dwoss.redtape.ee.entity.Dossier 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());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) GregorianCalendar(java.util.GregorianCalendar) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Date(java.util.Date)

Aggregations

Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)47 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)30 Test (org.junit.Test)17 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)11 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)8 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)6 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)6 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)5 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)4 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3 AddressEmo (eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)3 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)3 RepaymentCustomers (eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers)2 PositionBuilder (eu.ggnet.dwoss.redtape.ee.entity.PositionBuilder)2 Reminder (eu.ggnet.dwoss.redtape.ee.entity.Reminder)2 RedTapeWorker (eu.ggnet.dwoss.redtapext.ee.RedTapeWorker)2 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 Report (eu.ggnet.dwoss.report.ee.entity.Report)2 eu.ggnet.dwoss.rules (eu.ggnet.dwoss.rules)2