use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method autoTaxLineGenerate.
@Override
public void autoTaxLineGenerate(Move move) throws AxelorException {
List<MoveLine> moveLineList = move.getMoveLineList();
moveLineList.sort(new Comparator<MoveLine>() {
@Override
public int compare(MoveLine o1, MoveLine o2) {
if (o2.getSourceTaxLine() != null) {
return 0;
}
return -1;
}
});
Iterator<MoveLine> moveLineItr = moveLineList.iterator();
Map<String, MoveLine> map = new HashMap<>();
Map<String, MoveLine> newMap = new HashMap<>();
while (moveLineItr.hasNext()) {
MoveLine moveLine = moveLineItr.next();
TaxLine taxLine = moveLine.getTaxLine();
TaxLine sourceTaxLine = moveLine.getSourceTaxLine();
if (sourceTaxLine != null) {
String sourceTaxLineKey = moveLine.getAccount().getCode() + sourceTaxLine.getId();
moveLine.setCredit(BigDecimal.ZERO);
moveLine.setDebit(BigDecimal.ZERO);
map.put(sourceTaxLineKey, moveLine);
moveLineItr.remove();
continue;
}
if (taxLine != null) {
String accountType = moveLine.getAccount().getAccountType().getTechnicalTypeSelect();
if (accountType.equals(AccountTypeRepository.TYPE_DEBT) || accountType.equals(AccountTypeRepository.TYPE_CHARGE) || accountType.equals(AccountTypeRepository.TYPE_INCOME) || accountType.equals(AccountTypeRepository.TYPE_ASSET)) {
BigDecimal debit = moveLine.getDebit();
BigDecimal credit = moveLine.getCredit();
LocalDate date = moveLine.getDate();
Company company = move.getCompany();
MoveLine newOrUpdatedMoveLine = new MoveLine();
if (accountType.equals(AccountTypeRepository.TYPE_DEBT) || accountType.equals(AccountTypeRepository.TYPE_CHARGE)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, true, false));
} else if (accountType.equals(AccountTypeRepository.TYPE_INCOME)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, false, false));
} else if (accountType.equals(AccountTypeRepository.TYPE_ASSET)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, true, true));
}
Account newAccount = newOrUpdatedMoveLine.getAccount();
if (newAccount == null) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), taxLine.getName(), company.getName());
}
String newSourceTaxLineKey = newAccount.getCode() + taxLine.getId();
if (!map.containsKey(newSourceTaxLineKey) && !newMap.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = this.createNewMoveLine(debit, credit, date, accountType, taxLine, newOrUpdatedMoveLine);
} else {
if (newMap.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = newMap.get(newSourceTaxLineKey);
} else if (!newMap.containsKey(newSourceTaxLineKey) && map.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = map.get(newSourceTaxLineKey);
}
newOrUpdatedMoveLine.setDebit(newOrUpdatedMoveLine.getDebit().add(debit.multiply(taxLine.getValue())));
newOrUpdatedMoveLine.setCredit(newOrUpdatedMoveLine.getCredit().add(credit.multiply(taxLine.getValue())));
}
newMap.put(newSourceTaxLineKey, newOrUpdatedMoveLine);
}
}
}
moveLineList.addAll(newMap.values());
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
BigDecimal hundred = new BigDecimal(100);
for (HashMap<String, Object> data : dataList) {
LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
boolean isDebit = false;
Partner debitPartner = null;
Partner creditPartner = null;
BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
Partner partner = null;
if (data.get("debitPartner") != null) {
debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
partner = debitPartner;
}
if (data.get("creditPartner") != null) {
creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
partner = creditPartner;
}
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
partner = null;
if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
isDebit = true;
if (moveTemplateLine.getHasPartnerToDebit()) {
partner = debitPartner;
}
} else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
isDebit = false;
if (moveTemplateLine.getHasPartnerToCredit()) {
partner = creditPartner;
}
}
BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class ContractLineServiceImpl method compute.
@Override
public ContractLine compute(ContractLine contractLine, Contract contract, Product product) throws AxelorException {
Preconditions.checkNotNull(contract, I18n.get("Contract can't be " + "empty for compute contract line price."));
Preconditions.checkNotNull(product, "Product can't be " + "empty for compute contract line price.");
// TODO: maybe put tax computing in another method
contractLine.setFiscalPosition(contract.getPartner().getFiscalPosition());
TaxLine taxLine = accountManagementService.getTaxLine(appBaseService.getTodayDate(contract.getCompany()), product, contract.getCompany(), contractLine.getFiscalPosition(), false);
contractLine.setTaxLine(taxLine);
if (taxLine != null && (Boolean) productCompanyService.get(product, "inAti", contract.getCompany())) {
BigDecimal price = contractLine.getPrice();
price = price.divide(taxLine.getValue().add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
contractLine.setPrice(price);
}
BigDecimal price = contractLine.getPrice();
BigDecimal convert = currencyService.getCurrencyConversionRate((Currency) productCompanyService.get(product, "saleCurrency", contract.getCompany()), contract.getCurrency(), appBaseService.getTodayDate(contract.getCompany()));
contractLine.setPrice(price.multiply(convert));
return contractLine;
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method updateInTaxPrice.
/**
* Update the in. tax unit price of an invoice line from its ex. tax unit price.
*
* @param request
* @param response
*/
public void updateInTaxPrice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
try {
BigDecimal exTaxPrice = purchaseOrderLine.getPrice();
TaxLine taxLine = purchaseOrderLine.getTaxLine();
response.setValue("inTaxPrice", Beans.get(PurchaseOrderLineService.class).convertUnitPrice(false, taxLine, exTaxPrice));
} catch (Exception e) {
response.setFlash(e.getMessage());
}
}
Aggregations