use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoiceLines.
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<PurchaseOrderLine> purchaseOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
if (qtyToInvoiceMap.containsKey(purchaseOrderLine.getId())) {
List<InvoiceLine> invoiceLines = this.createInvoiceLine(invoice, purchaseOrderLine, qtyToInvoiceMap.get(purchaseOrderLine.getId()));
invoiceLineList.addAll(invoiceLines);
purchaseOrderLine.setInvoiced(true);
}
}
return invoiceLineList;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoice.
@Override
public Invoice createInvoice(PurchaseOrder purchaseOrder) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(purchaseOrder);
Invoice invoice = invoiceGenerator.generate();
List<InvoiceLine> invoiceLineList = this.createInvoiceLines(invoice, purchaseOrder.getPurchaseOrderLineList());
invoiceGenerator.populate(invoice, invoiceLineList);
invoice.setPurchaseOrder(purchaseOrder);
return invoice;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class ContractServiceImpl method invoicingContract.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice invoicingContract(Contract contract) throws AxelorException {
Invoice invoice = generateInvoice(contract);
InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
invoiceRepository.save(invoice);
// Compute all additional lines
List<ContractLine> additionalLines = contract.getAdditionalBenefitContractLineList().stream().filter(contractLine -> !contractLine.getIsInvoiced()).peek(contractLine -> contractLine.setIsInvoiced(true)).collect(Collectors.toList());
for (ContractLine line : additionalLines) {
InvoiceLine invLine = generate(invoice, line);
invLine.setContractLine(line);
contractLineRepo.save(line);
}
// Compute all classic contract lines
for (ContractVersion version : getVersions(contract)) {
BigDecimal ratio = BigDecimal.ONE;
if (contract.getCurrentContractVersion().getIsTimeProratedInvoice()) {
if (isFullProrated(contract) && !DateTool.isProrata(contract.getInvoicePeriodStartDate(), contract.getInvoicePeriodEndDate(), version.getActivationDate(), version.getEndDate())) {
continue;
}
LocalDate start = version.getActivationDate().isBefore(contract.getInvoicePeriodStartDate()) ? contract.getInvoicePeriodStartDate() : version.getActivationDate();
LocalDate end = version.getEndDate() == null || (version.getEndDate() != null && contract.getInvoicePeriodEndDate().isBefore(version.getEndDate())) ? contract.getInvoicePeriodEndDate() : version.getEndDate();
ratio = durationService.computeRatio(start, end, contract.getCurrentContractVersion().getInvoicingDuration());
}
List<ContractLine> lines = version.getContractLineList().stream().filter(contractLine -> !contractLine.getIsConsumptionLine()).collect(Collectors.toList());
for (ContractLine line : lines) {
ContractLine tmp = contractLineRepo.copy(line, false);
tmp.setAnalyticMoveLineList(line.getAnalyticMoveLineList());
tmp.setQty(tmp.getQty().multiply(ratio).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP));
tmp = this.contractLineService.computeTotal(tmp);
InvoiceLine invLine = generate(invoice, tmp);
invLine.setContractLine(line);
}
}
// Compute all consumption lines
Multimap<ContractLine, ConsumptionLine> consLines = mergeConsumptionLines(contract);
for (Entry<ContractLine, Collection<ConsumptionLine>> entries : consLines.asMap().entrySet()) {
ContractLine line = entries.getKey();
InvoiceLine invoiceLine = generate(invoice, line);
invoiceLine.setContractLine(line);
entries.getValue().stream().peek(cons -> cons.setInvoiceLine(invoiceLine)).forEach(cons -> cons.setIsInvoiced(true));
line.setQty(BigDecimal.ZERO);
contractLineService.computeTotal(line);
}
// Compute invoice
if (invoice.getInvoiceLineList() != null && !invoice.getInvoiceLineList().isEmpty()) {
Beans.get(InvoiceServiceImpl.class).compute(invoice);
}
// Increase invoice period date
increaseInvoiceDates(contract);
return invoiceRepository.save(invoice);
}
use of com.axelor.apps.account.db.InvoiceLine 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);
}
Aggregations