update by CODEX
This commit is contained in:
@@ -41,64 +41,40 @@ class DashboardController extends Controller
|
|||||||
$closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay();
|
$closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
$forms = [
|
$formQueries = [
|
||||||
'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m'))
|
'vehicle' => FormVehicleRunningCost::query()
|
||||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
->whereMonth('tanggal', date('m'))
|
||||||
->orderBy('tanggal', 'desc')
|
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||||
->get(),
|
'upcountry' => FormUpCountry::query()
|
||||||
'upcountry' => FormUpCountry::whereMonth('tanggal', date('m'))
|
->whereMonth('tanggal', date('m'))
|
||||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||||
->orderBy('tanggal', 'desc')
|
'entertainment' => FormEntertaimentPresentation::query()
|
||||||
->get(),
|
->whereMonth('tanggal', date('m'))
|
||||||
'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m'))
|
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
'meeting' => FormMeetingSeminar::query()
|
||||||
->orderBy('tanggal', 'desc')
|
->whereMonth('created_at', date('m'))
|
||||||
->get(),
|
->whereBetween('created_at', [$startDate, $closingDate]),
|
||||||
'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m'))
|
'others' => FormOthers::query()
|
||||||
->whereBetween('created_at', [$startDate, $closingDate])
|
->whereMonth('tanggal', date('m'))
|
||||||
->orderBy('created_at', 'desc')
|
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||||
->get(),
|
|
||||||
'others' => FormOthers::whereMonth('tanggal', date('m'))
|
|
||||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
|
||||||
->orderBy('tanggal', 'desc')
|
|
||||||
->get(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
$approvedStatuses = [
|
||||||
$region_id = auth()->user()->getMyCabangAndRegionId()['region'];
|
// 'Approved',
|
||||||
|
// 'Approved 1',
|
||||||
|
// 'Approved 2',
|
||||||
|
// 'Final Approved',
|
||||||
|
// 'Final Approve',
|
||||||
|
'Closed',
|
||||||
|
];
|
||||||
|
|
||||||
if ($region_id) {
|
$forms = [];
|
||||||
$users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) {
|
|
||||||
$query->where('region_id', $region_id);
|
|
||||||
})->pluck('user_id');
|
|
||||||
|
|
||||||
foreach ($forms as $key => $query) {
|
foreach ($formQueries as $key => $query) {
|
||||||
$forms[$key] = $query->whereIn('user_id', $users)->whereIn('status', ['Approved', 'Closed']);
|
$forms[$key] = $query
|
||||||
}
|
->whereIn('status', $approvedStatuses)
|
||||||
}
|
->whereNotNull('final_approved_at')
|
||||||
} elseif ($role == 'Area Manager Cabang') {
|
->sum('approved_total');
|
||||||
$cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];
|
|
||||||
|
|
||||||
if ($cabang_id) {
|
|
||||||
$users = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
|
|
||||||
|
|
||||||
foreach ($forms as $key => $query) {
|
|
||||||
$forms[$key] = $query->whereIn('user_id', $users)->whereIn('status', ['Approved', 'Closed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($role == 'Medical Representatif') {
|
|
||||||
foreach ($forms as $key => $query) {
|
|
||||||
$forms[$key] = $query->where('user_id', auth()->user()->id)->whereIn('status', ['Approved', 'Closed']);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($forms as $key => $query) {
|
|
||||||
$forms[$key] = $query->whereIn('status', ['Approved', 'Closed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sum the filtered queries
|
|
||||||
foreach ($forms as $key => $query) {
|
|
||||||
$forms[$key] = $query->sum('approved_total');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
|
|||||||
@@ -465,147 +465,147 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
public function all()
|
public function all()
|
||||||
{
|
{
|
||||||
$role = auth()->user()->getRoleNames()[0]; // Assuming Spatie Laravel-permission
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$cabangs = collect(); // Initialize as an empty collection
|
$cabangs = collect();
|
||||||
$regions = collect(); // Initialize as an empty collection
|
$regions = collect();
|
||||||
|
|
||||||
$availableBudget = 0;
|
$availableBudget = 0;
|
||||||
|
|
||||||
$month = strtolower(date('F')); // convert to lowercase for DB compatibility
|
$currentMonthKey = strtolower(date('F'));
|
||||||
$year = (int) date('Y');
|
$currentYear = (int) date('Y');
|
||||||
|
|
||||||
$region_id = auth()->user()->getMyCabangAndRegionId()['region'] ?? null;
|
$userRegionData = auth()->user()->getMyCabangAndRegionId();
|
||||||
$cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'] ?? null;
|
$region_id = isset($userRegionData['region']) && $userRegionData['region'] !== '-' ? (int) $userRegionData['region'] : null;
|
||||||
|
$cabang_id = isset($userRegionData['cabang']) && $userRegionData['cabang'] !== '-' ? (int) $userRegionData['cabang'] : null;
|
||||||
$userId = auth()->user()->id;
|
$userId = auth()->user()->id;
|
||||||
|
|
||||||
// Initialize the query for forms with eager loading
|
$userFilter = null;
|
||||||
$formsQuery = FormOthers::with([
|
$statusFilter = null;
|
||||||
'user.region', // Eager load 'region' within 'user'
|
$dateRange = null;
|
||||||
'user.cabang', // Eager load 'cabang' within 'user'
|
$selectedMonth = $currentMonthKey;
|
||||||
'kategori'
|
$selectedYear = $currentYear;
|
||||||
]);
|
|
||||||
|
$monthLookup = [
|
||||||
|
'january' => 'January',
|
||||||
|
'february' => 'February',
|
||||||
|
'march' => 'March',
|
||||||
|
'april' => 'April',
|
||||||
|
'may' => 'May',
|
||||||
|
'june' => 'June',
|
||||||
|
'july' => 'July',
|
||||||
|
'august' => 'August',
|
||||||
|
'september' => 'September',
|
||||||
|
'october' => 'October',
|
||||||
|
'november' => 'November',
|
||||||
|
'december' => 'December',
|
||||||
|
];
|
||||||
|
|
||||||
|
$applyUserFilter = static function (array $ids) use (&$userFilter): void {
|
||||||
|
$ids = array_values(array_unique(array_filter($ids, static fn ($id) => !is_null($id))));
|
||||||
|
|
||||||
|
if (empty($ids)) {
|
||||||
|
$userFilter = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($userFilter)) {
|
||||||
|
$userFilter = $ids;
|
||||||
|
} else {
|
||||||
|
$userFilter = array_values(array_intersect($userFilter, $ids));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Apply role-based query logic for initial data
|
|
||||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
||||||
if ($region_id) {
|
if ($region_id) {
|
||||||
$cabangs = Cabang::where('region_id', $region_id)->get();
|
$cabangs = Cabang::where('region_id', $region_id)->get();
|
||||||
$regions = Region::where('id', $region_id)->get();
|
$regions = Region::where('id', $region_id)->get();
|
||||||
$userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
|
$userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id')->toArray();
|
||||||
$formsQuery->whereIn('user_id', $userIds);
|
$applyUserFilter($userIds);
|
||||||
} else {
|
} else {
|
||||||
// If no region found for Admin Region/MOM Region, return empty results
|
$userFilter = [];
|
||||||
$cabangs = collect();
|
|
||||||
$regions = collect();
|
|
||||||
$formsQuery->whereRaw('1 = 0'); // Ensure no results are returned
|
|
||||||
}
|
}
|
||||||
} elseif ($role == 'Area Manager Cabang') {
|
} elseif ($role == 'Area Manager Cabang') {
|
||||||
if ($cabang_id) {
|
if ($cabang_id) {
|
||||||
$cabangs = Cabang::where('id', $cabang_id)->get();
|
$cabangs = Cabang::where('id', $cabang_id)->get();
|
||||||
$regions = Region::where('id', $cabangs->first()->region_id)->get();
|
$regions = $cabangs->isNotEmpty() ? Region::where('id', $cabangs->first()->region_id)->get() : collect();
|
||||||
$userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
|
$userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id')->toArray();
|
||||||
$formsQuery->whereIn('user_id', $userIds);
|
$applyUserFilter($userIds);
|
||||||
} else {
|
} else {
|
||||||
// If no cabang found for Area Manager, return empty results
|
$userFilter = [];
|
||||||
$cabangs = collect();
|
|
||||||
$regions = collect();
|
|
||||||
$formsQuery->whereRaw('1 = 0'); // Ensure no results are returned
|
|
||||||
}
|
}
|
||||||
} elseif ($role == 'Medical Representatif') {
|
} elseif ($role == 'Medical Representatif') {
|
||||||
// For Medical Representative, filter forms by their own user ID
|
$applyUserFilter([$userId]);
|
||||||
$formsQuery->where('user_id', $userId);
|
$cabangs = collect();
|
||||||
// Cabangs and regions might be determined by the user's assigned cabang, or kept empty if not directly relevant to their view
|
$regions = collect();
|
||||||
// If a user is assigned to a specific cabang, you might want to fetch that.
|
|
||||||
// For now, let's keep them empty as per your original logic if not explicitly needed.
|
|
||||||
$cabangs = collect(); // Or fetch the user's assigned cabang: Cabang::find($cabang_id)
|
|
||||||
$regions = collect(); // Or fetch the region of the user's assigned cabang
|
|
||||||
} else {
|
} else {
|
||||||
// Default for roles like 'Admin' or others without specific restrictions
|
|
||||||
$cabangs = Cabang::all();
|
$cabangs = Cabang::all();
|
||||||
$regions = Region::all();
|
$regions = Region::all();
|
||||||
// No specific user_id filter needed here as it's for all forms
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all params in URL
|
|
||||||
$params = request()->all();
|
$params = request()->all();
|
||||||
|
|
||||||
// Apply additional filters from URL parameters
|
if (!empty($params['region'])) {
|
||||||
if ($params) {
|
$selectedRegion = Region::where('code', $params['region'])->first();
|
||||||
// Filter by region (if parameter exists and no prior role-based region filter was applied for Admin Region/MOM)
|
$regionUserIds = $selectedRegion
|
||||||
// Or, if it's a general user (not Admin Region/MOM/Area Manager), allow filtering by region param
|
? UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $selectedRegion->id)->pluck('id'))->pluck('user_id')->toArray()
|
||||||
if (isset($params['region']) && (!in_array($role, ['Admin Region', 'Marketing Operational Manager Region', 'Area Manager Cabang']) || empty($region_id))) {
|
: [];
|
||||||
$region = Region::where('code', $params['region'])->first();
|
$applyUserFilter($regionUserIds);
|
||||||
if ($region) {
|
|
||||||
$userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id')->toArray();
|
|
||||||
$formsQuery->whereIn('user_id', $userIds);
|
|
||||||
} else {
|
|
||||||
// If region param is provided but not found, ensure no results
|
|
||||||
$formsQuery->whereRaw('1 = 0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter by cabang (if parameter exists and no prior role-based cabang filter was applied for Area Manager)
|
if ($selectedRegion && ($regions->isEmpty() || in_array($role, ['Superadmin', 'Admin'], true))) {
|
||||||
// Or, if it's a general user, allow filtering by cabang param
|
$regions = Region::all();
|
||||||
if (isset($params['cabang']) && (!in_array($role, ['Area Manager Cabang']) || empty($cabang_id))) {
|
|
||||||
$cabang = Cabang::where('code', $params['cabang'])->first();
|
|
||||||
if ($cabang) {
|
|
||||||
$userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id')->toArray();
|
|
||||||
$formsQuery->whereIn('user_id', $userIds);
|
|
||||||
|
|
||||||
// Ensure lowercase month for BudgetHelper
|
|
||||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, strtolower($month), (int) $year);
|
|
||||||
} else {
|
|
||||||
// If cabang param is provided but not found, ensure no results
|
|
||||||
$formsQuery->whereRaw('1 = 0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter by date range
|
|
||||||
if (isset($params['month']) || isset($params['year'])) {
|
|
||||||
$month = strtolower($params['month'] ?? date('F'));
|
|
||||||
$year = (int) ($params['year'] ?? date('Y'));
|
|
||||||
|
|
||||||
$startOfMonth = Carbon::parse("first day of $month $year")->startOfDay();
|
|
||||||
$endOfMonth = Carbon::parse("last day of $month $year")->endOfDay();
|
|
||||||
|
|
||||||
$dateColumn = Schema::hasColumn('form_others', 'tanggal') ? 'tanggal' : 'created_at'; // Assuming your forms table is 'form_others'
|
|
||||||
$formsQuery->whereBetween($dateColumn, [$startOfMonth, $endOfMonth]);
|
|
||||||
|
|
||||||
// Recalculate available budget if month/year changed and a cabang filter is present
|
|
||||||
if (isset($params['cabang'])) {
|
|
||||||
$cabang = Cabang::where('code', $params['cabang'])->first();
|
|
||||||
if ($cabang) {
|
|
||||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, strtolower($month), (int) $year);
|
|
||||||
}
|
|
||||||
} elseif ($cabang_id) { // If Area Manager Cabang and no specific cabang param, use their assigned cabang
|
|
||||||
$cabang = Cabang::find($cabang_id);
|
|
||||||
if ($cabang) {
|
|
||||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, strtolower($month), (int) $year);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter by status
|
|
||||||
if (isset($params['status'])) {
|
|
||||||
$formsQuery->where('status', $params['status']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the forms after all filters have been applied
|
if (!empty($params['month']) || !empty($params['year'])) {
|
||||||
// Sort by 'tanggal' if it exists, otherwise by 'created_at'
|
$selectedMonth = strtolower($params['month'] ?? $selectedMonth);
|
||||||
|
$selectedYear = (int) ($params['year'] ?? $selectedYear);
|
||||||
$tables = [
|
|
||||||
|
if (!isset($monthLookup[$selectedMonth])) {
|
||||||
|
$selectedMonth = $currentMonthKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
$monthName = $monthLookup[$selectedMonth];
|
||||||
|
$startOfMonth = Carbon::parse("first day of {$monthName} {$selectedYear}")->startOfDay();
|
||||||
|
$endOfMonth = Carbon::parse("last day of {$monthName} {$selectedYear}")->endOfDay();
|
||||||
|
$dateRange = [$startOfMonth, $endOfMonth];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($params['cabang'])) {
|
||||||
|
$selectedCabang = Cabang::where('code', $params['cabang'])->first();
|
||||||
|
$cabangUserIds = $selectedCabang
|
||||||
|
? UserHasCabang::where('cabang_id', $selectedCabang->id)->pluck('user_id')->toArray()
|
||||||
|
: [];
|
||||||
|
$applyUserFilter($cabangUserIds);
|
||||||
|
|
||||||
|
if ($selectedCabang) {
|
||||||
|
$availableBudget = BudgetHelper::getAvailableBudget($selectedCabang->id, $selectedMonth, $selectedYear);
|
||||||
|
}
|
||||||
|
} elseif ($cabang_id && $dateRange) {
|
||||||
|
$cabang = Cabang::find($cabang_id);
|
||||||
|
if ($cabang) {
|
||||||
|
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, $selectedMonth, $selectedYear);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($params['status'])) {
|
||||||
|
$statusFilter = $params['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tables = [
|
||||||
'form_others',
|
'form_others',
|
||||||
'form_up_country',
|
'form_up_country',
|
||||||
'form_vehicle_running_cost',
|
'form_vehicle_running_cost',
|
||||||
'form_meeting_seminar',
|
'form_meeting_seminar',
|
||||||
'form_entertainment_presentation'
|
'form_entertainment_presentation',
|
||||||
];
|
];
|
||||||
|
|
||||||
$formsQuery = null;
|
$formsQuery = null;
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
|
$dateColumn = Schema::hasColumn($table, 'tanggal') ? 'tanggal' : 'created_at';
|
||||||
|
|
||||||
$query = DB::table($table)
|
$query = DB::table($table)
|
||||||
->selectRaw("
|
->selectRaw("
|
||||||
|
id,
|
||||||
expense_number,
|
expense_number,
|
||||||
'$table' as type,
|
'$table' as type,
|
||||||
user_id,
|
user_id,
|
||||||
@@ -613,40 +613,62 @@ class ReportController extends Controller
|
|||||||
approved_total,
|
approved_total,
|
||||||
account_number,
|
account_number,
|
||||||
status,
|
status,
|
||||||
|
$dateColumn as report_date,
|
||||||
created_at
|
created_at
|
||||||
");
|
");
|
||||||
|
|
||||||
|
if (!is_null($userFilter)) {
|
||||||
|
$query->whereIn('user_id', $userFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($statusFilter !== null) {
|
||||||
|
$query->where('status', $statusFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dateRange) {
|
||||||
|
$query->whereBetween($dateColumn, $dateRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Schema::hasColumn($table, 'deleted_at')) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
}
|
||||||
|
|
||||||
$formsQuery = $formsQuery
|
$formsQuery = $formsQuery
|
||||||
? $formsQuery->unionAll($query)
|
? $formsQuery->unionAll($query)
|
||||||
: $query;
|
: $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
$forms = DB::query()
|
if (!$formsQuery) {
|
||||||
->fromSub($formsQuery, 'forms')
|
$forms = collect();
|
||||||
->join('admins', 'admins.id', '=', 'forms.user_id')
|
} else {
|
||||||
->select('forms.*', 'admins.id as admin_id')
|
$forms = DB::query()
|
||||||
->orderBy('forms.created_at', 'desc')
|
->fromSub($formsQuery, 'forms')
|
||||||
->paginate(100);
|
->join('admins', 'admins.id', '=', 'forms.user_id')
|
||||||
|
->select('forms.*', 'admins.id as admin_id')
|
||||||
|
->orderByDesc('forms.report_date')
|
||||||
|
->paginate(100)
|
||||||
|
->appends($params);
|
||||||
|
|
||||||
|
$forms->getCollection()->transform(function ($item) {
|
||||||
|
$item->user = \App\Models\Admin::with([
|
||||||
// inject relasi Admin model ke setiap item
|
'region.cabang.region',
|
||||||
$forms->getCollection()->transform(function ($item) {
|
'cabang.cabang.region',
|
||||||
$item->user = \App\Models\Admin::with(['region', 'rayon.region'])->find($item->admin_id);
|
'rayon.region',
|
||||||
$item->type = ucwords(str_replace('_', ' ', str_replace('form_', '', $item->type)));
|
])->find($item->admin_id);
|
||||||
|
$item->type = ucwords(str_replace('_', ' ', str_replace('form_', '', $item->type)));
|
||||||
return $item;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return view('backend.pages.report.all', [
|
return view('backend.pages.report.all', [
|
||||||
'pageInfo' => [
|
'pageInfo' => [
|
||||||
'title' => 'Generate Reports For All Forms',
|
'title' => 'Generate Reports For All Forms',
|
||||||
],
|
],
|
||||||
'forms' => $forms,
|
'forms' => $forms,
|
||||||
'cabangs' => $cabangs, // Note the plural 'cabangs' for the variable name
|
'cabangs' => $cabangs,
|
||||||
'regions' => $regions,
|
'regions' => $regions,
|
||||||
'availableBudget' => $availableBudget
|
'availableBudget' => $availableBudget,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,6 +692,22 @@ class ReportController extends Controller
|
|||||||
$cabangs = Cabang::where('id', $cabang_id)->get();
|
$cabangs = Cabang::where('id', $cabang_id)->get();
|
||||||
$regions = Region::where('id', $cabangs[0]->region_id)->get();
|
$regions = Region::where('id', $cabangs[0]->region_id)->get();
|
||||||
}
|
}
|
||||||
|
} else if ($role == 'Superadmin') {
|
||||||
|
$regions = Region::all();
|
||||||
|
$cabangs = collect();
|
||||||
|
$selectedRegionCode = request()->get('region');
|
||||||
|
|
||||||
|
if ($selectedRegionCode) {
|
||||||
|
$selectedRegion = Region::where('code', $selectedRegionCode)->first();
|
||||||
|
|
||||||
|
if ($selectedRegion) {
|
||||||
|
$cabangs = Cabang::where('region_id', $selectedRegion->id)->get();
|
||||||
|
} else {
|
||||||
|
$cabangs = Cabang::all();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$cabangs = Cabang::all();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$cabangs = Cabang::all();
|
$cabangs = Cabang::all();
|
||||||
$regions = Region::all();
|
$regions = Region::all();
|
||||||
@@ -689,8 +727,18 @@ class ReportController extends Controller
|
|||||||
{
|
{
|
||||||
$params = request()->all();
|
$params = request()->all();
|
||||||
|
|
||||||
$kategoris = Kategori::all();
|
|
||||||
$kategori_bca = Kategori::where('name', 'Cash in Bank BCA')->first();
|
$kategori_bca = Kategori::where('name', 'Cash in Bank BCA')->first();
|
||||||
|
$excludedCategories = [
|
||||||
|
'Cash in Bank BCA',
|
||||||
|
'Donasi/Gift',
|
||||||
|
'PPn Masukan',
|
||||||
|
'Vehicle Maintenance',
|
||||||
|
'Bahan Promosi',
|
||||||
|
'Sponsorship',
|
||||||
|
'Presentation',
|
||||||
|
];
|
||||||
|
|
||||||
|
$kategoris = Kategori::whereNotIn('name', $excludedCategories)->get();
|
||||||
$cabang = Cabang::with('cost')->where('code', $params['cabang'])->firstOrFail();
|
$cabang = Cabang::with('cost')->where('code', $params['cabang'])->firstOrFail();
|
||||||
|
|
||||||
$year = $params['year'];
|
$year = $params['year'];
|
||||||
|
|||||||
@@ -37,6 +37,25 @@ class FormOtherController extends Controller
|
|||||||
{
|
{
|
||||||
protected AttachmentService $attachmentService;
|
protected AttachmentService $attachmentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kategori yang tidak boleh dipilih pada Form Others.
|
||||||
|
*
|
||||||
|
* @var array<int,string>
|
||||||
|
*/
|
||||||
|
protected array $excludedKategoriNames = [
|
||||||
|
'Up Country',
|
||||||
|
'Vehicle Running Cost',
|
||||||
|
'Entertainment',
|
||||||
|
'Meeting / Seminar',
|
||||||
|
'Presentation',
|
||||||
|
'Sponsorship',
|
||||||
|
'Cash in Bank BCA',
|
||||||
|
'Donasi/Gift',
|
||||||
|
'PPn Masukan',
|
||||||
|
'Vehicle Maintenance',
|
||||||
|
'Bahan Promosi',
|
||||||
|
];
|
||||||
|
|
||||||
protected array $attachmentCategories = [
|
protected array $attachmentCategories = [
|
||||||
'bukti_total',
|
'bukti_total',
|
||||||
];
|
];
|
||||||
@@ -155,7 +174,7 @@ class FormOtherController extends Controller
|
|||||||
|
|
||||||
return view('backend.pages.forms.other.view', [
|
return view('backend.pages.forms.other.view', [
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'kategori' => Kategori::whereNotIn('name', ['Up Country', 'Vehicle Running Cost', 'Entertainment', 'Meeting / Seminar'])->get(),
|
'kategori' => Kategori::whereNotIn('name', $this->excludedKategoriNames)->get(),
|
||||||
'attachments' => $attachments,
|
'attachments' => $attachments,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -165,7 +184,7 @@ class FormOtherController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.other.create']);
|
$this->checkAuthorization(auth()->user(), ['forms.other.create']);
|
||||||
|
|
||||||
return view('backend.pages.forms.other.create', [
|
return view('backend.pages.forms.other.create', [
|
||||||
'kategori' => Kategori::whereNotIn('name', ['Up Country', 'Vehicle Running Cost', 'Entertainment','Presentation','Sponsorship', 'Meeting / Seminar'])->get(),
|
'kategori' => Kategori::whereNotIn('name', $this->excludedKategoriNames)->get(),
|
||||||
'attachmentCategories' => $this->attachmentCategories,
|
'attachmentCategories' => $this->attachmentCategories,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -396,7 +415,7 @@ class FormOtherController extends Controller
|
|||||||
|
|
||||||
return view('backend.pages.forms.other.edit', [
|
return view('backend.pages.forms.other.edit', [
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'kategori' => Kategori::whereNotIn('name', ['Up Country', 'Vehicle Running Cost', 'Entertainment','Presentation','Sponsorship', 'Meeting / Seminar'])->get(),
|
'kategori' => Kategori::whereNotIn('name', $this->excludedKategoriNames)->get(),
|
||||||
'attachments' => $this->formatAttachmentCollection($form),
|
'attachments' => $this->formatAttachmentCollection($form),
|
||||||
'attachmentCategories' => $this->attachmentCategories,
|
'attachmentCategories' => $this->attachmentCategories,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -38,19 +38,26 @@ use Illuminate\Container\Attributes\Auth;
|
|||||||
class FormUpCountryController extends Controller
|
class FormUpCountryController extends Controller
|
||||||
{
|
{
|
||||||
protected AttachmentService $attachmentService;
|
protected AttachmentService $attachmentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attachment categories (key => label) for Up Country forms.
|
||||||
|
*
|
||||||
|
* @var array<string,string>
|
||||||
|
*/
|
||||||
protected array $attachmentCategories = [
|
protected array $attachmentCategories = [
|
||||||
'bukti_allowance',
|
'bukti_allowance' => 'Bukti Allowance',
|
||||||
'bukti_transport_dalkot',
|
'bukti_transport_dalkot' => 'Bukti Transport Dalam Kota',
|
||||||
'bukti_transport_ankot',
|
'bukti_transport_ankot' => 'Bukti Transport Antar Kota',
|
||||||
'bukti_hotel',
|
'bukti_hotel' => 'Bukti Hotel',
|
||||||
'bukti_total',
|
'bukti_total' => 'Bukti Total',
|
||||||
'bukti_lainnya',
|
'bukti_lainnya' => 'Bukti Lainnya',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(AttachmentService $attachmentService)
|
public function __construct(AttachmentService $attachmentService)
|
||||||
{
|
{
|
||||||
$this->attachmentService = $attachmentService;
|
$this->attachmentService = $attachmentService;
|
||||||
view()->share('upCountryAttachmentCategories', $this->attachmentCategories);
|
view()->share('upCountryAttachmentCategories', $this->attachmentCategories);
|
||||||
|
view()->share('upCountryAttachmentCategoryKeys', array_keys($this->attachmentCategories));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
@@ -186,11 +193,12 @@ class FormUpCountryController extends Controller
|
|||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['forms.country.create']);
|
$this->checkAuthorization(auth()->user(), ['forms.country.create']);
|
||||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
$rayons = $this->getAccessibleRayonsForCurrentUser();
|
||||||
|
|
||||||
return view('backend.pages.forms.upcountry.create', [
|
return view('backend.pages.forms.upcountry.create', [
|
||||||
'rayons' => Rayon::where('cabang_id', $cabang->id)->get(),
|
'rayons' => $rayons,
|
||||||
'attachmentCategories' => $this->attachmentCategories,
|
'attachmentCategories' => array_keys($this->attachmentCategories),
|
||||||
|
'attachmentCategoryLabels' => $this->attachmentCategories,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +215,7 @@ class FormUpCountryController extends Controller
|
|||||||
'transport_ankot' => 'nullable|numeric',
|
'transport_ankot' => 'nullable|numeric',
|
||||||
'hotel' => 'nullable|numeric',
|
'hotel' => 'nullable|numeric',
|
||||||
'attachments' => 'nullable|array',
|
'attachments' => 'nullable|array',
|
||||||
'attachments.*.file_category' => 'required|string|in:' . implode(',', $this->attachmentCategories),
|
'attachments.*.file_category' => 'required|string|in:' . implode(',', array_keys($this->attachmentCategories)),
|
||||||
'attachments.*.file_path' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:5120'],
|
'attachments.*.file_path' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:5120'],
|
||||||
'uc_plan' => 'nullable|file|max:51200',
|
'uc_plan' => 'nullable|file|max:51200',
|
||||||
]);
|
]);
|
||||||
@@ -416,32 +424,19 @@ class FormUpCountryController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
|
|
||||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
$rayonData = $this->getAccessibleRayonsForCurrentUser();
|
||||||
$regionId = Cabang::where('id', 1)->value('region_id');
|
|
||||||
$rayonData = Rayon::where('cabang_id', $cabang->id)->get();
|
|
||||||
|
|
||||||
if ($role == "Admin Region") {
|
|
||||||
$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();
|
|
||||||
} elseif ($role == "Marketing Information System" || $role == "Superadmin") {
|
|
||||||
$rayonData = DB::table('rayon')
|
|
||||||
->join('cabang', 'rayon.cabang_id', '=', 'cabang.id')
|
|
||||||
->join('region', 'cabang.region_id', '=', 'region.id')
|
|
||||||
->whereNotNull('region.id')
|
|
||||||
->select('rayon.*')
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = FormUpCountry::with(['rayon', 'attachments'])->findOrfail($id);
|
$form = FormUpCountry::with(['rayon.cabang', 'attachments'])->findOrfail($id);
|
||||||
if (($form->status != 'On Progress' && $form->status != 'Rejected') && $role == 'Medical Representatif') {
|
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.');
|
session()->flash('error', 'You cannot edit this form because it has been approved or closed.');
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($form->rayon && !$rayonData->contains('id', $form->rayon_id)) {
|
||||||
|
$rayonData->push($form->rayon);
|
||||||
|
$rayonData = $rayonData->sortBy('name')->values();
|
||||||
|
}
|
||||||
|
|
||||||
$existingAttachments = $form->attachments->map(function ($attachment) {
|
$existingAttachments = $form->attachments->map(function ($attachment) {
|
||||||
$filePath = $attachment->file_path;
|
$filePath = $attachment->file_path;
|
||||||
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
||||||
@@ -462,10 +457,42 @@ class FormUpCountryController extends Controller
|
|||||||
'rayons' => $rayonData,
|
'rayons' => $rayonData,
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'attachments' => $existingAttachments,
|
'attachments' => $existingAttachments,
|
||||||
'attachmentCategories' => $this->attachmentCategories,
|
'attachmentCategories' => array_keys($this->attachmentCategories),
|
||||||
|
'attachmentCategoryLabels' => $this->attachmentCategories,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAccessibleRayonsForCurrentUser()
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
$role = $user->getRoleNames()->first();
|
||||||
|
$rayonQuery = Rayon::with('cabang')->orderBy('name');
|
||||||
|
|
||||||
|
if (in_array($role, ['Superadmin', 'Marketing Information System'], true)) {
|
||||||
|
return $rayonQuery->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$userRegionData = $user->getMyCabangAndRegionId();
|
||||||
|
$regionContextId = $userRegionData['region'] !== '-' ? $userRegionData['region'] : null;
|
||||||
|
$cabangContextId = $userRegionData['cabang'] !== '-' ? $userRegionData['cabang'] : null;
|
||||||
|
|
||||||
|
if ($role === 'Admin Region' && $regionContextId) {
|
||||||
|
return $rayonQuery
|
||||||
|
->whereHas('cabang', function ($query) use ($regionContextId) {
|
||||||
|
$query->where('region_id', $regionContextId);
|
||||||
|
})
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cabangContextId) {
|
||||||
|
return $rayonQuery
|
||||||
|
->where('cabang_id', $cabangContextId)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
||||||
@@ -481,7 +508,7 @@ class FormUpCountryController extends Controller
|
|||||||
'transport_ankot' => 'nullable|numeric',
|
'transport_ankot' => 'nullable|numeric',
|
||||||
'hotel' => 'nullable|numeric',
|
'hotel' => 'nullable|numeric',
|
||||||
'attachments' => 'nullable|array',
|
'attachments' => 'nullable|array',
|
||||||
'attachments.*.file_category' => 'required|string|in:' . implode(',', $this->attachmentCategories),
|
'attachments.*.file_category' => 'required|string|in:' . implode(',', array_keys($this->attachmentCategories)),
|
||||||
'attachments.*.file_path' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:5120'],
|
'attachments.*.file_path' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:5120'],
|
||||||
'uc_plan' => 'nullable|file|max:51200',
|
'uc_plan' => 'nullable|file|max:51200',
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@php
|
||||||
|
$attachmentCategoryLabels = $meetingAttachmentCategories ?? [];
|
||||||
|
$attachmentCategories = $meetingAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels);
|
||||||
|
@endphp
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="card card-primary card-outline">
|
<div class="card card-primary card-outline">
|
||||||
@@ -76,7 +80,7 @@
|
|||||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
<h5 class="mb-0">Lampiran</h5>
|
<h5 class="mb-0">Lampiran</h5>
|
||||||
<button type="button" class="btn btn-sm btn-primary" id="meeting-add-attachment-row">
|
<button type="button" class="btn btn-sm btn-primary" id="meeting-add-attachment-row">
|
||||||
<i class="fas fa-plus mr-1"></i> Tambah Attachment
|
<i class="fas fa-plus mr-1"></i> Tambah Lampiran
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -85,13 +89,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%;">Kategori</th>
|
<th style="width: 30%;">Kategori</th>
|
||||||
<th>File</th>
|
<th>File</th>
|
||||||
<th style="width: 120px;" class="text-center">Preview</th>
|
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 80px;" class="text-center">Aksi</th>
|
<th style="width: 80px;" class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="meeting-empty-row">
|
<tr class="meeting-empty-row">
|
||||||
<td colspan="4" class="text-center text-muted">Belum ada attachment.</td>
|
<td colspan="4" class="text-center text-muted">Belum ada lampiran.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -111,7 +115,7 @@
|
|||||||
<div class="spinner-wrapper">
|
<div class="spinner-wrapper">
|
||||||
<div class="spinner-border text-primary" role="status">
|
<div class="spinner-border text-primary" role="status">
|
||||||
</div>
|
</div>
|
||||||
<p>Submitting, please wait...</p>
|
<p>Sedang mengirim, mohon tunggu...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -81,12 +81,15 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 25%;">Kategori</th>
|
<th style="width: 25%;">Kategori</th>
|
||||||
<th>Nama File</th>
|
<th>Nama File</th>
|
||||||
<th style="width: 120px;" class="text-center">Preview</th>
|
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 120px;" class="text-center">Download</th>
|
<th style="width: 120px;" class="text-center">Unduh</th>
|
||||||
<th style="width: 100px;" class="text-center">Delete</th>
|
<th style="width: 100px;" class="text-center">Hapus</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@php
|
||||||
|
$attachmentCategoryLabels = $meetingAttachmentCategories ?? [];
|
||||||
|
@endphp
|
||||||
@forelse ($attachments as $attachment)
|
@forelse ($attachments as $attachment)
|
||||||
<tr class="meeting-attachment-row">
|
<tr class="meeting-attachment-row">
|
||||||
<td>{{ $attachment['category_label'] ?? '-' }}</td>
|
<td>{{ $attachment['category_label'] ?? '-' }}</td>
|
||||||
@@ -98,13 +101,13 @@
|
|||||||
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
||||||
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
||||||
data-filename="{{ $attachment['filename'] }}">
|
data-filename="{{ $attachment['filename'] }}">
|
||||||
Preview
|
Pratinjau
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@if (!empty($attachment['download_url']))
|
@if (!empty($attachment['download_url']))
|
||||||
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">
|
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">
|
||||||
Download
|
Unduh
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<span class="text-muted">Tidak tersedia</span>
|
<span class="text-muted">Tidak tersedia</span>
|
||||||
@@ -123,8 +126,8 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr class="meeting-empty-row">
|
<tr class="meeting-empty-row">
|
||||||
<td colspan="5" class="text-center text-muted">Belum ada attachment.</td>
|
<td colspan="5" class="text-center text-muted">Belum ada lampiran.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -137,7 +140,7 @@
|
|||||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
<h5 class="mb-0">Tambah Lampiran Baru</h5>
|
<h5 class="mb-0">Tambah Lampiran Baru</h5>
|
||||||
<button type="button" class="btn btn-sm btn-primary" id="meeting-add-attachment-row">
|
<button type="button" class="btn btn-sm btn-primary" id="meeting-add-attachment-row">
|
||||||
<i class="fas fa-plus mr-1"></i> Tambah Attachment
|
<i class="fas fa-plus mr-1"></i> Tambah Lampiran
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -146,13 +149,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%;">Kategori</th>
|
<th style="width: 30%;">Kategori</th>
|
||||||
<th>File</th>
|
<th>File</th>
|
||||||
<th style="width: 120px;" class="text-center">Preview</th>
|
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 80px;" class="text-center">Aksi</th>
|
<th style="width: 80px;" class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="meeting-empty-row">
|
<tr class="meeting-empty-row">
|
||||||
<td colspan="4" class="text-center text-muted">Belum ada attachment.</td>
|
<td colspan="4" class="text-center text-muted">Belum ada lampiran.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -172,7 +175,7 @@
|
|||||||
<div class="spinner-wrapper">
|
<div class="spinner-wrapper">
|
||||||
<div class="spinner-border text-primary" role="status">
|
<div class="spinner-border text-primary" role="status">
|
||||||
</div>
|
</div>
|
||||||
<p>Submitting, please wait...</p>
|
<p>Sedang mengirim, mohon tunggu...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
<div class="modal-dialog modal-lg" role="document">
|
<div class="modal-dialog modal-lg" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title mb-0" id="meetingAttachmentPreviewModalLabel">Preview Lampiran</h5>
|
<h5 class="modal-title mb-0" id="meetingAttachmentPreviewModalLabel">Pratinjau Lampiran</h5>
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="meeting-preview-image d-none text-center">
|
<div class="meeting-preview-image d-none text-center">
|
||||||
<img src="" alt="Preview Lampiran" class="img-fluid">
|
<img src="" alt="Pratinjau Lampiran" class="img-fluid">
|
||||||
</div>
|
</div>
|
||||||
<div class="meeting-preview-pdf d-none">
|
<div class="meeting-preview-pdf d-none">
|
||||||
<object data="" type="application/pdf" width="100%" height="500px"></object>
|
<object data="" type="application/pdf" width="100%" height="500px"></object>
|
||||||
</div>
|
</div>
|
||||||
<div class="meeting-preview-fallback d-none text-center">
|
<div class="meeting-preview-fallback d-none text-center">
|
||||||
<p class="mb-2">Preview tidak tersedia untuk file ini.</p>
|
<p class="mb-2">Preview tidak tersedia untuk file ini.</p>
|
||||||
<button type="button" class="btn btn-primary meeting-preview-download-direct">Download</button>
|
<button type="button" class="btn btn-primary meeting-preview-download-direct">Unduh</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -49,14 +49,53 @@
|
|||||||
|
|
||||||
function ensureEmptyRowState($tbody) {
|
function ensureEmptyRowState($tbody) {
|
||||||
if ($tbody.find('.meeting-attachment-row').length === 0) {
|
if ($tbody.find('.meeting-attachment-row').length === 0) {
|
||||||
|
const columnCount = $tbody.closest('table').find('thead th').length || 4;
|
||||||
$tbody.html(
|
$tbody.html(
|
||||||
'<tr class="meeting-empty-row">' +
|
'<tr class="meeting-empty-row">' +
|
||||||
'<td colspan="4" class="text-center text-muted">Belum ada attachment.</td>' +
|
'<td colspan="' + columnCount + '" class="text-center text-muted">Belum ada lampiran.</td>' +
|
||||||
'</tr>'
|
'</tr>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetInlinePreview($row) {
|
||||||
|
const $previewBox = $row.find('.meeting-attachment-inline-preview');
|
||||||
|
if ($previewBox.length) {
|
||||||
|
$previewBox
|
||||||
|
.removeClass('bg-light')
|
||||||
|
.html('<i class="fas fa-file-upload text-muted"></i>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setInlinePreview($row, type, source) {
|
||||||
|
const $previewBox = $row.find('.meeting-attachment-inline-preview');
|
||||||
|
if (!$previewBox.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resetInlinePreview($row);
|
||||||
|
|
||||||
|
if (type === 'image' && source) {
|
||||||
|
$previewBox
|
||||||
|
.addClass('bg-light')
|
||||||
|
.html('<img src="' + source + '" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'pdf') {
|
||||||
|
$previewBox
|
||||||
|
.addClass('bg-light')
|
||||||
|
.html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type && source) {
|
||||||
|
$previewBox
|
||||||
|
.addClass('bg-light')
|
||||||
|
.html('<i class="fas fa-file text-secondary fa-lg"></i>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function cleanupPreviewButton($button) {
|
function cleanupPreviewButton($button) {
|
||||||
const objectUrl = $button.data('objectUrl');
|
const objectUrl = $button.data('objectUrl');
|
||||||
if (objectUrl) {
|
if (objectUrl) {
|
||||||
@@ -68,6 +107,7 @@
|
|||||||
.data('downloadUrl', null)
|
.data('downloadUrl', null)
|
||||||
.data('objectUrl', null)
|
.data('objectUrl', null)
|
||||||
.data('filename', null);
|
.data('filename', null);
|
||||||
|
resetInlinePreview($button.closest('tr'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetAttachmentRow($row) {
|
function resetAttachmentRow($row) {
|
||||||
@@ -77,6 +117,7 @@
|
|||||||
$row.find('.meeting-selected-filename').text('');
|
$row.find('.meeting-selected-filename').text('');
|
||||||
const $fileInput = $row.find('.meeting-new-attachment-file');
|
const $fileInput = $row.find('.meeting-new-attachment-file');
|
||||||
$fileInput.val('');
|
$fileInput.val('');
|
||||||
|
resetInlinePreview($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileExtension(filename) {
|
function getFileExtension(filename) {
|
||||||
@@ -220,12 +261,19 @@
|
|||||||
'</select>' +
|
'</select>' +
|
||||||
'</td>' +
|
'</td>' +
|
||||||
'<td>' +
|
'<td>' +
|
||||||
'<input type="file" class="form-control meeting-new-attachment-file" name="attachments[' + index + '][file_path]">' +
|
'<div class="d-flex align-items-center" style="gap: 0.75rem;">' +
|
||||||
'<small class="form-text text-muted meeting-selected-filename"></small>' +
|
'<div class="meeting-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">' +
|
||||||
|
'<i class="fas fa-file-upload text-muted"></i>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="flex-grow-1">' +
|
||||||
|
'<input type="file" class="form-control meeting-new-attachment-file" name="attachments[' + index + '][file_path]">' +
|
||||||
|
'<small class="form-text text-muted meeting-selected-filename"></small>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
'</td>' +
|
'</td>' +
|
||||||
'<td class="text-center">' +
|
'<td class="text-center">' +
|
||||||
'<button type="button" class="btn btn-sm btn-outline-secondary meeting-preview-trigger d-none">' +
|
'<button type="button" class="btn btn-sm btn-outline-secondary meeting-preview-trigger d-none">' +
|
||||||
'Preview' +
|
'Pratinjau' +
|
||||||
'</button>' +
|
'</button>' +
|
||||||
'</td>' +
|
'</td>' +
|
||||||
'<td class="text-center">' +
|
'<td class="text-center">' +
|
||||||
@@ -296,14 +344,15 @@
|
|||||||
|
|
||||||
const extension = getFileExtension(filename);
|
const extension = getFileExtension(filename);
|
||||||
const previewType = getPreviewType(extension);
|
const previewType = getPreviewType(extension);
|
||||||
|
|
||||||
$previewButton.data('previewType', previewType);
|
$previewButton.data('previewType', previewType);
|
||||||
$previewButton.data('filename', filename);
|
$previewButton.data('filename', filename);
|
||||||
|
|
||||||
if (previewType === 'image') {
|
if (previewType === 'image') {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function (event) {
|
reader.onload = function (event) {
|
||||||
$previewButton.data('previewSource', event.target.result);
|
const result = event.target.result;
|
||||||
|
$previewButton.data('previewSource', result);
|
||||||
|
setInlinePreview($row, 'image', result);
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
} else if (previewType === 'pdf') {
|
} else if (previewType === 'pdf') {
|
||||||
@@ -311,10 +360,12 @@
|
|||||||
$previewButton.data('previewSource', objectUrl);
|
$previewButton.data('previewSource', objectUrl);
|
||||||
$previewButton.data('downloadUrl', objectUrl);
|
$previewButton.data('downloadUrl', objectUrl);
|
||||||
$previewButton.data('objectUrl', objectUrl);
|
$previewButton.data('objectUrl', objectUrl);
|
||||||
|
setInlinePreview($row, 'pdf', objectUrl);
|
||||||
} else {
|
} else {
|
||||||
const objectUrl = URL.createObjectURL(file);
|
const objectUrl = URL.createObjectURL(file);
|
||||||
$previewButton.data('downloadUrl', objectUrl);
|
$previewButton.data('downloadUrl', objectUrl);
|
||||||
$previewButton.data('objectUrl', objectUrl);
|
$previewButton.data('objectUrl', objectUrl);
|
||||||
|
setInlinePreview($row, previewType, objectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$previewButton.removeClass('d-none');
|
$previewButton.removeClass('d-none');
|
||||||
@@ -349,12 +400,12 @@
|
|||||||
_token: $('meta[name="csrf-token"]').attr('content')
|
_token: $('meta[name="csrf-token"]').attr('content')
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
showAlert(response.message || 'Attachment berhasil dihapus.', 'success');
|
showAlert(response.message || 'Lampiran berhasil dihapus.', 'success');
|
||||||
$row.remove();
|
$row.remove();
|
||||||
ensureEmptyRowState($('#meeting-existing-attachments-table tbody'));
|
ensureEmptyRowState($('#meeting-existing-attachments-table tbody'));
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
const message = (xhr.responseJSON && xhr.responseJSON.message) ? xhr.responseJSON.message : 'Gagal menghapus attachment.';
|
const message = (xhr.responseJSON && xhr.responseJSON.message) ? xhr.responseJSON.message : 'Gagal menghapus lampiran.';
|
||||||
showAlert(message);
|
showAlert(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -68,8 +68,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%;">Kategori</th>
|
<th style="width: 30%;">Kategori</th>
|
||||||
<th>Nama File</th>
|
<th>Nama File</th>
|
||||||
<th style="width: 120px;" class="text-center">Preview</th>
|
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 120px;" class="text-center">Download</th>
|
<th style="width: 120px;" class="text-center">Unduh</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -84,12 +84,12 @@
|
|||||||
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
||||||
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
||||||
data-filename="{{ $attachment['filename'] }}">
|
data-filename="{{ $attachment['filename'] }}">
|
||||||
Preview
|
Pratinjau
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@if (!empty($attachment['download_url']))
|
@if (!empty($attachment['download_url']))
|
||||||
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">Download</a>
|
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">Unduh</a>
|
||||||
@else
|
@else
|
||||||
<span class="text-muted">Tidak tersedia</span>
|
<span class="text-muted">Tidak tersedia</span>
|
||||||
@endif
|
@endif
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr class="meeting-empty-row">
|
<tr class="meeting-empty-row">
|
||||||
<td colspan="4" class="text-center text-muted">Belum ada attachment.</td>
|
<td colspan="4" class="text-center text-muted">Belum ada lampiran.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@php
|
||||||
|
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
|
||||||
|
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
|
||||||
|
@endphp
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="card card-primary card-outline">
|
<div class="card card-primary card-outline">
|
||||||
@@ -54,7 +58,9 @@
|
|||||||
<select class="form-control form-control-md" name="rayon_id" required>
|
<select class="form-control form-control-md" name="rayon_id" required>
|
||||||
<option value="">Pilih Rayon</option>
|
<option value="">Pilih Rayon</option>
|
||||||
@foreach ($rayons as $rayon)
|
@foreach ($rayons as $rayon)
|
||||||
<option value="{{ $rayon->id }}">{{ $rayon->name }}</option>
|
<option value="{{ $rayon->id }}">
|
||||||
|
{{ $rayon->name }}{{ $rayon->cabang ? ' - ' . $rayon->cabang->name : '' }}
|
||||||
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -94,22 +100,22 @@
|
|||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="d-flex align-items-center justify-content-between">
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
<label class="form-label mb-0">Attachments</label>
|
<label class="form-label mb-0">Lampiran</label>
|
||||||
<button type="button" class="btn btn-outline-primary btn-sm" id="add-attachment-row">
|
<button type="button" class="btn btn-outline-primary btn-sm" id="add-attachment-row">
|
||||||
<i class="fas fa-plus me-1"></i> Add Attachment
|
<i class="fas fa-plus me-1"></i> Tambah Lampiran
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-muted small mt-1 mb-2">
|
<p class="text-muted small mt-1 mb-2">
|
||||||
Allowed files: JPG, JPEG, PNG, PDF. Max size 5 MB per file.
|
Format file yang diperbolehkan: JPG, JPEG, PNG, atau PDF. Ukuran maksimum 5 MB per file.
|
||||||
</p>
|
</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered align-middle" id="attachments-table">
|
<table class="table table-bordered align-middle" id="attachments-table">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%">File Category</th>
|
<th style="width: 30%">Kategori Lampiran</th>
|
||||||
<th style="width: 45%">Attachment</th>
|
<th style="width: 45%">Lampiran</th>
|
||||||
<th style="width: 15%" class="text-center">Preview</th>
|
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 10%" class="text-center">Action</th>
|
<th style="width: 10%" class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -137,11 +143,11 @@
|
|||||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">Attachment Preview - <span id="newAttachmentPreviewTitle"></span></h5>
|
<h5 class="modal-title">Pratinjau Lampiran - <span id="newAttachmentPreviewTitle" class="attachment-preview-modal-title"></span></h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<img id="newAttachmentPreviewImage" class="img-fluid d-none" alt="Attachment preview">
|
<img id="newAttachmentPreviewImage" class="img-fluid d-none" alt="Pratinjau lampiran">
|
||||||
<iframe id="newAttachmentPreviewPdf" class="w-100 d-none" style="min-height: 480px;" frameborder="0"></iframe>
|
<iframe id="newAttachmentPreviewPdf" class="w-100 d-none" style="min-height: 480px;" frameborder="0"></iframe>
|
||||||
<div id="newAttachmentPreviewPlaceholder" class="text-center text-muted">Tidak ada file untuk ditampilkan.</div>
|
<div id="newAttachmentPreviewPlaceholder" class="text-center text-muted">Tidak ada file untuk ditampilkan.</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,7 +159,7 @@
|
|||||||
<div class="spinner-wrapper">
|
<div class="spinner-wrapper">
|
||||||
<div class="spinner-border text-primary" role="status">
|
<div class="spinner-border text-primary" role="status">
|
||||||
</div>
|
</div>
|
||||||
<p>Submitting, please wait...</p>
|
<p>Sedang mengirim, mohon tunggu...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -194,22 +200,27 @@
|
|||||||
unformatOnSubmit: true
|
unformatOnSubmit: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategories ?? []));
|
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
|
||||||
|
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
|
||||||
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
||||||
let attachmentIndex = 0;
|
let attachmentIndex = 0;
|
||||||
|
|
||||||
function categoryToLabel(value) {
|
function categoryToLabel(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return 'Pilih Kategori';
|
return 'Pilih Kategori';
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
|
||||||
.replace(/_/g, ' ')
|
return attachmentCategoryLabels[value];
|
||||||
.replace(/\b\w/g, (char) => char.toUpperCase());
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
.replace(/_/g, ' ')
|
||||||
|
.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildCategoryOptions() {
|
function buildCategoryOptions() {
|
||||||
return attachmentCategories
|
return attachmentCategories
|
||||||
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
|
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
|
||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
@@ -257,14 +268,14 @@
|
|||||||
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
|
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
|
||||||
<i class="fas fa-file-upload text-muted"></i>
|
<i class="fas fa-file-upload text-muted"></i>
|
||||||
</div>
|
</div>
|
||||||
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}">
|
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}">
|
||||||
</div>
|
</div>
|
||||||
<div class="small text-muted mt-1 preview-filename"></div>
|
<div class="small text-muted mt-1 preview-filename"></div>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
|
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
|
||||||
Preview
|
Pratinjau
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
|
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
|
||||||
@@ -295,7 +306,7 @@
|
|||||||
|
|
||||||
if (type === 'image' && source) {
|
if (type === 'image' && source) {
|
||||||
previewBox
|
previewBox
|
||||||
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Preview image">`)
|
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">`)
|
||||||
.addClass('bg-light');
|
.addClass('bg-light');
|
||||||
} else if (type === 'pdf') {
|
} else if (type === 'pdf') {
|
||||||
previewBox
|
previewBox
|
||||||
@@ -312,7 +323,7 @@
|
|||||||
const $object = $modal.find('.attachment-preview-object');
|
const $object = $modal.find('.attachment-preview-object');
|
||||||
const $placeholder = $modal.find('.attachment-preview-placeholder');
|
const $placeholder = $modal.find('.attachment-preview-placeholder');
|
||||||
|
|
||||||
$modal.find('.attachment-preview-modal-title').text(title || 'Attachment');
|
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
|
||||||
$image.addClass('d-none').attr('src', '');
|
$image.addClass('d-none').attr('src', '');
|
||||||
$object.addClass('d-none').attr('data', '').attr('src', '');
|
$object.addClass('d-none').attr('data', '').attr('src', '');
|
||||||
$placeholder.removeClass('d-none');
|
$placeholder.removeClass('d-none');
|
||||||
@@ -399,4 +410,3 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@php
|
||||||
|
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
|
||||||
|
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
|
||||||
|
@endphp
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="card card-primary card-outline">
|
<div class="card card-primary card-outline">
|
||||||
@@ -56,7 +60,9 @@
|
|||||||
<select class="form-control form-control-md" name="rayon_id" required>
|
<select class="form-control form-control-md" name="rayon_id" required>
|
||||||
<option value="">Pilih Rayon</option>
|
<option value="">Pilih Rayon</option>
|
||||||
@foreach ($rayons as $rayon)
|
@foreach ($rayons as $rayon)
|
||||||
<option value="{{ $rayon->id }}" {{ $form->rayon_id == $rayon->id ? 'selected' : '' }}>{{ $rayon->name }}</option>
|
<option value="{{ $rayon->id }}" {{ $form->rayon_id == $rayon->id ? 'selected' : '' }}>
|
||||||
|
{{ $rayon->name }}{{ $rayon->cabang ? ' - ' . $rayon->cabang->name : '' }}
|
||||||
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -95,24 +101,26 @@
|
|||||||
|
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label class="form-label mb-0">Existing Attachments</label>
|
<label class="form-label mb-0">Lampiran Tersimpan</label>
|
||||||
<p class="text-muted small mt-1 mb-2">Preview, download, or delete attachments that were previously uploaded.</p>
|
<p class="text-muted small mt-1 mb-2">Pratinjau, unduh, atau hapus lampiran yang telah diunggah sebelumnya.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered align-middle" id="existing-attachments-table">
|
<table class="table table-bordered align-middle" id="existing-attachments-table">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%">File Category</th>
|
<th style="width: 30%">Kategori Lampiran</th>
|
||||||
<th style="width: 30%">Filename</th>
|
<th style="width: 30%">Nama File</th>
|
||||||
<th style="width: 15%" class="text-center">Preview</th>
|
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 15%" class="text-center">Download</th>
|
<th style="width: 15%" class="text-center">Unduh</th>
|
||||||
<th style="width: 10%" class="text-center">Action</th>
|
<th style="width: 10%" class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@forelse ($attachments as $attachment)
|
@forelse ($attachments as $attachment)
|
||||||
@php
|
@php
|
||||||
$categoryValue = $attachment['file_category'] ?? null;
|
$categoryValue = $attachment['file_category'] ?? null;
|
||||||
$categoryLabel = $categoryValue ? ucwords(str_replace('_', ' ', $categoryValue)) : '-';
|
$categoryLabel = $categoryValue
|
||||||
|
? ($attachmentCategoryLabels[$categoryValue] ?? ucwords(str_replace('_', ' ', $categoryValue)))
|
||||||
|
: '-';
|
||||||
@endphp
|
@endphp
|
||||||
<tr data-attachment-id="{{ $attachment['id'] }}">
|
<tr data-attachment-id="{{ $attachment['id'] }}">
|
||||||
<td>{{ $categoryLabel }}</td>
|
<td>{{ $categoryLabel }}</td>
|
||||||
@@ -124,14 +132,14 @@
|
|||||||
data-download-url="{{ $attachment['download_url'] }}"
|
data-download-url="{{ $attachment['download_url'] }}"
|
||||||
data-preview-type="{{ $attachment['preview_type'] }}"
|
data-preview-type="{{ $attachment['preview_type'] }}"
|
||||||
data-category="{{ $categoryLabel }}">
|
data-category="{{ $categoryLabel }}">
|
||||||
Preview
|
Pratinjau
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<a href="{{ $attachment['download_url'] }}"
|
<a href="{{ $attachment['download_url'] }}"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="btn btn-sm btn-outline-primary">
|
class="btn btn-sm btn-outline-primary">
|
||||||
Download
|
Unduh
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@@ -156,22 +164,22 @@
|
|||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="d-flex align-items-center justify-content-between">
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
<label class="form-label mb-0">Add New Attachments</label>
|
<label class="form-label mb-0">Tambah Lampiran Baru</label>
|
||||||
<button type="button" class="btn btn-outline-primary btn-sm" id="add-new-attachment-row">
|
<button type="button" class="btn btn-outline-primary btn-sm" id="add-new-attachment-row">
|
||||||
<i class="fas fa-plus me-1"></i> Add Attachment
|
<i class="fas fa-plus me-1"></i> Tambah Lampiran
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-muted small mt-1 mb-2">
|
<p class="text-muted small mt-1 mb-2">
|
||||||
Allowed files: JPG, JPEG, PNG, PDF. Max size 5 MB per file.
|
Format file yang diperbolehkan: JPG, JPEG, PNG, atau PDF. Ukuran maksimum 5 MB per file.
|
||||||
</p>
|
</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered align-middle" id="new-attachments-table">
|
<table class="table table-bordered align-middle" id="new-attachments-table">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 30%">File Category</th>
|
<th style="width: 30%">Kategori Lampiran</th>
|
||||||
<th style="width: 45%">Attachment</th>
|
<th style="width: 45%">Lampiran</th>
|
||||||
<th style="width: 15%" class="text-center">Preview</th>
|
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||||
<th style="width: 10%" class="text-center">Action</th>
|
<th style="width: 10%" class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -197,19 +205,19 @@
|
|||||||
|
|
||||||
@include('backend.components.attachment-preview-modal', [
|
@include('backend.components.attachment-preview-modal', [
|
||||||
'modalId' => 'existingAttachmentPreviewModal',
|
'modalId' => 'existingAttachmentPreviewModal',
|
||||||
'title' => 'Attachment Preview',
|
'title' => 'Pratinjau Lampiran',
|
||||||
])
|
])
|
||||||
|
|
||||||
@include('backend.components.attachment-preview-modal', [
|
@include('backend.components.attachment-preview-modal', [
|
||||||
'modalId' => 'newAttachmentPreviewModal',
|
'modalId' => 'newAttachmentPreviewModal',
|
||||||
'title' => 'Attachment Preview',
|
'title' => 'Pratinjau Lampiran',
|
||||||
])
|
])
|
||||||
|
|
||||||
<div id="loading-spinner-overlay" class="d-none">
|
<div id="loading-spinner-overlay" class="d-none">
|
||||||
<div class="spinner-wrapper">
|
<div class="spinner-wrapper">
|
||||||
<div class="spinner-border text-primary" role="status">
|
<div class="spinner-border text-primary" role="status">
|
||||||
</div>
|
</div>
|
||||||
<p>Submitting, please wait...</p>
|
<p>Sedang mengirim, mohon tunggu...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -250,7 +258,8 @@
|
|||||||
unformatOnSubmit: true
|
unformatOnSubmit: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategories ?? []));
|
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
|
||||||
|
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
|
||||||
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
||||||
let attachmentIndex = 0;
|
let attachmentIndex = 0;
|
||||||
let newAttachmentsTableBody;
|
let newAttachmentsTableBody;
|
||||||
@@ -263,6 +272,10 @@
|
|||||||
return 'Pilih Kategori';
|
return 'Pilih Kategori';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
|
||||||
|
return attachmentCategoryLabels[value];
|
||||||
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
.replace(/_/g, ' ')
|
.replace(/_/g, ' ')
|
||||||
.replace(/\b\w/g, (char) => char.toUpperCase());
|
.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||||
@@ -324,7 +337,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none">
|
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none">
|
||||||
Preview
|
Pratinjau
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@@ -357,7 +370,7 @@
|
|||||||
|
|
||||||
if (type === 'image' && source) {
|
if (type === 'image' && source) {
|
||||||
previewBox
|
previewBox
|
||||||
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Preview image">`)
|
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">`)
|
||||||
.addClass('bg-light');
|
.addClass('bg-light');
|
||||||
} else if (type === 'pdf') {
|
} else if (type === 'pdf') {
|
||||||
previewBox
|
previewBox
|
||||||
@@ -374,7 +387,7 @@
|
|||||||
const $object = $modal.find('.attachment-preview-object');
|
const $object = $modal.find('.attachment-preview-object');
|
||||||
const $placeholder = $modal.find('.attachment-preview-placeholder');
|
const $placeholder = $modal.find('.attachment-preview-placeholder');
|
||||||
|
|
||||||
$modal.find('.attachment-preview-modal-title').text(title || 'Attachment');
|
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
|
||||||
$image.addClass('d-none').attr('src', '');
|
$image.addClass('d-none').attr('src', '');
|
||||||
$object.addClass('d-none').attr('data', '').attr('src', '');
|
$object.addClass('d-none').attr('data', '').attr('src', '');
|
||||||
$placeholder.removeClass('d-none');
|
$placeholder.removeClass('d-none');
|
||||||
@@ -477,7 +490,7 @@
|
|||||||
const previewType = button.data('preview-type');
|
const previewType = button.data('preview-type');
|
||||||
const previewUrl = button.data('preview-url');
|
const previewUrl = button.data('preview-url');
|
||||||
const downloadUrl = button.data('download-url');
|
const downloadUrl = button.data('download-url');
|
||||||
const category = button.data('category') || 'Attachment';
|
const category = button.data('category') || 'Lampiran';
|
||||||
|
|
||||||
if (!previewUrl) {
|
if (!previewUrl) {
|
||||||
if (downloadUrl) {
|
if (downloadUrl) {
|
||||||
@@ -527,6 +540,3 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label for="region">Pilih Region</label>
|
<label for="region">Pilih Region</label>
|
||||||
<select name="region" id="region" class="form-control" required>
|
<select name="region" id="region" class="form-control">
|
||||||
<option value="">Semua Region</option>
|
<option value="">Semua Region</option>
|
||||||
@foreach ($regions as $region)
|
@foreach ($regions as $region)
|
||||||
<option value="{{ $region->code }}" {{ request()->region == $region->code ? 'selected' : '' }}>
|
<option value="{{ $region->code }}" {{ request()->region == $region->code ? 'selected' : '' }}>
|
||||||
@@ -29,16 +29,20 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label for="cabang">Pilih Cabang</label>
|
<label for="cabang">Pilih Cabang</label>
|
||||||
<select name="cabang" id="cabang" class="form-control" required>
|
<select name="cabang" id="cabang" class="form-control">
|
||||||
<option value="">Semua Cabang</option>
|
<option value="">Semua Cabang</option>
|
||||||
<!-- Cabang options will be dynamically populated -->
|
@foreach ($cabang as $itemCabang)
|
||||||
|
<option value="{{ $itemCabang->code }}" {{ request()->cabang == $itemCabang->code ? 'selected' : '' }}>
|
||||||
|
{{ $itemCabang->name }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label for="month">Pilih Periode Bulan</label>
|
<label for="month">Pilih Periode Bulan</label>
|
||||||
<select name="month" id="month" class="form-control" required>
|
<select name="month" id="month" class="form-control">
|
||||||
<option value="">Pilih Bulan</option>
|
<option value="">Pilih Bulan</option>
|
||||||
<option value="january" {{ request()->month == 'january' ? 'selected' : '' }}>Januari</option>
|
<option value="january" {{ request()->month == 'january' ? 'selected' : '' }}>Januari</option>
|
||||||
<option value="february" {{ request()->month == 'february' ? 'selected' : '' }}>Februari</option>
|
<option value="february" {{ request()->month == 'february' ? 'selected' : '' }}>Februari</option>
|
||||||
@@ -59,7 +63,7 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label for="year">Pilih Periode Tahun</label>
|
<label for="year">Pilih Periode Tahun</label>
|
||||||
<select name="year" id="year" class="form-control" required>
|
<select name="year" id="year" class="form-control">
|
||||||
<option value="">Pilih Tahun</option>
|
<option value="">Pilih Tahun</option>
|
||||||
@for ($i = 2024; $i <= date('Y'); $i++)
|
@for ($i = 2024; $i <= date('Y'); $i++)
|
||||||
<option value="{{ $i }}" {{ request()->year == $i ? 'selected' : '' }}>{{ $i }}</option>
|
<option value="{{ $i }}" {{ request()->year == $i ? 'selected' : '' }}>{{ $i }}</option>
|
||||||
@@ -120,27 +124,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
|
||||||
document.getElementById('region').addEventListener('change', function () {
|
|
||||||
const regionCode = this.value;
|
|
||||||
const cabangSelect = document.getElementById('cabang');
|
|
||||||
|
|
||||||
// Clear existing options
|
|
||||||
cabangSelect.innerHTML = '<option value="">Semua Cabang</option>';
|
|
||||||
|
|
||||||
if (regionCode) {
|
|
||||||
fetch(`/api/cabang-by-region/${regionCode}`)
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
data.forEach(cabang => {
|
|
||||||
const option = document.createElement('option');
|
|
||||||
option.value = cabang.code;
|
|
||||||
option.textContent = cabang.name;
|
|
||||||
cabangSelect.appendChild(option);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => console.error('Error fetching cabang data:', error));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user