use of com.axelor.apps.account.db.Tax in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method createMoveLines.
/**
* Créer les lignes d'écritures comptables d'une facture.
*
* @param invoice
* @param move
* @param consolidate
* @return
*/
@Override
public List<MoveLine> createMoveLines(Invoice invoice, Move move, Company company, Partner partner, Account partnerAccount, boolean consolidate, boolean isPurchase, boolean isDebitCustomer) throws AxelorException {
log.debug("Création des lignes d'écriture comptable de la facture/l'avoir {}", invoice.getInvoiceId());
List<MoveLine> moveLines = new ArrayList<MoveLine>();
Set<AnalyticAccount> analyticAccounts = new HashSet<AnalyticAccount>();
int moveLineId = 1;
if (partner == null) {
throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_1), invoice.getInvoiceId());
}
if (partnerAccount == null) {
throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_2), invoice.getInvoiceId());
}
String origin = invoice.getInvoiceId();
if (InvoiceToolService.isPurchase(invoice)) {
origin = invoice.getSupplierInvoiceNb();
}
// Creation of partner move line
MoveLine moveLine1 = this.createMoveLine(move, partner, partnerAccount, invoice.getInTaxTotal(), invoice.getCompanyInTaxTotal(), null, isDebitCustomer, invoice.getInvoiceDate(), invoice.getDueDate(), invoice.getOriginDate(), moveLineId++, origin, null);
moveLines.add(moveLine1);
AnalyticMoveLineRepository analyticMoveLineRepository = Beans.get(AnalyticMoveLineRepository.class);
// Creation of product move lines for each invoice line
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
BigDecimal companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
if (companyExTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
analyticAccounts.clear();
Account account = invoiceLine.getAccount();
if (account == null) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_4), invoiceLine.getName(), company.getName());
}
companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
log.debug("Traitement de la ligne de facture : compte comptable = {}, montant = {}", new Object[] { account.getName(), companyExTaxTotal });
if (invoiceLine.getAnalyticDistributionTemplate() == null && (invoiceLine.getAnalyticMoveLineList() == null || invoiceLine.getAnalyticMoveLineList().isEmpty()) && account.getAnalyticDistributionAuthorized() && account.getAnalyticDistributionRequiredOnInvoiceLines()) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ANALYTIC_DISTRIBUTION_MISSING), invoiceLine.getName(), company.getName());
}
MoveLine moveLine = this.createMoveLine(move, partner, account, invoiceLine.getExTaxTotal(), companyExTaxTotal, null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, invoiceLine.getProductName());
moveLine.setAnalyticDistributionTemplate(invoiceLine.getAnalyticDistributionTemplate());
if (invoiceLine.getAnalyticMoveLineList() != null && !invoiceLine.getAnalyticMoveLineList().isEmpty()) {
for (AnalyticMoveLine invoiceAnalyticMoveLine : invoiceLine.getAnalyticMoveLineList()) {
AnalyticMoveLine analyticMoveLine = analyticMoveLineRepository.copy(invoiceAnalyticMoveLine, false);
analyticMoveLine.setTypeSelect(AnalyticMoveLineRepository.STATUS_REAL_ACCOUNTING);
analyticMoveLine.setInvoiceLine(null);
analyticMoveLine.setAccount(moveLine.getAccount());
analyticMoveLine.setAccountType(moveLine.getAccount().getAccountType());
analyticMoveLineService.updateAnalyticMoveLine(analyticMoveLine, moveLine.getDebit().add(moveLine.getCredit()), moveLine.getDate());
moveLine.addAnalyticMoveLineListItem(analyticMoveLine);
}
} else {
generateAnalyticMoveLines(moveLine);
}
TaxLine taxLine = invoiceLine.getTaxLine();
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(taxLine.getTax().getCode());
}
moveLines.add(moveLine);
}
}
// Creation of tax move lines for each invoice line tax
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
BigDecimal companyTaxTotal = invoiceLineTax.getCompanyTaxTotal();
if (companyTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
Tax tax = invoiceLineTax.getTaxLine().getTax();
boolean hasFixedAssets = !invoiceLineTax.getSubTotalOfFixedAssets().equals(BigDecimal.ZERO);
boolean hasOtherAssets = !invoiceLineTax.getSubTotalExcludingFixedAssets().equals(BigDecimal.ZERO);
Account account;
MoveLine moveLine;
if (hasFixedAssets && invoiceLineTax.getCompanySubTotalOfFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
account = taxAccountService.getAccount(tax, company, isPurchase, true);
if (account == null) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
}
moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalOfFixedAssets(), invoiceLineTax.getCompanySubTotalOfFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
moveLine.setTaxLine(invoiceLineTax.getTaxLine());
moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
moveLine.setTaxCode(tax.getCode());
moveLines.add(moveLine);
}
if (hasOtherAssets && invoiceLineTax.getCompanySubTotalExcludingFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
account = taxAccountService.getAccount(tax, company, isPurchase, false);
if (account == null) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
}
moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalExcludingFixedAssets(), invoiceLineTax.getCompanySubTotalExcludingFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
moveLine.setTaxLine(invoiceLineTax.getTaxLine());
moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
moveLine.setTaxCode(tax.getCode());
moveLines.add(moveLine);
}
}
}
if (consolidate) {
this.consolidateMoveLines(moveLines);
}
return moveLines;
}
use of com.axelor.apps.account.db.Tax 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;
}
use of com.axelor.apps.account.db.Tax in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, 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;
}
use of com.axelor.apps.account.db.Tax in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateTaxMoveLine.
protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
TaxLine taxLine = productMoveLine.getTaxLine();
Tax tax = taxLine.getTax();
Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
taxMoveLine.setDate(move.getDate());
taxMoveLine.setDueDate(move.getDate());
move.addMoveLineListItem(taxMoveLine);
}
use of com.axelor.apps.account.db.Tax 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;
}
Aggregations