use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class ImportMove method importFECMove.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Object importFECMove(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof MoveLine;
MoveLine moveLine = (MoveLine) bean;
try {
moveLine.setCounter(1);
if (values.get("EcritureNum") == null) {
return null;
}
String moveReference = values.get("EcritureNum").toString();
MoveLine mvLine = moveLineRepo.all().filter("self.name LIKE '" + moveReference + "-%'").order("-counter").fetchOne();
if (mvLine != null) {
int counter = mvLine.getCounter() + 1;
moveLine.setCounter(counter);
}
if (values.get("EcritureDate") != null) {
LocalDate moveLineDate = LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE);
moveLine.setDate(moveLineDate);
}
Move move = moveRepository.all().filter("self.reference = ?", moveReference).fetchOne();
if (move == null) {
move = new Move();
move.setReference(moveReference);
if (values.get("ValidDate") != null) {
move.setStatusSelect(MoveRepository.STATUS_VALIDATED);
move.setValidationDate(LocalDate.parse(values.get("ValidDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
} else {
move.setStatusSelect(MoveRepository.STATUS_ACCOUNTED);
}
move.setCompany(getCompany(values));
move.setCompanyCurrency(move.getCompany().getCurrency());
move.setDate(LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
move.setPeriod(Beans.get(PeriodService.class).getPeriod(move.getDate(), move.getCompany(), YearRepository.TYPE_FISCAL));
if (values.get("Idevise") != null) {
move.setCurrency(Beans.get(CurrencyRepository.class).findByCode(values.get("Idevise").toString()));
move.setCurrencyCode(values.get("Idevise").toString());
}
if (values.get("JournalCode") != null) {
Journal journal = Beans.get(JournalRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("JournalCode").toString(), move.getCompany().getId()).fetchOne();
move.setJournal(journal);
}
if (values.get("CompAuxNum") != null) {
Partner partner = Beans.get(PartnerRepository.class).all().filter("self.partnerSeq = ?", values.get("CompAuxNum").toString()).fetchOne();
move.setPartner(partner);
}
moveRepository.save(move);
}
if (values.get("CompteNum") != null) {
Account account = Beans.get(AccountRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("CompteNum").toString(), move.getCompany().getId()).fetchOne();
moveLine.setAccount(account);
}
moveLine.setMove(move);
} catch (Exception e) {
TraceBackService.trace(e);
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
}
return moveLine;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class ImportMoveLine method importMoveLine.
@Transactional(rollbackOn = Exception.class)
public Object importMoveLine(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof MoveLine;
MoveLine moveLine = (MoveLine) bean;
String accountId = (String) values.get("account_importId");
Account account = getAccount(accountId);
if (account != null) {
moveLine.setAccountCode(account.getCode());
moveLine.setAccountName(account.getName());
} else {
moveLine.setAccountCode((String) values.get("accountCode"));
moveLine.setAccountName((String) values.get("accountName"));
}
String taxLineId = (String) values.get("taxLine_importId");
TaxLine taxLine = getTaxLine(taxLineId);
if (taxLine != null) {
moveLine.setTaxCode(taxLine.getTax().getCode());
moveLine.setTaxRate(taxLine.getValue());
} else {
moveLine.setTaxCode((String) values.get("taxCode"));
moveLine.setTaxRate(new BigDecimal((String) values.get("taxRate")));
}
String partnerId = (String) values.get("partner_importId");
Partner partner = getPartner(partnerId);
if (partner != null) {
moveLine.setPartnerSeq(partner.getPartnerSeq());
moveLine.setPartnerFullName(partner.getFullName());
} else {
moveLine.setPartnerSeq((String) values.get("partnerSeq"));
moveLine.setPartnerFullName((String) values.get("partnerFullName"));
}
moveLineRepository.save(moveLine);
return moveLine;
}
use of com.axelor.apps.account.db.Account 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.Account in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method generateAdvancePayment.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateAdvancePayment(SaleOrder saleOrder, BigDecimal amountToInvoice, boolean isPercent) throws AxelorException {
List<SaleOrderLineTax> taxLineList = saleOrder.getSaleOrderLineTaxList();
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
BigDecimal percentToInvoice = computeAmountToInvoicePercent(saleOrder, amountToInvoice, isPercent);
Product invoicingProduct = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentProduct();
Account advancePaymentAccount = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentAccount();
if (invoicingProduct == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_PRODUCT));
}
if (advancePaymentAccount == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_ACCOUNT), saleOrder.getCompany().getName());
}
Invoice invoice = createInvoiceAndLines(saleOrder, taxLineList, invoicingProduct, percentToInvoice, InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE, advancePaymentAccount);
// no need for link to sale order lines for an advance payment
if (invoice.getInvoiceLineList() != null) {
invoice.getInvoiceLineList().forEach(invoiceLine -> invoiceLine.setSaleOrderLine(null));
}
return invoiceRepo.save(invoice);
}
use of com.axelor.apps.account.db.Account 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;
}
Aggregations