@param Money    $total
@param Discount $discount

@return Money
324290
protected function subtractPercentageDiscount(Money $total, Discount $discount): Money
    {
        return $total->subtract($total->multiply($discount->rate()->int() / 100));
    }
613575
public function getPrice($price, $discount, $request)
    {
        if(!$this->isValid($discount, $request))
            throw new Discount_Exception_InvalidDiscount();
        $newPrice = $price - ($price * $discount->off_value / 100);
        return $newPrice;
    }
822668
public function formatAmount(Money $money, $decPoint = ',', $thousandsSep = ' ')
    {
        return $this->moneyFormatter->formatAmount($money, $decPoint, $thousandsSep);
    }
1269280
public function setDiscountPrice($discount_price) {
        if($this->setModified('discount_price', $discount_price)->isModified()) {
            $this->discount_price = $discount_price;
        }

        return $this;
    }
62862
protected function transformAmount($amount = '', $currency = '')
    {
        if (!empty($amount) && !empty($currency)) {
            return \Genesis\Utils\Currency::amountToExponent($amount, $currency);
        }

        return false;
    }
935179
private function _checkDiscount(&$discount)
    {
        if (!isset($discount)) {
            throw new Klarna_ArgumentNotSetException("Discount");
        }
        if (is_numeric($discount)
            && (!is_int($discount) || !is_float($discount))
        ) {
            $discount = floatval($discount);
        }

        if (!is_numeric($discount)
            || (!is_int($discount) && !is_float($discount))
        ) {
            throw new Klarna_InvalidTypeException("Discount", "integer or float");
        }
    }
167213
public function maxDiscount($maxDiscount, $discount, $throwErrors = true)
    {
        if ($maxDiscount == 0 || $maxDiscount > $discount) {
            return $discount;
        } else {
            if ($throwErrors) {
                throw new CouponException('This has a max discount of '.\App::make(\LukePOLO\Laracart\LaraCart::SERVICE)->formatMoney($maxDiscount));
            } else {
                return $maxDiscount;
            }
        }
    }
684096
public function formatMoney(Money $money, $decPoint = ',', $thousandsSep = ' ')
    {
        $symbol = $this->formatCurrency($money);
        $amount = $this->formatAmount($money, $decPoint, $thousandsSep);
        $price = $amount." ".$symbol;

        return $price;
    }
587913
static function discountPercent( $user, $params )
    {
        $bestMatch = 0.0;

        if ( is_object( $user ) )
        {
            $groups = $user->groups();
            $idArray = array_merge( $groups, array( $user->attribute( 'contentobject_id' ) ) );

            // Fetch discount rules for the current user
            $rules = eZUserDiscountRule::fetchByUserIDArray( $idArray );

            if ( count( $rules ) > 0 )
            {
                $db = eZDB::instance();

                $i = 1;
                $subRuleStr = '';
                foreach ( $rules as $rule )
                {
                    $subRuleStr .= $rule->attribute( 'id' );
                    if ( $i < count( $rules ) )
                        $subRuleStr .= ', ';
                    $i++;
                }

                // Fetch the discount sub rules
                $subRules = $db->arrayQuery( "SELECT * FROM
                                       ezdiscountsubrule
                                       WHERE discountrule_id IN ( $subRuleStr )
                                       ORDER BY discount_percent DESC" );

                // Find the best matching discount rule
                foreach ( $subRules as $subRule )
                {
                    if ( $subRule['discount_percent'] > $bestMatch )
                    {
                        // Rule has better discount, see if it matches
                        if ( $subRule['limitation'] == '*' )
                            $bestMatch = $subRule['discount_percent'];
                        else
                        {
                            // Do limitation check
                            $limitationArray = $db->arrayQuery( "SELECT * FROM
                                       ezdiscountsubrule_value
                                       WHERE discountsubrule_id='" . $subRule['id']. "'" );

                            $hasSectionLimitation = false;
                            $hasClassLimitation = false;
                            $hasObjectLimitation = false;
                            $objectMatch = false;
                            $sectionMatch = false;
                            $classMatch = false;
                            foreach ( $limitationArray as $limitation )
                            {
                                if ( $limitation['issection'] == '1' )
                                {
                                    $hasSectionLimitation = true;

                                    if ( isset( $params['section_id'] ) && $params['section_id'] == $limitation['value'] )
                                        $sectionMatch = true;
                                }
                                elseif ( $limitation['issection'] == '2' )
                                {
                                    $hasObjectLimitation = true;

                                    if ( isset( $params['contentobject_id'] ) && $params['contentobject_id'] == $limitation['value'] )
                                        $objectMatch = true;
                                }
                                else
                                {
                                    $hasClassLimitation = true;
                                    if ( isset( $params['contentclass_id'] ) && $params['contentclass_id'] == $limitation['value'] )
                                        $classMatch = true;
                                }
                            }

                            $match = true;
                            if ( ( $hasClassLimitation == true ) and ( $classMatch == false ) )
                                $match = false;

                            if ( ( $hasSectionLimitation == true ) and ( $sectionMatch == false ) )
                                $match = false;

                            if ( ( $hasObjectLimitation == true ) and ( $objectMatch == false ) )
                                $match = false;

                            if ( $match == true  )
                                $bestMatch = $subRule['discount_percent'];
                        }
                    }
                }
            }
        }
        return $bestMatch;
    }
747838
public function get($priceRuleId, $discountCodeId)
    {
        $endpoint = '/admin/price_rules/'.$priceRuleId.'/discount_codes/'.$discountCodeId.'.json';
        $response = $this->request($endpoint);
        return $this->createObject(DiscountCode::class, $response['discount_code']);
    }
1171784
private function createMoney($amount, $currency) { $precision = isset($this->config[$currency]) ? $this->config[$currency]['precision'] : 2;
        return new Money($amount, new Currency($currency, $precision));
    }
685858
public function getAmount(MoneyInterface $money = null, $currency = null)
    {
        if (null === $money) {
            return 0.0;
        }

        $reduced = $this->bank->reduce($money, $currency);

        return $reduced->getAmount();
    }
1354795
public function getTotal(string $defaultCurrency = 'DKK') : Money
    {
        $total = null;

        foreach ($this->stockMovements as $stockMovement) {
            if (!$total) {
                $total = new Money(0, new Currency($stockMovement->getCurrency()));
            }

            $total = $total->add($stockMovement->getPrice()->multiply($stockMovement->getQuantity()));
        }

        if (!$total) {
            $total = new Money(0, new Currency($defaultCurrency));
        }

        return $total;
    }
459165
public function formatAmount(Money $money, $decPoint = ',', $thousandsSep = ' ')
    {
        $amount = $this->asFloat($money);
        $amount = number_format($amount, $this->decimals, $decPoint, $thousandsSep);

        return $amount;
    }
500312
public function addInstallmentCheckoutPreferences($quantity, $discountValue = 0, $additionalValue = 0)
    {
        $installmentPreferences = new stdClass();
        $installmentPreferences->quantity = $quantity;
        $installmentPreferences->discount = $discountValue;
        $installmentPreferences->addition = $additionalValue;

        $this->data->checkoutPreferences->installments[] = $installmentPreferences;

        return $this;
    }
980162
public function add(Money $money)
  {
    if($this->isSameCurrency($money))
    {
      return Money::init($this->cents + $money->cents, $this->currency->getIsoCode());
    }

    throw new InvalidCurrencyException("You can't add two Money objects with different currencies");
  }
1230425
public function multiply(
        Money $money,
        $fraction
    ): Money {
        return new Money(
            $money->getAmount() * $fraction,
            $money->getCurrency()
        );
    }