use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableReportLineList.
/**
* Fonction permettant de créer une liste de ligne de reporting pour une ligne Facture
*
* @param iil Une ligne Facture
* @param invoice Une facture
* @param prorataRate Un taux de restant à payer d'une facture
* @return
*/
public List<IrrecoverableReportLine> createIrrecoverableReportLineList(IrrecoverableInvoiceLine iil, Invoice invoice, BigDecimal prorataRate) {
int seq = 1;
List<IrrecoverableReportLine> irlList = new ArrayList<IrrecoverableReportLine>();
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
irlList.add(this.createIrrecoverableReportLine(iil, invoiceLine.getName(), invoiceLine.getExTaxTotal().multiply(prorataRate).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP), seq));
seq++;
}
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
irlList.add(this.createIrrecoverableReportLine(iil, invoiceLineTax.getTaxLine().getTax().getName(), invoiceLineTax.getTaxTotal().multiply(prorataRate).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP), seq));
seq++;
}
// Afin de ne pas modifier les valeurs des lignes de factures, on les recharges depuis la base
invoiceRepo.refresh(invoice);
return irlList;
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class InvoiceGenerator method computeInvoice.
/**
* Compute the invoice total amounts
*
* @param invoice
* @throws AxelorException
*/
public void computeInvoice(Invoice invoice) throws AxelorException {
// In the invoice currency
invoice.setExTaxTotal(BigDecimal.ZERO);
invoice.setTaxTotal(BigDecimal.ZERO);
invoice.setInTaxTotal(BigDecimal.ZERO);
// In the company accounting currency
invoice.setCompanyExTaxTotal(BigDecimal.ZERO);
invoice.setCompanyTaxTotal(BigDecimal.ZERO);
invoice.setCompanyInTaxTotal(BigDecimal.ZERO);
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
if (invoiceLine.getTypeSelect() != InvoiceLineRepository.TYPE_NORMAL) {
continue;
}
// In the invoice currency
invoice.setExTaxTotal(invoice.getExTaxTotal().add(invoiceLine.getExTaxTotal()));
// In the company accounting currency
invoice.setCompanyExTaxTotal(invoice.getCompanyExTaxTotal().add(invoiceLine.getCompanyExTaxTotal()));
}
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
// In the invoice currency
invoice.setTaxTotal(invoice.getTaxTotal().add(invoiceLineTax.getTaxTotal()));
// In the company accounting currency
invoice.setCompanyTaxTotal(invoice.getCompanyTaxTotal().add(invoiceLineTax.getCompanyTaxTotal()));
}
// In the invoice currency
invoice.setInTaxTotal(invoice.getExTaxTotal().add(invoice.getTaxTotal()));
// In the company accounting currency
invoice.setCompanyInTaxTotal(invoice.getCompanyExTaxTotal().add(invoice.getCompanyTaxTotal()));
invoice.setAmountRemaining(invoice.getInTaxTotal());
invoice.setHasPendingPayments(false);
logger.debug("Invoice amounts : W.T. = {}, Tax = {}, A.T.I. = {}", new Object[] { invoice.getExTaxTotal(), invoice.getTaxTotal(), invoice.getInTaxTotal() });
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class TaxInvoiceLine method createOrUpdateInvoiceLineTax.
protected void createOrUpdateInvoiceLineTax(InvoiceLine invoiceLine, TaxLine taxLine, Map<TaxLine, InvoiceLineTax> map) {
LOG.debug("TVA {}", taxLine);
InvoiceLineTax invoiceLineTax = map.get(taxLine);
if (invoiceLineTax != null) {
updateInvoiceLineTax(invoiceLine, invoiceLineTax);
invoiceLineTax.setReverseCharged(false);
} else {
invoiceLineTax = createInvoiceLineTax(invoiceLine, taxLine);
invoiceLineTax.setReverseCharged(false);
map.put(taxLine, invoiceLineTax);
}
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class TaxInvoiceLine method createInvoiceLineTax.
protected InvoiceLineTax createInvoiceLineTax(InvoiceLine invoiceLine, TaxLine taxLine) {
InvoiceLineTax invoiceLineTax = new InvoiceLineTax();
invoiceLineTax.setInvoice(invoice);
// Dans la devise de la facture
invoiceLineTax.setExTaxBase(invoiceLine.getExTaxTotal());
// Dans la devise de la comptabilité du tiers
invoiceLineTax.setCompanyExTaxBase(invoiceLine.getCompanyExTaxTotal().setScale(2, RoundingMode.HALF_UP));
if (!invoiceLine.getFixedAssets()) {
invoiceLineTax.setSubTotalExcludingFixedAssets(invoiceLine.getExTaxTotal().setScale(2, RoundingMode.HALF_UP));
invoiceLineTax.setCompanySubTotalExcludingFixedAssets(invoiceLineTax.getCompanySubTotalExcludingFixedAssets().add(invoiceLine.getCompanyExTaxTotal()).setScale(2, RoundingMode.HALF_UP));
}
invoiceLineTax.setTaxLine(taxLine);
return invoiceLineTax;
}
use of com.axelor.apps.account.db.InvoiceLineTax 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;
}
Aggregations