Search in sources :

Example 1 with AccountConfigService

use of com.axelor.apps.account.service.config.AccountConfigService in project axelor-open-suite by axelor.

the class InvoiceGenerator method createInvoiceHeader.

protected Invoice createInvoiceHeader() throws AxelorException {
    Invoice invoice = new Invoice();
    invoice.setCompany(company);
    invoice.setOperationTypeSelect(operationType);
    if (partner == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    if (Beans.get(BlockingService.class).getBlocking(partner, company, BlockingRepository.INVOICING_BLOCKING) != null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_VALIDATE_BLOCKING));
    }
    invoice.setPartner(partner);
    AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
    if (accountingSituation != null) {
        invoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
        invoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
        invoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
    }
    if (paymentCondition == null) {
        paymentCondition = InvoiceToolService.getPaymentCondition(invoice);
    }
    invoice.setPaymentCondition(paymentCondition);
    if (paymentMode == null) {
        paymentMode = InvoiceToolService.getPaymentMode(invoice);
    }
    invoice.setPaymentMode(paymentMode);
    if (mainInvoicingAddress == null) {
        mainInvoicingAddress = Beans.get(PartnerService.class).getInvoicingAddress(partner);
    }
    invoice.setAddress(mainInvoicingAddress);
    invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
    invoice.setContactPartner(contactPartner);
    if (currency == null) {
        currency = partner.getCurrency();
    }
    if (currency == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_6), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    invoice.setCurrency(currency);
    invoice.setStatusSelect(InvoiceRepository.STATUS_DRAFT);
    invoice.setPriceList(priceList);
    invoice.setInternalReference(internalReference);
    invoice.setExternalReference(externalReference);
    invoice.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, company));
    invoice.setTradingName(tradingName);
    if (groupProductsOnPrintings == null) {
        groupProductsOnPrintings = partner.getGroupProductsOnPrintings();
    }
    invoice.setGroupProductsOnPrintings(groupProductsOnPrintings);
    // Set ATI mode on invoice
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    int atiChoice = accountConfig.getInvoiceInAtiSelect();
    if (inAti == null) {
        invoice.setInAti(accountConfigService.getInvoiceInAti(accountConfig));
    } else if (atiChoice == AccountConfigRepository.INVOICE_ATI_DEFAULT || atiChoice == AccountConfigRepository.INVOICE_WT_DEFAULT) {
        invoice.setInAti(inAti);
    } else if (atiChoice == AccountConfigRepository.INVOICE_ATI_ALWAYS) {
        invoice.setInAti(true);
    } else {
        invoice.setInAti(false);
    }
    if (partner.getFactorizedCustomer() && accountConfig.getFactorPartner() != null) {
        List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
        companyBankDetails = bankDetailsList.stream().filter(bankDetails -> bankDetails.getIsDefault()).findFirst().orElse(null);
    } else if (accountingSituation != null) {
        if (paymentMode != null) {
            if (paymentMode.equals(partner.getOutPaymentMode())) {
                companyBankDetails = accountingSituation.getCompanyOutBankDetails();
            } else if (paymentMode.equals(partner.getInPaymentMode())) {
                companyBankDetails = accountingSituation.getCompanyInBankDetails();
            }
        }
    }
    if (companyBankDetails == null) {
        companyBankDetails = company.getDefaultBankDetails();
        List<BankDetails> allowedBDs = Beans.get(PaymentModeService.class).getCompatibleBankDetailsList(paymentMode, company);
        if (!allowedBDs.contains(companyBankDetails)) {
            companyBankDetails = null;
        }
    }
    invoice.setCompanyBankDetails(companyBankDetails);
    if (partner.getBankDetailsList() != null && invoice.getBankDetails() == null) {
        invoice.setBankDetails(partner.getBankDetailsList().stream().filter(b -> b.getActive() && b.getIsDefault()).findFirst().orElse(null));
    }
    if (partner != null && !Strings.isNullOrEmpty(partner.getInvoiceComments())) {
        invoice.setNote(partner.getInvoiceComments());
    }
    invoice.setInvoicesCopySelect(getInvoiceCopy());
    initCollections(invoice);
    return invoice;
}
Also used : Company(com.axelor.apps.base.db.Company) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AccountConfig(com.axelor.apps.account.db.AccountConfig) PartnerService(com.axelor.apps.base.service.PartnerService) LoggerFactory(org.slf4j.LoggerFactory) PaymentCondition(com.axelor.apps.account.db.PaymentCondition) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) AddressService(com.axelor.apps.base.service.AddressService) ArrayList(java.util.ArrayList) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BlockingService(com.axelor.apps.base.service.BlockingService) ContextEntity(com.axelor.rpc.ContextEntity) I18n(com.axelor.i18n.I18n) AccountConfigRepository(com.axelor.apps.account.db.repo.AccountConfigRepository) TradingName(com.axelor.apps.base.db.TradingName) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) MethodHandles(java.lang.invoke.MethodHandles) Invoice(com.axelor.apps.account.db.Invoice) TradingNameService(com.axelor.apps.base.service.TradingNameService) Currency(com.axelor.apps.base.db.Currency) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) BlockingRepository(com.axelor.apps.base.db.repo.BlockingRepository) List(java.util.List) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) LocalDate(java.time.LocalDate) PriceList(com.axelor.apps.base.db.PriceList) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) BankDetails(com.axelor.apps.base.db.BankDetails) TaxInvoiceLine(com.axelor.apps.account.service.invoice.generator.tax.TaxInvoiceLine) AxelorException(com.axelor.exception.AxelorException) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 2 with AccountConfigService

use of com.axelor.apps.account.service.config.AccountConfigService 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);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 3 with AccountConfigService

use of com.axelor.apps.account.service.config.AccountConfigService in project axelor-open-suite by axelor.

the class AccountingReportServiceImpl method getJournalType.

public JournalType getJournalType(AccountingReport accountingReport) throws AxelorException {
    if (accountingReport.getReportType() == null) {
        return null;
    }
    Company company = accountingReport.getCompany();
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    switch(accountingReport.getReportType().getTypeSelect()) {
        case AccountingReportRepository.EXPORT_SALES:
            return accountConfigService.getSaleJournalType(accountConfig);
        case AccountingReportRepository.EXPORT_REFUNDS:
            return accountConfigService.getCreditNoteJournalType(accountConfig);
        case AccountingReportRepository.EXPORT_TREASURY:
            return accountConfigService.getCashJournalType(accountConfig);
        case AccountingReportRepository.EXPORT_PURCHASES:
            return accountConfigService.getPurchaseJournalType(accountConfig);
        default:
            break;
    }
    return null;
}
Also used : Company(com.axelor.apps.base.db.Company) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 4 with AccountConfigService

use of com.axelor.apps.account.service.config.AccountConfigService in project axelor-open-suite by axelor.

the class InvoicingProjectService method generateInvoice.

@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(InvoicingProject invoicingProject) throws AxelorException {
    Project project = invoicingProject.getProject();
    Partner customer = project.getClientPartner();
    Partner customerContact = project.getContactPartner();
    if (invoicingProject.getSaleOrderLineSet().isEmpty() && invoicingProject.getPurchaseOrderLineSet().isEmpty() && invoicingProject.getLogTimesSet().isEmpty() && invoicingProject.getExpenseLineSet().isEmpty() && invoicingProject.getProjectSet().isEmpty() && invoicingProject.getProjectTaskSet().isEmpty()) {
        throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_EMPTY));
    }
    if (invoicingProject.getProject() == null) {
        throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT));
    }
    if (invoicingProject.getProject().getClientPartner() == null) {
        throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_PARTNER));
    }
    if (customerContact == null && customer.getContactPartnerSet().size() == 1) {
        customerContact = customer.getContactPartnerSet().iterator().next();
    }
    Company company = this.getRootCompany(project);
    if (company == null) {
        throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_COMPANY));
    }
    InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, customer.getPaymentCondition(), customer.getInPaymentMode(), partnerService.getInvoicingAddress(customer), customer, customerContact, customer.getCurrency(), Beans.get(PartnerPriceListService.class).getDefaultPriceList(customer, PriceListRepository.TYPE_SALE), null, null, null, null, null, null) {

        @Override
        public Invoice generate() throws AxelorException {
            Invoice invoice = super.createInvoiceHeader();
            invoice.setProject(project);
            invoice.setPriceList(project.getPriceList());
            return invoice;
        }
    };
    Invoice invoice = invoiceGenerator.generate();
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    invoice.setDisplayTimesheetOnPrinting(accountConfig.getDisplayTimesheetOnPrinting());
    invoice.setDisplayExpenseOnPrinting(accountConfig.getDisplayExpenseOnPrinting());
    invoiceGenerator.populate(invoice, this.populate(invoice, invoicingProject));
    Beans.get(InvoiceRepository.class).save(invoice);
    invoicingProject.setInvoice(invoice);
    invoicingProject.setStatusSelect(InvoicingProjectRepository.STATUS_GENERATED);
    invoicingProjectRepo.save(invoicingProject);
    return invoice;
}
Also used : InvoicingProject(com.axelor.apps.businessproject.db.InvoicingProject) Project(com.axelor.apps.project.db.Project) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 5 with AccountConfigService

use of com.axelor.apps.account.service.config.AccountConfigService in project axelor-open-suite by axelor.

the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.

@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
    MoveService moveService = Beans.get(MoveService.class);
    MoveRepository moveRepository = Beans.get(MoveRepository.class);
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    Company company = subrogationRelease.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
    Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
    if (subrogationRelease.getAccountingDate() == null) {
        subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
        boolean isRefund = false;
        if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
            isRefund = true;
        }
        LocalDate date = subrogationRelease.getAccountingDate();
        Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        MoveLine creditMoveLine, debitMoveLine;
        debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        move.addMoveLineListItem(debitMoveLine);
        move.addMoveLineListItem(creditMoveLine);
        move = moveRepository.save(move);
        moveService.getMoveValidateService().validate(move);
        invoice.setSubrogationRelease(subrogationRelease);
        invoice.setSubrogationReleaseMove(move);
        subrogationRelease.addMoveListItem(move);
    }
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) MoveService(com.axelor.apps.account.service.move.MoveService) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AccountConfig(com.axelor.apps.account.db.AccountConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Move(com.axelor.apps.account.db.Move) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)6 AccountConfig (com.axelor.apps.account.db.AccountConfig)5 Invoice (com.axelor.apps.account.db.Invoice)5 Company (com.axelor.apps.base.db.Company)5 AxelorException (com.axelor.exception.AxelorException)4 Transactional (com.google.inject.persist.Transactional)4 Account (com.axelor.apps.account.db.Account)3 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)3 Journal (com.axelor.apps.account.db.Journal)2 Move (com.axelor.apps.account.db.Move)2 MoveLine (com.axelor.apps.account.db.MoveLine)2 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)2 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)2 InvoiceToolService (com.axelor.apps.account.service.invoice.InvoiceToolService)2 MoveService (com.axelor.apps.account.service.move.MoveService)2 Partner (com.axelor.apps.base.db.Partner)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)2 I18n (com.axelor.i18n.I18n)2 Beans (com.axelor.inject.Beans)2