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();
|
||||
}
|
||||
|
||||
$forms = [
|
||||
'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'upcountry' => FormUpCountry::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m'))
|
||||
->whereBetween('created_at', [$startDate, $closingDate])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get(),
|
||||
'others' => FormOthers::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
$formQueries = [
|
||||
'vehicle' => FormVehicleRunningCost::query()
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||
'upcountry' => FormUpCountry::query()
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||
'entertainment' => FormEntertaimentPresentation::query()
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||
'meeting' => FormMeetingSeminar::query()
|
||||
->whereMonth('created_at', date('m'))
|
||||
->whereBetween('created_at', [$startDate, $closingDate]),
|
||||
'others' => FormOthers::query()
|
||||
->whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDate]),
|
||||
];
|
||||
|
||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
||||
$region_id = auth()->user()->getMyCabangAndRegionId()['region'];
|
||||
$approvedStatuses = [
|
||||
// 'Approved',
|
||||
// 'Approved 1',
|
||||
// 'Approved 2',
|
||||
// 'Final Approved',
|
||||
// 'Final Approve',
|
||||
'Closed',
|
||||
];
|
||||
|
||||
if ($region_id) {
|
||||
$users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) {
|
||||
$query->where('region_id', $region_id);
|
||||
})->pluck('user_id');
|
||||
$forms = [];
|
||||
|
||||
foreach ($forms as $key => $query) {
|
||||
$forms[$key] = $query->whereIn('user_id', $users)->whereIn('status', ['Approved', 'Closed']);
|
||||
}
|
||||
}
|
||||
} elseif ($role == 'Area Manager Cabang') {
|
||||
$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');
|
||||
foreach ($formQueries as $key => $query) {
|
||||
$forms[$key] = $query
|
||||
->whereIn('status', $approvedStatuses)
|
||||
->whereNotNull('final_approved_at')
|
||||
->sum('approved_total');
|
||||
}
|
||||
|
||||
return view(
|
||||
|
||||
@@ -465,147 +465,147 @@ class ReportController extends Controller
|
||||
|
||||
public function all()
|
||||
{
|
||||
$role = auth()->user()->getRoleNames()[0]; // Assuming Spatie Laravel-permission
|
||||
$cabangs = collect(); // Initialize as an empty collection
|
||||
$regions = collect(); // Initialize as an empty collection
|
||||
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$cabangs = collect();
|
||||
$regions = collect();
|
||||
$availableBudget = 0;
|
||||
|
||||
$month = strtolower(date('F')); // convert to lowercase for DB compatibility
|
||||
$year = (int) date('Y');
|
||||
$currentMonthKey = strtolower(date('F'));
|
||||
$currentYear = (int) date('Y');
|
||||
|
||||
$region_id = auth()->user()->getMyCabangAndRegionId()['region'] ?? null;
|
||||
$cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'] ?? null;
|
||||
$userRegionData = auth()->user()->getMyCabangAndRegionId();
|
||||
$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;
|
||||
|
||||
// Initialize the query for forms with eager loading
|
||||
$formsQuery = FormOthers::with([
|
||||
'user.region', // Eager load 'region' within 'user'
|
||||
'user.cabang', // Eager load 'cabang' within 'user'
|
||||
'kategori'
|
||||
]);
|
||||
$userFilter = null;
|
||||
$statusFilter = null;
|
||||
$dateRange = null;
|
||||
$selectedMonth = $currentMonthKey;
|
||||
$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 ($region_id) {
|
||||
$cabangs = Cabang::where('region_id', $region_id)->get();
|
||||
$regions = Region::where('id', $region_id)->get();
|
||||
$userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
|
||||
$formsQuery->whereIn('user_id', $userIds);
|
||||
$userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id')->toArray();
|
||||
$applyUserFilter($userIds);
|
||||
} else {
|
||||
// If no region found for Admin Region/MOM Region, return empty results
|
||||
$cabangs = collect();
|
||||
$regions = collect();
|
||||
$formsQuery->whereRaw('1 = 0'); // Ensure no results are returned
|
||||
$userFilter = [];
|
||||
}
|
||||
} elseif ($role == 'Area Manager Cabang') {
|
||||
if ($cabang_id) {
|
||||
$cabangs = Cabang::where('id', $cabang_id)->get();
|
||||
$regions = Region::where('id', $cabangs->first()->region_id)->get();
|
||||
$userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
|
||||
$formsQuery->whereIn('user_id', $userIds);
|
||||
$regions = $cabangs->isNotEmpty() ? Region::where('id', $cabangs->first()->region_id)->get() : collect();
|
||||
$userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id')->toArray();
|
||||
$applyUserFilter($userIds);
|
||||
} else {
|
||||
// If no cabang found for Area Manager, return empty results
|
||||
$cabangs = collect();
|
||||
$regions = collect();
|
||||
$formsQuery->whereRaw('1 = 0'); // Ensure no results are returned
|
||||
$userFilter = [];
|
||||
}
|
||||
} elseif ($role == 'Medical Representatif') {
|
||||
// For Medical Representative, filter forms by their own user ID
|
||||
$formsQuery->where('user_id', $userId);
|
||||
// Cabangs and regions might be determined by the user's assigned cabang, or kept empty if not directly relevant to their view
|
||||
// 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
|
||||
$applyUserFilter([$userId]);
|
||||
$cabangs = collect();
|
||||
$regions = collect();
|
||||
} else {
|
||||
// Default for roles like 'Admin' or others without specific restrictions
|
||||
$cabangs = Cabang::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();
|
||||
|
||||
// Apply additional filters from URL parameters
|
||||
if ($params) {
|
||||
// Filter by region (if parameter exists and no prior role-based region filter was applied for Admin Region/MOM)
|
||||
// Or, if it's a general user (not Admin Region/MOM/Area Manager), allow filtering by region param
|
||||
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();
|
||||
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');
|
||||
if (!empty($params['region'])) {
|
||||
$selectedRegion = Region::where('code', $params['region'])->first();
|
||||
$regionUserIds = $selectedRegion
|
||||
? UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $selectedRegion->id)->pluck('id'))->pluck('user_id')->toArray()
|
||||
: [];
|
||||
$applyUserFilter($regionUserIds);
|
||||
|
||||
if ($selectedRegion && ($regions->isEmpty() || in_array($role, ['Superadmin', 'Admin'], true))) {
|
||||
$regions = Region::all();
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by cabang (if parameter exists and no prior role-based cabang filter was applied for Area Manager)
|
||||
// Or, if it's a general user, allow filtering by cabang param
|
||||
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);
|
||||
if (!empty($params['month']) || !empty($params['year'])) {
|
||||
$selectedMonth = strtolower($params['month'] ?? $selectedMonth);
|
||||
$selectedYear = (int) ($params['year'] ?? $selectedYear);
|
||||
|
||||
// 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');
|
||||
}
|
||||
if (!isset($monthLookup[$selectedMonth])) {
|
||||
$selectedMonth = $currentMonthKey;
|
||||
}
|
||||
|
||||
// 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);
|
||||
$monthName = $monthLookup[$selectedMonth];
|
||||
$startOfMonth = Carbon::parse("first day of {$monthName} {$selectedYear}")->startOfDay();
|
||||
$endOfMonth = Carbon::parse("last day of {$monthName} {$selectedYear}")->endOfDay();
|
||||
$dateRange = [$startOfMonth, $endOfMonth];
|
||||
}
|
||||
} elseif ($cabang_id) { // If Area Manager Cabang and no specific cabang param, use their assigned cabang
|
||||
|
||||
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, strtolower($month), (int) $year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by status
|
||||
if (isset($params['status'])) {
|
||||
$formsQuery->where('status', $params['status']);
|
||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, $selectedMonth, $selectedYear);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the forms after all filters have been applied
|
||||
// Sort by 'tanggal' if it exists, otherwise by 'created_at'
|
||||
if (!empty($params['status'])) {
|
||||
$statusFilter = $params['status'];
|
||||
}
|
||||
|
||||
$tables = [
|
||||
'form_others',
|
||||
'form_up_country',
|
||||
'form_vehicle_running_cost',
|
||||
'form_meeting_seminar',
|
||||
'form_entertainment_presentation'
|
||||
'form_entertainment_presentation',
|
||||
];
|
||||
|
||||
$formsQuery = null;
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$dateColumn = Schema::hasColumn($table, 'tanggal') ? 'tanggal' : 'created_at';
|
||||
|
||||
$query = DB::table($table)
|
||||
->selectRaw("
|
||||
id,
|
||||
expense_number,
|
||||
'$table' as type,
|
||||
user_id,
|
||||
@@ -613,40 +613,62 @@ class ReportController extends Controller
|
||||
approved_total,
|
||||
account_number,
|
||||
status,
|
||||
$dateColumn as report_date,
|
||||
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->unionAll($query)
|
||||
: $query;
|
||||
}
|
||||
|
||||
if (!$formsQuery) {
|
||||
$forms = collect();
|
||||
} else {
|
||||
$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);
|
||||
->orderByDesc('forms.report_date')
|
||||
->paginate(100)
|
||||
->appends($params);
|
||||
|
||||
|
||||
|
||||
// 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->user = \App\Models\Admin::with([
|
||||
'region.cabang.region',
|
||||
'cabang.cabang.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', [
|
||||
'pageInfo' => [
|
||||
'title' => 'Generate Reports For All Forms',
|
||||
],
|
||||
'forms' => $forms,
|
||||
'cabangs' => $cabangs, // Note the plural 'cabangs' for the variable name
|
||||
'cabangs' => $cabangs,
|
||||
'regions' => $regions,
|
||||
'availableBudget' => $availableBudget
|
||||
'availableBudget' => $availableBudget,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -670,6 +692,22 @@ class ReportController extends Controller
|
||||
$cabangs = Cabang::where('id', $cabang_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 {
|
||||
$cabangs = Cabang::all();
|
||||
$regions = Region::all();
|
||||
@@ -689,8 +727,18 @@ class ReportController extends Controller
|
||||
{
|
||||
$params = request()->all();
|
||||
|
||||
$kategoris = Kategori::all();
|
||||
$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();
|
||||
|
||||
$year = $params['year'];
|
||||
|
||||
@@ -37,6 +37,25 @@ class FormOtherController extends Controller
|
||||
{
|
||||
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 = [
|
||||
'bukti_total',
|
||||
];
|
||||
@@ -155,7 +174,7 @@ class FormOtherController extends Controller
|
||||
|
||||
return view('backend.pages.forms.other.view', [
|
||||
'form' => $form,
|
||||
'kategori' => Kategori::whereNotIn('name', ['Up Country', 'Vehicle Running Cost', 'Entertainment', 'Meeting / Seminar'])->get(),
|
||||
'kategori' => Kategori::whereNotIn('name', $this->excludedKategoriNames)->get(),
|
||||
'attachments' => $attachments,
|
||||
]);
|
||||
}
|
||||
@@ -165,7 +184,7 @@ class FormOtherController extends Controller
|
||||
$this->checkAuthorization(auth()->user(), ['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,
|
||||
]);
|
||||
}
|
||||
@@ -396,7 +415,7 @@ class FormOtherController extends Controller
|
||||
|
||||
return view('backend.pages.forms.other.edit', [
|
||||
'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),
|
||||
'attachmentCategories' => $this->attachmentCategories,
|
||||
]);
|
||||
|
||||
@@ -38,19 +38,26 @@ use Illuminate\Container\Attributes\Auth;
|
||||
class FormUpCountryController extends Controller
|
||||
{
|
||||
protected AttachmentService $attachmentService;
|
||||
|
||||
/**
|
||||
* Attachment categories (key => label) for Up Country forms.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
protected array $attachmentCategories = [
|
||||
'bukti_allowance',
|
||||
'bukti_transport_dalkot',
|
||||
'bukti_transport_ankot',
|
||||
'bukti_hotel',
|
||||
'bukti_total',
|
||||
'bukti_lainnya',
|
||||
'bukti_allowance' => 'Bukti Allowance',
|
||||
'bukti_transport_dalkot' => 'Bukti Transport Dalam Kota',
|
||||
'bukti_transport_ankot' => 'Bukti Transport Antar Kota',
|
||||
'bukti_hotel' => 'Bukti Hotel',
|
||||
'bukti_total' => 'Bukti Total',
|
||||
'bukti_lainnya' => 'Bukti Lainnya',
|
||||
];
|
||||
|
||||
public function __construct(AttachmentService $attachmentService)
|
||||
{
|
||||
$this->attachmentService = $attachmentService;
|
||||
view()->share('upCountryAttachmentCategories', $this->attachmentCategories);
|
||||
view()->share('upCountryAttachmentCategoryKeys', array_keys($this->attachmentCategories));
|
||||
}
|
||||
|
||||
public function index()
|
||||
@@ -186,11 +193,12 @@ class FormUpCountryController extends Controller
|
||||
public function 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', [
|
||||
'rayons' => Rayon::where('cabang_id', $cabang->id)->get(),
|
||||
'attachmentCategories' => $this->attachmentCategories,
|
||||
'rayons' => $rayons,
|
||||
'attachmentCategories' => array_keys($this->attachmentCategories),
|
||||
'attachmentCategoryLabels' => $this->attachmentCategories,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -207,7 +215,7 @@ class FormUpCountryController extends Controller
|
||||
'transport_ankot' => 'nullable|numeric',
|
||||
'hotel' => 'nullable|numeric',
|
||||
'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'],
|
||||
'uc_plan' => 'nullable|file|max:51200',
|
||||
]);
|
||||
@@ -416,32 +424,19 @@ class FormUpCountryController extends Controller
|
||||
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
||||
$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();
|
||||
$rayonData = $this->getAccessibleRayonsForCurrentUser();
|
||||
|
||||
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') {
|
||||
session()->flash('error', 'You cannot edit this form because it has been approved or closed.');
|
||||
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) {
|
||||
$filePath = $attachment->file_path;
|
||||
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
||||
@@ -462,10 +457,42 @@ class FormUpCountryController extends Controller
|
||||
'rayons' => $rayonData,
|
||||
'form' => $form,
|
||||
'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)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.country.edit']);
|
||||
@@ -481,7 +508,7 @@ class FormUpCountryController extends Controller
|
||||
'transport_ankot' => 'nullable|numeric',
|
||||
'hotel' => 'nullable|numeric',
|
||||
'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'],
|
||||
'uc_plan' => 'nullable|file|max:51200',
|
||||
]);
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
@php
|
||||
$attachmentCategoryLabels = $meetingAttachmentCategories ?? [];
|
||||
$attachmentCategories = $meetingAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels);
|
||||
@endphp
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
@@ -76,7 +80,7 @@
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h5 class="mb-0">Lampiran</h5>
|
||||
<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>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@@ -85,13 +89,13 @@
|
||||
<tr>
|
||||
<th style="width: 30%;">Kategori</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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<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>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -111,7 +115,7 @@
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
</div>
|
||||
<p>Submitting, please wait...</p>
|
||||
<p>Sedang mengirim, mohon tunggu...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -81,12 +81,15 @@
|
||||
<tr>
|
||||
<th style="width: 25%;">Kategori</th>
|
||||
<th>Nama File</th>
|
||||
<th style="width: 120px;" class="text-center">Preview</th>
|
||||
<th style="width: 120px;" class="text-center">Download</th>
|
||||
<th style="width: 100px;" class="text-center">Delete</th>
|
||||
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||
<th style="width: 120px;" class="text-center">Unduh</th>
|
||||
<th style="width: 100px;" class="text-center">Hapus</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$attachmentCategoryLabels = $meetingAttachmentCategories ?? [];
|
||||
@endphp
|
||||
@forelse ($attachments as $attachment)
|
||||
<tr class="meeting-attachment-row">
|
||||
<td>{{ $attachment['category_label'] ?? '-' }}</td>
|
||||
@@ -98,13 +101,13 @@
|
||||
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
||||
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
||||
data-filename="{{ $attachment['filename'] }}">
|
||||
Preview
|
||||
Pratinjau
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@if (!empty($attachment['download_url']))
|
||||
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">
|
||||
Download
|
||||
Unduh
|
||||
</a>
|
||||
@else
|
||||
<span class="text-muted">Tidak tersedia</span>
|
||||
@@ -124,7 +127,7 @@
|
||||
</tr>
|
||||
@empty
|
||||
<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>
|
||||
@endforelse
|
||||
</tbody>
|
||||
@@ -137,7 +140,7 @@
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h5 class="mb-0">Tambah Lampiran Baru</h5>
|
||||
<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>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@@ -146,13 +149,13 @@
|
||||
<tr>
|
||||
<th style="width: 30%;">Kategori</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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<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>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -172,7 +175,7 @@
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
</div>
|
||||
<p>Submitting, please wait...</p>
|
||||
<p>Sedang mengirim, mohon tunggu...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<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">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<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 class="meeting-preview-pdf d-none">
|
||||
<object data="" type="application/pdf" width="100%" height="500px"></object>
|
||||
</div>
|
||||
<div class="meeting-preview-fallback d-none text-center">
|
||||
<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>
|
||||
|
||||
@@ -49,14 +49,53 @@
|
||||
|
||||
function ensureEmptyRowState($tbody) {
|
||||
if ($tbody.find('.meeting-attachment-row').length === 0) {
|
||||
const columnCount = $tbody.closest('table').find('thead th').length || 4;
|
||||
$tbody.html(
|
||||
'<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>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
const objectUrl = $button.data('objectUrl');
|
||||
if (objectUrl) {
|
||||
@@ -68,6 +107,7 @@
|
||||
.data('downloadUrl', null)
|
||||
.data('objectUrl', null)
|
||||
.data('filename', null);
|
||||
resetInlinePreview($button.closest('tr'));
|
||||
}
|
||||
|
||||
function resetAttachmentRow($row) {
|
||||
@@ -77,6 +117,7 @@
|
||||
$row.find('.meeting-selected-filename').text('');
|
||||
const $fileInput = $row.find('.meeting-new-attachment-file');
|
||||
$fileInput.val('');
|
||||
resetInlinePreview($row);
|
||||
}
|
||||
|
||||
function getFileExtension(filename) {
|
||||
@@ -220,12 +261,19 @@
|
||||
'</select>' +
|
||||
'</td>' +
|
||||
'<td>' +
|
||||
'<div class="d-flex align-items-center" style="gap: 0.75rem;">' +
|
||||
'<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 class="text-center">' +
|
||||
'<button type="button" class="btn btn-sm btn-outline-secondary meeting-preview-trigger d-none">' +
|
||||
'Preview' +
|
||||
'Pratinjau' +
|
||||
'</button>' +
|
||||
'</td>' +
|
||||
'<td class="text-center">' +
|
||||
@@ -296,14 +344,15 @@
|
||||
|
||||
const extension = getFileExtension(filename);
|
||||
const previewType = getPreviewType(extension);
|
||||
|
||||
$previewButton.data('previewType', previewType);
|
||||
$previewButton.data('filename', filename);
|
||||
|
||||
if (previewType === 'image') {
|
||||
const reader = new FileReader();
|
||||
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);
|
||||
} else if (previewType === 'pdf') {
|
||||
@@ -311,10 +360,12 @@
|
||||
$previewButton.data('previewSource', objectUrl);
|
||||
$previewButton.data('downloadUrl', objectUrl);
|
||||
$previewButton.data('objectUrl', objectUrl);
|
||||
setInlinePreview($row, 'pdf', objectUrl);
|
||||
} else {
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
$previewButton.data('downloadUrl', objectUrl);
|
||||
$previewButton.data('objectUrl', objectUrl);
|
||||
setInlinePreview($row, previewType, objectUrl);
|
||||
}
|
||||
|
||||
$previewButton.removeClass('d-none');
|
||||
@@ -349,12 +400,12 @@
|
||||
_token: $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
success: function (response) {
|
||||
showAlert(response.message || 'Attachment berhasil dihapus.', 'success');
|
||||
showAlert(response.message || 'Lampiran berhasil dihapus.', 'success');
|
||||
$row.remove();
|
||||
ensureEmptyRowState($('#meeting-existing-attachments-table tbody'));
|
||||
},
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
<tr>
|
||||
<th style="width: 30%;">Kategori</th>
|
||||
<th>Nama File</th>
|
||||
<th style="width: 120px;" class="text-center">Preview</th>
|
||||
<th style="width: 120px;" class="text-center">Download</th>
|
||||
<th style="width: 120px;" class="text-center">Pratinjau</th>
|
||||
<th style="width: 120px;" class="text-center">Unduh</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -84,12 +84,12 @@
|
||||
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
|
||||
data-download-url="{{ $attachment['download_url'] ?? '' }}"
|
||||
data-filename="{{ $attachment['filename'] }}">
|
||||
Preview
|
||||
Pratinjau
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@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
|
||||
<span class="text-muted">Tidak tersedia</span>
|
||||
@endif
|
||||
@@ -97,7 +97,7 @@
|
||||
</tr>
|
||||
@empty
|
||||
<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>
|
||||
@endforelse
|
||||
</tbody>
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
@php
|
||||
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
|
||||
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
|
||||
@endphp
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
@@ -54,7 +58,9 @@
|
||||
<select class="form-control form-control-md" name="rayon_id" required>
|
||||
<option value="">Pilih Rayon</option>
|
||||
@foreach ($rayons as $rayon)
|
||||
<option value="{{ $rayon->id }}">{{ $rayon->name }}</option>
|
||||
<option value="{{ $rayon->id }}">
|
||||
{{ $rayon->name }}{{ $rayon->cabang ? ' - ' . $rayon->cabang->name : '' }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@@ -94,22 +100,22 @@
|
||||
<div class="col-lg-12">
|
||||
<div class="mb-3">
|
||||
<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">
|
||||
<i class="fas fa-plus me-1"></i> Add Attachment
|
||||
<i class="fas fa-plus me-1"></i> Tambah Lampiran
|
||||
</button>
|
||||
</div>
|
||||
<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>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="attachments-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 30%">File Category</th>
|
||||
<th style="width: 45%">Attachment</th>
|
||||
<th style="width: 15%" class="text-center">Preview</th>
|
||||
<th style="width: 10%" class="text-center">Action</th>
|
||||
<th style="width: 30%">Kategori Lampiran</th>
|
||||
<th style="width: 45%">Lampiran</th>
|
||||
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||
<th style="width: 10%" class="text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -137,11 +143,11 @@
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
<div id="newAttachmentPreviewPlaceholder" class="text-center text-muted">Tidak ada file untuk ditampilkan.</div>
|
||||
</div>
|
||||
@@ -153,7 +159,7 @@
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
</div>
|
||||
<p>Submitting, please wait...</p>
|
||||
<p>Sedang mengirim, mohon tunggu...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -194,7 +200,8 @@
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategories ?? []));
|
||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
|
||||
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
|
||||
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
||||
let attachmentIndex = 0;
|
||||
|
||||
@@ -203,6 +210,10 @@
|
||||
return 'Pilih Kategori';
|
||||
}
|
||||
|
||||
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
|
||||
return attachmentCategoryLabels[value];
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(/_/g, ' ')
|
||||
.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||
@@ -263,7 +274,7 @@
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
|
||||
Preview
|
||||
Pratinjau
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@@ -295,7 +306,7 @@
|
||||
|
||||
if (type === 'image' && source) {
|
||||
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');
|
||||
} else if (type === 'pdf') {
|
||||
previewBox
|
||||
@@ -312,7 +323,7 @@
|
||||
const $object = $modal.find('.attachment-preview-object');
|
||||
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', '');
|
||||
$object.addClass('d-none').attr('data', '').attr('src', '');
|
||||
$placeholder.removeClass('d-none');
|
||||
@@ -399,4 +410,3 @@
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
@php
|
||||
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
|
||||
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
|
||||
@endphp
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
@@ -56,7 +60,9 @@
|
||||
<select class="form-control form-control-md" name="rayon_id" required>
|
||||
<option value="">Pilih Rayon</option>
|
||||
@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
|
||||
</select>
|
||||
</div>
|
||||
@@ -95,24 +101,26 @@
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="mb-4">
|
||||
<label class="form-label mb-0">Existing Attachments</label>
|
||||
<p class="text-muted small mt-1 mb-2">Preview, download, or delete attachments that were previously uploaded.</p>
|
||||
<label class="form-label mb-0">Lampiran Tersimpan</label>
|
||||
<p class="text-muted small mt-1 mb-2">Pratinjau, unduh, atau hapus lampiran yang telah diunggah sebelumnya.</p>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="existing-attachments-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 30%">File Category</th>
|
||||
<th style="width: 30%">Filename</th>
|
||||
<th style="width: 15%" class="text-center">Preview</th>
|
||||
<th style="width: 15%" class="text-center">Download</th>
|
||||
<th style="width: 10%" class="text-center">Action</th>
|
||||
<th style="width: 30%">Kategori Lampiran</th>
|
||||
<th style="width: 30%">Nama File</th>
|
||||
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||
<th style="width: 15%" class="text-center">Unduh</th>
|
||||
<th style="width: 10%" class="text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($attachments as $attachment)
|
||||
@php
|
||||
$categoryValue = $attachment['file_category'] ?? null;
|
||||
$categoryLabel = $categoryValue ? ucwords(str_replace('_', ' ', $categoryValue)) : '-';
|
||||
$categoryLabel = $categoryValue
|
||||
? ($attachmentCategoryLabels[$categoryValue] ?? ucwords(str_replace('_', ' ', $categoryValue)))
|
||||
: '-';
|
||||
@endphp
|
||||
<tr data-attachment-id="{{ $attachment['id'] }}">
|
||||
<td>{{ $categoryLabel }}</td>
|
||||
@@ -124,14 +132,14 @@
|
||||
data-download-url="{{ $attachment['download_url'] }}"
|
||||
data-preview-type="{{ $attachment['preview_type'] }}"
|
||||
data-category="{{ $categoryLabel }}">
|
||||
Preview
|
||||
Pratinjau
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="{{ $attachment['download_url'] }}"
|
||||
target="_blank"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
Download
|
||||
Unduh
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@@ -156,22 +164,22 @@
|
||||
<div class="col-lg-12">
|
||||
<div class="mb-3">
|
||||
<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">
|
||||
<i class="fas fa-plus me-1"></i> Add Attachment
|
||||
<i class="fas fa-plus me-1"></i> Tambah Lampiran
|
||||
</button>
|
||||
</div>
|
||||
<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>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="new-attachments-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 30%">File Category</th>
|
||||
<th style="width: 45%">Attachment</th>
|
||||
<th style="width: 15%" class="text-center">Preview</th>
|
||||
<th style="width: 10%" class="text-center">Action</th>
|
||||
<th style="width: 30%">Kategori Lampiran</th>
|
||||
<th style="width: 45%">Lampiran</th>
|
||||
<th style="width: 15%" class="text-center">Pratinjau</th>
|
||||
<th style="width: 10%" class="text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -197,19 +205,19 @@
|
||||
|
||||
@include('backend.components.attachment-preview-modal', [
|
||||
'modalId' => 'existingAttachmentPreviewModal',
|
||||
'title' => 'Attachment Preview',
|
||||
'title' => 'Pratinjau Lampiran',
|
||||
])
|
||||
|
||||
@include('backend.components.attachment-preview-modal', [
|
||||
'modalId' => 'newAttachmentPreviewModal',
|
||||
'title' => 'Attachment Preview',
|
||||
'title' => 'Pratinjau Lampiran',
|
||||
])
|
||||
|
||||
<div id="loading-spinner-overlay" class="d-none">
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
</div>
|
||||
<p>Submitting, please wait...</p>
|
||||
<p>Sedang mengirim, mohon tunggu...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -250,7 +258,8 @@
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategories ?? []));
|
||||
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
|
||||
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
|
||||
const fileAccept = '.jpg,.jpeg,.png,.pdf';
|
||||
let attachmentIndex = 0;
|
||||
let newAttachmentsTableBody;
|
||||
@@ -263,6 +272,10 @@
|
||||
return 'Pilih Kategori';
|
||||
}
|
||||
|
||||
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
|
||||
return attachmentCategoryLabels[value];
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(/_/g, ' ')
|
||||
.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||
@@ -324,7 +337,7 @@
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none">
|
||||
Preview
|
||||
Pratinjau
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@@ -357,7 +370,7 @@
|
||||
|
||||
if (type === 'image' && source) {
|
||||
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');
|
||||
} else if (type === 'pdf') {
|
||||
previewBox
|
||||
@@ -374,7 +387,7 @@
|
||||
const $object = $modal.find('.attachment-preview-object');
|
||||
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', '');
|
||||
$object.addClass('d-none').attr('data', '').attr('src', '');
|
||||
$placeholder.removeClass('d-none');
|
||||
@@ -477,7 +490,7 @@
|
||||
const previewType = button.data('preview-type');
|
||||
const previewUrl = button.data('preview-url');
|
||||
const downloadUrl = button.data('download-url');
|
||||
const category = button.data('category') || 'Attachment';
|
||||
const category = button.data('category') || 'Lampiran';
|
||||
|
||||
if (!previewUrl) {
|
||||
if (downloadUrl) {
|
||||
@@ -527,6 +540,3 @@
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<div class="col-md-3">
|
||||
<div class="form-group mb-3">
|
||||
<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>
|
||||
@foreach ($regions as $region)
|
||||
<option value="{{ $region->code }}" {{ request()->region == $region->code ? 'selected' : '' }}>
|
||||
@@ -29,16 +29,20 @@
|
||||
<div class="col-md-3">
|
||||
<div class="form-group mb-3">
|
||||
<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>
|
||||
<!-- Cabang options will be dynamically populated -->
|
||||
@foreach ($cabang as $itemCabang)
|
||||
<option value="{{ $itemCabang->code }}" {{ request()->cabang == $itemCabang->code ? 'selected' : '' }}>
|
||||
{{ $itemCabang->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group mb-3">
|
||||
<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="january" {{ request()->month == 'january' ? 'selected' : '' }}>Januari</option>
|
||||
<option value="february" {{ request()->month == 'february' ? 'selected' : '' }}>Februari</option>
|
||||
@@ -59,7 +63,7 @@
|
||||
<div class="col-md-3">
|
||||
<div class="form-group mb-3">
|
||||
<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>
|
||||
@for ($i = 2024; $i <= date('Y'); $i++)
|
||||
<option value="{{ $i }}" {{ request()->year == $i ? 'selected' : '' }}>{{ $i }}</option>
|
||||
@@ -120,27 +124,6 @@
|
||||
}
|
||||
</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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user