Calculate the VAT based on the net price, country code and indication if the
customer is a company or not.
public calculate ( integer | float $netPrice, null | string $countryCode = null, null | string $postalCode = null, null | boolean $company = null ) : float | ||
$netPrice | integer | float | The net price to use for the calculation |
$countryCode | null | string | The country code to use for the rate lookup |
$postalCode | null | string | The postal code to use for the rate exception lookup |
$company | null | boolean | |
Résultat | float |
/** * Returns the tax rate for the given country. * * @param Request $request * * @return \Illuminate\Http\Response */ 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]; }