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', [
|
||||
|
||||
@@ -29,6 +29,7 @@ use App\Helpers\NotificationHelper;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\BrevoService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Container\Attributes\Auth;
|
||||
|
||||
class FormUpCountryController extends Controller
|
||||
{
|
||||
@@ -372,7 +373,19 @@ class FormUpCountryController extends Controller
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
$regionId = Cabang::where('id', 1)->value('region_id');
|
||||
$rayonData = Rayon::where('cabang_id', $cabang->id)->get();
|
||||
|
||||
if ($role = "Admin Region" || "Marketing Information System" || "Superadmin") {
|
||||
$rayonData = DB::table('rayon')
|
||||
->join('cabang', 'rayon.cabang_id', '=', 'cabang.id')
|
||||
->join('region', 'cabang.region_id', '=', 'region.id')
|
||||
->where('region.id', $regionId)
|
||||
->select('rayon.*')
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
$form = FormUpCountry::with('rayon')->findOrfail($id);
|
||||
if (($form->status != 'On Progress' && $form->status != 'Rejected') && $role == 'Medical Representatif') {
|
||||
session()->flash('error', 'You cannot edit this form because it has been approved or closed.');
|
||||
@@ -380,7 +393,7 @@ class FormUpCountryController extends Controller
|
||||
}
|
||||
|
||||
return view('backend.pages.forms.upcountry.edit', [
|
||||
'rayons' => Rayon::where('cabang_id', $cabang->id)->get(),
|
||||
'rayons' => $rayonData,
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -168,6 +168,11 @@ class Admin extends Authenticatable
|
||||
return $this->belongsTo(Rayon::class, 'rayon_id');
|
||||
}
|
||||
|
||||
public function rayon()
|
||||
{
|
||||
return $this->belongsTo(Rayon::class, 'rayon_id');
|
||||
}
|
||||
|
||||
public function getRegion()
|
||||
{
|
||||
return $this->belongsTo(Region::class, 'region_id');
|
||||
|
||||
@@ -16,4 +16,9 @@ class Rayon extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Cabang');
|
||||
}
|
||||
|
||||
public function region()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Region::class, 'region_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user