new commit
This commit is contained in:
@@ -17,6 +17,7 @@ use App\Models\Cabang;
|
||||
use App\Models\Region;
|
||||
use App\Helpers\FormHelper;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Models\Kategori;
|
||||
@@ -591,10 +592,51 @@ class ReportController extends Controller
|
||||
|
||||
// Get the forms after all filters have been applied
|
||||
// Sort by 'tanggal' if it exists, otherwise by 'created_at'
|
||||
$forms = $formsQuery->orderBy(
|
||||
Schema::hasColumn('form_others', 'tanggal') ? 'tanggal' : 'created_at',
|
||||
'desc'
|
||||
)->get();
|
||||
|
||||
$tables = [
|
||||
'form_others',
|
||||
'form_up_country',
|
||||
'form_vehicle_running_cost',
|
||||
'form_meeting_seminar',
|
||||
'form_entertainment_presentation'
|
||||
];
|
||||
|
||||
$formsQuery = null;
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$query = DB::table($table)
|
||||
->selectRaw("
|
||||
expense_number,
|
||||
'$table' as type,
|
||||
user_id,
|
||||
total,
|
||||
approved_total,
|
||||
account_number,
|
||||
status,
|
||||
created_at
|
||||
");
|
||||
|
||||
$formsQuery = $formsQuery
|
||||
? $formsQuery->unionAll($query)
|
||||
: $query;
|
||||
}
|
||||
|
||||
$forms = DB::query()
|
||||
->fromSub($formsQuery, 'forms')
|
||||
->join('admins', 'admins.id', '=', 'forms.user_id')
|
||||
->select('forms.*', 'admins.id as admin_id')
|
||||
->orderBy('forms.created_at', 'desc')
|
||||
->paginate(100);
|
||||
|
||||
|
||||
|
||||
// inject relasi Admin model ke setiap item
|
||||
$forms->getCollection()->transform(function ($item) {
|
||||
$item->user = \App\Models\Admin::with(['region', 'rayon.region'])->find($item->admin_id);
|
||||
$item->type = ucwords(str_replace('_', ' ', str_replace('form_', '', $item->type)));
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
|
||||
return view('backend.pages.report.all', [
|
||||
|
||||
Reference in New Issue
Block a user