Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Hi I am a newbe and writing a simple code for tax purposes. So far I have wrote a small code but I think there seems to be a problem with the function taxable_i($i) which is not letting me make $taxable_i NIL. I have tried everything.
When I try to made $taxable_i NIL via function it wont let me do it. It shows me a result of £13900. I think the program is echoing $taxable_i rather then the tax payable.
If I delete the above all together then the tax payable comes to -£2199.80, which is in minus.
Please note that I put $taxable_i <personal_allowance so that the answer is zero but the result is not zero. I do not know why and what I am doing wrong.
Any help is most welcome.'
<?php
// VAT
define("vat_threshold",83000 );
define("vat_rate",0.2 );
// RELIEFS
define("personal_allowance",11000 );
//RATES
define("starting_rate",0 );
define("basic_rate",0.2 );
define("higher_rate",0.4 );
define("add_rate",0.45 );
define("divs_ord_rate",0.075 );
define("divs_uuper_rate",0.325 );
define("divs_add_rate",0.381 );
// THRESHOLDS
define("savings_income_band",5000 );
define("basic_rate_band",32000 );
define("higher_rate_band",150000 );
define("divs_allowance",5000 );
define ("band_0",0);
define("band_1",11000);
define("band_2",32000);
define("band_3",100000);
define("band_4",122000);
define("band_5",150000);
function taxable_i($i) {
if ($i <= band_1 ) {
$taxable_i = $i * 0;
return $taxable_i;
}
if ($i <= band_3 ) {
$taxable_i = $i - personal_allowance;
return $taxable_i;
}
if ($i >band_3 && $i <=band_4) {
$taxable_i = $i - (personal_allowance-($i - band_3)/2);
return $taxable_i;
}
if ($i > band_4) {
$taxable_i = $i;
return $taxable_i;
}
}
$starting_income = $i = 1;
echo $i;
$taxable_i = taxable_i($i);
echo $taxable_i;
switch ($taxable_i) {
case ($taxable_i > band_5):
$diff = $taxable_i - band_5;
$tax5 = $diff * add_rate;
$taxable_i = band_5;
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax5 + $tax4 + $tax3;
break;
case ($taxable_i > band_2 && $taxable_i <= band_5 ):
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax4 + $tax3;
break;
case ($taxable_i < band_2):
$tax = $taxable_i * basic_rate;
$tax_payable = $tax;
break;
default:
$taxable_i <= band_0;
$tax_payable == 0;
break;
}
echo $tax_payable;
?>
You don't put conditions in case statements, you should be using if/elseif/else there. The way switch/case works is that it compares the value of the initial switch () expression with the values of each case expression. So it's comparing $taxable_i to the value of $taxable_i > band_5, so it's comparing a number to true or false.
Replace the switch block with:
if ($taxable_i > band_5) {
$diff = $taxable_i - band_5;
$tax5 = $diff * add_rate;
$taxable_i = band_5;
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax5 + $tax4 + $tax3;
}
elseif ($taxable_i > band_2 ) {
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax4 + $tax3;
}
elseif ($taxable_i >= band_0) {
$tax = $taxable_i * basic_rate;
$tax_payable = $tax;
}
else {
$tax_payable == 0;
break;
}
Related
private function getRefundPaymentMethods(array $invoices, bool $hasUpgrade): array
{
$refundMethods = [self::CREDITS];
if ($hasUpgrade) {
return $refundMethods;
}
$transaction = $this->wsTransRepository->getPaymentTransactionByInvoice($invoices[0]['invoiceId']);
$originalPaymentMethod = $transaction->gateway;
$dateTransaction = strtotime($transaction->date);
$now = time();
$timeDiff = $now - $dateTransaction;
$diffDays = round($timeDiff / (60 * 60 * 24));
switch ($originalPaymentMethod) {
case strstr($originalPaymentMethod, self::BRP_CREDIT) && $diffDays <= 330:
$refundMethods[] = self::BRP_CREDIT_1X;
break;
case self::DIL && $diffDays <= 90:
case self::PLP:
case PlpConfig::GATEWAY:
if ($diffDays <= 180) {
$refundMethods[] = $originalPaymentMethod;
}
break;
**case PxConfig::GATEWAY:
return $refundMethods[] = $originalPaymentMethod;**
}
return $refundMethods;
}
I need to return two values, the one in $refundMethods and the one in $originalPaymentMethods.
I tried to use str_split but I couldn't bring the two values
I'm using a IRR function in php to create calculation a that is done in excel using its own IRR function. The problem is mine is need XIRR function and I have no idea why. Here's the code below.
function IRR($investment, $flow, $precision = 0.001) {
$min = 0;
$max = 1;
$net_present_value = 1;
while(abs($net_present_value - $investment) > $precision) {
$net_present_value = 0;
$guess = ($min + $max) / 2;
foreach ($flow as $period => $cashflow) {
$net_present_value += $cashflow / (1 + $guess) ** ($period + 1);
}
if ($net_present_value - $investment > 0) {
$min = $guess;
} else {
$max = $guess;
}
}
return $guess * 100;
}
I need to validate that an inputted number is a valid number based on my stepping rules and round up to the nearest valid number if not. These numbers will change but one example would be:
$min = 0.25;
$step = 0.1
$qty = 0.75 // user input
so these would be valid inputs:
0.75
0.85
0.95
But these should round:
0.76 (to 0.85)
0.80 (to 0.85)
I thought I could use modulus somehow but not getting the calculation correct.
if (($qty % min) / $step == 0)) {
echo "good";
}
I've tried some variations of math that are likely very wrong
$step = 0.1;
$min = 0.25;
$qty = .85;
$h = ($qty / $min) / $step;
echo $h;
$j = mround($qty, $min-$step);
echo $j;
function mround($num, $parts) {
if ($parts <= 0) { $parts = 1; }
$res = $num * (1/$parts);
$res = round($res);
return $res /(1/$parts);
}
I think you can use fmod to do this.
$new = $original + ($step - fmod($original - $minimum, $step));
Example on 3v4l.org
I get price from database with 9xx items.
I add this on show items page. Using Foreach $rows=$row. vprice is my sellingprice and dprice is my dealerprice
$commisionrate = 30;
$commisionfee = 100;
$fee = $row['dprice'] + $commisionfee;//+100
$x = $row['dprice'];
$y = $x * $commisionrate / 100;
$z = $x + $y;
$rate = $z;//(100*30%)+100
if (($rate > $row['vprice']) && ($fee < $row['vprice'])){
echo $fee;
}elseif (($fee > $row['vprice']) && ($rate < $row['vprice'])){
echo $rate;
}elseif ($row['dprice']=$row['vprice']){
echo $row['dprice'];
}
when I recheck all, I found that few items of $row['dprice'] is not counted and still show by old price. Example that is false: I found vprice is 188 with 80 dprice after calculate should be 104 but not changing with still stay on 80.
$commisionrate = 30;
$commisionfee = 100;
$fee = $row['dprice'] + $commisionfee;//+100
$x = $row['dprice'];
$y = $x * $commisionrate / 100;
$rate = $x + $y;
// You don't need to put nested brackets, it very simple condition
if ($rate > $row['vprice'] && $fee < $row['vprice']){
echo "fee: " . $fee; //add some hint words, so you know which condition fires
// You don't need to put nested brackets, it very simple condition
} elseif ($fee > $row['vprice'] && $rate < $row['vprice']) {
echo "rate: " . echo $rate;
// USE double `==`, because when single `=` used, the condition always returns true and you're confused by your result
} elseif ($row['dprice'] == $row['vprice']) {
echo "row[\'dprice\']: " . $row['dprice'];
// add last else
} else {
// this is helpful for debugging of your possible output, regardless you are awaiting some output here
}
Can you help me solve this problem:
For that
$share Value <= 30000 the term is from 1 - 36 with 1.3% on the first
term and diminishing value of .65 on the next term while $share Value >= 30001 with diminishing value of .75
<?php
// Create a function that can accept parameters
function CalculateItem($share = 0,$terms = 0)
{
if($share <= 30000)
$multiplier = ($terms == "1")? .0130 : .0195;
elseif($share >= 30001)
$multiplier = ($terms == "1")? .0130 : .0205;
if(empty($multiplier))
return;
$data['share'] = $share;
$data['terms'] = $terms;
$data['interest'] = ($share * $multiplier);
$data['service_fee'] = ($share * .01);
$data['filling_fee'] = 30;
$data['cash_on_hand'] = $share - ($data['service_fee'] + $data['interest'] + $data['filling_fee']);
$data['loan_receivable'] = $data['cash_on_hand'] + $data['service_fee'] + $data['interest'] + $data['filling_fee'];
$data['debit'] = $data['loan_receivable'];
$data['credit'] = $data['interest'] + $data['service_fee'] + $data['filling_fee'] + $data['cash_on_hand'];
return $data;
}
// Get the state of data. Anything but false will trigger the breakout table
$data = (isset($_POST['calculate']))? CalculateItem($_POST['share'],$_POST['terms']) : false;
?>
While the rate is fixed you may do it as --
$rate=.0130;
if($share <= 30000)
$multiplier = $rate + ($terms-1)*(0.65);
elseif($share >= 30001)
$multiplier = $rate + ($terms-1)*(0.75);
By this way , you may calculate as per all terms