Commit 926b586a by hannan

insert data chargeable

parent 1cb89676
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RenameColumnInTimesheetDtlTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('timesheet_dtl', function (Blueprint $table) {
$table->renameColumn('tm_id', 'fk_tm_id');
$table->renameColumn('tm_staff_id', 'fk_tm_staff_id');
$table->renameColumn('tm_month', 'fk_tm_month');
$table->renameColumn('tm_year', 'fk_tm_year');
$table->renameColumn('tm_phase', 'fk_tm_phase');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('timesheet_dtl', function (Blueprint $table) {
$table->renameColumn('fk_tm_id', 'tm_id');
$table->renameColumn('fk_tm_staff_id', 'tm_staff_id');
$table->renameColumn('fk_tm_month', 'tm_month');
$table->renameColumn('fk_tm_year', 'tm_year');
$table->renameColumn('fk_tm_phase', 'tm_phase');
});
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTimesheetDtlTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('timesheet_dtl', function (Blueprint $table) {
$table->renameColumn('fk_tm_staff_id', 'tm_staff_id');
$table->renameColumn('fk_tm_month', 'tm_month');
$table->renameColumn('fk_tm_year', 'tm_year');
$table->renameColumn('fk_tm_phase', 'tm_phase');
$table->dropColumn('fk_p_project_code');
$table->integer('td_project')->after('td_date')->unsigned()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('timesheet_dtl', function (Blueprint $table) {
$table->renameColumn('tm_staff_id', 'fk_tm_staff_id');
$table->renameColumn('tm_month', 'fk_tm_month');
$table->renameColumn('tm_year', 'fk_tm_year');
$table->renameColumn('tm_phase', 'fk_tm_phase');
$table->string('fk_p_project_code');
$table->dropColumn('td_project');
});
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RenameTableProjectTask extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('project_task', function (Blueprint $table) {
Schema::rename('project_task', 'project_team');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('project_task', function (Blueprint $table) {
//
});
}
}
......@@ -28,7 +28,7 @@ input[type=number] {
Phase = {{$phase}}
<br>
<hr>
<form class="ui form" action="{{ url('saveHours' )}}" method="POST">
<form class="ui form" action="{{ route('timesheet::dashboard.savechargeablehours' )}}" method="POST">
{{csrf_field()}}
<input type="hidden" name="userId" value="{{$userId}}">
<input type="hidden" name="year" value="{{$year}}">
......
......@@ -20,10 +20,7 @@ Route::group(
Route::get('timesheet_report',['uses' => 'DashboardController@timesheetReport', 'as' => 'dashboard.timesheetReport']);
Route::get('timesheet_review',['uses' => 'DashboardController@timesheetReview', 'as' => 'dashboard.timesheetReview']);
Route::get('timesheet_viewer',['uses' => 'DashboardController@timesheetViewer', 'as' => 'dashboard.timesheetViewer']);
// Route::get('phase1/{phase}',['uses' => 'DashboardController@phase1', 'as' => 'dashboard.phase1']);
// Route::get('phase2/{phase}',['uses' => 'DashboardController@phase2', 'as' => 'dashboard.phase2']);
Route::post('saveHours',['uses' => 'DashboardController@saveHours', 'as' => 'dashboard.saveHours']);
Route::post('savechargeablehours',['uses' => 'DashboardController@savechargeablehours', 'as' => 'dashboard.savechargeablehours']);
}
);
......
......@@ -8,6 +8,7 @@ use DB;
use Portal\Timesheet\Model\Users;
use Portal\Timesheet\Model\Ts_master;
use Portal\Timesheet\Model\Ts_detail;
use Portal\Timesheet\Model\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use File;
......@@ -105,8 +106,7 @@ class DashboardController extends Controller
'td_id' => '1',
'td_date' => date('j-n-Y',strtotime('6/5/2022')),
'td_project' => '1',
'tm_id' => '1',
'tm_staff_id' => '1000',
'fk_tm_id' => '1',
'project_type' => '1',
'fk_o_id' => '',
'tm_year' => '2022',
......@@ -123,8 +123,7 @@ class DashboardController extends Controller
'td_id' => '2',
'td_date' => date('j-n-Y',strtotime('6/5/2022')),
'td_project' => '2',
'tm_id' => '1',
'tm_staff_id' => '1000',
'fk_tm_id' => '1',
'project_type' => '1',
'fk_o_id' => '',
'tm_year' => '2022',
......@@ -174,19 +173,19 @@ class DashboardController extends Controller
$user = users::where('id', Auth::id())->first();
// dd($user);
// check timesheet detail
// check timesheet master
$checkTimesheetDetail = Ts_detail::where('tm_staff_id', $user->u_staffID)
$check = Ts_master::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $year)
->where('tm_month', $month)
->where('tm_phase', $phase)
->whereNotNull('td_hours')
->whereNotNull('tm_chargeable_hrs')
->first();
// kalau ada, dia gi ke edit
if($checkTimesheetDetail)
//kalau ada, dia gi ke edit
if($check)
{
$data = Ts_detail::where('id',$request->id)->first();
$data = Ts_master::where('id',$request->id)->first();
}
//klu xde g create.php
else
......@@ -194,21 +193,21 @@ class DashboardController extends Controller
$data = [];
}
// dd($checkTimesheetDetail);
//kalau ada juga = bawak data details
//check timesheet master
// check timesheet detail
// $check = Ts_master::where('tm_staff_id', $user->u_staffID)
// ->where('tm_year', $year)
// ->where('tm_month', $month)
// $checkTimesheetDetail = Ts_detail::where('fk_tm_staff_id', $user->u_staffID)
// ->where('fk_tm_year', $year)
// ->where('fk_tm_month', $month)
// ->where('tm_phase', $phase)
// ->whereNotNull('tm_chargeable_hrs')
// ->whereNotNull('td_hours')
// ->first();
// //kalau ada, dia gi ke edit
// if($check)
// // kalau ada, dia gi ke edit
// if($checkTimesheetDetail)
// {
// $data = Ts_master::where('id',$request->id)->first();
// $data = Ts_detail::where('id',$request->id)->first();
// }
// //klu xde g create.php
// else
......@@ -216,7 +215,7 @@ class DashboardController extends Controller
// $data = [];
// }
//kalau ada juga = bawak data details
// dd($checkTimesheetDetail);
return view('timesheet::dashboard.borangBolehCaj', compact('userId','projectcode', 'projectname','month','phase','samplequery','daymonth','year','sampleTimesheet_dtl','day','data'));
}
......@@ -236,12 +235,15 @@ class DashboardController extends Controller
return view('timesheet::dashboard.kalendar');
}
public function saveHours(Request $request)
public function savechargeablehours(Request $request)
{
// chargeable, project type 1.
$chargeable = 1;
$nonchargeable = 2;
$overhead = 3;
$user = users::where('id', Auth::id())->first();
// check table master. untuk total chargeable hours.
$check = Ts_master::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $request->year)
......@@ -251,27 +253,32 @@ class DashboardController extends Controller
->first();
//kalau ada, update().
//staff kena edit bila submission timesheet kena reject.
//staff kena edit bila timesheet kena reject.
//kalau ada, biar dlu.
if($check)
{
}
// kalau takda, save().
// kalau takda, save() baru.
else
{
$check = new Ts_master;
$check ->tm_year = $request ->year;
$check ->tm_month = $request ->month;
$check ->tm_phase = $request ->phase;
$check->tm_year = $request->year;
$check->tm_month = $request->month;
$check->tm_phase = $request->phase;
// $check ->tm_chargeable_hrs = ;
$check ->save();
$check->save();
}
$tmasterid = $check->id;
// semak detail dari form
//untuk project type : 1=chargeable,2 nonchargeable, 3=overhead;
// untuk project type : 1 = chargeable, 2 = nonchargeable, 3 = overhead;
// . . .
$detail = $request->hour;
foreach ($detail as $key => $value)
{
foreach ($value as $keyday => $day)
......@@ -279,15 +286,15 @@ class DashboardController extends Controller
$projectid = $key;
$date = $request->year.'-'.$request->month.'-'.sprintf('%02d', $keyday);
$checkTimesheetDetail = Ts_detail::where('fk_p_project_code', $projectid)
->where('td_project_type',1)
$checkTimesheetDetail = Ts_detail::where('td_project', $projectid)
// ->where('td_project_type', $project_type)
->where('td_date', $date)
->where('tm_phase', $request->phase)
->first();
if($checkTimesheetDetail)
{
//update hours
//update hours to null
$valuehour = $day;
if($valuehour == null)
{
......@@ -297,16 +304,31 @@ class DashboardController extends Controller
$checkTimesheetDetail->td_hours = $valuehour;
$checkTimesheetDetail->update();
}else
}//kalau takde, isi semua.
else
{
//isi semua
$tmdetail = new Ts_detail;
$tmdetail->td_date = $date;
$tmdetail->td_project = $projectid;
$tmdetail->fk_tm_id = $tmasterid;
$tmdetail->tm_staff_id = $user->u_staffID;
$tmdetail->tm_month = $check->tm_month;
$tmdetail->tm_year = $check->tm_year;
$tmdetail->tm_phase = $check->tm_phase;
$tmdetail->td_project_type = $chargeable;
$project = Project::where('id', $projectid)->first();
$tmdetail->td_project_name = $project->p_project_description;
$tmdetail->td_hours = $day;
$tmdetail->save();
//$tmdetail -> kjhdiwhdf;
//project = Project::where('id','project')->first();
//
// /lepas save ();
}
......@@ -314,17 +336,17 @@ class DashboardController extends Controller
}
//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)
//buat query sum td_hours where condition :
$sumdetailhour = Ts_detail::where('td_project', $projectid)
->where('td_project_type', $chargeable)
// ->where('td_date', $date)
// ->where('tm_phase', $request->phase)
// ->sum();
->where('tm_phase', $request->phase)
->sum('td_hours');
dd($sumdetailhour);
// $check = Ts_master::where('id', $tmasterid)->first();
// $check->totaloiwfwoei = udaoe
$checktotalhours = Ts_master::where('id', $tmasterid)
->where('tm_chargeable_hrs', $sumdetailhour)
->update();
// return redirect::to('mobile/profile');
......
......@@ -4,14 +4,14 @@ namespace Portal\Timesheet\Model;
use Illuminate\Database\Eloquent\Model;
class P_task extends Model
class Pteam extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'project_task';
protected $table = 'project_team';
/**
......
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