use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class EbicsPartnerServiceImpl method checkBankDetailsMissingCurrency.
public void checkBankDetailsMissingCurrency(EbicsPartner ebicsPartner) throws AxelorException {
List<com.axelor.apps.bankpayment.db.EbicsPartnerService> ebicsPartnerServiceSet = ebicsPartner.getBoEbicsPartnerServiceList();
if (ebicsPartnerServiceSet == null) {
return;
}
boolean allowOrderCurrDiffFromBankDetails = false;
for (com.axelor.apps.bankpayment.db.EbicsPartnerService ebicsPartnerService : ebicsPartnerServiceSet) {
allowOrderCurrDiffFromBankDetails = ebicsPartnerService.getBankOrderFileFormat().getAllowOrderCurrDiffFromBankDetails();
if (allowOrderCurrDiffFromBankDetails) {
break;
}
}
if (!allowOrderCurrDiffFromBankDetails) {
return;
}
Set<BankDetails> bankDetailsSet = ebicsPartner.getBankDetailsSet();
if (bankDetailsSet == null) {
return;
}
List<String> bankDetailsWithoutCurrency = new ArrayList<>();
for (BankDetails bankDetails : bankDetailsSet) {
if (bankDetails.getCurrency() == null) {
bankDetailsWithoutCurrency.add(bankDetails.getFullName());
}
}
if (!bankDetailsWithoutCurrency.isEmpty()) {
Function<String, String> addLi = s -> "<li>".concat(s).concat("</li>");
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.EBICS_PARTNER_BANK_DETAILS_WARNING), "<ul>" + Joiner.on("").join(Iterables.transform(bankDetailsWithoutCurrency, addLi)) + "<ul>"), ebicsPartner);
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class PaymentVoucherConfirmService method createMoveAndConfirm.
/**
* Confirm payment voucher and create move.
*
* @param paymentVoucher
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createMoveAndConfirm(PaymentVoucher paymentVoucher) throws AxelorException {
Partner payerPartner = paymentVoucher.getPartner();
PaymentMode paymentMode = paymentVoucher.getPaymentMode();
Company company = paymentVoucher.getCompany();
BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
LocalDate paymentDate = paymentVoucher.getPaymentDate();
boolean scheduleToBePaid = false;
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
// If paid by a moveline check if all the lines selected have the same account + company
// Excess payment
boolean allRight = paymentVoucherControlService.checkIfSameAccount(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine());
// Check if allright=true (means companies and accounts in lines are all the same and same as in
// move line selected for paying
log.debug("allRight : {}", allRight);
if (allRight) {
scheduleToBePaid = this.toPayWithExcessPayment(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine(), scheduleToBePaid, paymentDate);
}
if (paymentVoucher.getMoveLine() == null || (paymentVoucher.getMoveLine() != null && !allRight) || (scheduleToBePaid && !allRight && paymentVoucher.getMoveLine() != null)) {
// Manage all the cases in the same way. As if a move line (Excess payment) is selected, we
// cancel it first
Move move = moveService.getMoveCreateService().createMoveWithPaymentVoucher(journal, company, paymentVoucher, payerPartner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.setPaymentVoucher(paymentVoucher);
move.setTradingName(paymentVoucher.getTradingName());
paymentVoucher.setGeneratedMove(move);
// Create move lines for payment lines
BigDecimal paidLineTotal = BigDecimal.ZERO;
int moveLineNo = 1;
boolean isDebitToPay = paymentVoucherToolService.isDebitToPay(paymentVoucher);
for (PayVoucherElementToPay payVoucherElementToPay : this.getPayVoucherElementToPayList(paymentVoucher)) {
MoveLine moveLineToPay = payVoucherElementToPay.getMoveLine();
log.debug("PV moveLineToPay debit : {}", moveLineToPay.getDebit());
log.debug("PV moveLineToPay amountPaid : {}", moveLineToPay.getAmountPaid());
BigDecimal amountToPay = payVoucherElementToPay.getAmountToPayCurrency();
if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
paidLineTotal = paidLineTotal.add(amountToPay);
this.payMoveLine(move, moveLineNo++, payerPartner, moveLineToPay, amountToPay, payVoucherElementToPay, isDebitToPay, paymentDate);
}
}
// Create move line for the payment amount
MoveLine moveLine = null;
// in the else case we create a classical balance on the bank account of the payment mode
if (paymentVoucher.getMoveLine() != null) {
moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), paymentVoucher.getMoveLine().getAccount(), paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
Reconcile reconcile = reconcileService.createReconcile(moveLine, paymentVoucher.getMoveLine(), moveLine.getDebit(), !isDebitToPay);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
} else {
moveLine = moveLineService.createMoveLine(move, payerPartner, paymentModeAccount, paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
}
move.getMoveLineList().add(moveLine);
// Then Use Excess payment on old invoices / moveLines
if (paymentVoucher.getPaidAmount().compareTo(paidLineTotal) > 0) {
BigDecimal remainingPaidAmount = paymentVoucher.getRemainingAmount();
// TODO rajouter le process d'imputation automatique
// if(paymentVoucher.getHasAutoInput()) {
//
// List<MoveLine> debitMoveLines =
// Lists.newArrayList(pas.getDebitLinesToPay(contractLine,
// paymentVoucher.getPaymentScheduleToPay()));
// pas.createExcessPaymentWithAmount(debitMoveLines, remainingPaidAmount,
// move, moveLineNo,
// paymentVoucher.getPayerPartner(), company, contractLine, null,
// paymentDate, updateCustomerAccount);
// }
// else {
Account partnerAccount = Beans.get(AccountCustomerService.class).getPartnerAccount(payerPartner, company, paymentVoucherToolService.isPurchase(paymentVoucher));
moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), partnerAccount, remainingPaidAmount, !isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
move.getMoveLineList().add(moveLine);
if (isDebitToPay) {
reconcileService.balanceCredit(moveLine);
}
}
moveService.getMoveValidateService().validate(move);
paymentVoucher.setGeneratedMove(move);
}
paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_CONFIRMED);
deleteUnPaidLines(paymentVoucher);
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class PaymentVoucherConfirmService method confirmPaymentVoucher.
/**
* Confirms the payment voucher if the selected lines PiToPay 2nd O2M belongs to different
* companies -> error I - Payment with an amount If we pay a classical moveLine (invoice, reject
* ..) -> just create a payment If we pay a schedule 2 payments are created 1st reconciled with
* the invoice and the second reconciled with the schedule II - Payment with an excess Payment If
* we pay a moveLine having the same account, we just reconcile If we pay a with different account
* -> 1- switch money to the good account 2- reconcile then
*
* @param paymentVoucher
*/
@Transactional(rollbackOn = { Exception.class })
public void confirmPaymentVoucher(PaymentVoucher paymentVoucher) throws AxelorException {
log.debug("In confirmPaymentVoucherService ....");
paymentVoucherSequenceService.setReference(paymentVoucher);
PaymentMode paymentMode = paymentVoucher.getPaymentMode();
Company company = paymentVoucher.getCompany();
BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
paymentVoucherControlService.checkPaymentVoucherField(paymentVoucher, company, paymentModeAccount, journal);
if (paymentVoucher.getRemainingAmount().compareTo(BigDecimal.ZERO) > 0 && !journal.getExcessPaymentOk()) {
throw new AxelorException(paymentVoucher, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_AMOUNT_EXCEEDING), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
// TODO VEIRIFER QUE LES ELEMENTS A PAYER NE CONCERNE QU'UNE SEULE DEVISE
// TODO RECUPERER DEVISE DE LA PREMIERE DETTE
// Currency currencyToPay = null;
AppAccountService appAccountService = Beans.get(AppAccountService.class);
if (appAccountService.getAppAccount().getPaymentVouchersOnInvoice() && paymentVoucher.getPaymentMode().getValidatePaymentByDepositSlipPublication()) {
waitForDepositSlip(paymentVoucher);
} else {
createMoveAndConfirm(paymentVoucher);
}
paymentVoucherSequenceService.setReceiptNo(paymentVoucher, company, journal);
paymentVoucherRepository.save(paymentVoucher);
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class PaymentVoucherLoadService method initFromInvoice.
/**
* Initialize a payment voucher from an invoice.
*
* @param paymentVoucher
* @param invoice
* @throws AxelorException
*/
public void initFromInvoice(PaymentVoucher paymentVoucher, Invoice invoice) throws AxelorException {
paymentVoucher.setOperationTypeSelect(invoice.getOperationTypeSelect());
paymentVoucher.setPartner(invoice.getPartner());
paymentVoucher.setPaymentMode(invoice.getPaymentMode());
paymentVoucher.setCurrency(invoice.getCurrency());
paymentVoucher.clearPayVoucherDueElementList();
paymentVoucher.clearPayVoucherElementToPayList();
paymentVoucher.setCompany(invoice.getCompany());
BankDetails companyBankDetails;
if (invoice.getCompanyBankDetails() != null) {
companyBankDetails = invoice.getCompanyBankDetails();
} else {
companyBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(invoice.getCompany(), invoice.getPaymentMode(), invoice.getPartner(), null);
}
paymentVoucher.setCompanyBankDetails(companyBankDetails);
BigDecimal amount = BigDecimal.ZERO;
List<MoveLine> moveLineList = getMoveLines(paymentVoucher);
for (MoveLine moveLine : moveLineList) {
PayVoucherDueElement payVoucherDueElement = createPayVoucherDueElement(moveLine);
paymentVoucher.addPayVoucherDueElementListItem(payVoucherDueElement);
if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice())) {
amount = amount.add(payVoucherDueElement.getAmountRemaining());
}
}
paymentVoucher.setPaidAmount(amount);
paymentVoucher.clearPayVoucherDueElementList();
for (MoveLine moveLine : moveLineList) {
paymentVoucher.addPayVoucherDueElementListItem(createPayVoucherDueElement(moveLine));
}
if (paymentVoucher.getPayVoucherDueElementList() == null) {
return;
}
int sequence = 0;
for (Iterator<PayVoucherDueElement> it = paymentVoucher.getPayVoucherDueElementList().iterator(); it.hasNext(); ) {
PayVoucherDueElement payVoucherDueElement = it.next();
if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice()) && paymentVoucher.getCurrency().equals(payVoucherDueElement.getCurrency())) {
paymentVoucher.addPayVoucherElementToPayListItem(createPayVoucherElementToPay(paymentVoucher, payVoucherDueElement, ++sequence));
it.remove();
}
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class InvoicePaymentController method fillBankDetails.
/**
* On payment mode change, fill the bank details field if we find precisely one bank details
* available in the payment mode for the current company.
*
* @param request
* @param response
* @throws AxelorException
*/
@SuppressWarnings("unchecked")
public void fillBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
Map<String, Object> partialInvoice = (Map<String, Object>) request.getContext().get("_invoice");
Invoice invoice = Beans.get(InvoiceRepository.class).find(((Integer) partialInvoice.get("id")).longValue());
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Company company = invoice.getCompany();
List<BankDetails> bankDetailsList = Beans.get(InvoicePaymentToolService.class).findCompatibleBankDetails(company, invoicePayment);
if (bankDetailsList.size() == 1) {
response.setValue("companyBankDetails", bankDetailsList.get(0));
} else {
response.setValue("companyBankDetails", null);
}
Partner partner = invoice.getPartner();
if (company == null) {
return;
}
if (partner != null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
}
BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
response.setValue("bankDetails", defaultBankDetails);
}
Aggregations