use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class ImportAccountingReportConfigLine method setAccounts.
@Transactional(rollbackOn = { Exception.class })
public Object setAccounts(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof AccountingReportConfigLine;
AccountingReportConfigLine configLine = (AccountingReportConfigLine) bean;
if (configLine.getRuleTypeSelect() == AccountingReportConfigLineRepository.RULE_TYPE_SUM_OF_ACCOUNTS) {
String accountTypeValues = (String) values.get("accountType");
if (accountTypeValues != null && !accountTypeValues.isEmpty()) {
String[] types = accountTypeValues.split("\\|");
Set<AccountType> accountTypes = new HashSet<>();
AccountType typeToAdd;
for (String type : types) {
typeToAdd = accountTypeRepo.all().filter("self.importId = :importId").bind("importId", type).fetchOne();
if (typeToAdd != null) {
accountTypes.add(typeToAdd);
}
}
configLine.setAccountTypeSet(accountTypes);
}
String accountValues = (String) values.get("accountCode");
if (accountValues != null && !accountValues.isEmpty()) {
String[] codes = accountValues.split("\\|");
Set<Account> accounts = new HashSet<>();
Account accountToAdd;
List<Account> fetched;
for (String code : codes) {
accountToAdd = accountRepo.all().filter("self.code = :code").bind("code", code).fetchOne();
if (accountToAdd == null) {
fetched = accountRepo.all().fetch();
for (Account account : fetched) {
if (compareCodes(account.getCode(), code)) {
accountToAdd = account;
break;
}
}
}
if (accountToAdd != null) {
accounts.add(accountToAdd);
}
}
configLine.setAccountSet(accounts);
}
accountingReportConfigLineRepo.save(configLine);
}
return configLine;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class ContractServiceImpl method generate.
public InvoiceLine generate(Invoice invoice, ContractLine line) throws AxelorException {
BigDecimal inTaxPriceComputed = invoiceLineService.convertUnitPrice(false, line.getTaxLine(), line.getPrice());
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, line.getProduct(), line.getProductName(), line.getPrice(), inTaxPriceComputed, invoice.getInAti() ? inTaxPriceComputed : line.getPrice(), line.getDescription(), line.getQty(), line.getUnit(), line.getTaxLine(), line.getSequence(), BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, line.getExTaxTotal(), line.getInTaxTotal(), false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
InvoiceLine invoiceLine = invoiceLineGenerator.creates().get(0);
FiscalPositionAccountService fiscalPositionAccountService = Beans.get(FiscalPositionAccountService.class);
FiscalPosition fiscalPosition = line.getFiscalPosition();
Account currentAccount = invoiceLine.getAccount();
Account replacedAccount = fiscalPositionAccountService.getAccount(fiscalPosition, currentAccount);
boolean isPurchase = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice) == PriceListRepository.TYPE_PURCHASE;
TaxLine taxLine = Beans.get(AccountManagementService.class).getTaxLine(appBaseService.getTodayDate(invoice.getCompany()), invoiceLine.getProduct(), invoice.getCompany(), fiscalPosition, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setAccount(replacedAccount);
if (line.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(line.getAnalyticDistributionTemplate());
this.copyAnalyticMoveLines(line.getAnalyticMoveLineList(), invoiceLine);
}
invoice.addInvoiceLineListItem(invoiceLine);
return Beans.get(InvoiceLineRepository.class).save(invoiceLine);
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class InvoiceLineGeneratorSupplyChain method createInvoiceLine.
/**
* @return
* @throws AxelorException
*/
@Override
protected InvoiceLine createInvoiceLine() throws AxelorException {
InvoiceLine invoiceLine = super.createInvoiceLine();
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return invoiceLine;
}
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
this.assignOriginElements(invoiceLine);
List<AnalyticMoveLine> analyticMoveLineList = null;
if (saleOrderLine != null) {
switch(saleOrderLine.getTypeSelect()) {
case SaleOrderLineRepository.TYPE_END_OF_PACK:
invoiceLine.setIsHideUnitAmounts(saleOrderLine.getIsHideUnitAmounts());
invoiceLine.setIsShowTotal(saleOrderLine.getIsShowTotal());
break;
case SaleOrderLineRepository.TYPE_NORMAL:
if (saleOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(saleOrderLine.getAnalyticMoveLineList())) {
invoiceLine.setAnalyticDistributionTemplate(saleOrderLine.getAnalyticDistributionTemplate());
this.copyAnalyticMoveLines(saleOrderLine.getAnalyticMoveLineList(), invoiceLine);
analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
} else {
analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
}
break;
default:
return invoiceLine;
}
} else if (purchaseOrderLine != null) {
if (purchaseOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(purchaseOrderLine.getAnalyticMoveLineList())) {
invoiceLine.setAnalyticDistributionTemplate(purchaseOrderLine.getAnalyticDistributionTemplate());
this.copyAnalyticMoveLines(purchaseOrderLine.getAnalyticMoveLineList(), invoiceLine);
analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
} else {
analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
}
this.copyBudgetDistributionList(purchaseOrderLine.getBudgetDistributionList(), invoiceLine);
invoiceLine.setBudget(purchaseOrderLine.getBudget());
invoiceLine.setBudgetDistributionSumAmount(purchaseOrderLine.getBudgetDistributionSumAmount());
invoiceLine.setFixedAssets(purchaseOrderLine.getFixedAssets());
if (product != null) {
invoiceLine.setProductCode((String) productCompanyService.get(product, "code", invoice.getCompany()));
Account account = accountManagementService.getProductAccount(product, invoice.getCompany(), invoice.getPartner().getFiscalPosition(), InvoiceToolService.isPurchase(invoice), invoiceLine.getFixedAssets());
invoiceLine.setAccount(account);
}
if (product != null && purchaseOrderLine.getFixedAssets()) {
FixedAssetCategory fixedAssetCategory = accountManagementService.getProductFixedAssetCategory(product, invoice.getCompany());
invoiceLine.setFixedAssetCategory(fixedAssetCategory);
}
} else if (stockMoveLine != null) {
this.price = stockMoveLine.getUnitPriceUntaxed();
this.inTaxPrice = stockMoveLine.getUnitPriceTaxed();
this.price = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.price, appBaseService.getNbDecimalDigitForUnitPrice(), product);
this.inTaxPrice = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.inTaxPrice, appBaseService.getNbDecimalDigitForUnitPrice(), product);
invoiceLine.setPrice(price);
invoiceLine.setInTaxPrice(inTaxPrice);
analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
}
return invoiceLine;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountManagementServiceAccountImpl method getProductAccount.
/**
* Get the product tax according to the fiscal position
*
* @param product
* @param company
* @param fiscalPosition
* @param isPurchase Specify if we want get the tax for purchase or sale
* @param fixedAsset Specify if we should get the purchase account for fixed asset or not. Used
* only if isPurchase param is true.
* @return the tax defined for the product, according to the fiscal position
* @throws AxelorException
*/
public Account getProductAccount(Product product, Company company, FiscalPosition fiscalPosition, boolean isPurchase, boolean fixedAsset) throws AxelorException {
log.debug("Get the account for the product {} (company : {}, purchase : {}, fixed asset : {}, fiscal position : {})", new Object[] { product != null ? product.getCode() : null, company.getName(), isPurchase, fixedAsset, fiscalPosition != null ? fiscalPosition.getCode() : null });
Account generalAccount = this.getProductAccount(product, company, isPurchase, fixedAsset, CONFIG_OBJECT_PRODUCT);
Account account = new FiscalPositionAccountServiceImpl().getAccount(fiscalPosition, generalAccount);
if (account != null) {
return account;
}
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNT_MANAGEMENT_1_ACCOUNT), product != null ? product.getCode() : null, company.getName());
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountingCloseAnnualServiceImpl method getAllAccountOfYear.
public List<Long> getAllAccountOfYear(Set<Account> accountSet, Year year) {
List<Long> accountIdList = accountService.getAllAccountsSubAccountIncluded(accountSet.stream().map(Account::getId).collect(Collectors.toList()));
Query q = JPA.em().createQuery("select distinct(self.account.id) FROM MoveLine as self " + "WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year = ?1 AND self.account.id in (?2) " + "AND self.move.statusSelect = ?3 AND self.move.autoYearClosureMove is not true", Long.class);
q.setParameter(1, year);
q.setParameter(2, accountIdList);
q.setParameter(3, MoveRepository.STATUS_VALIDATED);
List<Long> result = q.getResultList();
return result;
}
Aggregations