Search in sources :

Example 1 with PaymentCondition

use of com.axelor.apps.account.db.PaymentCondition 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 PaymentCondition

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

the class InvoiceController method fillPaymentModeAndCondition.

/**
 * Function returning both the paymentMode and the paymentCondition
 *
 * @param request
 * @param response
 */
public void fillPaymentModeAndCondition(ActionRequest request, ActionResponse response) {
    Invoice invoice = request.getContext().asType(Invoice.class);
    try {
        if (invoice.getOperationTypeSelect() == null) {
            return;
        }
        PaymentMode paymentMode = InvoiceToolService.getPaymentMode(invoice);
        PaymentCondition paymentCondition = InvoiceToolService.getPaymentCondition(invoice);
        response.setValue("paymentMode", paymentMode);
        response.setValue("paymentCondition", paymentCondition);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) Invoice(com.axelor.apps.account.db.Invoice) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 3 with PaymentCondition

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

the class StockMoveInvoiceController method generateInvoiceConcatInStockMove.

/**
 * Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
 * call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiIncomingStockMove(List,
 * PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatInStockMove(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        String stockMoveListStr = (String) request.getContext().get("supplierStockMoveToInvoice");
        for (String stockMoveId : stockMoveListStr.split(",")) {
            stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
        }
        PaymentCondition paymentCondition = null;
        PaymentMode paymentMode = null;
        Partner contactPartner = null;
        if (request.getContext().get("paymentCondition") != null) {
            paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
        }
        if (request.getContext().get("paymentMode") != null) {
            paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
        }
        if (request.getContext().get("contactPartner") != null) {
            contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
        }
        Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
        invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 4 with PaymentCondition

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

the class StockMoveMultiInvoiceServiceImpl method areFieldsConflictedToGenerateCustInvoice.

@Override
public Map<String, Object> areFieldsConflictedToGenerateCustInvoice(List<StockMove> stockMoveList) throws AxelorException {
    Map<String, Object> mapResult = new HashMap<>();
    boolean paymentConditionToCheck = false;
    boolean paymentModeToCheck = false;
    boolean contactPartnerToCheck = false;
    checkForAlreadyInvoicedStockMove(stockMoveList);
    List<Invoice> dummyInvoiceList = stockMoveList.stream().map(this::createDummyOutInvoice).collect(Collectors.toList());
    checkOutStockMoveRequiredFieldsAreTheSame(dummyInvoiceList);
    if (!dummyInvoiceList.isEmpty()) {
        PaymentCondition firstPaymentCondition = dummyInvoiceList.get(0).getPaymentCondition();
        PaymentMode firstPaymentMode = dummyInvoiceList.get(0).getPaymentMode();
        Partner firstContactPartner = dummyInvoiceList.get(0).getContactPartner();
        paymentConditionToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentCondition).allMatch(paymentCondition -> Objects.equals(paymentCondition, firstPaymentCondition));
        paymentModeToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentMode).allMatch(paymentMode -> Objects.equals(paymentMode, firstPaymentMode));
        contactPartnerToCheck = !dummyInvoiceList.stream().map(Invoice::getContactPartner).allMatch(contactPartner -> Objects.equals(contactPartner, firstContactPartner));
        mapResult.put("paymentCondition", firstPaymentCondition);
        mapResult.put("paymentMode", firstPaymentMode);
        mapResult.put("contactPartner", firstContactPartner);
    }
    mapResult.put("paymentConditionToCheck", paymentConditionToCheck);
    mapResult.put("paymentModeToCheck", paymentModeToCheck);
    mapResult.put("contactPartnerToCheck", contactPartnerToCheck);
    return mapResult;
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) HashMap(java.util.HashMap) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 5 with PaymentCondition

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

the class StockMoveMultiInvoiceServiceImpl method areFieldsConflictedToGenerateSupplierInvoice.

@Override
public Map<String, Object> areFieldsConflictedToGenerateSupplierInvoice(List<StockMove> stockMoveList) throws AxelorException {
    Map<String, Object> mapResult = new HashMap<>();
    boolean paymentConditionToCheck = false;
    boolean paymentModeToCheck = false;
    boolean contactPartnerToCheck = false;
    checkForAlreadyInvoicedStockMove(stockMoveList);
    List<Invoice> dummyInvoiceList = stockMoveList.stream().map(this::createDummyInInvoice).collect(Collectors.toList());
    checkInStockMoveRequiredFieldsAreTheSame(dummyInvoiceList);
    if (!dummyInvoiceList.isEmpty()) {
        PaymentCondition firstPaymentCondition = dummyInvoiceList.get(0).getPaymentCondition();
        PaymentMode firstPaymentMode = dummyInvoiceList.get(0).getPaymentMode();
        Partner firstContactPartner = dummyInvoiceList.get(0).getContactPartner();
        paymentConditionToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentCondition).allMatch(paymentCondition -> Objects.equals(paymentCondition, firstPaymentCondition));
        paymentModeToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentMode).allMatch(paymentMode -> Objects.equals(paymentMode, firstPaymentMode));
        contactPartnerToCheck = !dummyInvoiceList.stream().map(Invoice::getContactPartner).allMatch(contactPartner -> Objects.equals(contactPartner, firstContactPartner));
        mapResult.put("paymentCondition", firstPaymentCondition);
        mapResult.put("paymentMode", firstPaymentMode);
        mapResult.put("contactPartner", firstContactPartner);
    }
    mapResult.put("paymentConditionToCheck", paymentConditionToCheck);
    mapResult.put("paymentModeToCheck", paymentModeToCheck);
    mapResult.put("contactPartnerToCheck", contactPartnerToCheck);
    return mapResult;
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) HashMap(java.util.HashMap) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)9 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)9 PaymentMode (com.axelor.apps.account.db.PaymentMode)9 Partner (com.axelor.apps.base.db.Partner)8 ArrayList (java.util.ArrayList)6 AxelorException (com.axelor.exception.AxelorException)5 Map (java.util.Map)5 Company (com.axelor.apps.base.db.Company)4 Currency (com.axelor.apps.base.db.Currency)4 PriceList (com.axelor.apps.base.db.PriceList)4 List (java.util.List)4 Wizard (com.axelor.apps.base.db.Wizard)3 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)2 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 StockMove (com.axelor.apps.stock.db.StockMove)2 StockMoveMultiInvoiceService (com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService)2 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)2 HashMap (java.util.HashMap)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1