Search in sources :

Example 26 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoicingProjectService method createInvoiceLine.

public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, int priority) throws AxelorException {
    Product product = purchaseOrderLine.getProduct();
    InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), priority, 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();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product)

Example 27 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoicingProjectService method populate.

public List<InvoiceLine> populate(Invoice invoice, InvoicingProject folder) throws AxelorException {
    List<SaleOrderLine> saleOrderLineList = new ArrayList<SaleOrderLine>(folder.getSaleOrderLineSet());
    List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>(folder.getPurchaseOrderLineSet());
    List<TimesheetLine> timesheetLineList = new ArrayList<TimesheetLine>(folder.getLogTimesSet());
    List<ExpenseLine> expenseLineList = new ArrayList<ExpenseLine>(folder.getExpenseLineSet());
    List<ProjectTask> projectTaskList = new ArrayList<ProjectTask>(folder.getProjectTaskSet());
    List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
    invoiceLineList.addAll(this.createSaleOrderInvoiceLines(invoice, saleOrderLineList, folder.getSaleOrderLineSetPrioritySelect()));
    invoiceLineList.addAll(this.createPurchaseOrderInvoiceLines(invoice, purchaseOrderLineList, folder.getPurchaseOrderLineSetPrioritySelect()));
    invoiceLineList.addAll(timesheetService.createInvoiceLines(invoice, timesheetLineList, folder.getLogTimesSetPrioritySelect()));
    invoiceLineList.addAll(expenseService.createInvoiceLines(invoice, expenseLineList, folder.getExpenseLineSetPrioritySelect()));
    invoiceLineList.addAll(projectTaskBusinessProjectService.createInvoiceLines(invoice, projectTaskList, folder.getProjectTaskSetPrioritySelect()));
    Collections.sort(invoiceLineList, new InvoiceLineComparator());
    for (InvoiceLine invoiceLine : invoiceLineList) {
        invoiceLine.setSequence(sequence);
        sequence++;
    }
    return invoiceLineList;
}
Also used : InvoiceLineComparator(com.axelor.apps.account.util.InvoiceLineComparator) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 28 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceServiceSupplychainImpl method computePackTotal.

@Override
public void computePackTotal(Invoice invoice) {
    List<InvoiceLine> invoiceLineList = invoice.getInvoiceLineList();
    if (!invoiceLineService.hasEndOfPackTypeLine(invoiceLineList)) {
        return;
    }
    invoiceLineList.sort(Comparator.comparing(InvoiceLine::getSequence));
    BigDecimal totalExTaxTotal = BigDecimal.ZERO;
    BigDecimal totalInTaxTotal = BigDecimal.ZERO;
    for (InvoiceLine invoiceLine : invoiceLineList) {
        switch(invoiceLine.getTypeSelect()) {
            case InvoiceLineRepository.TYPE_NORMAL:
                totalExTaxTotal = totalExTaxTotal.add(invoiceLine.getExTaxTotal());
                totalInTaxTotal = totalInTaxTotal.add(invoiceLine.getInTaxTotal());
                break;
            case InvoiceLineRepository.TYPE_TITLE:
                break;
            case InvoiceLineRepository.TYPE_START_OF_PACK:
                totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
                break;
            case InvoiceLineRepository.TYPE_END_OF_PACK:
                invoiceLine.setQty(BigDecimal.ZERO);
                invoiceLine.setExTaxTotal(invoiceLine.getIsShowTotal() ? totalExTaxTotal : BigDecimal.ZERO);
                invoiceLine.setInTaxTotal(invoiceLine.getIsShowTotal() ? totalInTaxTotal : BigDecimal.ZERO);
                totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
                break;
            default:
                break;
        }
    }
    invoice.setInvoiceLineList(invoiceLineList);
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal)

Example 29 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiIncomingStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList) throws AxelorException {
    if (stockMoveList == null || stockMoveList.isEmpty()) {
        return Optional.empty();
    }
    // create dummy invoice from the first stock move
    Invoice dummyInvoice = createDummyInInvoice(stockMoveList.get(0));
    // Check if field constraints are respected
    for (StockMove stockMove : stockMoveList) {
        completeInvoiceInMultiIncomingStockMove(dummyInvoice, stockMove);
    }
    /*  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()));
    }
    fillReferenceInvoiceFromMultiInStockMove(stockMoveList, dummyInvoice);
    InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE, 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(), null) {

        @Override
        public Invoice generate() throws AxelorException {
            return super.createInvoiceHeader();
        }
    };
    Invoice invoice = invoiceGenerator.generate();
    invoice.setAddressStr(dummyInvoice.getAddressStr());
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    for (StockMove stockMoveLocal : stockMoveList) {
        List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
        if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
            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_SUPPLIER_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) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 30 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceLineController method getInvoice.

public Invoice getInvoice(Context context) {
    Context parentContext = context.getParent();
    Invoice invoice = parentContext.asType(Invoice.class);
    if (!parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
        InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
        invoice = invoiceLine.getInvoice();
    }
    return invoice;
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

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