Postingan lainnya
Cara membuat multiple foreach berdasarkan tanggal di laravel 8
saya mempunyai data export dari laravel ke excel seperti ini.
Capture1.PNG
nah saya ingin menampilkan data kesamping seperti itu tapi datanya berdasarkan inputan per tgl, misal tgl sekarang nginputnya 2 data maka yg tampil 2 data. kurang lebih seperti ini contohnya.
Capture2.PNG
ada yang bisa bantu gan?
ini view nya
<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td,
#customers th {
border: 1px solid rgb(0, 0, 0);
padding: 8px;
}
#customers tr:nth-child(even) {
background-color: #f2f2f2;
}
#customers tr:hover {
background-color: #ddd;
}
#customers th {
padding-top: 11px;
padding-bottom: 11px;
text-align: center;
background-color: white;
color: rgb(0, 0, 0);
}
</style>
</head>
<body>
<table id="customers">
<thead class="table-info">
<tr>
<th colspan="6" rowspan="1"><strong>REKAPITULASI BUKU BESAR</strong></th>
</tr>
<tr>
<th colspan="6" rowspan="1"><strong>BIAYA MARKETING PROYEK</strong></th>
</tr>
<tr>
<th colspan="6" rowspan="1"><strong>CONTOH PT</strong></th>
</tr>
<tr></tr>
<tr>
<th>No</th>
<th>Tanggal</th>
<th>Kode ACC</th>
<th>Transaksi</th>
{{-- <th>Marketing Proyek</th> --}}
{{-- <th>Biaya</th> --}}
@php
$no = 1;
$total = 0;
@endphp
@foreach ($bm as $row)
<th>{{ $row->marketing_proyek }}</th>
@endforeach
<th colspan="5"><strong>Total</strong></th>
</tr>
</thead>
@php
$total = 0;
@endphp
@foreach ($bm as $row)
<tr align="center">
<td scope="row">{{ $no++ }}</td>
<td>{{ $row->tanggal }}</td>
<td>{{ $row->kode_akun }}</td>
<td>{{ $row->transaksi }}</td>
@php
$total += $row['biaya'];
@endphp
@foreach ($bm as $row )
<td><?= 'Rp. ' . number_format($row->biaya, 0, ',', '.') ?></td>
@endforeach
<th class="text-center"><strong><?= 'Rp. ' . number_format($total, 0, ',', '.') ?></strong></th>
</tr>
@endforeach
<tr>
</tr>
</table>
</body>
</html>
ini controllernya :
public function exporttexcel()
{
return Excel::download(new BmarketingExport, 'DataBiayaMarketing.xlsx');
}
ini Export Excelnya
<?php
namespace App\Exports;
use App\Models\Bks;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class BksExport implements FromView, ShouldAutoSize, WithHeadings, WithStyles
{
/**
* @return \Illuminate\Support\Collection
*/
// public function collection()
// {
// return Bks::all();
// }
use Exportable;
private $bk;
public function __construct()
{
$this->bk = Bks::all();
}
public function view(): View
{
return view('bks-excel', [
'bk' => $this->bk
// $sheet->mergeCells('A1:E1');
]);
}
public function headings(): array
{
return [
'No', 'Tanggal', 'Perkiraan', 'Reff', 'Kode Akun', 'Debit', 'Kredit', 'Balance', 'Kode Proyek', 'Nama Perkiraan', 'Nama Group', 'Created at', 'Updated at'
];
}
public function styles(Worksheet $sheet)
{
return [
// Style the first row as bold text.
4 => ['font' => ['bold' => true]],
'1:2' => ['alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,]],
'22' => ['alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,]],
// // Styling a specific cell by coordinate.
// '2' => ['font' => ['italic' => true]],
// // Styling an entire column.
// 'C' => ['font' => ['size' => 16]],
];
}
}
ini Modelnya
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BMarketing extends Model
{
// use HasFactory;
protected $table = "bmarketings";
protected $guarded = [];
public function akun()
{
return $this->hasMany(Akun::class, 'kode_akun', 'kode_akun');
}
}
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban