initial commit

This commit is contained in:
2026-09-23 12:45:02 +07:00
parent d16f454083
commit 507fc6ccdf
235 changed files with 19587 additions and 2835 deletions
+83
View File
@@ -0,0 +1,83 @@
<?php
namespace App\Exports;
use App\Models\Cat;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class CatWeightTemplateExport implements FromCollection, WithHeadings, WithMapping, WithStyles, ShouldAutoSize, WithColumnFormatting
{
/**
* Ambil data kucing yang aktif
*/
public function collection()
{
// Tetap mengambil semua kucing yang tidak dihapus
return Cat::whereNull('deleted_at')->get(['id', 'nama_kucing']);
}
/**
* Header Tabel
*/
public function headings(): array
{
return [
"Kode Kucing",
"Nama Kucing",
"Berat Badan (Kg)",
"Tanggal & Waktu" // Ubah header agar staf tahu ini mendukung jam
];
}
/**
* Mapping baris data
*/
public function map($cat): array
{
return [
$cat->id,
$cat->nama_kucing,
'', // Kosongkan untuk diisi staf
// Konversi tanggal PHP murni ke Serial Number Date milik Excel
// Ini mencegah Excel mengubah tanggal menjadi format teks yang berantakan
Date::dateTimeToExcel(now())
];
}
/**
* Format Kolom secara spesifik
*/
public function columnFormats(): array
{
return [
// Memaksa kolom D (Tanggal & Waktu) menggunakan format kalender bawaan Excel
// Formatnya akan menjadi YYYY-MM-DD HH:MM:SS saat staf membuka filenya
'D' => NumberFormat::FORMAT_DATE_DATETIME,
];
}
/**
* Styling Header agar lebih cantik
*/
public function styles(Worksheet $sheet)
{
return [
1 => [
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'startColor' => ['rgb' => '4F81BD']
],
],
];
}
}
+2 -2
View File
@@ -54,7 +54,7 @@ class MattingExport implements FromCollection, WithHeadings, WithMapping, Should
($item->sire?->nama_kucing ?? '-') . ' x ' . ($item->dam?->nama_kucing ?? '-'),
($item->dam?->pedigree ?? '-'),
'S: ' . ($item->ems_bapak ?? '-') . ' / D: ' . ($item->ems_ibu ?? '-'),
'S: ' . ($item->no_pedigree_bapak ?? 'Non-Ped') . ' / D: ' . ($item->no_pedigree_ibu ?? 'Non-Ped'),
'S: ' . ($item->no_pedigree_bapak ?? 'Non-pedigree') . ' / D: ' . ($item->no_pedigree_ibu ?? 'Non-pedigree'),
'S: ' . ($item->no_microchip_bapak ?? '-') . ' / D: ' . ($item->no_microchip_ibu ?? '-'),
$tglKawin,
$eddDate,
@@ -66,7 +66,7 @@ class MattingExport implements FromCollection, WithHeadings, WithMapping, Should
return [
AfterSheet::class => function(AfterSheet $event) {
$sheet = $event->sheet;
$sheet->setCellValue('A1', 'ILY CATTERY - STRATEGIC BREEDING REPORT');
$sheet->setCellValue('A1', 'ILY CATTERY - LAPORAN PEMBIAKAN');
$sheet->setCellValue('A2', 'Dicetak Oleh: ' . Auth::user()->name);
$sheet->setCellValue('A3', 'Tanggal Cetak: ' . now()->translatedFormat('d F Y H:i'));
$sheet->setCellValue('A4', 'Total Data: ' . $this->data->count() . ' Records');
+142
View File
@@ -0,0 +1,142 @@
<?php
namespace App\Exports;
use App\Models\Treatment;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class TreatmentExport implements FromQuery, WithHeadings, WithMapping, WithStyles, ShouldAutoSize
{
protected $request;
public function __construct($request)
{
// Kita bisa menerima objek Request atau Query Builder hasil clone dari Controller
$this->request = $request;
}
/**
* Query data dengan filter yang sinkron dengan tampilan UI
*/
public function query()
{
$query = Treatment::query()->with(['cat', 'user', 'details.medicine']);
// Filter 1: Pencarian Nama Kucing
if ($this->request->filled('search')) {
$query->whereHas('cat', function($q) {
$q->where('nama_kucing', 'like', '%' . $this->request->search . '%');
});
}
// Filter 2: Nama PIC (Staf)
if ($this->request->filled('pic_id')) {
$query->where('user_id', $this->request->pic_id);
}
// Filter 3: Rentang Tanggal
if ($this->request->filled('start_date') && $this->request->filled('end_date')) {
$query->whereBetween('tanggal', [$this->request->start_date, $this->request->end_date]);
}
// Filter 4: Kondisi (Healthy / Under Treatment)
if ($this->request->filled('status')) {
$query->whereHas('cat', function($q) {
$q->where('treatment_status', $this->request->status);
});
}
return $query->latest('tanggal');
}
/**
* Header Tabel Excel
*/
public function headings(): array
{
return [
"TANGGAL",
"NAMA KUCING",
"STATUS KESEHATAN",
"KELUHAN",
"DIAGNOSA & TINDAKAN",
"DAFTAR OBAT (QTY)",
"DOSIS & KET",
"PIC / STAF"
];
}
/**
* Transformasi Data per Baris
*/
public function map($t): array
{
// Menggabungkan daftar obat menjadi satu string jika ada multi-medicine
$medicineList = $t->details->map(function($d) {
$namaObat = $d->medicine->nama_obat ?? 'Obat Terhapus';
return "{$namaObat} ({$d->qty_used})";
})->implode(", ");
// Jika data detail kosong, gunakan data fallback (legacy support)
if ($medicineList === "") {
$medicineList = $t->nama_obat ? "{$t->nama_obat} ({$t->qty_used})" : "-";
}
// Mengambil deskripsi dosis/keterangan dari detail pertama atau header
$dosisKet = $t->details->map(function($d) {
return "{$d->dosis} [{$d->keterangan}]";
})->implode(" | ");
return [
$t->tanggal->format('d/m/Y'),
$t->cat->nama_kucing ?? 'N/A',
($t->cat->treatment_status == 1) ? 'UNDER TREATMENT' : 'HEALTHY',
$t->keluhan,
$t->diagnosa,
$medicineList,
$dosisKet ?: $t->dosis,
$t->user->name ?? 'System'
];
}
/**
* Memberikan Styling pada file Excel
*/
public function styles(Worksheet $sheet)
{
return [
// Style Header (Baris 1)
1 => [
'font' => [
'bold' => true,
'color' => ['rgb' => 'FFFFFF'],
'size' => 11
],
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'startColor' => ['rgb' => '4F46E5'] // Indigo-600
],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
],
],
// Memberikan border ke seluruh data yang ada
'A1:H' . ($sheet->getHighestRow()) => [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['rgb' => 'E2E8F0'], // Slate-200
],
],
],
];
}
}
+1 -1
View File
@@ -92,7 +92,7 @@ class UnifiedReportExport implements FromCollection, WithHeadings, WithMapping,
$sheet = $event->sheet;
// Menulis Metadata
$sheet->setCellValue('A1', 'ILY CATTERY - STRATEGIC REPORT');
$sheet->setCellValue('A1', 'ILY CATTERY - LAPORAN TERPADU');
$sheet->setCellValue('A2', 'Dicetak Oleh: ' . Auth::user()->name);
$sheet->setCellValue('A3', 'Tanggal Cetak: ' . now()->translatedFormat('d F Y H:i'));
$sheet->setCellValue('A4', 'Total Data: ' . $this->data->count() . ' Records');