first commit
This commit is contained in:
commit
e557826642
|
|
@ -0,0 +1,60 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=production
|
||||
APP_KEY=base64:wIhXfVX/DNNDUeNSEpSnl7PeOjzWdrgvkChBzmEiu4M=
|
||||
APP_DEBUG=true
|
||||
APP_URL=https://ta.myhost.id/E31230906
|
||||
APP_TIMEZONE=Asia/Jakarta
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=tamyhost_E31230906
|
||||
DB_USERNAME=tamyhost_E31230906
|
||||
DB_PASSWORD=MIF_E31230906
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=cookie
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=live.smtp.mailtrap.io
|
||||
MAIL_PORT=587
|
||||
MAIL_USERNAME=api
|
||||
MAIL_PASSWORD=28971c622d8cfb592be491a9e4306bdb
|
||||
MAIL_ENCRYPTION=tls
|
||||
MAIL_FROM_ADDRESS=hello@demomailtrap.com
|
||||
MAIL_FROM_NAME="SIPDAM - Tirta Sanjiwani"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/.phpunit.cache
|
||||
/node_modules
|
||||
/public/build
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
auth.json
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
/.fleet
|
||||
/.idea
|
||||
/.vscode
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## About Laravel
|
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
||||
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
||||
- [Robust background job processing](https://laravel.com/docs/queues).
|
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
||||
|
||||
## Learning Laravel
|
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
|
||||
|
||||
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
|
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
||||
|
||||
## Laravel Sponsors
|
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||
|
||||
### Premium Partners
|
||||
|
||||
- **[Vehikl](https://vehikl.com/)**
|
||||
- **[Tighten Co.](https://tighten.co)**
|
||||
- **[WebReinvent](https://webreinvent.com/)**
|
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||
- **[64 Robots](https://64robots.com)**
|
||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
||||
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
||||
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||
- **[Jump24](https://jump24.co.uk)**
|
||||
- **[Redberry](https://redberry.international/laravel/)**
|
||||
- **[Active Logic](https://activelogic.com)**
|
||||
- **[byte5](https://byte5.de)**
|
||||
- **[OP.GG](https://op.gg)**
|
||||
|
||||
## Contributing
|
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
||||
|
||||
## Security Vulnerabilities
|
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
||||
|
||||
## License
|
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Penugasan;
|
||||
|
||||
class MigrateOldCatatanData extends Command
|
||||
{
|
||||
protected $signature = 'penugasan:migrate-catatan';
|
||||
protected $description = 'Migrasikan data lama dari kolom catatan_admin ke kolom terstruktur';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$penugasans = Penugasan::whereNull('alamat_lokasi')
|
||||
->whereNotNull('catatan_admin')
|
||||
->get();
|
||||
|
||||
$this->info("Ditemukan {$penugasans->count()} data lama yang perlu dimigrasi...");
|
||||
$updated = 0;
|
||||
|
||||
foreach ($penugasans as $p) {
|
||||
$catatan = $p->catatan_admin;
|
||||
$nama = null;
|
||||
$alamat = null;
|
||||
$noSamb = null;
|
||||
|
||||
// ── Cari Nama ──────────────────────────────────
|
||||
// Pola: "Nama : ...", "Nama DR ...", "Nama: ..."
|
||||
if (preg_match('/Nama\s*[:\-]?\s*(.+?)(?=Alamat|Pekerjaan|No\.?|$)/is', $catatan, $m)) {
|
||||
$nama = trim($m[1]);
|
||||
}
|
||||
|
||||
// ── Cari Alamat ─────────────────────────────────
|
||||
// Pola: "Alamat: ...", "Alamat BR. ..."
|
||||
if (preg_match('/Alamat\s*[:\-]?\s*(.+?)(?=Pekerjaan|No\.?|Nama|$)/is', $catatan, $m)) {
|
||||
$alamat = trim($m[1]);
|
||||
}
|
||||
|
||||
// ── Cari No Sambungan ───────────────────────────
|
||||
// Pola: "no sambungan 0032", "No sambungannya 0008", "no samb 0032"
|
||||
if (preg_match('/no\.?\s*samb(?:ungan(?:nya)?)?\s*[:\-]?\s*([0-9]+)/is', $catatan, $m)) {
|
||||
$noSamb = trim($m[1]);
|
||||
}
|
||||
|
||||
// Bersihkan trailing punct dari hasil parsing
|
||||
$nama = $nama ? rtrim($nama, ' ,;.') : null;
|
||||
$alamat = $alamat ? rtrim($alamat, ' ,;.') : null;
|
||||
|
||||
// Hanya update kalau minimal ada salah satu yang berhasil di-parse
|
||||
if ($nama || $alamat || $noSamb) {
|
||||
$p->update([
|
||||
'nama_pelanggan' => $nama,
|
||||
'alamat_lokasi' => $alamat,
|
||||
'no_sambungan' => $noSamb,
|
||||
]);
|
||||
$updated++;
|
||||
$this->line(" ✅ ID #{$p->id_penugasan} → Nama: $nama | Alamat: $alamat | No: $noSamb");
|
||||
} else {
|
||||
$this->line(" ⚠️ ID #{$p->id_penugasan} → Format tidak dikenali: \"{$catatan}\"");
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("\n✅ Selesai! $updated dari {$penugasans->count()} data berhasil dimigrasi.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Absensi;
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AbsensiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Menampilkan daftar data absensi dengan fitur filter.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$teknisis = Teknisi::orderBy('nama', 'asc')->get();
|
||||
|
||||
// Query dasar untuk data utama
|
||||
$query = Absensi::with('teknisi');
|
||||
|
||||
// Filter Rentang Tanggal
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
$query->whereBetween('tanggal', [$request->start_date, $request->end_date]);
|
||||
} elseif ($request->filled('start_date')) {
|
||||
$query->whereDate('tanggal', '>=', $request->start_date);
|
||||
} elseif ($request->filled('end_date')) {
|
||||
$query->whereDate('tanggal', '<=', $request->end_date);
|
||||
}
|
||||
|
||||
// Filter Teknisi
|
||||
if ($request->filled('teknisi')) {
|
||||
$query->where('id_teknisi', $request->teknisi);
|
||||
}
|
||||
|
||||
// Hitung statistik berdasarkan filter di atas (sebelum filter status)
|
||||
$counts = [
|
||||
'total' => (clone $query)->count(),
|
||||
'hadir' => (clone $query)->where('status', 'hadir')->count(),
|
||||
'izin' => (clone $query)->whereIn('status', ['izin', 'sakit'])->count(),
|
||||
];
|
||||
|
||||
// Apply filter status untuk tabel
|
||||
if ($request->query('status') === 'izin') {
|
||||
$query->whereIn('status', ['izin', 'sakit']);
|
||||
} else {
|
||||
$query->filterByStatus($request->query('status'));
|
||||
}
|
||||
|
||||
$absensis = $query->orderBy('tanggal', 'desc')
|
||||
->orderBy('jam_masuk', 'desc')
|
||||
->paginate(15);
|
||||
|
||||
return view('Admin.KelolaTeknisi.Absensi', compact('absensis', 'teknisis', 'counts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menampilkan detail data absensi spesifik.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$absensi = Absensi::with('teknisi')->where('id_absensi', $id)->first();
|
||||
|
||||
if (!$absensi) {
|
||||
return response()->json([
|
||||
'error' => 'Data absensi tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Generate URL yang benar untuk hosting
|
||||
$fotoMasukUrl = null;
|
||||
$fotoKeluarUrl = null;
|
||||
|
||||
if ($absensi->foto_absen_masuk) {
|
||||
$fotoMasukUrl = 'https://ta.myhost.id/E31230906/laravel/public/storage/' . $absensi->foto_absen_masuk;
|
||||
}
|
||||
|
||||
if ($absensi->foto_absen_keluar) {
|
||||
$fotoKeluarUrl = 'https://ta.myhost.id/E31230906/laravel/public/storage/' . $absensi->foto_absen_keluar;
|
||||
}
|
||||
$data = [
|
||||
'id' => $absensi->id_absensi,
|
||||
'tanggal' => $absensi->tanggal instanceof \Carbon\Carbon
|
||||
? $absensi->tanggal->format('d/m/Y')
|
||||
: Carbon::parse($absensi->tanggal)->format('d/m/Y'),
|
||||
'tanggal_full' => $absensi->tanggal instanceof \Carbon\Carbon
|
||||
? $absensi->tanggal->isoFormat('dddd, D MMMM YYYY')
|
||||
: Carbon::parse($absensi->tanggal)->isoFormat('dddd, D MMMM YYYY'),
|
||||
'jam_masuk' => $absensi->jam_masuk
|
||||
? Carbon::parse($absensi->jam_masuk)->format('H:i')
|
||||
: '-',
|
||||
'jam_keluar' => $absensi->jam_keluar
|
||||
? Carbon::parse($absensi->jam_keluar)->format('H:i')
|
||||
: '-',
|
||||
'durasi_kerja' => $absensi->durasi_kerja_formatted ?? '00:00',
|
||||
'status' => $absensi->status,
|
||||
'status_formatted' => ucfirst($absensi->status),
|
||||
'status_badge_class' => $absensi->status_badge_class ?? 'badge-secondary',
|
||||
'is_terlambat' => $absensi->is_terlambat ?? false,
|
||||
'keterangan' => $absensi->keterangan ?? '-',
|
||||
'teknisi' => [
|
||||
'id' => $absensi->teknisi ? $absensi->teknisi->id_teknisi : null,
|
||||
'nama' => $absensi->teknisi ? $absensi->teknisi->nama : 'Teknisi tidak ditemukan',
|
||||
'email' => ($absensi->teknisi && $absensi->teknisi->email)
|
||||
? $absensi->teknisi->email
|
||||
: 'Email tidak tersedia',
|
||||
],
|
||||
'foto_masuk_url' => $fotoMasukUrl,
|
||||
'foto_keluar_url' => $fotoKeluarUrl,
|
||||
'kategori_kerja' => $absensi->kategori_kerja,
|
||||
'latitude' => $absensi->latitude ?? '0',
|
||||
'longitude' => $absensi->longitude ?? '0',
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan statistik absensi
|
||||
*/
|
||||
public function getStatistik(Request $request)
|
||||
{
|
||||
$id_teknisi = $request->id_teknisi;
|
||||
$start = $request->start_date;
|
||||
$end = $request->end_date;
|
||||
|
||||
$data = \DB::table('absensis')
|
||||
->whereBetween('tanggal', [$start . ' 00:00:00', $end . ' 23:59:59'])
|
||||
->get();
|
||||
|
||||
$stats = ['hadir' => 0, 'terlambat' => 0, 'izin' => 0, 'sakit' => 0];
|
||||
$trendGroups = [];
|
||||
$rankGroups = [];
|
||||
$weekly = ['Sen'=>0, 'Sel'=>0, 'Rab'=>0, 'Kam'=>0, 'Jum'=>0];
|
||||
$dayMap = [1=>'Min', 2=>'Sen', 3=>'Sel', 4=>'Rab', 5=>'Kam', 6=>'Jum', 7=>'Sab'];
|
||||
|
||||
foreach ($data as $d) {
|
||||
$status = strtolower($d->status);
|
||||
$tgl = \Carbon\Carbon::parse($d->tanggal);
|
||||
|
||||
if (!$id_teknisi || $d->id_teknisi == $id_teknisi) {
|
||||
if (isset($stats[$status])) $stats[$status]++;
|
||||
$jam = $d->jam_masuk ? \Carbon\Carbon::parse($d->jam_masuk)->format('H:i') : '';
|
||||
if ($jam && ($jam < '07:00' || $jam > '18:00')) $stats['terlambat']++;
|
||||
}
|
||||
|
||||
$week = 'Minggu ' . ceil($tgl->day / 7);
|
||||
if (!isset($trendGroups[$week])) {
|
||||
$trendGroups[$week] = ['label' => $week, 'hadir' => 0, 'urgent' => 0];
|
||||
}
|
||||
if ($status == 'hadir') $trendGroups[$week]['hadir']++;
|
||||
|
||||
if (!isset($rankGroups[$d->id_teknisi])) {
|
||||
$tek = \DB::table('teknisis')->where('id_teknisi', $d->id_teknisi)->first();
|
||||
$rankGroups[$d->id_teknisi] = [
|
||||
'name' => $tek ? $tek->nama : 'Unknown',
|
||||
'init' => $tek ? strtoupper(substr($tek->nama, 0, 2)) : '??',
|
||||
'total' => 0, 'hadir' => 0
|
||||
];
|
||||
}
|
||||
$rankGroups[$d->id_teknisi]['total']++;
|
||||
if ($status == 'hadir') $rankGroups[$d->id_teknisi]['hadir']++;
|
||||
|
||||
$dayName = $dayMap[$tgl->dayOfWeek + 1] ?? '';
|
||||
if (isset($weekly[$dayName]) && $status == 'hadir') $weekly[$dayName]++;
|
||||
}
|
||||
|
||||
$rankings = collect($rankGroups)->map(function($r) {
|
||||
$r['pct'] = $r['total'] > 0 ? round(($r['hadir'] / $r['total']) * 100) : 0;
|
||||
return $r;
|
||||
})->sortByDesc('pct')->values()->take(5);
|
||||
|
||||
ksort($trendGroups);
|
||||
$trend = array_values($trendGroups);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => array_merge($stats, [
|
||||
'trend' => $trend,
|
||||
'rankings' => $rankings,
|
||||
'weekly' => $weekly
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Memperbarui data absensi (digunakan oleh Admin).
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'jam_masuk' => 'nullable',
|
||||
'jam_keluar' => 'nullable',
|
||||
'status' => 'required|in:hadir,izin,sakit',
|
||||
'keterangan' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$absensi = Absensi::findOrFail($id);
|
||||
$tgl = \Carbon\Carbon::parse($absensi->tanggal)->format('Y-m-d');
|
||||
|
||||
$absensi->jam_masuk = $request->jam_masuk ? $tgl . ' ' . $request->jam_masuk : null;
|
||||
$absensi->jam_keluar = $request->jam_keluar ? $tgl . ' ' . $request->jam_keluar : null;
|
||||
$absensi->status = $request->status;
|
||||
$absensi->keterangan = $request->keterangan;
|
||||
|
||||
$absensi->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data absensi berhasil diperbarui.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,408 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\AkunTeknisi;
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
|
||||
class AkunTeknisiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan daftar semua akun teknisi.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$akunTeknisis = AkunTeknisi::with('teknisi')->get();
|
||||
$teknisis = Teknisi::whereNotIn('id_teknisi',
|
||||
AkunTeknisi::pluck('id_teknisi'))->get();
|
||||
|
||||
return view('Admin.KelolaTeknisi.AkunTeknisi', compact('akunTeknisis', 'teknisis'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan form untuk membuat akun teknisi baru.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$teknisi = Teknisi::all();
|
||||
return view('Admin.KelolaTeknisi.create-akun', compact('teknisi'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan akun teknisi baru ke database.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|exists:teknisis,id_teknisi|unique:akun_teknisis,id_teknisi',
|
||||
'username' => 'required|string|max:255|unique:akun_teknisis,username',
|
||||
'password' => 'required|string|min:6',
|
||||
'status' => 'required|in:aktif,tidak_aktif',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
AkunTeknisi::create([
|
||||
'id_teknisi' => $request->id_teknisi,
|
||||
'username' => $request->username,
|
||||
'password' => Hash::make($request->password),
|
||||
'password_plain' => $request->password,
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun teknisi berhasil dibuat!'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal membuat akun teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan detail akun teknisi tertentu.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
try {
|
||||
$akunTeknisi = AkunTeknisi::with('teknisi')->findOrFail($id);
|
||||
return response()->json($akunTeknisi);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Akun teknisi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan form untuk mengedit akun teknisi.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
try {
|
||||
$akunTeknisi = AkunTeknisi::with('teknisi')->findOrFail($id);
|
||||
return response()->json($akunTeknisi);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Akun teknisi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update akun teknisi di database.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$akunTeknisi = AkunTeknisi::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|exists:teknisis,id_teknisi|unique:akun_teknisis,id_teknisi,' . $id . ',id_akun_teknisi',
|
||||
'username' => 'required|string|max:255|unique:akun_teknisis,username,' . $id . ',id_akun_teknisi',
|
||||
'password' => 'nullable|string|min:6',
|
||||
'status' => 'required|in:aktif,tidak_aktif',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'id_teknisi' => $request->id_teknisi,
|
||||
'username' => $request->username,
|
||||
'status' => $request->status,
|
||||
];
|
||||
|
||||
// Hanya update password jika diisi
|
||||
if ($request->filled('password')) {
|
||||
$updateData['password'] = Hash::make($request->password);
|
||||
$updateData['password_plain'] = $request->password;
|
||||
}
|
||||
|
||||
$akunTeknisi->update($updateData);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun teknisi berhasil diupdate!'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal update akun teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus akun teknisi dari database.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$akunTeknisi = AkunTeknisi::findOrFail($id);
|
||||
$akunTeknisi->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun teknisi berhasil dihapus!'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal hapus akun teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login untuk teknisi (Mobile App).
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
// Cari akun teknisi
|
||||
$akun = AkunTeknisi::where('username', $request->username)
|
||||
->where('status', 'aktif')
|
||||
->with('teknisi')
|
||||
->first();
|
||||
|
||||
// Cek kredensial
|
||||
if (!$akun || !Hash::check($request->password, $akun->password)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Username atau password salah'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Generate JWT token
|
||||
$token = auth('api')->login($akun);
|
||||
|
||||
if (!$token) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal membuat token'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Login berhasil',
|
||||
'access_token' => $token,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => auth('api')->factory()->getTTL() * 60,
|
||||
'user' => [
|
||||
'id_akun_teknisi' => $akun->id_akun_teknisi,
|
||||
'username' => $akun->username,
|
||||
'status' => $akun->status,
|
||||
'teknisi' => $akun->teknisi
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan saat login: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout teknisi.
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
try {
|
||||
auth('api')->logout();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Logout berhasil'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan saat logout: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile teknisi yang sedang login.
|
||||
*/
|
||||
public function me()
|
||||
{
|
||||
try {
|
||||
$akun = auth('api')->user();
|
||||
|
||||
if (!$akun) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Load relasi teknisi
|
||||
$akun->load('teknisi');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data berhasil diambil',
|
||||
'data' => [
|
||||
'id_akun_teknisi' => $akun->id_akun_teknisi,
|
||||
'username' => $akun->username,
|
||||
'status' => $akun->status,
|
||||
'teknisi' => $akun->teknisi
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh JWT token.
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
try {
|
||||
$newToken = auth('api')->refresh();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Token berhasil di-refresh',
|
||||
'access_token' => $newToken,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => auth('api')->factory()->getTTL() * 60
|
||||
]);
|
||||
} catch (JWTException $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal refresh token: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change password teknisi.
|
||||
*/
|
||||
public function changePassword(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'password_lama' => 'required|string',
|
||||
'password_baru' => 'required|string|min:6|confirmed',
|
||||
], [
|
||||
'password_baru.confirmed' => 'Konfirmasi password tidak sesuai',
|
||||
'password_baru.min' => 'Password baru minimal 6 karakter',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$akun = auth('api')->user();
|
||||
|
||||
// Cek password lama
|
||||
if (!Hash::check($request->password_lama, $akun->password)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Password lama tidak sesuai'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Update password
|
||||
$akun->update([
|
||||
'password' => Hash::make($request->password_baru)
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Password berhasil diubah'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengubah password: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status akun teknisi.
|
||||
*/
|
||||
public function updateStatus(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$akunTeknisi = AkunTeknisi::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'status' => 'required|in:aktif,tidak_aktif',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$akunTeknisi->update([
|
||||
'status' => $request->status
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status akun teknisi berhasil diupdate!'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal update status: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,577 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Absensi;
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AbsensiApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Absen masuk untuk teknisi dengan support status.
|
||||
*/
|
||||
public function absenMasuk(Request $request)
|
||||
{
|
||||
Log::info('Absen Masuk Request:', $request->all());
|
||||
|
||||
$status = $request->input('status', 'hadir');
|
||||
|
||||
$rules = [
|
||||
'id_teknisi' => 'required|exists:teknisis,id_teknisi',
|
||||
'status' => 'nullable|in:hadir,izin,sakit',
|
||||
'keterangan' => 'nullable|string|max:255',
|
||||
'latitude' => 'nullable|string',
|
||||
'longitude' => 'nullable|string',
|
||||
];
|
||||
|
||||
if ($status === 'hadir') {
|
||||
$rules['foto_absen_masuk'] = 'required|image|mimes:jpeg,png,jpg,gif|max:2048';
|
||||
} else {
|
||||
$rules['foto_absen_masuk'] = 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048';
|
||||
}
|
||||
|
||||
if ($status === 'izin') {
|
||||
$rules['keterangan'] = 'required|string|max:255';
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), $rules, [
|
||||
'foto_absen_masuk.required' => 'Foto wajib untuk status Hadir',
|
||||
'keterangan.required' => 'Keterangan wajib untuk status Izin',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::error('Validation failed:', $validator->errors()->toArray());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
// Cek apakah ada sesi yang masih aktif (belum absen keluar)
|
||||
$activeAbsen = Absensi::where('id_teknisi', $request->id_teknisi)
|
||||
->whereNull('jam_keluar')
|
||||
->whereDate('tanggal', Carbon::today())
|
||||
->first();
|
||||
|
||||
if ($activeAbsen) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda masih memiliki sesi absen yang aktif'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id_teknisi' => $request->id_teknisi,
|
||||
'tanggal' => Carbon::now('Asia/Jakarta')->toDateString(),
|
||||
'jam_masuk' => $status === 'hadir' ? Carbon::now('Asia/Jakarta') : null,
|
||||
'status' => $status,
|
||||
'keterangan' => $request->keterangan,
|
||||
'latitude' => $request->latitude,
|
||||
'longitude' => $request->longitude,
|
||||
];
|
||||
|
||||
if ($request->hasFile('foto_absen_masuk')) {
|
||||
$file = $request->file('foto_absen_masuk');
|
||||
$filename = uniqid() . '.' . $file->extension();
|
||||
$file->move(public_path('storage/absensi-masuk'), $filename);
|
||||
$data['foto_absen_masuk'] = 'absensi-masuk/' . $filename;
|
||||
}
|
||||
|
||||
$absensi = Absensi::create($data);
|
||||
$absensi->load('teknisi');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Absen masuk berhasil dicatat',
|
||||
'data' => $absensi
|
||||
], 201);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in absenMasuk: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal melakukan absen masuk',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Absen keluar untuk teknisi dengan support status.
|
||||
*/
|
||||
public function absenKeluar(Request $request)
|
||||
{
|
||||
Log::info('Absen Keluar Request:', $request->all());
|
||||
|
||||
$status = $request->input('status', 'hadir');
|
||||
|
||||
$rules = [
|
||||
'id_teknisi' => 'required|exists:teknisis,id_teknisi',
|
||||
'status' => 'nullable|in:hadir,izin,sakit',
|
||||
'keterangan' => 'nullable|string|max:255',
|
||||
'latitude' => 'nullable|string',
|
||||
'longitude' => 'nullable|string',
|
||||
];
|
||||
|
||||
if ($status === 'hadir') {
|
||||
$rules['foto_absen_keluar'] = 'required|image|mimes:jpeg,png,jpg,gif|max:2048';
|
||||
} else {
|
||||
$rules['foto_absen_keluar'] = 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048';
|
||||
}
|
||||
|
||||
if ($status === 'izin') {
|
||||
$rules['keterangan'] = 'required|string|max:255';
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), $rules, [
|
||||
'foto_absen_keluar.required' => 'Foto wajib untuk status Hadir',
|
||||
'keterangan.required' => 'Keterangan wajib untuk status Izin',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::error('Validation failed:', $validator->errors()->toArray());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
// Cari sesi terbaru yang belum absen keluar
|
||||
$absensi = Absensi::where('id_teknisi', $request->id_teknisi)
|
||||
->whereNull('jam_keluar')
|
||||
->orderBy('id_absensi', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$absensi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Tidak ada sesi absen aktif yang ditemukan'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = ['jam_keluar' => Carbon::now('Asia/Jakarta')];
|
||||
|
||||
if ($request->has('status')) {
|
||||
$data['status'] = $status;
|
||||
}
|
||||
|
||||
if ($request->has('keterangan')) {
|
||||
$data['keterangan'] = $absensi->keterangan
|
||||
? $absensi->keterangan . ' | ' . $request->keterangan
|
||||
: $request->keterangan;
|
||||
}
|
||||
|
||||
if ($request->has('latitude')) {
|
||||
$data['latitude'] = $request->latitude;
|
||||
}
|
||||
|
||||
if ($request->has('longitude')) {
|
||||
$data['longitude'] = $request->longitude;
|
||||
}
|
||||
|
||||
if ($request->hasFile('foto_absen_keluar')) {
|
||||
$file = $request->file('foto_absen_keluar');
|
||||
$filename = uniqid() . '.' . $file->extension();
|
||||
$file->move(public_path('storage/absensi-keluar'), $filename);
|
||||
$data['foto_absen_keluar'] = 'absensi-keluar/' . $filename;
|
||||
}
|
||||
|
||||
$absensi->update($data);
|
||||
$absensi->load('teknisi');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Absen keluar berhasil dicatat',
|
||||
'data' => $absensi
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in absenKeluar: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal melakukan absen keluar',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mengecek status absensi teknisi hari ini.
|
||||
*/
|
||||
public function checkStatus($id_teknisi)
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('id_teknisi', $id_teknisi)->first();
|
||||
|
||||
if (!$teknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Teknisi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Ambil sesi terbaru hari ini
|
||||
$absensi = Absensi::where('id_teknisi', $id_teknisi)
|
||||
->whereDate('tanggal', Carbon::today())
|
||||
->orderBy('id_absensi', 'desc')
|
||||
->first();
|
||||
|
||||
$status = [
|
||||
'sudah_absen_masuk' => false,
|
||||
'sudah_absen_keluar' => false,
|
||||
'data_absensi' => null,
|
||||
];
|
||||
|
||||
if ($absensi) {
|
||||
$status['sudah_absen_masuk'] = !empty($absensi->jam_masuk) && empty($absensi->jam_keluar) && $absensi->status === 'hadir';
|
||||
$status['sudah_absen_keluar'] = !empty($absensi->jam_keluar);
|
||||
$status['data_absensi'] = [
|
||||
'jam_masuk' => $absensi->jam_masuk,
|
||||
'jam_keluar' => $absensi->jam_keluar,
|
||||
'jam_masuk_formatted' => $absensi->jam_masuk_formatted,
|
||||
'jam_keluar_formatted' => $absensi->jam_keluar_formatted,
|
||||
'durasi_kerja_formatted' => $absensi->durasi_kerja_formatted,
|
||||
'status' => $absensi->status,
|
||||
'keterangan' => $absensi->keterangan,
|
||||
'lokasi_masuk' => $absensi->lokasi_masuk ?? '-',
|
||||
'lokasi_valid' => $absensi->lokasi_valid ?? false,
|
||||
'latitude' => $absensi->latitude,
|
||||
'longitude' => $absensi->longitude,
|
||||
'foto_absen_masuk' => $absensi->foto_absen_masuk,
|
||||
'foto_absen_keluar' => $absensi->foto_absen_keluar,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status absensi berhasil diambil',
|
||||
'data' => $status
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in checkStatus: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengecek status absensi',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan riwayat absensi teknisi per bulan
|
||||
* dengan field yang sudah diformat untuk blade & Flutter.
|
||||
*/
|
||||
public function riwayat(Request $request)
|
||||
{
|
||||
try {
|
||||
$id_teknisi = $request->query('id_teknisi');
|
||||
|
||||
if (!$id_teknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'id_teknisi diperlukan'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = Absensi::where('id_teknisi', $id_teknisi);
|
||||
|
||||
if ($request->has('bulan') && $request->has('tahun')) {
|
||||
$query->filterByMonth($request->bulan, $request->tahun);
|
||||
}
|
||||
|
||||
$absensis = $query->orderBy('tanggal', 'desc')->get();
|
||||
|
||||
// ── Transform: kirim field yang sudah diformat ──────────────
|
||||
$data = $absensis->map(function ($absensi) {
|
||||
// Hitung menit telat (jadwal masuk 08:00)
|
||||
$menitTelat = 0;
|
||||
$terlambat = false;
|
||||
|
||||
if ($absensi->jam_masuk && $absensi->status === 'hadir') {
|
||||
$jamMasuk = Carbon::parse($absensi->jam_masuk)->setTimezone('Asia/Jakarta');
|
||||
$jamJadwal = Carbon::parse(
|
||||
$absensi->tanggal->format('Y-m-d') . ' 08:00:00'
|
||||
)->setTimezone('Asia/Jakarta');
|
||||
|
||||
if ($jamMasuk->gt($jamJadwal)) {
|
||||
$terlambat = true;
|
||||
$menitTelat = $jamMasuk->diffInMinutes($jamJadwal);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'tanggal' => $absensi->tanggal
|
||||
? $absensi->tanggal->format('Y-m-d')
|
||||
: null,
|
||||
'status' => $absensi->status,
|
||||
'jam_masuk_formatted' => $absensi->jam_masuk_formatted,
|
||||
'jam_keluar_formatted' => $absensi->jam_keluar_formatted,
|
||||
'durasi_kerja_formatted' => $absensi->durasi_kerja_formatted,
|
||||
'terlambat' => $terlambat,
|
||||
'menit_telat' => $menitTelat,
|
||||
'keterangan' => $absensi->keterangan,
|
||||
'latitude' => $absensi->latitude,
|
||||
'longitude' => $absensi->longitude,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Riwayat absensi berhasil diambil',
|
||||
'data' => $data
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in riwayat: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil riwayat absensi',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan statistik absensi.
|
||||
*/
|
||||
public function statistik(Request $request)
|
||||
{
|
||||
try {
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
$query = Absensi::query();
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$query->whereBetween('tanggal', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
if ($idTeknisi) {
|
||||
$query->where('id_teknisi', $idTeknisi);
|
||||
}
|
||||
|
||||
$statistik = [
|
||||
'total' => $query->count(),
|
||||
'hadir' => (clone $query)->where('status', 'hadir')->count(),
|
||||
'sakit' => (clone $query)->where('status', 'sakit')->count(),
|
||||
'izin' => (clone $query)->where('status', 'izin')->count(),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Statistik absensi berhasil diambil',
|
||||
'data' => $statistik
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in statistik: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil statistik absensi',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan daftar status absensi yang tersedia.
|
||||
*/
|
||||
public function getStatusOptions()
|
||||
{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Daftar status absensi berhasil diambil',
|
||||
'data' => [
|
||||
'hadir' => 'Hadir',
|
||||
'izin' => 'Izin',
|
||||
'sakit' => 'Sakit',
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan rekap absensi bulanan teknisi.
|
||||
*/
|
||||
public function rekap(Request $request)
|
||||
{
|
||||
try {
|
||||
$id_teknisi = $request->query('id_teknisi');
|
||||
$bulan = (int) $request->query('bulan', date('n'));
|
||||
$tahun = (int) $request->query('tahun', date('Y'));
|
||||
|
||||
if (!$id_teknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'id_teknisi diperlukan'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$absensis = Absensi::where('id_teknisi', $id_teknisi)
|
||||
->whereMonth('tanggal', $bulan)
|
||||
->whereYear('tanggal', $tahun)
|
||||
->get();
|
||||
|
||||
$hadir = $absensis->where('status', 'hadir')->count();
|
||||
$izin = $absensis->where('status', 'izin')->count();
|
||||
$sakit = $absensis->where('status', 'sakit')->count();
|
||||
$total = $absensis->count();
|
||||
|
||||
// Hitung persentase kehadiran
|
||||
$persentase = $total > 0 ? round(($hadir / $total) * 100, 1) : 0;
|
||||
|
||||
// Hitung rata-rata jam masuk
|
||||
$hadirItems = $absensis->where('status', 'hadir')
|
||||
->filter(fn($a) => $a->jam_masuk !== null);
|
||||
|
||||
$rataJamMasuk = '-';
|
||||
$rataJamKeluar = '-';
|
||||
$rataDurasi = '-';
|
||||
$terlambat = 0;
|
||||
$streak = 0;
|
||||
|
||||
if ($hadirItems->count() > 0) {
|
||||
// Rata-rata masuk
|
||||
$totalMasukMenit = $hadirItems->sum(function ($a) {
|
||||
return Carbon::parse($a->jam_masuk)
|
||||
->setTimezone('Asia/Jakarta')
|
||||
->hour * 60
|
||||
+ Carbon::parse($a->jam_masuk)
|
||||
->setTimezone('Asia/Jakarta')
|
||||
->minute;
|
||||
});
|
||||
$avgMasuk = round($totalMasukMenit / $hadirItems->count());
|
||||
$rataJamMasuk = sprintf('%02d:%02d', intdiv($avgMasuk, 60), $avgMasuk % 60);
|
||||
|
||||
// Rata-rata keluar
|
||||
$keluarItems = $hadirItems->filter(fn($a) => $a->jam_keluar !== null);
|
||||
if ($keluarItems->count() > 0) {
|
||||
$totalKeluarMenit = $keluarItems->sum(function ($a) {
|
||||
return Carbon::parse($a->jam_keluar)
|
||||
->setTimezone('Asia/Jakarta')
|
||||
->hour * 60
|
||||
+ Carbon::parse($a->jam_keluar)
|
||||
->setTimezone('Asia/Jakarta')
|
||||
->minute;
|
||||
});
|
||||
$avgKeluar = round($totalKeluarMenit / $keluarItems->count());
|
||||
$rataJamKeluar = sprintf('%02d:%02d', intdiv($avgKeluar, 60), $avgKeluar % 60);
|
||||
|
||||
// Rata-rata durasi
|
||||
$totalDurasiMenit = $keluarItems->sum(fn($a) => $a->durasi_kerja);
|
||||
$avgDurasi = round($totalDurasiMenit / $keluarItems->count());
|
||||
$jam = intdiv($avgDurasi, 60);
|
||||
$menit = $avgDurasi % 60;
|
||||
$rataDurasi = "{$jam}j {$menit}m";
|
||||
}
|
||||
|
||||
// Hitung keterlambatan
|
||||
$jadwalMasuk = '08:00';
|
||||
$terlambat = $hadirItems->filter(function ($a) use ($jadwalMasuk) {
|
||||
$jamMasuk = Carbon::parse($a->jam_masuk)->setTimezone('Asia/Jakarta');
|
||||
$jamJadwal = Carbon::parse(
|
||||
$a->tanggal->format('Y-m-d') . ' ' . $jadwalMasuk
|
||||
)->setTimezone('Asia/Jakarta');
|
||||
return $jamMasuk->gt($jamJadwal);
|
||||
})->count();
|
||||
}
|
||||
|
||||
// Hitung streak (berturut-turut hadir dari hari ini mundur)
|
||||
$sortedDesc = $absensis->sortByDesc('tanggal');
|
||||
foreach ($sortedDesc as $a) {
|
||||
if ($a->status === 'hadir') $streak++;
|
||||
else break;
|
||||
}
|
||||
|
||||
// Nama bulan Indonesia
|
||||
$namaBulan = [
|
||||
1=>'Januari',2=>'Februari',3=>'Maret',4=>'April',
|
||||
5=>'Mei',6=>'Juni',7=>'Juli',8=>'Agustus',
|
||||
9=>'September',10=>'Oktober',11=>'November',12=>'Desember'
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Rekap absensi berhasil diambil',
|
||||
'data' => [
|
||||
'bulan' => ($namaBulan[$bulan] ?? $bulan) . ' ' . $tahun,
|
||||
'total_hari_kerja'=> $total,
|
||||
'hadir' => $hadir,
|
||||
'izin' => $izin,
|
||||
'sakit' => $sakit,
|
||||
'persentase' => $persentase,
|
||||
'rata_masuk' => $rataJamMasuk,
|
||||
'rata_keluar' => $rataJamKeluar,
|
||||
'rata_durasi' => $rataDurasi,
|
||||
'keterlambatan' => $terlambat,
|
||||
'streak' => $streak,
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in rekap: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil rekap absensi',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan status absensi per tanggal dalam 1 bulan (untuk kalender).
|
||||
* Response: { "1": "hadir", "5": "izin", "10": "alpha", ... }
|
||||
*/
|
||||
public function kalender(Request $request)
|
||||
{
|
||||
try {
|
||||
$id_teknisi = $request->query('id_teknisi');
|
||||
$bulan = $request->query('bulan', date('n'));
|
||||
$tahun = $request->query('tahun', date('Y'));
|
||||
|
||||
if (!$id_teknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'id_teknisi diperlukan'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$absensis = Absensi::where('id_teknisi', $id_teknisi)
|
||||
->whereMonth('tanggal', $bulan)
|
||||
->whereYear('tanggal', $tahun)
|
||||
->get(['tanggal', 'status']);
|
||||
|
||||
// Map tanggal (angka) => status
|
||||
$data = [];
|
||||
foreach ($absensis as $absensi) {
|
||||
$tgl = (int) Carbon::parse($absensi->tanggal)->format('j');
|
||||
$data[$tgl] = $absensi->status;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data kalender berhasil diambil',
|
||||
'data' => $data
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in kalender: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data kalender',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class AkunTeknisi extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected $table = 'akun_teknisis';
|
||||
protected $primaryKey = 'id_akun_teknisi';
|
||||
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'username',
|
||||
'password',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
// Relasi ke tabel teknisi
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
// JWT Methods
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\Penggajian;
|
||||
use App\Models\Kasbon;
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\Absensi;
|
||||
use App\Models\TarifPekerjaan;
|
||||
use Illuminate\Http\Request;
|
||||
use Exception;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET - Data dashboard mobile teknisi
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$teknisi = Teknisi::findOrFail($idTeknisi);
|
||||
|
||||
// 1. Tugas Hari Ini / Aktif
|
||||
$tugasAktif = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi);
|
||||
});
|
||||
})
|
||||
->whereIn('status_pekerjaan', ['belum_mulai', 'dalam_proses'])
|
||||
->count();
|
||||
|
||||
// 2. Gaji Bulan Berjalan (Estimasi Ongkos Kerja)
|
||||
$now = Carbon::now();
|
||||
|
||||
// Cari semua penugasan yang melibatkan teknisi ini di bulan berjalan (eager loaded untuk performa)
|
||||
$penugasans = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
// (a) Teknisi utama penugasan
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
// (b) Anggota tim yang hadir
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi)
|
||||
->where('status_kehadiran', 'hadir');
|
||||
});
|
||||
})
|
||||
->where('status_pekerjaan', 'selesai')
|
||||
->where(function ($q) use ($now) {
|
||||
// Filter berdasarkan bulan selesai (Prioritas: tanggal_diselesaikan, fallback ke updated_at)
|
||||
$q->where(function ($q2) use ($now) {
|
||||
$q2->whereNotNull('tanggal_diselesaikan')
|
||||
->whereMonth('tanggal_diselesaikan', $now->month)
|
||||
->whereYear('tanggal_diselesaikan', $now->year);
|
||||
})->orWhere(function ($q2) use ($now) {
|
||||
$q2->whereNull('tanggal_diselesaikan')
|
||||
->whereMonth('updated_at', $now->month)
|
||||
->whereYear('updated_at', $now->year);
|
||||
});
|
||||
})
|
||||
->with(['items.tarif', 'timTeknisi'])
|
||||
->get();
|
||||
|
||||
$estimasiGaji = 0;
|
||||
$tugasSelesaiBulanIni = 0;
|
||||
|
||||
foreach ($penugasans as $penugasan) {
|
||||
$tugasSelesaiBulanIni++;
|
||||
|
||||
// Hitung jumlah anggota tim yang hadir
|
||||
$jumlahHadir = $penugasan->countTimHadir();
|
||||
if ($jumlahHadir === 0) {
|
||||
$jumlahHadir = 1;
|
||||
}
|
||||
|
||||
// Hitung total ongkos dari penugasan_items
|
||||
$totalOngkosTugas = 0;
|
||||
if ($penugasan->items->count() > 0) {
|
||||
foreach ($penugasan->items as $item) {
|
||||
$itemTotal = (float) $item->total_nilai_pekerjaan;
|
||||
if ($itemTotal <= 0) {
|
||||
$itemTotal = $this->calculatePenugasanItemValue($item);
|
||||
}
|
||||
$totalOngkosTugas += $itemTotal;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: ambil dari total_nilai_pekerjaan penugasan induk atau tarif
|
||||
if ($totalOngkosTugas <= 0) {
|
||||
$totalOngkosTugas = $this->calculatePenugasanValue($penugasan);
|
||||
}
|
||||
|
||||
if ($totalOngkosTugas <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bagian ongkos = total ongkos dibagi jumlah anggota tim yang hadir
|
||||
$bagianOngkos = $totalOngkosTugas / $jumlahHadir;
|
||||
$estimasiGaji += $bagianOngkos;
|
||||
}
|
||||
|
||||
// 3. Total Kasbon Aktif
|
||||
$totalKasbon = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->where('status', 'belum_lunas')
|
||||
->sum('jumlah_kasbon');
|
||||
|
||||
// 4. Gaji Terakhir Diterima
|
||||
$gajiTerakhir = Penggajian::where('id_teknisi', $idTeknisi)
|
||||
->where('status_pembayaran', 'sudah_bayar')
|
||||
->orderBy('periode_tahun', 'desc')
|
||||
->orderBy('periode_bulan', 'desc')
|
||||
->first();
|
||||
|
||||
// 5. Statistik Absensi Bulan Ini
|
||||
$absensiBulanIni = Absensi::where('id_teknisi', $idTeknisi)
|
||||
->whereMonth('tanggal', $now->month)
|
||||
->whereYear('tanggal', $now->year)
|
||||
->get();
|
||||
|
||||
$hadir = $absensiBulanIni->where('status', 'hadir')->count();
|
||||
$totalAbsen = $absensiBulanIni->count();
|
||||
$kehadiran = $totalAbsen > 0 ? round(($hadir / $totalAbsen) * 100) : 0;
|
||||
|
||||
// Rata-rata jam kerja (dalam jam)
|
||||
$totalDurasiMenit = $absensiBulanIni->where('status', 'hadir')->sum(function($a) {
|
||||
return $a->durasi_kerja;
|
||||
});
|
||||
$jamKerja = round($totalDurasiMenit / 60, 1);
|
||||
|
||||
// Efisiensi
|
||||
$poolTugas = $tugasAktif + $tugasSelesaiBulanIni;
|
||||
$efisiensi = $poolTugas > 0 ? round(($tugasSelesaiBulanIni / $poolTugas) * 100) : 0;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data dashboard berhasil diambil',
|
||||
'data' => [
|
||||
'teknisi' => [
|
||||
'nama' => $teknisi->nama,
|
||||
'spesialisasi' => $teknisi->spesialisasi,
|
||||
'foto' => $teknisi->foto_url
|
||||
],
|
||||
'statistik' => [
|
||||
'tugas_aktif' => $tugasAktif,
|
||||
'tugas_selesai' => $tugasSelesaiBulanIni,
|
||||
'estimasi_gaji' => (float) $estimasiGaji,
|
||||
'total_kasbon' => (float) $totalKasbon,
|
||||
'gaji_terakhir' => $gajiTerakhir ? (float) $gajiTerakhir->gaji_bersih : 0,
|
||||
'periode_terakhir' => $gajiTerakhir ? Penggajian::getNamaBulan($gajiTerakhir->periode_bulan) . ' ' . $gajiTerakhir->periode_tahun : '-',
|
||||
'kehadiran' => $kehadiran,
|
||||
'jam_kerja' => $jamKerja,
|
||||
'efisiensi' => $efisiensi,
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data dashboard: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate nilai penugasan dengan fallback ke tarif
|
||||
*/
|
||||
private function calculatePenugasanValue($penugasan): float
|
||||
{
|
||||
if ($penugasan->total_nilai_pekerjaan > 0) {
|
||||
return (float) $penugasan->total_nilai_pekerjaan;
|
||||
}
|
||||
|
||||
$tarif = $penugasan->tarif;
|
||||
if (!$tarif) {
|
||||
$query = TarifPekerjaan::where('jenis_pekerjaan', $penugasan->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($penugasan->dimensi_pipa) {
|
||||
$query->where('dimensi_pipa', $penugasan->dimensi_pipa);
|
||||
}
|
||||
$tarif = $query->first();
|
||||
}
|
||||
|
||||
if (!$tarif) return 0;
|
||||
|
||||
if ($penugasan->jarak_meter > 0 && $tarif->tarif_per_meter) {
|
||||
return (float) $tarif->tarif_per_meter * (float) $penugasan->jarak_meter;
|
||||
}
|
||||
if ($penugasan->jumlah_unit > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_unit;
|
||||
}
|
||||
if ($penugasan->jumlah_titik > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_titik;
|
||||
}
|
||||
|
||||
return (float) ($tarif->tarif_per_unit ?? $tarif->tarif_per_meter ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate nilai untuk setiap PenugasanItem
|
||||
*/
|
||||
private function calculatePenugasanItemValue($item): float
|
||||
{
|
||||
if ($item->total_nilai_pekerjaan > 0) {
|
||||
return (float) $item->total_nilai_pekerjaan;
|
||||
}
|
||||
|
||||
$tarif = $item->tarif;
|
||||
if (!$tarif) {
|
||||
$query = TarifPekerjaan::where('jenis_pekerjaan', $item->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($item->dimensi_pipa) {
|
||||
$query->where('dimensi_pipa', $item->dimensi_pipa);
|
||||
}
|
||||
$tarif = $query->first();
|
||||
}
|
||||
|
||||
if (!$tarif) return 0;
|
||||
|
||||
if ($item->jarak_meter > 0 && $tarif->tarif_per_meter) {
|
||||
return (float) $tarif->tarif_per_meter * (float) $item->jarak_meter;
|
||||
}
|
||||
if ($item->jumlah_unit > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $item->jumlah_unit;
|
||||
}
|
||||
if ($item->jumlah_titik > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $item->jumlah_titik;
|
||||
}
|
||||
|
||||
return (float) ($tarif->tarif_per_unit ?? $tarif->tarif_per_meter ?? 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Penggajian;
|
||||
use Illuminate\Http\Request;
|
||||
use Exception;
|
||||
|
||||
class GajiApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET - Riwayat penggajian teknisi
|
||||
*/
|
||||
public function riwayat(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$riwayat = Penggajian::where('id_teknisi', $idTeknisi)
|
||||
->orderBy('periode_tahun', 'desc')
|
||||
->orderBy('periode_bulan', 'desc')
|
||||
->paginate(12);
|
||||
|
||||
$riwayat->getCollection()->transform(function ($item) {
|
||||
return [
|
||||
'id_penggajian' => $item->id_penggajian,
|
||||
'periode_bulan' => $item->periode_bulan,
|
||||
'periode_tahun' => $item->periode_tahun,
|
||||
'nama_bulan' => Penggajian::getNamaBulan($item->periode_bulan),
|
||||
'tanggal_penggajian' => $item->tanggal_penggajian->format('d M Y'),
|
||||
'total_ongkos' => (float) $item->total_ongkos_pekerjaan,
|
||||
'potongan_kasbon' => (float) $item->total_kasbon,
|
||||
'potongan_makan' => (float) $item->biaya_makan,
|
||||
'gaji_bersih' => (float) $item->gaji_bersih,
|
||||
'status_pembayaran' => $item->status_pembayaran,
|
||||
'is_paid' => $item->isPaid(),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Riwayat gaji berhasil diambil',
|
||||
'data' => $riwayat
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Detail slip gaji
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
$penggajian = Penggajian::with(['detailPenggajian.penugasan'])->findOrFail($id);
|
||||
|
||||
// Keamanan: Pastikan teknisi hanya bisa lihat gajinya sendiri
|
||||
if ($idTeknisi && $penggajian->id_teknisi != $idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Akses ditolak'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$details = $penggajian->detailPenggajian->map(function ($detail) {
|
||||
return [
|
||||
'id_penugasan' => $detail->id_penugasan,
|
||||
'pekerjaan' => $detail->penugasan->label_jenis_pekerjaan ?? 'Pekerjaan',
|
||||
'lokasi' => $detail->lokasi,
|
||||
'bagian_ongkos' => (float) $detail->bagian_ongkos,
|
||||
'rincian' => $detail->rincian_pekerjaan,
|
||||
'tanggal_selesai' => $detail->tanggal_selesai ? $detail->tanggal_selesai->format('d/m/Y') : '-',
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Detail gaji berhasil diambil',
|
||||
'data' => [
|
||||
'header' => [
|
||||
'id_penggajian' => $penggajian->id_penggajian,
|
||||
'periode' => Penggajian::getNamaBulan($penggajian->periode_bulan) . ' ' . $penggajian->periode_tahun,
|
||||
'tanggal_hitung' => $penggajian->tanggal_penggajian->format('d M Y'),
|
||||
'hari_kerja' => $penggajian->jumlah_hari_kerja,
|
||||
'gaji_kotor' => (float) $penggajian->total_ongkos_pekerjaan,
|
||||
'potongan_kasbon' => (float) $penggajian->total_kasbon,
|
||||
'potongan_makan' => (float) $penggajian->biaya_makan,
|
||||
'gaji_bersih' => (float) $penggajian->gaji_bersih,
|
||||
'status_pembayaran' => $penggajian->status_pembayaran,
|
||||
],
|
||||
'items' => $details
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data tidak ditemukan: ' . $e->getMessage()
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Kasbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Exception;
|
||||
|
||||
class KasbonApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET - Riwayat kasbon teknisi
|
||||
*/
|
||||
public function riwayat(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$query = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->orderBy('tanggal_kasbon', 'desc');
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
|
||||
$riwayat = $query->paginate(15);
|
||||
|
||||
$riwayat->getCollection()->transform(function ($item) {
|
||||
return [
|
||||
'id_kasbon' => $item->id_kasbon,
|
||||
'nominal' => (float) $item->jumlah_kasbon,
|
||||
'tanggal' => $item->tanggal_kasbon->format('d M Y'),
|
||||
'keperluan' => $item->keperluan,
|
||||
'detail' => $item->keterangan_detail,
|
||||
'status' => $item->status,
|
||||
'status_label' => $item->status == 'lunas' ? 'Lunas' : 'Belum Lunas',
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Riwayat kasbon berhasil diambil',
|
||||
'data' => $riwayat
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Statistik kasbon (total hutang)
|
||||
*/
|
||||
public function statistik(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$totalHutang = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->where('status', 'belum_lunas')
|
||||
->sum('jumlah_kasbon');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Statistik kasbon berhasil diambil',
|
||||
'data' => [
|
||||
'total_hutang' => (float) $totalHutang
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil statistik: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,854 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\TarifPekerjaan;
|
||||
use App\Models\TimTeknisiPenugasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
|
||||
class PenugasanApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET - Daftar penugasan untuk teknisi (via mobile)
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$query = Penugasan::with(['teknisi', 'tarif', 'timTeknisi.teknisi', 'items.tarif'])
|
||||
->where(function ($q) use ($idTeknisi) {
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi);
|
||||
});
|
||||
});
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status_pekerjaan', $request->status);
|
||||
}
|
||||
|
||||
if ($request->filled('jenis_pekerjaan')) {
|
||||
$query->where('jenis_pekerjaan', $request->jenis_pekerjaan);
|
||||
}
|
||||
|
||||
if ($request->filled('tanggal_mulai')) {
|
||||
$query->whereDate('tanggal_diberikan', '>=', $request->tanggal_mulai);
|
||||
}
|
||||
|
||||
if ($request->filled('tanggal_akhir')) {
|
||||
$query->whereDate('tanggal_diberikan', '<=', $request->tanggal_akhir);
|
||||
}
|
||||
|
||||
$penugasan = $query->orderBy('tanggal_diberikan', 'desc')->paginate(15);
|
||||
|
||||
$penugasan->getCollection()->transform(function ($item) {
|
||||
$namaTim = $item->timTeknisi->map(function ($tt) {
|
||||
return $tt->teknisi->nama ?? 'N/A';
|
||||
})->implode(', ');
|
||||
|
||||
$item->nama_tim = !empty($namaTim) ? $namaTim : ($item->teknisi->nama ?? 'N/A');
|
||||
|
||||
if ($item->teknisi) {
|
||||
$item->teknisi->nama = $item->nama_tim;
|
||||
}
|
||||
|
||||
$item->foto_surat_url = $item->foto_surat_url;
|
||||
$item->foto_sebelum_url = $item->foto_sebelum_url;
|
||||
$item->foto_sesudah_url = $item->foto_sesudah_url;
|
||||
$item->label_jenis_pekerjaan = $item->label_jenis_pekerjaan;
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data penugasan berhasil diambil',
|
||||
'data' => $penugasan
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Detail penugasan
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::with(['teknisi', 'tarif', 'timTeknisi.teknisi', 'items.tarif'])
|
||||
->findOrFail($id);
|
||||
|
||||
$teamMembers = $penugasan->timTeknisi->map(function ($tt) {
|
||||
return $tt->teknisi->nama ?? null;
|
||||
})->filter()->unique()->values();
|
||||
|
||||
$namaTim = $teamMembers->implode(', ');
|
||||
|
||||
$data = $penugasan->toArray();
|
||||
|
||||
$fullTeamNames = !empty($namaTim) ? $namaTim : ($penugasan->teknisi->nama ?? 'N/A');
|
||||
|
||||
if (isset($data['teknisi'])) {
|
||||
$data['teknisi']['nama'] = $fullTeamNames;
|
||||
}
|
||||
|
||||
$prefix = !empty($namaTim) ? "[Tim: $namaTim] " : "";
|
||||
$data['catatan_admin'] = $prefix . ($penugasan->catatan_admin ?? '');
|
||||
$data['instruksi_tambahan'] = $data['catatan_admin'];
|
||||
|
||||
$data['foto_surat_url'] = $penugasan->foto_surat_url;
|
||||
$data['foto_sebelum_url'] = $penugasan->foto_sebelum_url;
|
||||
$data['foto_sesudah_url'] = $penugasan->foto_sesudah_url;
|
||||
$data['label_jenis_pekerjaan'] = $penugasan->label_jenis_pekerjaan;
|
||||
$data['is_garansi_aktif'] = $penugasan->isGaransiAktif();
|
||||
$data['sisa_hari_garansi'] = $penugasan->getSisaHariGaransi();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Detail penugasan berhasil diambil',
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data tidak ditemukan: ' . $e->getMessage()
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST - Teknisi melengkapi detail pekerjaan via mobile (pertama kali)
|
||||
*/
|
||||
public function lengkapiDetail(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.jenis_pekerjaan' => 'required|string',
|
||||
'items.*.dimensi_pipa' => 'nullable',
|
||||
'items.*.jarak_meter' => 'nullable|numeric',
|
||||
'items.*.jumlah_unit' => 'nullable|integer',
|
||||
'items.*.jumlah_titik' => 'nullable|integer',
|
||||
'items.*.pakai_pipa_besi' => 'nullable',
|
||||
'items.*.jenis_pengangkatan' => 'nullable',
|
||||
'detail_pekerjaan' => 'nullable|string',
|
||||
'tanggal_mulai' => 'required|date',
|
||||
'tim_teknisi' => 'nullable|array',
|
||||
'foto_sebelum' => 'nullable|file|max:10240',
|
||||
'foto_sesudah' => 'nullable|file|max:10240',
|
||||
'foto_sebelum_base64' => 'nullable|string',
|
||||
'foto_sesudah_base64' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
\Illuminate\Support\Facades\Log::error('Validation Fail in lengkapiDetail', $validator->errors()->toArray());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
\App\Models\PenugasanItem::where('id_penugasan', $penugasan->id_penugasan)->delete();
|
||||
|
||||
$fotoSebelum = $penugasan->foto_sebelum;
|
||||
if ($request->hasFile('foto_sebelum')) {
|
||||
$fotoSebelum = $request->file('foto_sebelum')->store('penugasan/foto-sebelum', 'public');
|
||||
} elseif ($request->foto_sebelum_base64) {
|
||||
$fotoSebelum = $this->storeBase64($request->foto_sebelum_base64, 'penugasan/foto-sebelum');
|
||||
}
|
||||
|
||||
$fotoSesudah = $penugasan->foto_sesudah;
|
||||
if ($request->hasFile('foto_sesudah')) {
|
||||
$fotoSesudah = $request->file('foto_sesudah')->store('penugasan/foto-sesudah', 'public');
|
||||
} elseif ($request->foto_sesudah_base64) {
|
||||
$fotoSesudah = $this->storeBase64($request->foto_sesudah_base64, 'penugasan/foto-sesudah');
|
||||
}
|
||||
|
||||
$totalNilaiPenugasan = 0;
|
||||
$hasSR = false;
|
||||
|
||||
foreach ($request->items as $itemData) {
|
||||
$tarif = TarifPekerjaan::where('jenis_pekerjaan', $itemData['jenis_pekerjaan'])
|
||||
->where('is_active', true);
|
||||
|
||||
if (!empty($itemData['dimensi_pipa'])) {
|
||||
$tarif->where('dimensi_pipa', $itemData['dimensi_pipa']);
|
||||
}
|
||||
|
||||
if (isset($itemData['pakai_pipa_besi'])) {
|
||||
$tarif->where('pakai_pipa_besi', $itemData['pakai_pipa_besi']);
|
||||
}
|
||||
|
||||
$tarif = $tarif->first();
|
||||
$nilaiItem = $this->hitungNilaiItem($tarif, $itemData);
|
||||
$totalNilaiPenugasan += $nilaiItem;
|
||||
|
||||
\App\Models\PenugasanItem::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_tarif' => $tarif ? $tarif->id_tarif : null,
|
||||
'jenis_pekerjaan' => $itemData['jenis_pekerjaan'],
|
||||
'dimensi_pipa' => $itemData['dimensi_pipa'] ?? null,
|
||||
'jarak_meter' => $itemData['jarak_meter'] ?? null,
|
||||
'jumlah_unit' => $itemData['jumlah_unit'] ?? null,
|
||||
'jumlah_titik' => $itemData['jumlah_titik'] ?? null,
|
||||
'pakai_pipa_besi' => $itemData['pakai_pipa_besi'] ?? null,
|
||||
'jenis_pengangkatan' => $itemData['jenis_pengangkatan'] ?? null,
|
||||
'total_nilai_pekerjaan' => $nilaiItem,
|
||||
]);
|
||||
|
||||
if ($itemData['jenis_pekerjaan'] === 'sr') $hasSR = true;
|
||||
}
|
||||
|
||||
$firstItem = $request->items[0];
|
||||
|
||||
$penugasan->update([
|
||||
'jenis_pekerjaan' => $firstItem['jenis_pekerjaan'],
|
||||
'dimensi_pipa' => $firstItem['dimensi_pipa'] ?? $penugasan->dimensi_pipa,
|
||||
'jarak_meter' => $firstItem['jarak_meter'] ?? $penugasan->jarak_meter,
|
||||
'jumlah_unit' => $firstItem['jumlah_unit'] ?? $penugasan->jumlah_unit,
|
||||
'pakai_pipa_besi' => array_key_exists('pakai_pipa_besi', $firstItem)
|
||||
? $firstItem['pakai_pipa_besi']
|
||||
: $penugasan->pakai_pipa_besi,
|
||||
'status_pekerjaan' => $penugasan->status_pekerjaan === 'belum_mulai'
|
||||
? 'dalam_proses'
|
||||
: $penugasan->status_pekerjaan,
|
||||
'total_nilai_pekerjaan' => $totalNilaiPenugasan,
|
||||
'detail_pekerjaan' => $request->has('detail_pekerjaan')
|
||||
? $request->detail_pekerjaan
|
||||
: $penugasan->detail_pekerjaan,
|
||||
'tanggal_mulai' => $request->tanggal_mulai,
|
||||
'foto_sebelum' => $fotoSebelum,
|
||||
'foto_sesudah' => $fotoSesudah,
|
||||
]);
|
||||
|
||||
if ($hasSR) {
|
||||
$penugasan->setGaransiMeteranAir($request->tanggal_mulai);
|
||||
$penugasan->save();
|
||||
}
|
||||
|
||||
if ($request->filled('tim_teknisi')) {
|
||||
foreach ($request->tim_teknisi as $idTeknisiTambahan) {
|
||||
$exists = TimTeknisiPenugasan::where('id_penugasan', $penugasan->id_penugasan)
|
||||
->where('id_teknisi', $idTeknisiTambahan)
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
TimTeknisiPenugasan::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_teknisi' => $idTeknisiTambahan,
|
||||
'status_kehadiran' => 'hadir',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
$penugasan->load(['teknisi', 'tarif', 'timTeknisi.teknisi', 'items.tarif']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Detail pekerjaan berhasil dilengkapi!',
|
||||
'data' => $penugasan
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal melengkapi detail: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT - Update / edit detail pekerjaan yang sudah diisi sebelumnya (teknisi via mobile)
|
||||
*/
|
||||
public function updateDetail(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::with(['timTeknisi'])->findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|integer',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.id_penugasan_item' => 'nullable|integer',
|
||||
'items.*.jenis_pekerjaan' => 'required|string',
|
||||
'items.*.dimensi_pipa' => 'nullable',
|
||||
'items.*.jarak_meter' => 'nullable|numeric',
|
||||
'items.*.jumlah_unit' => 'nullable|integer',
|
||||
'items.*.jumlah_titik' => 'nullable|integer',
|
||||
'items.*.pakai_pipa_besi' => 'nullable',
|
||||
'items.*.jenis_pengangkatan' => 'nullable',
|
||||
'detail_pekerjaan' => 'nullable|string',
|
||||
'tanggal_mulai' => 'nullable|date',
|
||||
'tim_teknisi' => 'nullable|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$idTeknisiEditor = $request->id_teknisi;
|
||||
$isAssigned = ($penugasan->id_teknisi == $idTeknisiEditor) ||
|
||||
$penugasan->timTeknisi->pluck('id_teknisi')->contains($idTeknisiEditor);
|
||||
|
||||
if (!$isAssigned) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang mengedit penugasan ini'
|
||||
], 403);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
\App\Models\PenugasanItem::where('id_penugasan', $penugasan->id_penugasan)->delete();
|
||||
|
||||
$hasSR = false;
|
||||
$processedItemIds = [];
|
||||
|
||||
foreach ($request->items as $itemData) {
|
||||
$tarifQuery = TarifPekerjaan::where('jenis_pekerjaan', $itemData['jenis_pekerjaan'])
|
||||
->where('is_active', true);
|
||||
|
||||
if (!empty($itemData['dimensi_pipa'])) {
|
||||
$tarifQuery->where('dimensi_pipa', $itemData['dimensi_pipa']);
|
||||
}
|
||||
|
||||
if (isset($itemData['pakai_pipa_besi'])) {
|
||||
$tarifQuery->where('pakai_pipa_besi', $itemData['pakai_pipa_besi']);
|
||||
}
|
||||
|
||||
$tarif = $tarifQuery->first();
|
||||
$nilaiItem = $this->hitungNilaiItem($tarif, $itemData);
|
||||
|
||||
$created = \App\Models\PenugasanItem::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_tarif' => $tarif ? $tarif->id_tarif : null,
|
||||
'jenis_pekerjaan' => $itemData['jenis_pekerjaan'],
|
||||
'dimensi_pipa' => $itemData['dimensi_pipa'] ?? null,
|
||||
'jarak_meter' => $itemData['jarak_meter'] ?? null,
|
||||
'jumlah_unit' => $itemData['jumlah_unit'] ?? null,
|
||||
'jumlah_titik' => $itemData['jumlah_titik'] ?? null,
|
||||
'pakai_pipa_besi' => $itemData['pakai_pipa_besi'] ?? null,
|
||||
'jenis_pengangkatan' => $itemData['jenis_pengangkatan'] ?? null,
|
||||
'total_nilai_pekerjaan' => $nilaiItem,
|
||||
]);
|
||||
$processedItemIds[] = $created->id_penugasan_item;
|
||||
|
||||
if ($itemData['jenis_pekerjaan'] === 'sr') $hasSR = true;
|
||||
}
|
||||
|
||||
if ($request->has('detail_pekerjaan')) {
|
||||
$penugasan->detail_pekerjaan = $request->detail_pekerjaan;
|
||||
}
|
||||
|
||||
if ($request->filled('tanggal_mulai')) {
|
||||
$penugasan->tanggal_mulai = $request->tanggal_mulai;
|
||||
}
|
||||
|
||||
if ($request->filled('tim_teknisi')) {
|
||||
foreach ($request->tim_teknisi as $idTeknisiTambahan) {
|
||||
$exists = TimTeknisiPenugasan::where('id_penugasan', $penugasan->id_penugasan)
|
||||
->where('id_teknisi', $idTeknisiTambahan)
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
TimTeknisiPenugasan::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_teknisi' => $idTeknisiTambahan,
|
||||
'status_kehadiran' => 'hadir',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total = \App\Models\PenugasanItem::where('id_penugasan', $penugasan->id_penugasan)
|
||||
->sum('total_nilai_pekerjaan');
|
||||
|
||||
$firstItem = $request->items[0];
|
||||
|
||||
$penugasan->total_nilai_pekerjaan = $total;
|
||||
$penugasan->jenis_pekerjaan = $firstItem['jenis_pekerjaan'] ?? $penugasan->jenis_pekerjaan;
|
||||
$penugasan->dimensi_pipa = $firstItem['dimensi_pipa'] ?? $penugasan->dimensi_pipa;
|
||||
$penugasan->jarak_meter = $firstItem['jarak_meter'] ?? $penugasan->jarak_meter;
|
||||
$penugasan->jumlah_unit = $firstItem['jumlah_unit'] ?? $penugasan->jumlah_unit;
|
||||
$penugasan->pakai_pipa_besi = array_key_exists('pakai_pipa_besi', $firstItem)
|
||||
? $firstItem['pakai_pipa_besi']
|
||||
: $penugasan->pakai_pipa_besi;
|
||||
|
||||
$statusBolehDiubah = ['belum_mulai'];
|
||||
if (in_array($penugasan->status_pekerjaan, $statusBolehDiubah)) {
|
||||
$penugasan->status_pekerjaan = 'dalam_proses';
|
||||
}
|
||||
|
||||
$penugasan->save();
|
||||
|
||||
if ($hasSR) {
|
||||
$penugasan->setGaransiMeteranAir($penugasan->tanggal_mulai ?? null);
|
||||
$penugasan->save();
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
$penugasan->load(['teknisi', 'tarif', 'timTeknisi.teknisi', 'items.tarif']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Detail pekerjaan berhasil diperbarui!',
|
||||
'data' => $penugasan
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal memperbarui detail: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST - Tambah rincian pekerjaan baru di tengah progres
|
||||
*/
|
||||
public function addItem(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'jenis_pekerjaan' => 'required|string',
|
||||
'dimensi_pipa' => 'nullable',
|
||||
'jarak_meter' => 'nullable|numeric',
|
||||
'jumlah_unit' => 'nullable|integer',
|
||||
'jumlah_titik' => 'nullable|integer',
|
||||
'pakai_pipa_besi' => 'nullable',
|
||||
'jenis_pengangkatan' => 'nullable',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$tarif = TarifPekerjaan::where('jenis_pekerjaan', $request->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
|
||||
if ($request->filled('dimensi_pipa')) {
|
||||
$tarif->where('dimensi_pipa', $request->dimensi_pipa);
|
||||
}
|
||||
|
||||
if ($request->has('pakai_pipa_besi')) {
|
||||
$tarif->where('pakai_pipa_besi', $request->pakai_pipa_besi);
|
||||
}
|
||||
|
||||
$tarif = $tarif->first();
|
||||
$nilaiItem = $this->hitungNilaiItem($tarif, $request->all());
|
||||
|
||||
\App\Models\PenugasanItem::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_tarif' => $tarif ? $tarif->id_tarif : null,
|
||||
'jenis_pekerjaan' => $request->jenis_pekerjaan,
|
||||
'dimensi_pipa' => $request->dimensi_pipa,
|
||||
'jarak_meter' => $request->jarak_meter,
|
||||
'jumlah_unit' => $request->jumlah_unit,
|
||||
'jumlah_titik' => $request->jumlah_titik,
|
||||
'pakai_pipa_besi' => $request->pakai_pipa_besi,
|
||||
'jenis_pengangkatan' => $request->jenis_pengangkatan,
|
||||
'total_nilai_pekerjaan' => $nilaiItem,
|
||||
]);
|
||||
|
||||
$total = \App\Models\PenugasanItem::where('id_penugasan', $penugasan->id_penugasan)
|
||||
->sum('total_nilai_pekerjaan');
|
||||
$penugasan->total_nilai_pekerjaan = $total;
|
||||
$penugasan->save();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Rincian pekerjaan berhasil ditambahkan!',
|
||||
'data' => [
|
||||
'nilai_item' => $nilaiItem,
|
||||
'total_baru' => $penugasan->total_nilai_pekerjaan
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menambah rincian: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT - Update status pekerjaan
|
||||
*
|
||||
* ✅ FIX: Ketika status diubah menjadi 'selesai', semua anggota tim
|
||||
* otomatis dicatat status_kehadiran = 'hadir' di tabel tim_teknisi_penugasans.
|
||||
* Ini memastikan semua anggota tim terhitung gajinya meskipun
|
||||
* bukan dia yang menerima/menceklis tugas di awal.
|
||||
*/
|
||||
public function updateStatus(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'status_pekerjaan' => 'required|in:belum_mulai,dalam_proses,selesai,dibatalkan',
|
||||
'tanggal_diselesaikan' => 'required_if:status_pekerjaan,selesai|nullable|date',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$updateData = ['status_pekerjaan' => $request->status_pekerjaan];
|
||||
|
||||
if ($request->status_pekerjaan === 'selesai') {
|
||||
$updateData['tanggal_diselesaikan'] = $request->tanggal_diselesaikan ?? now();
|
||||
|
||||
// ✅ FIX: Pastikan semua anggota tim tercatat hadir
|
||||
// sehingga gaji semua anggota tim terhitung dengan benar
|
||||
TimTeknisiPenugasan::where('id_penugasan', $penugasan->id_penugasan)
|
||||
->update(['status_kehadiran' => 'hadir']);
|
||||
|
||||
// Recalculate total_nilai_pekerjaan if it's empty or zero
|
||||
if (empty($penugasan->total_nilai_pekerjaan) || $penugasan->total_nilai_pekerjaan <= 0) {
|
||||
$penugasan->load(['items.tarif']);
|
||||
$totalNilai = 0;
|
||||
|
||||
if ($penugasan->items && $penugasan->items->count() > 0) {
|
||||
foreach ($penugasan->items as $item) {
|
||||
$itemTotal = (float) $item->total_nilai_pekerjaan;
|
||||
if ($itemTotal <= 0) {
|
||||
$tarif = $item->tarif;
|
||||
if (!$tarif) {
|
||||
$tarifQuery = TarifPekerjaan::where('jenis_pekerjaan', $item->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($item->dimensi_pipa) {
|
||||
$tarifQuery->where('dimensi_pipa', $item->dimensi_pipa);
|
||||
}
|
||||
$tarif = $tarifQuery->first();
|
||||
}
|
||||
$itemTotal = $this->hitungNilaiItem($tarif, $item->toArray());
|
||||
if ($itemTotal > 0) {
|
||||
$item->update(['total_nilai_pekerjaan' => $itemTotal]);
|
||||
}
|
||||
}
|
||||
$totalNilai += $itemTotal;
|
||||
}
|
||||
}
|
||||
|
||||
if ($totalNilai <= 0 && $penugasan->jenis_pekerjaan) {
|
||||
$tarif = $penugasan->tarif;
|
||||
if (!$tarif) {
|
||||
$tarifQuery = TarifPekerjaan::where('jenis_pekerjaan', $penugasan->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($penugasan->dimensi_pipa) {
|
||||
$tarifQuery->where('dimensi_pipa', $penugasan->dimensi_pipa);
|
||||
}
|
||||
$tarif = $tarifQuery->first();
|
||||
}
|
||||
if ($tarif) {
|
||||
if ($penugasan->jarak_meter > 0 && $tarif->tarif_per_meter) {
|
||||
$totalNilai = (float) $tarif->tarif_per_meter * (float) $penugasan->jarak_meter;
|
||||
} elseif ($penugasan->jumlah_unit > 0 && $tarif->tarif_per_unit) {
|
||||
$totalNilai = (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_unit;
|
||||
} elseif ($penugasan->jumlah_titik > 0 && $tarif->tarif_per_unit) {
|
||||
$totalNilai = (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_titik;
|
||||
} else {
|
||||
$totalNilai = (float) ($tarif->tarif_per_unit ?? $tarif->tarif_per_meter ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($totalNilai > 0) {
|
||||
$updateData['total_nilai_pekerjaan'] = $totalNilai;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$penugasan->update($updateData);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status pekerjaan berhasil diupdate!',
|
||||
'data' => $penugasan
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal update status: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST - Upload foto sebelum/sesudah
|
||||
*/
|
||||
public function uploadFoto(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
\Illuminate\Support\Facades\Log::info('Upload Foto Request Received', [
|
||||
'id_penugasan' => $id,
|
||||
'tipe_foto' => $request->tipe_foto,
|
||||
'has_file' => $request->hasFile('foto'),
|
||||
]);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'tipe_foto' => 'required|in:sebelum,sesudah',
|
||||
'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:10240',
|
||||
'sebelum_base64' => 'nullable|string',
|
||||
'sesudah_base64' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validasi gagal',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$tipeFoto = $request->tipe_foto;
|
||||
$fotoPath = null;
|
||||
|
||||
if ($request->hasFile('foto')) {
|
||||
$fotoPath = $request->file('foto')->store("penugasan/foto-{$tipeFoto}", 'public');
|
||||
} elseif ($request->input($tipeFoto . '_base64')) {
|
||||
$fotoPath = $this->storeBase64($request->input($tipeFoto . '_base64'), "penugasan/foto-{$tipeFoto}");
|
||||
}
|
||||
|
||||
if (!$fotoPath) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Tidak ada foto yang diupload'
|
||||
], 422);
|
||||
}
|
||||
|
||||
if ($tipeFoto === 'sebelum') {
|
||||
$penugasan->foto_sebelum = $fotoPath;
|
||||
} else {
|
||||
$penugasan->foto_sesudah = $fotoPath;
|
||||
}
|
||||
$penugasan->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "Foto {$tipeFoto} berhasil diupload!",
|
||||
'data' => [
|
||||
'foto_url' => asset("storage/{$fotoPath}"),
|
||||
'foto_path' => $fotoPath
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal upload foto: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Tarif berdasarkan jenis pekerjaan
|
||||
*/
|
||||
public function getTarifByJenis(Request $request)
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'jenis_pekerjaan' => 'required|in:sr,pengembangan_jaringan_pipa,pengangkatan,pemasangan_gate_valve,gali_urug,perbaikan_jaringan_pipa,pengecatan_pipa_besi,penyempurnaan_jaringan_pipa',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Jenis pekerjaan tidak valid',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$tarifs = TarifPekerjaan::where('jenis_pekerjaan', $request->jenis_pekerjaan)
|
||||
->where('is_active', true)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data tarif berhasil diambil',
|
||||
'data' => $tarifs
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data tarif: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Statistik penugasan teknisi
|
||||
*/
|
||||
public function statistik(Request $request)
|
||||
{
|
||||
try {
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
|
||||
if (!$idTeknisi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID Teknisi tidak ditemukan'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$baseQuery = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi);
|
||||
});
|
||||
});
|
||||
|
||||
$statistik = [
|
||||
'total_penugasan' => (clone $baseQuery)->count(),
|
||||
'belum_mulai' => (clone $baseQuery)->where('status_pekerjaan', 'belum_mulai')->count(),
|
||||
'dalam_proses' => (clone $baseQuery)->where('status_pekerjaan', 'dalam_proses')->count(),
|
||||
'selesai' => (clone $baseQuery)->where('status_pekerjaan', 'selesai')->count(),
|
||||
'menunggu_detail' => (clone $baseQuery)->whereNull('jenis_pekerjaan')->count(),
|
||||
'detail_lengkap' => (clone $baseQuery)->whereNotNull('jenis_pekerjaan')->count(),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Statistik berhasil diambil',
|
||||
'data' => $statistik
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil statistik: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - Daftar teknisi aktif untuk tambah tim
|
||||
*/
|
||||
public function getTeknisiList()
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('status', 'aktif')
|
||||
->orderBy('nama')
|
||||
->get(['id_teknisi', 'nama', 'no_telepon', 'spesialisasi']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Daftar teknisi berhasil diambil',
|
||||
'data' => $teknisi
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal mengambil data teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// PRIVATE HELPER
|
||||
// ===================================
|
||||
|
||||
private function hitungNilaiItem($tarif, array $data): float
|
||||
{
|
||||
if (!$tarif) return 0;
|
||||
|
||||
if ($tarif->tarif_per_meter && !empty($data['jarak_meter'])) {
|
||||
return (float)$tarif->tarif_per_meter * (float)$data['jarak_meter'];
|
||||
}
|
||||
|
||||
if ($tarif->tarif_per_unit && !empty($data['jumlah_unit'])) {
|
||||
return (float)$tarif->tarif_per_unit * (int)$data['jumlah_unit'];
|
||||
}
|
||||
|
||||
if ($tarif->tarif_per_unit && !empty($data['jumlah_titik'])) {
|
||||
return (float)$tarif->tarif_per_unit * (int)$data['jumlah_titik'];
|
||||
}
|
||||
|
||||
return (float)($tarif->tarif_per_unit ?? 0);
|
||||
}
|
||||
|
||||
private function storeBase64($base64String, $folder)
|
||||
{
|
||||
try {
|
||||
if (preg_match("/^data:image\/(\w+);base64,/", $base64String, $type)) {
|
||||
$base64String = substr($base64String, strpos($base64String, ",") + 1);
|
||||
$type = strtolower($type[1]);
|
||||
} else {
|
||||
$type = "jpg";
|
||||
}
|
||||
|
||||
$image = base64_decode($base64String);
|
||||
if ($image === false) return null;
|
||||
|
||||
$fileName = \Illuminate\Support\Str::random(40) . "." . $type;
|
||||
$path = $folder . "/" . $fileName;
|
||||
|
||||
\Illuminate\Support\Facades\Storage::disk("public")->put($path, $image);
|
||||
|
||||
return $path;
|
||||
} catch (Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error("Base64 Store Error: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
// Redirect ke dashboard kamu (bukan RouteServiceProvider::HOME)
|
||||
return redirect()->intended(route('dashboard'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
if ($request->query('to') === 'login') {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
// Redirect ke halaman home/welcome setelah logout
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(RouteServiceProvider::HOME)
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View|RedirectResponse
|
||||
{
|
||||
if (User::exists()) {
|
||||
return redirect()->route('login')->with('error', 'Pendaftaran ditutup karena akun administrator sudah terdaftar.');
|
||||
}
|
||||
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (User::exists()) {
|
||||
return redirect()->route('login')->with('error', 'Pendaftaran ditutup karena akun administrator sudah terdaftar.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect()->route('verification.notice');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\PenugasanItem;
|
||||
use App\Models\Laporan;
|
||||
use App\Models\TarifPekerjaan;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
// ── STAT CARDS ──────────────────────────────────────
|
||||
// ── STAT CARDS ──
|
||||
$totalTeknisi = Teknisi::count();
|
||||
$teknisiAktif = Teknisi::where('status', 'aktif')->count(); // sesuaikan nanti kalau error
|
||||
$totalPekerjaan = Penugasan::count();
|
||||
$totalLaporan = 0;
|
||||
$penugasanAktif = Penugasan::where('status_pekerjaan', 'dalam_proses')->count(); // ✅
|
||||
|
||||
// ── BAR CHART & DONUT ────────────────────────────────
|
||||
$chartData = PenugasanItem::select('jenis_pekerjaan', DB::raw('count(*) as total'))
|
||||
->groupBy('jenis_pekerjaan')
|
||||
->pluck('total', 'jenis_pekerjaan');
|
||||
|
||||
$jenisMapping = [
|
||||
'sr' => 'Sambungan Rumah (SR)',
|
||||
'pengembangan_jaringan_pipa' => 'Pengembangan Pipa',
|
||||
'perbaikan_jaringan_pipa' => 'Perbaikan Pipa',
|
||||
'gali_urug' => 'Gali Urug',
|
||||
'pemasangan_gate_valve' => 'Pemas. Gate Valve',
|
||||
'pengangkatan' => 'Pengangkatan',
|
||||
'pengecatan_pipa_besi' => 'Pengecatan Pipa',
|
||||
'penyempurnaan_jaringan_pipa' => 'Penyempurnaan Pipa',
|
||||
];
|
||||
|
||||
$chartColors = ['#1d9e75', '#378add', '#e24b4a', '#ef9f27', '#7f77dd', '#a552cc', '#34d399', '#f472b6'];
|
||||
|
||||
$chartLabels = [];
|
||||
$chartValues = [];
|
||||
$chartBgColors = [];
|
||||
|
||||
$i = 0;
|
||||
foreach($jenisMapping as $key => $label) {
|
||||
$chartLabels[] = $label;
|
||||
$chartValues[] = $chartData->get($key, 0);
|
||||
$chartBgColors[] = $chartColors[$i % count($chartColors)];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// ── LINE CHART TEKNISI (MULTI-LINE PER BULAN) ──────────────────
|
||||
$months = [];
|
||||
$monthLabels = [];
|
||||
for ($i = 5; $i >= 0; $i--) {
|
||||
$date = Carbon::now()->subMonths($i);
|
||||
$months[] = $date->format('Y-m');
|
||||
$monthLabels[] = $date->translatedFormat('F'); // ex: Januari, Februari
|
||||
}
|
||||
|
||||
$teknisiData = Penugasan::join('teknisis', 'penugasans.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('teknisis.nama', DB::raw('DATE_FORMAT(penugasans.created_at, "%Y-%m") as month_year'), DB::raw('count(penugasans.id_penugasan) as total'))
|
||||
->where('penugasans.created_at', '>=', Carbon::now()->subMonths(5)->startOfMonth())
|
||||
->groupBy('teknisis.id_teknisi', 'teknisis.nama', 'month_year')
|
||||
->get();
|
||||
|
||||
$teknisiDatasets = [];
|
||||
$lineColors = ['#378add', '#e24b4a', '#1d9e75', '#ef9f27', '#7f77dd', '#a552cc', '#f472b6', '#34d399'];
|
||||
$colorIdx = 0;
|
||||
|
||||
foreach ($teknisiData->groupBy('nama') as $nama => $records) {
|
||||
$dataArray = [];
|
||||
foreach ($months as $m) {
|
||||
$record = $records->firstWhere('month_year', $m);
|
||||
$dataArray[] = $record ? $record->total : 0;
|
||||
}
|
||||
|
||||
$teknisiDatasets[] = [
|
||||
'label' => $nama,
|
||||
'data' => $dataArray,
|
||||
'borderColor' => $lineColors[$colorIdx % count($lineColors)],
|
||||
'backgroundColor' => 'transparent',
|
||||
'borderWidth' => 2,
|
||||
'pointBackgroundColor' => '#fff',
|
||||
'pointBorderColor' => $lineColors[$colorIdx % count($lineColors)],
|
||||
'pointBorderWidth' => 2,
|
||||
'pointRadius' => 4,
|
||||
'tension' => 0.3
|
||||
];
|
||||
$colorIdx++;
|
||||
}
|
||||
|
||||
// ── TARIF PEKERJAAN ──────────────────────────────────
|
||||
$tarifPekerjaans = TarifPekerjaan::where('is_active', true)
|
||||
->orderBy('jenis_pekerjaan')
|
||||
->orderBy('dimensi_pipa')
|
||||
->get();
|
||||
|
||||
// ── KONTRAK — tidak ada, kirim collection kosong ─────
|
||||
$kontrakJatuhTempo = collect();
|
||||
|
||||
return view('dashboard', compact(
|
||||
'totalTeknisi',
|
||||
'teknisiAktif',
|
||||
'totalPekerjaan',
|
||||
'totalLaporan',
|
||||
'penugasanAktif',
|
||||
'chartLabels',
|
||||
'chartValues',
|
||||
'chartBgColors',
|
||||
'monthLabels',
|
||||
'teknisiDatasets',
|
||||
'tarifPekerjaans',
|
||||
'kontrakJatuhTempo',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,515 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kasbon;
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\Penugasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class KasbonController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return View|JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Kasbon::query();
|
||||
|
||||
// Filter berdasarkan status jika ada
|
||||
if ($request->has('status') && $request->status != '') {
|
||||
$query->byStatus($request->status);
|
||||
}
|
||||
|
||||
// Filter berdasarkan teknisi jika ada
|
||||
if ($request->has('id_teknisi') && $request->id_teknisi != '') {
|
||||
$query->where('id_teknisi', $request->id_teknisi);
|
||||
}
|
||||
|
||||
// Filter berdasarkan tanggal
|
||||
if ($request->has('tanggal_dari') && $request->tanggal_dari != '') {
|
||||
$query->whereDate('tanggal_kasbon', '>=', $request->tanggal_dari);
|
||||
}
|
||||
|
||||
if ($request->has('tanggal_sampai') && $request->tanggal_sampai != '') {
|
||||
$query->whereDate('tanggal_kasbon', '<=', $request->tanggal_sampai);
|
||||
}
|
||||
|
||||
// Sorting
|
||||
$sortBy = $request->get('sort_by', 'created_at');
|
||||
$sortOrder = $request->get('sort_order', 'desc');
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
// Pagination
|
||||
$perPage = $request->get('per_page', 15);
|
||||
$kasbons = $query->paginate($perPage);
|
||||
|
||||
// Statistik (Disederhanakan untuk efisiensi)
|
||||
$totalKasbon = Kasbon::count();
|
||||
$totalNominal = Kasbon::sum('jumlah_kasbon');
|
||||
$kasbonLunas = Kasbon::where('status', 'lunas')->count();
|
||||
$kasbonBelumLunas = Kasbon::where('status', 'belum_lunas')->count();
|
||||
$totalNominalBelumLunas = Kasbon::where('status', 'belum_lunas')->sum('jumlah_kasbon');
|
||||
|
||||
// Daftar teknisi untuk dropdown modal & filter
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
// Untuk API response
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $kasbons,
|
||||
'message' => 'Data kasbon berhasil diambil'
|
||||
]);
|
||||
}
|
||||
|
||||
return view('Admin.Gaji.Kasbon', compact(
|
||||
'kasbons',
|
||||
'totalKasbon',
|
||||
'totalNominal',
|
||||
'kasbonLunas',
|
||||
'kasbonBelumLunas',
|
||||
'totalNominalBelumLunas',
|
||||
'teknisis'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
$statusOptions = Kasbon::getStatusOptions();
|
||||
return view('Admin.Gaji.create-kasbon', compact('statusOptions')); // DIPERBAIKI: path view
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('Kasbon Store Request Received', $request->all());
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|integer|min:1',
|
||||
'jumlah_kasbon' => 'required|numeric|min:0',
|
||||
'tanggal_kasbon' => 'required|date',
|
||||
'status' => 'nullable|in:lunas,belum_lunas',
|
||||
'keterangan' => 'nullable|string|max:100'
|
||||
], [
|
||||
'id_teknisi.required' => 'ID Teknisi harus diisi',
|
||||
'id_teknisi.integer' => 'ID Teknisi harus berupa angka',
|
||||
'jumlah_kasbon.required' => 'Jumlah kasbon harus diisi',
|
||||
'jumlah_kasbon.numeric' => 'Jumlah kasbon harus berupa angka',
|
||||
'jumlah_kasbon.min' => 'Jumlah kasbon minimal 0',
|
||||
'tanggal_kasbon.required' => 'Tanggal kasbon harus diisi',
|
||||
'tanggal_kasbon.date' => 'Format tanggal kasbon tidak valid',
|
||||
'status.required' => 'Status harus dipilih',
|
||||
'status.in' => 'Status harus lunas atau belum_lunas',
|
||||
'keterangan.max' => 'Keterangan maksimal 500 karakter'
|
||||
]);
|
||||
|
||||
$validator->after(function ($validator) use ($request) {
|
||||
$jumlah = (float) $request->input('jumlah_kasbon');
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
$tanggal = $request->input('tanggal_kasbon');
|
||||
|
||||
if ($idTeknisi) {
|
||||
$hasWork = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi)
|
||||
->where('status_kehadiran', 'hadir');
|
||||
});
|
||||
})->where('status_pekerjaan', 'selesai')->exists();
|
||||
|
||||
if (!$hasWork) {
|
||||
$validator->errors()->add('id_teknisi', 'Teknisi belum menyelesaikan pekerjaan apapun. Harus menyelesaikan minimal satu pekerjaan sebelum kasbon.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($jumlah > 0 && $jumlah <= 500000) {
|
||||
// Aturan 1: Minimal Rp 200.000 untuk Kasbon Rutin
|
||||
if ($jumlah < 200000) {
|
||||
$validator->errors()->add('jumlah_kasbon', 'Jumlah kasbon rutin minimal Rp 200.000. Di atas Rp 500.000 dianggap pinjaman besar.');
|
||||
}
|
||||
|
||||
// Aturan 2: Maksimal 2 kali kasbon rutin dalam 1 minggu kalender
|
||||
if ($idTeknisi && $tanggal) {
|
||||
try {
|
||||
$date = Carbon::parse($tanggal);
|
||||
$startOfWeek = $date->copy()->startOfWeek()->toDateString();
|
||||
$endOfWeek = $date->copy()->endOfWeek()->toDateString();
|
||||
|
||||
$kasbonCount = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->where('jumlah_kasbon', '<=', 500000)
|
||||
->whereBetween('tanggal_kasbon', [$startOfWeek, $endOfWeek])
|
||||
->count();
|
||||
|
||||
if ($kasbonCount >= 2) {
|
||||
$validator->errors()->add('tanggal_kasbon', 'Teknisi ini sudah mencapai batas maksimal 2 kali kasbon rutin dalam minggu ini (Senin - Minggu).');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Let built-in date validator handle formatting errors
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ($validator->fails()) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors(),
|
||||
'message' => $validator->errors()->first()
|
||||
], 422);
|
||||
}
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $validator->validated();
|
||||
|
||||
// Map keterangan ke keperluan (database schema)
|
||||
if (isset($data['keterangan'])) {
|
||||
$data['keperluan'] = $data['keterangan'];
|
||||
unset($data['keterangan']);
|
||||
}
|
||||
|
||||
// Set default status jika tidak ada
|
||||
if (!isset($data['status'])) {
|
||||
$data['status'] = Kasbon::STATUS_BELUM_LUNAS;
|
||||
}
|
||||
|
||||
$kasbon = Kasbon::create($data);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $kasbon,
|
||||
'message' => 'Kasbon berhasil ditambahkan'
|
||||
], 201);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('success', 'Kasbon berhasil ditambahkan');
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('Kasbon Store Error', [
|
||||
'message' => $e->getMessage(),
|
||||
'data' => $request->all(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan saat menyimpan data: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', 'Terjadi kesalahan saat menyimpan data: ' . $e->getMessage())->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param Request $request
|
||||
* @return View|JsonResponse
|
||||
*/
|
||||
public function show(int $id, Request $request)
|
||||
{
|
||||
try {
|
||||
$kasbon = Kasbon::findOrFail($id);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $kasbon,
|
||||
'message' => 'Data kasbon berhasil diambil'
|
||||
]);
|
||||
}
|
||||
|
||||
return view('Admin.Gaji.show-kasbon', compact('kasbon')); // DIPERBAIKI: path view
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Kasbon tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('error', 'Kasbon tidak ditemukan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return View|RedirectResponse
|
||||
*/
|
||||
public function edit(int $id, Request $request)
|
||||
{
|
||||
try {
|
||||
$kasbon = Kasbon::with('teknisi')->findOrFail($id);
|
||||
$statusOptions = Kasbon::getStatusOptions();
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'kasbon' => $kasbon,
|
||||
'statusOptions' => $statusOptions,
|
||||
'teknisis' => $teknisis
|
||||
]);
|
||||
}
|
||||
|
||||
return view('Admin.Gaji.edit-kasbon', compact('kasbon', 'statusOptions', 'teknisis'));
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Kasbon tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
return redirect()->route('kasbon.index')->with('error', 'Kasbon tidak ditemukan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|integer|min:1',
|
||||
'jumlah_kasbon' => 'required|numeric|min:0',
|
||||
'tanggal_kasbon' => 'required|date',
|
||||
'status' => 'nullable|in:lunas,belum_lunas',
|
||||
'keterangan' => 'nullable|string|max:100'
|
||||
], [
|
||||
'id_teknisi.required' => 'ID Teknisi harus diisi',
|
||||
'id_teknisi.integer' => 'ID Teknisi harus berupa angka',
|
||||
'jumlah_kasbon.required' => 'Jumlah kasbon harus diisi',
|
||||
'jumlah_kasbon.numeric' => 'Jumlah kasbon harus berupa angka',
|
||||
'jumlah_kasbon.min' => 'Jumlah kasbon minimal 0',
|
||||
'tanggal_kasbon.required' => 'Tanggal kasbon harus diisi',
|
||||
'tanggal_kasbon.date' => 'Format tanggal kasbon tidak valid',
|
||||
'status.required' => 'Status harus dipilih',
|
||||
'status.in' => 'Status harus lunas atau belum_lunas',
|
||||
'keterangan.max' => 'Keterangan maksimal 500 karakter'
|
||||
]);
|
||||
|
||||
$validator->after(function ($validator) use ($request, $id) {
|
||||
$jumlah = (float) $request->input('jumlah_kasbon');
|
||||
$idTeknisi = $request->input('id_teknisi');
|
||||
$tanggal = $request->input('tanggal_kasbon');
|
||||
|
||||
if ($idTeknisi) {
|
||||
$hasWork = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi)
|
||||
->where('status_kehadiran', 'hadir');
|
||||
});
|
||||
})->where('status_pekerjaan', 'selesai')->exists();
|
||||
|
||||
if (!$hasWork) {
|
||||
$validator->errors()->add('id_teknisi', 'Teknisi belum menyelesaikan pekerjaan apapun. Harus menyelesaikan minimal satu pekerjaan sebelum kasbon.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($jumlah > 0 && $jumlah <= 500000) {
|
||||
// Aturan 1: Minimal Rp 200.000 untuk Kasbon Rutin
|
||||
if ($jumlah < 200000) {
|
||||
$validator->errors()->add('jumlah_kasbon', 'Jumlah kasbon rutin minimal Rp 200.000. Di atas Rp 500.000 dianggap pinjaman besar.');
|
||||
}
|
||||
|
||||
// Aturan 2: Maksimal 2 kali kasbon rutin dalam 1 minggu kalender
|
||||
if ($idTeknisi && $tanggal) {
|
||||
try {
|
||||
$date = Carbon::parse($tanggal);
|
||||
$startOfWeek = $date->copy()->startOfWeek()->toDateString();
|
||||
$endOfWeek = $date->copy()->endOfWeek()->toDateString();
|
||||
|
||||
$kasbonCount = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->where('id_kasbon', '!=', $id)
|
||||
->where('jumlah_kasbon', '<=', 500000)
|
||||
->whereBetween('tanggal_kasbon', [$startOfWeek, $endOfWeek])
|
||||
->count();
|
||||
|
||||
if ($kasbonCount >= 2) {
|
||||
$validator->errors()->add('tanggal_kasbon', 'Teknisi ini sudah mencapai batas maksimal 2 kali kasbon rutin dalam minggu ini (Senin - Minggu).');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Let built-in date validator handle formatting errors
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ($validator->fails()) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors(),
|
||||
'message' => $validator->errors()->first()
|
||||
], 422);
|
||||
}
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
$kasbon = Kasbon::findOrFail($id);
|
||||
$data = $validator->validated();
|
||||
|
||||
// Map keterangan ke keperluan
|
||||
if (isset($data['keterangan'])) {
|
||||
$data['keperluan'] = $data['keterangan'];
|
||||
unset($data['keterangan']);
|
||||
}
|
||||
|
||||
$kasbon->update($data);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $kasbon,
|
||||
'message' => 'Kasbon berhasil diupdate'
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('success', 'Kasbon berhasil diupdate');
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Kasbon tidak ditemukan atau terjadi kesalahan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('error', 'Kasbon tidak ditemukan atau terjadi kesalahan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $id)
|
||||
{
|
||||
try {
|
||||
$kasbon = Kasbon::findOrFail($id);
|
||||
$kasbon->delete();
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Kasbon berhasil dihapus'
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('success', 'Kasbon berhasil dihapus');
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Kasbon tidak ditemukan atau terjadi kesalahan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->route('kasbon.index')->with('error', 'Kasbon tidak ditemukan atau terjadi kesalahan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get kasbon statistics
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function statistics(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$totalKasbon = Kasbon::count();
|
||||
$totalJumlahKasbon = Kasbon::sum('jumlah_kasbon');
|
||||
$kasbonLunas = Kasbon::lunas()->count();
|
||||
$kasbonBelumLunas = Kasbon::belumLunas()->count();
|
||||
$totalJumlahLunas = Kasbon::lunas()->sum('jumlah_kasbon');
|
||||
$totalJumlahBelumLunas = Kasbon::belumLunas()->sum('jumlah_kasbon');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'total_kasbon' => $totalKasbon,
|
||||
'total_jumlah_kasbon' => $totalJumlahKasbon,
|
||||
'kasbon_lunas' => $kasbonLunas,
|
||||
'kasbon_belum_lunas' => $kasbonBelumLunas,
|
||||
'total_jumlah_lunas' => $totalJumlahLunas,
|
||||
'total_jumlah_belum_lunas' => $totalJumlahBelumLunas,
|
||||
],
|
||||
'message' => 'Statistik kasbon berhasil diambil'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan saat mengambil statistik'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status kasbon to lunas
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
public function markAsLunas(Request $request, int $id)
|
||||
{
|
||||
try {
|
||||
$kasbon = Kasbon::findOrFail($id);
|
||||
$kasbon->update(['status' => Kasbon::STATUS_LUNAS]);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $kasbon,
|
||||
'message' => 'Kasbon berhasil diubah menjadi lunas'
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Kasbon berhasil diubah menjadi lunas');
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Kasbon tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', 'Kasbon tidak ditemukan');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class KelolaAdminController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan daftar semua akun admin.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$admins = User::orderBy('created_at', 'asc')->get();
|
||||
return view('Admin.KelolaAdmin.index', compact('admins'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan akun admin baru ke database.
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:users,email'],
|
||||
'password' => ['required', 'string', 'min:8'],
|
||||
], [
|
||||
'name.required' => 'Nama wajib diisi.',
|
||||
'email.required' => 'Email wajib diisi.',
|
||||
'email.email' => 'Format email tidak valid.',
|
||||
'email.unique' => 'Email sudah terdaftar.',
|
||||
'password.required' => 'Password wajib diisi.',
|
||||
'password.min' => 'Password minimal 8 karakter.',
|
||||
]);
|
||||
|
||||
try {
|
||||
$admin = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun admin berhasil dibuat!',
|
||||
'data' => $admin,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal membuat akun admin: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan detail akun admin tertentu (JSON).
|
||||
*/
|
||||
public function show(string $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$admin = User::findOrFail($id);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $admin,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Akun admin tidak ditemukan.',
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil data akun admin untuk form edit (JSON).
|
||||
*/
|
||||
public function edit(string $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$admin = User::findOrFail($id);
|
||||
return response()->json($admin);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Akun admin tidak ditemukan.',
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update akun admin di database.
|
||||
*/
|
||||
public function update(Request $request, string $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$admin = User::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', "unique:users,email,{$id}"],
|
||||
'password' => ['nullable', 'string', 'min:8'],
|
||||
], [
|
||||
'name.required' => 'Nama wajib diisi.',
|
||||
'email.required' => 'Email wajib diisi.',
|
||||
'email.email' => 'Format email tidak valid.',
|
||||
'email.unique' => 'Email sudah digunakan oleh akun lain.',
|
||||
'password.min' => 'Password minimal 8 karakter.',
|
||||
]);
|
||||
|
||||
$updateData = [
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
];
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$updateData['password'] = Hash::make($request->password);
|
||||
}
|
||||
|
||||
$admin->update($updateData);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun admin berhasil diperbarui!',
|
||||
]);
|
||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $e->errors(),
|
||||
], 422);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal memperbarui akun admin: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus akun admin dari database.
|
||||
*/
|
||||
public function destroy(string $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
// Tidak boleh menghapus akun sendiri
|
||||
if ((string) Auth::id() === $id) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak dapat menghapus akun Anda sendiri.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$admin = User::findOrFail($id);
|
||||
$admin->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Akun admin berhasil dihapus!',
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghapus akun admin: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,339 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Laporan;
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
|
||||
class LaporanController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the main report dashboard (Ringkasan)
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$statistics = Laporan::getStatistics();
|
||||
|
||||
// Ambil data terbaru dari semua jenis untuk ringkasan
|
||||
$recentKasbon = DB::table('kasbons')
|
||||
->leftJoin('teknisis', 'kasbons.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('kasbons.*', 'teknisis.nama as nama_teknisi')
|
||||
->orderBy('kasbons.created_at', 'desc')
|
||||
->limit(5)->get();
|
||||
|
||||
$recentAbsensi = DB::table('absensis')
|
||||
->leftJoin('teknisis', 'absensis.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('absensis.*', 'teknisis.nama as nama_teknisi')
|
||||
->orderBy('absensis.tanggal', 'desc')
|
||||
->limit(5)->get();
|
||||
|
||||
$recentPekerjaan = DB::table('penugasans')
|
||||
->leftJoin('teknisis', 'penugasans.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('penugasans.*', 'teknisis.nama as nama_teknisi')
|
||||
->orderBy('penugasans.created_at', 'desc')
|
||||
->limit(5)->get();
|
||||
|
||||
return view('Admin.Laporan', compact(
|
||||
'statistics', 'recentKasbon', 'recentAbsensi', 'recentPekerjaan'
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
\Log::error('Laporan Error: ' . $e->getMessage());
|
||||
return back()->with('error', 'Gagal memuat laporan: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics for AJAX refresh
|
||||
*/
|
||||
public function statistics()
|
||||
{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => Laporan::getStatistics()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Kasbon Report
|
||||
*/
|
||||
public function kasbon(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search']);
|
||||
$data = Laporan::getKasbonData($filters)->paginate(15)->appends($filters);
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
// Statistik ringkas kasbon
|
||||
$statsKasbon = [
|
||||
'total' => DB::table('kasbons')->count(),
|
||||
'lunas' => DB::table('kasbons')->where('status', 'lunas')->count(),
|
||||
'belum_lunas' => DB::table('kasbons')->where('status', 'belum_lunas')->count(),
|
||||
'total_nominal' => DB::table('kasbons')->sum('jumlah_kasbon'),
|
||||
'total_belum_lunas' => DB::table('kasbons')->where('status', 'belum_lunas')->sum('jumlah_kasbon'),
|
||||
];
|
||||
|
||||
return view('Admin.Laporan.kasbon', compact('data', 'teknisis', 'filters', 'statsKasbon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Teknisi/Kehadiran Report
|
||||
*/
|
||||
public function teknisi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'search']);
|
||||
$data = Laporan::getTeknisiData($filters)->get();
|
||||
return view('Admin.Laporan.teknisi', compact('data', 'filters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Absensi Report
|
||||
*/
|
||||
public function absensi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search', 'tanggal']);
|
||||
if (!empty($filters['tanggal'])) {
|
||||
$filters['tanggal_dari'] = $filters['tanggal'];
|
||||
$filters['tanggal_sampai'] = $filters['tanggal'];
|
||||
}
|
||||
$data = Laporan::getAbsensiData($filters)->paginate(15)->appends($filters);
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
// Statistik absensi bulan ini
|
||||
$statsAbsensi = [
|
||||
'hadir' => DB::table('absensis')->where('status', 'hadir')->whereMonth('tanggal', date('m'))->whereYear('tanggal', date('Y'))->count(),
|
||||
'izin' => DB::table('absensis')->where('status', 'izin')->whereMonth('tanggal', date('m'))->whereYear('tanggal', date('Y'))->count(),
|
||||
'sakit' => DB::table('absensis')->where('status', 'sakit')->whereMonth('tanggal', date('m'))->whereYear('tanggal', date('Y'))->count(),
|
||||
'alpha' => DB::table('absensis')->where('status', 'alpha')->whereMonth('tanggal', date('m'))->whereYear('tanggal', date('Y'))->count(),
|
||||
];
|
||||
|
||||
return view('Admin.Laporan.absensi', compact('data', 'teknisis', 'filters', 'statsAbsensi'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Pekerjaan Report
|
||||
*/
|
||||
public function pekerjaan(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search', 'tanggal']);
|
||||
if (!empty($filters['tanggal'])) {
|
||||
$filters['tanggal_dari'] = $filters['tanggal'];
|
||||
$filters['tanggal_sampai'] = $filters['tanggal'];
|
||||
}
|
||||
$data = Laporan::getPekerjaanData($filters)->paginate(15)->appends($filters);
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
$statsPekerjaan = [
|
||||
'total' => DB::table('penugasans')->count(),
|
||||
'selesai' => DB::table('penugasans')->where('status_pekerjaan', 'selesai')->count(),
|
||||
'proses' => DB::table('penugasans')->where('status_pekerjaan', 'proses')->count(),
|
||||
'pending' => DB::table('penugasans')->where('status_pekerjaan', 'pending')->count(),
|
||||
];
|
||||
|
||||
return view('Admin.Laporan.pekerjaan', compact('data', 'teknisis', 'filters', 'statsPekerjaan'));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// LAPORAN PENGGAJIAN & DATA TEKNISI
|
||||
// ============================================================
|
||||
|
||||
public function penggajian(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search', 'tanggal']);
|
||||
if (!empty($filters['tanggal'])) {
|
||||
$filters['tanggal_dari'] = $filters['tanggal'];
|
||||
$filters['tanggal_sampai'] = $filters['tanggal'];
|
||||
}
|
||||
|
||||
$query = DB::table('penggajians')
|
||||
->leftJoin('teknisis', 'penggajians.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('penggajians.*', 'teknisis.nama as nama_teknisi')
|
||||
->orderBy('penggajians.created_at', 'desc');
|
||||
|
||||
if (!empty($filters['id_teknisi'])) {
|
||||
$query->where('penggajians.id_teknisi', $filters['id_teknisi']);
|
||||
}
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('penggajians.status_pembayaran', $filters['status']);
|
||||
}
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$query->whereDate('penggajians.created_at', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$query->whereDate('penggajians.created_at', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
|
||||
$data = $query->paginate(15)->appends($filters);
|
||||
$teknisis = Teknisi::orderBy('nama')->get();
|
||||
|
||||
$statsPenggajian = [
|
||||
'total' => DB::table('penggajians')->count(),
|
||||
'lunas' => DB::table('penggajians')->where('status_pembayaran', 'lunas')->count(),
|
||||
'belum' => DB::table('penggajians')->where('status_pembayaran', 'belum_bayar')->count(),
|
||||
];
|
||||
|
||||
return view('Admin.Laporan.penggajian', compact('data', 'teknisis', 'filters', 'statsPenggajian'));
|
||||
}
|
||||
|
||||
public function dataTeknisi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['status', 'search']);
|
||||
$query = Teknisi::query();
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('nama', 'like', '%'.$filters['search'].'%');
|
||||
}
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
$data = $query->paginate(15)->appends($filters);
|
||||
|
||||
$statsTeknisi = [
|
||||
'total' => Teknisi::count(),
|
||||
'aktif' => Teknisi::where('status', 'aktif')->count(),
|
||||
'nonaktif' => Teknisi::where('status', 'nonaktif')->count(),
|
||||
];
|
||||
|
||||
return view('Admin.Laporan.data_teknisi', compact('data', 'filters', 'statsTeknisi'));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// CETAK LAPORAN (PRINT) METHODS
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* Cetak Laporan Kasbon
|
||||
*/
|
||||
public function exportKasbon(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search']);
|
||||
$data = Laporan::getKasbonData($filters)->get();
|
||||
$title = 'Kasbon Teknisi';
|
||||
$type = 'kasbon';
|
||||
$columns = ['Nama Teknisi', 'Tanggal Pinjam', 'Jumlah Kasbon', 'Status', 'Keperluan'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cetak Laporan Teknisi/Kehadiran
|
||||
*/
|
||||
public function exportTeknisi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'search']);
|
||||
$data = Laporan::getTeknisiData($filters)->get();
|
||||
$title = 'Performa & Kehadiran Teknisi';
|
||||
$type = 'teknisi';
|
||||
$columns = ['Nama Teknisi', 'Status', 'Hadir', 'Izin', 'Sakit', 'Alpha', 'Total Hari', 'Persentase'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cetak Laporan Absensi
|
||||
*/
|
||||
public function exportAbsensi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search']);
|
||||
$data = Laporan::getAbsensiData($filters)->get();
|
||||
$title = 'Absensi Harian';
|
||||
$type = 'absensi';
|
||||
$columns = ['Nama Teknisi', 'Tanggal', 'Status Kehadiran', 'Keterangan'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cetak Laporan Pekerjaan
|
||||
*/
|
||||
public function exportPekerjaan(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search']);
|
||||
$data = Laporan::getPekerjaanData($filters)->get();
|
||||
$title = 'Pekerjaan Teknisi';
|
||||
$type = 'pekerjaan';
|
||||
$columns = ['ID', 'Jenis Pekerjaan', 'Nama Teknisi', 'Status', 'Tgl Mulai', 'Tgl Selesai'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cetak Laporan Penggajian
|
||||
*/
|
||||
public function exportPenggajian(Request $request)
|
||||
{
|
||||
$filters = $request->only(['tanggal_dari', 'tanggal_sampai', 'status', 'id_teknisi', 'search', 'tanggal']);
|
||||
if (!empty($filters['tanggal'])) {
|
||||
$filters['tanggal_dari'] = $filters['tanggal'];
|
||||
$filters['tanggal_sampai'] = $filters['tanggal'];
|
||||
}
|
||||
|
||||
$query = DB::table('penggajians')
|
||||
->leftJoin('teknisis', 'penggajians.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select('penggajians.*', 'teknisis.nama as nama_teknisi')
|
||||
->orderBy('penggajians.created_at', 'desc');
|
||||
|
||||
if (!empty($filters['id_teknisi'])) {
|
||||
$query->where('penggajians.id_teknisi', $filters['id_teknisi']);
|
||||
}
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('penggajians.status_pembayaran', $filters['status']);
|
||||
}
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$query->whereDate('penggajians.created_at', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$query->whereDate('penggajians.created_at', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
|
||||
$data = $query->get();
|
||||
$title = 'Laporan Penggajian';
|
||||
$type = 'penggajian';
|
||||
$columns = ['Nama Teknisi', 'Periode', 'Total Gaji', 'Status Pembayaran'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cetak Laporan Data Teknisi
|
||||
*/
|
||||
public function exportDataTeknisi(Request $request)
|
||||
{
|
||||
$filters = $request->only(['status', 'search']);
|
||||
$query = Teknisi::query();
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('nama', 'like', '%'.$filters['search'].'%');
|
||||
}
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
|
||||
$data = $query->get();
|
||||
$title = 'Data Teknisi';
|
||||
$type = 'data_teknisi';
|
||||
$columns = ['Nama Teknisi', 'Email', 'No Telepon', 'Tanggal Masuk', 'Status'];
|
||||
|
||||
return view('Admin.Laporan.print', compact('data', 'filters', 'title', 'type', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic export (from Ringkasan page)
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
$jenis = $request->get('jenis_laporan', 'kasbon');
|
||||
|
||||
switch ($jenis) {
|
||||
case 'kasbon': return $this->exportKasbon($request);
|
||||
case 'teknisi': return $this->exportTeknisi($request);
|
||||
case 'absensi': return $this->exportAbsensi($request);
|
||||
case 'pekerjaan': return $this->exportPekerjaan($request);
|
||||
case 'penggajian': return $this->exportPenggajian($request);
|
||||
case 'data_teknisi': return $this->exportDataTeknisi($request);
|
||||
default: return back()->with('error', 'Jenis laporan tidak valid.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,907 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Penggajian;
|
||||
use App\Models\DetailPenggajian;
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\TarifPekerjaan;
|
||||
use App\Models\Absensi;
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\Kasbon;
|
||||
use App\Exports\PenggajianExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PenggajianController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Penggajian::with(['teknisi'])
|
||||
->latest('periode_tahun')
|
||||
->latest('periode_bulan');
|
||||
|
||||
if ($request->filled('periode_bulan')) {
|
||||
$query->where('periode_bulan', $request->periode_bulan);
|
||||
}
|
||||
if ($request->filled('periode_tahun')) {
|
||||
$query->where('periode_tahun', $request->periode_tahun);
|
||||
}
|
||||
if ($request->filled('status_pembayaran')) {
|
||||
$query->where('status_pembayaran', $request->status_pembayaran);
|
||||
}
|
||||
if ($request->filled('id_teknisi')) {
|
||||
$query->where('id_teknisi', $request->id_teknisi);
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
$penggajians = $query->get();
|
||||
$rows = $penggajians->map(function ($g) {
|
||||
return [
|
||||
'id_penggajian' => $g->id_penggajian,
|
||||
'nama_teknisi' => $g->teknisi->nama ?? 'N/A',
|
||||
'periode_label' => Carbon::create()->month($g->periode_bulan)->format('M') . ' ' . $g->periode_tahun,
|
||||
'tanggal_penggajian' => $g->tanggal_penggajian->format('d/m/Y'),
|
||||
'jumlah_hari_kerja' => $g->jumlah_hari_kerja,
|
||||
'total_ongkos_pekerjaan' => $g->total_ongkos_pekerjaan,
|
||||
'biaya_makan' => $g->biaya_makan,
|
||||
'total_kasbon' => $g->total_kasbon,
|
||||
'gaji_bersih' => $g->gaji_bersih,
|
||||
'status_pembayaran' => $g->status_pembayaran,
|
||||
];
|
||||
});
|
||||
$summary = $penggajians->count() > 0 ? [
|
||||
'total_teknisi' => $penggajians->count(),
|
||||
'total_gaji' => $penggajians->sum('total_ongkos_pekerjaan'),
|
||||
'total_kasbon' => $penggajians->sum('total_kasbon') + $penggajians->sum('biaya_makan'),
|
||||
'gaji_bersih' => $penggajians->sum('gaji_bersih'),
|
||||
] : null;
|
||||
return response()->json(['rows' => $rows, 'summary' => $summary]);
|
||||
}
|
||||
|
||||
$teknisiList = Teknisi::where('status', 'aktif')->orderBy('nama')->get();
|
||||
return view('Admin.Gaji.Penggajian', compact('teknisiList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$teknisis = Teknisi::where('status', 'aktif')->get();
|
||||
$tarifs = TarifPekerjaan::where('is_active', true)->get();
|
||||
return view('admin.penggajian.create', compact('teknisis', 'tarifs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'required|exists:teknisis,id_teknisi',
|
||||
'periode_bulan' => 'required|integer|between:1,12',
|
||||
'periode_tahun' => 'required|integer|min:2020|max:' . (date('Y') + 1),
|
||||
'tanggal_penggajian' => 'required|date',
|
||||
'biaya_makan' => 'nullable|numeric|min:0',
|
||||
'total_kasbon' => 'nullable|numeric|min:0',
|
||||
'details' => 'required|array|min:1',
|
||||
'details.*.id_tarif' => 'required|exists:tarif_pekerjaans,id_tarif',
|
||||
'details.*.jumlah_unit' => 'required|integer|min:1',
|
||||
'details.*.tarif_per_unit' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
$exists = Penggajian::isPeriodeExists(
|
||||
$request->id_teknisi,
|
||||
$request->periode_bulan,
|
||||
$request->periode_tahun
|
||||
);
|
||||
|
||||
if ($exists) {
|
||||
return back()->withErrors([
|
||||
'periode' => 'Penggajian untuk teknisi ini pada periode tersebut sudah ada.'
|
||||
])->withInput();
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$gaji_kotor = 0;
|
||||
foreach ($request->details as $detail) {
|
||||
$gaji_kotor += $detail['jumlah_unit'] * $detail['tarif_per_unit'];
|
||||
}
|
||||
|
||||
$penggajian = Penggajian::create([
|
||||
'id_teknisi' => $request->id_teknisi,
|
||||
'periode_bulan' => $request->periode_bulan,
|
||||
'periode_tahun' => $request->periode_tahun,
|
||||
'tanggal_penggajian' => $request->tanggal_penggajian,
|
||||
'jumlah_hari_kerja' => $this->calculateHariKerja(
|
||||
$request->id_teknisi,
|
||||
$request->periode_bulan,
|
||||
$request->periode_tahun
|
||||
),
|
||||
'gaji_kotor' => $gaji_kotor,
|
||||
'biaya_makan' => $request->biaya_makan ?? 0,
|
||||
'total_kasbon' => $request->total_kasbon ?? 0,
|
||||
'total_potongan' => $request->total_kasbon ?? 0,
|
||||
'status_pembayaran' => Penggajian::STATUS_BELUM_BAYAR,
|
||||
]);
|
||||
|
||||
foreach ($request->details as $detail) {
|
||||
DetailPenggajian::create([
|
||||
'id_penggajian' => $penggajian->id_penggajian,
|
||||
'id_teknisi' => $request->id_teknisi,
|
||||
'id_tarif' => $detail['id_tarif'],
|
||||
'jumlah_unit' => $detail['jumlah_unit'],
|
||||
'tarif_per_unit' => $detail['tarif_per_unit'],
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return redirect()->route('penggajian.index')
|
||||
->with('success', 'Data penggajian berhasil dibuat.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return back()->withErrors(['error' => 'Gagal menyimpan data penggajian.'])->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Penggajian $penggajian)
|
||||
{
|
||||
$penggajian->load(['teknisi', 'detailPenggajian.penugasan']);
|
||||
return view('admin.penggajian.show', compact('penggajian'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Penggajian $penggajian)
|
||||
{
|
||||
$penggajian->load(['teknisi', 'detailPenggajian.penugasan']);
|
||||
$teknisis = Teknisi::where('status', 'aktif')->get();
|
||||
$tarifs = TarifPekerjaan::where('is_active', true)->get();
|
||||
return view('admin.penggajian.edit', compact('penggajian', 'teknisis', 'tarifs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Penggajian $penggajian)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'tanggal_penggajian' => 'required|date',
|
||||
'biaya_makan' => 'nullable|numeric|min:0',
|
||||
'total_kasbon' => 'nullable|numeric|min:0',
|
||||
'details' => 'required|array|min:1',
|
||||
'details.*.id_tarif' => 'required|exists:tarif_pekerjaans,id_tarif',
|
||||
'details.*.jumlah_unit' => 'required|integer|min:1',
|
||||
'details.*.tarif_per_unit' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$gaji_kotor = 0;
|
||||
foreach ($request->details as $detail) {
|
||||
$gaji_kotor += $detail['jumlah_unit'] * $detail['tarif_per_unit'];
|
||||
}
|
||||
|
||||
$penggajian->update([
|
||||
'tanggal_penggajian' => $request->tanggal_penggajian,
|
||||
'total_ongkos_pekerjaan' => $gaji_kotor,
|
||||
'biaya_makan' => $request->biaya_makan ?? 0,
|
||||
'total_kasbon' => $request->total_kasbon ?? 0,
|
||||
'total_potongan' => $request->total_kasbon ?? 0,
|
||||
]);
|
||||
|
||||
$penggajian->detailPenggajian()->delete();
|
||||
|
||||
$gajiData = $this->calculateGajiTeknisi(
|
||||
$penggajian->id_teknisi,
|
||||
$penggajian->periode_bulan,
|
||||
$penggajian->periode_tahun,
|
||||
$penggajian->tanggal_penggajian
|
||||
);
|
||||
|
||||
foreach ($gajiData['details'] as $detail) {
|
||||
DetailPenggajian::create([
|
||||
'id_penggajian' => $penggajian->id_penggajian,
|
||||
'id_penugasan' => $detail['id_penugasan'],
|
||||
'tanggal_selesai' => $detail['tanggal_selesai'],
|
||||
'lokasi' => $detail['lokasi'],
|
||||
'ongkos_penugasan' => $detail['ongkos_penugasan'],
|
||||
'jumlah_tim' => $detail['jumlah_tim'],
|
||||
'bagian_ongkos' => $detail['bagian_ongkos'],
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return redirect()->route('penggajian.index')
|
||||
->with('success', 'Data penggajian berhasil diperbarui.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return back()->withErrors(['error' => 'Gagal memperbarui data penggajian.'])->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Penggajian $penggajian)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$penggajian->detailPenggajian()->delete();
|
||||
$penggajian->delete();
|
||||
DB::commit();
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Data penggajian berhasil dihapus.']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return response()->json(['success' => false, 'message' => 'Gagal menghapus data penggajian.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung gaji untuk periode tertentu.
|
||||
*
|
||||
* Tambahan parameter:
|
||||
* force_recalculate (boolean, default false)
|
||||
* → Jika true, data penggajian yang sudah ada akan dihapus dan dihitung ulang.
|
||||
* Gunakan ini ketika ada penugasan baru yang selesai SETELAH gaji di-generate,
|
||||
* sehingga semua anggota tim (termasuk yang tidak jadi teknisi utama) ikut terhitung.
|
||||
* → Jika false (default), teknisi yang sudah punya data di periode itu akan di-skip.
|
||||
*
|
||||
* CATATAN: Penggajian yang sudah berstatus 'sudah_bayar' TIDAK akan di-recalculate
|
||||
* meski force_recalculate = true, untuk mencegah perubahan data yang sudah dibayar.
|
||||
*/
|
||||
public function hitungGaji(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_teknisi' => 'nullable|exists:teknisis,id_teknisi',
|
||||
'periode_bulan' => 'required|integer|between:1,12',
|
||||
'periode_tahun' => 'required|integer|min:2020|max:' . (date('Y') + 1),
|
||||
'tanggal_penggajian' => 'required|date',
|
||||
'include_kasbon' => 'boolean',
|
||||
'force_recalculate' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data tidak valid. ' . implode(' ', $validator->errors()->all()),
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$periode_bulan = $request->periode_bulan;
|
||||
$periode_tahun = $request->periode_tahun;
|
||||
$tanggal_penggajian = $request->tanggal_penggajian
|
||||
?? Carbon::create($periode_tahun, $periode_bulan)->endOfMonth()->format('Y-m-d');
|
||||
$include_kasbon = $request->boolean('include_kasbon', true);
|
||||
$force_recalculate = $request->boolean('force_recalculate', false);
|
||||
$id_teknisi = $request->id_teknisi;
|
||||
|
||||
if ($id_teknisi) {
|
||||
$teknisis = Teknisi::where('id_teknisi', $id_teknisi)->where('status', 'aktif')->get();
|
||||
} else {
|
||||
$teknisis = Teknisi::where('status', 'aktif')->get();
|
||||
}
|
||||
|
||||
$created_count = 0;
|
||||
$skipped_count = 0;
|
||||
$recalculated_count = 0;
|
||||
|
||||
foreach ($teknisis as $teknisi) {
|
||||
// Cek apakah sudah ada penggajian untuk periode ini
|
||||
$existingPenggajian = Penggajian::where('id_teknisi', $teknisi->id_teknisi)
|
||||
->where('periode_bulan', $periode_bulan)
|
||||
->where('periode_tahun', $periode_tahun)
|
||||
->first();
|
||||
|
||||
if ($existingPenggajian) {
|
||||
if (!$force_recalculate) {
|
||||
// Tidak force → skip seperti perilaku lama
|
||||
$skipped_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sudah dibayar → jangan recalculate, lindungi data yang sudah final
|
||||
if ($existingPenggajian->status_pembayaran === Penggajian::STATUS_SUDAH_BAYAR) {
|
||||
$skipped_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Force recalculate → hapus detail dan penggajian lama, hitung ulang
|
||||
$existingPenggajian->detailPenggajian()->delete();
|
||||
$existingPenggajian->delete();
|
||||
$recalculated_count++;
|
||||
}
|
||||
|
||||
$gajiData = $this->calculateGajiTeknisi(
|
||||
$teknisi->id_teknisi,
|
||||
$periode_bulan,
|
||||
$periode_tahun,
|
||||
$tanggal_penggajian,
|
||||
$include_kasbon
|
||||
);
|
||||
|
||||
if ($gajiData['gaji_kotor'] > 0 || $gajiData['biaya_makan'] > 0 || !empty($gajiData['details'])) {
|
||||
$total_penugasan = !empty($gajiData['details']) ? count($gajiData['details']) : 0;
|
||||
|
||||
$penggajian = Penggajian::create([
|
||||
'id_teknisi' => $teknisi->id_teknisi,
|
||||
'periode_bulan' => $periode_bulan,
|
||||
'periode_tahun' => $periode_tahun,
|
||||
'tanggal_penggajian' => $tanggal_penggajian,
|
||||
'jumlah_hari_kerja' => $gajiData['jumlah_hari_kerja'],
|
||||
'jumlah_penugasan_selesai' => $total_penugasan,
|
||||
'total_ongkos_pekerjaan' => $gajiData['gaji_kotor'],
|
||||
'biaya_makan' => $gajiData['biaya_makan'],
|
||||
'total_kasbon' => $gajiData['total_kasbon'],
|
||||
'total_potongan' => $gajiData['total_kasbon'],
|
||||
'gaji_bersih' => $gajiData['gaji_kotor'] - $gajiData['biaya_makan'] - $gajiData['total_kasbon'],
|
||||
'status_pembayaran' => Penggajian::STATUS_BELUM_BAYAR,
|
||||
]);
|
||||
|
||||
foreach ($gajiData['details'] as $detail) {
|
||||
DetailPenggajian::create([
|
||||
'id_penggajian' => $penggajian->id_penggajian,
|
||||
'id_penugasan' => $detail['id_penugasan'],
|
||||
'tanggal_selesai' => $detail['tanggal_selesai'],
|
||||
'lokasi' => $detail['lokasi'],
|
||||
'ongkos_penugasan' => $detail['ongkos_penugasan'],
|
||||
'jumlah_tim' => $detail['jumlah_tim'],
|
||||
'bagian_ongkos' => $detail['bagian_ongkos'],
|
||||
'rincian_pekerjaan'=> $detail['rincian_pekerjaan'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
$created_count++;
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
$message = "Berhasil menghitung gaji untuk {$created_count} teknisi.";
|
||||
if ($recalculated_count > 0) {
|
||||
$message .= " {$recalculated_count} teknisi dihitung ulang.";
|
||||
}
|
||||
if ($skipped_count > 0) {
|
||||
$message .= " {$skipped_count} teknisi dilewati (sudah ada data atau sudah dibayar).";
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'data' => [
|
||||
'created' => $created_count,
|
||||
'recalculated' => $recalculated_count,
|
||||
'skipped' => $skipped_count,
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghitung gaji: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung ulang penggajian untuk satu teknisi tertentu.
|
||||
*
|
||||
* Endpoint: POST /penggajian/{penggajian}/recalculate
|
||||
*
|
||||
* Berguna ketika:
|
||||
* - Ada penugasan tim yang baru selesai setelah gaji di-generate
|
||||
* - Anggota tim yang tidak jadi teknisi utama tidak muncul di rincian
|
||||
* - Data detail penggajian tidak lengkap / tidak sesuai
|
||||
*
|
||||
* Penggajian yang sudah 'sudah_bayar' tidak bisa di-recalculate.
|
||||
*/
|
||||
public function recalculate(Penggajian $penggajian)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// Hapus detail lama
|
||||
$penggajian->detailPenggajian()->delete();
|
||||
|
||||
// Jika sudah lunas, kita tidak ingin menarik data kasbon baru dari database
|
||||
// karena kasbon aslinya mungkin sudah berstatus lunas.
|
||||
// Kita gunakan nilai total_kasbon yang sudah tersimpan di record ini.
|
||||
$isPaid = $penggajian->status_pembayaran === Penggajian::STATUS_SUDAH_BAYAR;
|
||||
|
||||
$gajiData = $this->calculateGajiTeknisi(
|
||||
$penggajian->id_teknisi,
|
||||
$penggajian->periode_bulan,
|
||||
$penggajian->periode_tahun,
|
||||
$penggajian->tanggal_penggajian,
|
||||
!$isPaid // includeKasbon hanya jika belum bayar
|
||||
);
|
||||
|
||||
$total_penugasan = count($gajiData['details']);
|
||||
|
||||
// Update header penggajian
|
||||
$penggajian->update([
|
||||
'jumlah_hari_kerja' => $gajiData['jumlah_hari_kerja'],
|
||||
'jumlah_penugasan_selesai' => $total_penugasan,
|
||||
'total_ongkos_pekerjaan' => $gajiData['gaji_kotor'],
|
||||
'biaya_makan' => $gajiData['biaya_makan'],
|
||||
'total_kasbon' => $isPaid ? $penggajian->total_kasbon : $gajiData['total_kasbon'],
|
||||
'total_potongan' => $isPaid ? $penggajian->total_kasbon : $gajiData['total_kasbon'],
|
||||
'gaji_bersih' => $gajiData['gaji_kotor'] - $gajiData['biaya_makan'] - ($isPaid ? $penggajian->total_kasbon : $gajiData['total_kasbon']),
|
||||
]);
|
||||
|
||||
// Insert detail baru
|
||||
foreach ($gajiData['details'] as $detail) {
|
||||
DetailPenggajian::create([
|
||||
'id_penggajian' => $penggajian->id_penggajian,
|
||||
'id_penugasan' => $detail['id_penugasan'],
|
||||
'tanggal_selesai' => $detail['tanggal_selesai'],
|
||||
'lokasi' => $detail['lokasi'],
|
||||
'ongkos_penugasan' => $detail['ongkos_penugasan'],
|
||||
'jumlah_tim' => $detail['jumlah_tim'],
|
||||
'bagian_ongkos' => $detail['bagian_ongkos'],
|
||||
'rincian_pekerjaan'=> $detail['rincian_pekerjaan'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "Penggajian berhasil dihitung ulang. Ditemukan {$total_penugasan} penugasan.",
|
||||
'data' => [
|
||||
'total_penugasan' => $total_penugasan,
|
||||
'total_ongkos' => $gajiData['gaji_kotor'],
|
||||
'jumlah_hari_kerja' => $gajiData['jumlah_hari_kerja'],
|
||||
'biaya_makan' => $gajiData['biaya_makan'],
|
||||
'total_kasbon' => $gajiData['total_kasbon'],
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghitung ulang: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detail penggajian for modal
|
||||
*/
|
||||
public function detail(Penggajian $penggajian)
|
||||
{
|
||||
$penggajian->load(['teknisi', 'detailPenggajian.penugasan']);
|
||||
return view('Admin.Gaji.detail_penggajian', compact('penggajian'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process payment for specific penggajian
|
||||
*/
|
||||
public function prosesPembayaran(Penggajian $penggajian)
|
||||
{
|
||||
try {
|
||||
if ($penggajian->isPaid()) {
|
||||
return response()->json(['success' => false, 'message' => 'Gaji sudah dibayar sebelumnya.']);
|
||||
}
|
||||
|
||||
$penggajian->markAsPaid();
|
||||
|
||||
// ── LOGIKA PELUNASAN KASBON (DENGAN SISTEM CICILAN/PARTIAL) ──
|
||||
$sisaPotongan = (float) $penggajian->total_kasbon;
|
||||
|
||||
if ($sisaPotongan > 0) {
|
||||
// Ambil semua kasbon belum lunas, urutkan dari yang paling lama
|
||||
$kasbons = Kasbon::where('id_teknisi', $penggajian->id_teknisi)
|
||||
->where('status', 'belum_lunas')
|
||||
->whereDate('tanggal_kasbon', '<=', $penggajian->tanggal_penggajian)
|
||||
->orderBy('tanggal_kasbon', 'asc')
|
||||
->get();
|
||||
|
||||
foreach ($kasbons as $kb) {
|
||||
if ($sisaPotongan <= 0) break;
|
||||
|
||||
$jumlahKb = (float) $kb->jumlah_kasbon;
|
||||
|
||||
if ($sisaPotongan >= $jumlahKb) {
|
||||
// Kasbon ini terbayar penuh
|
||||
$kb->update(['status' => 'lunas']);
|
||||
$sisaPotongan -= $jumlahKb;
|
||||
} else {
|
||||
// Kasbon ini terbayar sebagian (CICILAN)
|
||||
// 1. Kurangi nilai kasbon lama
|
||||
$kb->update([
|
||||
'jumlah_kasbon' => $jumlahKb - $sisaPotongan
|
||||
]);
|
||||
|
||||
// 2. Buat record baru untuk bagian yang sudah lunas (untuk histori)
|
||||
$newLunas = $kb->replicate();
|
||||
$newLunas->jumlah_kasbon = $sisaPotongan;
|
||||
$newLunas->status = 'lunas';
|
||||
$newLunas->keperluan = $kb->keperluan . ' (Cicilan via Gaji ' . $penggajian->formatted_periode . ')';
|
||||
$newLunas->save();
|
||||
|
||||
$sisaPotongan = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pembayaran berhasil diproses dan kasbon telah dilunasi.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal memproses pembayaran.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateKasbon(Request $request, Penggajian $penggajian)
|
||||
{
|
||||
try {
|
||||
$rawInput = $request->input('total_kasbon', 0);
|
||||
$cleanInput = preg_replace('/[^0-9]/', '', $rawInput);
|
||||
$newKasbon = (float) $cleanInput;
|
||||
|
||||
if ($newKasbon < 0) {
|
||||
return response()->json(['success' => false, 'message' => 'Nominal kasbon tidak boleh negatif.'], 422);
|
||||
}
|
||||
|
||||
$penggajian->update([
|
||||
'total_kasbon' => $newKasbon,
|
||||
'total_potongan' => $newKasbon,
|
||||
'gaji_bersih' => $penggajian->total_ongkos_pekerjaan - $penggajian->biaya_makan - $newKasbon,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Potongan kasbon berhasil diubah menjadi Rp ' . number_format($newKasbon, 0, ',', '.') . '. Gaji bersih akan dihitung ulang otomatis.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal mengubah potongan: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update food deduction amount manually.
|
||||
* Allows mandor to waive food costs for bereavement or emergencies.
|
||||
*/
|
||||
public function updateMakan(Request $request, Penggajian $penggajian)
|
||||
{
|
||||
try {
|
||||
$rawInput = $request->input('biaya_makan', 0);
|
||||
$cleanInput = preg_replace('/[^0-9]/', '', $rawInput);
|
||||
$newMakan = (float) $cleanInput;
|
||||
|
||||
if ($newMakan < 0) {
|
||||
return response()->json(['success' => false, 'message' => 'Nominal biaya makan tidak boleh negatif.'], 422);
|
||||
}
|
||||
|
||||
$penggajian->update([
|
||||
'biaya_makan' => $newMakan,
|
||||
'gaji_bersih' => $penggajian->total_ongkos_pekerjaan - $newMakan - $penggajian->total_kasbon,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Biaya makan berhasil diubah menjadi Rp ' . number_format($newMakan, 0, ',', '.') . '.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal mengubah biaya makan: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all unpaid payments
|
||||
*/
|
||||
public function prosesSemuaPembayaran()
|
||||
{
|
||||
try {
|
||||
$unpaidCount = Penggajian::belumBayar()->count();
|
||||
|
||||
if ($unpaidCount == 0) {
|
||||
return response()->json(['success' => false, 'message' => 'Tidak ada pembayaran yang perlu diproses.']);
|
||||
}
|
||||
|
||||
Penggajian::belumBayar()->update(['status_pembayaran' => Penggajian::STATUS_SUDAH_BAYAR]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "Berhasil memproses pembayaran untuk {$unpaidCount} teknisi."
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal memproses pembayaran.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate slip gaji
|
||||
*/
|
||||
public function slip(Penggajian $penggajian)
|
||||
{
|
||||
$penggajian->load(['teknisi', 'detailPenggajian.penugasan']);
|
||||
return view('admin.Gaji.slip_penggajian', compact('penggajian'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export to Excel
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
$query = Penggajian::with(['teknisi']);
|
||||
|
||||
if ($request->filled('periode_bulan')) $query->where('periode_bulan', $request->periode_bulan);
|
||||
if ($request->filled('periode_tahun')) $query->where('periode_tahun', $request->periode_tahun);
|
||||
if ($request->filled('status_pembayaran')) $query->where('status_pembayaran', $request->status_pembayaran);
|
||||
|
||||
$penggajians = $query->get();
|
||||
return Excel::download(new PenggajianExport($penggajians), 'penggajian_' . date('Y-m-d') . '.xlsx');
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// PRIVATE HELPERS
|
||||
// =====================================================================
|
||||
|
||||
/**
|
||||
* Calculate gaji untuk teknisi tertentu.
|
||||
*
|
||||
* Mencari semua penugasan di mana teknisi ini terlibat, baik sebagai:
|
||||
* (a) Teknisi utama (kolom id_teknisi di tabel penugasans), ATAU
|
||||
* (b) Anggota tim (tabel tim_teknisi_penugasans) dengan status_kehadiran = hadir
|
||||
*
|
||||
* Ongkos dibagi rata berdasarkan jumlah anggota tim yang hadir.
|
||||
* Contoh: ongkos Rp 50.000, tim 2 orang → masing-masing Rp 25.000
|
||||
*/
|
||||
private function calculateGajiTeknisi($idTeknisi, $bulan, $tahun, $tanggalLimit = null, $includeKasbon = true)
|
||||
{
|
||||
$jumlah_hari_kerja = Absensi::where('id_teknisi', $idTeknisi)
|
||||
->whereMonth('tanggal', $bulan)
|
||||
->whereYear('tanggal', $tahun)
|
||||
->where('status', 'hadir')
|
||||
->count();
|
||||
|
||||
// Cari semua penugasan yang melibatkan teknisi ini di bulan/tahun tsb
|
||||
$penugasans = Penugasan::where(function ($q) use ($idTeknisi) {
|
||||
// (a) Teknisi utama penugasan
|
||||
$q->where('id_teknisi', $idTeknisi)
|
||||
// (b) Anggota tim yang hadir
|
||||
->orWhereHas('timTeknisi', function ($sq) use ($idTeknisi) {
|
||||
$sq->where('id_teknisi', $idTeknisi)
|
||||
->where('status_kehadiran', 'hadir');
|
||||
});
|
||||
})
|
||||
->where('status_pekerjaan', 'selesai')
|
||||
->where(function ($q) use ($bulan, $tahun) {
|
||||
// Filter berdasarkan bulan selesai
|
||||
// Prioritas: tanggal_diselesaikan, fallback ke updated_at
|
||||
$q->where(function ($q2) use ($bulan, $tahun) {
|
||||
$q2->whereNotNull('tanggal_diselesaikan')
|
||||
->whereMonth('tanggal_diselesaikan', $bulan)
|
||||
->whereYear('tanggal_diselesaikan', $tahun);
|
||||
})->orWhere(function ($q2) use ($bulan, $tahun) {
|
||||
$q2->whereNull('tanggal_diselesaikan')
|
||||
->whereMonth('updated_at', $bulan)
|
||||
->whereYear('updated_at', $tahun);
|
||||
});
|
||||
})
|
||||
->with(['items.tarif', 'timTeknisi'])
|
||||
->get();
|
||||
|
||||
$gaji_kotor = 0;
|
||||
$list_penugasan = [];
|
||||
|
||||
foreach ($penugasans as $penugasan) {
|
||||
// Hitung jumlah anggota tim yang hadir
|
||||
// Jika tidak ada record tim → teknisi kerja sendiri → jumlah = 1
|
||||
$jumlahHadir = $penugasan->countTimHadir();
|
||||
if ($jumlahHadir === 0) {
|
||||
$jumlahHadir = 1;
|
||||
}
|
||||
|
||||
// Hitung total ongkos dari penugasan_items
|
||||
$totalOngkosTugas = 0;
|
||||
if ($penugasan->items->count() > 0) {
|
||||
foreach ($penugasan->items as $item) {
|
||||
$itemTotal = (float) $item->total_nilai_pekerjaan;
|
||||
if ($itemTotal <= 0) {
|
||||
$itemTotal = $this->calculatePenugasanItemValue($item);
|
||||
}
|
||||
$totalOngkosTugas += $itemTotal;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: ambil dari total_nilai_pekerjaan penugasan induk atau tarif
|
||||
if ($totalOngkosTugas <= 0) {
|
||||
$totalOngkosTugas = $this->calculatePenugasanValue($penugasan);
|
||||
}
|
||||
|
||||
// Lewati jika ongkos masih 0 setelah semua fallback
|
||||
if ($totalOngkosTugas <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bagian ongkos = total ongkos dibagi jumlah anggota tim yang hadir
|
||||
$bagianOngkos = $totalOngkosTugas / $jumlahHadir;
|
||||
$gaji_kotor += $bagianOngkos;
|
||||
|
||||
$list_penugasan[] = [
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'tanggal_selesai' => $penugasan->tanggal_diselesaikan ?? $penugasan->tanggal_diberikan,
|
||||
'lokasi' => $penugasan->alamat_lokasi
|
||||
?? $penugasan->lokasi_pekerjaan
|
||||
?? '-',
|
||||
'ongkos_penugasan' => $totalOngkosTugas,
|
||||
'jumlah_tim' => $jumlahHadir,
|
||||
'bagian_ongkos' => $bagianOngkos,
|
||||
'rincian_pekerjaan'=> $this->generateRincianLabel($penugasan),
|
||||
];
|
||||
}
|
||||
|
||||
$biaya_makan = $jumlah_hari_kerja * 25000;
|
||||
$total_kasbon = 0;
|
||||
|
||||
if ($includeKasbon) {
|
||||
$queryKasbon = Kasbon::where('id_teknisi', $idTeknisi)
|
||||
->where('status', 'belum_lunas');
|
||||
|
||||
if ($tanggalLimit) {
|
||||
$queryKasbon->whereDate('tanggal_kasbon', '<=', $tanggalLimit);
|
||||
}
|
||||
|
||||
$total_kasbon = $queryKasbon->sum('jumlah_kasbon');
|
||||
}
|
||||
|
||||
return [
|
||||
'jumlah_hari_kerja' => $jumlah_hari_kerja,
|
||||
'gaji_kotor' => $gaji_kotor,
|
||||
'biaya_makan' => $biaya_makan,
|
||||
'total_kasbon' => $total_kasbon,
|
||||
'details' => $list_penugasan,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate hari kerja dari absensi
|
||||
*/
|
||||
private function calculateHariKerja($idTeknisi, $bulan, $tahun)
|
||||
{
|
||||
return Absensi::where('id_teknisi', $idTeknisi)
|
||||
->whereMonth('tanggal', $bulan)
|
||||
->whereYear('tanggal', $tahun)
|
||||
->where('status', 'hadir')
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate nilai penugasan dengan fallback ke tarif
|
||||
*/
|
||||
private function calculatePenugasanValue($penugasan): float
|
||||
{
|
||||
if ($penugasan->total_nilai_pekerjaan > 0) {
|
||||
return (float) $penugasan->total_nilai_pekerjaan;
|
||||
}
|
||||
|
||||
$tarif = $penugasan->tarif;
|
||||
if (!$tarif) {
|
||||
$query = TarifPekerjaan::where('jenis_pekerjaan', $penugasan->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($penugasan->dimensi_pipa) {
|
||||
$query->where('dimensi_pipa', $penugasan->dimensi_pipa);
|
||||
}
|
||||
$tarif = $query->first();
|
||||
}
|
||||
|
||||
if (!$tarif) return 0;
|
||||
|
||||
if ($penugasan->jarak_meter > 0 && $tarif->tarif_per_meter) {
|
||||
return (float) $tarif->tarif_per_meter * (float) $penugasan->jarak_meter;
|
||||
}
|
||||
if ($penugasan->jumlah_unit > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_unit;
|
||||
}
|
||||
if ($penugasan->jumlah_titik > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $penugasan->jumlah_titik;
|
||||
}
|
||||
|
||||
return (float) ($tarif->tarif_per_unit ?? $tarif->tarif_per_meter ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate label rincian pekerjaan untuk slip gaji
|
||||
*/
|
||||
private function generateRincianLabel($penugasan): string
|
||||
{
|
||||
$rincian = [];
|
||||
|
||||
if ($penugasan->items && $penugasan->items->count() > 0) {
|
||||
foreach ($penugasan->items as $item) {
|
||||
$detail = $item->jenis_pekerjaan;
|
||||
if ($item->jarak_meter > 0) {
|
||||
$detail .= " ({$item->jarak_meter}m)";
|
||||
} elseif ($item->jumlah_unit > 0) {
|
||||
$detail .= " ({$item->jumlah_unit} Unit)";
|
||||
} elseif ($item->jumlah_titik > 0) {
|
||||
$detail .= " ({$item->jumlah_titik} Titik)";
|
||||
}
|
||||
$rincian[] = $detail;
|
||||
}
|
||||
} else {
|
||||
// Legacy: penugasan belum punya penugasan_items
|
||||
if ($penugasan->jarak_meter > 0) {
|
||||
$rincian[] = "{$penugasan->jarak_meter} Meter";
|
||||
} elseif ($penugasan->jumlah_unit > 0) {
|
||||
$rincian[] = "{$penugasan->jumlah_unit} Unit";
|
||||
} else {
|
||||
$rincian[] = "Borongan";
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $rincian);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate nilai untuk setiap PenugasanItem
|
||||
*/
|
||||
private function calculatePenugasanItemValue($item): float
|
||||
{
|
||||
if ($item->total_nilai_pekerjaan > 0) {
|
||||
return (float) $item->total_nilai_pekerjaan;
|
||||
}
|
||||
|
||||
$tarif = $item->tarif;
|
||||
if (!$tarif) {
|
||||
$query = TarifPekerjaan::where('jenis_pekerjaan', $item->jenis_pekerjaan)
|
||||
->where('is_active', true);
|
||||
if ($item->dimensi_pipa) {
|
||||
$query->where('dimensi_pipa', $item->dimensi_pipa);
|
||||
}
|
||||
$tarif = $query->first();
|
||||
}
|
||||
|
||||
if (!$tarif) return 0;
|
||||
|
||||
if ($item->jarak_meter > 0 && $tarif->tarif_per_meter) {
|
||||
return (float) $tarif->tarif_per_meter * (float) $item->jarak_meter;
|
||||
}
|
||||
if ($item->jumlah_unit > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $item->jumlah_unit;
|
||||
}
|
||||
if ($item->jumlah_titik > 0 && $tarif->tarif_per_unit) {
|
||||
return (float) $tarif->tarif_per_unit * (int) $item->jumlah_titik;
|
||||
}
|
||||
|
||||
return (float) ($tarif->tarif_per_unit ?? $tarif->tarif_per_meter ?? 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,406 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\Teknisi;
|
||||
use App\Models\TarifPekerjaan;
|
||||
use App\Models\TimTeknisiPenugasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PenugasanController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Penugasan::with(['teknisi', 'tarif', 'timTeknisi.teknisi']);
|
||||
|
||||
if ($request->filled('status')) {
|
||||
if ($request->status === 'garansi_aktif') {
|
||||
$query->garansiAktif();
|
||||
} else {
|
||||
$query->where('status_pekerjaan', $request->status);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->filled('jenis_pekerjaan')) {
|
||||
$query->where('jenis_pekerjaan', $request->jenis_pekerjaan);
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function($q) use ($search) {
|
||||
$q->where('catatan_admin', 'LIKE', "%{$search}%")
|
||||
->orWhere('detail_pekerjaan', 'LIKE', "%{$search}%")
|
||||
->orWhereHas('teknisi', function($tq) use ($search) {
|
||||
$tq->where('nama', 'LIKE', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('id_teknisi')) {
|
||||
$teknisiId = $request->id_teknisi;
|
||||
$query->where(function($q) use ($teknisiId) {
|
||||
$q->where('id_teknisi', $teknisiId)
|
||||
->orWhereHas('timTeknisi', function($tq) use ($teknisiId) {
|
||||
$tq->where('id_teknisi', $teknisiId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
$query->whereBetween('tanggal_diberikan', [$request->start_date, $request->end_date]);
|
||||
} elseif ($request->filled('start_date')) {
|
||||
$query->where('tanggal_diberikan', '>=', $request->start_date);
|
||||
} elseif ($request->filled('end_date')) {
|
||||
$query->where('tanggal_diberikan', '<=', $request->end_date);
|
||||
}
|
||||
|
||||
$penugasan = $query->orderBy('created_at', 'desc')->paginate(10);
|
||||
|
||||
$totalPenugasan = Penugasan::count();
|
||||
$belumMulai = Penugasan::where('status_pekerjaan', 'belum_mulai')->count();
|
||||
$dalamProses = Penugasan::where('status_pekerjaan', 'dalam_proses')->count();
|
||||
$selesai = Penugasan::where('status_pekerjaan', 'selesai')->count();
|
||||
$dibatalkan = Penugasan::where('status_pekerjaan', 'dibatalkan')->count();
|
||||
$garansiAktif = Penugasan::garansiAktif()->count();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$absentTechIds = \App\Models\Absensi::where('tanggal', $today)
|
||||
->whereIn('status', ['izin', 'sakit'])
|
||||
->pluck('id_teknisi')
|
||||
->toArray();
|
||||
|
||||
$abandonedTasks = collect();
|
||||
if (!empty($absentTechIds)) {
|
||||
$abandonedTasks = Penugasan::whereIn('status_pekerjaan', ['belum_mulai', 'dalam_proses'])
|
||||
->where(function($q) use ($absentTechIds) {
|
||||
$q->whereIn('id_teknisi', $absentTechIds)
|
||||
->orWhereHas('timTeknisi', function($tq) use ($absentTechIds) {
|
||||
$tq->whereIn('id_teknisi', $absentTechIds);
|
||||
});
|
||||
})
|
||||
->with('teknisi')
|
||||
->get();
|
||||
}
|
||||
|
||||
$teknisis = Teknisi::where('status', 'aktif')->orderBy('nama')->get();
|
||||
$teknisiList = $teknisis; // Use same data for the new dropdown
|
||||
|
||||
return view('Admin.KelolaPekerjaan.Penugasan', compact(
|
||||
'penugasan', 'totalPenugasan', 'belumMulai', 'dalamProses',
|
||||
'selesai', 'dibatalkan', 'garansiAktif', 'teknisis', 'teknisiList', 'abandonedTasks'
|
||||
));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$validated = $request->validate([
|
||||
'id_teknisi' => 'required|array',
|
||||
'id_teknisi.*' => 'exists:teknisis,id_teknisi',
|
||||
'tanggal_diberikan' => 'required|date',
|
||||
'foto_surat' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:5120',
|
||||
'catatan_admin' => 'nullable|string',
|
||||
'jenis_pekerjaan' => 'required|string',
|
||||
'alamat_lokasi' => 'required|string',
|
||||
'nama_pelanggan' => 'nullable|string',
|
||||
'no_sambungan' => 'nullable|string',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$path = null;
|
||||
if ($request->hasFile('foto_surat')) {
|
||||
$path = $request->file('foto_surat')->store('penugasan/surat', 'public');
|
||||
}
|
||||
|
||||
$penugasan = Penugasan::create([
|
||||
'id_teknisi' => $validated['id_teknisi'][0],
|
||||
'foto_surat' => $path,
|
||||
'tanggal_diberikan' => $validated['tanggal_diberikan'],
|
||||
'catatan_admin' => $validated['catatan_admin'] ?? null,
|
||||
'jenis_pekerjaan' => $validated['jenis_pekerjaan'],
|
||||
'alamat_lokasi' => $validated['alamat_lokasi'],
|
||||
'nama_pelanggan' => $validated['nama_pelanggan'] ?? null,
|
||||
'no_sambungan' => $validated['no_sambungan'] ?? null,
|
||||
'status_pekerjaan' => 'belum_mulai',
|
||||
]);
|
||||
|
||||
$techIds = array_unique($validated['id_teknisi']);
|
||||
foreach ($techIds as $techId) {
|
||||
TimTeknisiPenugasan::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_teknisi' => $techId,
|
||||
'status_kehadiran' => 'hadir',
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('pekerjaan.penugasan.index')
|
||||
->with('success', 'Penugasan berhasil dibuat! Teknisi akan melengkapi detail via mobile.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->back()
|
||||
->with('error', 'Gagal menambahkan data: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ✅ FIX: Tambah field garansi lengkap di response show()
|
||||
* - is_garansi_aktif → true/false apakah garansi masih aktif
|
||||
* - sisa_hari_garansi → berapa hari tersisa
|
||||
* - tanggal_garansi_mulai → sudah ikut dari toArray()
|
||||
* - tanggal_garansi_selesai → sudah ikut dari toArray()
|
||||
*
|
||||
* Sebelumnya field-field ini tidak di-append sehingga
|
||||
* badge garansi di modal detail tidak pernah muncul
|
||||
* meski datanya sudah ada di database
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::with(['teknisi', 'tarif', 'timTeknisi.teknisi', 'items.tarif'])
|
||||
->findOrFail($id);
|
||||
|
||||
$data = $penugasan->toArray();
|
||||
|
||||
$data['foto_surat_url'] = $penugasan->foto_surat_url;
|
||||
$data['foto_sebelum_url'] = $penugasan->foto_sebelum_url;
|
||||
$data['foto_sesudah_url'] = $penugasan->foto_sesudah_url;
|
||||
$data['label_jenis_pekerjaan'] = $penugasan->label_jenis_pekerjaan;
|
||||
|
||||
// ✅ FIX: Info garansi — dibutuhkan oleh blade untuk tampilkan badge
|
||||
$data['is_garansi_aktif'] = $penugasan->isGaransiAktif();
|
||||
$data['sisa_hari_garansi'] = $penugasan->getSisaHariGaransi();
|
||||
|
||||
return response()->json(['success' => true, 'data' => $data]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Data tidak ditemukan'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::with(['teknisi', 'timTeknisi.teknisi'])->findOrFail($id);
|
||||
|
||||
$data = $penugasan->toArray();
|
||||
$data['foto_surat_url'] = $penugasan->foto_surat_url;
|
||||
|
||||
return response()->json(['success' => true, 'data' => $data]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Data tidak ditemukan'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'id_teknisi' => 'required|array',
|
||||
'id_teknisi.*' => 'exists:teknisis,id_teknisi',
|
||||
'tanggal_diberikan' => 'required|date',
|
||||
'foto_surat' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:5120',
|
||||
'catatan_admin' => 'nullable|string',
|
||||
'jenis_pekerjaan' => 'required|string',
|
||||
'alamat_lokasi' => 'required|string',
|
||||
'nama_pelanggan' => 'nullable|string',
|
||||
'no_sambungan' => 'nullable|string',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$updateData = [
|
||||
'id_teknisi' => $validated['id_teknisi'][0],
|
||||
'tanggal_diberikan' => $validated['tanggal_diberikan'],
|
||||
'catatan_admin' => $validated['catatan_admin'] ?? null,
|
||||
'jenis_pekerjaan' => $validated['jenis_pekerjaan'],
|
||||
'alamat_lokasi' => $validated['alamat_lokasi'],
|
||||
'nama_pelanggan' => $validated['nama_pelanggan'] ?? null,
|
||||
'no_sambungan' => $validated['no_sambungan'] ?? null,
|
||||
];
|
||||
|
||||
if ($request->hasFile('foto_surat')) {
|
||||
if ($penugasan->foto_surat) {
|
||||
Storage::disk('public')->delete($penugasan->foto_surat);
|
||||
}
|
||||
$updateData['foto_surat'] = $request->file('foto_surat')->store('penugasan/surat', 'public');
|
||||
}
|
||||
|
||||
$penugasan->update($updateData);
|
||||
|
||||
TimTeknisiPenugasan::where('id_penugasan', $penugasan->id_penugasan)->delete();
|
||||
|
||||
$techIds = array_unique($validated['id_teknisi']);
|
||||
foreach ($techIds as $techId) {
|
||||
TimTeknisiPenugasan::create([
|
||||
'id_penugasan' => $penugasan->id_penugasan,
|
||||
'id_teknisi' => $techId,
|
||||
'status_kehadiran' => 'hadir',
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Data berhasil diupdate!']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => 'Gagal update: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$penugasan = Penugasan::findOrFail($id);
|
||||
|
||||
if ($penugasan->foto_surat) {
|
||||
Storage::disk('public')->delete($penugasan->foto_surat);
|
||||
}
|
||||
|
||||
$penugasan->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Data berhasil dihapus!']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => 'Gagal menghapus: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTarifByJenis(Request $request)
|
||||
{
|
||||
try {
|
||||
$tarifs = TarifPekerjaan::where('jenis_pekerjaan', $request->jenis_pekerjaan)
|
||||
->where('is_active', true)
|
||||
->get();
|
||||
|
||||
return response()->json(['success' => true, 'data' => $tarifs]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal mengambil tarif'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTeknisiByDate(Request $request)
|
||||
{
|
||||
try {
|
||||
// Selalu tampilkan seluruh teknisi aktif agar fleksibel secara operasional
|
||||
$teknisis = Teknisi::where('status', 'aktif')
|
||||
->orderBy('nama')
|
||||
->get();
|
||||
|
||||
return response()->json(['success' => true, 'data' => $teknisis]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal mengambil data teknisi: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ✅ FIX: Filter tanggal monitoring pakai tanggal_diselesaikan
|
||||
* bukan updated_at agar hasil filter akurat
|
||||
*/
|
||||
public function monitoring(Request $request)
|
||||
{
|
||||
$query = Penugasan::with(['teknisi', 'timTeknisi.teknisi']);
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status_pekerjaan', $request->status);
|
||||
}
|
||||
|
||||
if ($request->filled('teknisi_id')) {
|
||||
$teknisiId = $request->teknisi_id;
|
||||
$query->where(function($q) use ($teknisiId) {
|
||||
$q->where('id_teknisi', $teknisiId)
|
||||
->orWhereHas('timTeknisi', function($tq) use ($teknisiId) {
|
||||
$tq->where('id_teknisi', $teknisiId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
$start = $request->start_date . ' 00:00:00';
|
||||
$end = $request->end_date . ' 23:59:59';
|
||||
$query->where(function($q) use ($start, $end) {
|
||||
$q->where(function($q2) use ($start, $end) {
|
||||
$q2->whereNotNull('tanggal_diselesaikan')
|
||||
->whereBetween('tanggal_diselesaikan', [$start, $end]);
|
||||
})->orWhere(function($q2) use ($start, $end) {
|
||||
$q2->whereNull('tanggal_diselesaikan')
|
||||
->whereBetween('updated_at', [$start, $end]);
|
||||
});
|
||||
});
|
||||
} elseif ($request->filled('start_date')) {
|
||||
$start = $request->start_date . ' 00:00:00';
|
||||
$query->where(function($q) use ($start) {
|
||||
$q->where(function($q2) use ($start) {
|
||||
$q2->whereNotNull('tanggal_diselesaikan')
|
||||
->where('tanggal_diselesaikan', '>=', $start);
|
||||
})->orWhere(function($q2) use ($start) {
|
||||
$q2->whereNull('tanggal_diselesaikan')
|
||||
->where('updated_at', '>=', $start);
|
||||
});
|
||||
});
|
||||
} elseif ($request->filled('end_date')) {
|
||||
$end = $request->end_date . ' 23:59:59';
|
||||
$query->where(function($q) use ($end) {
|
||||
$q->where(function($q2) use ($end) {
|
||||
$q2->whereNotNull('tanggal_diselesaikan')
|
||||
->where('tanggal_diselesaikan', '<=', $end);
|
||||
})->orWhere(function($q2) use ($end) {
|
||||
$q2->whereNull('tanggal_diselesaikan')
|
||||
->where('updated_at', '<=', $end);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$progresKerja = $query->orderBy('updated_at', 'desc')->paginate(12);
|
||||
|
||||
$progresKerja->getCollection()->transform(function ($item) {
|
||||
$item->persentase_pekerjaan = match($item->status_pekerjaan) {
|
||||
'selesai' => 100,
|
||||
'dalam_proses' => 50,
|
||||
default => 0,
|
||||
};
|
||||
$item->is_garansi_aktif = $item->isGaransiAktif();
|
||||
$item->sisa_hari_garansi = $item->getSisaHariGaransi();
|
||||
return $item;
|
||||
});
|
||||
|
||||
$statistics = [
|
||||
'total' => Penugasan::count(),
|
||||
'dalam_progres' => Penugasan::where('status_pekerjaan', 'dalam_proses')->count(),
|
||||
'selesai' => Penugasan::where('status_pekerjaan', 'selesai')->count(),
|
||||
'belum_mulai' => Penugasan::where('status_pekerjaan', 'belum_mulai')->count(),
|
||||
'garansi_aktif' => Penugasan::garansiAktif()->count(),
|
||||
];
|
||||
|
||||
$statusList = [
|
||||
'belum_mulai' => 'Belum Mulai',
|
||||
'dalam_proses' => 'Dalam Proses',
|
||||
'selesai' => 'Selesai',
|
||||
];
|
||||
|
||||
$teknisiList = Teknisi::orderBy('nama')->get();
|
||||
|
||||
return view('Admin.KelolaPekerjaan.ProgresKerja', compact(
|
||||
'progresKerja', 'statistics', 'statusList', 'teknisiList'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,464 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ProgresKerja;
|
||||
use App\Models\Penugasan;
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ProgresKerjaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the progress kerja.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = ProgresKerja::with(['teknisi', 'penugasan']);
|
||||
|
||||
// Filter by status
|
||||
if ($request->filled('status')) {
|
||||
$query->byStatus($request->status);
|
||||
}
|
||||
|
||||
// Filter by teknisi
|
||||
if ($request->filled('teknisi_id')) {
|
||||
$query->byTeknisi($request->teknisi_id);
|
||||
}
|
||||
|
||||
// Filter by date range
|
||||
if ($request->filled('start_date') || $request->filled('end_date')) {
|
||||
$query->byDateRange($request->start_date, $request->end_date);
|
||||
}
|
||||
|
||||
// Search functionality
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function($q) use ($search) {
|
||||
$q->where('tugas', 'like', "%{$search}%")
|
||||
->orWhere('deskripsi_progres', 'like', "%{$search}%")
|
||||
->orWhereHas('teknisi', function($teknisiQuery) use ($search) {
|
||||
$teknisiQuery->where('nama', 'like', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$progresKerja = $query->latest()->paginate(10);
|
||||
|
||||
// Get filter options
|
||||
$teknisiList = Teknisi::orderBy('nama')->get();
|
||||
$statusList = ProgresKerja::$statusProgres;
|
||||
|
||||
// Get statistics
|
||||
$statistics = ProgresKerja::getStatistics();
|
||||
|
||||
return view('Admin.KelolaPekerjaan.ProgresKerja', compact(
|
||||
'progresKerja',
|
||||
'teknisiList',
|
||||
'statusList',
|
||||
'statistics'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new progress kerja.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$penugasanList = Penugasan::with('pelanggan')->orderBy('created_at', 'desc')->get();
|
||||
$teknisiList = Teknisi::orderBy('nama')->get();
|
||||
$statusList = ProgresKerja::$statusProgres;
|
||||
|
||||
return view('Admin.KelolaPekerjaan.ProgresKerjaForm', compact(
|
||||
'penugasanList',
|
||||
'teknisiList',
|
||||
'statusList'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created progress kerja in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_penugasan' => 'required|exists:penugasan,id_penugasan',
|
||||
'id_teknisi' => 'required|exists:teknisi,id_teknisi',
|
||||
'tugas' => 'required|string|max:255',
|
||||
'deskripsi_progres' => 'nullable|string',
|
||||
'status_progres' => 'required|in:' . implode(',', array_keys(ProgresKerja::$statusProgres)),
|
||||
'persentase_pekerjaan' => 'required|integer|min:0|max:100',
|
||||
'foto_progress' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$data = $request->only([
|
||||
'id_penugasan',
|
||||
'id_teknisi',
|
||||
'tugas',
|
||||
'deskripsi_progres',
|
||||
'status_progres',
|
||||
'persentase_pekerjaan'
|
||||
]);
|
||||
|
||||
// Handle foto progress upload
|
||||
if ($request->hasFile('foto_progress')) {
|
||||
$file = $request->file('foto_progress');
|
||||
$fileName = time() . '_' . Str::random(10) . '.' . $file->getClientOriginalExtension();
|
||||
|
||||
// Store in public/storage/progress_photos
|
||||
$file->storeAs('progress_photos', $fileName, 'public');
|
||||
$data['foto_progress'] = $fileName;
|
||||
}
|
||||
|
||||
$progresKerja = ProgresKerja::create($data);
|
||||
|
||||
// Auto update status based on percentage
|
||||
$progresKerja->autoUpdateStatus();
|
||||
|
||||
return redirect()->route('progres-kerja.index')
|
||||
->with('success', 'Progress kerja berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified progress kerja.
|
||||
*
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(ProgresKerja $progresKerja)
|
||||
{
|
||||
$progresKerja->load(['teknisi', 'penugasan.pelanggan']);
|
||||
|
||||
return view('Admin.KelolaPekerjaan.ProgresKerjaDetail', compact('progresKerja'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified progress kerja.
|
||||
*
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(ProgresKerja $progresKerja)
|
||||
{
|
||||
$penugasanList = Penugasan::with('pelanggan')->orderBy('created_at', 'desc')->get();
|
||||
$teknisiList = Teknisi::orderBy('nama')->get();
|
||||
$statusList = ProgresKerja::$statusProgres;
|
||||
|
||||
return view('Admin.KelolaPekerjaan.ProgresKerjaForm', compact(
|
||||
'progresKerja',
|
||||
'penugasanList',
|
||||
'teknisiList',
|
||||
'statusList'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified progress kerja in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, ProgresKerja $progresKerja)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_penugasan' => 'required|exists:penugasan,id_penugasan',
|
||||
'id_teknisi' => 'required|exists:teknisi,id_teknisi',
|
||||
'tugas' => 'required|string|max:255',
|
||||
'deskripsi_progres' => 'nullable|string',
|
||||
'status_progres' => 'required|in:' . implode(',', array_keys(ProgresKerja::$statusProgres)),
|
||||
'persentase_pekerjaan' => 'required|integer|min:0|max:100',
|
||||
'foto_progress' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$data = $request->only([
|
||||
'id_penugasan',
|
||||
'id_teknisi',
|
||||
'tugas',
|
||||
'deskripsi_progres',
|
||||
'status_progres',
|
||||
'persentase_pekerjaan'
|
||||
]);
|
||||
|
||||
// Handle foto progress upload
|
||||
if ($request->hasFile('foto_progress')) {
|
||||
// Delete old photo if exists
|
||||
if ($progresKerja->foto_progress) {
|
||||
Storage::disk('public')->delete('progress_photos/' . $progresKerja->foto_progress);
|
||||
}
|
||||
|
||||
$file = $request->file('foto_progress');
|
||||
$fileName = time() . '_' . Str::random(10) . '.' . $file->getClientOriginalExtension();
|
||||
|
||||
$file->storeAs('progress_photos', $fileName, 'public');
|
||||
$data['foto_progress'] = $fileName;
|
||||
}
|
||||
|
||||
$progresKerja->update($data);
|
||||
|
||||
// Auto update status based on percentage
|
||||
$progresKerja->autoUpdateStatus();
|
||||
|
||||
return redirect()->route('progres-kerja.index')
|
||||
->with('success', 'Progress kerja berhasil diperbarui.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified progress kerja from storage.
|
||||
*
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(ProgresKerja $progresKerja)
|
||||
{
|
||||
// Delete photo if exists
|
||||
if ($progresKerja->foto_progress) {
|
||||
Storage::disk('public')->delete('progress_photos/' . $progresKerja->foto_progress);
|
||||
}
|
||||
|
||||
$progresKerja->delete();
|
||||
|
||||
return redirect()->route('progres-kerja.index')
|
||||
->with('success', 'Progress kerja berhasil dihapus.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick update progress status
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function updateStatus(Request $request, ProgresKerja $progresKerja)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'status' => 'required|in:' . implode(',', array_keys(ProgresKerja::$statusProgres)),
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Status tidak valid.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Check if transition is valid
|
||||
if (!$progresKerja->canTransitionTo($request->status)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Transisi status tidak valid.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$progresKerja->update(['status_progres' => $request->status]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status berhasil diperbarui.',
|
||||
'new_status' => $progresKerja->status_formatted,
|
||||
'badge_class' => $progresKerja->status_badge_class
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update progress percentage
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProgresKerja $progresKerja
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function updatePercentage(Request $request, ProgresKerja $progresKerja)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'percentage' => 'required|integer|min:0|max:100',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Persentase tidak valid.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$progresKerja->update(['persentase_pekerjaan' => $request->percentage]);
|
||||
$progresKerja->autoUpdateStatus();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Persentase berhasil diperbarui.',
|
||||
'new_percentage' => $progresKerja->persentase_pekerjaan,
|
||||
'new_status' => $progresKerja->status_formatted,
|
||||
'badge_class' => $progresKerja->status_badge_class
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get progress by teknisi (AJAX)
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getByTeknisi(Request $request)
|
||||
{
|
||||
$teknisiId = $request->get('teknisi_id');
|
||||
|
||||
if (!$teknisiId) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Teknisi ID diperlukan.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$progresKerja = ProgresKerja::getByTeknisi($teknisiId);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $progresKerja->map(function($item) {
|
||||
return [
|
||||
'id' => $item->id_progres,
|
||||
'tugas' => $item->tugas,
|
||||
'status' => $item->status_formatted,
|
||||
'persentase' => $item->persentase_pekerjaan,
|
||||
'tanggal_update' => $item->tanggal_update_formatted,
|
||||
'penugasan' => $item->penugasan->nama_pekerjaan ?? 'N/A'
|
||||
];
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export progress data
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
$query = ProgresKerja::with(['teknisi', 'penugasan']);
|
||||
|
||||
// Apply same filters as index
|
||||
if ($request->filled('status')) {
|
||||
$query->byStatus($request->status);
|
||||
}
|
||||
|
||||
if ($request->filled('teknisi_id')) {
|
||||
$query->byTeknisi($request->teknisi_id);
|
||||
}
|
||||
|
||||
if ($request->filled('start_date') || $request->filled('end_date')) {
|
||||
$query->byDateRange($request->start_date, $request->end_date);
|
||||
}
|
||||
|
||||
$progresKerja = $query->latest()->get();
|
||||
|
||||
$filename = 'progress_kerja_' . date('Y-m-d') . '.csv';
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'text/csv',
|
||||
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
|
||||
];
|
||||
|
||||
$callback = function() use ($progresKerja) {
|
||||
$file = fopen('php://output', 'w');
|
||||
|
||||
// Add BOM for UTF-8
|
||||
fwrite($file, "\xEF\xBB\xBF");
|
||||
|
||||
// Header row
|
||||
fputcsv($file, [
|
||||
'ID',
|
||||
'Penugasan',
|
||||
'Teknisi',
|
||||
'Tugas',
|
||||
'Deskripsi Progress',
|
||||
'Status',
|
||||
'Persentase (%)',
|
||||
'Tanggal Update',
|
||||
'Foto Progress'
|
||||
]);
|
||||
|
||||
// Data rows
|
||||
foreach ($progresKerja as $item) {
|
||||
fputcsv($file, [
|
||||
$item->id_progres,
|
||||
$item->penugasan->nama_pekerjaan ?? 'N/A',
|
||||
$item->teknisi->nama ?? 'N/A',
|
||||
$item->tugas,
|
||||
$item->deskripsi_progres,
|
||||
$item->status_formatted,
|
||||
$item->persentase_pekerjaan,
|
||||
$item->tanggal_update_formatted,
|
||||
$item->has_foto ? 'Ya' : 'Tidak'
|
||||
]);
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
};
|
||||
|
||||
return response()->stream($callback, 200, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent updates for dashboard
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getRecentUpdates()
|
||||
{
|
||||
$recentUpdates = ProgresKerja::getRecentUpdates(5);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $recentUpdates->map(function($item) {
|
||||
return [
|
||||
'id' => $item->id_progres,
|
||||
'tugas' => $item->tugas,
|
||||
'teknisi' => $item->teknisi->nama ?? 'N/A',
|
||||
'status' => $item->status_formatted,
|
||||
'persentase' => $item->persentase_pekerjaan,
|
||||
'tanggal_update' => $item->tanggal_update_formatted,
|
||||
'days_since_update' => $item->days_since_update
|
||||
];
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics for dashboard
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getStatistics()
|
||||
{
|
||||
$statistics = ProgresKerja::getStatistics();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $statistics
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,346 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Teknisi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TeknisiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Teknisi::query();
|
||||
|
||||
// Handle search
|
||||
if ($request->has('q') && $request->q != '') {
|
||||
$searchTerm = $request->q;
|
||||
$query->where(function($q) use ($searchTerm) {
|
||||
$q->where('nama', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('email', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('no_telephone', 'LIKE', "%{$searchTerm}%");
|
||||
});
|
||||
}
|
||||
|
||||
$teknisis = $query->latest()->get();
|
||||
|
||||
// Jika request dari AJAX, return JSON
|
||||
if ($request->ajax() || $request->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $teknisis
|
||||
]);
|
||||
}
|
||||
|
||||
// Jika request biasa, return view
|
||||
return view('Admin.KelolaTeknisi.Teknisi', compact('teknisis'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('teknisi.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama' => 'required|string|max:100',
|
||||
'tanggal_lahir' => 'required|date',
|
||||
'alamat' => 'required|string',
|
||||
'email' => 'nullable|email|max:100|unique:teknisis,email',
|
||||
'no_telephone' => 'required|string|max:15',
|
||||
'tanggal_masuk' => 'required|date',
|
||||
'status' => 'required|in:aktif,tidak_aktif',
|
||||
], [
|
||||
'nama.required' => 'Nama wajib diisi',
|
||||
'nama.max' => 'Nama maksimal 100 karakter',
|
||||
'tanggal_lahir.required' => 'Tanggal lahir wajib diisi',
|
||||
'tanggal_lahir.date' => 'Format tanggal lahir tidak valid',
|
||||
'alamat.required' => 'Alamat wajib diisi',
|
||||
'email.email' => 'Format email tidak valid',
|
||||
'email.unique' => 'Email sudah terdaftar',
|
||||
'no_telephone.required' => 'Nomor telephone wajib diisi',
|
||||
'no_telephone.max' => 'Nomor telephone maksimal 15 karakter',
|
||||
'tanggal_masuk.required' => 'Tanggal masuk wajib diisi',
|
||||
'tanggal_masuk.date' => 'Format tanggal masuk tidak valid',
|
||||
'status.required' => 'Status wajib dipilih',
|
||||
'status.in' => 'Status harus aktif atau tidak_aktif',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
$teknisi = Teknisi::create($request->all());
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data teknisi berhasil ditambahkan',
|
||||
'data' => $teknisi
|
||||
], 201);
|
||||
}
|
||||
|
||||
return redirect()->route('teknisi.index')
|
||||
->with('success', 'Data teknisi berhasil ditambahkan');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error creating teknisi: ' . $e->getMessage());
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menambahkan data teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('error', 'Gagal menambahkan data teknisi: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('id_teknisi', $id)->firstOrFail();
|
||||
|
||||
// Jika AJAX request, return JSON
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $teknisi
|
||||
]);
|
||||
}
|
||||
|
||||
return view('teknisi.show', compact('teknisi'));
|
||||
} catch (\Exception $e) {
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data teknisi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->route('teknisi.index')
|
||||
->with('error', 'Data teknisi tidak ditemukan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('id_teknisi', $id)->firstOrFail();
|
||||
return view('teknisi.edit', compact('teknisi'));
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->route('teknisi.index')
|
||||
->with('error', 'Data teknisi tidak ditemukan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('id_teknisi', $id)->firstOrFail();
|
||||
|
||||
// Log untuk debugging
|
||||
Log::info('Update Teknisi Request', [
|
||||
'id' => $id,
|
||||
'request_data' => $request->all()
|
||||
]);
|
||||
|
||||
// Validasi - TANPA tanggal_lahir dan tanggal_masuk karena tidak boleh diubah
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama' => 'required|string|max:100',
|
||||
'alamat' => 'required|string',
|
||||
'email' => 'nullable|email|max:100|unique:teknisis,email,' . $id . ',id_teknisi',
|
||||
'no_telephone' => 'required|string|max:15',
|
||||
'status' => 'required|in:aktif,tidak_aktif',
|
||||
'tanggal_masuk' => 'required|date',
|
||||
], [
|
||||
'nama.required' => 'Nama wajib diisi',
|
||||
'nama.max' => 'Nama maksimal 100 karakter',
|
||||
'alamat.required' => 'Alamat wajib diisi',
|
||||
'email.email' => 'Format email tidak valid',
|
||||
'email.unique' => 'Email sudah terdaftar',
|
||||
'no_telephone.required' => 'Nomor telephone wajib diisi',
|
||||
'no_telephone.max' => 'Nomor telephone maksimal 15 karakter',
|
||||
'status.required' => 'Status wajib dipilih',
|
||||
'status.in' => 'Status harus aktif atau tidak_aktif',
|
||||
'tanggal_masuk.required' => 'Tanggal masuk wajib diisi',
|
||||
'tanggal_masuk.date' => 'Format tanggal masuk tidak valid',
|
||||
]);
|
||||
|
||||
// Allow deactivation even if unpaid kasbon; a warning will be shown in the UI.
|
||||
// The check is now performed in the view for visual indication.
|
||||
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::warning('Validation Failed', [
|
||||
'errors' => $validator->errors()->toArray()
|
||||
]);
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
// Update data
|
||||
$teknisi->update([
|
||||
'nama' => $request->nama,
|
||||
'alamat' => $request->alamat,
|
||||
'email' => $request->email,
|
||||
'no_telephone' => $request->no_telephone,
|
||||
'status' => $request->status,
|
||||
'tanggal_masuk' => $request->tanggal_masuk,
|
||||
]);
|
||||
|
||||
Log::info('Teknisi Updated Successfully', [
|
||||
'id' => $id,
|
||||
'updated_data' => $teknisi->fresh()->toArray()
|
||||
]);
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data teknisi berhasil diperbarui',
|
||||
'data' => $teknisi
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('teknisi.index')
|
||||
->with('success', 'Data teknisi berhasil diperbarui');
|
||||
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
Log::error('Teknisi Not Found', ['id' => $id]);
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data teknisi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return redirect()->route('teknisi.index')
|
||||
->with('error', 'Data teknisi tidak ditemukan');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Update Teknisi Failed', [
|
||||
'id' => $id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal memperbarui data teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('error', 'Gagal memperbarui data teknisi: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Search teknisi
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$query = $request->get('q');
|
||||
|
||||
$teknisis = Teknisi::where('nama', 'LIKE', "%{$query}%")
|
||||
->orWhere('email', 'LIKE', "%{$query}%")
|
||||
->orWhere('no_telephone', 'LIKE', "%{$query}%")
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
// Jika AJAX request
|
||||
if (request()->ajax() || request()->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $teknisis
|
||||
]);
|
||||
}
|
||||
|
||||
return view('Admin.KelolaTeknisi.Teknisi', compact('teknisis'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
try {
|
||||
$teknisi = Teknisi::where('id_teknisi', $id)->firstOrFail();
|
||||
|
||||
// Cek tunggakan kasbon
|
||||
$unpaidKasbon = \App\Models\Kasbon::where('id_teknisi', $id)
|
||||
->where('status', 'belum_lunas')
|
||||
->sum('jumlah_kasbon');
|
||||
|
||||
if ($unpaidKasbon > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Teknisi tidak dapat dihapus karena masih memiliki tunggakan kasbon sebesar Rp ' . number_format($unpaidKasbon, 0, ',', '.') . '.'
|
||||
], 422);
|
||||
}
|
||||
|
||||
$teknisi->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data teknisi berhasil dihapus'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghapus data teknisi: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,341 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Absensi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Nama tabel di database
|
||||
*/
|
||||
protected $table = 'absensis'; // PERBAIKAN: Ganti 'absensi' menjadi 'absensis'
|
||||
|
||||
/**
|
||||
* Primary key tabel
|
||||
*/
|
||||
protected $primaryKey = 'id_absensi';
|
||||
|
||||
/**
|
||||
* Field yang dapat diisi secara mass assignment
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'tanggal',
|
||||
'jam_masuk',
|
||||
'jam_keluar',
|
||||
'foto_absen_masuk',
|
||||
'foto_absen_keluar',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'status',
|
||||
'keterangan'
|
||||
];
|
||||
|
||||
/**
|
||||
* Field yang akan di-cast ke tipe data tertentu
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal' => 'date',
|
||||
'jam_masuk' => 'datetime',
|
||||
'jam_keluar' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
];
|
||||
|
||||
/**
|
||||
* Status absensi yang valid
|
||||
*/
|
||||
const STATUS_HADIR = 'hadir';
|
||||
const STATUS_SAKIT = 'sakit';
|
||||
const STATUS_IZIN = 'izin';
|
||||
|
||||
/**
|
||||
* Array status yang tersedia
|
||||
*/
|
||||
public static function getStatusOptions()
|
||||
{
|
||||
return [
|
||||
self::STATUS_HADIR => 'Hadir',
|
||||
self::STATUS_SAKIT => 'Sakit',
|
||||
self::STATUS_IZIN => 'Izin'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke model Teknisi
|
||||
* Satu absensi dimiliki oleh satu teknisi
|
||||
*/
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk filter berdasarkan tanggal
|
||||
*/
|
||||
public function scopeFilterByDate($query, $tanggal)
|
||||
{
|
||||
if ($tanggal) {
|
||||
return $query->whereDate('tanggal', $tanggal);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk filter berdasarkan status
|
||||
*/
|
||||
public function scopeFilterByStatus($query, $status)
|
||||
{
|
||||
if ($status) {
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk filter berdasarkan teknisi
|
||||
*/
|
||||
public function scopeFilterByTeknisi($query, $teknisiId)
|
||||
{
|
||||
if ($teknisiId) {
|
||||
return $query->where('id_teknisi', $teknisiId);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk filter berdasarkan bulan dan tahun
|
||||
*/
|
||||
public function scopeFilterByMonth($query, $bulan, $tahun = null)
|
||||
{
|
||||
if (!$tahun) {
|
||||
$tahun = date('Y');
|
||||
}
|
||||
|
||||
return $query->whereMonth('tanggal', $bulan)
|
||||
->whereYear('tanggal', $tahun);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk data absensi hari ini
|
||||
*/
|
||||
public function scopeToday($query)
|
||||
{
|
||||
return $query->whereDate('tanggal', Carbon::today());
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk data absensi minggu ini
|
||||
*/
|
||||
public function scopeThisWeek($query)
|
||||
{
|
||||
return $query->whereBetween('tanggal', [
|
||||
Carbon::now()->startOfWeek(),
|
||||
Carbon::now()->endOfWeek()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk data absensi bulan ini
|
||||
*/
|
||||
public function scopeThisMonth($query)
|
||||
{
|
||||
return $query->whereMonth('tanggal', Carbon::now()->month)
|
||||
->whereYear('tanggal', Carbon::now()->year);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk format tanggal Indonesia
|
||||
*/
|
||||
public function getTanggalFormattedAttribute()
|
||||
{
|
||||
return Carbon::parse($this->tanggal)->format('d/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk format jam masuk
|
||||
*/
|
||||
public function getJamMasukFormattedAttribute()
|
||||
{
|
||||
return $this->jam_masuk ? Carbon::parse($this->jam_masuk)->format('H:i') : '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk format jam keluar
|
||||
*/
|
||||
public function getJamKeluarFormattedAttribute()
|
||||
{
|
||||
return $this->jam_keluar ? Carbon::parse($this->jam_keluar)->format('H:i') : '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk nama status dengan format title case
|
||||
*/
|
||||
public function getStatusFormattedAttribute()
|
||||
{
|
||||
return ucfirst($this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk URL foto absen masuk
|
||||
*/
|
||||
public function getFotoAbsenMasukUrlAttribute()
|
||||
{
|
||||
return $this->foto_absen_masuk ? asset('storage/' . $this->foto_absen_masuk) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk URL foto absen keluar
|
||||
*/
|
||||
public function getFotoAbsenKeluarUrlAttribute()
|
||||
{
|
||||
return $this->foto_absen_keluar ? asset('storage/' . $this->foto_absen_keluar) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk menghitung durasi kerja (dalam menit)
|
||||
*/
|
||||
public function getDurasiKerjaAttribute()
|
||||
{
|
||||
if ($this->jam_masuk && $this->jam_keluar) {
|
||||
$masuk = Carbon::parse($this->jam_masuk);
|
||||
$keluar = Carbon::parse($this->jam_keluar);
|
||||
return $keluar->diffInMinutes($masuk);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk durasi kerja dalam format jam:menit
|
||||
*/
|
||||
public function getDurasiKerjaFormattedAttribute()
|
||||
{
|
||||
$durasi = $this->durasi_kerja;
|
||||
if ($durasi > 0) {
|
||||
$jam = floor($durasi / 60);
|
||||
$menit = $durasi % 60;
|
||||
return sprintf('%02d:%02d', $jam, $menit);
|
||||
}
|
||||
return '00:00';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk menentukan apakah terlambat (asumsi jam masuk normal 08:00)
|
||||
*/
|
||||
/**
|
||||
* Accessor untuk kategori kerja (Kerja Biasa vs Lembur)
|
||||
*/
|
||||
public function getKategoriKerjaAttribute()
|
||||
{
|
||||
if ($this->jam_masuk) {
|
||||
$jamMasuk = Carbon::parse($this->jam_masuk);
|
||||
$start = Carbon::parse('07:00');
|
||||
$end = Carbon::parse('18:00');
|
||||
|
||||
if ($jamMasuk->between($start, $end)) {
|
||||
return 'Kerja Biasa';
|
||||
}
|
||||
return 'Kerja Urgent';
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Label warna untuk kategori kerja
|
||||
*/
|
||||
public function getKategoriBadgeClassAttribute()
|
||||
{
|
||||
return $this->kategori_kerja === 'Kerja Biasa' ? 'badge-success' : 'badge-warning';
|
||||
}
|
||||
|
||||
/**
|
||||
* Logika terlambat ditiadakan sesuai permintaan user
|
||||
*/
|
||||
public function getIsTerlambatAttribute()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk CSS class badge berdasarkan status
|
||||
*/
|
||||
public function getStatusBadgeClassAttribute()
|
||||
{
|
||||
$classes = [
|
||||
self::STATUS_HADIR => 'badge-success',
|
||||
self::STATUS_SAKIT => 'badge-warning',
|
||||
self::STATUS_IZIN => 'badge-info'
|
||||
];
|
||||
|
||||
return $classes[$this->status] ?? 'badge-secondary';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method untuk mengecek apakah absensi sudah lengkap (ada jam masuk dan keluar)
|
||||
*/
|
||||
public function isComplete()
|
||||
{
|
||||
return !empty($this->jam_masuk) && !empty($this->jam_keluar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method untuk mengecek apakah sudah absen masuk
|
||||
*/
|
||||
public function hasAbsenMasuk()
|
||||
{
|
||||
return !empty($this->jam_masuk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method untuk mengecek apakah sudah absen keluar
|
||||
*/
|
||||
public function hasAbsenKeluar()
|
||||
{
|
||||
return !empty($this->jam_keluar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method untuk mendapatkan statistik absensi berdasarkan periode
|
||||
*/
|
||||
public static function getStatistik($startDate = null, $endDate = null)
|
||||
{
|
||||
$query = self::query();
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$query->whereBetween('tanggal', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
return [
|
||||
'total' => $query->count(),
|
||||
'hadir' => $query->where('status', self::STATUS_HADIR)->count(),
|
||||
'sakit' => $query->where('status', self::STATUS_SAKIT)->count(),
|
||||
'izin' => $query->where('status', self::STATUS_IZIN)->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot method untuk event model
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// Event ketika model akan dihapus
|
||||
static::deleting(function ($absensi) {
|
||||
// Hapus file foto jika ada
|
||||
if ($absensi->foto_absen_masuk && Storage::disk('public')->exists($absensi->foto_absen_masuk)) {
|
||||
Storage::disk('public')->delete($absensi->foto_absen_masuk);
|
||||
}
|
||||
|
||||
if ($absensi->foto_absen_keluar && Storage::disk('public')->exists($absensi->foto_absen_keluar)) {
|
||||
Storage::disk('public')->delete($absensi->foto_absen_keluar);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class AkunTeknisi extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Nama tabel yang berelasi dengan model ini.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'akun_teknisis';
|
||||
|
||||
/**
|
||||
* Nama primary key dari tabel.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id_akun_teknisi';
|
||||
|
||||
/**
|
||||
* Atribut yang dapat diisi secara massal (mass assignable).
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'username',
|
||||
'password',
|
||||
'password_plain',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* Atribut yang harus disembunyikan (hidden) dari array atau JSON.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* Atribut yang harus dikonversi ke tipe data tertentu.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke model Teknisi.
|
||||
* Sebuah AkunTeknisi dimiliki oleh satu Teknisi.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function teknisi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('dashboard', [
|
||||
'totalTeknisi' => 0,
|
||||
'teknisiAktif' => 0,
|
||||
'totalPekerjaan' => 0,
|
||||
'penugasanAktif' => 0,
|
||||
'chartPenugasan' => [0,0,0,0,0,0,0,0,0,0,0,0],
|
||||
'chartSelesai' => [0,0,0,0,0,0,0,0,0,0,0,0],
|
||||
'kontrakJatuhTempo' => collect(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DetailPenggajian extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'detail_penggajians';
|
||||
protected $primaryKey = 'id_detail';
|
||||
|
||||
protected $fillable = [
|
||||
'id_penggajian',
|
||||
'id_penugasan',
|
||||
'tanggal_selesai',
|
||||
'lokasi',
|
||||
'ongkos_penugasan',
|
||||
'jumlah_tim',
|
||||
'bagian_ongkos',
|
||||
'rincian_pekerjaan',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'ongkos_penugasan' => 'decimal:2',
|
||||
'jumlah_tim' => 'integer',
|
||||
'bagian_ongkos' => 'decimal:2',
|
||||
'tanggal_selesai' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relationship with Penggajian
|
||||
*/
|
||||
public function penggajian()
|
||||
{
|
||||
return $this->belongsTo(Penggajian::class, 'id_penggajian', 'id_penggajian');
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship with Penugasan
|
||||
*/
|
||||
public function penugasan()
|
||||
{
|
||||
return $this->belongsTo(Penugasan::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot method to update parent totals
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::saved(function ($detail) {
|
||||
$detail->updatePenggajianTotals();
|
||||
});
|
||||
|
||||
static::deleted(function ($detail) {
|
||||
$detail->updatePenggajianTotals();
|
||||
});
|
||||
}
|
||||
|
||||
public function updatePenggajianTotals()
|
||||
{
|
||||
$penggajian = $this->penggajian;
|
||||
if ($penggajian) {
|
||||
$totalOngkos = self::where('id_penggajian', $this->id_penggajian)->sum('bagian_ongkos');
|
||||
$biayaMakan = $penggajian->biaya_makan ?? 0;
|
||||
$potongan = $penggajian->total_potongan ?? $penggajian->total_kasbon ?? 0;
|
||||
$penggajian->update([
|
||||
'total_ongkos_pekerjaan' => $totalOngkos,
|
||||
'gaji_bersih' => ($totalOngkos - $biayaMakan) - $potongan,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kasbon extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($kasbon) {
|
||||
if ($kasbon->tanggal_kasbon) {
|
||||
$date = \Carbon\Carbon::parse($kasbon->tanggal_kasbon);
|
||||
$kasbon->periode_bulan = $date->month;
|
||||
$kasbon->periode_tahun = $date->year;
|
||||
}
|
||||
if (auth()->check()) {
|
||||
$kasbon->diinput_oleh = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'kasbons';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id_kasbon';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'jumlah_kasbon',
|
||||
'tanggal_kasbon',
|
||||
'periode_bulan',
|
||||
'periode_tahun',
|
||||
'keperluan',
|
||||
'keterangan_detail',
|
||||
'metode_pemberian',
|
||||
'diinput_oleh',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'jumlah_kasbon' => 'decimal:2',
|
||||
'tanggal_kasbon' => 'date',
|
||||
'status' => 'string',
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [];
|
||||
|
||||
/**
|
||||
* Status constants
|
||||
*/
|
||||
const STATUS_LUNAS = 'lunas';
|
||||
const STATUS_BELUM_LUNAS = 'belum_lunas';
|
||||
|
||||
/**
|
||||
* Get all available status options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStatusOptions()
|
||||
{
|
||||
return [
|
||||
self::STATUS_LUNAS => 'Lunas',
|
||||
self::STATUS_BELUM_LUNAS => 'Belum Lunas'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk filter berdasarkan status
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $status
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeByStatus($query, $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk kasbon yang belum lunas
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeBelumLunas($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_BELUM_LUNAS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk kasbon yang sudah lunas
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeLunas($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_LUNAS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk format jumlah kasbon dalam rupiah
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJumlahKasbonFormatAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->jumlah_kasbon, 0, ',', '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk format tanggal kasbon
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTanggalKasbonFormatAttribute()
|
||||
{
|
||||
return $this->tanggal_kasbon ? $this->tanggal_kasbon->format('d/m/Y') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk status dalam bahasa Indonesia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatusLabelAttribute()
|
||||
{
|
||||
$statusOptions = self::getStatusOptions();
|
||||
return $statusOptions[$this->status] ?? $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutator untuk format jumlah kasbon sebelum disimpan
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function setJumlahKasbonAttribute($value)
|
||||
{
|
||||
// Hapus format rupiah jika ada
|
||||
$cleanValue = str_replace(['Rp', '.', ',', ' '], '', $value);
|
||||
$this->attributes['jumlah_kasbon'] = (float) $cleanValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor untuk keterangan (alias keperluan)
|
||||
*/
|
||||
public function getKeteranganAttribute()
|
||||
{
|
||||
return $this->keperluan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke Teknisi
|
||||
*/
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Laporan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Tidak menggunakan tabel database karena hanya helper class
|
||||
protected $table = null;
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Get statistics for dashboard
|
||||
*/
|
||||
public static function getStatistics()
|
||||
{
|
||||
return [
|
||||
'total_kasbon' => DB::table('kasbons')->count(),
|
||||
'total_teknisi' => DB::table('teknisis')->count(),
|
||||
'total_pekerjaan' => DB::table('penugasans')->count(),
|
||||
'total_absensi' => DB::table('absensis')
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->count(),
|
||||
|
||||
// Kasbon statistics
|
||||
'total_lunas' => DB::table('kasbons')
|
||||
->where('status', 'lunas')
|
||||
->sum('jumlah_kasbon'),
|
||||
'total_belum_lunas' => DB::table('kasbons')
|
||||
->where('status', 'belum_lunas')
|
||||
->sum('jumlah_kasbon'),
|
||||
|
||||
// Teknisi statistics
|
||||
'teknisi_aktif' => DB::table('teknisis')
|
||||
->where('status', 'aktif')
|
||||
->count(),
|
||||
'teknisi_nonaktif' => DB::table('teknisis')
|
||||
->where('status', 'nonaktif')
|
||||
->count(),
|
||||
|
||||
// Absensi statistics
|
||||
'hadir' => DB::table('absensis')
|
||||
->where('status', 'hadir')
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->count(),
|
||||
'izin' => DB::table('absensis')
|
||||
->where('status', 'izin')
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->count(),
|
||||
'sakit' => DB::table('absensis')
|
||||
->where('status', 'sakit')
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->count(),
|
||||
'alpha' => DB::table('absensis')
|
||||
->where('status', 'alpha')
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->count(),
|
||||
|
||||
// Pekerjaan statistics - using penugasans table
|
||||
'selesai' => DB::table('penugasans')
|
||||
->where('status_pekerjaan', 'selesai')
|
||||
->count(),
|
||||
'progress' => DB::table('penugasans')
|
||||
->where('status_pekerjaan', 'proses')
|
||||
->count(),
|
||||
'pending' => DB::table('penugasans')
|
||||
->where('status_pekerjaan', 'pending')
|
||||
->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get kasbon data with filters
|
||||
*/
|
||||
public static function getKasbonData($filters = [])
|
||||
{
|
||||
$query = DB::table('kasbons')
|
||||
->leftJoin('teknisis', 'kasbons.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select(
|
||||
'kasbons.*',
|
||||
'teknisis.nama as nama_teknisi'
|
||||
);
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where(function($q) use ($filters) {
|
||||
$q->where('teknisis.nama', 'like', '%' . $filters['search'] . '%')
|
||||
->orWhere('kasbons.keperluan', 'like', '%' . $filters['search'] . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$query->whereDate('kasbons.tanggal_kasbon', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$query->whereDate('kasbons.tanggal_kasbon', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('kasbons.status', $filters['status']);
|
||||
}
|
||||
|
||||
if (!empty($filters['id_teknisi'])) {
|
||||
$query->where('kasbons.id_teknisi', $filters['id_teknisi']);
|
||||
}
|
||||
|
||||
return $query->orderBy('kasbons.tanggal_kasbon', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get teknisi data with filters
|
||||
*/
|
||||
public static function getTeknisiData($filters = [])
|
||||
{
|
||||
// Use raw SQL for groupBy to avoid MySQL strict mode issues
|
||||
$query = DB::table('teknisis')
|
||||
->leftJoin('absensis', function($join) use ($filters) {
|
||||
$join->on('teknisis.id_teknisi', '=', 'absensis.id_teknisi');
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$join->whereDate('absensis.tanggal', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$join->whereDate('absensis.tanggal', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
})
|
||||
->select(
|
||||
'teknisis.id_teknisi',
|
||||
'teknisis.nama',
|
||||
'teknisis.status',
|
||||
DB::raw('COUNT(absensis.id_absensi) as total_absensi'),
|
||||
DB::raw('COUNT(CASE WHEN absensis.status = "hadir" THEN 1 END) as hadir'),
|
||||
DB::raw('COUNT(CASE WHEN absensis.status = "izin" THEN 1 END) as izin'),
|
||||
DB::raw('COUNT(CASE WHEN absensis.status = "sakit" THEN 1 END) as sakit'),
|
||||
DB::raw('COUNT(CASE WHEN absensis.status = "alpha" THEN 1 END) as alpha')
|
||||
)
|
||||
->groupBy('teknisis.id_teknisi', 'teknisis.nama', 'teknisis.status');
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('teknisis.nama', 'like', '%' . $filters['search'] . '%');
|
||||
}
|
||||
|
||||
return $query->orderBy('teknisis.nama', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get absensi data with filters
|
||||
*/
|
||||
public static function getAbsensiData($filters = [])
|
||||
{
|
||||
$query = DB::table('absensis')
|
||||
->leftJoin('teknisis', 'absensis.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select(
|
||||
'absensis.*',
|
||||
'teknisis.nama as nama_teknisi'
|
||||
);
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('teknisis.nama', 'like', '%' . $filters['search'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$query->whereDate('absensis.tanggal', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$query->whereDate('absensis.tanggal', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('absensis.status', $filters['status']);
|
||||
}
|
||||
|
||||
if (!empty($filters['id_teknisi'])) {
|
||||
$query->where('absensis.id_teknisi', $filters['id_teknisi']);
|
||||
}
|
||||
|
||||
return $query->orderBy('absensis.tanggal', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pekerjaan data with filters
|
||||
*/
|
||||
public static function getPekerjaanData($filters = [])
|
||||
{
|
||||
$query = DB::table('penugasans')
|
||||
->leftJoin('teknisis', 'penugasans.id_teknisi', '=', 'teknisis.id_teknisi')
|
||||
->select(
|
||||
'penugasans.*',
|
||||
'teknisis.nama as nama_teknisi'
|
||||
);
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where(function($q) use ($filters) {
|
||||
$q->where('teknisis.nama', 'like', '%' . $filters['search'] . '%')
|
||||
->orWhere('penugasans.jenis_pekerjaan', 'like', '%' . $filters['search'] . '%')
|
||||
->orWhere('penugasans.catatan_admin', 'like', '%' . $filters['search'] . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_dari'])) {
|
||||
$query->whereDate('penugasans.tanggal_mulai', '>=', $filters['tanggal_dari']);
|
||||
}
|
||||
|
||||
if (!empty($filters['tanggal_sampai'])) {
|
||||
$query->whereDate('penugasans.tanggal_diselesaikan', '<=', $filters['tanggal_sampai']);
|
||||
}
|
||||
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('penugasans.status_pekerjaan', $filters['status']);
|
||||
}
|
||||
|
||||
if (!empty($filters['id_teknisi'])) {
|
||||
$query->where('penugasans.id_teknisi', $filters['id_teknisi']);
|
||||
}
|
||||
|
||||
return $query->orderBy('penugasans.created_at', 'desc');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,383 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Penggajian extends Model
|
||||
{
|
||||
// use HasFactory, SoftDeletes;
|
||||
|
||||
/**
|
||||
* Get nama bulan dari angka 1-12
|
||||
*/
|
||||
public static function getNamaBulan($angka)
|
||||
{
|
||||
$bulan = [
|
||||
1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April',
|
||||
5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus',
|
||||
9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember'
|
||||
];
|
||||
return $bulan[(int)$angka] ?? 'N/A';
|
||||
}
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected $table = 'penggajians';
|
||||
|
||||
/**
|
||||
* The primary key for the model.
|
||||
*/
|
||||
protected $primaryKey = 'id_penggajian';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'periode_bulan',
|
||||
'periode_tahun',
|
||||
'tanggal_penggajian',
|
||||
'total_ongkos_pekerjaan',
|
||||
'jumlah_penugasan_selesai',
|
||||
'jumlah_hari_kerja',
|
||||
'total_kasbon',
|
||||
'biaya_makan',
|
||||
'total_potongan',
|
||||
'gaji_bersih',
|
||||
'status_pembayaran',
|
||||
'metode_pembayaran',
|
||||
'tanggal_dibayar',
|
||||
'bukti_pembayaran',
|
||||
'catatan',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal_penggajian' => 'date',
|
||||
'jumlah_hari_kerja' => 'integer',
|
||||
'total_ongkos_pekerjaan' => 'decimal:2',
|
||||
'total_kasbon' => 'decimal:2',
|
||||
'biaya_makan' => 'decimal:2',
|
||||
'total_potongan' => 'decimal:2',
|
||||
'gaji_bersih' => 'decimal:2',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*/
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Status pembayaran constants
|
||||
*/
|
||||
const STATUS_BELUM_BAYAR = 'belum_bayar';
|
||||
const STATUS_SUDAH_BAYAR = 'sudah_bayar';
|
||||
|
||||
/**
|
||||
* Get all available status pembayaran
|
||||
*/
|
||||
public static function getStatusPembayaran()
|
||||
{
|
||||
return [
|
||||
self::STATUS_BELUM_BAYAR => 'Belum Bayar',
|
||||
self::STATUS_SUDAH_BAYAR => 'Sudah Bayar',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship with Teknisi
|
||||
*/
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship with DetailPenggajian
|
||||
*/
|
||||
public function detailPenggajian()
|
||||
{
|
||||
return $this->hasMany(DetailPenggajian::class, 'id_penggajian', 'id_penggajian');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for filtering by periode
|
||||
*/
|
||||
public function scopeByPeriode($query, $bulan = null, $tahun = null)
|
||||
{
|
||||
if ($bulan) {
|
||||
$query->where('periode_bulan', $bulan);
|
||||
}
|
||||
if ($tahun) {
|
||||
$query->where('periode_tahun', $tahun);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for filtering by status pembayaran
|
||||
*/
|
||||
public function scopeByStatus($query, $status)
|
||||
{
|
||||
return $query->where('status_pembayaran', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for belum bayar
|
||||
*/
|
||||
public function scopeBelumBayar($query)
|
||||
{
|
||||
return $query->where('status_pembayaran', self::STATUS_BELUM_BAYAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for sudah bayar
|
||||
*/
|
||||
public function scopeSudahBayar($query)
|
||||
{
|
||||
return $query->where('status_pembayaran', self::STATUS_SUDAH_BAYAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for current month
|
||||
*/
|
||||
public function scopeCurrentMonth($query)
|
||||
{
|
||||
return $query->where('periode_bulan', date('n'))
|
||||
->where('periode_tahun', date('Y'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for latest periode
|
||||
*/
|
||||
public function scopeLatestPeriode($query)
|
||||
{
|
||||
return $query->orderBy('periode_tahun', 'desc')
|
||||
->orderBy('periode_bulan', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted periode
|
||||
*/
|
||||
public function getFormattedPeriodeAttribute()
|
||||
{
|
||||
$bulan = Carbon::create()->month($this->periode_bulan)->format('F');
|
||||
return $bulan . ' ' . $this->periode_tahun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get periode short format
|
||||
*/
|
||||
public function getPeriodeShortAttribute()
|
||||
{
|
||||
$bulan = Carbon::create()->month($this->periode_bulan)->format('M');
|
||||
return $bulan . ' ' . $this->periode_tahun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status pembayaran label
|
||||
*/
|
||||
public function getStatusLabelAttribute()
|
||||
{
|
||||
$statuses = self::getStatusPembayaran();
|
||||
return $statuses[$this->status_pembayaran] ?? $this->status_pembayaran;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status badge class
|
||||
*/
|
||||
public function getStatusBadgeClassAttribute()
|
||||
{
|
||||
switch ($this->status_pembayaran) {
|
||||
case self::STATUS_SUDAH_BAYAR:
|
||||
return 'bg-success';
|
||||
case self::STATUS_BELUM_BAYAR:
|
||||
default:
|
||||
return 'bg-warning';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if already paid
|
||||
*/
|
||||
public function isPaid()
|
||||
{
|
||||
return $this->status_pembayaran === self::STATUS_SUDAH_BAYAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if not paid yet
|
||||
*/
|
||||
public function isUnpaid()
|
||||
{
|
||||
return $this->status_pembayaran === self::STATUS_BELUM_BAYAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark as paid
|
||||
*/
|
||||
public function markAsPaid()
|
||||
{
|
||||
$this->update([
|
||||
'status_pembayaran' => self::STATUS_SUDAH_BAYAR
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark as unpaid
|
||||
*/
|
||||
public function markAsUnpaid()
|
||||
{
|
||||
$this->update([
|
||||
'status_pembayaran' => self::STATUS_BELUM_BAYAR
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate total from detail penggajian
|
||||
*/
|
||||
public function calculateTotals()
|
||||
{
|
||||
$details = $this->detailPenggajian;
|
||||
|
||||
$totals = [
|
||||
'subtotal' => $details->sum('subtotal'),
|
||||
'total_unit' => $details->sum('jumlah_unit'),
|
||||
];
|
||||
|
||||
return $totals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted currency attributes
|
||||
*/
|
||||
public function getFormattedGajiKotorAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->total_ongkos_pekerjaan, 0, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedBiayaMakanAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->biaya_makan, 0, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedTotalKasbonAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->total_kasbon, 0, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedGajiBersihAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->gaji_bersih, 0, ',', '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get potongan (total kasbon)
|
||||
*/
|
||||
public function getPotonganAttribute()
|
||||
{
|
||||
return $this->total_kasbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted potongan
|
||||
*/
|
||||
public function getFormattedPotonganAttribute()
|
||||
{
|
||||
return 'Rp ' . number_format($this->potongan, 0, ',', '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to get summary by periode
|
||||
*/
|
||||
public static function getSummaryByPeriode($bulan = null, $tahun = null, $status = null)
|
||||
{
|
||||
$query = self::with('teknisi');
|
||||
|
||||
if ($bulan) {
|
||||
$query->where('periode_bulan', $bulan);
|
||||
}
|
||||
if ($tahun) {
|
||||
$query->where('periode_tahun', $tahun);
|
||||
}
|
||||
if ($status) {
|
||||
$query->where('status_pembayaran', $status);
|
||||
}
|
||||
|
||||
$data = $query->get();
|
||||
|
||||
return [
|
||||
'total_teknisi' => $data->count(),
|
||||
'total_gaji' => $data->sum('total_ongkos_pekerjaan'),
|
||||
'total_kasbon' => $data->sum('total_kasbon'),
|
||||
'total_biaya_makan' => $data->sum('biaya_makan'),
|
||||
'gaji_bersih' => $data->sum('gaji_bersih'),
|
||||
'belum_bayar' => $data->where('status_pembayaran', self::STATUS_BELUM_BAYAR)->count(),
|
||||
'sudah_bayar' => $data->where('status_pembayaran', self::STATUS_SUDAH_BAYAR)->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to check if periode already exists for teknisi
|
||||
*/
|
||||
public static function isPeriodeExists($idTeknisi, $bulan, $tahun)
|
||||
{
|
||||
return self::where('id_teknisi', $idTeknisi)
|
||||
->where('periode_bulan', $bulan)
|
||||
->where('periode_tahun', $tahun)
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to get latest periode
|
||||
*/
|
||||
public static function getLatestPeriode()
|
||||
{
|
||||
$latest = self::orderBy('periode_tahun', 'desc')
|
||||
->orderBy('periode_bulan', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$latest) {
|
||||
return [
|
||||
'bulan' => date('n'),
|
||||
'tahun' => date('Y')
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'bulan' => $latest->periode_bulan,
|
||||
'tahun' => $latest->periode_tahun
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot method
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// Auto calculate gaji_bersih before saving
|
||||
static::saving(function ($penggajian) {
|
||||
$ongkos = $penggajian->total_ongkos_pekerjaan ?? 0;
|
||||
$makan = $penggajian->biaya_makan ?? 0;
|
||||
$potongan = $penggajian->total_potongan ?? 0;
|
||||
|
||||
// Gaji Bersih = Ongkos - Uang Makan - Potongan Kasbon
|
||||
// (Uang makan sekarang dihitung sebagai potongan)
|
||||
$penggajian->gaji_bersih = $ongkos - $makan - $potongan;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Penugasan extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'penugasans';
|
||||
protected $primaryKey = 'id_penugasan';
|
||||
|
||||
protected $fillable = [
|
||||
'id_teknisi',
|
||||
'foto_surat',
|
||||
'tanggal_diberikan',
|
||||
'catatan_admin',
|
||||
'alamat_lokasi',
|
||||
'nama_pelanggan',
|
||||
'no_sambungan',
|
||||
|
||||
// Detail diisi teknisi via mobile
|
||||
'jenis_pekerjaan',
|
||||
'dimensi_pipa',
|
||||
'jarak_meter',
|
||||
'jumlah_unit',
|
||||
'jumlah_titik',
|
||||
'pakai_pipa_besi',
|
||||
'jenis_pengangkatan',
|
||||
'detail_pekerjaan',
|
||||
|
||||
// Ongkos
|
||||
'id_tarif',
|
||||
'total_nilai_pekerjaan',
|
||||
|
||||
// Status
|
||||
'status_pekerjaan',
|
||||
'tanggal_mulai',
|
||||
'tanggal_diselesaikan',
|
||||
|
||||
// Garansi
|
||||
'tanggal_garansi_mulai',
|
||||
'tanggal_garansi_selesai',
|
||||
'catatan_garansi',
|
||||
|
||||
// Foto bukti pekerjaan (dari teknisi)
|
||||
'foto_sebelum',
|
||||
'foto_sesudah',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tanggal_diberikan' => 'date',
|
||||
'tanggal_mulai' => 'datetime',
|
||||
'tanggal_diselesaikan' => 'datetime',
|
||||
'tanggal_garansi_mulai' => 'date',
|
||||
'tanggal_garansi_selesai' => 'date',
|
||||
'jarak_meter' => 'decimal:2',
|
||||
'total_nilai_pekerjaan' => 'decimal:2',
|
||||
'pakai_pipa_besi' => 'boolean',
|
||||
];
|
||||
|
||||
// ===================================
|
||||
// RELATIONSHIPS
|
||||
// ===================================
|
||||
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
public function teknisiPertama()
|
||||
{
|
||||
return $this->teknisi();
|
||||
}
|
||||
|
||||
public function tarif()
|
||||
{
|
||||
return $this->belongsTo(TarifPekerjaan::class, 'id_tarif', 'id_tarif');
|
||||
}
|
||||
|
||||
public function timTeknisi()
|
||||
{
|
||||
return $this->hasMany(TimTeknisiPenugasan::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PenugasanItem::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// ACCESSOR - FOTO URL
|
||||
// ===================================
|
||||
|
||||
public function getFotoSuratUrlAttribute(): ?string
|
||||
{
|
||||
if (!$this->foto_surat) return null;
|
||||
return 'https://ta.myhost.id/E31230906/laravel/public/storage/' . $this->foto_surat;
|
||||
}
|
||||
|
||||
public function getFotoSebelumUrlAttribute(): ?string
|
||||
{
|
||||
if (!$this->foto_sebelum) return null;
|
||||
return 'https://ta.myhost.id/E31230906/laravel/public/storage/' . $this->foto_sebelum;
|
||||
}
|
||||
|
||||
public function getFotoSesudahUrlAttribute(): ?string
|
||||
{
|
||||
if (!$this->foto_sesudah) return null;
|
||||
return 'https://ta.myhost.id/E31230906/laravel/public/storage/' . $this->foto_sesudah;
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// HELPER - TIM
|
||||
// ===================================
|
||||
|
||||
public function getAllTimTeknisi()
|
||||
{
|
||||
return $this->timTeknisi()->with('teknisi')->get();
|
||||
}
|
||||
|
||||
public function countTotalTim(): int
|
||||
{
|
||||
return $this->timTeknisi()->count();
|
||||
}
|
||||
|
||||
public function countTimHadir(): int
|
||||
{
|
||||
return $this->timTeknisi()->where('status_kehadiran', 'hadir')->count();
|
||||
}
|
||||
|
||||
public function getOngkosPerOrang(): float
|
||||
{
|
||||
$jumlahHadir = $this->countTimHadir();
|
||||
if ($jumlahHadir === 0 || !$this->total_nilai_pekerjaan) return 0;
|
||||
return $this->total_nilai_pekerjaan / $jumlahHadir;
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// HELPER - GARANSI
|
||||
// ===================================
|
||||
|
||||
public function setGaransiMeteranAir($tanggalMulai = null)
|
||||
{
|
||||
$mulai = $tanggalMulai ? Carbon::parse($tanggalMulai) : Carbon::now();
|
||||
$this->tanggal_garansi_mulai = $mulai;
|
||||
$this->tanggal_garansi_selesai = $mulai->copy()->addMonths(3);
|
||||
$this->catatan_garansi = 'Garansi 3 bulan untuk pemasangan meteran air (SR)';
|
||||
}
|
||||
|
||||
public function isGaransiAktif(): bool
|
||||
{
|
||||
if (!$this->tanggal_garansi_mulai || !$this->tanggal_garansi_selesai) return false;
|
||||
return now()->between($this->tanggal_garansi_mulai, $this->tanggal_garansi_selesai);
|
||||
}
|
||||
|
||||
public function getSisaHariGaransi(): ?int
|
||||
{
|
||||
if (!$this->tanggal_garansi_selesai) return null;
|
||||
$sisa = now()->diffInDays($this->tanggal_garansi_selesai, false);
|
||||
return $sisa > 0 ? (int)$sisa : 0;
|
||||
}
|
||||
|
||||
public function scopeGaransiAktif($query)
|
||||
{
|
||||
return $query->whereNotNull('tanggal_garansi_mulai')
|
||||
->whereNotNull('tanggal_garansi_selesai')
|
||||
->where('tanggal_garansi_selesai', '>=', now());
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// HELPER - STATUS
|
||||
// ===================================
|
||||
|
||||
public function isDetailLengkap(): bool
|
||||
{
|
||||
return !is_null($this->jenis_pekerjaan);
|
||||
}
|
||||
|
||||
public function isSelesai(): bool
|
||||
{
|
||||
return $this->status_pekerjaan === 'selesai';
|
||||
}
|
||||
|
||||
public function getLabelJenisPekerjaanAttribute(): string
|
||||
{
|
||||
$labels = [
|
||||
'sr' => 'SR (Sambungan Rumah)',
|
||||
'pengembangan_jaringan_pipa' => 'Pengembangan Jaringan Pipa',
|
||||
'pengangkatan' => 'Pengangkatan',
|
||||
'pemasangan_gate_valve' => 'Pemasangan Gate Valve',
|
||||
'gali_urug' => 'Gali Urug',
|
||||
'perbaikan_jaringan_pipa' => 'Perbaikan Jaringan Pipa',
|
||||
'pengecatan_pipa_besi' => 'Pengecatan Pipa Besi',
|
||||
'penyempurnaan_jaringan_pipa' => 'Penyempurnaan Jaringan Pipa',
|
||||
];
|
||||
return $labels[$this->jenis_pekerjaan] ?? '-';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PenugasanItem extends Model
|
||||
{
|
||||
protected $table = 'penugasan_items';
|
||||
protected $primaryKey = 'id_penugasan_item';
|
||||
|
||||
protected $fillable = [
|
||||
'id_penugasan',
|
||||
'id_tarif',
|
||||
'jenis_pekerjaan',
|
||||
'dimensi_pipa',
|
||||
'jarak_meter',
|
||||
'jumlah_unit',
|
||||
'jumlah_titik',
|
||||
'pakai_pipa_besi',
|
||||
'jenis_pengangkatan',
|
||||
'total_nilai_pekerjaan',
|
||||
];
|
||||
|
||||
public function penugasan()
|
||||
{
|
||||
return $this->belongsTo(Penugasan::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
public function tarif()
|
||||
{
|
||||
return $this->belongsTo(TarifPekerjaan::class, 'id_tarif', 'id_tarif');
|
||||
}
|
||||
|
||||
public function getLabelJenisPekerjaanAttribute(): string
|
||||
{
|
||||
$labels = [
|
||||
'sr' => 'SR (Sambungan Rumah)',
|
||||
'pengembangan_jaringan_pipa' => 'Pengembangan Jaringan Pipa',
|
||||
'pengangkatan' => 'Pengangkatan',
|
||||
'pemasangan_gate_valve' => 'Pemasangan Gate Valve',
|
||||
'gali_urug' => 'Gali Urug',
|
||||
'perbaikan_jaringan_pipa' => 'Perbaikan Jaringan Pipa',
|
||||
'pengecatan_pipa_besi' => 'Pengecatan Pipa Besi',
|
||||
'penyempurnaan_jaringan_pipa' => 'Penyempurnaan Jaringan Pipa',
|
||||
];
|
||||
return $labels[$this->jenis_pekerjaan] ?? $this->jenis_pekerjaan;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ProgresKerja extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'progres_kerjas'; // Ubah dari 'progres_kerja' ke 'progres_kerjas'
|
||||
protected $primaryKey = 'id_progres';
|
||||
|
||||
protected $fillable = [
|
||||
'id_penugasan',
|
||||
'id_teknisi',
|
||||
'tugas',
|
||||
'deskripsi_progres',
|
||||
'status_progres',
|
||||
'persentase_pekerjaan',
|
||||
'foto_progress',
|
||||
'tanggal_update'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tanggal_update' => 'datetime',
|
||||
'persentase_pekerjaan' => 'integer',
|
||||
];
|
||||
|
||||
// Status progres options
|
||||
public static $statusProgres = [
|
||||
'belum_mulai' => 'Belum Mulai',
|
||||
'dalam_progres' => 'Dalam Progres',
|
||||
'terhenti' => 'Terhenti',
|
||||
'selesai' => 'Selesai',
|
||||
'ditunda' => 'Ditunda'
|
||||
];
|
||||
|
||||
// Boot method untuk auto update tanggal_update
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->tanggal_update = now();
|
||||
});
|
||||
|
||||
static::updating(function ($model) {
|
||||
$model->tanggal_update = now();
|
||||
});
|
||||
}
|
||||
|
||||
// Relationships
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
public function penugasan()
|
||||
{
|
||||
return $this->belongsTo(Penugasan::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
// Scopes
|
||||
public function scopeByStatus($query, $status)
|
||||
{
|
||||
return $query->where('status_progres', $status);
|
||||
}
|
||||
|
||||
public function scopeByTeknisi($query, $teknisiId)
|
||||
{
|
||||
return $query->where('id_teknisi', $teknisiId);
|
||||
}
|
||||
|
||||
public function scopeByDateRange($query, $startDate = null, $endDate = null)
|
||||
{
|
||||
if ($startDate) {
|
||||
$query->whereDate('tanggal_update', '>=', $startDate);
|
||||
}
|
||||
|
||||
if ($endDate) {
|
||||
$query->whereDate('tanggal_update', '<=', $endDate);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
public function getStatusFormattedAttribute()
|
||||
{
|
||||
return self::$statusProgres[$this->status_progres] ?? 'Unknown';
|
||||
}
|
||||
|
||||
public function getStatusBadgeClassAttribute()
|
||||
{
|
||||
$badgeClasses = [
|
||||
'belum_mulai' => 'badge-secondary',
|
||||
'dalam_progres' => 'badge-primary',
|
||||
'terhenti' => 'badge-danger',
|
||||
'selesai' => 'badge-success',
|
||||
'ditunda' => 'badge-warning'
|
||||
];
|
||||
|
||||
return $badgeClasses[$this->status_progres] ?? 'badge-secondary';
|
||||
}
|
||||
|
||||
public function getTanggalUpdateFormattedAttribute()
|
||||
{
|
||||
return $this->tanggal_update ? $this->tanggal_update->format('d/m/Y H:i') : '-';
|
||||
}
|
||||
|
||||
public function getHasFotoAttribute()
|
||||
{
|
||||
return !empty($this->foto_progress);
|
||||
}
|
||||
|
||||
public function getFotoProgressUrlAttribute()
|
||||
{
|
||||
if ($this->foto_progress) {
|
||||
return asset('storage/progress_photos/' . $this->foto_progress);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getDaysSinceUpdateAttribute()
|
||||
{
|
||||
if ($this->tanggal_update) {
|
||||
return $this->tanggal_update->diffInDays(now());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Methods
|
||||
public function autoUpdateStatus()
|
||||
{
|
||||
$percentage = $this->persentase_pekerjaan;
|
||||
|
||||
if ($percentage == 0) {
|
||||
$newStatus = 'belum_mulai';
|
||||
} elseif ($percentage > 0 && $percentage < 100) {
|
||||
$newStatus = 'dalam_progres';
|
||||
} elseif ($percentage == 100) {
|
||||
$newStatus = 'selesai';
|
||||
} else {
|
||||
return; // No change needed
|
||||
}
|
||||
|
||||
// Only update if status is different
|
||||
if ($this->status_progres !== $newStatus) {
|
||||
$this->update(['status_progres' => $newStatus]);
|
||||
}
|
||||
}
|
||||
|
||||
public function canTransitionTo($newStatus)
|
||||
{
|
||||
$allowedTransitions = [
|
||||
'belum_mulai' => ['dalam_progres', 'ditunda'],
|
||||
'dalam_progres' => ['terhenti', 'selesai', 'ditunda'],
|
||||
'terhenti' => ['dalam_progres', 'ditunda'],
|
||||
'selesai' => [], // Cannot transition from completed
|
||||
'ditunda' => ['belum_mulai', 'dalam_progres']
|
||||
];
|
||||
|
||||
$currentStatus = $this->status_progres;
|
||||
|
||||
return in_array($newStatus, $allowedTransitions[$currentStatus] ?? []);
|
||||
}
|
||||
|
||||
// Static methods
|
||||
public static function getByTeknisi($teknisiId)
|
||||
{
|
||||
return self::with(['teknisi', 'penugasan'])
|
||||
->where('id_teknisi', $teknisiId)
|
||||
->orderBy('tanggal_update', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getRecentUpdates($limit = 10)
|
||||
{
|
||||
return self::with(['teknisi', 'penugasan'])
|
||||
->orderBy('tanggal_update', 'desc')
|
||||
->limit($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getStatistics()
|
||||
{
|
||||
$total = self::count();
|
||||
$byStatus = self::selectRaw('status_progres, COUNT(*) as count')
|
||||
->groupBy('status_progres')
|
||||
->pluck('count', 'status_progres')
|
||||
->toArray();
|
||||
|
||||
$statistics = [
|
||||
'total' => $total,
|
||||
'belum_mulai' => $byStatus['belum_mulai'] ?? 0,
|
||||
'dalam_progres' => $byStatus['dalam_progres'] ?? 0,
|
||||
'terhenti' => $byStatus['terhenti'] ?? 0,
|
||||
'selesai' => $byStatus['selesai'] ?? 0,
|
||||
'ditunda' => $byStatus['ditunda'] ?? 0,
|
||||
];
|
||||
|
||||
// Add percentages
|
||||
if ($total > 0) {
|
||||
$statistics['completion_rate'] = round(($statistics['selesai'] / $total) * 100, 1);
|
||||
$statistics['in_progress_rate'] = round(($statistics['dalam_progres'] / $total) * 100, 1);
|
||||
} else {
|
||||
$statistics['completion_rate'] = 0;
|
||||
$statistics['in_progress_rate'] = 0;
|
||||
}
|
||||
|
||||
return $statistics;
|
||||
}
|
||||
|
||||
public static function getOverdueProgress($days = 7)
|
||||
{
|
||||
return self::with(['teknisi', 'penugasan'])
|
||||
->whereIn('status_progres', ['dalam_progres', 'terhenti'])
|
||||
->where('tanggal_update', '<', now()->subDays($days))
|
||||
->orderBy('tanggal_update', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getProgressSummaryByTeknisi()
|
||||
{
|
||||
return self::with('teknisi')
|
||||
->selectRaw('id_teknisi, status_progres, COUNT(*) as count')
|
||||
->groupBy('id_teknisi', 'status_progres')
|
||||
->get()
|
||||
->groupBy('id_teknisi')
|
||||
->map(function ($items) {
|
||||
$teknisi = $items->first()->teknisi;
|
||||
$summary = [
|
||||
'teknisi_id' => $teknisi->id_teknisi,
|
||||
'teknisi_nama' => $teknisi->nama,
|
||||
'total' => $items->sum('count'),
|
||||
'belum_mulai' => 0,
|
||||
'dalam_progres' => 0,
|
||||
'terhenti' => 0,
|
||||
'selesai' => 0,
|
||||
'ditunda' => 0,
|
||||
];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$summary[$item->status_progres] = $item->count;
|
||||
}
|
||||
|
||||
return $summary;
|
||||
})
|
||||
->values();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
// app/Models/TarifPekerjaan.php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class TarifPekerjaan extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'tarif_pekerjaans';
|
||||
protected $primaryKey = 'id_tarif';
|
||||
|
||||
protected $fillable = [
|
||||
'jenis_pekerjaan',
|
||||
'nama_item',
|
||||
'kode_item',
|
||||
'dimensi_pipa',
|
||||
'tarif_per_unit',
|
||||
'tarif_per_meter',
|
||||
'pakai_pipa_besi',
|
||||
'ada_garansi',
|
||||
'durasi_garansi_bulan',
|
||||
'deskripsi',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tarif_per_unit' => 'decimal:2',
|
||||
'tarif_per_meter' => 'decimal:2',
|
||||
'pakai_pipa_besi' => 'boolean',
|
||||
'ada_garansi' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
// Accessor: ambil harga (tarif_per_unit atau tarif_per_meter)
|
||||
public function getHargaAttribute(): float
|
||||
{
|
||||
return (float) ($this->tarif_per_unit ?? $this->tarif_per_meter ?? 0);
|
||||
}
|
||||
|
||||
// Relationship
|
||||
public function penugasans()
|
||||
{
|
||||
return $this->hasMany(Penugasan::class, 'id_tarif', 'id_tarif');
|
||||
}
|
||||
|
||||
// Scope untuk filter aktif
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
// Scope untuk filter by kategori
|
||||
public function scopeKategori($query, $kategori)
|
||||
{
|
||||
return $query->where('kategori', $kategori);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Teknisi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'teknisis';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id_teknisi';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'tanggal_lahir',
|
||||
'alamat',
|
||||
'email',
|
||||
'no_telephone',
|
||||
'tanggal_masuk',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'tanggal_lahir' => 'date',
|
||||
'tanggal_masuk' => 'date',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [];
|
||||
|
||||
/**
|
||||
* Append computed attributes for API responses.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $appends = ['has_unpaid_kasbon', 'unpaid_kasbon_amount'];
|
||||
|
||||
// ─── Relationships ────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Relationship to Kasbon entries.
|
||||
*/
|
||||
public function kasbons()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Kasbon::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
// ─── Scopes ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Scope a query to only include active teknisi.
|
||||
*/
|
||||
public function scopeAktif($query)
|
||||
{
|
||||
return $query->where('status', 'aktif');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include inactive teknisi.
|
||||
*/
|
||||
public function scopeTidakAktif($query)
|
||||
{
|
||||
return $query->where('status', 'tidak_aktif');
|
||||
}
|
||||
|
||||
// ─── Helper Methods ───────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Check if the teknisi has any unpaid (belum_lunas) kasbon.
|
||||
*/
|
||||
public function hasUnpaidKasbon(): bool
|
||||
{
|
||||
return \App\Models\Kasbon::where('id_teknisi', $this->id_teknisi)
|
||||
->where('status', 'belum_lunas')
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total amount of unpaid kasbon.
|
||||
*/
|
||||
public function unpaidKasbonAmount(): float
|
||||
{
|
||||
return (float) \App\Models\Kasbon::where('id_teknisi', $this->id_teknisi)
|
||||
->where('status', 'belum_lunas')
|
||||
->sum('jumlah_kasbon');
|
||||
}
|
||||
|
||||
// ─── Accessors ────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Accessor for has_unpaid_kasbon attribute.
|
||||
*/
|
||||
public function getHasUnpaidKasbonAttribute(): bool
|
||||
{
|
||||
return $this->hasUnpaidKasbon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for unpaid_kasbon_amount attribute.
|
||||
*/
|
||||
public function getUnpaidKasbonAmountAttribute(): float
|
||||
{
|
||||
return $this->unpaidKasbonAmount();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
// app/Models/TimTeknisiPenugasan.php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TimTeknisiPenugasan extends Model
|
||||
{
|
||||
protected $table = 'tim_teknisi_penugasans';
|
||||
protected $primaryKey = 'id_tim_penugasan';
|
||||
|
||||
protected $fillable = [
|
||||
'id_penugasan',
|
||||
'id_teknisi',
|
||||
'status_kehadiran',
|
||||
'catatan',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
// ===================================
|
||||
// RELATIONSHIPS
|
||||
// ===================================
|
||||
|
||||
/**
|
||||
* Relasi ke penugasan
|
||||
*/
|
||||
public function penugasan()
|
||||
{
|
||||
return $this->belongsTo(Penugasan::class, 'id_penugasan', 'id_penugasan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke teknisi
|
||||
*/
|
||||
public function teknisi()
|
||||
{
|
||||
return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
|
||||
}
|
||||
|
||||
// ===================================
|
||||
// HELPER METHODS
|
||||
// ===================================
|
||||
|
||||
/**
|
||||
* Cek apakah teknisi hadir
|
||||
*/
|
||||
public function isHadir(): bool
|
||||
{
|
||||
return $this->status_kehadiran === 'hadir';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah teknisi tidak hadir
|
||||
*/
|
||||
public function isTidakHadir(): bool
|
||||
{
|
||||
return $this->status_kehadiran === 'tidak_hadir';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah teknisi izin
|
||||
*/
|
||||
public function isIzin(): bool
|
||||
{
|
||||
return $this->status_kehadiran === 'izin';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
date_default_timezone_set('Asia/Jakarta'); // Set timezone Jakarta
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to your application's "home" route.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/dashboard';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any of our classes manually. It's great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Http\Kernel::class,
|
||||
App\Http\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
App\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/tinker": "^2.8",
|
||||
"resend/resend-laravel": "^1.4",
|
||||
"tymon/jwt-auth": "^2.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/breeze": "^1.29",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| your application so that it is used when running Artisan tasks.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'asset_url' => env('ASSET_URL'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. We have gone
|
||||
| ahead and set this to a sensible default for you out of the box.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'Asia/Jakarta',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by the translation service provider. You are free to set this value
|
||||
| to any of the locales which will be supported by the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Fallback Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The fallback locale determines the locale to use when the current one
|
||||
| is not available. You may change the value to correspond to any of
|
||||
| the language folders that are provided through your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'fallback_locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Faker Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This locale will be used by the Faker PHP library when generating fake
|
||||
| data for your database seeds. For example, this will be used to get
|
||||
| localized telephone numbers, street address information and more.
|
||||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is used by the Illuminate encrypter service and should be set
|
||||
| to a random, 32 character string, otherwise these encrypted strings
|
||||
| will not be safe. Please do this before deploying an application!
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => 'file',
|
||||
// 'store' => 'redis',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => ServiceProvider::defaultProviders()->merge([
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be registered when this application
|
||||
| is started. However, feel free to register as many as you wish as
|
||||
| the aliases are "lazy" loaded so they don't hinder performance.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => Facade::defaultAliases()->merge([
|
||||
// 'Example' => App\Facades\Example::class,
|
||||
])->toArray(),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default authentication "guard" and password
|
||||
| reset options for your application. You may change these defaults
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => 'web',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| here which uses session storage and the Eloquent user provider.
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
|
||||
// Guard untuk API dengan JWT (digunakan untuk Teknisi Mobile App)
|
||||
'api' => [
|
||||
'driver' => 'jwt',
|
||||
'provider' => 'akun_teknisi',
|
||||
'hash' => false,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| sources which represent each model / table. These sources may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
],
|
||||
|
||||
// Provider untuk Akun Teknisi (Mobile App)
|
||||
'akun_teknisi' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\AkunTeknisi::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => 'password_reset_tokens',
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| times out and the user is prompted to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => 10800,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Broadcaster
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default broadcaster that will be used by the
|
||||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "ably", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the broadcast connections that will be used
|
||||
| to broadcast events to other systems or over websockets. Samples of
|
||||
| each available type of connection are provided inside this array.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'pusher' => [
|
||||
'driver' => 'pusher',
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
|
||||
],
|
||||
'client_options' => [
|
||||
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
|
||||
],
|
||||
],
|
||||
|
||||
'ably' => [
|
||||
'driver' => 'ably',
|
||||
'key' => env('ABLY_KEY'),
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache connection that gets used while
|
||||
| using this caching library. This connection is used when another is
|
||||
| not explicitly specified when executing a given caching function.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "apc", "array", "database", "file",
|
||||
| "memcached", "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'apc' => [
|
||||
'driver' => 'apc',
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'cache',
|
||||
'connection' => null,
|
||||
'lock_connection' => null,
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'cache',
|
||||
'lock_connection' => 'default',
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
|
||||
| stores there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure your settings for cross-origin resource sharing
|
||||
| or "CORS". This determines what cross-origin operations may execute
|
||||
| in web browsers. You are free to adjust these settings as needed.
|
||||
|
|
||||
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => ['api/*', 'sanctum/csrf-cookie', 'storage/*'],
|
||||
|
||||
'allowed_methods' => ['*'],
|
||||
|
||||
'allowed_origins' => ['*'],
|
||||
|
||||
'allowed_origins_patterns' => [],
|
||||
|
||||
'allowed_headers' => ['*'],
|
||||
|
||||
'exposed_headers' => [],
|
||||
|
||||
'max_age' => 0,
|
||||
|
||||
'supports_credentials' => false,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Hash Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default hash driver that will be used to hash
|
||||
| passwords for your application. By default, the bcrypt algorithm is
|
||||
| used; however, you remain free to modify this option if you wish.
|
||||
|
|
||||
| Supported: "bcrypt", "argon", "argon2id"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => 'bcrypt',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bcrypt Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Bcrypt algorithm. This will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'bcrypt' => [
|
||||
'rounds' => env('BCRYPT_ROUNDS', 12),
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Argon Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Argon algorithm. These will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'argon' => [
|
||||
'memory' => 65536,
|
||||
'threads' => 1,
|
||||
'time' => 4,
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of jwt-auth.
|
||||
*
|
||||
* (c) Sean Tymon <tymon148@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Authentication Secret
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Don't forget to set this in your .env file, as it will be used to sign
|
||||
| your tokens. A helper command is provided for this:
|
||||
| `php artisan jwt:secret`
|
||||
|
|
||||
| Note: This will be used for Symmetric algorithms only (HMAC),
|
||||
| since RSA and ECDSA use a private/public key combo (See below).
|
||||
|
|
||||
*/
|
||||
|
||||
'secret' => env('JWT_SECRET', 'HdykYAkpGa4pOREb4vbddz16ujQkqMxBvWdDg4F0fHEwISnJp8asJiDfBWG8qT5V'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Authentication Keys
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The algorithm you are using, will determine whether your tokens are
|
||||
| signed with a random string (defined in `JWT_SECRET`) or using the
|
||||
| following public & private keys.
|
||||
|
|
||||
| Symmetric Algorithms:
|
||||
| HS256, HS384 & HS512 will use `JWT_SECRET`.
|
||||
|
|
||||
| Asymmetric Algorithms:
|
||||
| RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below.
|
||||
|
|
||||
*/
|
||||
|
||||
'keys' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Public Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A path or resource to your public key.
|
||||
|
|
||||
| E.g. 'file://path/to/public/key'
|
||||
|
|
||||
*/
|
||||
|
||||
'public' => env('JWT_PUBLIC_KEY'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Private Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A path or resource to your private key.
|
||||
|
|
||||
| E.g. 'file://path/to/private/key'
|
||||
|
|
||||
*/
|
||||
|
||||
'private' => env('JWT_PRIVATE_KEY'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Passphrase
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The passphrase for your private key. Can be null if none set.
|
||||
|
|
||||
*/
|
||||
|
||||
'passphrase' => env('JWT_PASSPHRASE'),
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT time to live
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the length of time (in minutes) that the token will be valid for.
|
||||
| Defaults to 1 hour.
|
||||
|
|
||||
| You can also set this to null, to yield a never expiring token.
|
||||
| Some people may want this behaviour for e.g. a mobile app.
|
||||
| This is not particularly recommended, so make sure you have appropriate
|
||||
| systems in place to revoke the token if necessary.
|
||||
| Notice: If you set this to null you should remove 'exp' element from 'required_claims' list.
|
||||
|
|
||||
*/
|
||||
|
||||
'ttl' => env('JWT_TTL', 60),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Refresh time to live
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the length of time (in minutes) that the token can be refreshed
|
||||
| within. I.E. The user can refresh their token within a 2 week window of
|
||||
| the original token being created until they must re-authenticate.
|
||||
| Defaults to 2 weeks.
|
||||
|
|
||||
| You can also set this to null, to yield an infinite refresh time.
|
||||
| Some may want this instead of never expiring tokens for e.g. a mobile app.
|
||||
| This is not particularly recommended, so make sure you have appropriate
|
||||
| systems in place to revoke the token if necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'refresh_ttl' => env('JWT_REFRESH_TTL', 20160),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT hashing algorithm
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the hashing algorithm that will be used to sign the token.
|
||||
|
|
||||
*/
|
||||
|
||||
'algo' => env('JWT_ALGO', Tymon\JWTAuth\Providers\JWT\Provider::ALGO_HS256),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Required Claims
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the required claims that must exist in any token.
|
||||
| A TokenInvalidException will be thrown if any of these claims are not
|
||||
| present in the payload.
|
||||
|
|
||||
*/
|
||||
|
||||
'required_claims' => [
|
||||
'iss',
|
||||
'iat',
|
||||
'exp',
|
||||
'nbf',
|
||||
'sub',
|
||||
'jti',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Persistent Claims
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the claim keys to be persisted when refreshing a token.
|
||||
| `sub` and `iat` will automatically be persisted, in
|
||||
| addition to the these claims.
|
||||
|
|
||||
| Note: If a claim does not exist then it will be ignored.
|
||||
|
|
||||
*/
|
||||
|
||||
'persistent_claims' => [
|
||||
// 'foo',
|
||||
// 'bar',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Lock Subject
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This will determine whether a `prv` claim is automatically added to
|
||||
| the token. The purpose of this is to ensure that if you have multiple
|
||||
| authentication models e.g. `App\User` & `App\OtherPerson`, then we
|
||||
| should prevent one authentication request from impersonating another,
|
||||
| if 2 tokens happen to have the same id across the 2 different models.
|
||||
|
|
||||
| Under specific circumstances, you may want to disable this behaviour
|
||||
| e.g. if you only have one authentication model, then you would save
|
||||
| a little on token size.
|
||||
|
|
||||
*/
|
||||
|
||||
'lock_subject' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Leeway
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This property gives the jwt timestamp claims some "leeway".
|
||||
| Meaning that if you have any unavoidable slight clock skew on
|
||||
| any of your servers then this will afford you some level of cushioning.
|
||||
|
|
||||
| This applies to the claims `iat`, `nbf` and `exp`.
|
||||
|
|
||||
| Specify in seconds - only if you know you need it.
|
||||
|
|
||||
*/
|
||||
|
||||
'leeway' => env('JWT_LEEWAY', 0),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Blacklist Enabled
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| In order to invalidate tokens, you must have the blacklist enabled.
|
||||
| If you do not want or need this functionality, then set this to false.
|
||||
|
|
||||
*/
|
||||
|
||||
'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Blacklist Grace Period
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| When multiple concurrent requests are made with the same JWT,
|
||||
| it is possible that some of them fail, due to token regeneration
|
||||
| on every request.
|
||||
|
|
||||
| Set grace period in seconds to prevent parallel request failure.
|
||||
|
|
||||
*/
|
||||
|
||||
'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cookies encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default Laravel encrypt cookies for security reason.
|
||||
| If you decide to not decrypt cookies, you will have to configure Laravel
|
||||
| to not encrypt your cookie token by adding its name into the $except
|
||||
| array available in the middleware "EncryptCookies" provided by Laravel.
|
||||
| see https://laravel.com/docs/master/responses#cookies-and-encryption
|
||||
| for details.
|
||||
|
|
||||
| Set it to true if you want to decrypt cookies.
|
||||
|
|
||||
*/
|
||||
|
||||
'decrypt_cookies' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the various providers used throughout the package.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to create and decode the tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to authenticate users.
|
||||
|
|
||||
*/
|
||||
|
||||
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Storage Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to store tokens in the blacklist.
|
||||
|
|
||||
*/
|
||||
|
||||
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that gets used when writing
|
||||
| messages to the logs. The name specified in this option should match
|
||||
| one of the channels defined in the "channels" configuration array.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Out of
|
||||
| the box, Laravel uses the Monolog PHP logging library. This gives
|
||||
| you a variety of powerful log handlers / formatters to utilize.
|
||||
|
|
||||
| Available Drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog",
|
||||
| "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 14,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => 'Laravel Log',
|
||||
'emoji' => ':boom:',
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => LOG_USER,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send any email
|
||||
| messages sent by your application. Alternative mailers may be setup
|
||||
| and used as needed; however, this mailer will be used by default.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers to be used while
|
||||
| sending an e-mail. You will specify which one you are using for your
|
||||
| mailers below. You are free to add additional mailers as required.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "log", "array", "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
'stream' => [
|
||||
'ssl' => [
|
||||
'allow_self_signed' => true,
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => null,
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all e-mails sent by your application to be sent from
|
||||
| the same address. Here, you may specify a name and address that is
|
||||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Markdown Mail Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you are using Markdown based email rendering, you may configure your
|
||||
| theme and component paths here, allowing you to customize the design
|
||||
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||
|
|
||||
*/
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue API supports an assortment of back-ends via a single
|
||||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for every one. Here you may define a default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'sync'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection information for each server that
|
||||
| is used by your application. A default configuration has been added
|
||||
| for each back-end shipped with Laravel. You are free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control which database and table are used to store the jobs that
|
||||
| have failed. You may change them to any database / table you wish.
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Stateful Domains
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Requests from the following domains / hosts will receive stateful API
|
||||
| authentication cookies. Typically, these should include your local
|
||||
| and production domains which access your API via a frontend SPA.
|
||||
|
|
||||
*/
|
||||
|
||||
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
|
||||
'%s%s',
|
||||
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
|
||||
Sanctum::currentApplicationUrlWithPort()
|
||||
))),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array contains the authentication guards that will be checked when
|
||||
| Sanctum is trying to authenticate a request. If none of these guards
|
||||
| are able to authenticate the request, Sanctum will use the bearer
|
||||
| token that's present on an incoming request for authentication.
|
||||
|
|
||||
*/
|
||||
|
||||
'guard' => ['web'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expiration Minutes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value controls the number of minutes until an issued token will be
|
||||
| considered expired. This will override any values set in the token's
|
||||
| "expires_at" attribute, but first-party sessions are not affected.
|
||||
|
|
||||
*/
|
||||
|
||||
'expiration' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Token Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sanctum can prefix new tokens in order to take advantage of numerous
|
||||
| security scanning initiatives maintained by open source platforms
|
||||
| that notify developers if they commit tokens into repositories.
|
||||
|
|
||||
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
|
||||
|
|
||||
*/
|
||||
|
||||
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When authenticating your first-party SPA with Sanctum you may need to
|
||||
| customize some of the middleware Sanctum uses while processing the
|
||||
| request. You may change the middleware listed below as required.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
|
||||
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'recaptcha' => [
|
||||
'site_key' => env('RECAPTCHA_SITE_KEY'),
|
||||
'secret_key' => env('RECAPTCHA_SECRET_KEY'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default session "driver" that will be used on
|
||||
| requests. By default, we will use the lightweight native driver but
|
||||
| you may specify any of the other wonderful drivers provided here.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to immediately expire on the browser closing, set that option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it is stored. All encryption will be run
|
||||
| automatically by Laravel and you can use the Session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the native session driver, we need a location where session
|
||||
| files may be stored. A default has been set for you but a different
|
||||
| location may be specified. This is only needed for file sessions.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table we
|
||||
| should use to manage the sessions. Of course, a sensible default is
|
||||
| provided for you; however, you are free to change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using one of the framework's cache driven session backends you may
|
||||
| list a cache store that should be used for these sessions. This value
|
||||
| must match with one of the application's configured cache "stores".
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the cookie used to identify a session
|
||||
| instance by ID. The name specified here will get used every time a
|
||||
| new session cookie is created by the framework for every driver.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application but you are free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the domain of the cookie used to identify a session
|
||||
| in your application. This will determine which domains the cookie is
|
||||
| available to in your application. A sensible default has been set.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. You are free to modify this option if needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" since this is a secure default value.
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => false,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| View Storage Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Most templating systems load templates from disk. Here you may specify
|
||||
| an array of paths that should be checked for your views. Of course
|
||||
| the usual Laravel view path has already been registered for you.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Compiled View Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines where all the compiled Blade templates will be
|
||||
| stored for your application. Typically, this is within the storage
|
||||
| directory. However, as usual, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'compiled' => env(
|
||||
'VIEW_COMPILED_PATH',
|
||||
realpath(storage_path('framework/views'))
|
||||
),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1 @@
|
|||
*.sqlite*
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?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::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?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::create('teknisis', function (Blueprint $table) {
|
||||
$table->id('id_teknisi');
|
||||
$table->string('nama', 100);
|
||||
$table->date('tanggal_lahir');
|
||||
$table->text('alamat');
|
||||
$table->string('email', 100)->unique()->nullable();
|
||||
$table->string('no_telephone', 15);
|
||||
$table->date('tanggal_masuk');
|
||||
$table->enum('status', ['aktif', 'tidak_aktif'])->default('aktif');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('teknisis');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* Tabel penggajian untuk teknisi per bulan
|
||||
* Formula SEDERHANA: Total Ongkos Pekerjaan - Kasbon - Biaya Makan = Gaji Bersih
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('penggajians', function (Blueprint $table) {
|
||||
$table->id('id_penggajian');
|
||||
|
||||
// ===================================
|
||||
// IDENTITAS & PERIODE
|
||||
// ===================================
|
||||
$table->unsignedBigInteger('id_teknisi')
|
||||
->comment('ID teknisi yang digaji');
|
||||
|
||||
$table->integer('periode_bulan')
|
||||
->check('periode_bulan >= 1 AND periode_bulan <= 12')
|
||||
->comment('Bulan periode gaji (1-12)');
|
||||
|
||||
$table->year('periode_tahun')
|
||||
->comment('Tahun periode gaji');
|
||||
|
||||
$table->date('tanggal_penggajian')
|
||||
->comment('Tanggal gaji dihitung/dibuat');
|
||||
|
||||
// ===================================
|
||||
// PENDAPATAN (HANYA ONGKOS PEKERJAAN)
|
||||
// ===================================
|
||||
$table->decimal('total_ongkos_pekerjaan', 12, 2)
|
||||
->default(0.00)
|
||||
->comment('Total ongkos dari penugasan yang selesai bulan ini (sudah dibagi tim)');
|
||||
|
||||
$table->integer('jumlah_penugasan_selesai')
|
||||
->default(0)
|
||||
->comment('Jumlah penugasan yang diselesaikan bulan ini');
|
||||
|
||||
$table->integer('jumlah_hari_kerja')
|
||||
->default(0)
|
||||
->comment('Jumlah hari kerja efektif bulan ini');
|
||||
|
||||
// ===================================
|
||||
// POTONGAN (HANYA KASBON & BIAYA MAKAN)
|
||||
// ===================================
|
||||
$table->decimal('total_kasbon', 12, 2)
|
||||
->default(0.00)
|
||||
->comment('Total kasbon yang diambil bulan ini');
|
||||
|
||||
$table->decimal('biaya_makan', 12, 2)
|
||||
->default(0.00)
|
||||
->comment('Biaya makan yang dipotong dari gaji (hari kerja × tarif makan)');
|
||||
|
||||
$table->decimal('total_potongan', 12, 2)
|
||||
->default(0.00)
|
||||
->comment('Total potongan = kasbon + biaya_makan');
|
||||
|
||||
// ===================================
|
||||
// GAJI BERSIH
|
||||
// ===================================
|
||||
$table->decimal('gaji_bersih', 12, 2)
|
||||
->default(0.00)
|
||||
->comment('Gaji bersih = ongkos_pekerjaan - total_potongan');
|
||||
|
||||
// ===================================
|
||||
// STATUS & PEMBAYARAN
|
||||
// ===================================
|
||||
$table->enum('status_pembayaran', ['belum_bayar', 'sudah_bayar'])
|
||||
->default('belum_bayar')
|
||||
->comment('Status pembayaran gaji');
|
||||
|
||||
$table->enum('metode_pembayaran', ['cash', 'transfer'])
|
||||
->nullable()
|
||||
->comment('Metode pembayaran');
|
||||
|
||||
$table->dateTime('tanggal_dibayar')
|
||||
->nullable()
|
||||
->comment('Tanggal gaji benar-benar dibayarkan');
|
||||
|
||||
$table->text('bukti_pembayaran')
|
||||
->nullable()
|
||||
->comment('Path file/foto bukti transfer');
|
||||
|
||||
// ===================================
|
||||
// CATATAN
|
||||
// ===================================
|
||||
$table->text('catatan')
|
||||
->nullable()
|
||||
->comment('Catatan tambahan untuk slip gaji ini');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
// ===================================
|
||||
// FOREIGN KEYS
|
||||
// ===================================
|
||||
$table->foreign('id_teknisi')
|
||||
->references('id_teknisi')
|
||||
->on('teknisis')
|
||||
->onDelete('cascade');
|
||||
|
||||
// ===================================
|
||||
// INDEXES
|
||||
// ===================================
|
||||
$table->unique(['id_teknisi', 'periode_bulan', 'periode_tahun'], 'unique_teknisi_periode');
|
||||
$table->index(['periode_tahun', 'periode_bulan'], 'idx_periode');
|
||||
$table->index('status_pembayaran', 'idx_status_bayar');
|
||||
$table->index('tanggal_penggajian', 'idx_tgl_gaji');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('penggajians');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?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::create('tarif_pekerjaans', function (Blueprint $table) {
|
||||
$table->id('id_tarif');
|
||||
|
||||
// ===================================
|
||||
// KATEGORI & JENIS PEKERJAAN
|
||||
// ===================================
|
||||
$table->enum('jenis_pekerjaan', [
|
||||
'sr', // 1. Sambungan Rumah (meteran air)
|
||||
'pengembangan_jaringan_pipa', // 2. Pengembangan Jaringan Pipa (pipa baru)
|
||||
'pengangkatan', // 3. Pengangkatan meteran/gate valve
|
||||
'pemasangan_gate_valve', // 4. Pemasangan Gate Valve + Pressure
|
||||
'gali_urug', // 5. Gali Urug
|
||||
'perbaikan_jaringan_pipa', // 6. Perbaikan Jaringan Pipa Bocor
|
||||
'pengecatan_pipa_besi', // 7. Pengecatan Pipa Besi
|
||||
'penyempurnaan_jaringan_pipa' // 8. Penyempurnaan Jaringan Pipa
|
||||
])->comment('Jenis pekerjaan');
|
||||
|
||||
// ===================================
|
||||
// IDENTITAS TARIF
|
||||
// ===================================
|
||||
$table->string('nama_item', 100)->comment('Nama item/pekerjaan');
|
||||
$table->string('kode_item', 20)->unique()->comment('Kode unik item');
|
||||
|
||||
// ===================================
|
||||
// DIMENSI PIPA (untuk pekerjaan yang bergantung diameter)
|
||||
// ===================================
|
||||
$table->enum('dimensi_pipa', ['1-2', '3', '4', '6', '8', '10', '12'])
|
||||
->nullable()
|
||||
->comment('Dimensi/diameter pipa dalam inchi. NULL untuk pekerjaan yang tidak butuh dimensi pipa');
|
||||
|
||||
// ===================================
|
||||
// TARIF PEKERJAAN
|
||||
// ===================================
|
||||
$table->decimal('tarif_per_unit', 12, 2)
|
||||
->nullable()
|
||||
->comment('Tarif flat per unit/titik. Dipakai untuk: SR (150k), Pengangkatan (200k), Gate Valve (200k/free), Gali Urug (200k/titik), Perbaikan & Pengecatan per dimensi');
|
||||
|
||||
$table->decimal('tarif_per_meter', 12, 2)
|
||||
->nullable()
|
||||
->comment('Tarif per meter. Dipakai untuk: Pengembangan & Penyempurnaan Jaringan Pipa sesuai dimensi');
|
||||
|
||||
// ===================================
|
||||
// KONDISI KHUSUS
|
||||
// ===================================
|
||||
$table->boolean('pakai_pipa_besi')
|
||||
->nullable()
|
||||
->comment('Khusus Pemasangan Gate Valve: TRUE=ada pipa besi(200k), FALSE=tanpa pipa besi(free/0)');
|
||||
|
||||
// ===================================
|
||||
// GARANSI (Khusus SR - Pemasangan Meteran Air)
|
||||
// ===================================
|
||||
$table->boolean('ada_garansi')
|
||||
->default(false)
|
||||
->comment('Apakah pekerjaan ini memiliki garansi?');
|
||||
|
||||
$table->integer('durasi_garansi_bulan')
|
||||
->nullable()
|
||||
->comment('Durasi garansi dalam bulan (3 bulan untuk SR)');
|
||||
|
||||
// ===================================
|
||||
// INFO TAMBAHAN
|
||||
// ===================================
|
||||
$table->text('deskripsi')->nullable()->comment('Keterangan tambahan');
|
||||
|
||||
$table->boolean('is_active')
|
||||
->default(true)
|
||||
->comment('Status aktif tarif');
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tarif_pekerjaans');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?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::create('absensis', function (Blueprint $table) {
|
||||
$table->id('id_absensi');
|
||||
$table->unsignedBigInteger('id_teknisi');
|
||||
$table->date('tanggal');
|
||||
$table->time('jam_masuk')->nullable();
|
||||
$table->time('jam_keluar')->nullable();
|
||||
$table->string('foto_absen_masuk', 255)->nullable();
|
||||
$table->string('foto_absen_keluar', 255)->nullable();
|
||||
$table->enum('status', ['hadir', 'izin', 'sakit', 'alpha']);
|
||||
$table->text('keterangan')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('id_teknisi')->references('id_teknisi')->on('teknisis')->onDelete('cascade');
|
||||
$table->unique(['id_teknisi', 'tanggal'], 'unique_teknisi_tanggal');
|
||||
$table->index('tanggal');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('absensis');
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue