commit

parent 7e89f00e
...@@ -30,6 +30,22 @@ final class Permission extends Enum ...@@ -30,6 +30,22 @@ final class Permission extends Enum
const FINANCE = "FINANCE"; const FINANCE = "FINANCE";
const STAFF = "STAFF"; const STAFF = "STAFF";
// start overtime menu
const APPLICATION_OT = "APPLICATION_OT";
const APPLICATION_OT_REVIEW = "APPLICATION_OT_REVIEW";
const REQUEST_OT = "REQUEST_OT";
const APPLICATION_OT_HOD = "APPLICATION_OT_HOD";
const APPLICATION_OT_PD = "APPLICATION_OT_PD";
const APPLICATION_OT_SUPPORT = "APPLICATION_OT_SUPPORT";
const APPLICATION_OT_APPROVE = "APPLICATION_OT_APPROVE";
// end overtime menu
// start mileage menu
const APPLICATION_MILEAGE = "APPLICATION_MILEAGE";
// end mileage menu
//should added to in table:acl_permission //should added to in table:acl_permission
} }
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('overtime_claim_main', function (Blueprint $table) {
$table->tinyInteger('ocm_query_status')->nullable()->after('ocm_status');
if (!Schema::hasColumn('overtime_claim_main', 'ocm_approved_by')) {
$table->integer('ocm_approved_by')->nullable()->after('ocm_query_status');
}
});
}
public function down(): void
{
Schema::table('overtime_claim_main', function (Blueprint $table) {
$table->dropColumn(['ocm_query_status', 'ocm_approved_by']);
});
}
};
\ No newline at end of file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::create('overtime_audit_query', function (Blueprint $table) {
$table->increments('id');
$table->integer('fk_main');
$table->string('no_permohonan');
$table->integer('fk_user_kueri');
$table->text('remarks')->nullable();
$table->text('respond')->nullable();
$table->timestamp('tarikh')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('overtime_audit_query');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('overtime_request_main', function (Blueprint $table) {
$table->text('orm_query_remark')->nullable()->after('orm_status');
$table->integer('orm_query_by')->nullable()->after('orm_query_remark');
$table->text('orm_query_respond')->nullable()->after('orm_query_by');
});
}
public function down(): void
{
Schema::table('overtime_request_main', function (Blueprint $table) {
$table->dropColumn(['orm_query_remark', 'orm_query_by', 'orm_query_respond']);
});
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('overtime_claim_detail', function (Blueprint $table) {
$table->boolean('ocd_pm_reviewed')->default(0);
$table->integer('ocd_pm_reviewed_by')->nullable();
$table->timestamp('ocd_pm_reviewed_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('overtime_claim_detail', function (Blueprint $table) {
$table->dropColumn([
'ocd_pm_reviewed',
'ocd_pm_reviewed_by',
'ocd_pm_reviewed_at',
]);
});
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('overtime_request_main', function (Blueprint $table) {
$table->string('orm_name')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('overtime_request_main', function (Blueprint $table) {
$table->integer('orm_name')->nullable()->change();
});
}
};
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<div class="ui small modal" id="modalTuntutanBaharu"> <div class="ui small modal" id="modalTuntutanBaharu">
<div class="header"> <div class="header">
<i class="file alternate outline icon"></i> <i class="file alternate outline icon"></i>
Tuntutan Baharu New Claim
</div> </div>
<div class="content"> <div class="content">
...@@ -28,15 +28,15 @@ ...@@ -28,15 +28,15 @@
<p style="color:#888; margin-bottom:1.2rem;"> <p style="color:#888; margin-bottom:1.2rem;">
<i class="info circle icon"></i> <i class="info circle icon"></i>
Pilih bulan dan tahun untuk tuntutan baharu. Select the month and year for the new claim.
Butiran lanjut boleh dilengkapkan selepas ini. Further details can be completed later.
</p> </p>
@php @php
$monthNames = [ $monthNames = [
1 => 'Januari', 2 => 'Februari', 3 => 'Mac', 4 => 'April', 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
5 => 'Mei', 6 => 'Jun', 7 => 'Julai', 8 => 'Ogos', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Disember', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December',
]; ];
$currentYear = now()->year; $currentYear = now()->year;
@endphp @endphp
...@@ -44,10 +44,10 @@ ...@@ -44,10 +44,10 @@
<div class="two fields"> <div class="two fields">
<div class="required field" id="field-ocm_month"> <div class="required field" id="field-ocm_month">
<label>Bulan</label> <label>Month</label>
<select name="ocm_month" id="ocm_month" <select name="ocm_month" id="ocm_month"
style="width:100%; padding:8px; border:1px solid rgba(34,36,38,.15); border-radius:4px;"> style="width:100%; padding:8px; border:1px solid rgba(34,36,38,.15); border-radius:4px;">
<option value="">-- Pilih Bulan --</option> <option value="">-- Choose Month --</option>
@foreach($monthNames as $monthNum => $monthName) @foreach($monthNames as $monthNum => $monthName)
<option value="{{ $monthNum }}">{{ $monthName }}</option> <option value="{{ $monthNum }}">{{ $monthName }}</option>
@endforeach @endforeach
...@@ -55,10 +55,10 @@ ...@@ -55,10 +55,10 @@
</div> </div>
<div class="required field" id="field-ocm_year"> <div class="required field" id="field-ocm_year">
<label>Tahun</label> <label>Year</label>
<select name="ocm_year" id="ocm_year" <select name="ocm_year" id="ocm_year"
style="width:100%; padding:8px; border:1px solid rgba(34,36,38,.15); border-radius:4px;"> style="width:100%; padding:8px; border:1px solid rgba(34,36,38,.15); border-radius:4px;">
<option value="">-- Pilih Tahun --</option> <option value="">-- Choose Year --</option>
@for($y = now()->year; $y >= now()->year - 3; $y--) @for($y = now()->year; $y >= now()->year - 3; $y--)
<option value="{{ $y }}" {{ $y === now()->year ? 'selected' : '' }}> <option value="{{ $y }}" {{ $y === now()->year ? 'selected' : '' }}>
{{ $y }} {{ $y }}
...@@ -74,10 +74,10 @@ ...@@ -74,10 +74,10 @@
<div class="actions"> <div class="actions">
<button type="button" class="ui teal button" id="btn-modal-claim-submit"> <button type="button" class="ui teal button" id="btn-modal-claim-submit">
Cipta Tuntutan Create New Claim
</button> </button>
<button type="button" class="ui deny button"> <button type="button" class="ui deny button">
<i class="times icon"></i> Batal <i class="times icon"></i> Cancel
</button> </button>
</div> </div>
</div> </div>
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
9: 'September', 10: 'Oktober', 11: 'November', 12: 'Disember', 9: 'September', 10: 'Oktober', 11: 'November', 12: 'Disember',
}; };
// ONE PERMOHONAN PER MONTH // REFRESH MONTH
function refreshMonthOptions() { function refreshMonthOptions() {
var year = $('#ocm_year').val(); var year = $('#ocm_year').val();
if (!year) return; if (!year) return;
...@@ -102,28 +102,27 @@ function refreshMonthOptions() { ...@@ -102,28 +102,27 @@ function refreshMonthOptions() {
url : EXISTING_MONTHS_URL, url : EXISTING_MONTHS_URL,
method : 'GET', method : 'GET',
success: function (res) { success: function (res) {
var occupied = (res.success && res.existingMonths) ? res.existingMonths : []; var claimed = (res.success && res.existingMonths) ? res.existingMonths : [];
buildMonthOptions(year, occupied); buildMonthOptions(year, claimed);
}, },
error: function (xhr) { error: function (xhr) {
console.warn('Gagal memuat bulan sedia ada.', xhr.status, xhr.statusText); console.warn('Error fetching existing months.', xhr.status, xhr.statusText);
buildMonthOptions(year, []); buildMonthOptions(year, []);
} }
}); });
} }
function buildMonthOptions(year, occupied) { function buildMonthOptions(year, claimed) {
var current = $('#ocm_month').val(); var current = $('#ocm_month').val();
var html = '<option value="">-- Pilih Bulan --</option>'; var html = '<option value="">-- Choose Month --</option>';
var claimedYear = claimed.filter(function (m) { return String(m).startsWith(String(year)); });
for (var m = 1; m <= 12; m++) { for (var m = 1; m <= 12; m++) {
var key = String(year) + String(m).padStart(2, '0'); var key = String(year) + String(m).padStart(2, '0');
var isTaken = occupied.indexOf(key) !== -1; var isClaimed = claimedYear.indexOf(key) !== -1;
var label = isTaken var label = MONTH_NAMES[m] + (isClaimed ? ' (Already submitted claim)' : '');
? MONTH_NAMES[m] + ' (Telah ada permohonan)' var disabled = isClaimed ? ' disabled' : '';
: MONTH_NAMES[m]; var selected = (!disabled && String(current) === String(m)) ? ' selected' : '';
var disabled = isTaken ? ' disabled' : '';
var selected = (!isTaken && String(current) === String(m)) ? ' selected' : '';
html += '<option value="' + m + '"' + disabled + selected + '>' + label + '</option>'; html += '<option value="' + m + '"' + disabled + selected + '>' + label + '</option>';
} }
...@@ -134,7 +133,6 @@ function buildMonthOptions(year, occupied) { ...@@ -134,7 +133,6 @@ function buildMonthOptions(year, occupied) {
$('#ocm_year').on('change', refreshMonthOptions); $('#ocm_year').on('change', refreshMonthOptions);
refreshMonthOptions(); refreshMonthOptions();
// REFRESH LIST EVERY TIME MODAL OPENS
$('#modalTuntutanBaharu').on('show', function () { $('#modalTuntutanBaharu').on('show', function () {
$('#modal-success-msg, #modal-error-msg').hide(); $('#modal-success-msg, #modal-error-msg').hide();
$('#field-ocm_month, #field-ocm_year').removeClass('error'); $('#field-ocm_month, #field-ocm_year').removeClass('error');
...@@ -156,7 +154,7 @@ function buildMonthOptions(year, occupied) { ...@@ -156,7 +154,7 @@ function buildMonthOptions(year, occupied) {
if (!month) { $('#field-ocm_month').addClass('error'); hasError = true; } if (!month) { $('#field-ocm_month').addClass('error'); hasError = true; }
if (!year) { $('#field-ocm_year').addClass('error'); hasError = true; } if (!year) { $('#field-ocm_year').addClass('error'); hasError = true; }
if (hasError) { if (hasError) {
$('#modal-error-text').text('Sila pilih bulan dan tahun.'); $('#modal-error-text').text('Choose month and year.');
$('#modal-error-msg').show(); $('#modal-error-msg').show();
return; return;
} }
...@@ -176,14 +174,14 @@ function buildMonthOptions(year, occupied) { ...@@ -176,14 +174,14 @@ function buildMonthOptions(year, occupied) {
$('#modal-success-msg').show(); $('#modal-success-msg').show();
setTimeout(function () { window.location.href = res.redirect; }, 800); setTimeout(function () { window.location.href = res.redirect; }, 800);
} else { } else {
$('#modal-error-text').text(res.message || 'Ralat tidak diketahui.'); $('#modal-error-text').text(res.message || 'Unknown error.');
$('#modal-error-msg').show(); $('#modal-error-msg').show();
refreshMonthOptions(); refreshMonthOptions();
} }
}, },
error: function (xhr) { error: function (xhr) {
btn.removeClass('loading disabled'); btn.removeClass('loading disabled');
var msg = 'Ralat rangkaian. Sila cuba lagi.'; var msg = 'Network error. Please try again';
if (xhr.status === 422 && xhr.responseJSON && xhr.responseJSON.errors) { if (xhr.status === 422 && xhr.responseJSON && xhr.responseJSON.errors) {
var errors = xhr.responseJSON.errors; var errors = xhr.responseJSON.errors;
msg = Object.values(errors).flat().join(' '); msg = Object.values(errors).flat().join(' ');
......
@extends('ui::layouts.app')
@section('content')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
@if(session('success'))
<div class="ui positive message">{{ session('success') }}</div>
@endif
<div class="ui segment">
<a class="ui teal left ribbon label">List of Overtime Claims - HOD Support</a>
<div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">
List of Overtime Claims - HOD Support
<div class="sub header">Only claims with status <strong>{{ $statuses[5]->description ?? '-' }}</strong> wil be shown.</div>
</div>
</h1>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Overtime Claims (HOD)'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'ocm_apply_no', 'sortable' => true],
['header' => __('Name'), 'raw' => function ($row) {
return $row->ocm_staff_name ?: '-';
}],
['header' => __('Month / Year'), 'raw' => function ($row) {
return ($row->ocm_month && $row->ocm_year)
? \Carbon\Carbon::createFromDate($row->ocm_year, $row->ocm_month, 1)->format('M Y')
: '-';
}],
['header' => __('Date Submitted'), 'raw' => function ($row) {
return $row->ocm_submit_date
? \Carbon\Carbon::parse($row->ocm_submit_date)->format('d/m/Y')
: '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->ocm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
$view = "<a href='" . route('overtime::overtime.hodviewclaim', $row->id) . "'
class='ui blue button tiny'>
<i class='eye icon'></i> Review
</a>";
return "<div style='text-align:center;'>{$view}</div>";
}],
])
->render()
!!}
</div>
</div>
</div>
@endsection
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
@section('content') @section('content')
@include('overtime::overtime.modal.create_modal') @include('overtime::overtime.overtimeclaim.create_modal')
@include('overtime::overtime.modal.view_modal') @include('overtime::overtime.overtimeclaim.view_modal')
<style> <style>
.table-uppercase td { text-transform: uppercase; } .table-uppercase td { text-transform: uppercase; }
...@@ -17,19 +17,19 @@ ...@@ -17,19 +17,19 @@
@endif @endif
<div class="ui segment"> <div class="ui segment">
<a class="ui teal left ribbon label">Senarai Tuntutan Lebih Masa</a> <a class="ui teal left ribbon label">List of Overtime Claim Forms</a>
<div class="ui segment"> <div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;"> <div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column"> <div class="column">
<h1 class="ui header"> <h1 class="ui header">
<div class="content">Senarai Tuntutan Lebih Masa</div> <div class="content">List of Overtime Claim Forms</div>
</h1> </h1>
</div> </div>
<div class="column" style="text-align:right; padding-top:1.2rem;"> <div class="column" style="text-align:right; padding-top:1.2rem;">
<button class="ui teal button" id="btn-tuntutan-baharu"> <button class="ui teal button" id="btn-tuntutan-baharu">
<i class="plus icon"></i> Tuntutan Baharu <i class="plus icon"></i> New Claim
</button> </button>
</div> </div>
</div> </div>
...@@ -39,17 +39,17 @@ ...@@ -39,17 +39,17 @@
<div class="column sixteen wide table-uppercase"> <div class="column sixteen wide table-uppercase">
{!! {!!
Suitable::source($list) Suitable::source($list)
->title(__('Senarai Tuntutan Lebih Masa')) ->title(__('List of Overtime Claim Forms'))
->columns([ ->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'), \Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('No. Tuntutan'), 'field' => 'ocm_apply_no', 'sortable' => true], ['header' => __('Application Number'), 'field' => 'ocm_apply_no', 'sortable' => true],
['header' => __('Nama'), 'raw' => function ($row) { ['header' => __('Name'), 'raw' => function ($row) {
return $row->ocm_staff_name ?: '-'; return $row->ocm_staff_name ?: '-';
}], }],
['header' => __('Bulan / Tahun'), 'raw' => function ($row) { ['header' => __('Month/Year'), 'raw' => function ($row) {
if ($row->ocm_year && $row->ocm_month) { if ($row->ocm_year && $row->ocm_month) {
$months = [ $months = [
1=>'Jan',2=>'Feb',3=>'Mac',4=>'Apr', 1=>'Jan',2=>'Feb',3=>'Mac',4=>'Apr',
...@@ -62,53 +62,47 @@ ...@@ -62,53 +62,47 @@
}], }],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) { ['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$colours = [ $label = $statuses[$row->ocm_status]->description ?? '-';
1 => 'grey', return "<span class='ui label'>{$label}</span>";
2 => 'blue',
3 => 'blue',
4 => 'red',
5 => 'yellow',
6 => 'orange',
7 => 'yellow',
8 => 'orange',
9 => 'yellow',
10 => 'orange',
11 => 'green',
12 => 'red',
];
$statusRow = $statuses[$row->ocm_status] ?? null;
$label = $statusRow ? $statusRow->description : '-';
$colour = $colours[$row->ocm_status] ?? 'grey';
return "<span class='ui {$colour} label'>{$label}</span>";
}], }],
['header' => __('Tindakan'), 'raw' => function ($row) { ['header' => __('Action'), 'raw' => function ($row) {
$view = "<button $view = "<button
class='ui blue button tiny' class='ui blue button tiny'
onclick='viewTuntutan({$row->id})'> onclick='viewTuntutan({$row->id})'>
<i class='eye icon'></i> Lihat <i class='eye icon'></i> View
</button>"; </button>";
$edit = "<a href='" . route('overtime::overtime.editovertimeclaim', $row->id) . "' // Editable only for Draf (1) or Dikueri oleh PM (6)
class='ui yellow button tiny'> $canEdit = in_array($row->ocm_status, [1, 6]);
<i class='edit icon'></i> Kemaskini
</a>"; $edit = $canEdit
? "<a href='" . route('overtime::overtime.editovertimeclaim', $row->id) . "'
$delete = "<button class='ui yellow button tiny'>
class='ui red button tiny btn-delete' <i class='edit icon'></i> Update
data-id='{$row->id}' </a>"
data-url='" . route('overtime::overtime.deleteovertimeclaim', $row->id) . "'> : "";
<i class='trash icon'></i> Padam
</button>"; // Batal allowed only from Draf (1) or Dikueri oleh PM (6)
$canBatal = in_array($row->ocm_status, [1, 6]);
return "{$view} {$edit} {$delete}";
$batal = $canBatal
? "<button
class='ui red button tiny btn-batal'
data-id='{$row->id}'
data-url='" . route('overtime::overtime.batalovertimeclaim', $row->id) . "'>
<i class='ban icon'></i> Cancel
</button>"
: "";
return "<div style='display:flex;justify-content:center;gap:.35rem;flex-wrap:wrap;'>{$view} {$edit} {$batal}</div>";
}], }],
]) ])
->render() ->render()
!!} !!}
</div> </div>
</div> </div>
</div> </div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
...@@ -119,30 +113,30 @@ ...@@ -119,30 +113,30 @@
$('#modalTuntutanBaharu').modal({ blurring: true, closable: true }).modal('show'); $('#modalTuntutanBaharu').modal({ blurring: true, closable: true }).modal('show');
}); });
$(document).on('click', '.btn-delete', function () { $(document).on('click', '.btn-batal', function () {
if (!confirm('Padam tuntutan ini? Semua butiran dan nombor tuntutan akan dipadamkan.')) return; if (!confirm('Cancel this claim form? This action cannot be undone.')) return;
var url = $(this).data('url'); var url = $(this).data('url');
var row = $(this).closest('tr'); var row = $(this).closest('tr');
$.ajax({ $.ajax({
url : url, url : url,
method : 'POST', method : 'POST',
data : { _token: $('meta[name="csrf-token"]').attr('content') }, data : { _token: $('meta[name="csrf-token"]').attr('content') },
success: function (res) { success: function (res) {
if (res.success) { if (res.success) {
row.fadeOut(300, function () { $(this).remove(); }); location.reload();
} else { } else {
alert(res.message || 'Ralat semasa memadam.'); alert(res.message || 'Error while canceling. Please try again');
} }
}, },
error: function () { error: function () {
alert('Ralat rangkaian. Sila cuba lagi.'); alert('Network error.');
}, },
});
}); });
});
}); });
</script> </script>
@endsection @endsection
\ No newline at end of file
@extends('ui::layouts.app')
@section('content')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
<div class="ui segment">
<a class="ui teal left ribbon label">List of Overtime Claims - PD Approval</a>
<div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">
List of Overtime Claims - PD Approval
<div class="sub header">Claims with status <strong>{{ $statuses[7]->description ?? '-' }}</strong> and <strong>{{ $statuses[11]->description ?? '-' }}</strong>.</div>
</div>
</h1>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Overtime Claims (PD)'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'ocm_apply_no', 'sortable' => true],
['header' => __('Name'), 'raw' => function ($row) {
return $row->ocm_staff_name ?: '-';
}],
['header' => __('Month / Year'), 'raw' => function ($row) {
return ($row->ocm_month && $row->ocm_year)
? \Carbon\Carbon::createFromDate($row->ocm_year, $row->ocm_month, 1)->format('M Y')
: '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->ocm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
$view = "<a href='" . route('overtime::overtime.pdviewclaim', $row->id) . "'
class='ui blue button tiny'>
<i class='eye icon'></i> Lihat
</a>";
return "<div style='text-align:center;'>{$view}</div>";
}],
])
->render()
!!}
</div>
</div>
</div>
@endsection
@extends('ui::layouts.app')
@section('content')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
<div class="ui segment">
<a class="ui teal left ribbon label">List of Overtime Claim Forms</a>
<div class="ui segment">
<div class="ui two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">List of Overtime Claim Forms</div>
</h1>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Overtime Claim Forms (PM)'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'ocm_apply_no', 'sortable' => true],
['header' => __('Name'), 'raw' => function ($row) {
return $row->ocm_staff_name ?: '-';
}],
['header' => __('Month / Year'), 'raw' => function ($row) {
$months = [
1=>'Jan',2=>'Feb',3=>'Mac',4=>'Apr',
5=>'Mei',6=>'Jun',7=>'Jul',8=>'Ogos',
9=>'Sep',10=>'Okt',11=>'Nov',12=>'Dis',
];
if ($row->ocm_year && $row->ocm_month) {
return ($months[$row->ocm_month] ?? '-') . ' ' . $row->ocm_year;
}
return '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->ocm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
return "<a href='" . route('overtime::overtime.pmviewclaim', $row->id) . "'\n class='ui blue button tiny'>\n <i class='eye icon'></i> Review\n </a>";
}],
])
->render()
!!}
</div>
</div>
</div>
@push('scripts')
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</script>
@endpush
@endsection
<style>
.rf-summary {
background: #ddeeff; border-radius: 6px;
padding: .9rem 1.2rem; margin-bottom: 1.2rem; line-height: 1.7;
}
.rf-summary .apply-no { font-size: 1.05rem; font-weight: 700; color: #1a56a0; }
.rf-summary .meta-line { font-size: .92rem; color: #333; }
.rf-tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.rf-tbl th, .rf-tbl td {
border: 1px solid #cfd8e3; padding: 6px 10px;
text-align: center; vertical-align: middle;
}
.rf-tbl thead th { background: #2185d0; color: #fff; font-size: .82rem; }
.rf-tbl tbody td.td-left { text-align: left; }
.rf-tbl tfoot td {
background: #ddeeff; font-weight: 700; color: #1a56a0;
border-top: 2px solid #2185d0;
}
.rf-tbl tfoot .lbl { text-align: right; font-size: .82rem; letter-spacing: .04em; }
</style>
<div class="ui segment" style="padding-bottom: 2rem;">
@php
$project = \DB::table('lkp_project')->where('id', $main->orm_project ?? null)->value('p_project_description');
$department = \DB::table('lkp_department')->where('id', $main->orm_department ?? null)->value('name');
$requestedBy = \DB::table('project_team')->where('id', $main->orm_requested_by_id ?? null)->value('pt_team');
@endphp
<div class="rf-summary">
<div class="apply-no">{{ $main->orm_apply_no ?? ('#' . $main->id) }}</div>
<div class="meta-line"><strong>Project:</strong> {{ $project ?? '-' }}</div>
<div class="meta-line"><strong>Date:</strong> {{ $main->orm_date ? \Carbon\Carbon::parse($main->orm_date)->format('d/m/Y') : '-' }}</div>
<div class="meta-line"><strong>Requested By:</strong> {{ $requestedBy ?? '-' }}</div>
<div class="meta-line"><strong>Department:</strong> {{ $department ?? '-' }}</div>
</div>
<div style="overflow-x:auto;">
<table class="rf-tbl">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Overtime Month</th>
<th>Budgeted</th>
<th>Utilised to Date</th>
<th>Planned OT Hour</th>
<th>Balance</th>
<th>Reason</th>
<th>Total Hours</th>
</tr>
</thead>
<tbody>
@forelse($details as $i => $d)
<tr>
<td>{{ $i + 1 }}</td>
<td class="td-left">{{ $d->ord_name ?? '-' }}</td>
<td>{{ $d->ord_month_of_overtime ? \Carbon\Carbon::parse($d->ord_month_of_overtime)->format('M Y') : '-' }}</td>
<td>{{ number_format($d->ord_budgeted ?? 0, 2) }}</td>
<td>{{ number_format($d->ord_utilised_to_date ?? 0, 2) }}</td>
<td>{{ number_format($d->ord_planned_ot_hour ?? 0, 2) }}</td>
<td>{{ number_format($d->ord_balance ?? 0, 2) }}</td>
<td class="td-left">{{ $d->ord_reason ?? '-' }}</td>
<td><strong>{{ number_format($d->ord_total_hours ?? 0, 2) }}</strong></td>
</tr>
@empty
<tr><td colspan="9" style="color:#bbb; font-style:italic; padding:1.5rem;">No details.</td></tr>
@endforelse
</tbody>
<tfoot>
<tr>
<td colspan="8" class="lbl">TOTAL HOURS OVERALL</td>
<td>{{ number_format($details->sum('ord_total_hours'), 2) }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
\ No newline at end of file
...@@ -30,21 +30,21 @@ ...@@ -30,21 +30,21 @@
#modalViewTuntutan .vm-loading { text-align: center; padding: 2.5rem; color: #888; } #modalViewTuntutan .vm-loading { text-align: center; padding: 2.5rem; color: #888; }
</style> </style>
<div class="ui large modal" id="modalViewTuntutan"> <div class="ui fullscreen modal" id="modalViewTuntutan">
<div class="header"> <div class="header">
<i class="eye icon"></i> <i class="eye icon"></i>
Lihat Tuntutan Lebih Masa View Overtime Claim Form
</div> </div>
<div class="scrolling content" id="vm-claim-content"> <div class="scrolling content" id="vm-claim-content">
<div class="vm-loading"> <div class="vm-loading">
<i class="spinner loading icon"></i> Memuatkan data… <i class="spinner loading icon"></i> Loading data…
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
<button class="ui grey button" onclick="$('#modalViewTuntutan').modal('hide');"> <button class="ui grey button" onclick="$('#modalViewTuntutan').modal('hide');">
<i class="times icon"></i> Tutup <i class="times icon"></i> Close
</button> </button>
</div> </div>
</div> </div>
...@@ -72,7 +72,7 @@ function vcmFmtDate(str) { ...@@ -72,7 +72,7 @@ function vcmFmtDate(str) {
function viewTuntutan(id) { function viewTuntutan(id) {
$('#vm-claim-content').html( $('#vm-claim-content').html(
'<div class="vm-loading"><i class="spinner loading icon"></i> Memuatkan data…</div>' '<div class="vm-loading"><i class="spinner loading icon"></i> Loading data…</div>'
); );
$('#modalViewTuntutan').modal({ blurring: true, closable: true }).modal('show'); $('#modalViewTuntutan').modal({ blurring: true, closable: true }).modal('show');
...@@ -85,21 +85,20 @@ function viewTuntutan(id) { ...@@ -85,21 +85,20 @@ function viewTuntutan(id) {
} else { } else {
$('#vm-claim-content').html( $('#vm-claim-content').html(
'<div class="ui negative message"><p>' '<div class="ui negative message"><p>'
+ vcmEsc(res.message || 'Ralat semasa memuatkan data.') + vcmEsc(res.message || 'Error occurred while loading data.')
+ '</p></div>' + '</p></div>'
); );
} }
}, },
error: function () { error: function () {
$('#vm-claim-content').html( $('#vm-claim-content').html(
'<div class="ui negative message"><p>Ralat rangkaian. Sila cuba lagi.</p></div>' '<div class="ui negative message"><p>Network error. Please try again.</p></div>'
); );
}, },
}); });
} }
function vcmBuildHtml(main, details) { function vcmBuildHtml(main, details) {
// Status label comes directly from the controller (lkp_status lookup)
var badge = '<span class="ui label" style="font-size:.78rem;">' + vcmEsc(main.ocm_status_label || '-') + '</span>'; var badge = '<span class="ui label" style="font-size:.78rem;">' + vcmEsc(main.ocm_status_label || '-') + '</span>';
var monthName = (main.ocm_month && main.ocm_year) var monthName = (main.ocm_month && main.ocm_year)
...@@ -108,24 +107,26 @@ function vcmBuildHtml(main, details) { ...@@ -108,24 +107,26 @@ function vcmBuildHtml(main, details) {
var html = '<div class="vm-summary">' var html = '<div class="vm-summary">'
+ '<div class="apply-no">' + vcmEsc(main.ocm_apply_no || '-') + '</div>' + '<div class="apply-no">' + vcmEsc(main.ocm_apply_no || '-') + '</div>'
+ '<div class="meta-line">Nama: <strong>' + vcmEsc(main.ocm_staff_name || '-') + '</strong></div>' + '<div class="meta-line">Request by: <strong>' + vcmEsc(main.ocm_staff_name || '-') + '</strong></div>'
+ '<div class="meta-line">Bulan: <strong>' + monthName + '</strong></div>' + '<div class="meta-line">Department: <strong>' + vcmEsc(main.ocm_division_label || '-') + '</strong></div>'
+ '<div class="meta-line">Status: ' + badge + '</div>'; + '<div class="meta-line">Month/Year: <strong>' + monthName + '</strong></div>'
if (main.ocm_submit_date) + '<div class="meta-line">Status: ' + badge + '</div>'
html += '<div class="meta-line">Tarikh Hantar: <strong>' + vcmFmtDate(main.ocm_submit_date) + '</strong></div>'; + '<div class="meta-line">Claim Date: <strong>' + vcmFmtDate(main.ocm_submit_date) + '</strong></div>'
if (main.ocm_approved_date) + '<div class="meta-line">Approved by: <strong>' + vcmEsc(main.ocm_approved_by_name || '-') + '</strong></div>'
html += '<div class="meta-line">Tarikh Lulus: <strong>' + vcmFmtDate(main.ocm_approved_date) + '</strong></div>'; + '<div class="meta-line">Approved Date: <strong>' + vcmFmtDate(main.ocm_approved_date) + '</strong></div>'
html += '</div>'; html += '</div>';
html += '<div style="overflow-x:auto;">' html += '<div style="overflow-x:auto;">'
+ '<table class="vm-tbl"><thead>' + '<table class="vm-tbl"><thead>'
+ '<tr class="grp">' + '<tr class="grp">'
+ '<th rowspan="2" class="vm-plain" style="min-width:105px;vertical-align:middle;">Tarikh</th>' + '<th rowspan="2" class="vm-plain" style="min-width:105px;vertical-align:middle;">Date</th>'
+ '<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Jenis Hari</th>' + '<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Day Type</th>'
+ '<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Office Hour</th>' + '<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Office Hour</th>'
+ '<th colspan="2" style="min-width:180px;">Overtime</th>' + '<th colspan="2" style="min-width:180px;">Overtime</th>'
+ '<th rowspan="2" style="min-width:180px;vertical-align:middle;">Projek</th>' + '<th rowspan="2" style="min-width:180px;vertical-align:middle;">Project</th>'
+ '<th rowspan="2" style="min-width:280px;vertical-align:middle;">Tasks</th>' + '<th rowspan="2" style="min-width:220px;vertical-align:middle;">Tasks</th>'
+ '<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">PM Review</th>'
+ '<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">Total Hours</th>'
+ '<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">Effective Hours</th>' + '<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">Effective Hours</th>'
+ '</tr>' + '</tr>'
+ '<tr class="grp">' + '<tr class="grp">'
...@@ -135,12 +136,13 @@ function vcmBuildHtml(main, details) { ...@@ -135,12 +136,13 @@ function vcmBuildHtml(main, details) {
+ '</thead><tbody>'; + '</thead><tbody>';
if (!details || details.length === 0) { if (!details || details.length === 0) {
html += '<tr><td colspan="8" class="vm-empty">Tiada butiran ditambah.</td></tr>' html += '<tr><td colspan="10" class="vm-empty">No details added.</td></tr>'
+ '</tbody></table></div>'; + '</tbody></table></div>';
return html; return html;
} }
var grandTotal = 0; var grandTotalTotal = 0;
var grandTotalEffective = 0;
details.forEach(function (d) { details.forEach(function (d) {
var dt = new Date(d.ocd_date); var dt = new Date(d.ocd_date);
...@@ -149,8 +151,10 @@ function vcmBuildHtml(main, details) { ...@@ -149,8 +151,10 @@ function vcmBuildHtml(main, details) {
var dateLabel = vcmPad(day) + ' ' + VCM_MONTHS[dt.getMonth()] + ' ' + dt.getFullYear() var dateLabel = vcmPad(day) + ' ' + VCM_MONTHS[dt.getMonth()] + ' ' + dt.getFullYear()
+ '<br><small style="color:#999;font-weight:400;">' + dayName + '</small>'; + '<br><small style="color:#999;font-weight:400;">' + dayName + '</small>';
var hours = parseFloat(d.ocd_effective_hours) || 0; var totalHours = parseFloat(d.ocd_total_hours) || 0;
grandTotal += hours; var effectiveHours = parseFloat(d.ocd_effective_hours) || 0;
grandTotalTotal += totalHours;
grandTotalEffective += effectiveHours;
html += '<tr>' html += '<tr>'
+ '<td>' + dateLabel + '</td>' + '<td>' + dateLabel + '</td>'
...@@ -159,15 +163,21 @@ function vcmBuildHtml(main, details) { ...@@ -159,15 +163,21 @@ function vcmBuildHtml(main, details) {
+ '<td>' + vcmEsc(d.ocd_overtime_from || '-') + '</td>' + '<td>' + vcmEsc(d.ocd_overtime_from || '-') + '</td>'
+ '<td>' + vcmEsc(d.ocd_overtime_to || '-') + '</td>' + '<td>' + vcmEsc(d.ocd_overtime_to || '-') + '</td>'
+ '<td>' + vcmEsc(d.project_name || '-') + '</td>' + '<td>' + vcmEsc(d.project_name || '-') + '</td>'
+ '<td class="vm-left">' + vcmEsc(d.ocd_tasks || '-') + '</td>' + '<td class="vm-left">' + vcmEsc(d.ocd_tasks || '-') + '</td>'
+ '<td><strong>' + hours.toFixed(1) + '</strong></td>' + '<td>' + (d.ocd_pm_reviewed
? '<span class="ui green label">Reviewed</span>'
: '<span class="ui orange label">Pending</span>')
+ '</td>'
+ '<td><strong>' + totalHours.toFixed(1) + '</strong></td>'
+ '<td><strong>' + effectiveHours.toFixed(1) + '</strong></td>'
+ '</tr>'; + '</tr>';
}); });
html += '</tbody>' html += '</tbody>'
+ '<tfoot><tr>' + '<tfoot><tr>'
+ '<td colspan="7" class="lbl">GRAND TOTAL HOURS</td>' + '<td colspan="8" class="lbl">GRAND TOTAL HOURS</td>'
+ '<td style="text-align:center;">' + grandTotal.toFixed(1) + '</td>' + '<td style="text-align:center;">' + grandTotalTotal.toFixed(1) + '</td>'
+ '<td style="text-align:center;">' + grandTotalEffective.toFixed(1) + '</td>'
+ '</tr></tfoot>' + '</tr></tfoot>'
+ '</table></div>'; + '</table></div>';
......
<?php
$months = ['Jan','Feb','Mac','Apr','Mei','Jun','Jul','Ogos','Sep','Okt','Nov','Dis'];
$days = ['Ahad','Isnin','Selasa','Rabu','Khamis','Jumaat','Sabtu'];
$monthNames = [
'Januari','Februari','Mac','April','Mei','Jun',
'Julai','Ogos','September','Oktober','November','Disember'
];
$escape = function ($value) {
if ($value === null || $value === '') {
return '';
}
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
};
$formatDate = function ($value) use ($escape) {
if (empty($value)) {
return '-';
}
try {
$date = $value instanceof \DateTimeInterface ? $value : \Carbon\Carbon::parse($value);
return $date->format('d/m/Y');
} catch (\Throwable $e) {
return '-';
}
};
$monthName = ($main['ocm_month'] && $main['ocm_year'])
? ($monthNames[(int) $main['ocm_month'] - 1] ?? '-') . ' ' . $main['ocm_year']
: '-';
$badge = '<span class="ui label" style="font-size:.78rem;">' . $escape($main['ocm_status_label'] ?? '-') . '</span>';
$grandTotalTotal = 0;
$grandTotalEffective = 0;
?>
<div class="vm-summary">
<div class="apply-no">{{ $escape($main['ocm_apply_no'] ?? '-') }}</div>
<div class="meta-line">Request by: <strong>{{ $escape($main['ocm_staff_name'] ?? '-') }}</strong></div>
<div class="meta-line">Department: <strong>{{ $escape($main['ocm_division_label'] ?? '-') }}</strong></div>
<div class="meta-line">Month/Year: <strong>{{ $escape($monthName) }}</strong></div>
<div class="meta-line">Status: {!! $badge !!}</div>
<div class="meta-line">Claim Date: <strong>{{ $formatDate($main['ocm_submit_date'] ?? null) }}</strong></div>
<div class="meta-line">Approved by: <strong>{{ $escape($main['ocm_approved_by_name'] ?? '-') }}</strong></div>
<div class="meta-line">Approved Date: <strong>{{ $formatDate($main['ocm_approved_date'] ?? null) }}</strong></div>
</div>
<div style="overflow-x:auto;">
<table class="vm-tbl">
<thead>
<tr class="grp">
<th rowspan="2" class="vm-plain" style="min-width:105px;vertical-align:middle;">Date</th>
<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Day Type</th>
<th rowspan="2" class="vm-plain" style="min-width:110px;vertical-align:middle;">Office Hour</th>
<th colspan="2" style="min-width:180px;">Overtime</th>
<th rowspan="2" style="min-width:180px;vertical-align:middle;">Project</th>
<th rowspan="2" style="min-width:220px;vertical-align:middle;">Tasks</th>
<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">PM Review</th>
<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">Total Hours</th>
<th rowspan="2" class="vm-light" style="min-width:90px; vertical-align:middle;">Effective Hours</th>
</tr>
<tr class="grp">
<th class="vm-light" style="min-width:85px;">From</th>
<th class="vm-light" style="min-width:85px;">To</th>
</tr>
</thead>
<tbody>
@if (empty($details))
<tr><td colspan="10" class="vm-empty">No details added.</td></tr>
@else
@foreach ($details as $detail)
@php
try {
$date = !empty($detail['ocd_date']) ? \Carbon\Carbon::parse($detail['ocd_date']) : null;
} catch (\Throwable $e) {
$date = null;
}
$dayName = $date ? $days[$date->dayOfWeek] : '-';
$dateLabel = $date ? $date->format('d') . ' ' . ($months[$date->month - 1] ?? '') . ' ' . $date->format('Y') . '<br><small style="color:#999;font-weight:400;">' . $dayName . '</small>' : '-';
$totalHours = (float) ($detail['ocd_total_hours'] ?? 0);
$effectiveHours = (float) ($detail['ocd_effective_hours'] ?? 0);
$grandTotalTotal += $totalHours;
$grandTotalEffective += $effectiveHours;
@endphp
<tr>
<td>{!! $dateLabel !!}</td>
<td class="vm-shade">{{ $escape($detail['ocd_day_type'] ?? '-') }}</td>
<td class="vm-shade">{{ $escape($detail['ocd_office_hour'] ?? '-') }}</td>
<td>{{ $escape($detail['ocd_overtime_from'] ?? '-') }}</td>
<td>{{ $escape($detail['ocd_overtime_to'] ?? '-') }}</td>
<td>{{ $escape($detail['project_name'] ?? '-') }}</td>
<td class="vm-left">{{ $escape($detail['ocd_tasks'] ?? '-') }}</td>
<td>
@if (!empty($detail['ocd_pm_reviewed']))
<span class="ui green label">Reviewed</span>
@else
<span class="ui orange label">Pending</span>
@endif
</td>
<td><strong>{{ number_format($totalHours, 1) }}</strong></td>
<td><strong>{{ number_format($effectiveHours, 1) }}</strong></td>
</tr>
@endforeach
@endif
</tbody>
@if (!empty($details))
<tfoot>
<tr>
<td colspan="8" class="lbl">GRAND TOTAL HOURS</td>
<td style="text-align:center;">{{ number_format($grandTotalTotal, 1) }}</td>
<td style="text-align:center;">{{ number_format($grandTotalEffective, 1) }}</td>
</tr>
</tfoot>
@endif
</table>
</div>
@extends('ui::layouts.app')
@section('content')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
<div class="ui segment">
<a class="ui teal left ribbon label">Review of Overtime Request Forms (HOD)</a>
<div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">List of Forms Awaiting HOD Review</div>
</h1>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Overtime Request Forms (HOD)'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'orm_apply_no', 'sortable' => true],
['header' => __('Project'), 'raw' => function ($row) {
return \DB::table('lkp_project')->where('id', $row->orm_project)->value('p_project_description') ?? '-';
}],
['header' => __('Date'), 'raw' => function ($row) {
return $row->orm_date ? \Carbon\Carbon::parse($row->orm_date)->format('d/m/Y') : '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->orm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
return "<a href='" . route('overtime::overtime.hodviewrequest', $row->id) . "'
class='ui blue button tiny'>
<i class='eye icon'></i> View
</a>";
}],
])
->render()
!!}
</div>
</div>
</div>
@endsection
@extends('ui::layouts.app')
@section('content')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
<div class="ui segment">
<a class="ui teal left ribbon label">Approval of Overtime Request Form (PD)</a>
<div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">List of Forms Awaiting Approval</div>
</h1>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Request Forms'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'orm_apply_no', 'sortable' => true],
['header' => __('Project'), 'raw' => function ($row) {
return \DB::table('lkp_project')->where('id', $row->orm_project)->value('p_project_description') ?? '-';
}],
['header' => __('Date'), 'raw' => function ($row) {
return $row->orm_date ? \Carbon\Carbon::parse($row->orm_date)->format('d/m/Y') : '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->orm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
return "<a href='" . route('overtime::overtime.pdviewrequest', $row->id) . "'
class='ui blue button tiny'>
<i class='eye icon'></i> View
</a>";
}],
])
->render()
!!}
</div>
</div>
</div>
@endsection
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<div class="ui small modal" id="modalRequestBaharu">
<div class="header">
<i class="file alternate outline icon"></i>
Create New Request Form
</div>
<div class="content">
<div id="rmodal-success-msg" class="ui positive message" style="display:none;">
<p id="rmodal-success-text"></p>
</div>
<div id="rmodal-error-msg" class="ui negative message" style="display:none;">
<p id="rmodal-error-text"></p>
</div>
<form class="ui form" id="form-request-baharu">
@csrf
<p style="color:#888; margin-bottom:1.2rem;">
<i class="info circle icon"></i>
Select project for the new request form.
</p>
<div class="required field" id="field-orm_project">
<label>Project</label>
<select name="orm_project" id="orm_project"
style="width:100%; padding:8px; border:1px solid rgba(34,36,38,.15); border-radius:4px;">
<option value="">-- Select Project --</option>
</select>
</div>
<div class="required field" id="field-orm_date">
<label>OT Request Month</label>
<div class="two fields" style="margin-bottom:0;">
<div class="field">
<select name="orm_month" id="orm_month" class="ui dropdown">
<option value="">Month</option>
@foreach(['01'=>'January','02'=>'February','03'=>'March','04'=>'April','05'=>'May','06'=>'June','07'=>'July','08'=>'August','09'=>'September','10'=>'October','11'=>'November','12'=>'December'] as $monthValue => $monthLabel)
<option value="{{ $monthValue }}">{{ $monthLabel }}</option>
@endforeach
</select>
</div>
<div class="field">
<select name="orm_year" id="orm_year" class="ui dropdown">
<option value="">Year</option>
@for($year = now()->year - 1; $year <= now()->year + 2; $year++)
<option value="{{ $year }}">{{ $year }}</option>
@endfor
</select>
</div>
</div>
</div>
</form>
</div>
<div class="actions">
<button type="button" class="ui teal button" id="btn-modal-request-submit">
Create Form
</button>
<button type="button" class="ui deny button">
<i class="times icon"></i> Cancel
</button>
</div>
</div>
<script>
$(document).ready(function () {
var EXISTING_PROJECTS_URL = "{{ route('overtime::overtime.existingprojects') }}";
var ALL_PROJECTS = @json($projects->map(fn($p) => ['id' => $p->id, 'name' => $p->p_project_description]));
function escapeHtml(value) {
return $('<div>').text(value || '').html();
}
function renderProjectOptions(occupied) {
occupied = occupied || [];
var current = $('#orm_project').val();
var html = '<option value="">-- Select Project --</option>';
ALL_PROJECTS.forEach(function (p) {
var isTaken = occupied.indexOf(String(p.id)) !== -1;
var label = p.name + (isTaken ? ' (Sudah ada borang untuk bulan ini)' : '');
var attrs = isTaken ? ' disabled style="color:#bbb;"' : '';
var selected = (!isTaken && current == p.id) ? ' selected' : '';
html += '<option value="' + escapeHtml(p.id) + '"' + attrs + selected + '>'
+ escapeHtml(label)
+ '</option>';
});
$('#orm_project').html(html);
}
function refreshProjectOptions() {
var month = $('#orm_month').val();
var year = $('#orm_year').val();
if (!month || !year) {
renderProjectOptions([]);
return;
}
var requestKeySuffix = year + month;
$.ajax({
url : EXISTING_PROJECTS_URL,
method : 'GET',
success: function (res) {
var occupiedKeys = res.success ? (res.existingRequests || []) : [];
var occupied = occupiedKeys
.filter(function (item) { return item.endsWith('|' + requestKeySuffix); })
.map(function (item) { return item.split('|')[0]; });
renderProjectOptions(occupied);
},
});
}
function resetRequestModal() {
$('#rmodal-success-msg, #rmodal-error-msg').hide();
$('#field-orm_project, #field-orm_date').removeClass('error');
$('#orm_month, #orm_year').val('');
if ($.fn.dropdown) $('#orm_month, #orm_year').dropdown('clear');
refreshProjectOptions();
}
renderProjectOptions(@json($existingRequests ?? []));
$('#modalRequestBaharu').modal({
blurring: true,
closable: true,
onShow: resetRequestModal,
});
$('#orm_month, #orm_year').on('change', refreshProjectOptions);
$('#btn-modal-request-submit').on('click', function () {
var btn = $(this);
var project = $('#orm_project').val();
var token = $('input[name="_token"]').first().val()
|| $('meta[name="csrf-token"]').attr('content');
$('#rmodal-success-msg, #rmodal-error-msg').hide();
$('#field-orm_project').removeClass('error');
var month = $('#orm_month').val();
var year = $('#orm_year').val();
if (!project) {
$('#field-orm_project').addClass('error');
$('#rmodal-error-text').text('Sila pilih projek.');
$('#rmodal-error-msg').show();
return;
}
if (!month || !year) {
$('#field-orm_date').addClass('error');
$('#rmodal-error-text').text('Sila pilih bulan permohonan OT.');
$('#rmodal-error-msg').show();
return;
}
btn.addClass('loading disabled');
$.ajax({
url : "{{ route('overtime::overtime.storeovertimerequest') }}",
method : 'POST',
dataType: 'json',
headers : { 'X-CSRF-TOKEN': token },
data : {
_token: token,
orm_project: project,
orm_date: year + '-' + month + '-01',
},
success : function (res) {
btn.removeClass('loading disabled');
if (res.success) {
$('#rmodal-success-text').text(res.message);
$('#rmodal-success-msg').show();
setTimeout(function () { window.location.href = res.redirect; }, 800);
} else {
$('#rmodal-error-text').text(res.message || 'Ralat tidak diketahui.');
$('#rmodal-error-msg').show();
}
},
error: function (xhr) {
btn.removeClass('loading disabled');
var msg = 'Ralat rangkaian. Sila cuba lagi.';
if (xhr.status === 422 && xhr.responseJSON && xhr.responseJSON.errors) {
msg = Object.values(xhr.responseJSON.errors).flat().join(' ');
} else if (xhr.responseJSON && xhr.responseJSON.message) {
msg = xhr.responseJSON.message;
}
$('#rmodal-error-text').text(msg);
$('#rmodal-error-msg').show();
},
});
});
});
</script>
@extends('ui::layouts.app')
@section('content')
@include('overtime::overtime.overtimerequest.pm.create')
@include('overtime::overtime.overtimerequest.pm.view_modal')
<style>
.table-uppercase td { text-transform: uppercase; }
</style>
<div class="ui segment">
<a class="ui teal left ribbon label">List of Overtime Request Forms</a>
<div class="ui segment">
<div class="ui stackable two column grid" style="margin-bottom:1rem;">
<div class="column">
<h1 class="ui header">
<div class="content">List of Overtime Request Forms</div>
</h1>
</div>
<div class="column" style="text-align:right; padding-top:1.2rem;">
<button class="ui teal button" id="btn-request-baharu">
<i class="plus icon"></i> New Request
</button>
</div>
</div>
<div class="ui divider"></div>
<div class="column sixteen wide table-uppercase">
{!!
Suitable::source($list)
->title(__('List of Overtime Request Forms'))
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => __('Application Number'), 'field' => 'orm_apply_no', 'sortable' => true],
['header' => __('Project'), 'raw' => function ($row) {
return \DB::table('lkp_project')->where('id', $row->orm_project)->value('p_project_description') ?? '-';
}],
['header' => __('OT Month'), 'raw' => function ($row) {
return $row->orm_date ? \Carbon\Carbon::parse($row->orm_date)->format('M Y') : '-';
}],
['header' => __('Status'), 'raw' => function ($row) use ($statuses) {
$label = $statuses[$row->orm_status]->description ?? '-';
return "<span class='ui label'>{$label}</span>";
}],
['header' => __('Action'), 'raw' => function ($row) {
$view = "<button
class='ui blue button tiny'
onclick='viewRequestForm({$row->id})'>
<i class='eye icon'></i> View
</button>";
$canEdit = in_array($row->orm_status, [0, 8, 10]);
$canBatal = in_array($row->orm_status, [0, 8, 10]);
$edit = $canEdit
? "<a href='" . route('overtime::overtime.editovertimerequest', $row->id) . "'
class='ui yellow button tiny'>
<i class='edit icon'></i> Update
</a>"
: "";
$batal = $canBatal
? "<button
class='ui red button tiny btn-batal-request'
data-id='{$row->id}'
data-url='" . route('overtime::overtime.batalovertimerequest', $row->id) . "'>
<i class='ban icon'></i> Cancel
</button>"
: "";
return "<div style='display:flex;justify-content:center;gap:.35rem;flex-wrap:wrap;'>{$view} {$edit} {$batal}</div>";
}],
])
->render()
!!}
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function () {
$('#btn-request-baharu').on('click', function () {
$('#modalRequestBaharu').modal('show');
});
$(document).on('click', '.btn-batal-request', function () {
if (!confirm('Cancel this application form? This action cannot be undone.')) return;
var url = $(this).data('url');
$.ajax({
url : url,
method : 'POST',
data : { _token: $('meta[name="csrf-token"]').attr('content') },
success: function (res) {
if (res.success) {
location.reload();
} else {
alert(res.message || 'Error while canceling the application form. Please try again.');
}
},
error: function () {
alert('Network error. Please try again.');
},
});
});
});
</script>
@endsection
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<style>
#modalViewRequestForm .scrolling.content { max-height: 80vh; overflow-y: auto; }
#modalViewRequestForm .vm-summary {
background: #ddeeff; border-radius: 6px;
padding: .8rem 1.1rem; margin-bottom: 1rem; line-height: 1.75;
}
#modalViewRequestForm .vm-summary .apply-no { font-size: 1.05rem; font-weight: 700; color: #1a56a0; }
#modalViewRequestForm .vm-summary .meta-line { font-size: .88rem; color: #333; }
#modalViewRequestForm .vm-tbl { width: 100%; border-collapse: collapse; font-size: .83rem; }
#modalViewRequestForm .vm-tbl th,
#modalViewRequestForm .vm-tbl td {
border: 1px solid #cfd8e3; padding: 6px 9px;
vertical-align: middle; text-align: center;
}
#modalViewRequestForm .vm-tbl thead th { background: #2185d0; color: #fff; font-weight: 600; font-size: .82rem; }
#modalViewRequestForm .vm-tbl tbody td.vm-left { text-align: left; }
#modalViewRequestForm .vm-tbl tfoot td {
background: #ddeeff; font-weight: 700; color: #1a56a0;
border-top: 2px solid #2185d0;
}
#modalViewRequestForm .vm-tbl tfoot .lbl { text-align: right; font-size: .8rem; letter-spacing: .04em; }
#modalViewRequestForm .vm-empty { text-align: center; color: #bbb; font-style: italic; padding: 1.6rem; }
#modalViewRequestForm .vm-loading { text-align: center; padding: 2.5rem; color: #888; }
</style>
<div class="ui fullscreen modal" id="modalViewRequestForm">
<div class="header">
<i class="eye icon"></i>
View Overtime Request Form
</div>
<div class="scrolling content" id="vrf-content">
<div class="vm-loading">
<i class="spinner loading icon"></i> Loading data…
</div>
</div>
<div class="actions">
<button class="ui grey button" onclick="$('#modalViewRequestForm').modal('hide');">
<i class="times icon"></i> Close
</button>
</div>
</div>
<script>
var VRF_MONTHS = ['Jan','Feb','Mac','Apr','Mei','Jun','Jul','Ogos','Sep','Okt','Nov','Dis'];
function vrfEsc(s) {
if (s === null || s === undefined) return '';
return String(s)
.replace(/&/g,'&amp;').replace(/</g,'&lt;')
.replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
function vrfFmtDate(str) {
if (!str) return '-';
var d = new Date(str);
if (isNaN(d.getTime())) return '-';
return d.toLocaleDateString('en-GB');
}
function vrfFmtMonth(str) {
if (!str) return '-';
var d = new Date(str);
return VRF_MONTHS[d.getMonth()] + ' ' + d.getFullYear();
}
function viewRequestForm(id) {
$('#vrf-content').html(
'<div class="vm-loading"><i class="spinner loading icon"></i> Loading data…</div>'
);
$('#modalViewRequestForm').modal({ blurring: true, closable: true }).modal('show');
$.ajax({
url : "{{ route('overtime::overtime.viewovertimerequest', ':id') }}".replace(':id', id),
method : 'GET',
success: function (res) {
if (res.success) {
$('#vrf-content').html(vrfBuildHtml(res.data.main, res.data.details));
} else {
$('#vrf-content').html(
'<div class="ui negative message"><p>'
+ vrfEsc(res.message || 'Error while loading data. Please try again.')
+ '</p></div>'
);
}
},
error: function () {
$('#vrf-content').html(
'<div class="ui negative message"><p>Network error. Please try again.</p></div>'
);
},
});
}
function vrfBuildHtml(main, details) {
var badge = '<span class="ui label" style="font-size:.78rem;">' + vrfEsc(main.orm_status_label || '-') + '</span>';
var html = '<div class="vm-summary">'
+ '<div class="apply-no">' + vrfEsc(main.orm_apply_no || '-') + '</div>'
+ '<div class="meta-line">Request by: <strong>' + vrfEsc(main.orm_requested_by_name || '-') + '</strong></div>'
+ '<div class="meta-line">Position: <strong>' + vrfEsc(main.orm_position_label || '-') + '</strong></div>'
+ '<div class="meta-line">Project: <strong>' + vrfEsc(main.orm_project_label || '-') + '</strong></div>'
+ '<div class="meta-line">Department: <strong>' + vrfEsc(main.orm_department_label || '-') + '</strong></div>'
+ '<div class="meta-line">Request Date: <strong>' + vrfFmtDate(main.orm_requested_date || main.orm_date) + '</strong></div>'
+ '<div class="meta-line">Approve by: <strong>' + vrfEsc(main.orm_approved_by_name || '-') + '</strong></div>'
+ '<div class="meta-line">Approved Date: <strong>' + vrfFmtDate(main.orm_approved_date) + '</strong></div>'
+ '<div class="meta-line">Status: ' + badge + '</div>'
+ '</div>';
html += '<div style="overflow-x:auto;">'
+ '<table class="vm-tbl"><thead><tr>'
+ '<th>No</th><th>Name</th><th>Month of Overtime</th><th>Budgeted</th>'
+ '<th>Utilised to Date</th><th>Planned OT Hour</th><th>Balance</th>'
+ '<th>Reason</th>'
+ '</tr></thead><tbody>';
if (!details || details.length === 0) {
html += '<tr><td colspan="8" class="vm-empty">No additional details.</td></tr></tbody></table></div>';
return html;
}
var grandTotal = 0;
details.forEach(function (d, i) {
var hours = parseFloat(d.ord_planned_ot_hour) || 0;
grandTotal += hours;
html += '<tr>'
+ '<td>' + (i + 1) + '</td>'
+ '<td class="vm-left">' + vrfEsc(d.ord_name || '-') + '</td>'
+ '<td>' + vrfFmtMonth(d.ord_month_of_overtime) + '</td>'
+ '<td>' + parseFloat(d.ord_budgeted || 0).toFixed(2) + '</td>'
+ '<td>' + parseFloat(d.ord_utilised_to_date || 0).toFixed(2) + '</td>'
+ '<td>' + parseFloat(d.ord_planned_ot_hour || 0).toFixed(2) + '</td>'
+ '<td>' + parseFloat(d.ord_balance || 0).toFixed(2) + '</td>'
+ '<td class="vm-left">' + vrfEsc(d.ord_reason || '-') + '</td>'
+ '</tr>';
});
html += '</tbody><tfoot><tr>'
+ '<td colspan="4"></td>'
+ '<td class="lbl" style="text-align:center;">TOTAL PLANNED OT HOURS</td>'
+ '<td>' + grandTotal.toFixed(2) + '</td>'
+ '<td colspan="2"></td>'
+ '</tr></tfoot></table></div>';
return html;
}
</script>
<?php
namespace Portal\Overtime\Data\Repo;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Model\OvertimeAuditQuery;
use Portal\Overtime\Model\OvertimeAuditTrail;
use Portal\Overtime\Model\OvertimeClaimDetail;
use Portal\Overtime\Model\OvertimeClaimMain;
class OvertimeClaimHodRepo
{
// =========================================================================
// STATUSES
// =========================================================================
public function getOtStatuses(): \Illuminate\Support\Collection
{
return DB::table('lkp_status')
->where('module', 'ot')
->where('status', 1)
->orderBy('ref_id')
->get()
->keyBy('ref_id');
}
private function currentHodDepartmentId(): ?int
{
return DB::table('staff_info')
->where('fk_users', Auth::id())
->value('fk_lkp_department');
}
// =========================================================================
// HOD REVIEW LIST — status 7 is set by HOD itself, so the inbox is
// claims sokong'd by PM (status 5) waiting for HOD action
// =========================================================================
public function getHodReviewList($request)
{
$search = $request->get('search');
return OvertimeClaimMain::where('ocm_status', 5)
->where(function ($q) use ($search) {
$q->where('ocm_apply_no', 'like', "%{$search}%")
->orWhere('ocm_staff_name', 'like', "%{$search}%");
})
->orderBy('created_at', 'desc')
->paginate(10);
}
// =========================================================================
// FIND CLAIM (read-only view)
// =========================================================================
public function findClaim(int $id): OvertimeClaimMain
{
return OvertimeClaimMain::findOrFail($id);
}
public function findClaimDetails(int $id)
{
return OvertimeClaimDetail::where('fk_overtime_claim_main', $id)
->orderBy('ocd_date', 'asc')
->get();
}
public function countPendingPmReviews(int $claimId): int
{
return OvertimeClaimDetail::where('fk_overtime_claim_main', $claimId)
->where('ocd_pm_reviewed', 0)
->count();
}
public function findLatestKueri(int $claimId): ?OvertimeAuditQuery
{
$claim = $this->findClaim($claimId);
return OvertimeAuditQuery::where('fk_main', $claim->id)
->where('no_permohonan', $claim->ocm_apply_no)
->orderBy('created_at', 'desc')
->first();
}
public function findQueryHistory(int $claimId)
{
$claim = $this->findClaim($claimId);
return OvertimeAuditQuery::where('fk_main', $claim->id)
->where('no_permohonan', $claim->ocm_apply_no)
->orderBy('created_at', 'desc')
->get();
}
// =========================================================================
// SOKONG — HOD approves, forwards to PD
// =========================================================================
public function sokongClaim($request, int $claimId): OvertimeClaimMain
{
$claim = $this->findClaim($claimId);
$pending = $this->countPendingPmReviews($claimId);
if ($pending > 0) {
throw new \Exception('Belum semua PM telah menyemak. Sokongan HOD tidak dibenarkan lagi.');
}
$claim->update([
'ocm_status' => 7, // Disokong Oleh HOD
'updated_by' => Auth::id(),
]);
$this->logAudit('UPDATE', $claim->id, null,
"menyokong permohonan {$claim->ocm_apply_no} dan menghantar ke PD.");
return $claim;
}
// =========================================================================
// KUERI — HOD sends back to pemohon (same pattern as PM kueri)
// =========================================================================
public function kueriClaim($request, int $claimId): OvertimeClaimMain
{
$claim = $this->findClaim($claimId);
$claim->update([
'ocm_status' => 8, // Dikueri Oleh HOD
'kueri_status' => 1,
'updated_by' => Auth::id(),
]);
OvertimeAuditQuery::create([
'fk_main' => $claim->id,
'no_permohonan' => $claim->ocm_apply_no,
'fk_user_kueri' => Auth::id(),
'remarks' => $request->remarks,
'respond' => null,
'tarikh' => now(),
]);
$this->logAudit('UPDATE', $claim->id, null,
"mengueri permohonan {$claim->ocm_apply_no} dan menghantar semula kepada pemohon.");
return $claim;
}
// =========================================================================
// AUDIT TRAIL HELPER
// =========================================================================
private function logAudit(string $taskCode, int $claimId, ?int $detailId, string $extra = ''): void
{
$taskId = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->where('is_active', 1)
->value('id');
$taskName = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->value('task_name') ?? $taskCode;
$userName = Auth::user()->name ?? 'Unknown';
$applyNo = OvertimeClaimMain::where('id', $claimId)->value('ocm_apply_no') ?? '-';
$description = "{$userName} melakukan tindakan {$taskName} pada permohonan {$applyNo}.";
if ($extra) {
$description .= ' ' . $extra;
}
OvertimeAuditTrail::create([
'fk_overtime_claim_main' => $claimId,
'fk_overtime_claim_detail' => $detailId,
'fk_lkp_overtime_task' => $taskId,
'user' => Auth::id(),
'description' => $description,
]);
}
}
<?php
namespace Portal\Overtime\Data\Repo;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Model\OvertimeAuditQuery;
use Portal\Overtime\Model\OvertimeAuditTrail;
use Portal\Overtime\Model\OvertimeClaimDetail;
use Portal\Overtime\Model\OvertimeClaimMain;
class OvertimeClaimPdRepo
{
// =========================================================================
// STATUSES
// =========================================================================
public function getOtStatuses(): \Illuminate\Support\Collection
{
return DB::table('lkp_status')
->where('module', 'ot')
->where('status', 1)
->orderBy('ref_id')
->get()
->keyBy('ref_id');
}
// =========================================================================
// PD REVIEW LIST — claims sokong'd by HOD (status 7) waiting for PD action
// =========================================================================
public function getPdReviewList($request)
{
$search = $request->get('search');
return OvertimeClaimMain::where('ocm_status', 7)
->where(function ($q) use ($search) {
$q->where('ocm_apply_no', 'like', "%{$search}%")
->orWhere('ocm_staff_name', 'like', "%{$search}%");
})
->orderBy('created_at', 'desc')
->paginate(10);
}
// =========================================================================
// FIND CLAIM (read-only view)
// =========================================================================
public function findClaim(int $id): OvertimeClaimMain
{
return OvertimeClaimMain::findOrFail($id);
}
public function findClaimDetails(int $id)
{
return OvertimeClaimDetail::where('fk_overtime_claim_main', $id)
->orderBy('ocd_date', 'asc')
->get();
}
public function findLatestKueri(int $claimId): ?OvertimeAuditQuery
{
$claim = $this->findClaim($claimId);
return OvertimeAuditQuery::where('fk_main', $claim->id)
->where('no_permohonan', $claim->ocm_apply_no)
->orderBy('created_at', 'desc')
->first();
}
public function findQueryHistory(int $claimId)
{
$claim = $this->findClaim($claimId);
return OvertimeAuditQuery::where('fk_main', $claim->id)
->where('no_permohonan', $claim->ocm_apply_no)
->orderBy('created_at', 'desc')
->get();
}
// =========================================================================
// SOKONG — PD gives final approval
// =========================================================================
public function sokongClaim($request, int $claimId): OvertimeClaimMain
{
$claim = $this->findClaim($claimId);
$claim->update([
'ocm_status' => 11, // Permohonan Diluluskan (final)
'ocm_approved_by' => Auth::id(),
'ocm_approved_date' => now(),
'updated_by' => Auth::id(),
]);
$this->logAudit('UPDATE', $claim->id, null,
"meluluskan permohonan {$claim->ocm_apply_no}.");
return $claim;
}
// =========================================================================
// KUERI — PD sends back to pemohon (same pattern as PM/HOD kueri)
// =========================================================================
public function kueriClaim($request, int $claimId): OvertimeClaimMain
{
$claim = $this->findClaim($claimId);
$claim->update([
'ocm_status' => 10, // Dikueri Oleh BOD/PD
'kueri_status' => 1,
'updated_by' => Auth::id(),
]);
OvertimeAuditQuery::create([
'fk_main' => $claim->id,
'no_permohonan' => $claim->ocm_apply_no,
'fk_user_kueri' => Auth::id(),
'remarks' => $request->remarks,
'respond' => null,
'tarikh' => now(),
]);
$this->logAudit('UPDATE', $claim->id, null,
"mengueri permohonan {$claim->ocm_apply_no} dan menghantar semula kepada pemohon.");
return $claim;
}
// =========================================================================
// AUDIT TRAIL HELPER
// =========================================================================
private function logAudit(string $taskCode, int $claimId, ?int $detailId, string $extra = ''): void
{
$taskId = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->where('is_active', 1)
->value('id');
$taskName = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->value('task_name') ?? $taskCode;
$userName = Auth::user()->name ?? 'Unknown';
$applyNo = OvertimeClaimMain::where('id', $claimId)->value('ocm_apply_no') ?? '-';
$description = "{$userName} melakukan tindakan {$taskName} pada permohonan {$applyNo}.";
if ($extra) {
$description .= ' ' . $extra;
}
OvertimeAuditTrail::create([
'fk_overtime_claim_main' => $claimId,
'fk_overtime_claim_detail' => $detailId,
'fk_lkp_overtime_task' => $taskId,
'user' => Auth::id(),
'description' => $description,
]);
}
}
...@@ -32,6 +32,29 @@ public function getOtStatuses(): \Illuminate\Support\Collection ...@@ -32,6 +32,29 @@ public function getOtStatuses(): \Illuminate\Support\Collection
->keyBy('ref_id'); ->keyBy('ref_id');
} }
public function getAttendanceByDate(string $date): ?array
{
$staffInfoId = $this->currentStaffInfoId();
if (!$staffInfoId) {
return null;
}
$attendance = DB::table('attendance')
->where('fk_staff_info', $staffInfoId)
->whereDate('date', $date)
->first();
if (!$attendance) {
return null;
}
return [
'time_in' => $attendance->time_in,
'time_out' => $attendance->time_out,
];
}
// LIST // LIST
...@@ -112,12 +135,12 @@ public function getExistingMonthsForUser(): array ...@@ -112,12 +135,12 @@ public function getExistingMonthsForUser(): array
return OvertimeClaimMain::where('fk_lkp_staff_info', $staffInfoId) return OvertimeClaimMain::where('fk_lkp_staff_info', $staffInfoId)
->whereNotNull('ocm_month') ->whereNotNull('ocm_month')
->whereNotNull('ocm_year') ->whereNotNull('ocm_year')
->whereNotIn('ocm_status', [4])
->get() ->get()
->map(fn ($item) => $item->ocm_year . str_pad($item->ocm_month, 2, '0', STR_PAD_LEFT)) ->map(fn ($item) => $item->ocm_year . str_pad($item->ocm_month, 2, '0', STR_PAD_LEFT))
->toArray(); ->toArray();
} }
// ADD DETAIL // ADD DETAIL
...@@ -133,6 +156,7 @@ public function addOvertimeClaimDetail(int $id, $request): OvertimeClaimDetail ...@@ -133,6 +156,7 @@ public function addOvertimeClaimDetail(int $id, $request): OvertimeClaimDetail
'ocd_office_hour' => $officeHour, 'ocd_office_hour' => $officeHour,
'ocd_overtime_from' => $request->ocd_overtime_from, 'ocd_overtime_from' => $request->ocd_overtime_from,
'ocd_overtime_to' => $request->ocd_overtime_to, 'ocd_overtime_to' => $request->ocd_overtime_to,
'ocd_total_hours' => $request->ocd_total_hours,
'ocd_effective_hours' => $request->ocd_effective_hours, 'ocd_effective_hours' => $request->ocd_effective_hours,
'ocd_tasks' => $request->ocd_tasks, 'ocd_tasks' => $request->ocd_tasks,
'fk_lkp_project' => $request->fk_lkp_project ?: null, 'fk_lkp_project' => $request->fk_lkp_project ?: null,
...@@ -206,25 +230,40 @@ public function updateOvertimeClaim($request, int $id): OvertimeClaimMain ...@@ -206,25 +230,40 @@ public function updateOvertimeClaim($request, int $id): OvertimeClaimMain
// SUBMIT // SUBMIT
// =========================================================================
// SUBMIT (status-aware — first submission goes to 2, resubmission after kueri goes to 3)
// =========================================================================
public function submitOvertimeClaim($request, int $id): OvertimeClaimMain public function submitOvertimeClaim($request, int $id): OvertimeClaimMain
{ {
$record = $this->findOvertimeClaim($id); $record = $this->findOvertimeClaim($id);
$detailCount = OvertimeClaimDetail::where('fk_overtime_claim_main', $id)->count(); $detailCount = OvertimeClaimDetail::where('fk_overtime_claim_main', $id)->count();
if ($detailCount === 0) { if ($detailCount === 0) {
throw new \Exception('Sila tambah sekurang-kurangnya satu hari tuntutan lebih masa.'); throw new \Exception('Sila tambah sekurang-kurangnya satu hari tuntutan lebih masa.');
} }
$record->update([ $isResubmission = $record->ocm_status == 6 && $record->ocm_query_status == 1;
'ocm_status' => 2, // Permohonan Baharu $newStatus = $isResubmission ? 3 : 2;
'ocm_submit_date' => now(),
'updated_by' => Auth::id(), OvertimeClaimDetail::where('fk_overtime_claim_main', $id)
->update([
'ocd_pm_reviewed' => 0,
'ocd_pm_reviewed_by' => null,
'ocd_pm_reviewed_at' => null,
]); ]);
$this->getAuditTrail('UPDATE', $id, null, 'Tuntutan dihantar untuk kelulusan.'); $record->update([
'ocm_status' => $newStatus,
'ocm_submit_date' => now(),
'updated_by' => Auth::id(),
]);
return $record; $this->getAuditTrail('SUBMIT', $id, null,
} $isResubmission ? 'Tuntutan dihantar semula selepas kueri.' : 'Tuntutan dihantar untuk kelulusan.');
return $record;
}
// DELETE // DELETE
...@@ -286,4 +325,47 @@ public function getAuditTrailList($request) ...@@ -286,4 +325,47 @@ public function getAuditTrailList($request)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->paginate(15); ->paginate(15);
} }
}
\ No newline at end of file // =========================================================================
// BATAL (cancel — allowed only from Draf=1 or Dikueri oleh PM=6)
// =========================================================================
public function batalOvertimeClaim(int $id): OvertimeClaimMain
{
$record = $this->findOvertimeClaim($id);
if (!in_array($record->ocm_status, [1, 6])) {
throw new \Exception('Permohonan pada status semasa tidak boleh dibatalkan.');
}
$record->update([
'ocm_status' => 4, // Batal Permohonan
'updated_by' => Auth::id(),
]);
$this->getAuditTrail('UPDATE', $id, null, 'Permohonan dibatalkan oleh pemohon.');
return $record;
}
// =========================================================================
// SAVE KUERI RESPOND (pemohon responding to PM's kueri remark)
// =========================================================================
public function saveKueriRespond(int $claimId, string $respond): void
{
$record = $this->findOvertimeClaim($claimId);
$query = \Portal\Overtime\Model\OvertimeAuditQuery::where('fk_main', $record->id)
->where('no_permohonan', $record->ocm_apply_no)
->orderBy('created_at', 'desc')
->first();
if ($query) {
$query->update(['respond' => $respond]);
}
// Audit trail: claimant respond to kueri
$this->getAuditTrail('RESPOND', $record->id, null, 'Pemohon menjawab kueri: ' . substr($respond, 0, 100));
}
}
<?php
namespace Portal\Overtime\Data\Repo;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Portal\Overtime\Model\OvertimeAuditQuery;
use Portal\Overtime\Model\OvertimeAuditTrail;
use Portal\Overtime\Model\OvertimeRequestMain;
use Portal\Overtime\Model\OvertimeRequestDetail;
class OvertimeHodRepo
{
private function currentStaffId(): ?string
{
return DB::table('staff_info')
->where('fk_users', Auth::id())
->value('staff_id');
}
private function currentHodDepartmentId(): ?int
{
$staffId = $this->currentStaffId();
if (!$staffId) {
return null;
}
return DB::table('staff_info')
->where('staff_id', $staffId)
->value('fk_lkp_department');
}
private function projectTeamProjectColumn(): string
{
if (Schema::hasColumn('project_team', 'pt_project_id')) {
return 'pt_project_id';
}
return 'fk_project_id';
}
private function currentHodProjectIds(): \Illuminate\Support\Collection
{
$departmentId = $this->currentHodDepartmentId();
if (!$departmentId) {
return collect();
}
$projectColumn = $this->projectTeamProjectColumn();
return DB::table('project_team as pt')
->join('staff_info as si', 'si.staff_id', '=', 'pt.pt_staff_id')
->where('si.fk_lkp_department', $departmentId)
->whereNotNull("pt.{$projectColumn}")
->select("pt.{$projectColumn} as project_id")
->distinct()
->pluck('project_id')
->filter()
->unique()
->values();
}
public function getOtStatuses(): \Illuminate\Support\Collection
{
return DB::table('lkp_status')
->where('module', 'ot')
->where('status', 1)
->orderBy('ref_id')
->get()
->keyBy('ref_id');
}
// =========================================================================
// LIST (all status=2 — no role scoping for now)
// =========================================================================
public function getReviewList($request)
{
$search = $request->get('search', '');
$projectIds = $this->currentHodProjectIds();
$query = OvertimeRequestMain::where('orm_status', 2)
->whereNull('deleted_at')
->when($search, fn ($q) => $q->where('orm_apply_no', 'like', "%{$search}%"));
if ($projectIds->isEmpty()) {
return $query->whereRaw('0 = 1')->orderBy('created_at', 'desc')->paginate(10);
}
return $query->whereIn('orm_project', $projectIds)
->orderBy('created_at', 'desc')
->paginate(10);
}
// =========================================================================
// FIND
// =========================================================================
public function findRequestForm(int $id): OvertimeRequestMain
{
return OvertimeRequestMain::findOrFail($id);
}
public function findRequestFormDetails(int $id)
{
return OvertimeRequestDetail::where('fk_overtime_request_main', $id)
->orderBy('id', 'asc')
->get();
}
public function findQueryHistory(int $id)
{
$record = $this->findRequestForm($id);
return OvertimeAuditQuery::where('fk_main', $record->id)
->where('no_permohonan', $record->orm_apply_no)
->orderBy('created_at', 'desc')
->get();
}
// =========================================================================
// SOKONG → status 7 (Disokong Oleh HOD, forwarded to PD)
// =========================================================================
public function approveRequestForm(int $id): OvertimeRequestMain
{
$record = OvertimeRequestMain::findOrFail($id);
if ($record->orm_status !== 2) {
throw new \Exception('Borang ini tidak lagi menunggu semakan HOD.');
}
$record->update([
'orm_status' => 7, // Disokong Oleh HOD
'updated_by' => Auth::id(),
]);
// Audit trail: HOD approval
$this->logAuditTrail('APPROVE', $record->id, null, 'Borang permohonan disokong oleh HOD.');
return $record;
}
// =========================================================================
// KUERI → status 8 (Dikueri Oleh HOD, sent back to PM)
// =========================================================================
public function kueriRequestForm(int $id, string $remark): OvertimeRequestMain
{
$record = OvertimeRequestMain::findOrFail($id);
if ($record->orm_status !== 2) {
throw new \Exception('Borang ini tidak lagi menunggu semakan HOD.');
}
$record->update([
'orm_status' => 8, // Dikueri Oleh HOD
'orm_query_remark' => $remark,
'orm_query_by' => Auth::id(),
'orm_query_respond'=> null,
'updated_by' => Auth::id(),
]);
OvertimeAuditQuery::create([
'fk_main' => $record->id,
'no_permohonan' => $record->orm_apply_no,
'fk_user_kueri' => Auth::id(),
'remarks' => $remark,
'respond' => null,
'tarikh' => now(),
]);
// Audit trail: HOD kueri
$this->logAuditTrail('KUERI', $record->id, null, 'Request form queried by HOD.');
return $record;
}
// =========================================================================
// REJECT → status 12 (Permohonan Ditolak)
// =========================================================================
public function rejectRequestForm(int $id): OvertimeRequestMain
{
$record = OvertimeRequestMain::findOrFail($id);
$record->update([
'orm_status' => 12,
'updated_by' => Auth::id(),
]);
// Audit trail: HOD reject
$this->logAuditTrail('REJECT', $record->id, null, 'Request form rejected by HOD.');
return $record;
}
// AUDIT TRAIL HELPER (for request actions)
private function logAuditTrail(string $taskCode, int $requestId, ?int $detailId = null, string $extra = ''): void
{
$taskId = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->where('is_active', 1)
->value('id');
$taskName = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->value('task_name') ?? $taskCode;
$userName = Auth::user()->name ?? 'Unknown';
$applyNo = OvertimeRequestMain::where('id', $requestId)->value('orm_apply_no') ?? '-';
$description = "{$userName} performed the action {$taskName} on application {$applyNo}.";
if ($extra) {
$description .= ' ' . $extra;
}
OvertimeAuditTrail::create([
'fk_overtime_claim_main' => null,
'fk_overtime_claim_detail' => null,
'fk_lkp_overtime_task' => $taskId,
'user' => Auth::id(),
'description' => $description,
]);
}
}
<?php
namespace Portal\Overtime\Data\Repo;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Model\OvertimeAuditQuery;
use Portal\Overtime\Model\OvertimeAuditTrail;
use Portal\Overtime\Model\OvertimeRequestMain;
use Portal\Overtime\Model\OvertimeRequestDetail;
class OvertimePdRepo
{
public function getOtStatuses(): \Illuminate\Support\Collection
{
return DB::table('lkp_status')
->where('module', 'ot')
->where('status', 1)
->orderBy('ref_id')
->get()
->keyBy('ref_id');
}
// =========================================================================
// LIST (status 7 = pending, status 11 = approved — both stay in PD list)
// =========================================================================
public function getReviewList($request)
{
$search = $request->get('search', '');
return OvertimeRequestMain::whereIn('orm_status', [7, 11])
->whereNull('deleted_at')
->when($search, fn ($q) => $q->where('orm_apply_no', 'like', "%{$search}%"))
->orderBy('created_at', 'desc')
->paginate(10);
}
// =========================================================================
// FIND
// =========================================================================
public function findRequestForm(int $id): OvertimeRequestMain
{
return OvertimeRequestMain::findOrFail($id);
}
public function findRequestFormDetails(int $id)
{
return OvertimeRequestDetail::where('fk_overtime_request_main', $id)
->orderBy('id', 'asc')
->get();
}
public function findQueryHistory(int $id)
{
$record = $this->findRequestForm($id);
return OvertimeAuditQuery::where('fk_main', $record->id)
->where('no_permohonan', $record->orm_apply_no)
->orderBy('created_at', 'desc')
->get();
}
// =========================================================================
// APPROVE → status 11 (Permohonan Diluluskan — stays in PD list, visible in Sokong picker)
// =========================================================================
public function approveRequestForm(int $id): OvertimeRequestMain
{
$record = $this->findRequestForm($id);
if ($record->orm_status !== 7) {
throw new \Exception('Borang ini tidak lagi menunggu kelulusan PD.');
}
$record->update([
'orm_status' => 9, // Diluluskan Oleh Project Director
'orm_approved_by_id' => Auth::id(),
'orm_approved_date' => now(),
'updated_by' => Auth::id(),
]);
// Audit trail: PD approval
$this->logAuditTrail('APPROVE', $record->id, null, 'Borang permohonan diluluskan oleh PD.');
return $record;
}
// =========================================================================
// KUERI → status 10 (Dikueri Oleh BOD, sent back to PM)
// =========================================================================
public function kueriRequestForm(int $id, string $remark): OvertimeRequestMain
{
$record = $this->findRequestForm($id);
if (! in_array($record->orm_status, [7, 11])) {
throw new \Exception('Borang ini tidak boleh dikueri pada status semasa.');
}
$record->update([
'orm_status' => 10, // Dikueri Oleh BOD
'orm_query_remark' => $remark,
'orm_query_by' => Auth::id(),
'orm_query_respond'=> null,
'updated_by' => Auth::id(),
]);
OvertimeAuditQuery::create([
'fk_main' => $record->id,
'no_permohonan' => $record->orm_apply_no,
'fk_user_kueri' => Auth::id(),
'remarks' => $remark,
'respond' => null,
'tarikh' => now(),
]);
// Audit trail: PD kueri
$this->logAuditTrail('KUERI', $record->id, null, 'Request form queried by PD.');
return $record;
}
// =========================================================================
// REJECT → status 12 (Permohonan Ditolak)
// =========================================================================
public function rejectRequestForm(int $id): OvertimeRequestMain
{
$record = $this->findRequestForm($id);
if (! in_array($record->orm_status, [7, 11])) {
throw new \Exception('Borang ini tidak boleh ditolak pada status semasa.');
}
$record->update([
'orm_status' => 12, // Permohonan Ditolak
'updated_by' => Auth::id(),
]);
// Audit trail: PD reject
$this->logAuditTrail('REJECT', $record->id, null, 'Request form rejected by PD.');
return $record;
}
// AUDIT TRAIL HELPER (for PD actions)
private function logAuditTrail(string $taskCode, int $requestId, ?int $detailId = null, string $extra = ''): void
{
$taskId = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->where('is_active', 1)
->value('id');
$taskName = DB::table('lkp_overtime_task')
->where('task_code', $taskCode)
->value('task_name') ?? $taskCode;
$userName = Auth::user()->name ?? 'Unknown';
$applyNo = OvertimeRequestMain::where('id', $requestId)->value('orm_apply_no') ?? '-';
$description = "{$userName} performed the action {$taskName} on application {$applyNo}.";
if ($extra) {
$description .= ' ' . $extra;
}
OvertimeAuditTrail::create([
'fk_overtime_claim_main' => null,
'fk_overtime_claim_detail' => null,
'fk_lkp_overtime_task' => $taskId,
'user' => Auth::id(),
'description' => $description,
]);
}
}
<?php
namespace Portal\Overtime\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Data\Repo\OvertimeClaimHodRepo;
class OvertimeClaimHodController extends Controller
{
public function __construct(
protected OvertimeClaimHodRepo $repos
) {}
// =========================================================================
// HOD REVIEW LIST (status 5, sokong'd by PM)
// =========================================================================
public function getHodReviewList(Request $request)
{
$list = $this->repos->getHodReviewList($request);
$statuses = $this->repos->getOtStatuses();
return view('overtime::overtime.overtimeclaim.hod.list', compact('list', 'statuses'));
}
// =========================================================================
// HOD VIEW — read-only claim render + Sokong/Kueri actions
// =========================================================================
public function viewClaim(Request $request, int $id)
{
$data = $this->repos->findClaim($id);
$details = $this->repos->findClaimDetails($id);
$statuses = $this->repos->getOtStatuses();
$latestKueri = $this->repos->findLatestKueri($id);
$queryHistory = $this->repos->findQueryHistory($id);
$pendingPmReviews = $this->repos->countPendingPmReviews($id);
return view('overtime::overtime.overtimeclaim.hod.view', compact(
'data', 'details', 'statuses', 'latestKueri', 'queryHistory', 'pendingPmReviews'
));
}
// =========================================================================
// SOKONG — forwards to PD (status 7)
// =========================================================================
public function sokongClaim(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($request, $id) {
$claim = $this->repos->sokongClaim($request, $id);
return response()->json([
'success' => true,
'message' => "Permohonan {$claim->ocm_apply_no} disokong dan dihantar ke PD.",
'redirect' => route('overtime::overtime.hodreviewlist'),
]);
});
}
// =========================================================================
// KUERI — sends back to pemohon (status 8)
// =========================================================================
public function kueriClaim(Request $request, int $id): JsonResponse
{
$request->validate(
['remarks' => 'required|string|max:2000'],
['remarks.required' => 'Sila isi remarks untuk kueri.']
);
return $this->withTransaction(function () use ($request, $id) {
$claim = $this->repos->kueriClaim($request, $id);
return response()->json([
'success' => true,
'message' => "Permohonan {$claim->ocm_apply_no} dikueri dan dihantar semula kepada pemohon.",
'redirect' => route('overtime::overtime.hodreviewlist'),
]);
});
}
// =========================================================================
// PRIVATE HELPERS
// =========================================================================
private function withTransaction(callable $callback): JsonResponse
{
try {
DB::beginTransaction();
$response = $callback();
DB::commit();
return $response;
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => $e->getMessage() ?: 'An error occurred.',
], 500);
}
}
}
<?php
namespace Portal\Overtime\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Data\Repo\OvertimeClaimPdRepo;
class OvertimeClaimPdController extends Controller
{
public function __construct(
protected OvertimeClaimPdRepo $repos
) {}
// =========================================================================
// PD REVIEW LIST (status 7, sokong'd by HOD)
// =========================================================================
public function getPdReviewList(Request $request)
{
$list = $this->repos->getPdReviewList($request);
$statuses = $this->repos->getOtStatuses();
return view('overtime::overtime.overtimeclaim.pd.list', compact('list', 'statuses'));
}
// =========================================================================
// PD VIEW — read-only claim render + Sokong/Kueri actions
// =========================================================================
public function viewClaim(Request $request, int $id)
{
$data = $this->repos->findClaim($id);
$details = $this->repos->findClaimDetails($id);
$statuses = $this->repos->getOtStatuses();
$latestKueri = $this->repos->findLatestKueri($id);
$queryHistory = $this->repos->findQueryHistory($id);
return view('overtime::overtime.overtimeclaim.pd.view', compact(
'data', 'details', 'statuses', 'latestKueri', 'queryHistory'
));
}
// =========================================================================
// SOKONG — final approval (status 11)
// =========================================================================
public function sokongClaim(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($request, $id) {
$claim = $this->repos->sokongClaim($request, $id);
return response()->json([
'success' => true,
'message' => "Permohonan {$claim->ocm_apply_no} telah diluluskan.",
'redirect' => route('overtime::overtime.pdreviewlist'),
]);
});
}
// =========================================================================
// KUERI — sends back to pemohon (status 10)
// =========================================================================
public function kueriClaim(Request $request, int $id): JsonResponse
{
$request->validate(
['remarks' => 'required|string|max:2000'],
['remarks.required' => 'Sila isi remarks untuk kueri.']
);
return $this->withTransaction(function () use ($request, $id) {
$claim = $this->repos->kueriClaim($request, $id);
return response()->json([
'success' => true,
'message' => "Permohonan {$claim->ocm_apply_no} dikueri dan dihantar semula kepada pemohon.",
'redirect' => route('overtime::overtime.pdreviewlist'),
]);
});
}
// =========================================================================
// PRIVATE HELPERS
// =========================================================================
private function withTransaction(callable $callback): JsonResponse
{
try {
DB::beginTransaction();
$response = $callback();
DB::commit();
return $response;
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => $e->getMessage() ?: 'An error occurred.',
], 500);
}
}
}
<?php
namespace Portal\Overtime\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Data\Repo\OvertimeHodRepo;
class OvertimeHodController extends Controller
{
public function __construct(
protected OvertimeHodRepo $repos
) {}
public function getReviewList(Request $request)
{
$list = $this->repos->getReviewList($request);
$statuses = $this->repos->getOtStatuses();
return view('overtime::overtime.overtimerequest.hod.list', compact('list', 'statuses'));
}
public function viewRequestForm(Request $request, int $id)
{
$main = $this->repos->findRequestForm($id);
$details = $this->repos->findRequestFormDetails($id);
$project = DB::table('lkp_project')->where('id', $main->orm_project)->first();
$statuses = $this->repos->getOtStatuses();
$queryHistory = $this->repos->findQueryHistory($id);
$requestedByName = null;
if ($main->orm_requested_by_id) {
$requestedByName = DB::table('project_team')->where('id', $main->orm_requested_by_id)->value('pt_team');
}
if (!$requestedByName && $main->orm_name && is_numeric((string) $main->orm_name)) {
$requestedByName = DB::table('staff_info')->where('fk_users', (int) $main->orm_name)->value('fullname')
?: DB::table('users')->where('id', (int) $main->orm_name)->value('name')
?: (string) $main->orm_name;
} elseif (!$requestedByName && $main->orm_name) {
$requestedByName = (string) $main->orm_name;
}
$main->orm_requested_by_name = $requestedByName ?: '-';
$staffInfoForMain = $main->orm_name && is_numeric((string) $main->orm_name)
? DB::table('staff_info')->where('fk_users', (int) $main->orm_name)->first()
: null;
$main->orm_position_label = $main->orm_position
? (DB::table('project_role')->where('id', $main->orm_position)->value('role') ?: (string) $main->orm_position)
: '-';
$main->orm_department_label = $staffInfoForMain && $staffInfoForMain->fk_lkp_department
? (DB::table('lkp_department')->where('id', $staffInfoForMain->fk_lkp_department)->value('description') ?: DB::table('lkp_department')->where('id', $staffInfoForMain->fk_lkp_department)->value('name') ?: '-')
: (DB::table('lkp_department')->where('id', $main->orm_department)->value('description') ?: DB::table('lkp_department')->where('id', $main->orm_department)->value('name') ?: '-');
$main->orm_approved_by_name = $main->orm_approved_by_id
? (DB::table('staff_info')->where('fk_users', $main->orm_approved_by_id)->value('fullname')
?: DB::table('users')->where('id', $main->orm_approved_by_id)->value('name')
?: '-')
: '-';
return view('overtime::overtime.overtimerequest.hod.view', compact('main', 'details', 'project', 'statuses', 'queryHistory'));
}
public function approveRequestForm(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($id) {
$this->repos->approveRequestForm($id);
return response()->json([
'success' => true,
'message' => 'Borang permohonan disokong dan dihantar ke Project Director.',
'redirect' => route('overtime::overtime.hodreviewlist'),
]);
});
}
public function rejectRequestForm(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($id) {
$this->repos->rejectRequestForm($id);
return response()->json([
'success' => true,
'message' => 'Borang permohonan ditolak.',
'redirect' => route('overtime::overtime.hodreviewlist'),
]);
});
}
private function withTransaction(callable $callback): JsonResponse
{
try {
DB::beginTransaction();
$response = $callback();
DB::commit();
return $response;
} catch (\Exception $e) {
DB::rollBack();
return response()->json(['success' => false, 'message' => $e->getMessage() ?: 'An error occurred.'], 500);
}
}
public function kueriRequestForm(Request $request, int $id): JsonResponse
{
$request->validate([
'remark' => 'required|string|max:2000',
], [
'remark.required' => 'Sila isi catatan kueri.',
]);
return $this->withTransaction(function () use ($request, $id) {
$this->repos->kueriRequestForm($id, $request->remark);
return response()->json([
'success' => true,
'message' => 'Borang permohonan dikueri dan dihantar balik kepada PM.',
'redirect' => route('overtime::overtime.hodreviewlist'),
]);
});
}
}
<?php
namespace Portal\Overtime\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Data\Repo\OvertimePdRepo;
class OvertimePdController extends Controller
{
public function __construct(
protected OvertimePdRepo $repos
) {}
public function getReviewList(Request $request)
{
$list = $this->repos->getReviewList($request);
$statuses = $this->repos->getOtStatuses();
return view('overtime::overtime.overtimerequest.pd.list', compact('list', 'statuses'));
}
public function getClaimReviewList(Request $request)
{
$list = $this->repos->getReviewList($request);
$statuses = $this->repos->getOtStatuses();
return view('overtime::overtime.overtimerequest.pd.list', compact('list', 'statuses'));
}
public function viewRequestForm(Request $request, int $id)
{
$main = $this->repos->findRequestForm($id);
$details = $this->repos->findRequestFormDetails($id);
$project = DB::table('lkp_project')->where('id', $main->orm_project)->first();
$statuses = $this->repos->getOtStatuses();
$queryHistory = $this->repos->findQueryHistory($id);
$requestedByName = null;
if ($main->orm_requested_by_id) {
$requestedByName = DB::table('project_team')->where('id', $main->orm_requested_by_id)->value('pt_team');
}
if (!$requestedByName && $main->orm_name && is_numeric((string) $main->orm_name)) {
$requestedByName = DB::table('staff_info')->where('fk_users', (int) $main->orm_name)->value('fullname')
?: DB::table('users')->where('id', (int) $main->orm_name)->value('name')
?: (string) $main->orm_name;
} elseif (!$requestedByName && $main->orm_name) {
$requestedByName = (string) $main->orm_name;
}
$main->orm_requested_by_name = $requestedByName ?: '-';
$staffInfoForMain = $main->orm_name && is_numeric((string) $main->orm_name)
? DB::table('staff_info')->where('fk_users', (int) $main->orm_name)->first()
: null;
$main->orm_position_label = $main->orm_position
? (DB::table('project_role')->where('id', $main->orm_position)->value('role') ?: (string) $main->orm_position)
: '-';
$main->orm_department_label = $staffInfoForMain && $staffInfoForMain->fk_lkp_department
? (DB::table('lkp_department')->where('id', $staffInfoForMain->fk_lkp_department)->value('description') ?: DB::table('lkp_department')->where('id', $staffInfoForMain->fk_lkp_department)->value('name') ?: '-')
: (DB::table('lkp_department')->where('id', $main->orm_department)->value('description') ?: DB::table('lkp_department')->where('id', $main->orm_department)->value('name') ?: '-');
$main->orm_approved_by_name = $main->orm_approved_by_id
? (DB::table('staff_info')->where('fk_users', $main->orm_approved_by_id)->value('fullname')
?: DB::table('users')->where('id', $main->orm_approved_by_id)->value('name')
?: '-')
: '-';
return view('overtime::overtime.overtimerequest.pd.view', compact('main', 'details', 'project', 'statuses', 'queryHistory'));
}
public function approveRequestForm(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($id) {
$this->repos->approveRequestForm($id);
return response()->json([
'success' => true,
'message' => 'Borang permohonan diluluskan.',
'redirect' => route('overtime::overtime.pdreviewlist'),
]);
});
}
public function rejectRequestForm(Request $request, int $id): JsonResponse
{
return $this->withTransaction(function () use ($id) {
$this->repos->rejectRequestForm($id);
return response()->json([
'success' => true,
'message' => 'Borang permohonan ditolak.',
'redirect' => route('overtime::overtime.pdreviewlist'),
]);
});
}
private function withTransaction(callable $callback): JsonResponse
{
try {
DB::beginTransaction();
$response = $callback();
DB::commit();
return $response;
} catch (\Exception $e) {
DB::rollBack();
return response()->json(['success' => false, 'message' => $e->getMessage() ?: 'An error occurred.'], 500);
}
}
public function kueriRequestForm(Request $request, int $id): JsonResponse
{
$request->validate([
'remark' => 'required|string|max:2000',
], [
'remark.required' => 'Sila isi catatan kueri.',
]);
return $this->withTransaction(function () use ($request, $id) {
$this->repos->kueriRequestForm($id, $request->remark);
return response()->json([
'success' => true,
'message' => 'Borang permohonan dikueri dan dihantar balik kepada PM.',
'redirect' => route('overtime::overtime.pdreviewlist'),
]);
});
}
}
<?php
namespace Portal\Overtime\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Portal\Overtime\Data\Repo\OvertimeProjectManagerRepo;
class OvertimeProjectManagerController extends Controller
{
public function __construct(
protected OvertimeProjectManagerRepo $repos
) {}
// =========================================================================
// LIST (status 2 + 3)
// =========================================================================
public function getProjectManagerReviewList(Request $request)
{
$list = $this->repos->getProjectManagerReviewList($request);
$statuses = $this->repos->getOtStatuses();
$pmProjectIds = $this->repos->getPmProjectIds();
return view('overtime::overtime.overtimeclaim.projectmanager.list', compact('list', 'statuses', 'pmProjectIds'));
}
// =========================================================================
// VIEW (full read-only claim + sokong/kueri actions)
// =========================================================================
public function viewClaim(Request $request, int $id)
{
$data = $this->repos->findClaimWithDetails($id);
$statuses = $this->repos->getOtStatuses();
$selectionData = $this->repos->getRequestFormSelectionData($data['main']);
return view('overtime::overtime.overtimeclaim.projectmanager.view', [
'main' => $data['main'],
'details' => $data['details'],
'projectNames' => $data['projectNames'],
'latestQuery' => $data['latestQuery'],
'queryHistory' => $data['queryHistory'],
'statuses' => $statuses,
'forms' => $selectionData['forms'],
'months' => $selectionData['months'],
'staffNames' => $selectionData['staffNames'],
]);
}
// =========================================================================
// VIEW A REQUEST FORM (modal content, for picker preview)
// =========================================================================
public function viewRequestForm(Request $request, int $id)
{
$data = $this->repos->findRequestForm($id);
$view = view('overtime::overtime.overtimeclaim.projectmanager.request_form_view', [
'main' => $data['main'],
'details' => $data['details'],
]);
if ($request->ajax()) {
return response($view->render());
}
return $view;
}
// =========================================================================
// SOKONG
// =========================================================================
public function markReviewed(Request $request, int $id): JsonResponse
{
$request->validate([
'request_form_id' => 'required|integer|exists:overtime_request_main,id',
], [
'request_form_id.required' => 'Sila pilih borang permohonan berkaitan.',
]);
return $this->withTransaction(function () use ($request, $id) {
$this->repos->markClaimReviewed($id, $request->request_form_id);
return response()->json([
'success' => true,
'message' => 'Baris tuntutan projek telah ditandakan sebagai disemak.',
'redirect' => route('overtime::overtime.projectmanager.list'),
]);
});
}
public function sokongClaim(Request $request, int $id): JsonResponse
{
$request->validate([
'request_form_id' => 'required|integer|exists:overtime_request_main,id',
], [
'request_form_id.required' => 'Sila pilih borang permohonan berkaitan.',
]);
return $this->withTransaction(function () use ($request, $id) {
$this->repos->sokongClaim($id, $request->request_form_id);
return response()->json([
'success' => true,
'message' => 'Permohonan disokong dan dihantar ke HOD.',
'redirect' => route('overtime::overtime.projectmanager.list'),
]);
});
}
// =========================================================================
// KUERI
// =========================================================================
public function kueriClaim(Request $request, int $id): JsonResponse
{
$request->validate([
'remarks' => 'required|string|max:2000',
], [
'remarks.required' => 'Sila isi catatan kueri.',
]);
return $this->withTransaction(function () use ($request, $id) {
$this->repos->kueriClaim($id, $request->remarks);
return response()->json([
'success' => true,
'message' => 'Permohonan dikueri dan dihantar balik kepada pemohon.',
'redirect' => route('overtime::overtime.projectmanager.list'),
]);
});
}
// =========================================================================
// PRIVATE HELPERS
// =========================================================================
private function withTransaction(callable $callback): JsonResponse
{
try {
DB::beginTransaction();
$response = $callback();
DB::commit();
return $response;
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => $e->getMessage() ?: 'An error occurred.',
], 500);
}
}
}
<?php
namespace Portal\Overtime\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class LkpStatus extends Model
{
use SoftDeletes;
protected $table = 'lkp_status';
protected $guarded = ['id'];
}
\ No newline at end of file
<?php
namespace Portal\Overtime\Model;
use Illuminate\Database\Eloquent\Model;
class OvertimeAuditQuery extends Model
{
protected $table = 'overtime_audit_query';
protected $guarded = ['id'];
protected $casts = [
'tarikh' => 'datetime',
];
public function claim()
{
return $this->belongsTo(OvertimeClaimMain::class, 'fk_main');
}
public function queriedBy()
{
return $this->belongsTo(\App\Models\User::class, 'fk_user_kueri');
}
}
\ No newline at end of file
...@@ -17,6 +17,8 @@ class OvertimeClaimDetail extends Model ...@@ -17,6 +17,8 @@ class OvertimeClaimDetail extends Model
'ocd_date' => 'date', 'ocd_date' => 'date',
'ocd_effective_hours' => 'decimal:2', 'ocd_effective_hours' => 'decimal:2',
'ocd_total_hours' => 'decimal:2', 'ocd_total_hours' => 'decimal:2',
'ocd_pm_reviewed' => 'boolean',
'ocd_pm_reviewed_at' => 'datetime',
'deleted_at' => 'datetime', 'deleted_at' => 'datetime',
]; ];
} }
\ No newline at end of file
...@@ -16,9 +16,24 @@ class OvertimeClaimMain extends Model ...@@ -16,9 +16,24 @@ class OvertimeClaimMain extends Model
protected $casts = [ protected $casts = [
'ocm_month' => 'integer', 'ocm_month' => 'integer',
'ocm_year' => 'integer', 'ocm_year' => 'integer',
'ocm_query_status' => 'integer',
'ocm_verified_date' => 'datetime', 'ocm_verified_date' => 'datetime',
'ocm_approved_date' => 'datetime', 'ocm_approved_date' => 'datetime',
'ocm_submit_date' => 'datetime', 'ocm_submit_date' => 'datetime',
'deleted_at' => 'datetime', 'deleted_at' => 'datetime',
]; ];
public function auditQueries()
{
return $this->hasMany(OvertimeAuditQuery::class, 'fk_main')->orderBy('created_at', 'desc');
}
public function latestAuditQuery()
{
return $this->hasOne(OvertimeAuditQuery::class, 'fk_main')->latestOfMany();
}
public function details()
{
return $this->hasMany(OvertimeClaimDetail::class, 'fk_overtime_claim_main');
}
} }
\ No newline at end of file
...@@ -3,23 +3,24 @@ ...@@ -3,23 +3,24 @@
namespace Portal\Overtime\Model; namespace Portal\Overtime\Model;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\SoftDeletes;
class OvertimeRequestDetail extends Model class OvertimeRequestDetail extends Model
{ {
// use SoftDeletes;
protected $table = 'overtime_request_detail'; protected $table = 'overtime_request_detail';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected $casts = [
'ord_month_of_overtime' => 'date', // ← was 'datetime', caused ISO timestamp in JSON 'ord_month_of_overtime' => 'date',
'deleted_at' => 'datetime', 'ord_budgeted' => 'decimal:2',
'ord_budgeted' => 'decimal:2', 'ord_utilised_to_date' => 'decimal:2',
'ord_utilised_to_date' => 'decimal:2', 'ord_planned_ot_hour' => 'decimal:2',
'ord_planned_ot_hour' => 'decimal:2', 'ord_balance' => 'decimal:2',
'ord_balance' => 'decimal:2', 'ord_total_hours' => 'decimal:2',
'ord_total_hours' => 'decimal:2',
]; ];
public function main()
{
return $this->belongsTo(OvertimeRequestMain::class, 'fk_overtime_request_main');
}
} }
\ No newline at end of file
...@@ -3,12 +3,9 @@ ...@@ -3,12 +3,9 @@
namespace Portal\Overtime\Model; namespace Portal\Overtime\Model;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\SoftDeletes;
class OvertimeRequestMain extends Model class OvertimeRequestMain extends Model
{ {
// use SoftDeletes;
protected $table = 'overtime_request_main'; protected $table = 'overtime_request_main';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $guarded = ['id']; protected $guarded = ['id'];
...@@ -19,4 +16,16 @@ class OvertimeRequestMain extends Model ...@@ -19,4 +16,16 @@ class OvertimeRequestMain extends Model
'orm_approved_date' => 'datetime', 'orm_approved_date' => 'datetime',
'deleted_at' => 'datetime', 'deleted_at' => 'datetime',
]; ];
}
\ No newline at end of file public function details()
{
return $this->hasMany(OvertimeRequestDetail::class, 'fk_overtime_request_main');
}
public function auditQueries()
{
return $this->hasMany(OvertimeAuditQuery::class, 'fk_main')
->where('no_permohonan', $this->orm_apply_no)
->orderBy('created_at', 'desc');
}
}
...@@ -87,6 +87,44 @@ protected function menu() ...@@ -87,6 +87,44 @@ protected function menu()
// ->active('overtime/*'); // ->active('overtime/*');
// ->data('permission', Permission::PROJECT_MANAGER); // ->data('permission', Permission::PROJECT_MANAGER);
$menu = $menus->add(__('Tuntutan Lebih Masa'))->data('icon', 'align justify');
$menu = $menus->add(__('OT REQUEST'))->data('icon', 'align justify');
$menu->add(__('List of Request Forms (PM)'), url('/overtime/request/list'))
->data('icon', 'file alternate')
->active('overtime/request/*')
->data('permission', Permission::REQUEST_OT);
$menu->add(__('Support Request Forms (HOD)'), url('/overtime/request/hod/list'))
->data('icon', 'check circle')
->active('overtime/request/hod/*')
->data('permission', Permission::APPLICATION_OT_HOD);
$menu->add(__('Approve Request Forms (PD)'), url('/overtime/request/pd/list'))
->data('icon', 'check circle outline')
->active('overtime/request/pd/*')
->data('permission', Permission::APPLICATION_OT_PD);
$menu = $menus->add(__('OT CLAIM'))->data('icon', 'align justify');
$menu->add(__('List of Claim Forms '), url('/overtime/list'))
->data('icon', 'file alternate')
->active('overtime/*')
->data('permission', Permission::APPLICATION_OT);
$menu->add(__('Review Claim Forms (PM)'), url('/overtime/projectmanager/list'))
->data('icon', 'check')
->active('overtime/*')
->data('permission', Permission::APPLICATION_OT_REVIEW);
$menu->add(__('Support Claim Forms (HOD)'), url('/overtime/claim/hod/list'))
->data('icon', 'check circle')
->active('overtime/*')
->data('permission', Permission::APPLICATION_OT_SUPPORT);
$menu->add(__('Approve Claim Forms (PD)'), url('/overtime/claim/pd/list'))
->data('icon', 'check circle outline')
->active('overtime/*')
->data('permission', Permission::APPLICATION_OT_APPROVE);
}); });
} }
......
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