use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceServiceSupplychainImpl method updateProductQtyWithPackHeaderQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice updateProductQtyWithPackHeaderQty(Invoice invoice) throws AxelorException {
List<InvoiceLine> invoiceLineList = invoice.getInvoiceLineList();
invoiceLineList.sort(Comparator.comparing(InvoiceLine::getSequence));
boolean isStartOfPack = false;
BigDecimal oldQty = BigDecimal.ZERO;
BigDecimal newQty = BigDecimal.ZERO;
for (InvoiceLine invoiceLine : invoiceLineList) {
if (invoiceLine.getTypeSelect() == InvoiceLineRepository.TYPE_START_OF_PACK && !isStartOfPack) {
InvoiceLine oldInvoiceLine = invoiceLineRepo.find(invoiceLine.getId());
oldQty = oldInvoiceLine.getQty();
newQty = invoiceLine.getQty();
if (newQty.compareTo(oldQty) != 0) {
isStartOfPack = true;
oldInvoiceLine = EntityHelper.getEntity(invoiceLine);
oldInvoiceLine.setSubLineList(invoiceLine.getSubLineList());
invoiceLineRepo.save(oldInvoiceLine);
}
} else if (isStartOfPack) {
if (invoiceLine.getTypeSelect() == InvoiceLineRepository.TYPE_END_OF_PACK) {
break;
}
invoiceLineService.updateProductQty(invoiceLine, invoice, oldQty, newQty);
}
}
return invoice;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceServiceSupplychainImpl method getMoveLinesFromSOAdvancePayments.
@Override
public List<MoveLine> getMoveLinesFromSOAdvancePayments(Invoice invoice) {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return super.getMoveLinesFromSOAdvancePayments(invoice);
}
// search sale order in the invoice
SaleOrder saleOrder = invoice.getSaleOrder();
// search sale order in invoice lines
List<SaleOrder> saleOrderList = invoice.getInvoiceLineList().stream().map(invoiceLine -> invoice.getSaleOrder()).collect(Collectors.toList());
saleOrderList.add(saleOrder);
// remove null value and duplicates
saleOrderList = saleOrderList.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (saleOrderList.isEmpty()) {
return new ArrayList<>();
} else {
// get move lines from sale order
return saleOrderList.stream().flatMap(saleOrder1 -> saleOrder1.getAdvancePaymentList().stream()).filter(Objects::nonNull).distinct().map(AdvancePayment::getMove).filter(Objects::nonNull).distinct().flatMap(move -> moveToolService.getToReconcileCreditMoveLines(move).stream()).collect(Collectors.toList());
}
}
use of com.axelor.apps.account.db.InvoiceLine 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.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceLineController method computeBudgetDistributionSumAmount.
public void computeBudgetDistributionSumAmount(ActionRequest request, ActionResponse response) {
InvoiceLine invoiceLine = request.getContext().asType(InvoiceLine.class);
Invoice invoice = request.getContext().getParent().asType(Invoice.class);
Beans.get(InvoiceLineSupplychainService.class).computeBudgetDistributionSumAmount(invoiceLine, invoice);
response.setValue("budgetDistributionSumAmount", invoiceLine.getBudgetDistributionSumAmount());
response.setValue("budgetDistributionList", invoiceLine.getBudgetDistributionList());
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiOutgoingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
Set<Address> deliveryAddressSet = new HashSet<>();
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyOutInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiOutgoingStockMove(dummyInvoice, stockMove);
if (stockMove.getToAddressStr() != null) {
deliveryAddressSet.add(stockMove.getToAddress());
}
}
/* check if some other fields are different and assign a default value */
if (dummyInvoice.getAddress() == null) {
dummyInvoice.setAddress(Beans.get(PartnerService.class).getInvoicingAddress(dummyInvoice.getPartner()));
dummyInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(dummyInvoice.getAddress()));
}
fillReferenceInvoiceFromMultiOutStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, dummyInvoice.getCompany(), dummyInvoice.getPaymentCondition(), dummyInvoice.getPaymentMode(), dummyInvoice.getAddress(), dummyInvoice.getPartner(), dummyInvoice.getContactPartner(), dummyInvoice.getCurrency(), dummyInvoice.getPriceList(), dummyInvoice.getInternalReference(), dummyInvoice.getExternalReference(), dummyInvoice.getInAti(), null, dummyInvoice.getTradingName(), dummyInvoice.getGroupProductsOnPrintings()) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setPartnerTaxNbr(partner.getTaxNbr());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
StringBuilder deliveryAddressStr = new StringBuilder();
AddressService addressService = Beans.get(AddressService.class);
for (Address address : deliveryAddressSet) {
deliveryAddressStr.append(addressService.computeAddressStr(address).replaceAll("\n", ", ") + "\n");
}
invoice.setDeliveryAddressStr(deliveryAddressStr.toString());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
stockMoveInvoiceService.checkSplitSalePartiallyInvoicedStockMoveLines(stockMoveLocal, stockMoveLocal.getStockMoveLineList());
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
createdInvoiceLines.forEach(this::negateInvoiceLinePrice);
}
invoiceLineList.addAll(createdInvoiceLines);
}
invoiceGenerator.populate(invoice, invoiceLineList);
invoiceRepository.save(invoice);
invoice = toPositivePriceInvoice(invoice);
if (invoice.getExTaxTotal().signum() == 0 && stockMoveList.stream().allMatch(StockMove::getIsReversion)) {
invoice.setOperationTypeSelect(InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
Aggregations