Hi, I'm trying to make this work via an addon with PyroCMS. I almost copied the example code word per word, expect for the query where instead of using the model, I used "DB::Table.
$title = 'Account Balance Report'; // Report title
$meta = [ // For displaying filters description on header
'Registered on' => $fromDate . ' To ' . $toDate,
'Sort By' => $sortBy
];
$queryBuilder = DB::table('testreport_accountinfo_translations')->select('name', 'created_at as registered_at', 'balance')->wherebetween('created_at', [$fromDate, $toDate])->orderBy($sortBy)->get();
dd($queryBuilder);
$columns = [ // Set Column to be displayed
'Name' => 'name',
'Registered At' => 'registered_at',
'Total Balance' => 'balance',
];
// Generate Report with flexibility to manipulate column class even manipulate column value (using Carbon, etc).
return PDFReport::of($title, $meta, $queryBuilder, $columns)
->setpaper('legal')
->setorientation('landscape')
->editColumn('Registered At', [ // Change column class or manipulate its data for displaying to report
'displayAs' => function($result) {
return $result->registered_at->format('d M Y');
},
'class' => 'left'
])
->editColumns(['Total Balance', 'Status'], [ // Mass edit column
'class' => 'right bold'
])
->showTotal([ // Used to sum all value on specified column on the last table (except using groupBy method). 'point' is a type for displaying total with a thousand separator
'Total Balance' => 'point' // if you want to show dollar sign ($) then use 'Total Balance' => '$'
])
->stream(); // or download('filename here..') to download pdf
}