use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class DebtorBankAccountService method uniqueDebtorAccountToPay.
@Programmatic
public BankAccount uniqueDebtorAccountToPay(final IncomingInvoice invoice) {
final Party buyer = invoice.getBuyer();
List<BankAccount> bankAccountsForBuyer = bankAccountRepository.findBankAccountsByOwner(buyer);
final Property propertyIfAny = invoice.getProperty();
if (propertyIfAny != null) {
List<FixedAssetFinancialAccount> fafrList = fixedAssetFinancialAccountRepository.findByFixedAsset(propertyIfAny);
List<FinancialAccount> bankAccountsForProperty = fafrList.stream().map(FixedAssetFinancialAccount::getFinancialAccount).filter(BankAccount.class::isInstance).map(BankAccount.class::cast).collect(Collectors.toList());
bankAccountsForBuyer.retainAll(bankAccountsForProperty);
}
// original implementation ... see if we already have a unique bank account
int numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
}
// see if removing non-preferred helps
bankAccountsForBuyer.removeIf(x -> (x.getPreferred() == null || !x.getPreferred()));
numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
// give up, still non-duplicate
return null;
}
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class BankAccount_attachPdfAsIbanProof method act.
@Action(semantics = SemanticsOf.IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg0.class)
public BankAccount act(@Parameter(fileAccept = "application/pdf") final Blob document) {
final DocumentType ibanProofDocType = DocumentTypeData.IBAN_PROOF.findUsing(documentTypeRepository);
final List<Paperclip> ibanProofPaperclips = paperclipRepository.findByAttachedToAndRoleName(bankAccount, ROLE_NAME_FOR_IBAN_PROOF);
// delete all existing paperclips for this role whose type is also not IBAN_PROOF
// (ie any incoming invoices that were automatically attached as candidate iban proofs)
final Predicate<Paperclip> hasIbanProofDocType = paperclip -> Objects.equals(ibanProofDocType, paperclip.getDocument().getType());
final Predicate<Paperclip> doesNotHaveIbanProofDocType = hasIbanProofDocType.negate();
ibanProofPaperclips.stream().filter(doesNotHaveIbanProofDocType).forEach(paperclip -> paperclipRepository.delete(paperclip));
final String name = document.getName();
documentService.createAndAttachDocumentForBlob(ibanProofDocType, bankAccount.getAtPath(), name, document, ROLE_NAME_FOR_IBAN_PROOF, bankAccount);
return bankAccount;
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class PaymentBatchManager method autoCreateBatches.
@Action(semantics = SemanticsOf.IDEMPOTENT, publishing = Publishing.DISABLED)
public PaymentBatchManager autoCreateBatches(@Nullable final List<IncomingInvoice> payableInvoices) {
for (final IncomingInvoice payableInvoice : payableInvoices) {
final BankAccount uniqueBankAccountIfAny = debtorBankAccountService.uniqueDebtorAccountToPay(payableInvoice);
if (uniqueBankAccountIfAny != null && uniqueBankAccountIfAny.getBic() != null) {
// should be true, because those that don't pass this are filtered out in choicesXxx anyway.
PaymentBatch paymentBatch = paymentBatchRepository.findOrCreateNewByDebtorBankAccount(uniqueBankAccountIfAny);
paymentBatch.addLineIfRequired(payableInvoice);
}
}
final List<PaymentBatch> newBatches = getNewBatches();
for (final PaymentBatch paymentBatch : newBatches) {
removeNegativeTransfers(paymentBatch);
}
return new PaymentBatchManager(newBatches.isEmpty() ? null : 0);
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class PaymentBatch method downloadReviewPdf.
@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Blob downloadReviewPdf(final String documentName, @ParameterLayout(named = "How many first pages of each invoice's PDF?") final Integer numFirstPages, @ParameterLayout(named = "How many final pages of each invoice's PDF?") final Integer numLastPages) throws IOException {
final List<File> pdfFiles = Lists.newArrayList();
final List<CreditTransfer> transfers = this.getTransfers();
for (CreditTransfer transfer : transfers) {
final List<PaymentLine> lines = transfer.getLines();
for (final PaymentLine line : lines) {
final IncomingInvoice invoice = line.getInvoice();
final BankAccount bankAccount = invoice.getBankAccount();
final Optional<org.incode.module.document.dom.impl.docs.Document> invoiceDocIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
if (invoiceDocIfAny.isPresent()) {
final org.incode.module.document.dom.impl.docs.Document invoiceDoc = invoiceDocIfAny.get();
final byte[] invoiceDocBytes = invoiceDoc.asBytes();
final Optional<org.incode.module.document.dom.impl.docs.Document> ibanProofDocIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
List<String> leftLines = Lists.newArrayList();
leftLines.add("xfer id: " + transfer.getEndToEndId() + " / " + line.getSequence());
for (IncomingInvoice.ApprovalString approvalString : invoice.getApprovals()) {
leftLines.add(String.format("approved by: %s", approvalString.getCompletedBy()));
leftLines.add("on: " + approvalString.getCompletedOn());
}
final List<String> rightLines = Lists.newArrayList();
rightLines.add(String.format("debtor IBAN: %s", line.getBatch().getDebtorBankAccount().getIban()));
rightLines.add(String.format("crdtor IBAN: %s", line.getCreditorBankAccount().getIban()));
rightLines.add(String.format("gross Amt : %s", new DecimalFormat("0.00").format(line.getAmount())));
boolean attachProof = false;
final String proof;
if (ibanProofDocIfAny.isPresent()) {
final org.incode.module.document.dom.impl.docs.Document ibanProofDoc = ibanProofDocIfAny.get();
if (DocumentTypeData.IBAN_PROOF.isDocTypeFor(ibanProofDoc)) {
proof = "Separate IBAN proof (next page)";
attachProof = true;
} else {
proof = "Invoice used as IBAN proof";
}
} else {
proof = "No IBAN proof";
}
rightLines.add(proof);
URI uri = deepLinkService.deepLinkFor(invoice);
final Stamp stamp = new Stamp(leftLines, rightLines, uri.toString());
final byte[] extractedInvoiceDocBytes = pdfManipulator.extractAndStamp(invoiceDocBytes, new ExtractSpec(numFirstPages, numLastPages), stamp);
appendTempFile(extractedInvoiceDocBytes, documentName, pdfFiles);
if (attachProof) {
final org.incode.module.document.dom.impl.docs.Document ibanProofDoc = ibanProofDocIfAny.get();
final byte[] ibanProofBytes = ibanProofDoc.asBytes();
final byte[] firstPageIbanProofDocBytes = pdfManipulator.extract(ibanProofBytes, ExtractSpec.FIRST_PAGE_ONLY);
appendTempFile(firstPageIbanProofDocBytes, documentName, pdfFiles);
}
}
}
}
byte[] pdfMergedBytes = pdfBoxService.merge(pdfFiles);
pdfFiles.stream().forEach(this::cleanup);
return new Blob(documentName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, pdfMergedBytes);
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class BankMandateImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
final Lease lease = fetchLease(leaseReference);
BankAccount bankAccount;
BankMandate bankMandate = null;
// find or create bank account
final Party owner = lease.getSecondaryParty();
bankAccount = (BankAccount) financialAccountRepository.findByOwnerAndReference(owner, bankAccountReference);
if (bankAccount == null) {
bankAccount = bankAccountRepository.newBankAccount(owner, bankAccountReference, null);
}
if (reference != null) {
bankMandate = bankMandateRepository.findByReference(reference);
}
if (bankMandate == null) {
lease.newMandate(bankAccount, reference, startDate, endDate, SequenceType.valueOf(sequenceType), Scheme.valueOf(scheme), signatureDate);
bankMandate = lease.getPaidBy();
}
bankMandate.setBankAccount(bankAccount);
bankMandate.setReference(reference);
bankMandate.setName(name);
bankMandate.setStartDate(startDate);
bankMandate.setEndDate(endDate);
bankMandate.setSepaMandateIdentifier(sepaMandateIdentifier);
bankMandate.setSequenceType(SequenceType.valueOf(sequenceType));
bankMandate.setScheme(Scheme.valueOf(scheme));
bankMandate.setSignatureDate(signatureDate);
lease.paidBy(bankMandate);
return Lists.newArrayList(bankMandate);
}
Aggregations