use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoInvoiceLine.
protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
Invoice intercoInvoice = invoiceLine.getInvoice();
Partner partner = intercoInvoice.getPartner();
if (intercoInvoice.getCompany() != null) {
Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
invoiceLine.setAccount(account);
TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
if (invoiceLine.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
}
}
return invoiceLine;
}
use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method computeAnalyticDistribution.
@Override
public MoveLine computeAnalyticDistribution(MoveLine moveLine) {
List<AnalyticMoveLine> analyticMoveLineList = moveLine.getAnalyticMoveLineList();
if ((analyticMoveLineList == null || analyticMoveLineList.isEmpty())) {
createAnalyticDistributionWithTemplate(moveLine);
} else {
LocalDate date = moveLine.getDate();
BigDecimal amount = moveLine.getDebit().add(moveLine.getCredit());
for (AnalyticMoveLine analyticMoveLine : analyticMoveLineList) {
analyticMoveLineService.updateAnalyticMoveLine(analyticMoveLine, amount, date);
}
}
updateAccountTypeOnAnalytic(moveLine, analyticMoveLineList);
return moveLine;
}
use of com.axelor.apps.account.db.AnalyticMoveLine 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.AnalyticMoveLine 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.AnalyticMoveLine in project axelor-open-suite by axelor.
the class AnalyticDistributionLineController method computeAmount.
public void computeAmount(ActionRequest request, ActionResponse response) {
AnalyticMoveLine analyticMoveLine = request.getContext().asType(AnalyticMoveLine.class);
response.setValue("amount", Beans.get(AnalyticMoveLineService.class).computeAmount(analyticMoveLine));
}
Aggregations