Invoked through Ajax; this method calculates the taxed price from the untaxed price, and vice versa.
@since version 2.2
438356
public function priceCalculator()
    {
        $return_price = 0;

        $price      = \floatval($this->getRequest()->query->get('price', 0));
        $product_id = \intval($this->getRequest()->query->get('product_id', 0));
        $action     = $this->getRequest()->query->get('action', ''); // With ot without tax
        $convert    = \intval($this->getRequest()->query->get('convert_from_default_currency', 0));

        if (null !== $product = ProductQuery::create()->findPk($product_id)) {
            if ($action == 'to_tax') {
                $return_price = $this->computePrice($price, 'without_tax', $product);
            } elseif ($action == 'from_tax') {
                $return_price = $this->computePrice($price, 'with_tax', $product);
            } else {
                $return_price = $price;
            }

            if ($convert != 0) {
                $return_price = $price * Currency::getDefaultCurrency()->getRate();
            }
        }

        return new JsonResponse(array('result' => $this->formatPrice($return_price)));
    }
341065
def ajax_recalculate_prices(self):
        
        # When the option "Include and display pricing information" in
        # Bika Setup Accounting tab is not selected
        if not self.show_recalculate_prices():
            return {}

        # The sorted records from the request
        records = self.get_records()

        client = self.get_client()
        bika_setup = api.get_bika_setup()

        member_discount = float(bika_setup.getMemberDiscount())
        member_discount_applies = False
        if client:
            member_discount_applies = client.getMemberDiscountApplies()

        prices = {}
        for n, record in enumerate(records):
            ardiscount_amount = 0.00
            arservices_price = 0.00
            arprofiles_price = 0.00
            arprofiles_vat_amount = 0.00
            arservice_vat_amount = 0.00
            services_from_priced_profile = []

            profile_uids = record.get("Profiles_uid", "").split(",")
            profile_uids = filter(lambda x: x, profile_uids)
            profiles = map(self.get_object_by_uid, profile_uids)
            services = map(self.get_object_by_uid, record.get("Analyses", []))

            # ANALYSIS PROFILES PRICE
            for profile in profiles:
                use_profile_price = profile.getUseAnalysisProfilePrice()
                if not use_profile_price:
                    continue

                profile_price = float(profile.getAnalysisProfilePrice())
                arprofiles_price += profile_price
                arprofiles_vat_amount += profile.getVATAmount()
                profile_services = profile.getService()
                services_from_priced_profile.extend(profile_services)

            # ANALYSIS SERVICES PRICE
            for service in services:
                if service in services_from_priced_profile:
                    continue
                service_price = float(service.getPrice())
                # service_vat = float(service.getVAT())
                service_vat_amount = float(service.getVATAmount())
                arservice_vat_amount += service_vat_amount
                arservices_price += service_price

            base_price = arservices_price + arprofiles_price

            # Calculate the member discount if it applies
            if member_discount and member_discount_applies:
                logger.info("Member discount applies with {}%".format(
                    member_discount))
                ardiscount_amount = base_price * member_discount / 100

            subtotal = base_price - ardiscount_amount
            vat_amount = arprofiles_vat_amount + arservice_vat_amount
            total = subtotal + vat_amount

            prices[n] = {
                "discount": "{0:.2f}".format(ardiscount_amount),
                "subtotal": "{0:.2f}".format(subtotal),
                "vat": "{0:.2f}".format(vat_amount),
                "total": "{0:.2f}".format(total),
            }
            logger.info("Prices for AR {}: Discount={discount} "
                        "VAT={vat} Subtotal={subtotal} total={total}"
                        .format(n, **prices[n]))

        return prices
942675
function (newlySelectedIndexes, newlyUnselectedIndexes) {
            var data = this._data;
            if (newlySelectedIndexes.length === 0 && data.selectedCount === 0) {
                var preselect = this._checkPreselect();
                if (preselect != null) {
                    newlySelectedIndexes = [preselect];
                    this.json.setValue(data.itemsView.items[preselect].value, "selected", true);
                    this.json.setValue(data, "selectedIndex", preselect);
                    this.json.setValue(data, "selectedCount", 1);
                }
            }

            this.$raiseEvent({
                name : "onChange",
                selectedIndexes : newlySelectedIndexes,
                unselectedIndexes : newlyUnselectedIndexes
            });
        }
1235954
public function getTaxTotal(): int
    {
        $taxTotal = 0;

        foreach ($this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT) as $taxAdjustment) {
            $taxTotal += $taxAdjustment->getAmount();
        }

        foreach ($this->units as $unit) {
            $taxTotal += $unit->getTaxTotal();
        }

        return $taxTotal;
    }
650354
public static function TtcToHt($price, $tax, bool $taxIsPercent = false)
    {
        if ($taxIsPercent) {
            $tax = $tax / 100;
        }
        return $price / (1 + $tax);
    }
738590
protected function init()
    {
        $this->obTaxList = TaxCollection::make()->active()->sort();

        $this->bPriceIncludeTax = (bool) Settings::getValue('price_include_tax');
    }
772700
@Override
  public final void process(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    TradingSettings ts = (TradingSettings) pRqVs.get("tradSet");
    Cart cart = this.srvCart.getShoppingCart(pRqVs, pRqDt, true, false);
    CartLn cartLn = null;
    String lnIdStr = pRqDt.getParameter("lnId");
    String quantStr = pRqDt.getParameter("quant");
    String avQuanStr = pRqDt.getParameter("avQuan");
    String unStepStr = pRqDt.getParameter("unStep");
    BigDecimal quant = new BigDecimal(quantStr);
    BigDecimal avQuan = new BigDecimal(avQuanStr);
    if (quant.compareTo(avQuan) == 1) {
      quant = avQuan;
    }
    BigDecimal unStep = new BigDecimal(unStepStr);
    String itIdStr = pRqDt.getParameter("itId");
    String itTypStr = pRqDt.getParameter("itTyp");
    Long itId = Long.valueOf(itIdStr);
    AccSettings as = (AccSettings) pRqVs.get("accSet");
    TaxDestination txRules = this.srvCart
      .revealTaxRules(pRqVs, cart, as);
    EShopItemType itTyp = EShopItemType.class.
      getEnumConstants()[Integer.parseInt(itTypStr)];
    boolean redoPr = false;
    if (lnIdStr != null) { //change quantity
      Long lnId = Long.valueOf(lnIdStr);
      cartLn = findCartItemById(cart, lnId);
    } else { //add
      redoPr = true;
      String uomIdStr = pRqDt.getParameter("uomId");
      Long uomId = Long.valueOf(uomIdStr);
      for (CartLn ci : cart.getItems()) {
        //check for duplicate cause "weird" but accepted request
        if (!ci.getDisab() && ci.getItTyp().equals(itTyp)
          && ci.getItId().equals(itId)) {
          cartLn = ci;
          break;
        }
      }
      if (cartLn == null) {
        for (CartLn ci : cart.getItems()) {
          if (ci.getDisab()) {
            cartLn = ci;
            cartLn.setDisab(false);
            cartLn.setForc(false);
            cartLn.setSeller(null);
            cartLn.setTxCat(null);
            cartLn.setTxDsc(null);
            break;
          }
        }
      }
      if (cartLn == null) {
        cartLn = createCartItem(cart);
      }
      UnitOfMeasure uom = new UnitOfMeasure();
      uom.setItsId(uomId);
      cartLn.setUom(uom);
      cartLn.setItId(itId);
      cartLn.setItTyp(itTyp);
    }
    if (!cartLn.getForc()) {
      cartLn.setAvQuan(avQuan);
      cartLn.setQuant(quant);
      cartLn.setUnStep(unStep);
      BigDecimal amount = cartLn.getPrice().multiply(cartLn.getQuant()).
        setScale(as.getPricePrecision(), as.getRoundingMode());
      if (ts.getTxExcl()) {
        cartLn.setSubt(amount);
      } else {
        cartLn.setTot(amount);
      }
      this.srvCart.makeCartLine(pRqVs, cartLn, as, ts, txRules, redoPr, true);
      this.srvCart.makeCartTotals(pRqVs, ts, cartLn, as, txRules);
      this.srvCart.hndCartChan(pRqVs, cart, txRules);
    }
    if (txRules != null) {
      pRqDt.setAttribute("txRules", txRules);
    }
    redir(pRqVs, pRqDt);
  }
1263649
def recalculate(self, amount, billing_info):
        
        order = Order(pk=-1)
        order.amount = amount
        order.currency = self.get_currency()
        country = getattr(billing_info, 'country', None)
        if not country is None:
            country = country.code
        tax_number = getattr(billing_info, 'tax_number', None)

        # Calculating tax can be complex task (e.g. VIES webservice call)
        # To ensure that tax calculated on order preview will be the same on final order
        # tax rate is cached for a given billing data (as this value only depends on it)
        tax_session_key = "tax_%s_%s" % (tax_number, country)

        tax = self.request.session.get(tax_session_key)
        if tax is None:
            taxation_policy = getattr(settings, 'PLANS_TAXATION_POLICY', None)
            if not taxation_policy:
                raise ImproperlyConfigured('PLANS_TAXATION_POLICY is not set')
            taxation_policy = import_name(taxation_policy)
            tax = str(taxation_policy.get_tax_rate(tax_number, country))
            # Because taxation policy could return None which clutters with saving this value
            # into cache, we use str() representation of this value
            self.request.session[tax_session_key] = tax

        order.tax = Decimal(tax) if tax != 'None' else None

        return order
151397
public function getTaxList()
    {
        $taxes = ArrayList::create();

        foreach ($this->Items() as $item) {
            $existing = null;
            $rate = $item->Tax();

            if ($rate->exists()) {
                $existing = $taxes->find("ID", $rate->ID);
            }

            if (!$existing) {
                $currency = DBCurrency::create();
                $currency->setValue($item->getTaxTotal());
                $taxes->push(ArrayData::create([
                    "ID" => $rate->ID,
                    "Rate" => $rate,
                    "Total" => $currency
                ]));
            } elseif ($rate && $existing) {
                $existing->Total->setValue(
                    $existing->Total->getValue() + $item->getTaxTotal()
                );
            }
        }

        return $taxes;
    }
1150100
public function it_sets_price_in_createFromValues()
    {
        $this->moneyFactory->createFromValue(10.10)->willReturn($this->createMoney(1010));
        $this->moneyFactory->createFromValue(2.2)->willReturn($this->createMoney(220));

        $price = $this->createFromValues(10.10, 2.2);

        $price->getAmount()->getValue()->shouldReturn(10.10);
    }
157563
function pre_confirmation_check($order_total) {
    global $order;
    $od_amount = $this->calculate_deductions($order_total);
//    print_r($od_amount);
    $order->info['total'] = $order->info['total'] - $od_amount['total'];
    if (DISPLAY_PRICE_WITH_TAX != 'true') {
      $order->info['total'] -= $tax;
    }
    return $od_amount['total'] + (DISPLAY_PRICE_WITH_TAX == 'true' ? 0 : $od_amount['tax']);
  }
368836
public function getTaxTotal()
    {
        $total = $this->UnitTax * $this->Quantity;

        $this->extend("updateTaxTotal", $total);

        return $total;
    }
195114
private function applyCalculations()
    {
        $currency = Yii::$app->params['currency'];

        foreach ($this->models as $position) {
            $id = $position->id;

            $calculation = $this->getCalculation($id);
            if (!$calculation instanceof Calculation) {
                Yii::error('Cart position "' . $position->getName() . '" was removed from the cart because of failed value calculation. Normally this should never happen.', 'hipanel.cart');
                $this->cart->removeById($position->id);
                break;
            }

            $value = $calculation->forCurrency($currency);
            if (!$value instanceof Value) {
                Yii::error('Cart position "' . $position->getName() . '" was removed from the cart because calculation for currency "' . $currency . '" is not available', 'hipanel.cart');
                $this->cart->removeById($position->id);
                break;
            }

            $position->setPrice($value->price);
            $position->setValue($value->value);
        }
    }
129584
public function SetPriceBasedOnActiveDiscounts()
    {
        // this should only ever be executed once...
        $bDiscountedPriceUsed = $this->GetFromInternalCache('bDiscountedPriceUsed');
        if (is_null($bDiscountedPriceUsed) || false == $bDiscountedPriceUsed) {
            $bDiscountedPriceUsed = true;
            $dDiscountValue = $this->GetPriceIfDiscounted();
            if ($dDiscountValue < $this->fieldPrice) {
                $this->aPriceBeforeDiscount['fieldPrice'] = $this->fieldPrice;
                $this->aPriceBeforeDiscount['fieldPriceReference'] = $this->fieldPriceReference;
                $oLocal = &TCMSLocal::GetActive();
                $this->fieldPriceReference = $this->fieldPrice;
                $this->fieldPriceReferenceFormated = $this->fieldPriceFormated;
                $this->fieldPrice = $dDiscountValue;
                $this->fieldPriceFormated = $oLocal->FormatNumber($dDiscountValue, 2);
                $this->dPrice = $this->fieldPrice;
            }
            $this->SetInternalCache('bDiscountedPriceUsed', $bDiscountedPriceUsed);
        }
    }
23598
function onData() {
		var flg = false,
			diff,
			oldVal;

		/**
		* FUNCTION: onData( newVal, encoding, clbk )
		*	Data event handler. Calculates the difference.
		*
		* @private
		* @param {Number} newVal - new streamed data value
		* @param {String} encoding
		* @param {Function} clbk - callback to invoke after calculating the difference. Function accepts two arguments: [ error, chunk ].
		*/
		return function onData( newVal, encoding, clbk ) {
			if ( flg ) {
				diff = newVal - oldVal;
				oldVal = newVal;
				clbk( null, diff );
				return;
			}
			// Do not calculate a difference for the first streamed value...
			oldVal = newVal;
			flg = true;
			clbk();
		}; // end FUNCTION onData()
	}
1237149
public function calculateGrossPrice(Request $request)
    {
        if (!$request->has('netPrice')) {
            return Response::json([
                'error' => "The 'netPrice' parameter is missing",
            ], 422);
        }

        $valid_vat_id = null;
        $valid_company = false;
        if ($request->has('vat_number')) {
            $valid_company = $this->validateVATID($request->get('vat_number'));
            $valid_company = $valid_company['is_valid'];
            $valid_vat_id = $valid_company;
        }

        return [
            'gross_price'   => $this->calculator->calculate($request->get('netPrice'), $request->get('country'), $request->get('postal_code'), $valid_company),
            'net_price'     => $this->calculator->getNetPrice(),
            'tax_rate'      => $this->calculator->getTaxRate(),
            'tax_value'     => $this->calculator->getTaxValue(),
            'valid_vat_id'  => $valid_vat_id,
        ];
    }
699604
public function getUntaxedPostage()
    {
        if (0 < $this->getPostageTax()) {
            $untaxedPostage =  $this->getPostage() - $this->getPostageTax();
        } else {
            $untaxedPostage = $this->getPostage();
        }

        return $untaxedPostage;
    }