use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveRemoveService method updateSystem.
protected void updateSystem(Move move) throws Exception {
for (MoveLine moveLine : move.getMoveLineList()) {
if (moveLine.getPartner() != null) {
accountCustomerService.updateAccountingSituationCustomerAccount(accountingSituationService.getAccountingSituation(moveLine.getPartner(), move.getCompany()), true, true, true);
accountingSituationService.updateCustomerCredit(moveLine.getPartner());
}
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveServiceImpl method generateReverse.
@Transactional(rollbackOn = { Exception.class })
@Override
public Move generateReverse(Move move, boolean isAutomaticReconcile, boolean isAutomaticAccounting, boolean isUnreconcileOriginalMove, LocalDate dateOfReversion) throws AxelorException {
Move newMove = moveCreateService.createMove(move.getJournal(), move.getCompany(), move.getCurrency(), move.getPartner(), dateOfReversion, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_ENTRY, move.getFunctionalOriginSelect(), move.getIgnoreInDebtRecoveryOk(), move.getIgnoreInAccountingOk(), move.getAutoYearClosureMove());
move.setInvoice(move.getInvoice());
move.setPaymentVoucher(move.getPaymentVoucher());
boolean validatedMove = move.getStatusSelect() == MoveRepository.STATUS_ACCOUNTED || move.getStatusSelect() == MoveRepository.STATUS_VALIDATED;
for (MoveLine moveLine : move.getMoveLineList()) {
log.debug("Moveline {}", moveLine);
Boolean isDebit = moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0;
MoveLine newMoveLine = generateReverseMoveLine(newMove, moveLine, dateOfReversion, isDebit);
if (moveLine.getAnalyticDistributionTemplate() != null) {
newMoveLine.setAnalyticDistributionTemplate(moveLine.getAnalyticDistributionTemplate());
List<AnalyticMoveLine> analyticMoveLineList = Beans.get(AnalyticMoveLineService.class).generateLines(newMoveLine.getAnalyticDistributionTemplate(), newMoveLine.getDebit().add(newMoveLine.getCredit()), AnalyticMoveLineRepository.STATUS_REAL_ACCOUNTING, dateOfReversion);
if (CollectionUtils.isNotEmpty(analyticMoveLineList)) {
analyticMoveLineList.forEach(analyticMoveLine -> newMoveLine.addAnalyticMoveLineListItem(analyticMoveLine));
}
}
newMove.addMoveLineListItem(newMoveLine);
if (isUnreconcileOriginalMove) {
List<Reconcile> reconcileList = Beans.get(ReconcileRepository.class).all().filter("self.statusSelect != ?1 AND (self.debitMoveLine = ?2 OR self.creditMoveLine = ?2)", ReconcileRepository.STATUS_CANCELED, moveLine).fetch();
for (Reconcile reconcile : reconcileList) {
reconcileService.unreconcile(reconcile);
}
}
if (validatedMove && isAutomaticReconcile) {
if (isDebit) {
reconcileService.reconcile(moveLine, newMoveLine, false, true);
} else {
reconcileService.reconcile(newMoveLine, moveLine, false, true);
}
}
}
if (validatedMove && isAutomaticAccounting) {
moveValidateService.validate(newMove);
}
return moveRepository.save(newMove);
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMoveUseDebit.
@Override
public Move createMoveUseDebit(Invoice invoice, List<MoveLine> debitMoveLines, MoveLine invoiceCustomerMoveLine) throws AxelorException {
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
Account account = invoice.getPartnerAccount();
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfigService.getAccountConfig(company));
log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
BigDecimal remainingAmount = invoice.getInTaxTotal().abs();
log.debug("Montant à payer avec l'avoir récupéré : {}", remainingAmount);
Move oDmove = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
if (oDmove != null) {
BigDecimal totalDebitAmount = moveToolService.getTotalDebitAmount(debitMoveLines);
BigDecimal amount = totalDebitAmount.min(invoiceCustomerMoveLine.getCredit());
// Création de la ligne au débit
MoveLine debitMoveLine = moveLineService.createMoveLine(oDmove, partner, account, amount, true, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
oDmove.getMoveLineList().add(debitMoveLine);
// Emploie des dûs sur les lignes de credit qui seront créées au fil de l'eau
paymentService.createExcessPaymentWithAmount(debitMoveLines, amount, oDmove, 2, partner, company, null, account, appAccountService.getTodayDate(company));
moveValidateService.validate(oDmove);
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, invoiceCustomerMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
return oDmove;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMoveUseExcessPayment.
@Override
public void createMoveUseExcessPayment(Invoice invoice) throws AxelorException {
Company company = invoice.getCompany();
// Récupération des acomptes de la facture
List<MoveLine> creditMoveLineList = moveExcessPaymentService.getAdvancePaymentMoveList(invoice);
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
// Récupération des trop-perçus
creditMoveLineList.addAll(moveExcessPaymentService.getExcessPayment(invoice));
if (creditMoveLineList != null && creditMoveLineList.size() != 0) {
Partner partner = invoice.getPartner();
Account account = invoice.getPartnerAccount();
MoveLine invoiceCustomerMoveLine = moveToolService.getCustomerMoveLineByLoop(invoice);
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
// Si c'est le même compte sur les trop-perçus et sur la facture, alors on lettre directement
if (moveToolService.isSameAccount(creditMoveLineList, account)) {
List<MoveLine> debitMoveLineList = new ArrayList<MoveLine>();
debitMoveLineList.add(invoiceCustomerMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
} else // Sinon on créée une O.D. pour passer du compte de la facture à un autre compte sur les
// trop-perçus
{
log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
Move move = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
if (move != null) {
BigDecimal totalCreditAmount = moveToolService.getTotalCreditAmount(creditMoveLineList);
BigDecimal amount = totalCreditAmount.min(invoiceCustomerMoveLine.getDebit());
// Création de la ligne au crédit
MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, account, amount, false, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
move.getMoveLineList().add(creditMoveLine);
// Emploie des trop-perçus sur les lignes de debit qui seront créées au fil de l'eau
paymentService.useExcessPaymentWithAmountConsolidated(creditMoveLineList, amount, move, 2, partner, company, account, invoice.getInvoiceDate(), invoice.getDueDate());
moveValidateService.validate(move);
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(invoiceCustomerMoveLine, creditMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
}
invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
BigDecimal hundred = new BigDecimal(100);
for (HashMap<String, Object> data : dataList) {
LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
boolean isDebit = false;
Partner debitPartner = null;
Partner creditPartner = null;
BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
Partner partner = null;
if (data.get("debitPartner") != null) {
debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
partner = debitPartner;
}
if (data.get("creditPartner") != null) {
creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
partner = creditPartner;
}
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
partner = null;
if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
isDebit = true;
if (moveTemplateLine.getHasPartnerToDebit()) {
partner = debitPartner;
}
} else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
isDebit = false;
if (moveTemplateLine.getHasPartnerToCredit()) {
partner = creditPartner;
}
}
BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
Aggregations