use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class AccountingCloseAnnualServiceImpl method generateCloseAnnualAccountMove.
protected Move generateCloseAnnualAccountMove(Year year, Account account, LocalDate moveDate, LocalDate originDate, String origin, String moveDescription, Partner partner, boolean isReverse, boolean allocatePerPartner) throws AxelorException {
Company company = account.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
BigDecimal balance = computeBalance(year, account, partner, allocatePerPartner);
if (balance.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Integer functionalOriginSelect = null;
if (isReverse) {
balance = balance.negate();
functionalOriginSelect = MoveRepository.FUNCTIONAL_ORIGIN_OPENING;
} else {
functionalOriginSelect = MoveRepository.FUNCTIONAL_ORIGIN_CLOSURE;
}
Move move = moveCreateService.createMove(accountConfigService.getReportedBalanceJournal(accountConfig), company, company.getCurrency(), partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, functionalOriginSelect, false, false, !isReverse);
counter = 0;
this.generateCloseAnnualMoveLine(move, origin, account, moveDescription, originDate, balance.negate());
this.generateCloseAnnualMoveLine(move, origin, getYearClosureOrOpeningAccount(accountConfig, isReverse), moveDescription, originDate, balance);
if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
moveValidateService.validate(move);
} else {
moveRepository.remove(move);
return null;
}
return move;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveManagementRepository method copy.
@Override
public Move copy(Move entity, boolean deep) {
Move copy = super.copy(entity, deep);
copy.setDate(Beans.get(AppBaseService.class).getTodayDate(copy.getCompany()));
Period period = null;
try {
period = Beans.get(PeriodService.class).getActivePeriod(copy.getDate(), entity.getCompany(), YearRepository.TYPE_FISCAL);
} catch (AxelorException e) {
throw new PersistenceException(e.getMessage(), e);
}
copy.setStatusSelect(STATUS_NEW);
copy.setTechnicalOriginSelect(MoveRepository.TECHNICAL_ORIGIN_ENTRY);
copy.setReference(null);
copy.setExportNumber(null);
copy.setExportDate(null);
copy.setAccountingReport(null);
copy.setValidationDate(null);
copy.setPeriod(period);
copy.setAccountingOk(false);
copy.setIgnoreInDebtRecoveryOk(false);
copy.setPaymentVoucher(null);
copy.setRejectOk(false);
copy.setInvoice(null);
List<MoveLine> moveLineList = copy.getMoveLineList();
if (moveLineList != null) {
moveLineList.forEach(moveLine -> resetMoveLine(moveLine, copy.getDate()));
}
return copy;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.
@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
MoveService moveService = Beans.get(MoveService.class);
MoveRepository moveRepository = Beans.get(MoveRepository.class);
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
Company company = subrogationRelease.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
if (subrogationRelease.getAccountingDate() == null) {
subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
}
this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
boolean isRefund = false;
if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
isRefund = true;
}
LocalDate date = subrogationRelease.getAccountingDate();
Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine, debitMoveLine;
debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
move.addMoveLineListItem(debitMoveLine);
move.addMoveLineListItem(creditMoveLine);
move = moveRepository.save(move);
moveService.getMoveValidateService().validate(move);
invoice.setSubrogationRelease(subrogationRelease);
invoice.setSubrogationReleaseMove(move);
subrogationRelease.addMoveListItem(move);
}
subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableMove.
/**
* Fonction permettant de créer l'écriture de passage en irrécouvrable d'une échéance
*
* @param moveLine Une écriture d'échéance
* @return
* @throws AxelorException
*/
public Move createIrrecoverableMove(MoveLine moveLine, String irrecoverableName) throws AxelorException {
Company company = moveLine.getMove().getCompany();
Partner payerPartner = moveLine.getPartner();
BigDecimal amount = moveLine.getAmountRemaining();
AccountConfig accountConfig = company.getAccountConfig();
// Move
Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
int seq = 1;
// Credit MoveLine Customer account (411, 416, ...)
MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, moveLine.getAccount(), amount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine);
Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
Tax tax = accountConfig.getIrrecoverableStandardRateTax();
BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(company));
// Debit MoveLine 654. (irrecoverable account)
BigDecimal divid = taxRate.add(BigDecimal.ONE);
BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), irrecoverableAmount, true, appAccountService.getTodayDate(company), 2, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine1);
// Debit MoveLine 445 (Tax account)
Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, payerPartner, taxAccount, taxAmount, true, appAccountService.getTodayDate(company), 3, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine2);
return move;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableMove.
/**
* Fonction permettant de créer l'écriture de passage en irrécouvrable d'une facture
*
* @param invoice Une facture
* @param prorataRate Le taux de restant à payer sur la facture
* @param isInvoiceReject La facture est-elle rejetée?
* @return
* @throws AxelorException
*/
public Move createIrrecoverableMove(Invoice invoice, BigDecimal prorataRate, boolean isInvoiceReject, String irrecoverableName) throws AxelorException {
Company company = invoice.getCompany();
Partner payerPartner = invoice.getPartner();
AccountConfig accountConfig = company.getAccountConfig();
// Move
Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_SALE);
int seq = 1;
BigDecimal amount = BigDecimal.ZERO;
MoveLine debitMoveLine = null;
BigDecimal creditAmount = null;
BigDecimal debitAmount = null;
if (isInvoiceReject) {
creditAmount = invoice.getRejectMoveLine().getAmountRemaining();
debitAmount = creditAmount;
} else {
creditAmount = invoice.getCompanyInTaxTotalRemaining();
debitAmount = creditAmount;
}
// Debits MoveLines Tva
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
amount = (invoiceLineTax.getTaxTotal().multiply(prorataRate)).setScale(2, RoundingMode.HALF_UP);
// do not generate move line with amount equal to zero
if (amount.signum() == 0) {
continue;
}
debitMoveLine = moveLineService.createMoveLine(move, payerPartner, taxAccountService.getAccount(invoiceLineTax.getTaxLine().getTax(), company, false, false), amount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(debitMoveLine);
seq++;
debitAmount = debitAmount.subtract(amount);
}
// Debit MoveLine 654 (irrecoverable account)
debitMoveLine = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), debitAmount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(debitMoveLine);
seq++;
// Getting customer MoveLine from Facture
MoveLine customerMoveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
if (customerMoveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
}
customerMoveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
// Credit MoveLine Customer account (411, 416, ...)
MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, customerMoveLine.getAccount(), creditAmount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(creditMoveLine);
Reconcile reconcile = reconcileService.createReconcile(customerMoveLine, creditMoveLine, creditAmount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
return move;
}
Aggregations