我正在尝试使用php
开展税务计算工作。税务计算所需的平板或标准基于AGE
,startincome
和endincome
。我正在使用CODEIGNITER
框架。由于我是新手,我不知道如何完成任务。
我的代码应该只包含动态变量作为' slabs'要从数据库中获取,结果应根据随机给出的年龄和工资生成。
我的观点文件如下: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;
//}
}
}
&GT;
我的型号名称是Taxmodel.php
我是CodeIgniter的新手。将不胜感激。
答案 0 :(得分:0)
我已尝试此代码并为我工作,您可以将其作为参考。创建范围数组 $ getTaxCharge = array( 阵列( 'amount_range_from'=&gt; 0, 'amount_range_to'=&gt; 250000 'tax_percentage'=&gt; 0 ) 阵列( 'amount_range_from'=&gt; 250001 'amount_range_to'=&gt; 500000 'tax_percentage'=&gt; 10 ) 阵列( 'amount_range_from'=&gt; 500001, 'amount_range_to'=&gt; 1000000 'tax_percentage'=&gt; 20 ) 阵列( 'amount_range_from'=&gt; 1000001, 'amount_range_to'=&gt;千亿, 'tax_percentage'=&gt;三十 ) );
<?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);
?>