Initial commit: Struktur aplikasi ilycats
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ActivityLogExport implements FromCollection, WithHeadings, WithMapping
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return ActivityLog::with('user')->latest()->get();
|
||||
}
|
||||
|
||||
// Header Excel
|
||||
public function headings(): array
|
||||
{
|
||||
return ['Waktu', 'Pelaksana', 'Aksi', 'Deskripsi', 'IP Address'];
|
||||
}
|
||||
|
||||
// Mapping Data per Baris
|
||||
public function map($log): array
|
||||
{
|
||||
return [
|
||||
$log->created_at->format('d/m/Y H:i:s'),
|
||||
$log->user->name ?? 'System',
|
||||
$log->action,
|
||||
$log->description,
|
||||
$log->ip_address,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Cat;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class CatsExport implements FromCollection
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Cat::all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class FoodTemplateExport implements WithHeadings
|
||||
{
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'nama_makanan',
|
||||
'qty',
|
||||
'unit',
|
||||
'expired_date',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\{FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithStyles, WithEvents, WithCustomStartCell};
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class MattingExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithStyles, WithEvents, WithCustomStartCell
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function collection() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function startCell(): string {
|
||||
return 'A7';
|
||||
}
|
||||
|
||||
public function headings(): array {
|
||||
return [
|
||||
'ID',
|
||||
'NAMA KUCING (♂/♀)',
|
||||
'PARENT (SIRE x DAM)',
|
||||
'REGISTRY',
|
||||
'KODE EMS',
|
||||
'NO. PEDIGREE',
|
||||
'NO. MICROCHIP',
|
||||
'TGL KAWIN',
|
||||
'ESTIMASI LAHIR (EDD)',
|
||||
'STATUS'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \App\Models\Matting $item
|
||||
*/
|
||||
public function map($item): array {
|
||||
// Menggunakan Accessor edd dari Model Matting
|
||||
$eddDate = $item->edd ? $item->edd->format('d/m/Y') : '-';
|
||||
$tglKawin = $item->tgl_kawin_awal ? $item->tgl_kawin_awal->format('d/m/Y') : '-';
|
||||
|
||||
// Kita buat mapping yang mencakup data Sire & Dam dalam baris yang informatif
|
||||
return [
|
||||
$item->id,
|
||||
($item->sire?->nama_kucing ?? 'N/A') . ' & ' . ($item->dam?->nama_kucing ?? 'N/A'),
|
||||
($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_microchip_bapak ?? '-') . ' / D: ' . ($item->no_microchip_ibu ?? '-'),
|
||||
$tglKawin,
|
||||
$eddDate,
|
||||
strtoupper($item->status ?? 'PROSES')
|
||||
];
|
||||
}
|
||||
|
||||
public function registerEvents(): array {
|
||||
return [
|
||||
AfterSheet::class => function(AfterSheet $event) {
|
||||
$sheet = $event->sheet;
|
||||
$sheet->setCellValue('A1', 'ILY CATTERY - STRATEGIC BREEDING REPORT');
|
||||
$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');
|
||||
$sheet->setCellValue('A5', 'Sektor: PARENTAL INTELLIGENCE UNIT');
|
||||
|
||||
$sheet->getStyle('A1')->getFont()->setSize(16)->setBold(true);
|
||||
$sheet->getStyle('A2:A5')->getFont()->setBold(true);
|
||||
|
||||
// Memberikan border ke seluruh tabel data
|
||||
$lastRow = $this->data->count() + 7;
|
||||
$sheet->getStyle('A7:J' . $lastRow)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet) {
|
||||
return [
|
||||
7 => [
|
||||
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
||||
'fill' => ['fillType' => 'solid', 'startColor' => ['rgb' => '4F46E5']],
|
||||
'alignment' => ['horizontal' => 'center'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
|
||||
class MedicineTemplateExport implements FromCollection, WithHeadings, WithTitle
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
// Contoh data untuk user
|
||||
return collect([
|
||||
[
|
||||
'nama_obat' => 'Amoxicillin Syrup',
|
||||
'stok' => 10.5,
|
||||
'satuan' => 'ML',
|
||||
'kadaluarsa' => '2026-12-31'
|
||||
],
|
||||
[
|
||||
'nama_obat' => 'Drontal Cat',
|
||||
'stok' => 20,
|
||||
'satuan' => 'Tablet',
|
||||
'kadaluarsa' => '2027-05-20'
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return ['nama_obat', 'stok', 'satuan', 'kadaluarsa'];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Template Import Obat';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class SupplyTemplateExport implements WithHeadings, ShouldAutoSize
|
||||
{
|
||||
/**
|
||||
* Mendefinisikan judul kolom untuk template.
|
||||
* * @return array
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'nama_perlengkapan',
|
||||
'qty',
|
||||
'unit',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\{FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithStyles, WithEvents, WithCustomStartCell};
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UnifiedReportExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithStyles, WithEvents, WithCustomStartCell
|
||||
{
|
||||
protected $data;
|
||||
protected $module;
|
||||
|
||||
public function __construct($data, $module)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data tabel dimulai dari baris ke-7 (setelah metadata)
|
||||
*/
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A7';
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return match ($this->module) {
|
||||
'cats' => ['ID', 'NAMA KUCING', 'RAS', 'GENDER', 'TGL LAHIR', 'STATUS', 'PIC STAFF'],
|
||||
'vaccine', 'deworming', 'flea', 'grooming' => ['ID', 'NAMA KUCING', 'TINDAKAN', 'JADWAL', 'STATUS', 'PIC STAFF'],
|
||||
'medicine', 'food', 'supplies' => ['ID', 'NAMA PRODUK', 'STOK', 'SATUAN', 'TGL EXPIRED', 'PIC STAFF'],
|
||||
default => ['ID', 'NAMA', 'DETAIL', 'TANGGAL', 'PIC']
|
||||
};
|
||||
}
|
||||
|
||||
public function map($item): array
|
||||
{
|
||||
$dateCol = match($this->module) {
|
||||
'cats' => 'tanggal_lahir',
|
||||
'medicine', 'food', 'supplies' => 'expired_date',
|
||||
'vaccine' => 'jadwal_vaksin',
|
||||
'deworming' => 'jadwal_obat_cacing',
|
||||
'flea' => 'jadwal_obat_kutu',
|
||||
'grooming' => 'jadwal_grooming',
|
||||
default => 'created_at'
|
||||
};
|
||||
|
||||
$dateValue = $item->{$dateCol} ? Carbon::parse($item->{$dateCol})->format('d/m/Y') : 'Not Set';
|
||||
|
||||
return match ($this->module) {
|
||||
'cats' => [
|
||||
$item->id, $item->nama_kucing, $item->ras, $item->jenis_kelamin,
|
||||
$dateValue, $item->riwayat_sakit_terakhir ? 'IN TREATMENT' : 'HEALTHY',
|
||||
$item->pic->name ?? 'System'
|
||||
],
|
||||
'vaccine', 'deworming', 'flea', 'grooming' => [
|
||||
$item->id, $item->nama_kucing, strtoupper($this->module),
|
||||
$dateValue, $this->getScheduleStatus($item->{$dateCol}),
|
||||
$item->pic->name ?? 'System'
|
||||
],
|
||||
'medicine', 'food', 'supplies' => [
|
||||
$item->id, $item->nama_obat ?? $item->nama_makanan ?? $item->nama_perlengkapan,
|
||||
$item->qty, $item->unit, $dateValue, $item->pic->name ?? 'System'
|
||||
],
|
||||
default => [
|
||||
$item->id, $item->nama_kucing ?? 'Data', $item->ras ?? '-', $dateValue, $item->pic->name ?? 'System'
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
private function getScheduleStatus($date) {
|
||||
if (!$date) return 'NOT SET';
|
||||
return Carbon::parse($date)->isPast() ? 'OVERDUE' : 'SCHEDULED';
|
||||
}
|
||||
|
||||
/**
|
||||
* Menulis Metadata di bagian atas Sheet
|
||||
*/
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function(AfterSheet $event) {
|
||||
$sheet = $event->sheet;
|
||||
|
||||
// Menulis Metadata
|
||||
$sheet->setCellValue('A1', 'ILY CATTERY - STRATEGIC REPORT');
|
||||
$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');
|
||||
$sheet->setCellValue('A5', 'Status Laporan: LAPORAN ' . strtoupper($this->module));
|
||||
|
||||
// Styling Metadata
|
||||
$sheet->getStyle('A1')->getFont()->setSize(14)->setBold(true);
|
||||
$sheet->getStyle('A2:A5')->getFont()->setBold(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
return [
|
||||
// Style untuk Header Tabel (Sekarang di baris 7)
|
||||
7 => [
|
||||
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'startColor' => ['rgb' => '4F46E5']
|
||||
],
|
||||
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER]
|
||||
],
|
||||
// Border untuk seluruh tabel
|
||||
'A7:G' . (7 + $this->data->count()) => [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'E2E8F0'],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user