Search in sources :

Example 1 with UNIT

use of eu.ggnet.dwoss.rules.PositionType.UNIT in project dwoss by gg-net.

the class RedTapeView method initFxComponents.

private void initFxComponents() {
    final JFXPanel jfxp = new JFXPanel();
    positionFxPanel.add(jfxp, BorderLayout.CENTER);
    Platform.runLater(() -> {
        SelectionEnhancer<Position> selectionEnhancer = (selected) -> {
            if (selected != null && selected.getType() == UNIT)
                return Arrays.asList(new PicoUnit(selected.getUniqueUnitId(), selected.getName()));
            return Collections.EMPTY_LIST;
        };
        selector = Ops.seletor(Position.class, selectionEnhancer);
        BorderPane pane = new BorderPane();
        Scene scene = new Scene(pane, javafx.scene.paint.Color.ALICEBLUE);
        final ListView<Position> positionsFxList = new ListView<>();
        MultipleSelectionModel<Position> selectionModel = positionsFxList.getSelectionModel();
        selectionModel.setSelectionMode(SelectionMode.SINGLE);
        selectionModel.selectedItemProperty().addListener((ob, o, n) -> {
            selector.selected(n);
        });
        positionsFxList.setCellFactory(new PositionListCell.Factory());
        positionsFxList.setItems(positions);
        positionsFxList.setContextMenu(FxOps.contextMenuOf(selectionModel, selectionEnhancer));
        positionsFxList.setOnMouseClicked(FxOps.defaultMouseEventOf(selectionModel));
        /*
             positionsFxList.setOnMouseClicked((evt) -> {
             if ( positionsFxList.getSelectionModel().isEmpty() ) return;
             if ( evt.getButton() != PRIMARY ) return;
             if ( evt.getClickCount() != 2 ) return;
             HtmlDialog d = new HtmlDialog(RedTapeView.this, ModalityType.MODELESS);
             d.setText(controller.getDetailedPositionToHtml(positionsFxList.getSelectionModel().getSelectedItem()));
             d.setVisible(true);
             });
             */
        pane.setCenter(positionsFxList);
        jfxp.setScene(scene);
    });
}
Also used : Scene(javafx.scene.Scene) CustomerUpi(eu.ggnet.dwoss.customer.upi.CustomerUpi) java.util(java.util) javafx.scene.control(javafx.scene.control) eu.ggnet.saft.core.ops(eu.ggnet.saft.core.ops) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) JFXPanel(javafx.embed.swing.JFXPanel) eu.ggnet.dwoss.redtapext.ee.state(eu.ggnet.dwoss.redtapext.ee.state) DocumentStringRenderer(eu.ggnet.dwoss.redtapext.ui.cao.common.DocumentStringRenderer) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) eu.ggnet.dwoss.util(eu.ggnet.dwoss.util) Logger(org.slf4j.Logger) CustomerService(eu.ggnet.dwoss.customer.opi.CustomerService) DossierTableView(eu.ggnet.dwoss.redtapext.ui.cao.dossierTable.DossierTableView) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) java.awt(java.awt) Platform(javafx.application.Platform) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) PropertyChangeListener(java.beans.PropertyChangeListener) java.awt.event(java.awt.event) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) javax.swing.border(javax.swing.border) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) PositionListCell(eu.ggnet.dwoss.redtapext.ui.cao.common.PositionListCell) ListSelectionListener(javax.swing.event.ListSelectionListener) eu.ggnet.saft(eu.ggnet.saft) javax.swing(javax.swing) JFXPanel(javafx.embed.swing.JFXPanel) BorderPane(javafx.scene.layout.BorderPane) PositionListCell(eu.ggnet.dwoss.redtapext.ui.cao.common.PositionListCell) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) Scene(javafx.scene.Scene)

Example 2 with UNIT

use of eu.ggnet.dwoss.rules.PositionType.UNIT 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;
}
Also used : java.util(java.util) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) LoggerFactory(org.slf4j.LoggerFactory) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) ZoneId.systemDefault(java.time.ZoneId.systemDefault) Stocks(eu.ggnet.dwoss.stock.ee.assist.Stocks) Inject(javax.inject.Inject) CREDIT_MEMO(eu.ggnet.dwoss.rules.DocumentType.CREDIT_MEMO) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) Report(eu.ggnet.dwoss.report.ee.entity.Report) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) SingleReferenceType(eu.ggnet.dwoss.report.ee.entity.ReportLine.SingleReferenceType) RepaymentCustomers(eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) ReportEmo(eu.ggnet.dwoss.report.ee.emo.ReportEmo) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ANNULATION_INVOICE(eu.ggnet.dwoss.rules.DocumentType.ANNULATION_INVOICE) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) LocalDate(java.time.LocalDate) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Report(eu.ggnet.dwoss.report.ee.entity.Report) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) LocalDate(java.time.LocalDate) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 3 with UNIT

use of eu.ggnet.dwoss.rules.PositionType.UNIT 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)

Aggregations

Document (eu.ggnet.dwoss.redtape.ee.entity.Document)3 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)3 UNIT (eu.ggnet.dwoss.rules.PositionType.UNIT)3 java.util (java.util)3 RepaymentCustomers (eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 Report (eu.ggnet.dwoss.report.ee.entity.Report)2 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)2 eu.ggnet.dwoss.rules (eu.ggnet.dwoss.rules)2 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 CustomerGeneratorOperation (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation)1 CustomerMetaData (eu.ggnet.dwoss.customer.opi.CustomerMetaData)1 CustomerService (eu.ggnet.dwoss.customer.opi.CustomerService)1 CustomerUpi (eu.ggnet.dwoss.customer.upi.CustomerUpi)1 UnitHistory (eu.ggnet.dwoss.event.UnitHistory)1 ResolveRepayment (eu.ggnet.dwoss.misc.ee.ResolveRepayment)1 ResolveRepaymentBean (eu.ggnet.dwoss.misc.ee.ResolveRepaymentBean)1