Search in sources :

Example 56 with InvoiceLine

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;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 57 with InvoiceLine

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());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) Query(com.axelor.db.Query) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) EntityHelper(com.axelor.db.EntityHelper) PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) CancelFactory(com.axelor.apps.account.service.invoice.factory.CancelFactory) VentilateFactory(com.axelor.apps.account.service.invoice.factory.VentilateFactory) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) MoveLine(com.axelor.apps.account.db.MoveLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) ValidateFactory(com.axelor.apps.account.service.invoice.factory.ValidateFactory) SaleOrder(com.axelor.apps.sale.db.SaleOrder) InvoiceServiceImpl(com.axelor.apps.account.service.invoice.InvoiceServiceImpl) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) Timetable(com.axelor.apps.supplychain.db.Timetable) Set(java.util.Set) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Currency(com.axelor.apps.base.db.Currency) Objects(java.util.Objects) List(java.util.List) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) AdvancePayment(com.axelor.apps.sale.db.AdvancePayment) Beans(com.axelor.inject.Beans) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AlarmEngineService(com.axelor.apps.base.service.alarm.AlarmEngineService) ObjectUtils(com.axelor.common.ObjectUtils) TimetableRepository(com.axelor.apps.supplychain.db.repo.TimetableRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AdvancePayment(com.axelor.apps.sale.db.AdvancePayment)

Example 58 with InvoiceLine

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;
}
Also used : FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 59 with 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());
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineSupplychainService(com.axelor.apps.supplychain.service.InvoiceLineSupplychainService)

Example 60 with InvoiceLine

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);
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) Address(com.axelor.apps.base.db.Address) AddressService(com.axelor.apps.base.service.AddressService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)80 ArrayList (java.util.ArrayList)36 Invoice (com.axelor.apps.account.db.Invoice)27 BigDecimal (java.math.BigDecimal)22 AxelorException (com.axelor.exception.AxelorException)20 Product (com.axelor.apps.base.db.Product)13 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)12 Transactional (com.google.inject.persist.Transactional)12 Context (com.axelor.rpc.Context)11 Account (com.axelor.apps.account.db.Account)8 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)7 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)5 HashSet (java.util.HashSet)5 List (java.util.List)5