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.
use row_array() instead of result_array() because result_array() returns the first value in index 0 and you should call:
$tax[0]['company_tax13'];
Related
I have multiple checkboxes, I want to display an array of data when multiple checkboxes are clicked, but only one value is displayed, how to display an array ?What is the problem?
<div class="form-group" >
<h5>Your languages</h5>
<div class="col-md-12">
#foreach($langs as $key => $lang)
<input type="checkbox" name="foo[]" value="{{$key}}">
<label>{{ $lang }}</label>,
#endforeach
</div>
</div>
To controller
public function Method(Request $request)
{
foreach((array)$request->input('foo') as $value){
$file = 'la.txt';
file_put_contents($file,$value );
}
return redirect()->route('profile');
}
I want to display the value of all these three checkboxes, but only the data of one of them is displayed
enter image description here
Hmm - let me guess the issue, I think that you should return the values while you return back to the profile view. I think also the problem is not in the first load of the profile view, because you have to pass the langs array, but the issue happens when you click the checkboxes to store the data in the controller's method, so your code must be like so
public function storeData(Request $request)
{
foreach($request->input('foo') as $value){
$file = 'la.txt';
file_put_contents($file, $value);
}
$yourLangsArray = ["English", "Arabic"];
return redirect()->route('profile')->with('langs', $yourLangsArray);
}
In my leave management module I have a field , which displays count of employee took total leave and which are approved,
But unfortunately I can't get the count.
will anyone help me please???
Here is code of my view file
<div class="row">
<label class="col-md-6"><strong> Total Leave in this month </strong>/label>
<div class="col-md-6">
{{$count}}
</div>
</div>
Here is my code of controller file
public function handleLeave($id)
{
$employeeName = User::all();
$leaves = LeaveManagement::find($id);
$count = LeaveManagement::where('status', '=', 'Approved')->count();
return view('pages.leavelist', compact('leaves', 'id', 'count', 'employeeName'));
}
in my show method in laravel i have a form that i want to submit and show the result on the same page so here is my show method first of all :
public function show(Property $property)
{
$property = Property::with('propertycalendars')->where('id', $property->id)->first();
foreach ($property->propertycalendars as $prop) {
$end_reserve = $prop->reserve_end;
}
// HERE NEW RELATION
$pdate = Property::with('dates')->get();
return view('users.properties.show', compact('property','pdate','end_reserve'));
}
and in the view of my show which for example is the url of a uniq property like below just as an example :
http://localhost:8000/properties/1
now i have a form to submit to search the Date table and bring me the dates so here is what i have wrote for the search function :
public function search (Request $request,$property_id){
//Send an empty variable to the view, unless the if logic below changes, then it'll send a proper variable to the view.
$results = null;
//Runs only if the search has something in it.
if (!empty($request->property_id)) {
$start_date = $request->start_date;
$search_date = Date::all()->where('date',$start_date);
}
return view('admin.properties.show')->with('search_date', $search_date);
}
and
thats my route :
Route::get('/properties/{{property_id}}','PropertyController#search');
and finally my form to submit the search :
<form action="/properties/search" method="get">
{{csrf_field()}}
<div class="row">
<div class="col-lg-5">
<input type="hidden" value="{{$property->id}}" name="property_id">
<input name="start_date" class="form-control m-input start_date" autocomplete="off"> </div>
<div class="col-lg-5">
<input name="finish_date" class="form-control m-input start_date" autocomplete="off"> </div>
<div class="col-lg-2">
<input type="submit" value="seach" class="btn btn-primary btn-block" autocomplete="off">
</div>
</div>
</form>
but now when i submit the form it returns a 404 not found with a link like below :
http://localhost:8000/properties/search?_token=R8ncSBjeZANMHlWMcbC6o5mYJZfwWgdfTwuviFo1&property_id=1&start_date=1398%2F1%2F12&title=
In your controller, change to the following:
public function search (Request $request){
//Send an empty variable to the view, unless the if logic below changes, then it'll send a proper variable to the view.
$results = null;
//Runs only if the search has something in it.
if (!empty($request->title)) {
$results = Property::all()->where('some search here')->get();
}
return view('admin.article.index')->with('results', $results);
}
This will send any (and all) results that your query finds to the view. Now in your view, you'll need to ensure there are actual results, or you'll get an error, so for example:
#if ($results)
//There are results, loop through them
#foeach($results as $item)
{{$item->title}}
#endforeach
#else
//There are no results, show the form maybe?
#endif
Without knowing your table structure, I can't give the exact way to loop through your results, but this should get you started.
Edit: Since OP's question nature changed a fair bit from the original question:
In order to achieve the new flow, you'd need to pass in a URL param in the route, and change it to be a get, since you're no longer posting it from a form:
Route::get('/properties/{search}','PropertyController#search');
This tells Laravel you've got something coming from a website.com/properties/xxxxx request - the xxxxx would contain the search key you'd then pass to your controller to lookup. The {search} portion in the route can be whatever name you want, just ensure the controller's second param matches it.
If you wanted to allow for a posting from your search form, you can (in addition) add the following to your routes:
Route::post('/properties','PropertyController#search');
Then in your controller, fetch whatever came from the form via the Request facade.
Then in your controller, you'd check if this is valid:
public function search (Request $request, $search){
//Send an empty variable to the view, unless the if logic below changes, then it'll send a proper variable to the view.
$results = null;
//Runs only if the second URL param has a value
if (!empty($search)) {
$results = Property::all()->where('some search here')->get();
}
return view('admin.article.index')->with('results', $results);
}
I have an event and i want to add artists to it from artists table.
I want to do so by using a dropdown list where it need to get populated by artists name and their is a small '+' next to it to add other artists. Upon doing that a 3rd transitive table where event id and artist id should be inserted as foreign keys.
When I create the event
In my view:
<div class="form-group">
<label for="task-artist" class="col-sm-3 control-label">Artist:</label>
<div class="col-sm-6">
<select name="artist" id="artist" class="form-control input-sm">
<option value=""></option>
#foreach($artists as $artist)
{{$artist->stage_name}}
#endforeach
</select>
</div>
</div>
my controller:
public function index(Request $request)
{
return view('tasks.index', [
'tasks' => $this->tasks->forUser($request->user()),
'artists' => DB::table('artists')->pluck('stage_name', 'id'),
]);
}
public function show($id)
{
//Get results by targeting id
$task = Task::find($id);
//$artist = Artist::lists('stage_name', 'id');
//$artist = Artist::where('active', true)->orderBy('stage_name')->pluck('stage_name', 'id');
//
return view('tasks.show')->with('task',$task);
}
How shall i proceed ?
Please help.
Javascript is your friend here.
Let me write some steps that you can follow to achieve what you are looking for :
1) Have the Div tag and
2) use $.get() function in javascript to get the dynamic values from a controller.
3) $.each() to loop through the data and show it in select input field
4) on either selecting the value or clicking + button that you mentioned do another Javascript call to add the artist to the event.
Example :
HTML
<div class="uk-margin-bottom">
<div id="your select dropdown"></div>
</div>
JAVASCRIPT
$("#artist").change(function() {
getArtists();
});
function getArtist() {
var artist= $('#your div id');
artist.empty();
var code = '';
$.get("/url/" + variable_id, function(data) {
artist.empty();
console.log(data);// once you create route and controller you should see your artists lists here
code += '<label for="event_id" class="uk-form-label">Select Artist</label><select class="uk-width-1-1" name="artist_name" id="artist_name" value="select">';
code += '<option value="">Select Artists</option>';
$.each(data.artist, function(index, value) {
code += '<option value="' + value.artist_name+ '">' + value.artist_name + '</option>';
});
code += '</select>
artist.append(code);
});
}
have a form and add javascript to post artist to the controller and store data into events table. Try and see if you can achieve and follow my steps.
I want to load data to my view, particularly a variable in my controller items.
But in my controller I want to dynamically set what items is before it is push to the view.
I tried the code below but it doesn't work. The view loads up with an error "Undefined variable: items" .
public function index(){
if ($this->input->post('filter'))
{
$search = $this->input->post('filter');
$test=$this->upload_model->test_r();
$data['items']=$test;
}
else
{
$data['items']=$one;
}
$data=array ('other'=>$othrs, 'links'=>$links);
$this->load->view('gallery_view', $data);
}
How I would like this to work is that $data['items'] is set to $one by default, when the page loads up, but on the page I have a select box, so I want that if the select box is is changed that $data['items'] would be set to something else. But this is only if the select box is used, else, it should look up with the $data[items]=$one. The $data array has other values that need to be loaded in the view such as "others" and "links".
The select box on my view
<?php echo form_open(base_url().'page') ?>
<form class="form-inline" role="form">
<select class="form-control" id="filter" name="filter" onchange="this.form.submit()">
<option value="1">1</option>
<option>2</option>
<option>3</option>
</select>
</form>
<?php echo form_close(); ?>
The index controller function above is for my controller "Pages". The value from the select box is captured fine, when I do an echo on the value passed it shows up correctly.
The problem is getting the view data "items" to change depending on if the select box is used.
How do I fix this?
Do this line before if condition
$data=array ('other'=>$othrs, 'links'=>$links,'items'=>"");
Remove below line in controller.
$data=array ('other'=>$othrs, 'links'=>$links);
Because you are re-assign $data after setting $data["items"]