I am using codeigniter.When I perform add function I need to calculate tax. I have tax value in a table I need to fetch the value from the table and use it in my view page.
public function view()
{
$this->load->library('session');
$data['service_detail']=$this->session->userdata('service_detail');
$data['tax'] = $this->settings_model->get_tax();
$data['main_content'] = 'admin/service/view';
$this->load->view('includes/template', $data);
}
In model file I have this function by which I get the tax value from the table
public function get_tax()
{
$query = $this->db->query("SELECT company_tax13 FROM service_settings ");
$result = $query->result_array();
return $result;
}
Here is my view file where i get the tax value.
<div class="form-group">
<label for="email">Service price: <?=$service_detail['service_price']?> Rs</label>
</div>
<div class="form-group">
<label for="email">Tax Percentage : <?=$tax['company_tax13']?>%
<div class="form-group">
<?php
$tax_percentage=$tax['company_tax13'];
if(strstr($service_detail['service_tax'],"inclusive")==true) {
$taxamount=$service_detail['service_price']-($service_detail['service_price']/(1+($tax_percentage/100)));
$grand=$service_detail['service_price'];
}
else {
$taxamount=($service_detail['service_price']*(1+($tax_percentage/100)))-$service_detail['service_price'];
$grand=$taxamount+$service_detail['service_price'];
}
?>
<label for="email">Tax Amount : <?php echo $taxamount; ?> Rs</label>
<div class="form-group">
<label for="email">Grand Amount : <?php echo $grand; ?> Rs</label>
</div>
I could not get the tax value in my page. Can someone help me. I do not know the reason why i get no value in my output.
Edit 01
In service_detail['service_price']
contains either inclusive or exclusive. with that value I use strstr() to compare that string.
</div>