Search in sources :

Example 1 with Ledger

use of eu.ggnet.dwoss.mandator.api.value.Ledger in project dwoss by gg-net.

the class RedTapeCloserOperation method poluteReporting.

/**
 * Actually creating reportLines from the reportable documents.
 * For each position of a {@link Document} a {@link ReportLine} is created with all information supplied.
 * <p>
 * Exceptions are:
 * <ul>
 * <li>A {@link Document} with a {@link Condition#CANCELED} which is silently ignored</li>
 * <li>A {@link Document} with a {@link DocumentType#COMPLAINT} which sets all prices on the {@link ReportLine} to 0 and
 * <ul>
 * <li>If the {@link Document} has the {@link Condition#WITHDRAWN} or {@link Condition#REJECTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#DISCHARGED}</li>
 * <li>If the {@link Document} has the {@link Condition#ACCEPTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#CHARGED}</li>
 * <li>Otherwise set {@link ReportLine#workflowStatus} to {@link ReportLine.WorkflowStatus#UNDER_PROGRESS}</li>
 * </ul>
 * </li>
 * <li>A {@link Document} with a {@link DocumentType#CREDIT_MEMO} gets its prices inverted</li>
 * </ul>
 * <p/>
 * @param reportable the documents to create lines from
 * @param monitor    a optional monitor.
 * @return the amount of created lines.
 */
private int poluteReporting(Set<Document> reportable, Date reporting, IMonitor monitor) {
    WarrantyService warrantyService = null;
    if (!warrantyServiceInstance.isUnsatisfied()) {
        warrantyService = warrantyServiceInstance.get();
    }
    SubMonitor m = SubMonitor.convert(monitor, reportable.size() + 10);
    m.start();
    ReportLineEao reportLineEao = new ReportLineEao(reportEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductEao productEao = new ProductEao(uuEm);
    int amountCreate = 0;
    List<ReportLine> newLines = new ArrayList<>(reportable.size());
    for (Document document : reportable) {
        m.worked(1, "reported " + document.getIdentifier());
        // A canceled document must be closed, but must not create a reportline.
        if (document.getConditions().contains(Condition.CANCELED))
            continue;
        ReportLine l;
        for (Position position : document.getPositions().values()) {
            amountCreate++;
            l = new ReportLine();
            l.setActual(document.getActual());
            l.setAmount(position.getAmount());
            l.setBookingAccount(position.getBookingAccount().map(Ledger::getValue).orElse(-1));
            l.setCustomerId(document.getDossier().getCustomerId());
            l.setDescription(normalizeSpace(position.getDescription()));
            l.setDocumentId(document.getId());
            l.setDocumentIdentifier(document.getIdentifier());
            l.setDocumentType(document.getType());
            l.setDossierId(document.getDossier().getId());
            l.setDossierIdentifier(document.getDossier().getIdentifier());
            // TODO: We could use something else for a separator, but keep in mind that we want to avoid name, , , something.
            l.setInvoiceAddress(normalizeSpace(document.getInvoiceAddress().getDescription()));
            l.setName(normalizeSpace(position.getName()));
            l.setPositionType(position.getType());
            l.setPrice(position.getPrice());
            l.setReportingDate(reporting);
            l.setTax(position.getTax());
            // Set via Report afterwards
            l.setMarginPercentage(0);
            // Set via Report afterwards
            l.setPurchasePrice(0);
            UiCustomer c = customerService.asUiCustomer(document.getDossier().getCustomerId());
            if (c != null) {
                l.setCustomerCompany(c.getCompany());
                l.setCustomerName(c.toTitleNameLine());
                l.setCustomerEmail(c.getEmail());
            }
            // A Credit Memo gets its prices inverted
            if (document.getType() == DocumentType.CREDIT_MEMO) {
                l.setPrice(position.getPrice() * (-1));
            }
            // Special handling of complaints.
            if (document.getType() == DocumentType.COMPLAINT) {
                // A Complaint position has "tagging" effect, but shall never result in a plus or minus.
                l.setPrice(0);
                if (document.getConditions().contains(Condition.REJECTED) || document.getConditions().contains(Condition.WITHDRAWN)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.DISCHARGED);
                } else if (document.getConditions().contains(Condition.ACCEPTED)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.CHARGED);
                } else {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.UNDER_PROGRESS);
                }
            }
            // Extra information for Type Position
            if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
                UniqueUnit uu = Objects.requireNonNull(uniqueUnitEao.findById(position.getUniqueUnitId()), "No UniqueUnit with id=" + position.getUniqueUnitId());
                Product p = uu.getProduct();
                if (uu.getContractor() == p.getTradeName().getManufacturer()) {
                    l.setContractorPartNo(p.getPartNo());
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                } else {
                    l.setContractorPartNo(p.getAdditionalPartNo(uu.getContractor()));
                    l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                }
                l.setManufacturerCostPrice(p.getPrice(MANUFACTURER_COST));
                l.setContractor(uu.getContractor());
                l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                if (Math.abs(l.getContractorReferencePrice()) < 0.001)
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                l.setMfgDate(uu.getMfgDate());
                l.setRefurbishId(uu.getRefurbishId());
                l.setSerial(uu.getSerial());
                l.setUniqueUnitId(uu.getId());
                l.setSalesChannel(uu.getSalesChannel());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductName(p.getName());
                l.setProductGroup(p.getGroup());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
            // Extra Information for Type Product Batch
            } else if (position.getType() == PositionType.PRODUCT_BATCH) {
                Product p = Objects.requireNonNull(productEao.findById(position.getUniqueUnitProductId()), "No Product for id=" + position.getUniqueUnitProductId());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductGroup(p.getGroup());
                l.setProductName(p.getName());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
                l.setUniqueUnitId(position.getUniqueUnitId());
                l.setSerial(position.getSerial());
                l.setRefurbishId(position.getRefurbishedId());
                if (warrantyService != null) {
                    // If this is no warranty Partno, this will return null ;-)
                    l.setContractor(warrantyService.warrantyContractor(p.getPartNo()));
                }
            }
            reportEm.persist(l);
            newLines.add(l);
        }
    }
    reportEm.flush();
    m.message("Updateing References");
    for (ReportLine newLine : newLines) {
        // Not Refs for Product_Batches or Versandkosten jet.
        if (newLine.getUniqueUnitId() < 1)
            continue;
        if (newLine.getPositionType() == PositionType.PRODUCT_BATCH) {
            // TODO: also evaluate the productId.
            newLine.addAll(reportLineEao.findBySerialAndPositionTypeAndDossierId(newLine.getSerial(), newLine.getPositionType(), newLine.getDossierId()));
        } else {
            newLine.addAll(reportLineEao.findUnitsAlike(newLine.getUniqueUnitId(), newLine.getDossierId()));
        }
    }
    updateSingleReferences(newLines);
    m.worked(5);
    m.finish();
    return amountCreate;
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) WarrantyService(eu.ggnet.dwoss.mandator.api.service.WarrantyService) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer)

Example 2 with Ledger

use of eu.ggnet.dwoss.mandator.api.value.Ledger in project dwoss by gg-net.

the class PositionUpdateCask method accept.

@Override
public void accept(PositionAndTaxType posAndTax) {
    if (posAndTax == null)
        return;
    this.position = posAndTax.getPosition();
    PostLedger postLedger = Dl.local().lookup(CachedMandators.class).loadPostLedger();
    final List<Ledger> ledgers = postLedger.getAlternatives(position.getType(), posAndTax.getTaxType());
    bookingAccountBox.setModel(new DefaultComboBoxModel(ledgers.toArray()));
    this.positionTypeField.setText(position.getType() != null ? position.getType().getName() : "Nicht angegeben");
    this.taxedConverter.taxed = position.getTax() + 1;
    this.taxField.setText(TAX.format(position.getTax()));
    this.setPositionName(position.getName());
    this.setPrice(position.getPrice());
    this.setDescription(position.getDescription());
    this.setAmount(position.getAmount());
    this.setPreDecimal((int) (position.getAmount() - (position.getAmount() % 1)));
    this.setPostDecimal((int) ((position.getAmount() % 1) * 100));
    if (position.getBookingAccount().isPresent()) {
        // Remapping of the ledger.
        if (!ledgers.contains(position.getBookingAccount().get())) {
            Ui.build(this).alert("Buchungskonto " + position.getBookingAccount().get() + " nicht für diese Position und Steuer konfiguriert. Wurde auf Standard gesetzt");
            if (!ledgers.isEmpty())
                this.setBookingAccount(ledgers.get(0));
        } else {
            this.setBookingAccount(ledgers.get(ledgers.indexOf(position.getBookingAccount().get())));
        }
    }
    this.accessCos = Dl.local().lookup(Guardian.class);
    if (position.getDocument() != null && EnumSet.of(DocumentType.ANNULATION_INVOICE, DocumentType.CREDIT_MEMO).contains(position.getDocument().getType())) {
        disableComponents(preDecimalSpinner, postDecimalSpinner, nameArea, bookingAccountBox, priceField, afterTaxPriceField, descriptionArea);
        accessCos.add(priceSumField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(afterTaxSumField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(priceField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(afterTaxPriceField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
    } else {
        if (position.getType() == PRODUCT_BATCH || position.getType() == UNIT) {
            disableComponents(postDecimalSpinner);
            accessCos.add(priceField, UPDATE_PRICE_OF_UNITS_AND_PRODUCT_BATCH);
            accessCos.add(afterTaxPriceField, UPDATE_PRICE_OF_UNITS_AND_PRODUCT_BATCH);
        }
        if (position.getType() == UNIT) {
            disableComponents(preDecimalSpinner);
            bookingAccountBox.setEnabled(true);
        }
        if (position.getType() == COMMENT) {
            disableComponents(priceField, priceSumField, afterTaxPriceField, afterTaxSumField, preDecimalSpinner, postDecimalSpinner);
        }
        if (position.getType() == SHIPPING_COST) {
            disableComponents(nameArea, afterTaxPriceField, afterTaxSumField, preDecimalSpinner, postDecimalSpinner);
        }
        if (EnumSet.of(COMMENT, SERVICE, PRODUCT_BATCH).contains(position.getType())) {
            nameArea.setEditable(true);
            if (position.getType() == SERVICE)
                bookingAccountBox.setEnabled(true);
        }
    }
}
Also used : PostLedger(eu.ggnet.dwoss.mandator.api.value.PostLedger) PostLedger(eu.ggnet.dwoss.mandator.api.value.PostLedger) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) Guardian(eu.ggnet.saft.core.auth.Guardian) CachedMandators(eu.ggnet.dwoss.mandator.upi.CachedMandators)

Example 3 with Ledger

use of eu.ggnet.dwoss.mandator.api.value.Ledger in project dwoss by gg-net.

the class SageExporterEngineTest method testExport.

@Test
public void testExport() throws UnsupportedEncodingException {
    UiCustomer cus = new UiCustomer(1, "Herr", "Max", "Müstermann", null, "none", "max@example.com", 0);
    Date date = Date.from(LocalDate.of(2018, 01, 30).atStartOfDay(systemDefault()).toInstant());
    // Prepare some data
    Dossier dos = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos.setIdentifier("DW0001");
    Document doc = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc.setIdentifier("IN1234");
    doc.setActual(date);
    dos.add(doc);
    doc.append(unit(doc.getTaxType(), new Ledger(1000, "Demo1")));
    doc.append(Position.builder().type(SHIPPING_COST).amount(1).bookingAccount(new Ledger(2000, "Versand")).price(100).tax(doc.getTaxType().getTax()).name("Versandkosten").description("Versandkosten").build());
    Dossier dos2 = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos2.setIdentifier("DW0002");
    Document doc2 = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc2.setIdentifier("IN4321");
    doc2.setActual(date);
    doc2.setTaxType(REVERSE_CHARGE);
    dos2.add(doc2);
    doc2.append(unit(doc2.getTaxType(), new Ledger(1234, "Demo2")));
    // Comparator is needed for the resulting rowlines. In productive, this is not important, but for an exact string match.
    Map<Document, UiCustomer> content = new TreeMap<>(new Comparator<Document>() {

        @Override
        public int compare(Document t0, Document t1) {
            return t0.getIdentifier().compareTo(t1.getIdentifier());
        }
    });
    content.put(doc, cus);
    content.put(doc2, cus);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SageExporterEngine engine = new SageExporterEngine(out, content, new DefaultSageExporterConfig(666, false));
    engine.execute(null);
    String result = out.toString("ISO-8859-1");
    // Enable for problemhandling
    // System.out.println(result);
    // System.out.println("---------------");
    // System.out.println(VALID);
    // System.out.println("Diff: " + StringUtils.difference(result, VALID));
    // System.out.println("DiffIndex: " + StringUtils.indexOfDifference(result, VALID));
    assertThat(result).isEqualTo(VALID);
}
Also used : SageExporterEngine(eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) DefaultSageExporterConfig(eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LocalDate(java.time.LocalDate) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) Test(org.junit.Test)

Example 4 with Ledger

use of eu.ggnet.dwoss.mandator.api.value.Ledger in project dwoss by gg-net.

the class MandatorController method init.

@PostConstruct
public void init() {
    root = new DefaultTreeNode("Root", null);
    Map<PositionType, TreeNode> levelOneNodes = new HashMap<>();
    Map<PositionType, Map<TaxType, TreeNode>> levelTwoNodes = new HashMap<>();
    for (PositionType posType : PositionType.values()) {
        for (TaxType taxType : TaxType.values()) {
            Optional<Ledger> opt = mandator.loadPostLedger().get(posType, taxType);
            if (opt.isPresent()) {
                LOG.debug("Tax" + taxType + "  Pos: " + posType + "  Ledger " + opt.get());
                if (!levelOneNodes.containsKey(posType))
                    levelOneNodes.put(posType, new DefaultTreeNode(posType.toString(), root));
                if (!levelTwoNodes.containsKey(posType)) {
                    levelTwoNodes.put(posType, new EnumMap<TaxType, TreeNode>(TaxType.class));
                    levelTwoNodes.get(posType).put(taxType, new DefaultTreeNode(taxType, levelOneNodes.get(posType)));
                } else if (!levelTwoNodes.get(posType).containsKey(taxType)) {
                    levelTwoNodes.get(posType).put(taxType, new DefaultTreeNode(taxType, levelOneNodes.get(posType)));
                }
                levelTwoNodes.get(posType).get(taxType).getChildren().add(new DefaultTreeNode(opt.get()));
            }
        }
    }
}
Also used : DefaultTreeNode(org.primefaces.model.DefaultTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Ledger

use of eu.ggnet.dwoss.mandator.api.value.Ledger in project dwoss by gg-net.

the class PositionUpdateCask method setBookingAccount.

/**
 * Set the value of bookingAccount
 *
 * @param bookingAccount new value of bookingAccount
 */
public void setBookingAccount(Ledger bookingAccount) {
    Ledger oldBookingAccount = this.bookingAccount;
    this.bookingAccount = bookingAccount;
    firePropertyChange(PROP_BOOKINGACCOUNT, oldBookingAccount, bookingAccount);
}
Also used : PostLedger(eu.ggnet.dwoss.mandator.api.value.PostLedger) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger)

Aggregations

Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)5 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)2 PostLedger (eu.ggnet.dwoss.mandator.api.value.PostLedger)2 WarrantyService (eu.ggnet.dwoss.mandator.api.service.WarrantyService)1 CachedMandators (eu.ggnet.dwoss.mandator.upi.CachedMandators)1 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 DefaultSageExporterConfig (eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig)1 SageExporterEngine (eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine)1 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)1 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)1 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)1 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)1 Guardian (eu.ggnet.saft.core.auth.Guardian)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LocalDate (java.time.LocalDate)1 PostConstruct (javax.annotation.PostConstruct)1