美好的一天人
我正在创建一个Laravel项目,这是一个人力资源应用程序我被困在哪里我需要计算叶子,这意味着我有两个表,我分配员工离开天和其他表我存储叶子请求,所以我需要通过扣除日期
来更新分配日期这是我的JS文件
public function approvedLeave(Request $request) {
$results1 = DB::select("SELECT SUM(numberof_day - used_leave) AS diff from assign_leave WHERE emp_id=?",[$request->get("emp_id")]);
$requestedDays = 0;
if ($results1[0]->diff > 0) {
if ($request->get('unit') == "Hours") {
if ($request->get("start_date") == $request->get("return_date")) {
$requestedDays = 0.5;
} else {
$fdate = $request->get("start_date");
$tdate = $request->get("return_date");
$datetime1 = new \DateTime($fdate);
$datetime2 = new \DateTime($tdate);
$interval = $datetime1->diff($datetime2);
$days = $interval->format('%a');
$requestedDays = $days - 0.5;
}
} else {
$fdate = $request->get("start_date");
$tdate = $request->get("return_date");
$datetime1 = new \DateTime($fdate);
$datetime2 = new \DateTime($tdate);
$interval = $datetime1->diff($datetime2);
$requestedDays = $interval->format('%a');
}
if ($requestedDays < $results1[0]->diff) {
$results = DB::update("UPDATE leaves SET status=?, start_date=?, return_date=? WHERE id = ?", [$request->get("status"), $request->get("start_date"), $request->get("return_date"), $request->get("id")]);
$results1 = DB::update("UPDATE assign_leave SET numberof_day=? , used_leave = used_leave+? WHERE emp_id = ?", [$request->get("used_leave"),$request->get("numberof_day"),$request->get("emp_id")]);
// dd($request->get("used_leave"), $request->get("assign_id"));
if ($results) {
//$leave = Leave::find($request->get("id"));
return response()->json(["status" => "success"]);
} else {
return response()->json(["status" => "failed", "err_msg" => "update failed please try gain"]);
}
} else {
return response()->json(["status" => "failed", "err_msg" => "request days is more the remaining days"]);
}
} else {
return response()->json(["status" => "failed", "err_msg" => "you do not have enough available days "]);
}
}
我在控制器中的功能
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-content">
<ul class="nav nav-pills nav-pills-warning">
<li class="active">
<a href="#pill1" data-toggle="tab">New Leave Request</a>
</li>
<li>
<a href="#pill2" data-toggle="tab">Approved&Rejected</a>
</li>
</ul>
<div class="col-md-10 row">
<button type="button" class="btn btn-warning pull-right btn-sm" data-toggle="modal"
data-target="#exampleModal" data-whatever="@mdo">Add Leave Types</button>
<a href="{{url('/assignleave')}}" type="button" rel="tooltip" title="assign Leave" class="btn btn-danger btn-simple pull-right btn-sm">
Assign Leave
</a>
</div>
<div class="tab-content">
<div class="tab-pane active" id="pill1">
<table class="table" id="example" width="100%">
<thead>
<tr>
<th>FirstName</th>
<th>Leave-Type</th>
<th>Start-Date</th>
<th>End-Date</th>
<th>Expected Return</th>
<th>Approved Date </th>
<th>Comment</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($all_leaves as $index =>$leave)
@if($leave->status == "Pending")
<tr>
<td>{{$leave->First_name}}</td>
<td>{{$leave->leave_name}}</td>
<td>{{$leave->start_date}}</td>
<td>{{$leave->return_date}}</td>
<td>{{$leave->expected_start_date}} </td>
<td>{{$leave->date_approved}}</td>
<td>{{$leave->comment}}</td>
<td>{{$leave->status}} </td>
<td class="td-actions text-right">
<button type="button" onclick="approveLeave('{{$leave->id}}','{{$leave->unit}}','{{$leave->emp_id}}')" rel="tooltip" title="Approved" class="btn btn-primary btn-simple btn-xs">
Approve
</button>
<button type="button" onclick="rejectLeave('{{$leave->id}}' )" rel="tooltip" title="Rejected" class="btn btn-danger btn-simple btn-xs">
Reject
</button>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane" id="pill2">
<table class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%" id="data1">
<thead>
<tr>
<th>Name</th>
<th>Email </th>
<th>Type</th>
<th>Start-Date</th>
<th>End-Date</th>
<th>Expected </th>
<th>Approved Date </th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach($all_leaves as $index =>$leave)
<tr>
<td>{{$leave->First_name}}</td>
<td>{{$leave->email_address}}</td>
<td>{{$leave->leave_name}}</td>
<td>{{$leave->start_date}}</td>
<td>{{$leave->return_date}}</td>
<td>{{$leave->expected_start_date}} </td>
<td>{{$leave->date_approved}}</td>
<td>{{$leave->status}} </td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane" id="pill4">
<table class="table" id="datas">
<thead>
<tr>
<th>#</th>
<th>Name1</th>
<th>Email </th>
<th>Type</th>
<th>Start Date</th>
<th>Returned Date</th>
<th>Date Approved</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach($all_leaves as $index =>$leave)
<tr>
<td>
<div class="checkbox">
<label>
<input type="checkbox" type="checkbox" value="{{$leave->id}}" name="selected_employee[]" onchange="showOrHideBulkButton(this)">
</label>
</div>
</td>
<td>{{$leave->First_name}}</td>
<td>{{$leave->email_address}}</td>
<td>{{$leave->leave_name}}</td>
<td>{{$leave->start_date}} </td>
<td>{{$leave->return_date}}</td>
<td>{{$leave->date_approved}}</td>
<td>{{$leave->status}} </td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane" id="pill3">
</div>
</div>
</div>
</div>
</div>
<!-- end col-md-12 -->
</div>
<!-- Modal -->
<div id=rejectModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<textarea class="form-control" placeholder="enter comment for rejection" id="comment"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" data-loading-text="Processing..." class="btn btn-success">Reject</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog " role="document">
<div class="modal-content " >
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Leave Types</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" method="POST" action="" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="firstname" class="col-md-4 control-label">Leave Type</label>
<div class="col-md-6">
<input id="firstname" type="text" class="form-control" name="leave_name" value="" required autofocus>
<span class="help-block">
<strong></strong>
</span>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="lastname" class="col-md-4 control-label">Description</label>
<div class="col-md-6">
<input id="lastname" type="text" class="form-control" name="description" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="col-md-4 control-label">No of Days</label>
<div class="col-md-6">
<input id="lastname" type="text" class="form-control" name="no_of_days" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Save </button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div id="approveModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<input class="form-control" placeholder="enter leave start date" id="start_date">
</div>
<div class="form-group">
<input class="form-control" placeholder="enter leave end date" id="end_date">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" onclick="approveNow()" data-loading-text="Processing..." class="btn btn-success">Approve</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
@endsection
@section('footer_scripts')
<script src="{{url('/js/leave_management.js')}}"></script>
@endsection
MY BLADE.PHP
{{1}}