Skip to content

Commit 043b50e

Browse files
committed
Final Commit, Peace.
1 parent f36348b commit 043b50e

File tree

111 files changed

+12115
-3380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+12115
-3380
lines changed

app/Exports/BillExport.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
namespace App\Exports;
4+
5+
use App\Models\Profile;
6+
use App\Models\Transaction\Bill;
7+
use Maatwebsite\Excel\Concerns\FromCollection;
8+
use Maatwebsite\Excel\Concerns\WithHeadings;
9+
use Maatwebsite\Excel\Concerns\WithTitle;
10+
use Maatwebsite\Excel\Concerns\WithStyles;
11+
use Maatwebsite\Excel\Concerns\WithColumnWidths;
12+
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
13+
use Illuminate\Support\Collection;
14+
use Illuminate\Support\Facades\Log;
15+
16+
class BillExport implements FromCollection, WithHeadings, WithTitle, WithStyles, WithColumnWidths
17+
{
18+
protected $bill_id;
19+
protected $bill;
20+
21+
public function __construct($bill_id)
22+
{
23+
$this->bill_id = $bill_id;
24+
$this->bill = Bill::find($bill_id);
25+
}
26+
27+
public function collection(): Collection
28+
{
29+
if (!$this->bill) {
30+
Log::warning("Export gagal: Tidak ada bill dengan ID " . $this->bill_id);
31+
return collect([]);
32+
}
33+
34+
$transaction = $this->bill->transaction();
35+
$vendor = $transaction->vendor();
36+
$details = $transaction->details();
37+
38+
$data = [];
39+
40+
$profile = Profile::first();
41+
// Header Klinik
42+
$data[] = [$profile->name, '', '', '', '', 'No. LPB : ' . $transaction->code];
43+
$data[] = [$profile->address, '', '', '', '', 'Tanggal: ' . \Carbon\Carbon::parse($this->bill->created_at)->translatedFormat('j F Y')];
44+
$data[] = [$profile->phone, '', '', '', '', ''];
45+
$data[] = ['']; // Baris kosong
46+
$data[] = ['', '', 'LAPORAN PENERIMAAN BARANG', '', '', ''];
47+
$data[] = ['']; // Baris kosong
48+
$data[] = ['', '', '', '', '', 'Vendor: ' . $vendor->name];
49+
$data[] = ['', '', '', '', '', $vendor->address];
50+
$data[] = ['', '', '', '', '', $vendor->phone];
51+
$data[] = ['']; // Baris kosong
52+
53+
// Header Tabel
54+
$data[] = ['No', 'Kode Obat', 'Nama Obat', 'Jumlah', 'Harga Satuan', 'Subtotal'];
55+
56+
// Isi Data
57+
$grand_total = 0;
58+
foreach ($details as $index => $item) {
59+
$data[] = [
60+
$index + 1,
61+
$item->drug()->code,
62+
$item->drug()->name,
63+
$item->quantity,
64+
'Rp ' . number_format($item->piece_price, 0, ',', '.'),
65+
'Rp ' . number_format($item->total_price, 0, ',', '.'),
66+
];
67+
$grand_total += $item->total_price;
68+
}
69+
70+
// Summary
71+
$data[] = ['']; // Baris kosong setelah data
72+
$data[] = ['', '', '', '', 'Grand Total:', 'Rp ' . number_format($transaction->outcome, 0, ',', '.')];
73+
74+
// Status pembayaran
75+
if ($this->bill->status == 'Belum Bayar') {
76+
$data[] = ['', '', '', '', 'Status:', 'Belum Bayar'];
77+
}
78+
79+
return collect($data);
80+
}
81+
82+
public function styles(Worksheet $sheet)
83+
{
84+
$data = $this->collection()->toArray();
85+
$rowCount = count($data);
86+
87+
$styles = [
88+
5 => ['font' => ['bold' => true, 'size' => 14]], // Judul laporan
89+
10 => ['font' => ['bold' => true, 'size' => 12]], // Header tabel
90+
11 => ['font' => ['bold' => true]], // Kolom judul tabel
91+
];
92+
93+
// Grand Total row
94+
$grandTotalRow = $rowCount - 1;
95+
if ($this->bill->status == 'Belum Bayar') {
96+
$grandTotalRow = $rowCount - 2; // If status exists, grand total is second to last
97+
}
98+
$styles[$grandTotalRow] = ['font' => ['bold' => true]];
99+
100+
// Status row (if exists)
101+
if ($this->bill->status == 'Belum Bayar') {
102+
$styles[$rowCount] = ['font' => ['bold' => true, 'color' => ['rgb' => 'FF0000']]];
103+
}
104+
105+
// Alignment styles
106+
$styles['A10:F10'] = ['alignment' => ['horizontal' => 'center']]; // Header tabel
107+
$styles['A11:A' . $rowCount] = ['alignment' => ['horizontal' => 'center']]; // No urut
108+
$styles['B11:B' . $rowCount] = ['alignment' => ['horizontal' => 'center']]; // Kode Obat (tengah)
109+
$styles['C11:C' . $rowCount] = ['alignment' => ['horizontal' => 'left']]; // Nama Obat (kiri)
110+
$styles['D11:F' . $rowCount] = ['alignment' => ['horizontal' => 'center']]; // Jumlah, Harga, dan Subtotal
111+
$styles['F' . $grandTotalRow] = ['alignment' => ['horizontal' => 'right']]; // Grand Total (kanan)
112+
113+
if ($this->bill->status == 'Belum Bayar') {
114+
$styles['F' . $rowCount] = ['alignment' => ['horizontal' => 'center']]; // Status (kanan)
115+
}
116+
117+
return $styles;
118+
}
119+
120+
public function columnWidths(): array
121+
{
122+
return [
123+
'A' => 5, // No
124+
'B' => 15, // Kode Obat
125+
'C' => 30, // Nama Obat
126+
'D' => 15, // Jumlah
127+
'E' => 15, // Harga Satuan
128+
'F' => 20, // Subtotal
129+
];
130+
}
131+
132+
public function headings(): array
133+
{
134+
return [];
135+
}
136+
137+
public function title(): string
138+
{
139+
return 'Laporan Penerimaan Barang';
140+
}
141+
}

app/Exports/CheckoutExport.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
namespace App\Exports;
4+
5+
use App\Models\Profile;
6+
use App\Models\Transaction\TransactionDetail;
7+
use Maatwebsite\Excel\Concerns\FromCollection;
8+
use Maatwebsite\Excel\Concerns\WithHeadings;
9+
use Maatwebsite\Excel\Concerns\WithTitle;
10+
use Maatwebsite\Excel\Concerns\WithStyles;
11+
use Maatwebsite\Excel\Concerns\WithColumnWidths;
12+
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
13+
use Illuminate\Support\Collection;
14+
use Illuminate\Support\Facades\Log;
15+
16+
class CheckoutExport implements FromCollection, WithHeadings, WithTitle, WithStyles, WithColumnWidths
17+
{
18+
protected $transaction_id;
19+
20+
public function __construct($transaction_id)
21+
{
22+
$this->transaction_id = $transaction_id;
23+
}
24+
25+
public function collection(): Collection
26+
{
27+
// Ambil satu TransactionDetail sebagai acuan (pakai first)
28+
$transactionDetail = TransactionDetail::where('transaction_id', $this->transaction_id)
29+
->with('transaction')
30+
->first();
31+
32+
// Pastikan transaksi ditemukan
33+
if (!$transactionDetail || !$transactionDetail->transaction) {
34+
Log::warning("Export gagal: Tidak ada transaksi dengan ID " . $this->transaction_id);
35+
return collect([]);
36+
}
37+
38+
// Ambil data transaksi
39+
$transaction = $transactionDetail->transaction;
40+
$no_invoice = $transaction->code ?? 'N/A';
41+
$tanggal_transaksi = $transaction->created_at
42+
? \Carbon\Carbon::parse($transaction->created_at)->format('d F Y')
43+
: now()->format('d F Y');
44+
45+
// Ambil semua detail transaksi dengan kode dan nama obat
46+
$details = TransactionDetail::select(
47+
'transaction_details.*',
48+
'drugs.code as drug_code',
49+
'drugs.name as drug_name'
50+
)
51+
->leftJoin('drugs', 'transaction_details.drug_id', '=', 'drugs.id')
52+
->where('transaction_details.transaction_id', $this->transaction_id)
53+
->get();
54+
55+
$data = [];
56+
57+
$profile = Profile::first();
58+
// Header Klinik
59+
$data[] = [$profile->name, '', '', '', '', 'No. Invoice : ' . $no_invoice];
60+
$data[] = [$profile->address, '', '', '', '', 'Tanggal: ' . $tanggal_transaksi];
61+
$data[] = [$profile->phone, '', '', '', '', ''];
62+
$data[] = ['']; // Baris kosong
63+
$data[] = ['', '', 'INVOICE', '', '', ''];
64+
$data[] = ['']; // Baris kosong
65+
66+
// Header Tabel
67+
$data[] = ['No', 'Kode Obat', 'Nama Obat', 'Jumlah', 'Harga Satuan', 'Total'];
68+
69+
// Isi Data
70+
$grand_total = 0;
71+
foreach ($details as $index => $item) {
72+
$data[] = [
73+
$index + 1,
74+
$item->drug_code ?? '-',
75+
$item->drug_name ?? '-',
76+
$item->quantity . ' ',
77+
'Rp ' . number_format($item->piece_price, 0, ',', '.'),
78+
'Rp ' . number_format($item->total_price, 0, ',', '.'),
79+
];
80+
$grand_total += $item->total_price;
81+
}
82+
83+
// Summary
84+
$data[] = ['']; // Baris kosong setelah data
85+
$discount = $transaction->discount ?? 0;
86+
$subtotal = $grand_total;
87+
$total = $subtotal - $discount;
88+
89+
$data[] = ['', '', '', '', 'Subtotal:', 'Rp ' . number_format($subtotal, 0, ',', '.')];
90+
$data[] = ['', '', '', '', 'Diskon:', 'Rp ' . number_format($discount, 0, ',', '.')];
91+
$data[] = ['', '', '', '', 'Total:', 'Rp ' . number_format($total, 0, ',', '.')];
92+
93+
return collect($data);
94+
}
95+
96+
public function styles(Worksheet $sheet)
97+
{
98+
$rowCount = count($this->collection()) + 1; // Menghitung total baris termasuk header
99+
100+
return [
101+
5 => ['font' => ['bold' => true, 'size' => 14]], // Judul invoice
102+
10 => ['font' => ['bold' => true, 'size' => 12]], // Header tabel
103+
11 => ['font' => ['bold' => true]], // Kolom judul tabel
104+
($rowCount-2) => ['font' => ['bold' => true]], // Subtotal
105+
($rowCount-1) => ['font' => ['bold' => true]], // Diskon
106+
$rowCount => ['font' => ['bold' => true]], // Total
107+
108+
// Mengatur alignment
109+
'A10:F10' => ['alignment' => ['horizontal' => 'center']], // Header tabel
110+
'A11:A' . $rowCount => ['alignment' => ['horizontal' => 'center']], // No urut
111+
'B11:B' . $rowCount => ['alignment' => ['horizontal' => 'center']], // Kode Obat (tengah)
112+
'C11:C' . $rowCount => ['alignment' => ['horizontal' => 'left']], // Nama Obat (kiri)
113+
'D11:F' . $rowCount => ['alignment' => ['horizontal' => 'center']], // Jumlah, Harga, dan Subtotal
114+
'F' . ($rowCount-2) => ['alignment' => ['horizontal' => 'right']], // Subtotal (kanan)
115+
'F' . ($rowCount-1) => ['alignment' => ['horizontal' => 'right']], // Diskon (kanan)
116+
'F' . $rowCount => ['alignment' => ['horizontal' => 'right']], // Total (kanan)
117+
];
118+
}
119+
120+
public function columnWidths(): array
121+
{
122+
return [
123+
'A' => 5, // No
124+
'B' => 15, // Kode Obat
125+
'C' => 30, // Nama Obat
126+
'D' => 15, // Jumlah
127+
'E' => 15, // Harga Satuan
128+
'F' => 20, // Subtotal
129+
];
130+
}
131+
132+
public function headings(): array
133+
{
134+
return [];
135+
}
136+
137+
public function title(): string
138+
{
139+
return 'Invoice';
140+
}
141+
}

app/Exports/InventoryTemplateExport.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function array(): array
1818

1919
public function headings(): array
2020
{
21-
return ["Vendor", "Jenis Pembayaran", "Tanggal Pembayaran", "Nama Obat", "Jumlah", "Satuan", "Harga Satuan", "Tanggal EXP"];
21+
return ["Nama Obat", "Jumlah", "Satuan", "Harga Satuan", "Tanggal EXP"];
2222
}
2323

2424
public function registerEvents(): array
@@ -27,12 +27,6 @@ public function registerEvents(): array
2727
AfterSheet::class => function (AfterSheet $event) {
2828
$sheet = $event->sheet->getDelegate();
2929

30-
// Ambil daftar vendor dari database
31-
$vendors = Vendor::pluck('name')->toArray();
32-
33-
// Daftar pilihan manual untuk "Jenis Pembayaran"
34-
$jenisPembayaran = ['Bayar Langsung', 'Bayar Tempo'];
35-
3630
// Ambil daftar "Nama Obat" dan harga dari database
3731
$drugs = Drug::pluck('last_price', 'name')->toArray(); // Key: Nama Obat, Value: Harga
3832

@@ -48,7 +42,7 @@ function setDropdown($sheet, $column, $data, $startRow = 2, $endRow = 100)
4842
$validation = $sheet->getCell($column . $row)->getDataValidation();
4943
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST);
5044
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION);
51-
$validation->setAllowBlank(true); // Ubah menjadi true untuk memungkinkan sel kosong
45+
$validation->setAllowBlank(true);
5246
$validation->setShowInputMessage(true);
5347
$validation->setShowErrorMessage(true);
5448
$validation->setShowDropDown(true);
@@ -58,28 +52,24 @@ function setDropdown($sheet, $column, $data, $startRow = 2, $endRow = 100)
5852
}
5953

6054
// Terapkan dropdown ke masing-masing kolom
61-
setDropdown($sheet, 'A', $vendors); // Kolom Vendor
62-
setDropdown($sheet, 'B', $jenisPembayaran); // Kolom Jenis Pembayaran
63-
setDropdown($sheet, 'D', array_keys($drugs)); // Kolom Nama Obat
64-
setDropdown($sheet, 'F', $satuan); // Kolom Satuan
55+
setDropdown($sheet, 'A', array_keys($drugs)); // Kolom Nama Obat
56+
setDropdown($sheet, 'C', $satuan); // Kolom Satuan
6557

66-
// Terapkan format tanggal dan tambahkan date picker di kolom "Tanggal Pembayaran" (C) dan "Tanggal EXP" (H)
58+
// Terapkan format tanggal dan tambahkan date picker di kolom "Tanggal EXP" (E)
6759
for ($row = 2; $row <= 100; $row++) {
68-
$sheet->getStyle("C$row")->getNumberFormat()->setFormatCode('yyyy-mm-dd');
69-
$sheet->getStyle("H$row")->getNumberFormat()->setFormatCode('yyyy-mm-dd');
60+
$sheet->getStyle("E$row")->getNumberFormat()->setFormatCode('yyyy-mm-dd');
7061

71-
$dateValidation = $sheet->getCell("C$row")->getDataValidation();
62+
$dateValidation = $sheet->getCell("E$row")->getDataValidation();
7263
$dateValidation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DATE);
7364
$dateValidation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP);
74-
$dateValidation->setAllowBlank(true); // Ubah menjadi true
65+
$dateValidation->setAllowBlank(true);
7566
$dateValidation->setShowInputMessage(true);
7667
$dateValidation->setShowErrorMessage(true);
77-
$dateValidation->setFormula1('DATE(1900,1,1)'); // Gunakan fungsi DATE untuk tanggal minimum
78-
$dateValidation->setFormula2('DATE(2099,12,31)'); // Gunakan fungsi DATE untuk tanggal maksimum
68+
$dateValidation->setFormula1('DATE(1900,1,1)');
69+
$dateValidation->setFormula2('DATE(2099,12,31)');
7970
$dateValidation->setOperator(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_BETWEEN);
8071

81-
$sheet->getCell("C$row")->setDataValidation(clone $dateValidation);
82-
$sheet->getCell("H$row")->setDataValidation(clone $dateValidation);
72+
$sheet->getCell("E$row")->setDataValidation(clone $dateValidation);
8373
}
8474

8575
// *** Langkah untuk Menghubungkan Nama Obat dengan Harga Satuan ***
@@ -111,8 +101,8 @@ function setDropdown($sheet, $column, $data, $startRow = 2, $endRow = 100)
111101

112102
// 2. Gunakan VLOOKUP untuk mengambil harga berdasarkan obat yang dipilih (tanpa mengalikan dengan jumlah)
113103
for ($row = 2; $row <= 100; $row++) {
114-
$formula = "=IF(D$row<>\"\",VLOOKUP(D$row,'Data Harga Obat'!A:B,2,FALSE),\"\")";
115-
$sheet->getCell("G$row")->setValue($formula);
104+
$formula = "=IF(A$row<>\"\",VLOOKUP(A$row,'Data Harga Obat'!A:B,2,FALSE),\"\")";
105+
$sheet->getCell("D$row")->setValue($formula);
116106
}
117107

118108
// Sembunyikan sheet data harga obat

0 commit comments

Comments
 (0)