convert "DateInterval" to string for posetive times work employees - php

I want get total times of each person at company
for example
08:45
8:40
8:55
total n time
and I get this Error
Date Interval:: create From Date String (): Argument #1 ($datetime) must be of type string, Date Interval given
how can I solve it? Thanks :(
`
#if(is set($reports))
{{-- #if(is set($request->user id)) --}}
#php
$time = 0;
#endphp
#foreach ($reports as $key => $report)
<t r>
<td scope="row">{{ $key + 1 }}</td>
<td>{{ $report->user_ id->user_ name ?? 'خالی' }}</td>
<td>{{ $report->entry _ time ?? 'خالی' }}</td>
<td>{{ $report->exit _ time ?? 'خالی' }}</td>
<td>{{ $report->project->name ?? 'خالی' }}</td>
<td>
#php
$enter = new Date Time($report->entry _time );
$exit = new Date Time($report->exit_ time );
$interval = $enter->diff($exit);
Date Interval::create From Date String($interval);
$time+=$i;
#endphp
{{ $interval->format("%H") . ':' . $interval->format("%i=") }}
</td>
<td></td>
<td></td>
<td>{{ $report->main _report ?? 'خالی' }}</td>
</t r>
#endforeach
{{ $time }}
{{-- #endif --}}
#endif
</t body>`

Related

print days of a special month ? laravel

I need to print only the records for the month of May
I get them with the variable
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
I need to see only May results, how do I do it?
You can use if condition
#if($user->created_at->format('M')=="May")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif
or
#if($user->created_at->format('m')=="05")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif
Simply check May month in created_at date
#if($user->created_at->format('m')=="05")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif

Laravel modify cells with expired date

Sorry I didn´t know how to ask this question, but I want if a file reach his expiration date in each cell of expired date column just put "expired" otherwise just put his expiration date.
In my controller I create an variable called $actualDate= Carbon::now(); and I send it to my view.
In my view I have this on table:
#foreach ($Files as $File)
<tr>
<td><a href="/File/{{$File->id}}">{{
$File->Code}}</td>
<td>{{ $File->created_at }}</td>
<td>{{ $File->person}}</td>
<td>{{ $File->category_file}}</td>
<td>{{ $File->status}}</td>
<td>{{ $File->employed}}</td>
#if($File->expirationDate < $actualDate)
<td>{{$File->expirationDate}}</td>
#else
<td>Expired</td>
#endif
If I put < on comparision all the column will be "expired" and if I put > it will be no expired Files even if there are ¿what can I do to solve this? I hope you can help me.
Try it:
#foreach ($Files as $File)
<tr>
<td><a href="/File/{{$File->id}}">{{ $File->Code}}</td>
<td>{{ $File->created_at }}</td>
<td>{{ $File->person}}</td>
<td>{{ $File->category_file}}</td>
<td>{{ $File->status}}</td>
<td>{{ $File->employed}}</td>
#if(\Carbon\Carbon::parse($File->expirationDate)->lessThan(\Carbon\Carbon::now()))
<td>{{$File->expirationDate}}</td>
#else
<td>Expired</td>
#endif
#endforeach
Hope it helps.

Having problem with retriving json data in laravel

I'm working on a laravel project and i'm getting JSON error. I've try few options to solve the issue but did not come up with any solutions.
In this project I've to send multiple data into database onder one "ID". In that ID there are at list 10 data need to insert. So I used JSON format. It saves ok but getting error when I try to pull data.
Here is my code
Controller :
public function newExpenses(Request $request){
$Jexpenses = new Jexpenses;
$json = array(
'des' => $request->description,
'valu' => $request->expenses
);
$Jexpenses->voucher = $request->voucher_no;
$Jexpenses->date = $request->date;
$Jexpenses->description = json_encode($json);
$Jexpenses->expenses = $request->total;
$Jexpenses->remarks = $request->remark;
if($Jexpenses->save()){
$notification = array(
'message' => 'Expenses Saved',
'alert-type' => 'success'
);
}
return redirect()->back()->with($notification);
}
result :
{"des":["Jon","Sam","Pitter"],"valu":["20","30","15"]}
Return Controller:
public function expenses(){
$data = array(
'title' => 'Expenses',
'expenses' => Jexpenses::all()
);
return view('expenses.expenses')->with($data);
}
html :
#foreach ($expenses as $key => $getData)
{{ $array = #json( $getData->description ) }}
<tr>
<td>{{ ++$key }} </td>
<td>{{ $getData->voucher }} </td>
<td>{{ $getData->date }} </td>
#foreach ($array->description as $k => $v)
<td>{{ $array->des['$k'] }}</td>
<td>{{ $array->valu['$k'] }}</td>
#endforeach
<td>{{ $getData->expenses }}</td>
<td>{{ $getData->remarks }}</td>
</tr>
#endforeach
it should be work fine but getting error
error:
syntax error, unexpected '<' (View: C:\xampp\htdocs\acSoft\resources\views\expenses\expenses.blade.php
Need some help. Thanks.
1) Use json_decode($getData->description) instead #json. The #json is shortly form of json_encode
2) $array->description not exists property. Should be $array->des
3) You use variable in ' quotes. You should use " quote or nothing round variables.
4) It is bad idea using reserved words as variable names. I am about variable $array
#foreach ($expenses as $key => $getData)
{{ $descriptionData = json_decode( $getData->description ) }}
<tr>
<td>{{ $key + 1 }} </td>
<td>{{ $getData->voucher }} </td>
<td>{{ $getData->date }} </td>
#foreach ($descriptionData->des as $k => $v)
<td>{{ $descriptionData->des[$k] }}</td>
<td>{{ $descriptionData->valu[$k] }}</td>
#endforeach
<td>{{ $getData->expenses }}</td>
<td>{{ $getData->remarks }}</td>
</tr>
#endforeach

Symfony2 DATEDIFF function

I need to fill table in TWIG with data from database. Everything is Fine with the exception of this:
I need to have column with DATEDIFF property to get number of days.
TODAY-dateFromDateBase
Question is:
How to get number of days in loop in twig?
here is my twig:
<table>
<thead>
<tr>
<form action="" method="post" {{ form_enctype(searchform) }} class="form-index-permits">
<td>L.p </td>
<td>ID PRZEPUSTKI {{ form_widget(searchform.PermitId) }}</td>
<td>Name{{ form_widget(searchform.Permitname) }}</td>
<td>Surname {{ form_widget(searchform.Permitsurname) }}</td>
<td>Company {{ form_widget(searchform.Company) }}</td>
<td>GW {{ form_widget(searchform.Contractor) }}</td>
<td>Dayleft {{ form_widget(searchform.Dayleft) }}</td>
<td>End date {{ form_widget(searchform.date, { 'attr': {'class': 'datepicker'} }) }}</td>
</form>
</tr>
</thead>
{% for permit in permitcollection %}
<tbody>
<td>{{ loop.index }}</td>
<td>{{ permit.getPermitid()|number_format(0, '.', ' ') }}</td>
<td>{{ permit.getPermitname() }}</td>
<td>{{ permit.getPermitsurname() }}</td>
<td>{{ permit.getPermitsCompany().getName() }}</td>
<td>{{ permit.getPermitsContractor().getName() }}</td>
<td> HERE I WANT TO DISPLAY DAYS LEFT</td>
<td>{{ permit.getExpirationdate()|date('Y-m-d') }}</td>
</tbody>
{% endfor %}
</table>
Is something like this possible?
{{ permit.getExpirationdate()|date('Y-m-d') - "now"|date('Y-m-d') }}
First Solution (recommended) "Use an existing library":
You can use the KnpTimeBundle
In the Twig:
This compare with the current date:
{# Returns something like "3 minutes ago" #}
{{ time_diff(permit.expirationDate) }}
This compare with the another date:
{# Returns something like "3 minutes ago" #}
{{ time_diff(permit.expirationDate, anotherDate) }}
Second Solution "Do it yourself":
Make diff via php function:
$calcFrom = permit.getExpirationdate()
$now = new \DateTime('now');
$now->diff($calcFrom)->format("%a")
And make it available via a Twig extension or directly in an helper method in the entity.
Another possible solution is to write register a custom DQL Function to do the work in the repository
Hope this help

Case statements when updating a table based on clicked button?

I've got a table like below:
<tr>
<td>{{ item.wo_num_and_date }}</td>
<td>{{ item.comp_name_and_number }}</td>
<td>{{ item.finish_sizes }}</td>
<td>{{ item.material }}</td>
<td>{{ item.total_num_pieces }}</td>
<td>{{ item.workorder_num_one }}</td>
<td>{{ item.notes_one }}</td>
<td id='signoff_userone'><input type='button' id='signoff_user_one' data-rowid={{ item.id }} value='Signoff' /> {% if item.signoff_user_one is defined and item.signoff_date_one is defined %}{{ item.signoff_user_one.name|title }} {{ item.signoff_date_one }} {% endif %}</td>
<td>{{ item.workorder_num_two }}</td>
<td>{{ item.notes_two }}</td>
<td id='signoff_usertwo'><input type='button' id='signoff_user_two' data-rowid={{ item.id }} value='Signoff' /> {% if item.signoff_user_two is defined and item.signoff_date_two is defined %}{{ item.signoff_user_two.name|title }} {{ item.signoff_date_two }} {% endif %}</td>
<td>{{ item.workorder_num_three }}</td>
<td>{{ item.notes_three }}</td>
<td><input type='button' id='signoff_user_three' value='Signoff' /> {{ item.signoff_user_three.firstname }} {{ item.signoff_user_three.lastname }}</td>
</tr>
Fiddle: http://jsfiddle.net/qwUV4/1/
Here's my php code I call when a button is clicked, everything works well for the first "Sign Off" box but the other 2 don't work, obviously because of my Update statement below which is only set to update column "signoff_user_one".
<?php
require_once('../includes/config.php');
$user_id = getuserinfo($loggedin_id);
$row_id = (int)mysqli_escape_string($dbc3, $_POST['rowid']);
$sql = "UPDATE checklist_component_stock SET signoff_user_one = $loggedin_id, signoff_date_one = NOW() WHERE id = " . $row_id;
mysqli_query($dbc3, $sql);
$ret = array('rowid' => $row_id, 'user' => $user_id, 'date' => date('Y-m-d H:i:s')); //date('M d, Y')
echo json_encode($ret);
?>
My question is, would I need cases so the script checks whether its signoff_user_one, user_two, or user_three and executes the correct update statement? How would I do something like that? Is there another solution?
Are you using a loop? Because in such a case, it would probably not work very well.It should work well with the buttons and the specific ids which you have captured.You could use an isset function and use the name attribute for the button..

Categories