use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method createAndSetMove.
protected Move createAndSetMove(Expense expense) throws AxelorException {
LocalDate moveDate = expense.getMoveDate();
if (moveDate == null) {
moveDate = appAccountService.getTodayDate(expense.getCompany());
expense.setMoveDate(moveDate);
}
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
Account account = null;
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
if (partner == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
}
Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
List<MoveLine> moveLines = new ArrayList<>();
Set<AnalyticAccount> analyticAccounts = new HashSet<>();
BigDecimal exTaxTotal = null;
int moveLineId = 1;
int expenseLineId = 1;
Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
analyticAccounts.clear();
Product product = expenseLine.getExpenseProduct();
account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
if (account == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
}
exTaxTotal = expenseLine.getUntaxedAmount();
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
analyticDistributionLine.setExpenseLine(null);
moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
}
moveLines.add(moveLine);
expenseLineId++;
}
moveLineService.consolidateMoveLines(moveLines);
account = accountConfigService.getExpenseTaxAccount(accountConfig);
BigDecimal taxTotal = BigDecimal.ZERO;
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
exTaxTotal = expenseLine.getTotalTax();
taxTotal = taxTotal.add(exTaxTotal);
}
if (taxTotal.signum() != 0) {
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
moveLines.add(moveLine);
}
move.getMoveLineList().addAll(moveLines);
moveService.getMoveValidateService().validate(move);
expense.setMove(move);
return move;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method reconcile.
protected void reconcile(Move move, Move reverseMove) throws AxelorException {
List<MoveLine> moveLineSortedList = move.getMoveLineList();
Collections.sort(moveLineSortedList, Comparator.comparing(MoveLine::getCounter));
List<MoveLine> reverseMoveLineSortedList = reverseMove.getMoveLineList();
Collections.sort(reverseMoveLineSortedList, Comparator.comparing(MoveLine::getCounter));
Iterator<MoveLine> reverseMoveLinesIt = reverseMoveLineSortedList.iterator();
for (MoveLine moveLine : moveLineSortedList) {
MoveLine reverseMoveLine = reverseMoveLinesIt.next();
reconcileService.reconcile(moveLine, reverseMoveLine, false, false);
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateProductMoveLine.
protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
Company company = move.getCompany();
LocalDate moveDate = move.getDate();
Partner partner = move.getPartner();
boolean isFixedAssets = false;
BigDecimal amountInCurrency = null;
BigDecimal totalQty = null;
BigDecimal notInvoicedQty = null;
if (isPurchase && purchaseOrderLine != null) {
totalQty = purchaseOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
isFixedAssets = purchaseOrderLine.getFixedAssets();
if (ati && !recoveredTax) {
amountInCurrency = purchaseOrderLine.getInTaxTotal();
} else {
amountInCurrency = purchaseOrderLine.getExTaxTotal();
}
}
if (!isPurchase && saleOrderLine != null) {
totalQty = saleOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
if (ati) {
amountInCurrency = saleOrderLine.getInTaxTotal();
} else {
amountInCurrency = saleOrderLine.getExTaxTotal();
}
}
if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
return null;
}
BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Product product = stockMoveLine.getProduct();
Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
boolean isDebit = false;
if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
isDebit = true;
}
if (isReverse) {
isDebit = !isDebit;
}
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
moveLine.setDate(moveDate);
moveLine.setDueDate(moveDate);
getAndComputeAnalyticDistribution(product, move, moveLine);
move.addMoveLineListItem(moveLine);
if (recoveredTax) {
TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(taxLine.getTax().getCode());
if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
}
}
}
return moveLine;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generatePartnerMoveLine.
protected MoveLine generatePartnerMoveLine(Move move, String origin, Account account, String moveDescription, LocalDate originDate) throws AxelorException {
LocalDate moveDate = move.getDate();
BigDecimal currencyBalance = moveToolService.getBalanceCurrencyAmount(move.getMoveLineList());
BigDecimal balance = moveToolService.getBalanceAmount(move.getMoveLineList());
if (balance.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
MoveLine moveLine = moveLineService.createMoveLine(move, move.getPartner(), account, currencyBalance.abs(), balance.abs(), null, balance.compareTo(BigDecimal.ZERO) == -1, moveDate, moveDate, originDate, ++counter, origin, moveDescription);
move.addMoveLineListItem(moveLine);
return moveLine;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method balanceCreditDebit.
@Override
public MoveLine balanceCreditDebit(MoveLine moveLine, Move move) {
if (move.getMoveLineList() != null) {
BigDecimal totalCredit = move.getMoveLineList().stream().map(it -> it.getCredit()).reduce((a, b) -> a.add(b)).orElse(BigDecimal.ZERO);
BigDecimal totalDebit = move.getMoveLineList().stream().map(it -> it.getDebit()).reduce((a, b) -> a.add(b)).orElse(BigDecimal.ZERO);
if (totalCredit.compareTo(totalDebit) < 0) {
moveLine.setCredit(totalDebit.subtract(totalCredit));
} else if (totalCredit.compareTo(totalDebit) > 0) {
moveLine.setDebit(totalCredit.subtract(totalDebit));
}
}
return moveLine;
}
Aggregations