use of eu.ggnet.dwoss.redtape.ee.entity.Document.Directive 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.redtape.ee.entity.Document.Directive in project dwoss by gg-net.
the class RedTapeCreateDossierWorkflow method createDossier.
/**
* Creates the Dossier.
*
* @param customer the customer
* @return the Dossier.
*/
Dossier createDossier(long customerId, boolean dispatch, DocumentType type, PaymentMethod paymentMethod, Directive directive, String arranger) {
if (specialSystemCustomers.get(customerId).map(x -> x != type).orElse(false)) {
throw new IllegalStateException(type + " is not allowed for Customer " + customerId);
}
Dossier dos = new Dossier();
dos.setPaymentMethod(paymentMethod);
dos.setDispatch(dispatch);
dos.setCustomerId(customerId);
Document doc = new Document();
doc.setType(type);
doc.setActive(true);
doc.setDirective(directive);
doc.setHistory(new DocumentHistory(arranger, "Automatische Erstellung eines leeren Dokuments"));
AddressEmo adEmo = new AddressEmo(redTapeEm);
doc.setInvoiceAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.INVOICE)));
doc.setShippingAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.SHIPPING)));
dos.add(doc);
redTapeEm.persist(dos);
// Make sure the dos.id is generated an stored in the database.
redTapeEm.flush();
dos.setIdentifier(mandator.getDossierPrefix() + _00000_.format(dos.getId()));
// Force store Identifier
redTapeEm.flush();
L.info("Created {} by {}", DossierFormater.toSimpleLine(dos), arranger);
return dos;
}
Aggregations