use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class BankReconciliationService method getJournal.
public Journal getJournal(BankReconciliation bankReconciliation) {
Journal journal = null;
String journalIds = String.join(",", getAccountManagementJournals(bankReconciliation));
if (bankReconciliation.getBankDetails().getJournal() != null) {
journal = bankReconciliation.getBankDetails().getJournal();
} else if (!Strings.isNullOrEmpty(journalIds) && (journalIds.split(",").length) == 1) {
journal = Beans.get(JournalRepository.class).find(Long.parseLong(journalIds));
}
return journal;
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class BankOrderMoveServiceImpl method generateReceiverMove.
protected Move generateReceiverMove(BankOrderLine bankOrderLine) throws AxelorException {
Partner partner = bankOrderLine.getPartner();
Company receiverCompany = bankOrderLine.getReceiverCompany();
BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
Journal receiverJournal = paymentModeService.getPaymentModeJournal(paymentMode, receiverCompany, receiverBankDetails);
Account receiverBankAccount = paymentModeService.getPaymentModeAccount(paymentMode, receiverCompany, receiverBankDetails);
Move receiverMove = moveService.getMoveCreateService().createMove(receiverJournal, receiverCompany, this.getCurrency(bankOrderLine), partner, this.getDate(bankOrderLine), paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine bankMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, receiverBankAccount, bankOrderLine.getBankOrderAmount(), isDebit, receiverMove.getDate(), 1, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
receiverMove.addMoveLineListItem(bankMoveLine);
MoveLine partnerMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, getPartnerAccount(partner, receiverCompany, receiverMove.getCompany()), bankOrderLine.getBankOrderAmount(), !isDebit, receiverMove.getDate(), 2, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
receiverMove.addMoveLineListItem(partnerMoveLine);
return receiverMove;
}
use of com.axelor.apps.account.db.Journal 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.account.db.Journal 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.account.db.Journal in project axelor-open-suite by axelor.
the class InvoicePaymentValidateServiceImpl method createMoveForInvoicePayment.
/**
* Method to create a payment move for an invoice Payment
*
* <p>Create a move and reconcile it with the invoice move
*
* @param invoicePayment An invoice payment
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createMoveForInvoicePayment(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
Company company = invoice.getCompany();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Partner partner = invoice.getPartner();
LocalDate paymentDate = invoicePayment.getPaymentDate();
BigDecimal paymentAmount = invoicePayment.getAmount();
BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails();
Account customerAccount;
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
boolean isDebitInvoice = moveService.getMoveToolService().isDebitCustomer(invoice, true);
MoveLine invoiceMoveLine = moveService.getMoveToolService().getInvoiceCustomerMoveLineByLoop(invoice);
if (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
customerAccount = accountConfigService.getAdvancePaymentAccount(accountConfig);
} else {
if (invoiceMoveLine == null) {
return null;
}
customerAccount = invoiceMoveLine.getAccount();
}
String origin = invoicePayment.getInvoice().getInvoiceId();
if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_CHEQUE || invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_IPO_CHEQUE) {
origin = invoicePayment.getChequeNumber() != null ? invoicePayment.getChequeNumber() : origin;
} else if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_BANK_CARD) {
origin = invoicePayment.getInvoicePaymentRef() != null ? invoicePayment.getInvoicePaymentRef() : origin;
}
if (invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
origin = invoicePayment.getInvoice().getSupplierInvoiceNb();
}
Move move = moveService.getMoveCreateService().createMove(journal, company, invoicePayment.getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.setTradingName(invoice.getTradingName());
move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, isDebitInvoice, paymentDate, null, 1, origin, invoicePayment.getDescription()));
MoveLine customerMoveLine = moveLineService.createMoveLine(move, partner, customerAccount, paymentAmount, !isDebitInvoice, paymentDate, null, 2, origin, invoicePayment.getDescription());
move.addMoveLineListItem(customerMoveLine);
moveService.getMoveValidateService().validate(move);
if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
Reconcile reconcile = reconcileService.reconcile(invoiceMoveLine, customerMoveLine, true, false);
invoicePayment.setReconcile(reconcile);
}
invoicePayment.setMove(move);
invoicePaymentRepository.save(invoicePayment);
return invoicePayment;
}
Aggregations