use of eu.ggnet.dwoss.report.ee.entity.Report in project dwoss by gg-net.
the class ReportLineTest method testRepayment.
@Test
public void testRepayment() {
Report report = new Report("TestReport", ONESELF, NOW, NOW);
ReportLine line1 = ReportLine.builder().documentType(DocumentType.INVOICE).documentId(1).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(100).tax(0.19).build();
report.add(line1);
assertFalse(line1.isPartialRepayed());
// Creditmemo unitAnnex.
ReportLine line2 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(2).dossierId(1).customerId(1).positionType(PositionType.UNIT_ANNEX).name("Unit-123").refurbishId("123").amount(1).price(-10).tax(0.19).build();
line1.add(line2);
report.add(line2);
assertTrue(line2.isPartialRepayment());
assertFalse(line1.isFullRepayed());
assertTrue(line1.isPartialRepayed());
// Now add A Unit.
ReportLine line3 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(3).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(-90).tax(0.19).build();
line1.add(line3);
line2.add(line3);
report.add(line3);
assertTrue(line3.isFullRepayment());
assertTrue(line2.isFullRepayed());
assertFalse(line2.isPartialRepayed());
assertTrue(line1.isFullRepayed());
assertFalse(line1.isPartialRepayed());
}
use of eu.ggnet.dwoss.report.ee.entity.Report in project dwoss by gg-net.
the class ReportEmo method request.
/**
* This method search a Report where all parameters are equal to one in the Database, if no is existing in the database a new one will be created and
* returned.
* <p>
* @param name is the name of the Report
* @param contractor is the contractor of the Report as {@link TradeName}.
* @param starting is the Date where the report is starting
* @param end is the Date where the report is ending.
* @return the founded or the new created Report.
*/
public Report request(String name, TradeName contractor, Date starting, Date end) {
Report singleResult = new JPAQuery(reportEm).from(report).where(report.name.equalsIgnoreCase(name).and(report.startingDate.eq(starting).and(report.endingDate.eq(end).and(report.type.eq(contractor))))).singleResult(report);
if (singleResult != null)
return singleResult;
Report report = new Report(name, contractor, starting, end);
reportEm.persist(report);
return report;
}
use of eu.ggnet.dwoss.report.ee.entity.Report in project dwoss by gg-net.
the class PersistenceIT method testPersistence.
@Test
public void testPersistence() throws Exception {
ReportLine line1 = new ReportLine("PersName1", "This is a TestDescription1", 137, "DW0037", 3, "RE0008", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
ReportLine line2 = new ReportLine("PersName2", "This is a TestDescription2", 1337, "DW0013", 3, "RE001", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
ReportLine line3 = new ReportLine("PersName3", "This is a TestDescription3", 13, "DW1337", 3, "RE0003", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
Report report = new Report("TestReport", ONESELF, new Date(Calendar.getInstance().getTimeInMillis() - 100000), new Date());
utx.begin();
em.joinTransaction();
em.persist(line1);
em.persist(line2);
em.persist(line3);
report.add(line1);
report.add(line2);
report.add(line3);
em.persist(report);
utx.commit();
}
use of eu.ggnet.dwoss.report.ee.entity.Report 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.report.ee.entity.Report in project dwoss by gg-net.
the class ReportTest method testRepaymentThreeReports.
@Test
public void testRepaymentThreeReports() {
Report report1 = new Report("TestReport 1", ALSO, NOW, NOW);
Report report2 = new Report("TestReport 2", ALSO, NOW, NOW);
Report report3 = new Report("TestReport 3", ALSO, NOW, NOW);
ReportLine line1 = ReportLine.builder().documentType(DocumentType.INVOICE).documentId(1).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(100).tax(0.19).build();
report1.add(line1);
// Creditmemo unitAnnex.
ReportLine line2 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(2).dossierId(1).customerId(1).positionType(PositionType.UNIT_ANNEX).name("Unit-123").refurbishId("123").amount(1).price(-10).tax(0.19).build();
line1.add(line2);
report2.add(line2);
// Now add A Unit.
ReportLine line3 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(3).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(-90).tax(0.19).build();
line1.add(line3);
line2.add(line3);
report3.add(line3);
assertTrue("Report1 should only contain line1 of invoice\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report1.filterInvoiced().size() == 1 && report1.filterInvoiced().contains(line1) && report1.filterInfos().isEmpty() && report1.filterRepayed().isEmpty());
assertTrue("Report2 should only contaion line2 of partial repayment\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report2.filterInvoiced().isEmpty() && report2.filterInfos().isEmpty() && report2.filterRepayed().size() == 1 && report2.filterRepayed().contains(line2));
assertTrue("Report3 should only contaion line3 of full repayment\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report3.filterInvoiced().isEmpty() && report3.filterInfos().isEmpty() && report3.filterRepayed().size() == 1 && report3.filterRepayed().contains(line3));
}
Aggregations