Search in sources :

Example 41 with Account

use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.

the class ImportAccountingReportConfigLine method setAccounts.

@Transactional(rollbackOn = { Exception.class })
public Object setAccounts(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof AccountingReportConfigLine;
    AccountingReportConfigLine configLine = (AccountingReportConfigLine) bean;
    if (configLine.getRuleTypeSelect() == AccountingReportConfigLineRepository.RULE_TYPE_SUM_OF_ACCOUNTS) {
        String accountTypeValues = (String) values.get("accountType");
        if (accountTypeValues != null && !accountTypeValues.isEmpty()) {
            String[] types = accountTypeValues.split("\\|");
            Set<AccountType> accountTypes = new HashSet<>();
            AccountType typeToAdd;
            for (String type : types) {
                typeToAdd = accountTypeRepo.all().filter("self.importId = :importId").bind("importId", type).fetchOne();
                if (typeToAdd != null) {
                    accountTypes.add(typeToAdd);
                }
            }
            configLine.setAccountTypeSet(accountTypes);
        }
        String accountValues = (String) values.get("accountCode");
        if (accountValues != null && !accountValues.isEmpty()) {
            String[] codes = accountValues.split("\\|");
            Set<Account> accounts = new HashSet<>();
            Account accountToAdd;
            List<Account> fetched;
            for (String code : codes) {
                accountToAdd = accountRepo.all().filter("self.code = :code").bind("code", code).fetchOne();
                if (accountToAdd == null) {
                    fetched = accountRepo.all().fetch();
                    for (Account account : fetched) {
                        if (compareCodes(account.getCode(), code)) {
                            accountToAdd = account;
                            break;
                        }
                    }
                }
                if (accountToAdd != null) {
                    accounts.add(accountToAdd);
                }
            }
            configLine.setAccountSet(accounts);
        }
        accountingReportConfigLineRepo.save(configLine);
    }
    return configLine;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountingReportConfigLine(com.axelor.apps.account.db.AccountingReportConfigLine) AccountType(com.axelor.apps.account.db.AccountType) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 42 with Account

use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.

the class ContractServiceImpl method generate.

public InvoiceLine generate(Invoice invoice, ContractLine line) throws AxelorException {
    BigDecimal inTaxPriceComputed = invoiceLineService.convertUnitPrice(false, line.getTaxLine(), line.getPrice());
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, line.getProduct(), line.getProductName(), line.getPrice(), inTaxPriceComputed, invoice.getInAti() ? inTaxPriceComputed : line.getPrice(), line.getDescription(), line.getQty(), line.getUnit(), line.getTaxLine(), line.getSequence(), BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, line.getExTaxTotal(), line.getInTaxTotal(), false) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    InvoiceLine invoiceLine = invoiceLineGenerator.creates().get(0);
    FiscalPositionAccountService fiscalPositionAccountService = Beans.get(FiscalPositionAccountService.class);
    FiscalPosition fiscalPosition = line.getFiscalPosition();
    Account currentAccount = invoiceLine.getAccount();
    Account replacedAccount = fiscalPositionAccountService.getAccount(fiscalPosition, currentAccount);
    boolean isPurchase = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice) == PriceListRepository.TYPE_PURCHASE;
    TaxLine taxLine = Beans.get(AccountManagementService.class).getTaxLine(appBaseService.getTodayDate(invoice.getCompany()), invoiceLine.getProduct(), invoice.getCompany(), fiscalPosition, isPurchase);
    invoiceLine.setTaxLine(taxLine);
    invoiceLine.setAccount(replacedAccount);
    if (line.getAnalyticDistributionTemplate() != null) {
        invoiceLine.setAnalyticDistributionTemplate(line.getAnalyticDistributionTemplate());
        this.copyAnalyticMoveLines(line.getAnalyticMoveLineList(), invoiceLine);
    }
    invoice.addInvoiceLineListItem(invoiceLine);
    return Beans.get(InvoiceLineRepository.class).save(invoiceLine);
}
Also used : FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) Account(com.axelor.apps.account.db.Account) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 43 with Account

use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.

the class InvoiceLineGeneratorSupplyChain method createInvoiceLine.

/**
 * @return
 * @throws AxelorException
 */
@Override
protected InvoiceLine createInvoiceLine() throws AxelorException {
    InvoiceLine invoiceLine = super.createInvoiceLine();
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return invoiceLine;
    }
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    this.assignOriginElements(invoiceLine);
    List<AnalyticMoveLine> analyticMoveLineList = null;
    if (saleOrderLine != null) {
        switch(saleOrderLine.getTypeSelect()) {
            case SaleOrderLineRepository.TYPE_END_OF_PACK:
                invoiceLine.setIsHideUnitAmounts(saleOrderLine.getIsHideUnitAmounts());
                invoiceLine.setIsShowTotal(saleOrderLine.getIsShowTotal());
                break;
            case SaleOrderLineRepository.TYPE_NORMAL:
                if (saleOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(saleOrderLine.getAnalyticMoveLineList())) {
                    invoiceLine.setAnalyticDistributionTemplate(saleOrderLine.getAnalyticDistributionTemplate());
                    this.copyAnalyticMoveLines(saleOrderLine.getAnalyticMoveLineList(), invoiceLine);
                    analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
                } else {
                    analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
                    analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
                }
                break;
            default:
                return invoiceLine;
        }
    } else if (purchaseOrderLine != null) {
        if (purchaseOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(purchaseOrderLine.getAnalyticMoveLineList())) {
            invoiceLine.setAnalyticDistributionTemplate(purchaseOrderLine.getAnalyticDistributionTemplate());
            this.copyAnalyticMoveLines(purchaseOrderLine.getAnalyticMoveLineList(), invoiceLine);
            analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
        } else {
            analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
            analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
        }
        this.copyBudgetDistributionList(purchaseOrderLine.getBudgetDistributionList(), invoiceLine);
        invoiceLine.setBudget(purchaseOrderLine.getBudget());
        invoiceLine.setBudgetDistributionSumAmount(purchaseOrderLine.getBudgetDistributionSumAmount());
        invoiceLine.setFixedAssets(purchaseOrderLine.getFixedAssets());
        if (product != null) {
            invoiceLine.setProductCode((String) productCompanyService.get(product, "code", invoice.getCompany()));
            Account account = accountManagementService.getProductAccount(product, invoice.getCompany(), invoice.getPartner().getFiscalPosition(), InvoiceToolService.isPurchase(invoice), invoiceLine.getFixedAssets());
            invoiceLine.setAccount(account);
        }
        if (product != null && purchaseOrderLine.getFixedAssets()) {
            FixedAssetCategory fixedAssetCategory = accountManagementService.getProductFixedAssetCategory(product, invoice.getCompany());
            invoiceLine.setFixedAssetCategory(fixedAssetCategory);
        }
    } else if (stockMoveLine != null) {
        this.price = stockMoveLine.getUnitPriceUntaxed();
        this.inTaxPrice = stockMoveLine.getUnitPriceTaxed();
        this.price = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.price, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        this.inTaxPrice = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.inTaxPrice, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        invoiceLine.setPrice(price);
        invoiceLine.setInTaxPrice(inTaxPrice);
        analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
        analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
    }
    return invoiceLine;
}
Also used : FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 44 with Account

use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.

the class AccountManagementServiceAccountImpl method getProductAccount.

/**
 * Get the product tax according to the fiscal position
 *
 * @param product
 * @param company
 * @param fiscalPosition
 * @param isPurchase Specify if we want get the tax for purchase or sale
 * @param fixedAsset Specify if we should get the purchase account for fixed asset or not. Used
 *     only if isPurchase param is true.
 * @return the tax defined for the product, according to the fiscal position
 * @throws AxelorException
 */
public Account getProductAccount(Product product, Company company, FiscalPosition fiscalPosition, boolean isPurchase, boolean fixedAsset) throws AxelorException {
    log.debug("Get the account for the product {} (company : {}, purchase : {}, fixed asset : {}, fiscal position : {})", new Object[] { product != null ? product.getCode() : null, company.getName(), isPurchase, fixedAsset, fiscalPosition != null ? fiscalPosition.getCode() : null });
    Account generalAccount = this.getProductAccount(product, company, isPurchase, fixedAsset, CONFIG_OBJECT_PRODUCT);
    Account account = new FiscalPositionAccountServiceImpl().getAccount(fiscalPosition, generalAccount);
    if (account != null) {
        return account;
    }
    throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNT_MANAGEMENT_1_ACCOUNT), product != null ? product.getCode() : null, company.getName());
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException)

Example 45 with Account

use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.

the class AccountingCloseAnnualServiceImpl method getAllAccountOfYear.

public List<Long> getAllAccountOfYear(Set<Account> accountSet, Year year) {
    List<Long> accountIdList = accountService.getAllAccountsSubAccountIncluded(accountSet.stream().map(Account::getId).collect(Collectors.toList()));
    Query q = JPA.em().createQuery("select distinct(self.account.id) FROM MoveLine as self " + "WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year  = ?1 AND self.account.id in (?2) " + "AND self.move.statusSelect = ?3 AND self.move.autoYearClosureMove is not true", Long.class);
    q.setParameter(1, year);
    q.setParameter(2, accountIdList);
    q.setParameter(3, MoveRepository.STATUS_VALIDATED);
    List<Long> result = q.getResultList();
    return result;
}
Also used : Account(com.axelor.apps.account.db.Account) Query(javax.persistence.Query)

Aggregations

Account (com.axelor.apps.account.db.Account)59 MoveLine (com.axelor.apps.account.db.MoveLine)27 Company (com.axelor.apps.base.db.Company)26 BigDecimal (java.math.BigDecimal)26 Partner (com.axelor.apps.base.db.Partner)25 Move (com.axelor.apps.account.db.Move)21 AxelorException (com.axelor.exception.AxelorException)20 Journal (com.axelor.apps.account.db.Journal)18 Transactional (com.google.inject.persist.Transactional)18 AccountConfig (com.axelor.apps.account.db.AccountConfig)14 LocalDate (java.time.LocalDate)12 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)10 ArrayList (java.util.ArrayList)10 TaxLine (com.axelor.apps.account.db.TaxLine)8 Invoice (com.axelor.apps.account.db.Invoice)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 Product (com.axelor.apps.base.db.Product)5