use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursementMove.
/**
* Methode permettant de créer l'écriture de remboursement
*
* @param reimbursement Un objet d'export des prélèvements
* @throws AxelorException
*/
public void createReimbursementMove(Reimbursement reimbursement, Company company) throws AxelorException {
reimbursement = reimbursementRepo.find(reimbursement.getId());
Partner partner = null;
Move newMove = null;
boolean first = true;
AccountConfig accountConfig = company.getAccountConfig();
if (reimbursement.getMoveLineSet() != null && !reimbursement.getMoveLineSet().isEmpty()) {
int seq = 1;
for (MoveLine moveLine : reimbursement.getMoveLineSet()) {
BigDecimal amountRemaining = moveLine.getAmountRemaining();
if (amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
partner = moveLine.getPartner();
// On passe les lignes d'écriture (trop perçu) à l'état 'remboursé'
moveLine.setReimbursementStatusSelect(MoveLineRepository.REIMBURSEMENT_STATUS_REIMBURSED);
if (first) {
newMove = moveService.getMoveCreateService().createMove(accountConfig.getReimbursementJournal(), company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
first = false;
}
// Création d'une ligne au débit
MoveLine newDebitMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, true, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
newMove.getMoveLineList().add(newDebitMoveLine);
if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
newDebitMoveLine.setDescription(reimbursement.getDescription());
}
seq++;
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(newDebitMoveLine, moveLine, amountRemaining, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
}
// Création de la ligne au crédit
MoveLine newCreditMoveLine = moveLineService.createMoveLine(newMove, partner, accountConfig.getReimbursementAccount(), reimbursement.getAmountReimbursed(), false, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
newMove.getMoveLineList().add(newCreditMoveLine);
if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
newCreditMoveLine.setDescription(reimbursement.getDescription());
}
moveService.getMoveValidateService().validate(newMove);
moveRepo.save(newMove);
}
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method isBalanced.
@Override
public boolean isBalanced(List<Reconcile> reconcileList) {
List<MoveLine> debitMoveLineList = reconcileList.stream().map(Reconcile::getDebitMoveLine).distinct().collect(Collectors.toList());
List<MoveLine> creditMoveLineList = reconcileList.stream().map(Reconcile::getCreditMoveLine).distinct().collect(Collectors.toList());
List<Account> accountList = debitMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList());
accountList.addAll(creditMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList()));
for (Account account : accountList) {
BigDecimal totalDebit = debitMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getDebit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
BigDecimal totalCredit = creditMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getCredit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
if (totalDebit.compareTo(totalCredit) != 0) {
return false;
}
}
return true;
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method unletter.
@Override
@Transactional(rollbackOn = { Exception.class })
public void unletter(ReconcileGroup reconcileGroup) throws AxelorException {
List<Reconcile> reconcileList = this.getReconcileList(reconcileGroup);
for (Reconcile reconcile : reconcileList) {
reconcileService.unreconcile(reconcile);
}
reconcileGroup.setUnletteringDate(appBaseService.getTodayDate(reconcileGroup.getCompany()));
reconcileGroup.setStatusSelect(ReconcileGroupRepository.STATUS_UNLETTERED);
reconcileGroupRepository.save(reconcileGroup);
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class ReconcileServiceImpl method createReconcile.
/**
* Permet de créer une réconciliation en passant les paramètres qu'il faut
*
* @param lineDebit Une ligne d'écriture au débit
* @param lineCredit Une ligne d'écriture au crédit
* @param amount Le montant à reconciler
* @param canBeZeroBalanceOk Peut être soldé?
* @return Une reconciliation
*/
@Transactional
public Reconcile createReconcile(MoveLine debitMoveLine, MoveLine creditMoveLine, BigDecimal amount, boolean canBeZeroBalanceOk) {
if (ReconcileService.isReconcilable(debitMoveLine, creditMoveLine) && amount.compareTo(BigDecimal.ZERO) > 0) {
log.debug("Create Reconcile (Company : {}, Debit MoveLine : {}, Credit MoveLine : {}, Amount : {}, Can be zero balance ? {} )", debitMoveLine.getMove().getCompany(), debitMoveLine.getName(), creditMoveLine.getName(), amount, canBeZeroBalanceOk);
Reconcile reconcile = new Reconcile(debitMoveLine.getMove().getCompany(), amount.setScale(2, RoundingMode.HALF_UP), debitMoveLine, creditMoveLine, ReconcileRepository.STATUS_DRAFT, canBeZeroBalanceOk);
if (!moveToolService.isDebitMoveLine(debitMoveLine)) {
reconcile.setDebitMoveLine(creditMoveLine);
reconcile.setCreditMoveLine(debitMoveLine);
}
return reconcileRepository.save(reconcile);
}
return null;
}
use of com.axelor.apps.account.db.Reconcile in project axelor-open-suite by axelor.
the class DoubtfulCustomerService method createDoubtFulCustomerMove.
/**
* Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
* de facture
*
* @param move Une écritures de facture
* @param doubtfulCustomerAccount Un compte client douteux
* @param debtPassReason Un motif de passage en client douteux
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createDoubtFulCustomerMove(Move move, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
log.debug("Concerned account move : {} ", move.getReference());
Company company = move.getCompany();
Partner partner = move.getPartner();
Invoice invoice = move.getInvoice();
Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, invoice.getCurrency(), partner, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, move.getFunctionalOriginSelect());
newMove.setInvoice(invoice);
LocalDate todayDate = appBaseService.getTodayDate(company);
MoveLine invoicePartnerMoveLine = null;
for (MoveLine moveLine : move.getMoveLineList()) {
if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getAccount() != doubtfulCustomerAccount && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
invoicePartnerMoveLine = moveLine;
}
}
String origin = "";
BigDecimal amountRemaining = BigDecimal.ZERO;
MoveLine creditMoveLine = null;
if (invoicePartnerMoveLine != null) {
amountRemaining = invoicePartnerMoveLine.getAmountRemaining();
// Debit move line on partner account
creditMoveLine = moveLineService.createMoveLine(newMove, partner, invoicePartnerMoveLine.getAccount(), amountRemaining, false, todayDate, 1, move.getInvoice().getInvoiceId(), debtPassReason);
newMove.getMoveLineList().add(creditMoveLine);
origin = creditMoveLine.getOrigin();
}
// Credit move line on partner account
MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, partner, doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, origin, debtPassReason);
newMove.getMoveLineList().add(debitMoveLine);
debitMoveLine.setPassageReason(debtPassReason);
moveService.getMoveValidateService().validate(newMove);
moveRepo.save(newMove);
if (creditMoveLine != null) {
Reconcile reconcile = reconcileService.createReconcile(invoicePartnerMoveLine, creditMoveLine, amountRemaining, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
this.invoiceProcess(newMove, doubtfulCustomerAccount, debtPassReason);
}
Aggregations