use of eu.ggnet.dwoss.customer.opi.CustomerMetaData in project dwoss by gg-net.
the class RedTapeGeneratorOperation method makeSalesDossiers.
/**
* Generates a random amount of dossiers in a random valid state using already persisted elements like available units and product batches.
* <p/>
* @param amount
* @return the list of generated dossiers.
*/
// TODO: Some usefull repayments would be nice.
public List<Dossier> makeSalesDossiers(int amount) {
SubMonitor m = monitorFactory.newSubMonitor("Erzeuge " + amount + " Dossiers", amount);
m.start();
if (amount < 1)
return Collections.EMPTY_LIST;
List<CustomerMetaData> customers = customerService.allAsCustomerMetaData().stream().filter(c -> !c.getFlags().contains(SYSTEM_CUSTOMER)).collect(toList());
if (customers.isEmpty())
throw new RuntimeException("No Customers found, obviously there are non in the database");
List<UniqueUnit> freeUniqueUnits = uniqueUnitAgent.findAllEager(UniqueUnit.class);
List<Product> products = uniqueUnitAgent.findAllEager(Product.class);
List<Dossier> dossiers = new ArrayList<>();
for (int i = 0; i <= amount; i++) {
CustomerMetaData customer = customers.get(R.nextInt(customers.size()));
// Create a dossier on a random customer.
Dossier dos = redTapeWorker.create(customer.getId(), R.nextBoolean(), "Generated by RedTapeGeneratorOperation.makeSalesDossiers()");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
// At least two positions.
int noOfPositions = R.nextInt(10) + 2;
Set<Long> productIds = new HashSet<>();
for (int j = 0; j < noOfPositions; j++) {
// Add Some units, but make sure, not only units are added.
if (j < (noOfPositions - 2) && !freeUniqueUnits.isEmpty()) {
UniqueUnit uu = null;
while (uu == null && !freeUniqueUnits.isEmpty()) {
uu = freeUniqueUnits.remove(0);
StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uu.getId());
// Saftynet, so no unit is set double.
if (su == null || su.getLogicTransaction() != null)
uu = null;
}
if (uu == null)
continue;
double price = uu.getPrice(PriceType.CUSTOMER);
if (price < 0.001)
price = uu.getPrice(PriceType.RETAILER);
if (price < 0.001)
price = 1111.11;
Position pos = Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(price).tax(doc.getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).refurbishedId(uu.getIdentifier(REFURBISHED_ID)).build();
doc.append(pos);
continue;
}
double price = (R.nextInt(100000) + 100) / 100;
switch(// Add a random position
R.nextInt(3)) {
case // Add a Product Batch
0:
Product p;
int k = 0;
do {
p = products.get(R.nextInt(products.size()));
k++;
if (k > 10)
throw new RuntimeException("Could find a alternative product : p.size=" + products.size() + ", pids.size=" + productIds.size());
} while (productIds.contains(p.getId()));
productIds.add(p.getId());
doc.append(Position.builder().amount(R.nextInt(10) + 1).type(PositionType.PRODUCT_BATCH).uniqueUnitProductId(p.getId()).price(price).tax(doc.getSingleTax()).name(p.getName()).description(p.getDescription()).bookingAccount(postLedger.get(PositionType.PRODUCT_BATCH, doc.getTaxType()).orElse(null)).build());
break;
case // Add a Service
1:
doc.append(Position.builder().amount((R.nextInt(100) + 1) / 4.0).type(PositionType.SERVICE).price(price).tax(doc.getSingleTax()).name("Service").description("Service").bookingAccount(postLedger.get(PositionType.SERVICE, doc.getTaxType()).orElse(null)).build());
break;
case // Add a comment
2:
doc.append(Position.builder().amount(1).type(PositionType.COMMENT).name("Comment").description("Comment").bookingAccount(postLedger.get(PositionType.COMMENT, doc.getTaxType()).orElse(null)).build());
break;
}
}
if (dos.isDispatch()) {
// add the shipping costs.
double price = (R.nextInt(10) + 1) * 10;
doc.append(Position.builder().amount(1).type(PositionType.SHIPPING_COST).price(price).tax(doc.getSingleTax()).name("Versandkosten").description("Versandkosten").bookingAccount(postLedger.get(PositionType.SHIPPING_COST, doc.getTaxType()).orElse(null)).build());
}
// Break, if what we build is wrong.
ValidationUtil.validate(doc);
LOG.info("Preupdate document.id={}", doc.getId());
doc = redTapeWorker.update(doc, null, "JUnit");
for (int j = 0; j <= R.nextInt(4); j++) {
CustomerDocument cd = new CustomerDocument(customer.getFlags(), doc, customer.getShippingCondition(), customer.getPaymentMethod());
List<StateTransition<CustomerDocument>> transitions = redTapeWorker.getPossibleTransitions(cd);
if (transitions.isEmpty())
break;
RedTapeStateTransition transition = (RedTapeStateTransition) transitions.get(R.nextInt(transitions.size()));
if (transition.getHints().contains(RedTapeStateTransition.Hint.CREATES_ANNULATION_INVOICE) || transition.getHints().contains(RedTapeStateTransition.Hint.CREATES_CREDIT_MEMO))
break;
// Never fails.
Reply<Document> reply = redTapeWorker.stateChange(cd, transition, "JUnit");
if (reply.hasSucceded())
doc = reply.getPayload();
else {
LOG.error("Fail on startChange {}", reply.getSummary());
break;
}
}
dossiers.add(doc.getDossier());
m.worked(1, doc.getDossier().getIdentifier());
}
m.finish();
return dossiers;
}
use of eu.ggnet.dwoss.customer.opi.CustomerMetaData in project dwoss by gg-net.
the class RedTapeCreateDossierWorkflow method execute.
/**
* Executes the Workflow.
*
* @param customerId
* @param dispatch
* @param arranger
* @return the Dossier.
*/
public Dossier execute(long customerId, boolean dispatch, String arranger) {
DocumentType type = DocumentType.ORDER;
CustomerMetaData customer = customerService.asCustomerMetaData(customerId);
L.debug("Found Customer: {}", customer);
if (customer.getFlags().contains(SYSTEM_CUSTOMER)) {
type = specialSystemCustomers.get(customerId).orElse(BLOCK);
L.debug("CustomerId {} is SystemCustomer, using DocumentType: {}, source {}", customerId, type, specialSystemCustomers);
}
PaymentMethod paymentMethod = selectPaymentMethod(dispatch, customer);
Directive directive = primeDirective(type, paymentMethod, customer.getFlags(), dispatch);
return createDossier(customerId, dispatch, type, paymentMethod, directive, arranger);
}
use of eu.ggnet.dwoss.customer.opi.CustomerMetaData in project dwoss by gg-net.
the class RedTapeModel method setPurchaseCustomer.
/**
* Set the value of customer
*
* @param id id of the customer
*/
public void setPurchaseCustomer(long id) {
CustomerMetaData old = this.purchaseCustomer;
this.purchaseCustomer = Dl.remote().lookup(CustomerService.class).asCustomerMetaData(id);
propertyChangeSupport.firePropertyChange(PROP_CUSTOMER, old, purchaseCustomer);
}
use of eu.ggnet.dwoss.customer.opi.CustomerMetaData in project dwoss by gg-net.
the class RedTapeCloserOperationIT method testDayClosingWarrenty.
@Test
public void testDayClosingWarrenty() throws UserInfoException {
long customerId = customerGenerator.makeCustomer();
UniqueUnit uu = receiptGenerator.makeUniqueUnits(1, true, true).get(0);
Product p = redTapeCloserOpertaionItBean.makeWarrantyProduct();
CustomerMetaData metaCustomer = customerService.asCustomerMetaData(customerId);
assertFalse("no customer in database", customerId == 0);
assertFalse("bo unique unit in database", uu == null);
assertFalse("no customer meta data found", metaCustomer == null);
assertFalse("no warranty product in database", p == null);
// Create a dossier on a random customer.
Dossier dos = redTapeWorker.create(customerId, false, "Generated by RedTapeGeneratorOperation.makeSalesDossiers()");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
double price = uu.getPrice(PriceType.CUSTOMER);
if (price < 0.001)
price = uu.getPrice(PriceType.RETAILER);
if (price < 0.001)
price = 1111.11;
Position pos = Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(price).tax(doc.getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).build();
pos.setRefurbishedId(uu.getRefurbishId());
doc.appendAll(new RedTapeHookStup().elaborateUnitPosition(pos, doc.getId()).getPayload());
doc = redTapeWorker.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
redTapeCloser.executeManual("Junit");
doc = redTapeAgent.findByIdEager(Document.class, doc.getId());
doc.setType(DocumentType.COMPLAINT);
doc.setDirective(Document.Directive.WAIT_FOR_COMPLAINT_COMPLETION);
doc = redTapeWorker.update(doc, null, "JUnit");
redTapeCloser.executeManual("Junit");
redTapeCloserOpertaionItBean.checkReferences(dos.getId());
}
use of eu.ggnet.dwoss.customer.opi.CustomerMetaData in project dwoss by gg-net.
the class DocumentPrintAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Ui.exec(() -> {
// TODO: This is a very special case, there the Ui needs the result on construction. So the consumer pattern cannot be used.
// This meeans, for now no progress display.
JasperPrint print = Dl.remote().lookup(DocumentSupporter.class).render(document, type);
CustomerMetaData customer = Dl.remote().lookup(CustomerService.class).asCustomerMetaData(customerId);
boolean mailAvailable = customer.getEmail() != null && !customer.getEmail().trim().isEmpty();
Ui.exec(() -> {
Ui.build().parent(controller.getView()).swing().eval(() -> new JRViewerCask(print, document, type, mailAvailable)).opt().filter(c -> c.isCorrectlyBriefed()).ifPresent(c -> Ui.progress().call(() -> {
CustomerDocument customerDocument = new CustomerDocument(customer.getFlags(), document, customer.getShippingCondition(), customer.getPaymentMethod());
for (StateTransition<CustomerDocument> stateTransition : Dl.remote().lookup(RedTapeWorker.class).getPossibleTransitions(customerDocument)) {
RedTapeStateTransition redTapeStateTransition = (RedTapeStateTransition) stateTransition;
for (RedTapeStateTransition.Hint hint : redTapeStateTransition.getHints()) {
if (hint == RedTapeStateTransition.Hint.SENDED_INFORMATION) {
this.document = Optional.of(Dl.remote().lookup(RedTapeWorker.class).stateChange(customerDocument, redTapeStateTransition, Lookup.getDefault().lookup(Guardian.class).getUsername())).filter(Ui.failure()::handle).map(Reply::getPayload).orElse(document);
}
}
}
controller.reloadSelectionOnStateChange(Dl.remote().lookup(DocumentSupporter.class).briefed(document, Dl.local().lookup(Guardian.class).getUsername()));
return null;
}));
});
});
}
Aggregations