Search in sources :

Example 1 with AppAccountService

use of com.axelor.apps.account.service.app.AppAccountService in project axelor-open-suite by axelor.

the class PurchaseOrderController method generateBudgetDistribution.

public void generateBudgetDistribution(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (appAccountService.isApp("budget") && !appAccountService.getAppBudget().getManageMultiBudget()) {
        purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
        Beans.get(PurchaseOrderSupplychainService.class).generateBudgetDistribution(purchaseOrder);
        response.setValues(purchaseOrder);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderSupplychainService(com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService)

Example 2 with AppAccountService

use of com.axelor.apps.account.service.app.AppAccountService in project axelor-open-suite by axelor.

the class PaymentVoucherConfirmService method confirmPaymentVoucher.

/**
 * Confirms the payment voucher if the selected lines PiToPay 2nd O2M belongs to different
 * companies -> error I - Payment with an amount If we pay a classical moveLine (invoice, reject
 * ..) -> just create a payment If we pay a schedule 2 payments are created 1st reconciled with
 * the invoice and the second reconciled with the schedule II - Payment with an excess Payment If
 * we pay a moveLine having the same account, we just reconcile If we pay a with different account
 * -> 1- switch money to the good account 2- reconcile then
 *
 * @param paymentVoucher
 */
@Transactional(rollbackOn = { Exception.class })
public void confirmPaymentVoucher(PaymentVoucher paymentVoucher) throws AxelorException {
    log.debug("In confirmPaymentVoucherService ....");
    paymentVoucherSequenceService.setReference(paymentVoucher);
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    paymentVoucherControlService.checkPaymentVoucherField(paymentVoucher, company, paymentModeAccount, journal);
    if (paymentVoucher.getRemainingAmount().compareTo(BigDecimal.ZERO) > 0 && !journal.getExcessPaymentOk()) {
        throw new AxelorException(paymentVoucher, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_AMOUNT_EXCEEDING), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    // TODO VEIRIFER QUE LES ELEMENTS A PAYER NE CONCERNE QU'UNE SEULE DEVISE
    // TODO RECUPERER DEVISE DE LA PREMIERE DETTE
    // Currency currencyToPay = null;
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (appAccountService.getAppAccount().getPaymentVouchersOnInvoice() && paymentVoucher.getPaymentMode().getValidatePaymentByDepositSlipPublication()) {
        waitForDepositSlip(paymentVoucher);
    } else {
        createMoveAndConfirm(paymentVoucher);
    }
    paymentVoucherSequenceService.setReceiptNo(paymentVoucher, company, journal);
    paymentVoucherRepository.save(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) Transactional(com.google.inject.persist.Transactional)

Example 3 with AppAccountService

use of com.axelor.apps.account.service.app.AppAccountService in project axelor-open-suite by axelor.

the class ContractLineServiceImpl method createAnalyticDistributionWithTemplate.

@Override
public ContractLine createAnalyticDistributionWithTemplate(ContractLine contractLine, Contract contract) {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    List<AnalyticMoveLine> analyticMoveLineList = Beans.get(AnalyticMoveLineService.class).generateLines(contractLine.getAnalyticDistributionTemplate(), contractLine.getExTaxTotal(), AnalyticMoveLineRepository.STATUS_FORECAST_CONTRACT, appAccountService.getTodayDate(contract.getCompany()));
    contractLine.setAnalyticMoveLineList(analyticMoveLineList);
    return contractLine;
}
Also used : AnalyticMoveLineService(com.axelor.apps.account.service.AnalyticMoveLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 4 with AppAccountService

use of com.axelor.apps.account.service.app.AppAccountService in project axelor-open-suite by axelor.

the class BankDetailsServiceAccountImpl method createCompanyBankDetailsDomain.

/**
 * In this implementation, we use the O2M in payment mode.
 *
 * @param company
 * @param paymentMode
 * @return
 * @throws AxelorException
 */
@Override
public String createCompanyBankDetailsDomain(Partner partner, Company company, PaymentMode paymentMode, Integer operationTypeSelect) throws AxelorException {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (!appAccountService.isApp("account") || !appAccountService.getAppBase().getManageMultiBanks()) {
        return super.createCompanyBankDetailsDomain(partner, company, paymentMode, operationTypeSelect);
    } else {
        if (partner != null) {
            partner = Beans.get(PartnerRepository.class).find(partner.getId());
        }
        List<BankDetails> authorizedBankDetails = new ArrayList<>();
        if (partner != null && partner.getFactorizedCustomer() && operationTypeSelect != null && (operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_SALE || operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND)) {
            authorizedBankDetails = createCompanyBankDetailsDomainFromFactorPartner(company);
        } else {
            if (paymentMode == null) {
                return "self.id IN (0)";
            }
            List<AccountManagement> accountManagementList = paymentMode.getAccountManagementList();
            authorizedBankDetails = new ArrayList<>();
            for (AccountManagement accountManagement : accountManagementList) {
                if (accountManagement.getCompany() != null && accountManagement.getCompany().equals(company)) {
                    authorizedBankDetails.add(accountManagement.getBankDetails());
                }
            }
        }
        if (authorizedBankDetails.isEmpty()) {
            return "self.id IN (0)";
        } else {
            return "self.id IN (" + StringTool.getIdListString(authorizedBankDetails) + ") AND self.active = true";
        }
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 5 with AppAccountService

use of com.axelor.apps.account.service.app.AppAccountService in project axelor-open-suite by axelor.

the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetails.

/**
 * Find a default bank details.
 *
 * @param company
 * @param paymentMode
 * @param partner
 * @return the default bank details in accounting situation if it is active and allowed by the
 *     payment mode, or an authorized bank details if he is the only one authorized.
 * @throws AxelorException
 */
@Override
public BankDetails getDefaultCompanyBankDetails(Company company, PaymentMode paymentMode, Partner partner, Integer operationTypeSelect) throws AxelorException {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (!appAccountService.isApp("account") || !appAccountService.getAppBase().getManageMultiBanks()) {
        return super.getDefaultCompanyBankDetails(company, paymentMode, partner, operationTypeSelect);
    } else {
        if (partner != null && partner.getFactorizedCustomer() && operationTypeSelect != null && (operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_SALE || operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND)) {
            return getDefaultCompanyBankDetailsFromFactorPartner(company);
        } else {
            if (paymentMode == null) {
                return null;
            }
            BankDetails candidateBankDetails = getDefaultCompanyBankDetailsFromPartner(company, paymentMode, partner);
            List<BankDetails> authorizedBankDetails = Beans.get(PaymentModeService.class).getCompatibleBankDetailsList(paymentMode, company);
            if (candidateBankDetails != null && authorizedBankDetails.contains(candidateBankDetails) && candidateBankDetails.getActive()) {
                return candidateBankDetails;
            } else // we did not find a bank details in accounting situation
            {
                if (authorizedBankDetails.size() == 1) {
                    return authorizedBankDetails.get(0);
                }
            }
        }
        return null;
    }
}
Also used : PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) BankDetails(com.axelor.apps.base.db.BankDetails) AppAccountService(com.axelor.apps.account.service.app.AppAccountService)

Aggregations

AppAccountService (com.axelor.apps.account.service.app.AppAccountService)5 BankDetails (com.axelor.apps.base.db.BankDetails)3 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)1 Journal (com.axelor.apps.account.db.Journal)1 PaymentMode (com.axelor.apps.account.db.PaymentMode)1 AnalyticMoveLineService (com.axelor.apps.account.service.AnalyticMoveLineService)1 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)1 Company (com.axelor.apps.base.db.Company)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 PurchaseOrderSupplychainService (com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 ArrayList (java.util.ArrayList)1