╔══════════════════════════════════════════════════════════════╗
║         Permission Auto-Fix Script                          ║
╚══════════════════════════════════════════════════════════════╝

⚠️  Skipping AITestController (test controller - should be removed)
📄 Processing AccountController...
📄 Processing AccountingController...
📄 Processing ActionMenuEditorController...
📄 Processing ActivityController...
⏭️  Skipping AgreementController (intentionally public)
📄 Processing AgreementTemplateController...
📄 Processing AnalyticsController...
📄 Processing AnnouncementController...
📄 Processing ApiController...
  ✓ Fixed allUsers() - added: api.view
  ✓ Fixed usersList() - added: api.view
  💾 Saved changes (2 methods fixed)

📄 Processing ApplicationController...
📄 Processing ApprovalsController...
📄 Processing AssessmentController...
📄 Processing AssumptionsController...
📄 Processing AttendanceController...
📄 Processing AuditLogController...
⏭️  Skipping AuthController (intentionally public)
📄 Processing BOMController...
📄 Processing BackupController...
  ✓ Fixed showDetails() - added: backup.view
  ✓ Fixed getStats() - added: backup.view
  ✓ Fixed getHistory() - added: backup.view
  ✓ Fixed triggerFullBackup() - added: backup.view
  ✓ Fixed triggerGitPush() - added: backup.view
  ✓ Fixed triggerDatabaseBackup() - added: backup.view
  ✓ Fixed index() - added: backup.view
  💾 Saved changes (7 methods fixed)

📄 Processing BankAccountController...
📄 Processing BankImportController...
📄 Processing BankReconciliationController...
📄 Processing BatteryQuoteController...
📄 Processing BudgetController...
📄 Processing BusinessLineController...
📄 Processing CRMController...
📄 Processing CalendarController...
📄 Processing CameraAuditController...
📄 Processing CapacityController...
📄 Processing CategoryController...
📄 Processing ClientController...
📄 Processing CompanyController...
📄 Processing ContactAPIController...
📄 Processing ContactController...
📄 Processing ContractController...
📄 Processing CostingController...
📄 Processing CreditNoteController...
📄 Processing CurrencyController...
📄 Processing CustomReportsController...
  ✓ Fixed index() - added: reports.view
  💾 Saved changes (1 methods fixed)

📄 Processing CustomerController...
📄 Processing CustomerPaymentController...
📄 Processing DashboardController...
📄 Processing DataAccessController...
📄 Processing DebitNoteController...
📄 Processing DeliveryNoteController...
📄 Processing DepreciationController...
📄 Processing DocumentController...
📄 Processing DocumentationController...
  ✓ Fixed refreshCoverage() - added: documentation.view
  ✓ Fixed download() - added: documentation.export
  ✓ Fixed search() - added: documentation.view
  ✓ Fixed index() - added: documentation.view
  💾 Saved changes (4 methods fixed)

📄 Processing DocumentsController...
📄 Processing EmailController...
📄 Processing EmailTemplateController...
📄 Processing EmailWebhookController...
  ✓ Fixed test() - added: email.view
  ✓ Fixed receive() - added: email.view
  💾 Saved changes (2 methods fixed)

📄 Processing EmployeeController...
📄 Processing EquipmentController...
📄 Processing EquipmentLineController...
📄 Processing EquipmentTypeController...
📄 Processing ExpenseController...
📄 Processing FileManagerController...
📄 Processing FinancialPlannerController...
📄 Processing FinancialProFormaController...
📄 Processing FixedAssetController...
📄 Processing ForecasterController...
📄 Processing Form1099Controller...
📄 Processing GoodsReceiptController...
📄 Processing HRController...
📄 Processing HelpDeskController...
📄 Processing InternalNoteAPIController...
📄 Processing InterviewController...
📄 Processing InventoryController...
📄 Processing InvoiceController...
📄 Processing IssueController...
📄 Processing JobPositionController...
📄 Processing JournalEntryController...
📄 Processing LocationController...
📄 Processing LotSerialController...
📄 Processing MFAController...
  ✓ Fixed resendOTP() - added: security.view
  ✓ Fixed verify() - added: security.approve
  ✓ Fixed verifyForm() - added: security.approve
  💾 Saved changes (3 methods fixed)

📄 Processing MRPController...
📄 Processing MachineDataController...
  ✓ Fixed health() - added: machine_data.view
  ✓ Fixed getStatus() - added: machine_data.view
  💾 Saved changes (2 methods fixed)

📄 Processing MaintenanceController...
📄 Processing ManufacturingController...
📄 Processing MenuController...
📄 Processing MessagingController...
📄 Processing NDAController...
  ✓ Fixed declineNDA() - added: nda.view
  ✓ Fixed signNDA() - added: nda.view
  ✓ Fixed publicSign() - added: nda.view
  💾 Saved changes (3 methods fixed)

📄 Processing NDATemplateController...
📄 Processing NetworkMonitorController...
  ✓ Fixed logDetail() - added: network_monitor.view
  ✓ Fixed feed() - added: network_monitor.view
  ✓ Fixed statistics() - added: network_monitor.view
  ✓ Fixed logs() - added: network_monitor.view
  ✓ Fixed status() - added: network_monitor.view
  💾 Saved changes (5 methods fixed)

📄 Processing NextcloudAdminController...
📄 Processing NextcloudController...
  ✓ Fixed viewDocument() - added: nextcloud.view
  💾 Saved changes (1 methods fixed)

📄 Processing NextcloudProxyController...
📄 Processing NextcloudSSOController...
  ✓ Fixed validateToken() - added: nextcloud_sso.view
  💾 Saved changes (1 methods fixed)

📄 Processing NotificationController...
  ✓ Fixed delete() - added: notifications.delete
  ✓ Fixed markAllAsRead() - added: notifications.view
  ✓ Fixed markAsRead() - added: notifications.view
  ✓ Fixed getUnread() - added: notifications.view
  💾 Saved changes (4 methods fixed)

📄 Processing OfferController...
📄 Processing OpportunityController...
📄 Processing PaymentController...
📄 Processing PayrollController...
📄 Processing PeriodClosingController...
📄 Processing PermissionGroupController...
📄 Processing PipedriveImportController...
  ✓ Fixed getStats() - added: pipedrive_import.view
  ✓ Fixed viewLog() - added: pipedrive_import.view
  ✓ Fixed index() - added: pipedrive_import.view
  💾 Saved changes (3 methods fixed)

📄 Processing PositionController...
📄 Processing PricingRuleController...
  ✓ Fixed calculatePrice() - added: pricing_rule.view
  💾 Saved changes (1 methods fixed)

📄 Processing ProFormaController...
  ✓ Fixed calculate() - added: pro_forma.view
  💾 Saved changes (1 methods fixed)

📄 Processing ProductController...
📄 Processing ProductForecastController...
  ✓ Fixed gettingStarted() - added: product_forecast.view
  💾 Saved changes (1 methods fixed)

📄 Processing ProfileController...
📄 Processing ProjectsController...
  ✓ Fixed addTaskComment() - added: projects.create
  ✓ Fixed getTaskComments() - added: projects.view
  ✓ Fixed autoAllocateResources() - added: projects.view
  ✓ Fixed resourceDayDetails() - added: projects.view
  ✓ Fixed resources() - added: projects.view
  ✓ Fixed addTaskDependency() - added: projects.create
  ✓ Fixed calculateCriticalPath() - added: projects.view
  ✓ Fixed gantt() - added: projects.view
  ✓ Fixed processMigration() - added: projects.view
  ✓ Fixed migrateTransactions() - added: projects.view
  ✓ Fixed linkTransactionToTask() - added: projects.view
  ✓ Fixed editTransaction() - added: projects.edit
  ✓ Fixed storeTransaction() - added: projects.create
  ✓ Fixed createTransaction() - added: projects.create
  ✓ Fixed financials() - added: projects.view
  ✓ Fixed unassignGroupFromTask() - added: projects.view
  ✓ Fixed assignGroupToTask() - added: projects.view
  ✓ Fixed addTeamGroup() - added: projects.create
  ✓ Fixed addTeamMember() - added: projects.create
  ✓ Fixed toggleChecklistItem() - added: projects.view
  ✓ Fixed addChecklistItem() - added: projects.view
  ✓ Fixed unassignUser() - added: projects.view
  ✓ Fixed assignUser() - added: projects.view
  ✓ Fixed addComment() - added: projects.create
  ✓ Fixed getTask() - added: projects.view
  ✓ Fixed moveTask() - added: projects.view
  ✓ Fixed listView() - added: projects.view
  ✓ Fixed show() - added: projects.view
  ✓ Fixed index() - added: projects.view
  ✓ Fixed myTasks() - added: projects.view
  ✓ Fixed dashboard() - added: projects.view
  💾 Saved changes (31 methods fixed)

📄 Processing PromotionController...
  ✓ Fixed applyPromotion() - added: promotion.view
  ✓ Fixed validateCode() - added: promotion.view
  💾 Saved changes (2 methods fixed)

📄 Processing PurchaseBillController...
📄 Processing PurchaseOrderController...
📄 Processing PurchasePaymentController...
📄 Processing PurchaseRequisitionController...
📄 Processing PurchaseReturnController...
📄 Processing PurchasesController...
📄 Processing QualityController...
📄 Processing QuickBooksController...
📄 Processing QuoteController...
  ✓ Fixed declineQuote() - added: quote.view
  ✓ Fixed acceptQuote() - added: quote.view
  💾 Saved changes (2 methods fixed)

📄 Processing QuoteTemplateController...
📄 Processing RFQController...
📄 Processing RecruitmentController...
📄 Processing RecurringTransactionController...
📄 Processing ReportsController...
📄 Processing ReturnController...
  ✓ Fixed complete() - added: return.view
  💾 Saved changes (1 methods fixed)

📄 Processing ReviewController...
📄 Processing RoleController...
📄 Processing SalesController...
📄 Processing SalesOrderController...
📄 Processing SalesReportController...
  ✓ Fixed getQuoteConversion() - added: sales.view
  ✓ Fixed getSalesGrowth() - added: sales.view
  ✓ Fixed getCategoryPerformance() - added: sales.view
  ✓ Fixed getPaymentAnalytics() - added: sales.view
  ✓ Fixed getInvoiceAnalytics() - added: sales.view
  ✓ Fixed getByChannel() - added: sales.view
  ✓ Fixed getByStatus() - added: sales.view
  ✓ Fixed getTopCustomers() - added: sales.view
  ✓ Fixed getTopProducts() - added: sales.view
  ✓ Fixed getSummary() - added: sales.view
  💾 Saved changes (10 methods fixed)

📄 Processing SchedulingController...
📄 Processing SearchController...
📄 Processing SeparationController...
📄 Processing SettingsController...
📄 Processing ShipmentController...
📄 Processing ShopFloorController...
📄 Processing StockMovementController...
📄 Processing SupplierController...
📄 Processing SupportController...
📄 Processing SystemScriptsController...
📄 Processing TaxFilingController...
📄 Processing TaxJurisdictionController...
📄 Processing TaxPaymentController...
📄 Processing TermsConditionsController...
⚠️  Skipping TestController (test controller - should be removed)
📄 Processing TrainingController...
📄 Processing TransferController...
📄 Processing UserController...
📄 Processing UserGroupController...
📄 Processing VendorPaymentController...
📄 Processing WarehouseController...
📄 Processing WorkOrderController...
═══════════════════════════════════════════════════════════════
SUMMARY
═══════════════════════════════════════════════════════════════
Files modified: 21
Methods fixed: 87

Permissions used: 26

📋 Next Steps:
1. Review the changes in your controllers
2. Add missing permissions to database:
   php scripts/generate_missing_permissions_sql.php > missing.sql
   mysql -u rpmbbu brickwal_m1_ds < missing.sql
3. Assign permissions to roles: http://localhost:8080/roles/111/edit
4. Test the application thoroughly
5. Run audit again: php scripts/audit_permissions.php | head -30

✅ Complete!