Invoice/Builder/InvoiceBuilder.php
public function findOrCreateGoodLine(
        Invoice\InvoiceInterface $invoice,
        Common\SaleItemInterface $item,
        $available,
        $expected = null
    ) {
        $line = null;

        if (0 >= $available) {
            return $line;
        }

        // Existing line lookup
        foreach ($invoice->getLinesByType(Document\DocumentLineTypes::TYPE_GOOD) as $invoiceLine) {
            if ($invoiceLine->getSaleItem() === $item) {
                $line = $invoiceLine;
            }
        }

        // Not found, create it
        if (null === $line) {
            $line = $this->createLine($invoice);
            $line
                ->setInvoice($invoice)
                ->setType(Document\DocumentLineTypes::TYPE_GOOD)
                ->setSaleItem($item)
                ->setDesignation($item->getDesignation())
                ->setDescription($item->getDescription())
                ->setReference($item->getReference());
        }

        // Set available and expected quantity
        $line->setAvailable($available);
        $line->setExpected($expected);

        if (Invoice\InvoiceTypes::isInvoice($invoice) && null === $invoice->getId()) {
            // Set default quantity for new non return shipment items
            $line->setQuantity(min($expected, $available));
        }

        return $line;
    }
public function findOrCreateGoodLine(
        Invoice\InvoiceInterface $invoice,
        Common\SaleItemInterface $item,
        $available,
        $expected = null
    ) {
        $line = null;

        if (0 >= $available) {
            return $line;
        }

        // Existing line lookup
        foreach ($invoice->getLinesByType(Document\DocumentLineTypes::TYPE_GOOD) as $invoiceLine) {
            if ($invoiceLine->getSaleItem() === $item) {
                $line = $invoiceLine;
            }
        }

        // Not found, create it
        if (null === $line) {
            $line = $this->createLine($invoice);
            $line
                ->setInvoice($invoice)
                ->setType(Document\DocumentLineTypes::TYPE_GOOD)
                ->setSaleItem($item)
                ->setDesignation($item->getDesignation())
                ->setDescription($item->getDescription())
                ->setReference($item->getReference());
        }

        // Set available and expected quantity
        $line->setAvailable($available);
        $line->setExpected($expected);

        if (Invoice\InvoiceTypes::isInvoice($invoice) && null === $invoice->getId()) {
            // Set default quantity for new non return shipment items
            $line->setQuantity(min($expected, $available));
        }

        return $line;
    }
Finds or create the invoice line.

@param Invoice\InvoiceInterface $invoice
@param Common\SaleItemInterface $item
@param float                    $available
@param float                    $expected

@return Invoice\InvoiceLineInterface