use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class PaymentServiceImpl method createExcessPaymentWithAmount.
/**
* Il crée des écritures de trop percu avec des montants exacts pour chaque débitMoveLines avec le
* compte du débitMoveLines. A la fin, si il reste un trop-percu alors créer un trop-perçu
* classique.
*
* @param debitMoveLines Les lignes d'écriture à payer
* @param remainingPaidAmount Le montant restant à payer
* @param move Une écriture
* @param moveLineNo Un numéro de ligne d'écriture
* @return
* @throws AxelorException
*/
@Override
public int createExcessPaymentWithAmount(List<MoveLine> debitMoveLines, BigDecimal remainingPaidAmount, Move move, int moveLineNo, Partner partner, Company company, PayVoucherElementToPay payVoucherElementToPay, Account account, LocalDate paymentDate) throws AxelorException {
log.debug("In createExcessPaymentWithAmount");
int moveLineNo2 = moveLineNo;
BigDecimal remainingPaidAmount2 = remainingPaidAmount;
List<Reconcile> reconcileList = new ArrayList<Reconcile>();
int i = debitMoveLines.size();
for (MoveLine debitMoveLine : debitMoveLines) {
i--;
BigDecimal amountRemaining = debitMoveLine.getAmountRemaining();
// Afin de pouvoir arrêter si il n'y a plus rien pour payer
if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) <= 0) {
break;
}
BigDecimal amountToPay = remainingPaidAmount2.min(amountRemaining);
String invoiceName = "";
if (debitMoveLine.getMove().getInvoice() != null) {
invoiceName = debitMoveLine.getMove().getInvoice().getInvoiceId();
} else {
invoiceName = payVoucherElementToPay.getPaymentVoucher().getRef();
}
MoveLine creditMoveLine = moveLineService.createMoveLine(move, debitMoveLine.getPartner(), debitMoveLine.getAccount(), amountToPay, false, appAccountService.getTodayDate(company), moveLineNo2, invoiceName, null);
move.getMoveLineList().add(creditMoveLine);
// Utiliser uniquement dans le cas du paiemnt des échéances lors d'une saisie paiement
if (payVoucherElementToPay != null) {
creditMoveLine.setPaymentScheduleLine(payVoucherElementToPay.getMoveLine().getPaymentScheduleLine());
payVoucherElementToPay.setMoveLineGenerated(creditMoveLine);
}
moveLineNo2++;
Reconcile reconcile = null;
// Gestion du passage en 580
if (i == 0) {
log.debug("last loop");
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, true);
} else {
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, false);
}
if (reconcile != null) {
reconcileList.add(reconcile);
remainingPaidAmount2 = remainingPaidAmount2.subtract(amountRemaining);
}
}
for (Reconcile reconcile : reconcileList) {
reconcileService.confirmReconcile(reconcile, true);
}
// Si il y a un restant à payer, alors on crée un trop-perçu.
if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) > 0) {
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, remainingPaidAmount2, false, appAccountService.getTodayDate(company), moveLineNo2, null, null);
move.getMoveLineList().add(moveLine);
moveLineNo2++;
// Gestion du passage en 580
reconcileService.balanceCredit(moveLine);
}
log.debug("End createExcessPaymentWithAmount");
return moveLineNo2;
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class InvoicePaymentCancelServiceImpl method cancel.
/**
* Method to cancel an invoice Payment
*
* <p>Cancel the eventual Move and Reconcile Compute the total amount paid on the linked invoice
* Change the status to cancel
*
* @param invoicePayment An invoice payment
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void cancel(InvoicePayment invoicePayment) throws AxelorException {
Move paymentMove = invoicePayment.getMove();
Reconcile reconcile = invoicePayment.getReconcile();
log.debug("cancel : reconcile : {}", reconcile);
if (reconcile != null && reconcile.getStatusSelect() == ReconcileRepository.STATUS_CONFIRMED) {
reconcileService.unreconcile(reconcile);
}
if (paymentMove != null && invoicePayment.getTypeSelect() == InvoicePaymentRepository.TYPE_PAYMENT) {
invoicePayment.setMove(null);
moveCancelService.cancel(paymentMove);
} else {
this.updateCancelStatus(invoicePayment);
}
}
use of com.axelor.apps.account.db.Reconcile 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;
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class ReconcileController method reconcile.
// Reconcile button
public void reconcile(ActionRequest request, ActionResponse response) {
Reconcile reconcile = request.getContext().asType(Reconcile.class);
try {
Beans.get(ReconcileService.class).confirmReconcile(Beans.get(ReconcileRepository.class).find(reconcile.getId()), true);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class AccountClearanceService method createAccountClearanceMove.
public Move createAccountClearanceMove(MoveLine moveLine, BigDecimal taxRate, Account taxAccount, Account profitAccount, Company company, Journal journal, AccountClearance accountClearance) throws AxelorException {
Partner partner = moveLine.getPartner();
// Move
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
// Debit MoveLine 411
BigDecimal amount = moveLine.getAmountRemaining();
MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), amount, true, appBaseService.getTodayDateTime().toLocalDate(), 1, null, null);
move.getMoveLineList().add(debitMoveLine);
// Credit MoveLine 77. (profit account)
BigDecimal divid = taxRate.add(BigDecimal.ONE);
BigDecimal profitAmount = amount.divide(divid, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, partner, profitAccount, profitAmount, false, appBaseService.getTodayDateTime().toLocalDate(), 2, null, null);
move.getMoveLineList().add(creditMoveLine1);
// Credit MoveLine 445 (Tax account)
BigDecimal taxAmount = amount.subtract(profitAmount);
MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, partner, taxAccount, taxAmount, false, appBaseService.getTodayDateTime().toLocalDate(), 3, null, null);
move.getMoveLineList().add(creditMoveLine2);
Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, moveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
debitMoveLine.setAccountClearance(accountClearance);
creditMoveLine1.setAccountClearance(accountClearance);
creditMoveLine2.setAccountClearance(accountClearance);
return move;
}
Aggregations