Я пытаюсь сделать работу по расчету налога с использованием php
. Необходимые плиты или критерий для расчета налога основаны на AGE
,startincome
а также endincome
, я использую CODEIGNITER
framework. Поскольку я новичок в этом, я понятия не имею, как добиться цели.
Мой код должен содержать только динамические переменные в качестве «слябов», которые должны быть получены из базы данных, а результат должен быть получен на основе ВОЗРАСТА и зарплаты, заданных случайным образом.
Мой файл просмотра приведен ниже: tax.php
<form>
<table border="1" align="center" cellpadding="30">
<tr>
<td colspan="2" align="center">
<b>Tax calculation</b>
</td>
</tr>
<tr>
<td>
<label for="name"><b>Name</label>
</td>
<td>
<input id="name" name="name" type="textbox" placeholder="enter your name" size="30" >
</td>
</tr>
<tr>
<td>
<label for="name"><b>Age</label>
</td>
<td>
<input id="name" name="name" type="textbox"placeholder="enter your age" size="30" >
</td>
</tr><tr>
<td>
<label for=""><b>Salary:</label></td>
<td>
<input id="salary" name="phone" type="textbox"placeholder="enter your yearly salary" size="30" >
</tr>
<tr>
<td>
<div>
<input type="submit" value="calculate" name="submit" />
</div>
</td>
<td>
<label for=""><strong>Tax Amount:</strong></label>
<input id="Tax" name="tax" type="textbox" size="17" >
</td>
</table>
</form>
Мой код контроллера ниже: Tax.php
<?php
class Tax extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
public function index()
{
$servername='localhost';
$username='root';
$password='';
$database='register';
$conn = mysqli_connect($servername,$username,$password);
$this->load->view('tax');
//$this->load->model(Taxmodel);
if(isset($_POST['submit']))
{
//echo"inside submit";
$this->form_validation->set_rules('name','Name','trim|required');
$this->form_validation->set_rules('age','Age','trim|required');
$this->form_validation->set_rules('salary','Salary','trim|required',array('required' => 'You must provide a %s.'));
//checks whether the validation returns true or false
if ($this->form_validation->run() ==TRUE)
{
//echo' validation check';
//storing data to Array
$userdata = array(
'Name' => $this->input->post('name'),
'Age' => $this->input->post('age'),
'Salary' => $this->input->post('salary')
);
print_r($userdata);
$this->load->model('Taxmodel');
//$this->Taxmodel->insertdata($userdata);
}
}
}
public function getresult()//to get database values in a row
{
echo "inside getresult";
$salary=$_POST['salary'];
$data= $this->db->query("SELECT * FROM `admin_income` WHERE age<".$age." and age in (SELECT max(age) FROM `admin_income` WHERE age<".$age." order by `age` desc) order by `age` desc ");
print_r($data);
$result=$conn->query($data);
Global $totaltax;while ($row = mysql_fetch_assoc($result))
{echo "inside while1";
while($salary>= $row[$start_incom] && $salary< $row[$end_incom])
{
//echo"Inside tax calculation";
$diff=$salary-$startincome;
$tax=(($percentage/100)*$diff);
echo $tax;
}
echo $tax;
}
}
public function extamount()
{//to get the additional amount to be added
/*$query = $this->db->query("SELECT * FROM admin_income LIMIT 1;");
if ($query->num_rows() > 0)
{
$row = $query->next_row('array')*/
if($initial_income>$start_incom)//codnition for checking whether the salary exceeds first slab
{
$diffresult=$end_incom-$start_incom;
$adtntax=[($percentage/100)*$diffresult];
echo $adtntax;
}
$totaltax=$adtntax+$tax;
//}
}
}
?>
Моя модель зовут Taxmodel.php
Я новичок в CodeIgniter. Помощь будет оценена.
Я пробовал этот код и работал для меня, вы можете взять его в качестве ссылки. создать массив диапазонов, как
$ getTaxCharge = array (
массив (
‘amount_range_from’ => 0,
‘amount_range_to’ => 250000,
‘tax_percentage’ => 0
),
массив (
‘amount_range_from’ => 250001,
‘amount_range_to’ => 500000,
‘tax_percentage’ => 10
),
массив (
‘amount_range_from’ => 500001,
‘amount_range_to’ => 1000000,
‘tax_percentage’ => 20
),
массив (
‘amount_range_from’ => 1000001,
‘amount_range_to’ => 100000000000,
‘tax_percentage’ => 30
)
);
<?php
$getTaxCharge = array(
array(
'amount_range_from' => 0,
'amount_range_to' => 250000,
'tax_percentage' => 0,
),
array(
'amount_range_from' => 250001,
'amount_range_to' => 500000,
'tax_percentage' => 10,
),
array(
'amount_range_from' => 500001,
'amount_range_to' => 1000000,
'tax_percentage' =>20,
),
array(
'amount_range_from' => 1000001,
'amount_range_to' => 100000000000,
'tax_percentage' =>30,
)
);
$calculateTaxOnAmount = 900000;
$remainingAmount = $calculateTaxOnAmount;
$amount = $calculateTaxOnAmount;
$arrayAmount = array();
foreach ($getTaxCharge as $key => $value) {
$resultArray = array();
if ($calculateTaxOnAmount > $value['amount_range_to']) {
$sum = $value['amount_range_to'] - $value['amount_range_from'];
$resultArray['amount'] = $sum;
$resultArray['percentage'] = $value['tax_percentage'];
array_push($arrayAmount, $resultArray);
$remainingAmount = $remainingAmount - $sum;
} else {
$resultArray['amount'] = $remainingAmount;
$resultArray['percentage'] = $value['tax_percentage'];
array_push($arrayAmount, $resultArray);
break;
}
}
$resultantTaxAmount = 0;
foreach ($arrayAmount as $key => $value) {
$cal = (($value['amount'] * $value['percentage']) / 100);
$resultantTaxAmount = $resultantTaxAmount + $cal;
}
echo round($resultantTaxAmount);
?>
Других решений пока нет …