use of com.axelor.apps.account.service.invoice.InvoiceLineService in project axelor-open-suite by axelor.
the class InvoiceLineController method compute.
public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
if (invoice == null || invoiceLine.getPrice() == null || invoiceLine.getInTaxPrice() == null || invoiceLine.getQty() == null) {
return;
}
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
BigDecimal exTaxTotal;
BigDecimal companyExTaxTotal;
BigDecimal inTaxTotal;
BigDecimal companyInTaxTotal;
BigDecimal priceDiscounted = invoiceLineService.computeDiscount(invoiceLine, invoice.getInAti());
response.setValue("priceDiscounted", priceDiscounted);
response.setAttr("priceDiscounted", "hidden", priceDiscounted.compareTo(invoice.getInAti() ? invoiceLine.getInTaxPrice() : invoiceLine.getPrice()) == 0);
BigDecimal taxRate = BigDecimal.ZERO;
if (invoiceLine.getTaxLine() != null) {
taxRate = invoiceLine.getTaxLine().getValue();
response.setValue("taxRate", taxRate);
response.setValue("taxCode", invoiceLine.getTaxLine().getTax().getCode());
}
if (!invoice.getInAti()) {
exTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
} else {
inTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
}
companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
response.setValue("exTaxTotal", exTaxTotal);
response.setValue("inTaxTotal", inTaxTotal);
response.setValue("companyInTaxTotal", companyInTaxTotal);
response.setValue("companyExTaxTotal", companyExTaxTotal);
}
use of com.axelor.apps.account.service.invoice.InvoiceLineService in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoInvoiceLine.
protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
Invoice intercoInvoice = invoiceLine.getInvoice();
Partner partner = intercoInvoice.getPartner();
if (intercoInvoice.getCompany() != null) {
Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
invoiceLine.setAccount(account);
TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
if (invoiceLine.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
}
}
return invoiceLine;
}
use of com.axelor.apps.account.service.invoice.InvoiceLineService in project axelor-open-suite by axelor.
the class InvoiceLineController method updateQty.
public List<InvoiceLine> updateQty(List<InvoiceLine> invoiceLines, BigDecimal oldKitQty, BigDecimal newKitQty, Invoice invoice) throws AxelorException {
BigDecimal qty = BigDecimal.ZERO;
BigDecimal exTaxTotal = BigDecimal.ZERO;
BigDecimal companyExTaxTotal = BigDecimal.ZERO;
BigDecimal inTaxTotal = BigDecimal.ZERO;
BigDecimal companyInTaxTotal = BigDecimal.ZERO;
BigDecimal priceDiscounted = BigDecimal.ZERO;
BigDecimal taxRate = BigDecimal.ZERO;
AppBaseService appBaseService = Beans.get(AppBaseService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
int scale = appBaseService.getNbDecimalDigitForQty();
if (invoiceLines != null) {
if (newKitQty.compareTo(BigDecimal.ZERO) != 0) {
for (InvoiceLine line : invoiceLines) {
qty = (line.getQty().divide(oldKitQty, scale, RoundingMode.HALF_UP)).multiply(newKitQty).setScale(scale, RoundingMode.HALF_UP);
priceDiscounted = invoiceLineService.computeDiscount(line, invoice.getInAti());
if (line.getTaxLine() != null) {
taxRate = line.getTaxLine().getValue();
}
if (!invoice.getInAti()) {
exTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
} else {
inTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
}
companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
line.setQty(qty);
line.setExTaxTotal(exTaxTotal);
line.setCompanyExTaxTotal(companyExTaxTotal);
line.setInTaxTotal(inTaxTotal);
line.setCompanyInTaxTotal(companyInTaxTotal);
line.setPriceDiscounted(priceDiscounted);
line.setTaxRate(taxRate);
}
} else {
for (InvoiceLine line : invoiceLines) {
line.setQty(qty);
}
}
}
return invoiceLines;
}
use of com.axelor.apps.account.service.invoice.InvoiceLineService 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;
}
Aggregations