Подоходный налог (PAYE) Налоговые диапазоны Расчет PHP

Я написал расчет диапазона подоходного налога с помощью PHP, и похоже, что код работает для некоторых условий, а остальные возвращают неточные цифры. Ниже приведен мой PHP-код для расчета. Пожалуйста, не обращайте внимания на валюту. это может быть в UDS

Пытаюсь рассчитать подоходный налог на сумму, например. 1000 со следующими налоговыми диапазонами ниже

// first  3,828 GHS ==> Nil tax
// next   1,200 GHS ==> 5% tax
// next   1,440 GHS ==> 10% tax
// next  36,000 GHS ==> 17.5% tax
// next 197,532 GHS ==> 25% tax
// over 240,000 GHS ==> 30% tax


$income_tax_amount = 0;

        //the tops of each tax band
        $band1_top = 3828;
        $band2_top = 1200;
        $band3_top = 1440;
        $band4_top = 36000;
        $band5_top = 197532;
        $band6_top = 240000;
        //no top of band 4

        //the tax rates of each band
        $band1_rate = 0.0;
        $band2_rate = 0.05;
        $band3_rate = 0.10;
        $band4_rate = 0.175;
        $band5_rate = 0.25;
        $band6_rate = 0.30;

        $starting_income = 1000; //set this to your income
        $band1 = $band2 = $band3 = $band4 = $band5 = $band6 =0;
        if($starting_income >= $band1_top) {
            $band1 = ($band1_rate) *  $band1_top - ($band1_top);
        }
        if($starting_income >= $band2_top) {
            $band5 = ($band2_rate) *  $band2_top - ($band2_top);
        }
        if($starting_income >= $band4_top) {
            $band4 = ($band4_rate) *  $band4_top;
        }
        if($starting_income >= $band3_top) {
            $band3 = ($band3_rate) *  $band3_top;
        }
        if($starting_income >= $band2_top) {
            $band2 = ($band2_rate) *  $band2_top;
        }
        if($starting_income >= $band1_top) {
            $band1 = ($band1_rate) *  $band1_top;
        }
        
        $income_tax_amount = $band1 + $band2 + $band3 + $band4 + $band5 + $band6;
            
        echo $income_tax_amount;

Изображение ниже иллюстрирует картину, которую я пытаюсь нарисовать введите здесь описание изображения


person user3315848    schedule 20.12.2020    source источник
comment
Ваш код не имеет для меня особого смысла. Может быть, это потому, что вы не объяснили, как должен рассчитываться налог? Только взглянув на валюту, использованную на изображении, я могу сделать вывод, что это должен быть ганский седи из Ганы, и, следовательно, используемая там налоговая система.   -  person KIKO Software    schedule 20.12.2020
comment
Вы правы, @KIKO Software, если бы не ваш намек на то, что страна Гана, я бы не написал свой ответ ниже. Спасибо за это!   -  person rf1234    schedule 20.12.2020
comment
@ rf1234 ты прав. Извините, ребята, я обновлю код и объяснение, чтобы сделать его более ясным и понятным.   -  person user3315848    schedule 20.12.2020
comment
Вы пытаетесь рассчитать предельную налоговую ставку? Если это так, вы должны вычесть нижнюю границу из общего дохода после расчета налога на него, иначе вы будете облагать налогом первые несколько долларов снова и снова.   -  person Josh J    schedule 21.12.2020


Ответы (1)


Эта функция рассчитает налог в соответствии с правилами, указанными на этой странице: https://home.kpmg/xx/en/home/insights/2020/02/flash-alert-2020-036.html ищите Residents: Rates & Bands

function calc_income_tax($income) {

    // see this page for the bands in Ghana:
    // https://home.kpmg/xx/en/home/insights/2020/02/flash-alert-2020-036.html
    // look for "Residents: Rates & Bands"

    // first  3,828 GHS ==> Nil tax
    // next   1,200 GHS ==> 5% tax
    // next   1,440 GHS ==> 10% tax
    // next  36,000 GHS ==> 17.5% tax
    // next 197,532 GHS ==> 25% tax
    // over 240,000 GHS ==> 30% tax

    // $band_arr has the top amounts of each band in Ghana currency in descending order
    // We have 5 thresholds to higher tax rates and 5 rates for each of the thresholds
    $band_arr = [240000, 42468, 6468, 5028, 3828];
    $rate_arr = [0.3, 0.25, 0.175, 0.1, 0.05];
    $income_tax_amount = 0;

    foreach ($band_arr as $key => $threshold) {
        if ( $income > $threshold ) {
            $exceeding_income = $income - $threshold;
            $income_tax_amount += ( $exceeding_income * $rate_arr[$key] );
            $income = $threshold;
        }
    }

    return $income_tax_amount;
}

Я немного расширил это, чтобы отразить значения для различных налоговых категорий в зависимости от ввода пользователя. Этот код использует приведенную выше функцию, и здесь вы найдете пример песочницы: код/bec1084eb0d70ce8907979af65ab02c3eaa16b22

А вот и дополнительный код:

$input_income = 340000; //as entered by the user online

$rate_arr = ["0%", "5%", "10%", "17.5%", "25%", "30%"];
$band_arr = [3828, 5028, 6468, 42468, 240000];
for  ($i=0; $i < count($band_arr); $i++ ) {
    if ( $band_arr[$i] >= $input_income ) {
        unset($band_arr[$i]);
    }
}
$band_arr[] = $input_income;
$band_arr = array_values($band_arr); //reorganize array to close gaps in index

$total_tax = calc_income_tax($input_income);
echo "total income tax: ".number_format($total_tax). "<br>";

$previous_bands_tax = 0;
foreach ($band_arr as $key => $threshold) {
    $band_tax = calc_income_tax($threshold) - $previous_bands_tax;
    $previous_bands_tax += $band_tax;
    if ( $key == 0 ) {
        echo "first ".number_format($threshold)."; rate: "
            .$rate_arr[$key].": ".number_format($band_tax)."<br>";
    } else {
        echo "next ".number_format($threshold - $band_arr[$key-1])."; rate: "
            .$rate_arr[$key].": ".number_format($band_tax)."<br>";
    }
}
person rf1234    schedule 20.12.2020