Search in sources :

Example 6 with UiCustomer

use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.

the class DirectDebitReporterOperation method toXls.

/**
 * Creates the Report
 * <p/>
 * @return a ByteArray represeting the content of an xls file.
 */
@Override
public FileJacket toXls() {
    SubMonitor m = monitorFactory.newSubMonitor("Lastschriften", 25);
    m.worked(10);
    DocumentEao docEao = new DocumentEao(redTapeEm);
    List<Document> documents = docEao.findInvoiceUnpaid(DIRECT_DEBIT);
    Set<Long> customers = new HashSet<>();
    for (Document document : documents) {
        customers.add(document.getDossier().getCustomerId());
    }
    for (Long customerId : customers) {
        documents.addAll(docEao.findUnBalancedAnulation(customerId, DIRECT_DEBIT));
    }
    List<Object[]> rows = new ArrayList<>();
    for (Document doc : documents) {
        UiCustomer customer = customerService.asUiCustomer(doc.getDossier().getCustomerId());
        rows.add(new Object[] { doc.getDossier().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), doc.getDirective().getName(), DocumentFormater.toConditions(doc), doc.getIdentifier(), doc.getActual(), doc.getPrice(), doc.toAfterTaxPrice(), doc.getDossier().getComment(), customerService.asCustomerMetaData(customer.getId()).getEmail() });
    }
    m.worked(10);
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("Vorgang", 10)).add(new STableColumn("KID", 8)).add(new STableColumn("Kunde", 40));
    table.add(new STableColumn("Anweisung", 35)).add(new STableColumn("Status", 20)).add(new STableColumn("Dokument", 15)).add(new STableColumn("Datum", 15, new CFormat(SHORT_DATE)));
    table.add(new STableColumn("Netto", 15, new CFormat(RIGHT, CURRENCY_EURO))).add(new STableColumn("Brutto", 15, new CFormat(RIGHT, CURRENCY_EURO)));
    table.add(new STableColumn("Bemerkung", 50)).add(new STableColumn("eMail", 50));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument("Lastschriften");
    cdoc.add(new CSheet("Sheet1", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("Lastschriften", ".xls", file);
    m.finish();
    return result;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) File(java.io.File)

Example 7 with UiCustomer

use of eu.ggnet.dwoss.customer.opi.UiCustomer 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 8 with UiCustomer

use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.

the class SageExporterOperation method toXml.

/**
 * Exports the all Documents in the Range as the specified XML lines.
 * <p/>
 * @param start the starting date
 * @param end   the ending date
 * @return an Xml document, ready for import in GS Office.
 */
@Override
@AutoLogger
public FileJacket toXml(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("GS Buchhalter Export", 100);
    m.start();
    m.message("Loading Invoices");
    DocumentEao documentEao = new DocumentEao(redTapeEm);
    List<Document> documents = new ArrayList<>();
    documents.addAll(documentEao.findDocumentsBetweenDates(start, end, INVOICE, CREDIT_MEMO, ANNULATION_INVOICE));
    L.info("Loaded {} amount of documents", documents.size());
    m.worked(10);
    Map<Document, UiCustomer> customerInvoices = new HashMap<>();
    m.setWorkRemaining(documents.size() * 2);
    for (Document document : documents) {
        m.worked(1, "Handling Invoice " + document.getIdentifier());
        customerInvoices.put(document, customerService.asUiCustomer(document.getDossier().getCustomerId()));
    }
    m.message("Generating Outfile");
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        SageExporterEngine exporter = new SageExporterEngine(out, customerInvoices, config);
        exporter.execute(m);
        m.finish();
        return new FileJacket("Buchungsaetze DW " + mandator.getCompany().getName() + " von " + DATE_FORMAT.format(start) + " bis " + DATE_FORMAT.format(end), ".xml", out.toByteArray());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SageExporterEngine(eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine) DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) AutoLogger(eu.ggnet.dwoss.common.log.AutoLogger)

Example 9 with UiCustomer

use of eu.ggnet.dwoss.customer.opi.UiCustomer in project dwoss by gg-net.

the class CustomerServiceSimpleSearchIT method testFind.

@Test
public void testFind() {
    OldCustomer c1 = new OldCustomer("Die Firma", "Herr", "Max", "Mustermann", "Keine Bemerkungen", "Helle Strasse 22", "12345", "Musterhausen");
    OldCustomer c2 = new OldCustomer(null, "Frau", "Marria", "Mustermann", "Grosse Tüten", "Dunkle Allee 7", "12345", "Musterhausen", "Dünne Gasse 2", "22222", "Wolfsstaaad");
    c2.setPaymentMethod(PaymentMethod.DIRECT_DEBIT);
    c2.addFlag(CustomerFlag.CONFIRMS_DOSSIER);
    c1.setPaymentCondition(PaymentCondition.CUSTOMER);
    // by pp
    OldCustomer c3 = new OldCustomer("Schlagstock Ltd.", "Herr", "Michael", "Wankelmeier", "Bloß freundlich sein !!!", "Adamsweg 3", "00666", "Eisenhüttenstadt");
    c3.addFlag(CustomerFlag.CONFIRMS_DOSSIER);
    c3.addFlag(CustomerFlag.CONFIRMED_CASH_ON_DELIVERY);
    c3.setPaymentMethod(PaymentMethod.CASH_ON_DELIVERY);
    c3.setAllowedSalesChannels(EnumSet.of(SalesChannel.CUSTOMER, SalesChannel.RETAILER));
    c3.setPaymentCondition(PaymentCondition.DEALER_3_PERCENT_DISCOUNT);
    c3.setShippingCondition(ShippingCondition.DEALER_ONE);
    OldCustomer c4 = new OldCustomer(null, "Frau", "Lisa", "Lüstling", null, "Freie Straße 2", "98745", "Heimwehrhausen", "Dünne Gasse 2", "22222", "Heimwehrhausen");
    c4.addFlag(CustomerFlag.CONFIRMS_DOSSIER);
    c4.setAllowedSalesChannels(EnumSet.of(SalesChannel.CUSTOMER));
    c4.setPaymentCondition(PaymentCondition.EMPLOYEE);
    c4.setShippingCondition(ShippingCondition.DEALER_ONE);
    c4.setPaymentMethod(PaymentMethod.INVOICE);
    c4.setEmail("lisa@xxx.com");
    // --------
    agent.store(c1);
    agent.store(c2);
    agent.store(c3);
    agent.store(c4);
    assertEquals("Finding all Customers", 4, eao.findAll().size());
    List<UiCustomer> asUiCustomers = customerService.asUiCustomers("Die Firma", null, "", "   ", true);
    assertThat(asUiCustomers).hasSize(1);
    L.info("Y(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers("Die Fi", "Max", "", "   ", true);
    L.info("Y(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers("Die Fi", "Max", "Muster", "   ", true);
    L.info("Y(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers("Die Fi", "Moritz", "", "   ", true);
    L.info("N(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers("Die Fi", null, "", "   ", false);
    L.info("N(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers("Die Fam", null, "", "   ", true);
    L.info("N(" + asUiCustomers.size() + "):" + asUiCustomers);
    asUiCustomers = customerService.asUiCustomers(null, null, null, "lisa", true);
    L.info("Y(" + asUiCustomers.size() + "):" + asUiCustomers);
    assertEquals("Finding all Customers", 4, customerService.asUiCustomers(null, null, "", "   ", true).size());
    assertEquals(1, customerService.asUiCustomers("Die Firma", null, null, null, true).size());
    assertEquals(1, customerService.asUiCustomers("Schla", null, null, null, true).size());
    assertEquals(1, customerService.asUiCustomers(null, "Mic", null, null, true).size());
    assertEquals(3, customerService.asUiCustomers(null, "M", null, null, true).size());
}
Also used : OldCustomer(eu.ggnet.dwoss.customer.ee.priv.OldCustomer) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) Test(org.junit.Test)

Example 10 with UiCustomer

use of eu.ggnet.dwoss.customer.opi.UiCustomer 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)

Aggregations

UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)8 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)5 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)5 FileJacket (eu.ggnet.dwoss.util.FileJacket)5 File (java.io.File)4 OldCustomer (eu.ggnet.dwoss.customer.ee.priv.OldCustomer)3 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 CBorder (eu.ggnet.lucidcalc.CBorder)3 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)3 CFormat (eu.ggnet.lucidcalc.CFormat)3 CSheet (eu.ggnet.lucidcalc.CSheet)3 STable (eu.ggnet.lucidcalc.STable)3 STableColumn (eu.ggnet.lucidcalc.STableColumn)3 STableModelList (eu.ggnet.lucidcalc.STableModelList)3 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)3 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)2 SageExporterEngine (eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine)2 Row (eu.ggnet.dwoss.redtape.ee.sage.xml.Row)2