Commit 9ecc5ff7 by fezrul

update sample chargeable

parent 25bc4e7a
......@@ -239,99 +239,97 @@ class DashboardController extends Controller
public function saveHours(Request $request)
{
//filter function save atau update akan buat kat blade.
//Form Baru
//Form Edit after rejected
//Form Baru
//check dalam db table ts-detail. Kalau dah ada details dalam td_hours -> update().
//Kalau tak ada detail hours -> save()
$user = users::where('id', Auth::id())->first();
//me - check dalam db, table ts_detail, kalau dah ada detail hours, edit.
$checkTimesheetDetail = Ts_detail::where('tm_staff_id', $user->u_staffID)
// check table master. untuk total chargeable hours.
$check = Ts_master::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $request->year)
->where('tm_month', $request->month)
->where('tm_phase', $request->phase)
->whereNotNull('td_hours')
->whereNotNull('tm_chargeable_hrs')
->first();
//update total chargeable hrs
if($checkTimesheetDetail)
//kalau ada, update().
//staff kena edit bila submission timesheet kena reject.
if($check)
{
$data = Ts_detail::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $request->year)
->where('tm_month', $request->month)
->where('tm_phase', $request->phase)
->first();
$data ->td_hours = 10;
$data ->update();
}
//kalau takda, save().
// kalau takda, save().
else
{
// dd($checkTimesheetDetail);
$data = new Ts_detail;
$data ->id = $request ->id;
$data ->tm_year = $request ->year;
$data ->tm_month = $request ->month;
$data ->tm_phase = $request ->phase;
$data ->td_hours = 8;
$data ->save();
$check = new Ts_master;
$check ->tm_year = $request ->year;
$check ->tm_month = $request ->month;
$check ->tm_phase = $request ->phase;
// $check ->tm_chargeable_hrs = ;
$check ->save();
}
$tmasterid = $check->id;
// check table master. untuk total chargeable hours.
// $check = Ts_master::where('tm_staff_id', $user->u_staffID)
// ->where('tm_year', $request->year)
// ->where('tm_month', $request->month)
// ->where('tm_phase', $request->phase)
// ->whereNotNull('tm_chargeable_hrs')
// ->first();
// semak detail dari form
// //kalau ada, update().
// //staff kena edit bila submission timesheet kena reject.
// if($check)
// {
// $data = Ts_master::where('id',$request->id)->first();
// //update total chargeable hrs
// $data -> tm_chargeable_hrs = 10;
// $data -> update();
// }
// //kalau takda, save().
// else
// {
// $data = new Ts_master;
// $data ->id = $request ->id;
// $data ->tm_year = $request ->year;
// $data ->tm_month = $request ->month;
// $data ->tm_phase = $request ->phase;
// $data ->tm_chargeable_hrs = 8;
// $data ->save();
// }
//untuk project type : 1=chargeable,2 nonchargeable, 3=overhead;
$detail = $request->hour;
foreach ($detail as $key => $value)
{
foreach ($value as $keyday => $day)
{
$projectid = $key;
$date = $request->year.'-'.$request->month.'-'.sprintf('%02d', $keyday);
//kalau ada juga = bawak data details
$checkTimesheetDetail = Ts_detail::where('fk_p_project_code', $projectid)
->where('td_project_type',1)
->where('td_date', $date)
->where('tm_phase', $request->phase)
->first();
if($checkTimesheetDetail)
{
//update hours
$valuehour = $day;
if($valuehour == null)
{
$valuehour = 0;
}
$checkTimesheetDetail->td_hours = $valuehour;
$checkTimesheetDetail->update();
}else
{
//isi semua
$tmdetail = new Ts_detail;
//$tmdetail -> kjhdiwhdf;
//project = Project::where('id','project')->first();
//
// /lepas save ();
}
}
}
//update total ke master;
//buat query sum td_hour where condition :
// $sumdetailhour = Ts_detail::where('fk_p_project_code', $projectid)
// ->where('td_project_type',1)
// ->where('td_date', $date)
// ->where('tm_phase', $request->phase)
// ->sum();
// tm_master = Ts_master::where('tm_staff_id','=',Auth::id())
// ->where('tm_month','=',$tm_month)
// ->get();
// if(isset(tm_master))
// {
// }
//first = check dah ade ke belum
// $check = Ts_master::where('id', $tmasterid)->first();
// $check->totaloiwfwoei = udaoe
//mula2 masuk dalam table master untuk dapat id master.php
// return redirect::to('mobile/profile');
//pakai id master untuk update ke detail.
return redirect()->route('timesheet::dashboard.borangBolehCaj', ['phase' => $request->phase, 'month' =>$request->month,'year',$request->year])->with('success', 'Timesheet Updated');
// $data = new Ts_master;
// $data -> tm_chargeable_hrs = $request -> tm_chargeable_hrs;
// $data -> save();
// return redirect('home');
}
public function timesheetApproval()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment