use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ChequeRejectionService method createChequeRejectionMove.
/**
* Méthode permettant de créer une écriture de rejet de chèque (L'extourne de l'écriture de
* paiement)
*
* @param chequeRejection Un rejet de cheque brouillon
* @param company Une société
* @return L'écriture de rejet de chèque
* @throws AxelorException
*/
public Move createChequeRejectionMove(ChequeRejection chequeRejection, Company company) throws AxelorException {
this.testCompanyField(company);
Journal journal = company.getAccountConfig().getRejectJournal();
PaymentVoucher paymentVoucher = chequeRejection.getPaymentVoucher();
Move paymentMove = paymentVoucher.getGeneratedMove();
Partner partner = paymentVoucher.getPartner();
InterbankCodeLine interbankCodeLine = chequeRejection.getInterbankCodeLine();
String description = chequeRejection.getDescription();
LocalDate rejectionDate = chequeRejection.getRejectionDate();
// Move
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, rejectionDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
int ref = 1;
for (MoveLine moveLine : paymentMove.getMoveLineList()) {
if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
// Debit MoveLine
MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getCredit(), true, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
move.getMoveLineList().add(debitMoveLine);
debitMoveLine.setInterbankCodeLine(interbankCodeLine);
debitMoveLine.setDescription(description);
} else {
// Credit MoveLine
MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getDebit(), false, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
move.getMoveLineList().add(creditMoveLine);
creditMoveLine.setInterbankCodeLine(interbankCodeLine);
creditMoveLine.setDescription(description);
}
ref++;
}
move.setRejectOk(true);
moveService.getMoveValidateService().validate(move);
return move;
}
use of com.axelor.apps.account.db.MoveLine 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);
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class DoubtfulCustomerService method updateDoubtfulCustomerMove.
/**
* Procédure permettant de mettre à jour le motif de passage en client douteux, et créer
* l'évènement lié.
*
* @param moveList Une liste d'éciture de facture
* @param doubtfulCustomerAccount Un compte client douteux
* @param debtPassReason Un motif de passage en client douteux
*/
public void updateDoubtfulCustomerMove(List<Move> moveList, Account doubtfulCustomerAccount, String debtPassReason) {
for (Move move : moveList) {
for (MoveLine moveLine : move.getMoveLineList()) {
if (moveLine.getAccount().equals(doubtfulCustomerAccount) && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
moveLine.setPassageReason(debtPassReason);
moveLineRepo.save(moveLine);
break;
}
}
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class BatchDoubtfulCustomer method createDoubtFulCustomerRejectMove.
/**
* Procédure permettant de créer les écritures de passage en client douteux pour chaque ligne
* d'écriture de rejet de facture
*
* @param moveLineList Une liste de lignes d'écritures de rejet de facture
* @param doubtfulCustomerAccount Un compte client douteux
* @param debtPassReason Un motif de passage en client douteux
* @throws AxelorException
*/
public void createDoubtFulCustomerRejectMove(List<MoveLine> moveLineList, Account doubtfulCustomerAccount, String debtPassReason) {
int i = 0;
for (MoveLine moveLine : moveLineList) {
try {
doubtfulCustomerService.createDoubtFulCustomerRejectMove(moveLineRepo.find(moveLine.getId()), accountRepo.find(doubtfulCustomerAccount.getId()), debtPassReason);
updateInvoice(moveLineRepo.find(moveLine.getId()).getInvoiceReject());
i++;
} catch (AxelorException e) {
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Invoice") + " %s", moveLine.getInvoiceReject().getInvoiceId()), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
incrementAnomaly();
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("Invoice") + " %s", moveLine.getInvoiceReject().getInvoiceId()), e), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
incrementAnomaly();
log.error("Bug(Anomalie) généré(e) pour la facture {}", moveLineRepo.find(moveLine.getId()).getInvoiceReject().getInvoiceId());
} finally {
if (i % 10 == 0) {
JPA.clear();
}
}
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class BatchDoubtfulCustomer method process.
@SuppressWarnings("unchecked")
@Override
protected void process() {
if (!end) {
Company company = batch.getAccountingBatch().getCompany();
AccountConfig accountConfig = company.getAccountConfig();
Account doubtfulCustomerAccount = accountConfig.getDoubtfulCustomerAccount();
String sixMonthDebtPassReason = accountConfig.getSixMonthDebtPassReason();
String threeMonthDebtPassReason = accountConfig.getThreeMonthDebtPassReason();
// FACTURES
List<Move> moveList = doubtfulCustomerService.getMove(0, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 6 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveList = doubtfulCustomerService.getMove(1, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 3 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, threeMonthDebtPassReason);
// FACTURES REJETES
List<MoveLine> moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(0, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 6 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(1, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 3 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, threeMonthDebtPassReason);
updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(companyRepo.find(company.getId()));
}
}
Aggregations