Returns a line based on a "order total line".

@param array $line
The total line.
@param bool $exVat
Whether the value in this line is ex (true) or inc (false) vat.

@return array
An Acumulus invoice line.

@throws \Exception
772483
protected function getTotalLine(array $line, $exVat)
    {
        $result = array(
            Tag::Product => $line['title'],
            Tag::Quantity => 1,
        );
        if ($exVat) {
            $result[Tag::UnitPrice] = $line['value'];
        } else {
            $result[Meta::UnitPriceInc] = $line['value'];
        }

        if ($line['code'] === 'voucher') {
            // A voucher is to be seen as a partial payment, thus no tax.
            $result += array(
                Tag::VatRate => -1,
                Meta::VatRateSource => Creator::VatRateSource_Exact0,
            );
        } elseif ($line['code'] === 'coupon') {
            // Coupons may have to be split over various taxes.
            $result += array(
                Tag::VatRate => null,
                Meta::VatRateSource => Creator::VatRateSource_Strategy,
                Meta::StrategySplit => $line['code'] === 'coupon',
            );
        } else {
            // Try to get a vat rate.
            $vatRateLookupMetaData = $this->getVatRateLookupByTotalLineType($line['code']);
            // The completor will add the looked up vat rate based on looked up
            // or just the highest appearing vat rate, or wil pass it to the
            // strategy phase.
            $result += array(
                Tag::VatRate => null,
                Meta::VatRateSource => Creator::VatRateSource_Completor,
                Meta::StrategySplit => false,
            ) + $vatRateLookupMetaData;
        }

        return $result;
    }
154395
public static function runLexer($line) {
		$tokens = array();
		$offset = 0;
		while($offset < strlen($line)) {
			$result = static::_match($line, $offset);
			if($result === false) {
				throw new MoufException("Unable to parse line '".$line."'.");
			}
			$tokens[] = $result;
			$offset += strlen($result['match']);
		}
		 
		return $tokens;
	}
952005
public function update(array $data, $line)
    {
        if( is_integer($line) )
        {
            $line = array('Id' => $line);
        }

        foreach( $data as $name => $value )
        {
            if( is_null($value) )
                continue;

            switch( strtolower($name) )
            {
                case 'description':
                    $this->description($line, $value);
                    break;
                case 'price':
                    $this->price($line, $value);
                    break;
                case 'discount':
                    $this->discount($line, $value);
                    break;
                case 'qty':
                    $this->qty($line, $value);
                    break;
                case 'unit':
                    $this->unit($line, $value);
                    break;
            }
        }

        return $this->getArrayFromHandles( array('CurrentInvoiceLineHandle'=>$line) );
    }
834891
public function addLine(string $line): Source
    {
        if (strpos($line, "\n") !== false) {
            throw new MultilineException(
                "New line character is forbidden in addLine method argument"
            );
        }

        $this->lines[] = $line;

        return $this;
    }
980985
function order($expr, $direction = \Sirel\Node\Order::ASC)
    {
        return $this->from()->order($expr, $direction);
    }
570735
protected function getDiscountLinesOrder()
    {
        $result = array();

        foreach ($this->order->getCartRules() as $line) {
            $result[] = $this->getDiscountLineOrder($line);
        }

        return $result;
    }
1050360
public function populateFromOrderLine(OrderLineInterface $orderLine)
    {
        if (!$orderLine->getProduct()) {
            throw new UnsetProductException('No product set on order line with product number: '.$orderLine->getProductNumber());
        }

        $created = new \DateTime($orderLine->getOrder()->getCreatedDate()->format(\DateTime::ATOM));

        $this
            ->setQuantity(-1 * $orderLine->getQuantity()) // we multiply by -1 because we count an order as 'outgoing' from the stock
            ->setPrice($orderLine->getUnitPriceExclVat())
            ->setVatPercentage((string)$orderLine->getVatPct())
            ->setType(static::TYPE_SALE)
            ->setProduct($orderLine->getProduct())
            ->setOrderLine($orderLine)
            ->setReference('Order '.$orderLine->getOrder()->getExternalId())
            ->setCreatedAt($created) // for order lines we specifically override the createdAt and updatedAt dates because the stock movement is actually happening when the order comes in and not when the order is synced
        ;

        $retailPrice = $orderLine->getProduct()->findPriceByCurrency($orderLine->getUnitPrice()->getCurrency());
        if ($retailPrice) {
            $retailPrice = $retailPrice->getUnitPriceExclVat($orderLine->getVatPct());
        } else {
            $retailPrice = $orderLine->getUnitPriceExclVat();
        }

        $this->setRetailPrice($retailPrice);
    }
992119
public function order($expr)
    {
        $matches = array();

        $expr = (array)$expr;

        $result = array();

        foreach($expr as $e) {
            // basic syntax, with asc/desc suffix
            if (preg_match('/([a-z_0-9.]+) (asc|desc)$/i', $e)) {
                $result[] = $e;
            } else if (preg_match('/([\+\-]?)([a-z_0-9.]+)/i', $e, $matches)) {

                // alternative syntax - with +/- prefix
                $subResult = $matches[2];
                if ($matches[1] == '' || $matches[1] == '+') {
                    $subResult .= ' asc';
                } else {
                    $subResult .= ' desc';
                }
                $result[] = $subResult;
            } else {
                // something which should never happen but take care [;
                throw new \RuntimeException('Cannot understand ordering expression', ResourceException::ORDER_NOT_SUPPORTED);
            }
        }

        $this->order = $result;

    }
126287
public function with($line)
    {
        if ($line instanceof Action) {
            $this->action($line->text, $line->url);
        } else if (is_null($this->actionText)) {
            $this->introLines[] = $this->format($line);
        } else {
            $this->outroLines[] = $this->format($line);
        }

        return $this;
    }
1018955
public function analyseUNH(array $line)
    {
        if (\count($line) < 3) {
            return;
        }

        $lineElement = $line[2];
        if (!\is_array($lineElement)) {
            $this->messageFormat = $lineElement;

            return;
        }

        $this->messageFormat = $lineElement[0];
        $this->messageDirectory = $lineElement[2];
    }
670604
public function write($line)
    {
        return $this->pipes !== null ? fwrite($this->pipes[0], $line . PHP_EOL) : false;
    }
765198
public function invoices($code = null)
    {
        if (! $code) {
            $code = $this->data->code;
        }

        return $this->client->get('/{code}/invoices', [$code])
                            ->setDataKey('invoices')
                            ->getResults();
    }
382794
public static function fromLine($line, array $lineOptions)
    {
        $line = \json_decode($line, true);
        $method = Inflector::camelize($line['type']) . 'FromLine';
        if (\method_exists(\get_class(new static()), $method) && $method !== 'FromLine') {
            return static::$method($line, $lineOptions);
        }

        throw new \Exception('Unknown message type: ' . $line['type']);
    }
1122883
protected function splitLine($line)
    {
        $chunks = explode(';', $line);
        if (count($chunks) !== 6) {
            throw new InvalidValueException('Line "' . $line . '" is malformed');
        }

        return array_map('trim', $chunks);
    }
999451
public function getExcerptStart($line)
    {
        if ($this->isExcerptOnly() === false) {
            return 1;
        }

        return max(1, $line - floor($this->getExcerptSize() / 2));
    }
1204778
public function filterEmptyLines(array $lines)
    {
        return array_filter($lines, function ($line) {
            $line = trim($line);

            return $line !== '*' ? $line : false;
        });
    }
619772
public function line($line = '', $params = null)
    {
        if (empty($params)) {
            return parent::line($line);
        }

        //  We have some parameters, sub 'em in or the unicorns will die.
        $line = parent::line($line);

        if ($line !== false) {

            if (is_array($params)) {

                $line = vsprintf($line, $params);

            } else {

                $line = sprintf($line, $params);
            }
        }

        return $line;
    }