use of com.axelor.apps.base.db.Currency 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;
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class InvoiceLineGenerator method computeCompanyTotal.
public void computeCompanyTotal(InvoiceLine invoiceLine) throws AxelorException {
if (typeSelect == InvoiceLineRepository.TYPE_TITLE) {
return;
}
Company company = invoice.getCompany();
Currency companyCurrency = company.getCurrency();
if (companyCurrency == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICE_LINE_GENERATOR_2), company.getName());
}
invoiceLine.setCompanyExTaxTotal(currencyService.getAmountCurrencyConvertedAtDate(invoice.getCurrency(), companyCurrency, exTaxTotal, today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP));
invoiceLine.setCompanyInTaxTotal(currencyService.getAmountCurrencyConvertedAtDate(invoice.getCurrency(), companyCurrency, inTaxTotal, today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP));
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class CostSheetLineServiceImpl method getComponentCostPrice.
protected BigDecimal getComponentCostPrice(Product product, int componentsValuationMethod, Company company) throws AxelorException {
BigDecimal price = null;
Currency companyCurrency = company.getCurrency();
if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_AVERAGE) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
}
} else if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_COST) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
}
}
if (product.getPurchasable() && (price == null || price.compareTo(BigDecimal.ZERO) == 0)) {
price = (BigDecimal) productCompanyService.get(product, "purchasePrice", company);
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), price, appProductionService.getNbDecimalDigitForUnitPrice(), product);
BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, (Partner) productCompanyService.get(product, "defaultSupplierPartner", company), company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
if (productCompanyService.get(product, "purchaseCurrency", company) == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_PURCHASE_CURRENCY), product.getFullName());
}
price = currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), companyCurrency, price, appProductionService.getTodayDate(company));
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
@SuppressWarnings("unchecked") List<SupplierCatalog> supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
for (SupplierCatalog supplierCatalog : supplierCatalogList) {
if (BigDecimal.ZERO.compareTo(supplierCatalog.getPrice()) < 0) {
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), supplierCatalog.getPrice(), appProductionService.getNbDecimalDigitForUnitPrice(), product);
Partner supplierPartner = supplierCatalog.getSupplierPartner();
if (supplierPartner != null) {
shippingCoef = shippingCoefService.getShippingCoef(product, supplierPartner, company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
price = currencyService.getAmountCurrencyConvertedAtDate(supplierPartner.getCurrency(), companyCurrency, price, appProductionService.getTodayDate(company));
}
break;
}
}
}
}
return price;
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method createMoveLine.
/**
* Creating accounting move line method using move currency
*
* @param move
* @param partner
* @param account
* @param amountInSpecificMoveCurrency
* @param isDebit <code>true = debit</code>, <code>false = credit</code>
* @param date
* @param dueDate
* @param counter
* @param origin
* @return
* @throws AxelorException
*/
@Override
public MoveLine createMoveLine(Move move, Partner partner, Account account, BigDecimal amountInSpecificMoveCurrency, boolean isDebit, LocalDate date, LocalDate dueDate, int counter, String origin, String description) throws AxelorException {
log.debug("Creating accounting move line (Account : {}, Amount in specific move currency : {}, debit ? : {}, date : {}, counter : {}, reference : {}", new Object[] { account.getName(), amountInSpecificMoveCurrency, isDebit, date, counter, origin });
Currency currency = move.getCurrency();
Currency companyCurrency = companyConfigService.getCompanyCurrency(move.getCompany());
BigDecimal currencyRate = currencyService.getCurrencyConversionRate(currency, companyCurrency, date);
BigDecimal amountConvertedInCompanyCurrency = currencyService.getAmountCurrencyConvertedUsingExchangeRate(amountInSpecificMoveCurrency, currencyRate);
return this.createMoveLine(move, partner, account, amountInSpecificMoveCurrency, amountConvertedInCompanyCurrency, currencyRate, isDebit, date, dueDate, date, counter, origin, description);
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class MoveCreateService method createMove.
/**
* Creating a new generic accounting move
*
* @param journal
* @param company
* @param currency
* @param partner
* @param date
* @param paymentMode
* @param technicalOriginSelect
* @param ignoreInDebtRecoveryOk
* @param ignoreInAccountingOk
* @return
* @throws AxelorException
*/
public Move createMove(Journal journal, Company company, Currency currency, Partner partner, LocalDate date, PaymentMode paymentMode, int technicalOriginSelect, int functionalOriginSelect, boolean ignoreInDebtRecoveryOk, boolean ignoreInAccountingOk, boolean autoYearClosureMove) throws AxelorException {
log.debug("Creating a new generic accounting move (journal : {}, company : {}", new Object[] { journal.getName(), company.getName() });
Move move = new Move();
move.setJournal(journal);
move.setCompany(company);
move.setIgnoreInDebtRecoveryOk(ignoreInDebtRecoveryOk);
move.setIgnoreInAccountingOk(ignoreInAccountingOk);
move.setAutoYearClosureMove(autoYearClosureMove);
if (autoYearClosureMove) {
move.setPeriod(periodService.getPeriod(date, company, YearRepository.TYPE_FISCAL));
if (move.getPeriod() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), date.toString());
}
} else {
move.setPeriod(periodService.getActivePeriod(date, company, YearRepository.TYPE_FISCAL));
}
move.setDate(date);
move.setMoveLineList(new ArrayList<MoveLine>());
Currency companyCurrency = companyConfigService.getCompanyCurrency(company);
if (companyCurrency != null) {
move.setCompanyCurrency(companyCurrency);
move.setCompanyCurrencyCode(companyCurrency.getCode());
}
if (currency == null) {
currency = move.getCompanyCurrency();
}
if (currency != null) {
move.setCurrency(currency);
move.setCurrencyCode(currency.getCode());
}
move.setPartner(partner);
move.setPaymentMode(paymentMode);
move.setTechnicalOriginSelect(technicalOriginSelect);
move.setFunctionalOriginSelect(functionalOriginSelect);
moveRepository.save(move);
move.setReference(Beans.get(SequenceService.class).getDraftSequenceNumber(move));
return move;
}
Aggregations