public function tax($amountNotTaxable = 0, $grossTax = true, $rounded = false, $withDiscount = true)
    {
        $discountTaxable = ($withDiscount) ? !config('laracart.discountTaxable', false) : false;
        $totalDiscount = ($withDiscount) ? $this->getDiscount(false) : 0;

        if (!$this->taxable) {
            $amountNotTaxable = $this->price * $this->qty;
        }

        if (config('laracart.tax_by_item')) {
            $itemCount = 0;
            $totalTax = 0;
            while ($itemCount < $this->qty) {
                $totalTax += round($this->price * $this->tax, 2);
                $itemCount++;
            }

            if ($grossTax && config('laracart.discountsAlreadyTaxed', false)) {
                $totalTax = $totalTax - ($totalDiscount - ($totalDiscount / (1 + $this->tax)));
            } else {
                if ($totalDiscount < 0 || $totalDiscount > $this->price) {
                    return $totalTax - ($totalDiscount - $this->price);
                }
            }

            if ($rounded) {
                return LaraCart::formatMoney(
                    ($totalTax - $amountNotTaxable),
                    $this->locale,
                    $this->internationalFormat,
                    false
                );
            }

            return $totalTax - $amountNotTaxable;
        }

        $totalTax = $this->tax * ($this->subTotal(false, $discountTaxable, true, false) - $amountNotTaxable);

        if (config('laracart.discountsAlreadyTaxed', false) && $withDiscount) {
            $totalTax = $totalTax - ($this->getDiscount(false) - ($this->getDiscount(false) / (1 + $this->tax)));
        }

        if ($rounded) {
            return LaraCart::formatMoney(
                $totalTax,
                $this->locale,
                $this->internationalFormat,
                false
            );
        }

        return $totalTax;
    }