Search in sources :

Example 6 with AccountManagement

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

the class BankReconciliationService method getAccountManagementCashAccounts.

protected Set<String> getAccountManagementCashAccounts(BankReconciliation bankReconciliation) {
    List<AccountManagement> accountManagementList;
    Journal journal = bankReconciliation.getJournal();
    Set<String> cashAccountIdSet = new HashSet<String>();
    BankDetails bankDetails = bankReconciliation.getBankDetails();
    if (journal != null) {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1 AND self.journal = ?2", bankDetails, journal).fetch();
    } else {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1", bankDetails).fetch();
    }
    for (AccountManagement accountManagement : accountManagementList) {
        if (accountManagement.getCashAccount() != null) {
            cashAccountIdSet.add(accountManagement.getCashAccount().getId().toString());
        }
    }
    return cashAccountIdSet;
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) AccountManagement(com.axelor.apps.account.db.AccountManagement) HashSet(java.util.HashSet)

Example 7 with AccountManagement

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

the class BankReconciliationService method getAccountManagementJournals.

protected Set<String> getAccountManagementJournals(BankReconciliation bankReconciliation) {
    Set<String> journalIdSet = new HashSet<String>();
    Account cashAccount = bankReconciliation.getCashAccount();
    List<AccountManagement> accountManagementList = new ArrayList<>();
    if (cashAccount != null) {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1 and self.cashAccount = ?2", bankReconciliation.getBankDetails(), cashAccount).fetch();
    } else {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1", bankReconciliation.getBankDetails()).fetch();
    }
    for (AccountManagement accountManagement : accountManagementList) {
        if (accountManagement.getJournal() != null) {
            journalIdSet.add(accountManagement.getJournal().getId().toString());
        }
    }
    return journalIdSet;
}
Also used : Account(com.axelor.apps.account.db.Account) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 8 with AccountManagement

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

the class BatchDirectDebitPaymentSchedule method processPaymentScheduleLines.

protected void processPaymentScheduleLines(int paymentScheduleType) {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    if (generateBankOrderFlag) {
        Preconditions.checkNotNull(accountingBatch.getCompany(), I18n.get("Company is missing."));
        Preconditions.checkNotNull(accountingBatch.getPaymentMode(), I18n.get("Payment method is missing."));
        BankDetails companyBankDetails = getCompanyBankDetails(accountingBatch);
        AccountManagement accountManagement = Beans.get(PaymentModeService.class).getAccountManagement(accountingBatch.getPaymentMode(), accountingBatch.getCompany(), companyBankDetails);
        Preconditions.checkNotNull(accountManagement, I18n.get("Account management is missing."));
        Preconditions.checkNotNull(accountManagement.getBankDetails(), I18n.get("Bank details in account management is missing."));
        Preconditions.checkNotNull(companyBankDetails.getCurrency(), I18n.get("Currency in company bank details is missing."));
        String bankOrderExportPath = accountingBatch.getPaymentMode().getBankOrderExportFolderPath();
        String dataExpotDir;
        try {
            dataExpotDir = appBaseService.getDataExportDir();
            BankPaymentConfigService bankPaymentConfigService = Beans.get(BankPaymentConfigService.class);
            BankPaymentConfig bankPaymentConfig = bankPaymentConfigService.getBankPaymentConfig(accountingBatch.getCompany());
            bankPaymentConfigService.getIcsNumber(bankPaymentConfig);
        } catch (AxelorException e) {
            throw new RuntimeException(e);
        }
        Preconditions.checkArgument(bankOrderExportPath != null && new File(dataExpotDir + bankOrderExportPath).exists(), String.format(I18n.get("Bank order export folder does not exist: %s"), dataExpotDir + bankOrderExportPath));
    }
    QueryBuilder<PaymentScheduleLine> queryBuilder = QueryBuilder.of(PaymentScheduleLine.class);
    queryBuilder.add("self.paymentSchedule.statusSelect = :paymentScheduleStatusSelect");
    queryBuilder.bind("paymentScheduleStatusSelect", PaymentScheduleRepository.STATUS_CONFIRMED);
    queryBuilder.add("self.paymentSchedule.typeSelect = :paymentScheduleTypeSelect");
    queryBuilder.bind("paymentScheduleTypeSelect", paymentScheduleType);
    queryBuilder.add("self.statusSelect = :statusSelect");
    queryBuilder.bind("statusSelect", PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
    LocalDate dueDate = accountingBatch.getDueDate() != null ? accountingBatch.getDueDate() : Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany());
    queryBuilder.add("self.scheduleDate <= :dueDate");
    queryBuilder.bind("dueDate", dueDate);
    if (accountingBatch.getCompany() != null) {
        queryBuilder.add("self.paymentSchedule.company IS NULL OR self.paymentSchedule.company = :company");
        queryBuilder.bind("company", accountingBatch.getCompany());
    }
    queryBuilder.add("self.paymentSchedule.partner.id NOT IN (SELECT DISTINCT partner.id FROM Partner partner LEFT JOIN partner.blockingList blocking WHERE blocking.blockingSelect = :blockingSelect AND blocking.blockingToDate >= :blockingToDate)");
    queryBuilder.bind("blockingSelect", BlockingRepository.DEBIT_BLOCKING);
    queryBuilder.bind("blockingToDate", Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany()));
    if (accountingBatch.getBankDetails() != null) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts() && appBaseService.getAppBase().getManageMultiBanks()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        queryBuilder.add("self.paymentSchedule.companyBankDetails IS NULL OR self.paymentSchedule.companyBankDetails IN (:bankDetailsSet)");
        queryBuilder.bind("bankDetailsSet", bankDetailsSet);
    }
    if (accountingBatch.getPaymentMode() != null) {
        queryBuilder.add("self.paymentSchedule.paymentMode IS NULL OR self.paymentSchedule.paymentMode = :paymentMode");
        queryBuilder.bind("paymentMode", accountingBatch.getPaymentMode());
    }
    queryBuilder.add(":batch NOT MEMBER OF self.batchSet");
    queryBuilder.bind("batch", batch);
    processQuery(queryBuilder);
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BankPaymentConfig(com.axelor.apps.bankpayment.db.BankPaymentConfig) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankPaymentConfigService(com.axelor.apps.bankpayment.service.config.BankPaymentConfigService) File(java.io.File) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 9 with AccountManagement

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

the class InvoiceLineController method getFixedAssetCategory.

public void getFixedAssetCategory(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    Product product = invoiceLine.getProduct();
    if (invoice == null || product == null) {
        return;
    }
    FixedAssetCategory fixedAssetCategory = null;
    if (!product.getAccountManagementList().isEmpty() && (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND)) {
        Optional<AccountManagement> optionalFixedAssetCategory = product.getAccountManagementList().stream().filter(am -> invoice.getCompany().equals(am.getCompany())).findFirst();
        fixedAssetCategory = optionalFixedAssetCategory.isPresent() ? optionalFixedAssetCategory.get().getFixedAssetCategory() : null;
    }
    response.setValue("fixedAssetCategory", fixedAssetCategory);
}
Also used : Context(com.axelor.rpc.Context) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) HashMap(java.util.HashMap) AccountManagementServiceAccountImpl(com.axelor.apps.account.service.AccountManagementServiceAccountImpl) Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AccountTypeRepository(com.axelor.apps.account.db.repo.AccountTypeRepository) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxLine(com.axelor.apps.account.db.TaxLine) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) ActionRequest(com.axelor.rpc.ActionRequest) AccountManagement(com.axelor.apps.account.db.AccountManagement) InvoiceLineManagement(com.axelor.apps.account.service.invoice.generator.line.InvoiceLineManagement) ITranslation(com.axelor.apps.account.translation.ITranslation) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Entry(java.util.Map.Entry) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 10 with AccountManagement

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

the class AccountManagementServiceAccountImpl method getAnalyticDistributionTemplate.

/**
 * Get the product analytic distribution template
 *
 * @param product
 * @param compan
 * @param configObject Specify if we want get the tax from the product or its product family
 *     <li>1 : product
 *     <li>2 : product family
 * @return
 * @throws AxelorException
 */
protected AnalyticDistributionTemplate getAnalyticDistributionTemplate(Product product, Company company, int configObject) {
    AccountManagement accountManagement = this.getAccountManagement(product, company, configObject);
    AnalyticDistributionTemplate analyticDistributionTemplate = null;
    if (accountManagement != null) {
        analyticDistributionTemplate = accountManagement.getAnalyticDistributionTemplate();
    }
    if (analyticDistributionTemplate == null && configObject == CONFIG_OBJECT_PRODUCT) {
        return getAnalyticDistributionTemplate(product, company, CONFIG_OBJECT_PRODUCT_FAMILY);
    }
    return analyticDistributionTemplate;
}
Also used : AnalyticDistributionTemplate(com.axelor.apps.account.db.AnalyticDistributionTemplate) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Aggregations

AccountManagement (com.axelor.apps.account.db.AccountManagement)12 ArrayList (java.util.ArrayList)5 BankDetails (com.axelor.apps.base.db.BankDetails)4 Account (com.axelor.apps.account.db.Account)3 AxelorException (com.axelor.exception.AxelorException)3 FixedAssetCategory (com.axelor.apps.account.db.FixedAssetCategory)2 AppAccountService (com.axelor.apps.account.service.app.AppAccountService)2 HashSet (java.util.HashSet)2 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 AnalyticDistributionTemplate (com.axelor.apps.account.db.AnalyticDistributionTemplate)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 Journal (com.axelor.apps.account.db.Journal)1 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)1 Tax (com.axelor.apps.account.db.Tax)1 TaxLine (com.axelor.apps.account.db.TaxLine)1 AccountTypeRepository (com.axelor.apps.account.db.repo.AccountTypeRepository)1 InvoiceLineRepository (com.axelor.apps.account.db.repo.InvoiceLineRepository)1 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 AccountManagementServiceAccountImpl (com.axelor.apps.account.service.AccountManagementServiceAccountImpl)1