1

我正在尝试使用 进行税收计算。税收计算所需的板或php标准基于AGE和。我正在使用框架。因为我是新手,所以我不知道如何完成这些事情。startincomeendincomeCODEIGNITER

我的代码应该只包含动态变量作为要从数据库中获取的“slabs”,并且应该根据随机给出的 AGE 和 Salary 生成结果。


我的视图文件如下: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 的新手。帮助将不胜感激。

4

1 回答 1

0

我已经尝试过这段代码并为我工作,您可以将其作为参考。创建范围数组,如 $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),数组('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);
    ?>
于 2017-11-28T11:38:26.783 回答