Commit f0636ed1 by hannan

update migration, add tm_years column in timesheet master.

changes in dashboard controller, query to update and save hours.
parent 2e58f616
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTimesheetMasterTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('timesheet_master', function (Blueprint $table) {
$table->integer('tm_year')->after('tm_month')->unsigned()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('timesheet_master', function (Blueprint $table) {
$table->dropColumn('tm_year');
});
}
}
......@@ -18,13 +18,9 @@ input[type=number] {
<div class="ui segment">
<a class="ui blue left ribbon label">Chargeable Form</a>
<br><br>
User Id = {{$userId}}
<br>
<hr>
Day = {{$day}}
@if($day==2)
naisu
@endif
{{$sampleTimesheet_dtl[0]['td_date']}}
<br>
Timesheet for month = {{$month}} <br>
......@@ -34,6 +30,10 @@ input[type=number] {
<hr>
<form class="ui form" action="{{ url('saveHours' )}}" method="POST">
{{csrf_field()}}
<input type="hidden" value="{{$userId}}">
<input type="hidden" value="{{$year}}">
<input type="hidden" value="{{$month}}">
<input type="hidden" value="{{$phase}}">
<table class="ui celled structured table">
<thead>
<tr>
......@@ -97,7 +97,7 @@ input[type=number] {
@endfor
@endif
<td>
<input type="number" onkeypress="onlynumber(event)" name="total-{{$project['td_project']}}" id="total-{{$project['td_project']}}" style="padding-right: 4px;padding-left: 4px;" onchange="limiter(this,'{{$project['td_project']}}');" readonly="">
<input type="text" onkeypress="onlynumber(event)" name="total-{{$project['td_project']}}" id="total-{{$project['td_project']}}" style="padding-right: 4px;padding-left: 4px;" onchange="limiter(this,'{{$project['td_project']}}');" readonly="">
</td>
</tr>
@endforeach
......
......@@ -109,9 +109,10 @@ class DashboardController extends Controller
'tm_staff_id' => '1000',
'project_type' => '1',
'fk_o_id' => '',
'tm_year' => '2022',
'tm_month' => '6',
'tm_phase' => '1',
'td_project_code' => 'LHD20212',
'td_project_code' => 'LHD2022',
'td_project_name' => 'SMART',
'td_hours' => '5'
......@@ -126,6 +127,7 @@ class DashboardController extends Controller
'tm_staff_id' => '1000',
'project_type' => '1',
'fk_o_id' => '',
'tm_year' => '2022',
'tm_month' => '6',
'tm_phase' => '1',
'td_project_code' => 'LHD2021',
......@@ -167,18 +169,30 @@ class DashboardController extends Controller
$daymonth=cal_days_in_month(CAL_GREGORIAN,$month,$year);
// dd($phase);
//check dlam db, kalau dah ada, kuar form edit, kalau belum, kuar form create
//check dlam db, kalau dah ada detail hours, kuar form edit, kalau belum, kuar form create
// $check = TimeSheetMaster::where('tm_staff_id',='id yg tgh login',)
//->where('tm_month', = $month)
//->year('dfsdf')
//->whereNotNull('tm_chargeable_hrs')->first();
$user = users::where('id', Auth::id())->first();
$check = Ts_master::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $year)
->where('tm_month', $month)
->where('tm_phase', $phase)
->whereNotNull('tm_chargeable_hrs')
->first();
//kalau ada, dia gi ke edit
if($check)
{
$data = Ts_master::where('id',$request->id)->first();
}
//klu xde g create.php
else
{
$data = [];
}
//if(check)
//dia g ke edit, klu xde g create.php
//kalau ada juga = bawak data details
return view('timesheet::dashboard.borangBolehCaj', compact('userId','projectcode', 'projectname','month','phase','samplequery','daymonth','year','sampleTimesheet_dtl','day'));
return view('timesheet::dashboard.borangBolehCaj', compact('userId','projectcode', 'projectname','month','phase','samplequery','daymonth','year','sampleTimesheet_dtl','day','data'));
}
public function kalendarCharge()
......@@ -199,6 +213,37 @@ class DashboardController extends Controller
public function saveHours(Request $request)
{
dd($request);
//check dlam db, kalau dah ada detail hours, kuar form edit, kalau belum, kuar form create
$user = users::where('id', Auth::id())->first();
$check = Ts_master::where('tm_staff_id', $user->u_staffID)
->where('tm_year', $year)
->where('tm_month', $month)
->where('tm_phase', $phase)
->whereNotNull('tm_chargeable_hrs')
->first();
//kalau ada, dia gi ke edit
if(check)
{
$data = Ts_master::where('id',$request->id)->first();
$data -> tm_chargeable_hrs = 10;
$data -> update();
}
//klu xde g create.php
else
{
$data = Ts_master::where('id',$request->id)->first();
$data -> tm_month = $request -> month;
$data -> tm_year = $request -> year;
$data -> tm_phase = $request -> phase;
$data -> tm_chargeable_hrs = 8;
$data -> save();
}
//kalau ada juga = bawak data details
// tm_master = Ts_master::where('tm_staff_id','=',Auth::id())
// ->where('tm_month','=',$tm_month)
// ->get();
......
......@@ -13,6 +13,10 @@ class Ts_master extends Model
*/
protected $table = 'timesheet_master';
public function Details()
{
return $this->hasMany('App\Models\Ts_detail','tm_id','id');
}
/**
* undocumented function
......
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