Search in sources :

Example 26 with BankAccount

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;
    }
}
Also used : FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 27 with BankAccount

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;
}
Also used : Action(org.apache.isis.applib.annotation.Action) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) PaperclipRepository(org.incode.module.document.dom.impl.paperclips.PaperclipRepository) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) Predicate(java.util.function.Predicate) DocumentTypeRepository(org.incode.module.document.dom.impl.types.DocumentTypeRepository) Objects(java.util.Objects) Inject(javax.inject.Inject) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) DocumentService(org.incode.module.document.dom.api.DocumentService) DeriveBlobFromDummyPdfArg0(org.incode.module.base.spi.DeriveBlobFromDummyPdfArg0) BankAccount(org.estatio.module.financial.dom.BankAccount) Parameter(org.apache.isis.applib.annotation.Parameter) Blob(org.apache.isis.applib.value.Blob) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) Action(org.apache.isis.applib.annotation.Action)

Example 28 with 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);
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Action(org.apache.isis.applib.annotation.Action)

Example 29 with BankAccount

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);
}
Also used : DecimalFormat(java.text.DecimalFormat) Document(iso.std.iso._20022.tech.xsd.pain_001_001.Document) URI(java.net.URI) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Blob(org.apache.isis.applib.value.Blob) Stamp(org.estatio.module.capex.platform.pdfmanipulator.Stamp) BankAccount(org.estatio.module.financial.dom.BankAccount) ExtractSpec(org.estatio.module.capex.platform.pdfmanipulator.ExtractSpec) File(java.io.File) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 30 with BankAccount

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);
}
Also used : Party(org.estatio.module.party.dom.Party) Lease(org.estatio.module.lease.dom.Lease) BankAccount(org.estatio.module.financial.dom.BankAccount) BankMandate(org.estatio.module.bankmandate.dom.BankMandate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

BankAccount (org.estatio.module.financial.dom.BankAccount)37 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)14 Test (org.junit.Test)13 Party (org.estatio.module.party.dom.Party)12 Programmatic (org.apache.isis.applib.annotation.Programmatic)11 Expectations (org.jmock.Expectations)9 Organisation (org.estatio.module.party.dom.Organisation)7 ArrayList (java.util.ArrayList)5 Action (org.apache.isis.applib.annotation.Action)4 Property (org.estatio.module.asset.dom.Property)4 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)4 FinancialAccount (org.estatio.module.financial.dom.FinancialAccount)4 BigDecimal (java.math.BigDecimal)3 List (java.util.List)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 Inject (javax.inject.Inject)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Blob (org.apache.isis.applib.value.Blob)2 FixedAssetFinancialAccount (org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount)2 BankMandate (org.estatio.module.bankmandate.dom.BankMandate)2