<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group(['namespace' => 'App\Http\Controllers'], function () {
    Route::get('/', 'HomeController@index')->name('home.index');

    Route::group(['middleware' => ['guest']], function () {
        Route::get(
            '/register',
            'RegisterController@show'
        )->name('register.show');
        Route::post('/register', 'RegisterController@register')->name('register.perform');

        Route::get('/login', 'LoginController@show')->name('login');
        Route::post('/login', 'LoginController@login')->name('login.perform');
    });

    Route::group(['middleware' => ['auth', 'permission']], function () {

        Route::get('/logout', 'LogoutController@perform')->name('logout.perform');

        Route::group(['prefix' => 'users', 'middleware' => ['auth']], function () {
            Route::get('/', 'UsersController@index')->name('users.index');
            Route::get('/create', 'UsersController@create')->name('users.create');
            Route::post('/{prm_id}/{prm_type?}/create', 'UsersController@store')->name('users.store');
            // Route::post('/{prm_id}/{prm_type}/create', 'UsersController@store')->name('users.store');
            Route::get('/{user}/show', 'UsersController@show')->name('users.show');
            Route::get('/{user}/edit', 'UsersController@edit')->name('users.edit');
            Route::get('/{user}/edit-my-account', 'UsersController@editMyAccount')->name('users.edit-my-account');
            Route::get('/{user}/change-password', 'UsersController@changePassword')->name('users.change-password');
            Route::get('/{user}/reset-password', 'UsersController@resetPassword')->name('users.reset-password');
            Route::delete('/{user}/delete', 'UsersController@destroy')->name('users.destroy');
            
            // Session Management Routes (Admin only)
            Route::get('/session-management', 'UsersController@sessionManagement')->name('users.session_management');
            Route::post('/{userId}/kill-session', 'UsersController@killSession')->name('users.kill_session');
        });

        Route::resource('roles', RolesController::class);
        Route::resource('permissions', PermissionsController::class);
 
        // Master Data Routes
        Route::group(['prefix' => 'raw_materials', 'middleware' => ['auth']], function () {
            Route::get('/', 'RawMaterialsController@index')->name('raw_materials.index');
            Route::get('/create', 'RawMaterialsController@create')->name('raw_materials.create');
            Route::post('/{prm_id}/create', 'RawMaterialsController@store')->name('raw_materials.store');
            Route::get('/{rawMaterial}/show', 'RawMaterialsController@show')->name('raw_materials.show');
            Route::get('/{rawMaterial}/edit', 'RawMaterialsController@edit')->name('raw_materials.edit');
            Route::delete('/{rawMaterial}/delete', 'RawMaterialsController@destroy')->name('raw_materials.destroy');
            Route::post('/upload_excel', 'RawMaterialsController@uploadExcel')->name('raw_materials.upload_excel');
            Route::get('/download_template', 'RawMaterialsController@downloadTemplate')->name('raw_materials.download_template');
        });

        // Item Conversions Routes
        Route::group(['prefix' => 'item_conversions', 'middleware' => ['auth']], function () {
            Route::get('/', 'ItemConversionsController@index')->name('item_conversions.index');
            Route::get('/create', 'ItemConversionsController@create')->name('item_conversions.create');
            Route::post('/{prm_id}/create', 'ItemConversionsController@store')->name('item_conversions.store');
            Route::get('/{itemConversion}/show', 'ItemConversionsController@show')->name('item_conversions.show');
            Route::get('/{itemConversion}/edit', 'ItemConversionsController@edit')->name('item_conversions.edit');
            Route::delete('/{itemConversion}/delete', 'ItemConversionsController@destroy')->name('item_conversions.destroy');
            Route::post('/upload_excel', 'ItemConversionsController@uploadExcel')->name('item_conversions.upload_excel');
            Route::get('/download_template', 'ItemConversionsController@downloadTemplate')->name('item_conversions.download_template');
        });

        // Menus Routes
        Route::group(['prefix' => 'menus', 'middleware' => ['auth']], function () {
            Route::get('/', 'MenusController@index')->name('menus.index');
            Route::get('/create', 'MenusController@create')->name('menus.create');
            Route::post('/{prm_id}/create', 'MenusController@store')->name('menus.store');
            Route::get('/{menu}/show', 'MenusController@show')->name('menus.show');
            Route::get('/{menu}/edit', 'MenusController@edit')->name('menus.edit');
            Route::delete('/{menu}/delete', 'MenusController@destroy')->name('menus.destroy');
            Route::post('/upload_excel', 'MenusController@uploadExcel')->name('menus.upload_excel');
            Route::get('/download_template', 'MenusController@downloadTemplate')->name('menus.download_template');
        });

        // Range DOI Routes
        Route::group(['prefix' => 'range_dois', 'middleware' => ['auth']], function () {
            Route::get('/', 'RangeDoisController@index')->name('range_dois.index');
            Route::get('/create', 'RangeDoisController@create')->name('range_dois.create');
            Route::post('/{prm_id}/create', 'RangeDoisController@store')->name('range_dois.store');
            Route::get('/{rangeDoi}/show', 'RangeDoisController@show')->name('range_dois.show');
            Route::get('/{rangeDoi}/edit', 'RangeDoisController@edit')->name('range_dois.edit');
            Route::delete('/{rangeDoi}/delete', 'RangeDoisController@destroy')->name('range_dois.destroy');
        });

        // FSTR Routes
        Route::group(['prefix' => 'fstrs', 'middleware' => ['auth']], function () {
            Route::get('/', 'FstrsController@index')->name('fstrs.index');
            Route::get('/create', 'FstrsController@create')->name('fstrs.create');
            Route::post('/{prm_id}/create', 'FstrsController@store')->name('fstrs.store');
            Route::get('/{fstr}/show', 'FstrsController@show')->name('fstrs.show');
            Route::get('/{fstr}/edit', 'FstrsController@edit')->name('fstrs.edit');
            Route::delete('/{fstr}/delete', 'FstrsController@destroy')->name('fstrs.destroy');
        });

        // Reason Adjustments Routes
        Route::group(['prefix' => 'reason_adjustments', 'middleware' => ['auth']], function () {
            Route::get('/', 'ReasonAdjustmentsController@index')->name('reason_adjustments.index');
            Route::get('/create', 'ReasonAdjustmentsController@create')->name('reason_adjustments.create');
            Route::post('/{prm_id}/create', 'ReasonAdjustmentsController@store')->name('reason_adjustments.store');
            Route::get('/{reasonAdjustment}/show', 'ReasonAdjustmentsController@show')->name('reason_adjustments.show');
            Route::get('/{reasonAdjustment}/edit', 'ReasonAdjustmentsController@edit')->name('reason_adjustments.edit');
            Route::delete('/{reasonAdjustment}/delete', 'ReasonAdjustmentsController@destroy')->name('reason_adjustments.destroy');
            Route::post('/seed-defaults', 'ReasonAdjustmentsController@seedDefaultReasons')->name('reason_adjustments.seed_defaults');
        });

        // Sales Types Routes
        Route::group(['prefix' => 'sales_types', 'middleware' => ['auth']], function () {
            Route::get('/', 'SalesTypesController@index')->name('sales_types.index');
            Route::get('/create', 'SalesTypesController@create')->name('sales_types.create');
            Route::post('/{prm_id}/create', 'SalesTypesController@store')->name('sales_types.store');
            Route::get('/{salesType}/show', 'SalesTypesController@show')->name('sales_types.show');
            Route::get('/{salesType}/edit', 'SalesTypesController@edit')->name('sales_types.edit');
            Route::delete('/{salesType}/delete', 'SalesTypesController@destroy')->name('sales_types.destroy');
            Route::post('/seed-defaults', 'SalesTypesController@seedDefaults')->name('sales_types.seed_defaults');
        });

        Route::group(['prefix' => 'stores', 'middleware' => ['auth']], function () {
            Route::get('/', 'StoresController@index')->name('stores.index');
            Route::get('/create', 'StoresController@create')->name('stores.create');
            Route::post('/{prm_id}/create', 'StoresController@store')->name('stores.store');
            Route::get('/{store}/show', 'StoresController@show')->name('stores.show');
            Route::get('/{store}/edit', 'StoresController@edit')->name('stores.edit');
            Route::delete('/{store}/delete', 'StoresController@destroy')->name('stores.destroy');
            Route::post('/upload_excel', 'StoresController@uploadExcel')->name('stores.upload_excel');
            Route::get('/download_template', 'StoresController@downloadTemplate')->name('stores.download_template');
        });

        // Periods Routes
        Route::group(['prefix' => 'periods', 'middleware' => ['auth']], function () {
            Route::get('/', 'PeriodsController@index')->name('periods.index');
            Route::get('/create', 'PeriodsController@create')->name('periods.create');
            Route::post('/{prm_id}/create', 'PeriodsController@store')->name('periods.store');
            Route::get('/{period}/show', 'PeriodsController@show')->name('periods.show');
            Route::get('/{period}/edit', 'PeriodsController@edit')->name('periods.edit');
            Route::delete('/{period}/delete', 'PeriodsController@destroy')->name('periods.destroy');
        });

        // Shipment Suppliers Routes
        Route::group(['prefix' => 'shipment_suppliers', 'middleware' => ['auth']], function () {
            Route::get('/', 'ShipmentSuppliersController@index')->name('shipment_suppliers.index');
            Route::get('/create', 'ShipmentSuppliersController@create')->name('shipment_suppliers.create');
            Route::post('/{prm_id}/create', 'ShipmentSuppliersController@store')->name('shipment_suppliers.store');
            Route::get('/{shipmentSupplier}/show', 'ShipmentSuppliersController@show')->name('shipment_suppliers.show');
            Route::get('/{shipmentSupplier}/edit', 'ShipmentSuppliersController@edit')->name('shipment_suppliers.edit');
            Route::delete('/{shipmentSupplier}/delete', 'ShipmentSuppliersController@destroy')->name('shipment_suppliers.destroy');
            Route::get('/contact_info', 'ShipmentSuppliersController@getContactInfo')->name('shipment_suppliers.contact_info');
            Route::post('/upload_excel', 'ShipmentSuppliersController@uploadExcel')->name('shipment_suppliers.upload_excel');
            Route::get('/download_template', 'ShipmentSuppliersController@downloadTemplate')->name('shipment_suppliers.download_template');
        });

        // Holidays Routes
        Route::group(['prefix' => 'holidays', 'middleware' => ['auth']], function () {
            Route::get('/', 'HolidaysController@index')->name('holidays.index');
            Route::get('/create', 'HolidaysController@create')->name('holidays.create');
            Route::post('/{prm_id}/create', 'HolidaysController@store')->name('holidays.store');
            Route::get('/{holiday}/show', 'HolidaysController@show')->name('holidays.show');
            Route::get('/{holiday}/edit', 'HolidaysController@edit')->name('holidays.edit');
            Route::delete('/{holiday}/delete', 'HolidaysController@destroy')->name('holidays.destroy');
            Route::get('/check', 'HolidaysController@checkHoliday')->name('holidays.check');
            Route::get('/range', 'HolidaysController@getHolidaysInRange')->name('holidays.range');
            Route::post('/generate_recurring', 'HolidaysController@generateRecurringHolidays')->name('holidays.generate_recurring');
            Route::post('/upload_excel', 'HolidaysController@uploadExcel')->name('holidays.upload_excel');
            Route::get('/download_template', 'HolidaysController@downloadTemplate')->name('holidays.download_template');
        });

        // Numbering Formats Routes
        Route::group(['prefix' => 'numbering_formats', 'middleware' => ['auth']], function () {
            Route::get('/', 'NumberingFormatsController@index')->name('numbering_formats.index');
            Route::get('/create', 'NumberingFormatsController@create')->name('numbering_formats.create');
            Route::post('/{prm_id}/create', 'NumberingFormatsController@store')->name('numbering_formats.store');
            Route::get('/{numberingFormat}/show', 'NumberingFormatsController@show')->name('numbering_formats.show');
            Route::get('/{numberingFormat}/edit', 'NumberingFormatsController@edit')->name('numbering_formats.edit');
            Route::delete('/{numberingFormat}/delete', 'NumberingFormatsController@destroy')->name('numbering_formats.destroy');
            Route::get('/preview', 'NumberingFormatsController@previewFormat')->name('numbering_formats.preview');
            Route::get('/generate', 'NumberingFormatsController@generateNumber')->name('numbering_formats.generate');
            Route::post('/{numberingFormat}/reset', 'NumberingFormatsController@resetCounter')->name('numbering_formats.reset');
        });

        Route::group(['prefix' => 'store_raw_materials', 'middleware' => ['auth']], function () {
            Route::get('/', 'StoreRawMaterialsController@index')->name('store_raw_materials.index');
            Route::get('/create', 'StoreRawMaterialsController@create')->name('store_raw_materials.create');
            Route::post('/{prm_id}/create', 'StoreRawMaterialsController@store')->name('store_raw_materials.store');
            Route::get('/{storeRawMaterial}/show', 'StoreRawMaterialsController@show')->name('store_raw_materials.show');
            Route::get('/{storeRawMaterial}/edit', 'StoreRawMaterialsController@edit')->name('store_raw_materials.edit');
            Route::delete('/{storeRawMaterial}/delete', 'StoreRawMaterialsController@destroy')->name('store_raw_materials.destroy');
            Route::post('/get_raw_materials_for_store', 'StoreRawMaterialsController@getRawMaterialsForStore')->name('store_raw_materials.get_raw_materials_for_store');
            Route::post('/bulk_assign', 'StoreRawMaterialsController@bulkAssign')->name('store_raw_materials.bulk_assign');
            Route::post('/upload', 'StoreRawMaterialsController@upload')->name('store_raw_materials.upload');
            Route::get('/download_template', 'StoreRawMaterialsController@downloadTemplate')->name('store_raw_materials.download_template');
        });

        Route::group(['prefix' => 'armada_types', 'middleware' => ['auth']], function () {
            Route::get('/', 'ArmadaTypesController@index')->name('armada_types.index');
            Route::get('/create', 'ArmadaTypesController@create')->name('armada_types.create');
            Route::post('/{prm_id}/create', 'ArmadaTypesController@store')->name('armada_types.store');
            Route::get('/{armadaType}/show', 'ArmadaTypesController@show')->name('armada_types.show');
            Route::get('/{armadaType}/edit', 'ArmadaTypesController@edit')->name('armada_types.edit');
            Route::delete('/{armadaType}/delete', 'ArmadaTypesController@destroy')->name('armada_types.destroy');
        });

        Route::group(['prefix' => 'shipment_deliveries', 'middleware' => ['auth']], function () {
            Route::get('/', 'ShipmentDeliveriesController@index')->name('shipment_deliveries.index');
            Route::get('/create', 'ShipmentDeliveriesController@create')->name('shipment_deliveries.create');
            Route::post('/{prm_id}/create', 'ShipmentDeliveriesController@store')->name('shipment_deliveries.store');
            Route::get('/{ShipmentDelivery}/show', 'ShipmentDeliveriesController@show')->name('shipment_deliveries.show');
            Route::get('/{ShipmentDelivery}/edit', 'ShipmentDeliveriesController@edit')->name('shipment_deliveries.edit');
            Route::delete('/{ShipmentDelivery}/delete', 'ShipmentDeliveriesController@destroy')->name('shipment_deliveries.destroy');
            Route::post('/upload_excel', 'ShipmentDeliveriesController@upload_excel')->name('shipment_deliveries.upload_excel');
            Route::get('/download_template', 'ShipmentDeliveriesController@download_template')->name('shipment_deliveries.download_template');
        });

        Route::group(['prefix' => 'target_sisa_malam', 'middleware' => ['auth']], function () {
            Route::get('/', 'TargetSisaMalamController@index')->name('target_sisa_malam.index');
            Route::get('/create', 'TargetSisaMalamController@create')->name('target_sisa_malam.create');
            Route::post('/{prm_id}/create', 'TargetSisaMalamController@store')->name('target_sisa_malam.store');
            Route::get('/{targetSisaMalam}/show', 'TargetSisaMalamController@show')->name('target_sisa_malam.show');
            Route::get('/{targetSisaMalam}/edit', 'TargetSisaMalamController@edit')->name('target_sisa_malam.edit');
            Route::delete('/{targetSisaMalam}/delete', 'TargetSisaMalamController@destroy')->name('target_sisa_malam.destroy');
            Route::post('/upload_excel', 'TargetSisaMalamController@uploadExcel')->name('target_sisa_malam.upload_excel');
            Route::get('/download_template', 'TargetSisaMalamController@downloadTemplate')->name('target_sisa_malam.download_template');
        });

        // Transaction Routes
        Route::group(['prefix' => 'stock_opnames', 'middleware' => ['auth']], function () {
            Route::get('/', 'StockOpnamesController@index')->name('stock_opnames.index');
            Route::get('/create', 'StockOpnamesController@create')->name('stock_opnames.create');
            Route::post('/{prm_id}/create', 'StockOpnamesController@store')->name('stock_opnames.store');
            Route::get('/{stockOpname}/show', 'StockOpnamesController@show')->name('stock_opnames.show');
            Route::get('/{stockOpname}/edit', 'StockOpnamesController@edit')->name('stock_opnames.edit');
            Route::delete('/{stockOpname}/delete', 'StockOpnamesController@destroy')->name('stock_opnames.destroy');
            Route::post('/get_raw_materials_for_store', 'StockOpnamesController@getRawMaterialsForStore')->name('stock_opnames.get_raw_materials_for_store');
            Route::post('/auto_load_raw_materials', 'StockOpnamesController@autoLoadRawMaterials')->name('stock_opnames.auto_load_raw_materials');
            Route::post('/auto_save_field', 'StockOpnamesController@autoSaveField')->name('stock_opnames.auto_save_field');
            Route::post('/clear_inputs', 'StockOpnamesController@clearInputs')->name('stock_opnames.clear_inputs');
            Route::get('/get_change_history', 'StockOpnamesController@getChangeHistory')->name('stock_opnames.get_change_history');
            Route::post('/save_only', 'StockOpnamesController@saveOnly')->name('stock_opnames.save_only');
            Route::post('/create_spb', 'StockOpnamesController@createSPB')->name('stock_opnames.create_spb');
            Route::post('/{soId}/generate_spb', 'StockOpnamesController@generateSPB')->name('stock_opnames.generate_spb');
            Route::get('/{soId}/preview_spb_grouping', 'StockOpnamesController@previewSPBGrouping')->name('stock_opnames.preview_spb_grouping');
            Route::post('/get_current_stock', 'StockOpnamesController@getCurrentStockForStore')->name('stock_opnames.get_current_stock');
            Route::post('/update_current_stock', 'StockOpnamesController@updateCurrentStockFromSO')->name('stock_opnames.update_current_stock');
            Route::post('/fix_adjustment_fields', 'StockOpnamesController@fixAdjustmentFields')->name('stock_opnames.fix_adjustment_fields');
            Route::get('/raw_materials_info', 'StockOpnamesController@getRawMaterialsInfo')->name('stock_opnames.raw_materials_info');
            Route::post('/unlock', 'StockOpnamesController@unlockSO')->name('stock_opnames.unlock');
            Route::post('/heartbeat', 'StockOpnamesController@heartbeat')->name('stock_opnames.heartbeat');
            Route::post('/force_unlock', 'StockOpnamesController@forceUnlock')->name('stock_opnames.force_unlock');
            Route::get('/check_today_so', 'StockOpnamesController@checkTodaySO')->name('stock_opnames.check_today_so');
        });

        Route::group(['prefix' => 'item_requests', 'middleware' => ['auth']], function () {
            Route::get('/', 'ItemRequestsController@index')->name('item_requests.index');
            Route::get('/create', 'ItemRequestsController@create')->name('item_requests.create');
            Route::post('/{prm_id}/create', 'ItemRequestsController@store')->name('item_requests.store');
            Route::get('/{itemRequest}/show', 'ItemRequestsController@show')->name('item_requests.show');
            Route::get('/{itemRequest}/edit', 'ItemRequestsController@edit')->name('item_requests.edit');
            Route::delete('/{itemRequest}/delete', 'ItemRequestsController@destroy')->name('item_requests.destroy');
            Route::post('/generate_from_so', 'ItemRequestsController@generateFromSO')->name('item_requests.generate_from_so');
            Route::post('/forecast_comparison', 'ItemRequestsController@getForecastComparison')->name('item_requests.forecast_comparison');
            
            // CSV Export routes
            Route::post('/{id}/generate_csv', 'ItemRequestsController@generateCsv')->name('item_requests.generate_csv');
            Route::get('/{id}/download_csv', 'ItemRequestsController@downloadCsv')->name('item_requests.download_csv');
            Route::get('/{id}/list_csv', 'ItemRequestsController@listCsvFiles')->name('item_requests.list_csv');
            Route::delete('/{id}/delete_csv', 'ItemRequestsController@deleteCsvFiles')->name('item_requests.delete_csv');
        });

        Route::group(['prefix' => 'item_request_cancellations', 'middleware' => ['auth']], function () {
            Route::get('/', 'ItemRequestCancellationsController@index')->name('item_request_cancellations.index');
            Route::get('/{itemRequestCancellation}/show', 'ItemRequestCancellationsController@show')->name('item_request_cancellations.show');
            Route::post('/request_cancellation', 'ItemRequestCancellationsController@requestCancellation')->name('item_request_cancellations.request');
            Route::post('/approve_cancellation', 'ItemRequestCancellationsController@approveCancellation')->name('item_request_cancellations.approve');
            Route::post('/reject_cancellation', 'ItemRequestCancellationsController@rejectCancellation')->name('item_request_cancellations.reject');
        });

        Route::group(['prefix' => 'forecasts', 'middleware' => ['auth']], function () {
            Route::get('/', 'ForecastsController@index')->name('forecasts.index');
            Route::get('/create', 'ForecastsController@create')->name('forecasts.create');
            Route::post('/upload_excel', 'ForecastsController@uploadExcel')->name('forecasts.upload_excel');
            Route::get('/{forecast}/show', 'ForecastsController@show')->name('forecasts.show');
            Route::delete('/{forecast}/delete', 'ForecastsController@destroy')->name('forecasts.destroy');
            Route::post('/approve', 'ForecastsController@confirm')->name('forecasts.confirm');
            Route::get('/download_template', 'ForecastsController@downloadTemplate')->name('forecasts.download_template');
            Route::post('/export_horizontal', 'ForecastsController@exportHorizontal')->name('forecasts.export_horizontal');
            Route::post('/{forecast}/replace_data', 'ForecastsController@replaceData')->name('forecasts.replace_data');
        });
  
        Route::group(['prefix' => 'parameter_globals', 'middleware' => ['auth']], function () {
            Route::get('/', 'ParameterGlobalsController@index')->name('parameter_globals.index');
            Route::get('/{parameterGlobal}/edit', 'ParameterGlobalsController@edit')->name('parameter_globals.edit');
            Route::post('/{prm_id}/edit', 'ParameterGlobalsController@store')->name('parameter_globals.store');
        }); 
       
        Route::group(['prefix' => 'reports', 'middleware' => ['auth']], function () {
            //saat print pakenya post, karena kalo pake query url takut kena batasan(seperti kasus di reposrt dinopts)  
            Route::match(['get', 'post'], '/balance_histories', 'ReportsController@balance_histories')->name('reports.balance_histories');
            Route::match(['get', 'post'], '/system_logs', 'ReportsController@system_logs')->name('reports.system_logs');
            Route::match(['get', 'post'], '/system_errors', 'ReportsController@system_errors')->name('reports.system_errors');
            
            // LSM Reports
            Route::match(['get', 'post'], '/lsm_report', 'ReportsController@lsm_report')->name('reports.lsm_report');
            Route::match(['get', 'post'], '/spb_report', 'ReportsController@spb_report')->name('reports.spb_report');
            Route::match(['get', 'post'], '/do_report', 'ReportsController@do_report')->name('reports.do_report');
            Route::match(['get', 'post'], '/doi_report', 'ReportsController@doi_report')->name('reports.doi_report');
        });

        // QAD Synchronization Routes
        Route::group(['prefix' => 'qad_sync', 'middleware' => ['auth']], function () {
            Route::get('/', 'QadSyncController@index')->name('qad_sync.index');
            Route::post('/test_connection', 'QadSyncController@testConnection')->name('qad_sync.test_connection');
            Route::post('/sync_stores', 'QadSyncController@syncStores')->name('qad_sync.sync_stores');
            Route::post('/sync_menus', 'QadSyncController@syncMenus')->name('qad_sync.sync_menus');
            Route::post('/sync_all', 'QadSyncController@syncAll')->name('qad_sync.sync_all');
            Route::get('/sync_history', 'QadSyncController@getSyncHistory')->name('qad_sync.sync_history');
            Route::get('/sync_statistics', 'QadSyncController@getSyncStatistics')->name('qad_sync.sync_statistics');
        });
    });

    //function yg tidak perlu permission
    Route::get('/ajax/check-permissions', 'AjaxController@checkPermissions')->name('ajax.checkPermissions');

    //untuk select store
    Route::post('/change-store', function (Illuminate\Http\Request $request) {
        $storeId = $request->store_id;

        if (!$storeId) {
            session()->forget('store_selected');
            return response()->json(['status' => 'success', 'message' => 'Store session cleared']);
        }

        session(['store_selected' => $storeId]);
        return response()->json(['status' => 'success', 'message' => 'Store changed']);
    })->name('change.store');

    Route::fallback(function () {
        return redirect()->to('login');
    });
});
