




================================================================================
PERMISSION SCANNER & SYNC UTILITY
MODE: DRY RUN (no changes will be made)
================================================================================

📚 LOADING DATABASE PERMISSIONS
--------------------------------------------------------------------------------
  Loaded 385 permissions from database

🔍 SCANNING CONTROLLERS
--------------------------------------------------------------------------------
  Scanned 147 controller files
  Found 132 files with permission checks
  Discovered 148 unique permissions

📋 DISCOVERED PERMISSIONS REPORT
--------------------------------------------------------------------------------
  Permission                               Checks   Controllers
--------------------------------------------------------------------------------

  (CORE):
  admin                                    101      ActionMenuEditorController,... ✓

  1099_CONTRACTORS:
  1099_contractors.export                  1        Form1099Controller ✓
  1099_contractors.generate_reports        1        Form1099Controller ✓
  1099_contractors.view                    1        Form1099Controller ✓
  1099_contractors.view_payments           1        Form1099Controller ✓

  ACCOUNTING:
  accounting.approve                       3        ExpenseController ✓
  accounting.create                        30       AccountController, BankAcco... ✓
  accounting.customer_payments.create      2        CustomerPaymentController ✓
  accounting.customer_payments.view        2        CustomerPaymentController ✓
  accounting.delete                        21       BankAccountController, Budg... ✓
  accounting.edit                          25       BankAccountController, Bank... ✓
  accounting.vendor_payments.create        4        VendorPaymentController ✓
  accounting.vendor_payments.delete        1        VendorPaymentController ✓
  accounting.vendor_payments.edit          2        VendorPaymentController ✓
  accounting.vendor_payments.print_checks  1        VendorPaymentController ✓
  accounting.vendor_payments.view          3        VendorPaymentController ✓
  accounting.vendor_payments.void          1        VendorPaymentController ✓
  accounting.view                          36       AccountController, Accounti... ✓

  ADMIN:
  admin.agreement_templates                9        AgreementTemplateController ✓
  admin.create                             7        PipedriveImportController, ... ✗
  admin.delete                             2        QuickBooksController, UserG... ✗
  admin.edit                               5        QuickBooksController, UserG... ✗
  admin.settings                           1        PipedriveImportController ✓
  admin.system_scripts                     3        SystemScriptsController ✓

  AUDIT_LOGS:
  audit_logs.view                          1        AuditLogController ✓

  BANK_IMPORT:
  bank_import.create                       2        BankImportController ✓
  bank_import.delete                       1        BankImportController ✓
  bank_import.edit                         2        BankImportController ✓
  bank_import.import                       1        BankImportController ✓
  bank_import.manage_rules                 4        BankImportController ✓
  bank_import.view                         2        BankImportController ✓

  CALENDAR:
  calendar.create                          1        CalendarController ✗
  calendar.delete                          1        CalendarController ✗
  calendar.edit                            1        CalendarController ✗

  CAMERA_AUDIT:
  camera_audit.capture                     1        CameraAuditController ✓
  camera_audit.delete                      1        CameraAuditController ✓
  camera_audit.stations                    3        CameraAuditController ✓
  camera_audit.verify                      1        CameraAuditController ✓
  camera_audit.view                        3        CameraAuditController ✓

  CRM:
  crm.create                               11       ActivityController, ClientC... ✓
  crm.delete                               13       ActivityController, ClientC... ✓
  crm.edit                                 13       ActivityController, ClientC... ✓
  crm.view                                 55       ActivityController, CRMCont... ✓

  DASHBOARD:
  dashboard.edit                           2        DashboardController ✗

  DOCUMENTS:
  documents.create                         1        DocumentsController ✗
  documents.delete                         1        DocumentsController ✓

  FORECASTING:
  forecasting.create                       10       FinancialPlannerController,... ✓
  forecasting.delete                       8        ForecasterController ✓
  forecasting.edit                         16       FinancialPlannerController,... ✓
  forecasting.generate_projections         1        ProductForecastController ✓
  forecasting.manage_assumptions           5        AssumptionsController ✓
  forecasting.manage_products              3        ProductForecastController ✓
  forecasting.update_daily                 3        AssumptionsController ✓
  forecasting.view                         9        FinancialPlannerController,... ✓
  forecasting.view_actuals                 1        AssumptionsController ✓
  forecasting.view_proforma                7        FinancialProFormaController... ✓

  HR:
  hr.create                                28       ApplicationController, Asse... ✓
  hr.delete                                16       ApplicationController, Asse... ✓
  hr.edit                                  25       ApplicationController, Asse... ✓
  hr.view                                  30       ApplicationController, Asse... ✓

  INVENTORY:
  inventory.create                         9        CategoryController, Locatio... ✓
  inventory.delete                         10       CategoryController, Locatio... ✓
  inventory.edit                           7        CategoryController, Locatio... ✓
  inventory.manage                         12       CategoryController, StockMo... ✓
  inventory.view                           20       CategoryController, Invento... ✓

  MANUFACTURING:
  manufacturing.approve                    2        MRPController ✓
  manufacturing.create                     13       BOMController, BusinessLine... ✓
  manufacturing.delete                     6        BusinessLineController, Equ... ✓
  manufacturing.edit                       44       BOMController, BusinessLine... ✓
  manufacturing.view                       53       AnalyticsController, BOMCon... ✓

  MESSAGING:
  messaging.create                         1        MessagingController ✗
  messaging.delete                         1        MessagingController ✗
  messaging.edit                           2        MessagingController ✗

  NDAS:
  ndas.countersign                         2        NDAController ✓
  ndas.create                              2        NDAController ✓
  ndas.delete                              1        NDAController ✓
  ndas.edit                                2        NDAController ✓
  ndas.send                                2        NDAController ✓
  ndas.view                                5        NDAController ✓

  NETWORK_MONITOR:
  network_monitor.manage                   3        NetworkMonitorController ✓
  network_monitor.view                     1        NetworkMonitorController ✓

  NEXTCLOUD:
  nextcloud.delete                         1        NextcloudController ✓
  nextcloud.manage                         7        NextcloudAdminController, N... ✓
  nextcloud.upload                         6        NextcloudController ✓
  nextcloud.view                           7        NextcloudController ✓

  PAYROLL:
  payroll.view                             1        PayrollController ✓

  PERMISSIONS:
  permissions.manage                       10       PermissionGroupController ✓

  PROCUREMENT:
  procurement.approve                      2        PurchaseRequisitionController ✓
  procurement.create                       16       DebitNoteController, GoodsR... ✓
  procurement.delete                       12       DebitNoteController, GoodsR... ✓
  procurement.edit                         12       DebitNoteController, Purcha... ✓
  procurement.view                         18       DebitNoteController, GoodsR... ✓

  PRODUCT_FORECAST:
  product_forecast.view                    2        ProductForecastController ✓

  PROFILE:
  profile.edit                             2        ProfileController ✗

  PROJECTS:
  projects.create                          3        ProjectsController ✓
  projects.delete                          5        ProjectsController ✓
  projects.edit                            9        ProjectsController ✓
  projects.view                            5        ProjectsController ✓

  PURCHASES:
  purchases.create                         3        SupplierController ✓
  purchases.delete                         3        SupplierController ✓
  purchases.edit                           2        SupplierController ✓
  purchases.view                           3        PurchasesController, Suppli... ✓

  PURCHASING:
  purchasing.create                        1        MRPController ✓

  RECURRING_TEMPLATES:
  recurring_templates.activate             1        RecurringTransactionController ✓
  recurring_templates.create               2        RecurringTransactionController ✓
  recurring_templates.delete               1        RecurringTransactionController ✓
  recurring_templates.edit                 2        RecurringTransactionController ✓
  recurring_templates.execute              2        RecurringTransactionController ✓
  recurring_templates.view                 3        RecurringTransactionController ✓

  REPORTS:
  reports.create                           2        CustomReportsController ✗
  reports.delete                           1        CustomReportsController ✗
  reports.edit                             2        CustomReportsController ✗
  reports.view                             7        ReportsController ✓

  ROLES:
  roles.create                             2        RoleController ✓
  roles.delete                             1        RoleController ✓
  roles.edit                               2        RoleController ✓
  roles.view                               4        RoleController ✓

  SALES:
  sales.agreements.create                  3        AgreementController ✓
  sales.agreements.delete                  3        AgreementController ✓
  sales.agreements.edit                    3        AgreementController ✓
  sales.agreements.send                    2        AgreementController ✓
  sales.agreements.view                    5        AgreementController ✓
  sales.approve                            2        ReturnController ✗
  sales.create                             28       BatteryQuoteController, Cre... ✓
  sales.delete                             23       BatteryQuoteController, Cre... ✓
  sales.edit                               20       BatteryQuoteController, Inv... ✓
  sales.view                               34       BatteryQuoteController, Cre... ✓

  SETTINGS:
  settings.edit                            23       MenuController, TermsCondit... ✓
  settings.view                            4        MenuController, TermsCondit... ✓

  SYSTEM:
  system.backup                            1        BackupController ✓
  system.edit                              1        ProfileController ✗
  system.files.delete                      3        FileManagerController ✗

  TAX_JURISDICTIONS:
  tax_jurisdictions.create                 2        TaxJurisdictionController ✓
  tax_jurisdictions.delete                 1        TaxJurisdictionController ✓
  tax_jurisdictions.edit                   3        TaxJurisdictionController ✓
  tax_jurisdictions.view                   2        TaxJurisdictionController ✓

  TAX_PAYMENTS:
  tax_payments.create                      2        TaxPaymentController ✓
  tax_payments.edit                        4        TaxPaymentController ✓
  tax_payments.file                        1        TaxPaymentController ✓
  tax_payments.view                        2        TaxPaymentController ✓

  TAX_REPORTS:
  tax_reports.view                         1        TaxPaymentController ✓

  TICKETS:
  tickets.create                           4        HelpDeskController, Support... ✓
  tickets.delete                           2        SupportController ✗
  tickets.edit                             2        HelpDeskController, Support... ✓

  USERS:
  users.create                             2        UserController ✓
  users.delete                             3        UserController ✓
  users.edit                               2        UserController ✓
  users.view                               3        UserController ✓

➕ CREATING MISSING PERMISSIONS
--------------------------------------------------------------------------------
  Found 19 missing permissions:

  + calendar.create (calendar) - "Create Calendar"
    Used in: CalendarController

  + calendar.edit (calendar) - "Edit Calendar"
    Used in: CalendarController

  + calendar.delete (calendar) - "Delete Calendar"
    Used in: CalendarController

  + reports.create (reports) - "Create Reports"
    Used in: CustomReportsController

  + reports.edit (reports) - "Edit Reports"
    Used in: CustomReportsController

  + reports.delete (reports) - "Delete Reports"
    Used in: CustomReportsController

  + dashboard.edit (dashboard) - "Edit Dashboard"
    Used in: DashboardController

  + documents.create (documents) - "Create Documents"
    Used in: DocumentsController

  + system.files.delete (system) - "System Files Delete"
    Used in: FileManagerController

  + messaging.create (messaging) - "Create Messaging"
    Used in: MessagingController

  + messaging.edit (messaging) - "Edit Messaging"
    Used in: MessagingController

  + messaging.delete (messaging) - "Delete Messaging"
    Used in: MessagingController

  + admin.create (admin) - "Create Admin"
    Used in: PipedriveImportController, UserGroupController

  + profile.edit (profile) - "Edit Profile"
    Used in: ProfileController

  + system.edit (system) - "Edit System"
    Used in: ProfileController

  + admin.edit (admin) - "Edit Admin"
    Used in: QuickBooksController, UserGroupController

  + admin.delete (admin) - "Delete Admin"
    Used in: QuickBooksController, UserGroupController

  + sales.approve (sales) - "Approve Sales"
    Used in: ReturnController

  + tickets.delete (tickets) - "Delete Tickets"
    Used in: SupportController

🗑️  UNUSED PERMISSIONS
--------------------------------------------------------------------------------
  Found 256 permissions in database not used in controllers:

  (CORE):
    - agreements.view - "View Agreements"
    - ai-test.view - "View AI Testing"
    - analytics.view - "View analytics"
    - announcements.view - "View Announcements"
    - assumptions.view - "View Daily Update"
    - audit-logs.view - "View Audit Log"
    - backup.view - "View System Backup"
    - calendar.view - "View calendar"
    - companies.view - "View Companies"
    - creditnotes.view - "View Credit Notes"
    ... and 16 more

  1099:
    - 1099_contractors.manage - "Manage 1099 contractor designations"
    - 1099_filings.file - "File 1099 forms"
    - 1099_filings.prepare - "Prepare 1099 forms"
    - 1099_payments.manage - "Manage 1099 payment classifications"
    - 1099_payments.view - "View 1099 reportable payments"
    - 1099_reports.view - "View 1099 reports"

  ACCOUNTING:
    - accounting.customer_payments.delete - "Delete customer payments"
    - accounting.customer_payments.edit - "Edit customer payments"
    - accounting.post - "Post journal entries"
    - accounts.create - "Create accounts"
    - accounts.delete - "Delete accounts"
    - accounts.edit - "Edit accounts"
    - accounts.view - "View chart of accounts"
    - bank_accounts.create - "Create bank accounts"
    - bank_accounts.edit - "Edit bank accounts"
    - bank_accounts.view - "View bank accounts"
    ... and 21 more

  AUDIT:
    - audit_trail.export - "Export audit trail"
    - audit_trail.view - "View audit trail"

  AUTOMATION:
    - automation.view - "View Templates"

  BANK_IMPORT:
    - bank_import.categorize - "Categorize imported transactions"
    - bank_import.rules - "Manage categorization rules"

  CREDIT_NOTES:
    - credit_notes.apply - "Apply Credit Notes to Invoices"
    - credit_notes.auto_apply - "Auto-apply Credit Notes"
    - credit_notes.reverse - "Reverse Credit Note Applications"
    - credit_notes.view_balances - "View Customer Credit Balances"

  CRM:
    - activities.create - "Create CRM activities"
    - activities.edit - "Edit CRM activities"
    - activities.view - "View CRM activities"
    - clients.create - "Create clients"
    - clients.delete - "Delete clients"
    - clients.edit - "Edit clients"
    - clients.view - "View clients"
    - contacts.create - "Create contacts"
    - contacts.delete - "Delete contacts"
    - contacts.edit - "Edit contacts"
    ... and 14 more

  DOCUMENTS:
    - documents.edit - "Edit documents"
    - documents.upload - "Upload documents"

  HELPDESK:
    - tickets.assign - "Assign support tickets"
    - tickets.close - "Close support tickets"
    - tickets.view - "View support tickets"

  HR:
    - applications.create - "Create job applications"
    - applications.edit - "Edit job applications"
    - applications.view - "View job applications"
    - assessments.create - "Create assessments"
    - assessments.view - "View assessments"
    - attendance.create - "Record attendance"
    - attendance.view - "View attendance"
    - contracts.create - "Create employee contracts"
    - contracts.edit - "Edit employee contracts"
    - contracts.view - "View employee contracts"
    ... and 31 more

  INVENTORY:
    - camera_audit.annotate - "Add annotations to audit images"
    - camera_audit.export - "Export camera audit data"
    - categories.create - "Create product categories"
    - categories.delete - "Delete product categories"
    - categories.edit - "Edit product categories"
    - categories.view - "View product categories"
    - inventory.adjust - "Adjust inventory levels"
    - lots.create - "Create lot/serial numbers"
    - lots.edit - "Edit lot/serial numbers"
    - lots.view - "View lot/serial numbers"
    ... and 11 more

  MANUFACTURING:
    - boms.create - "Create bills of materials"
    - boms.delete - "Delete bills of materials"
    - boms.edit - "Edit bills of materials"
    - boms.view - "View bills of materials"
    - capacity.edit - "Edit capacity planning"
    - capacity.view - "View capacity planning"
    - equipment.create - "Create equipment"
    - equipment.edit - "Edit equipment"
    - equipment.maintenance - "Perform equipment maintenance"
    - equipment.view - "View equipment"
    ... and 11 more

  MARKETING:
    - campaigns.create - "Create email campaigns"
    - campaigns.edit - "Edit email campaigns"
    - campaigns.send - "Send email campaigns"
    - campaigns.view - "View email campaigns"
    - lists.create - "Create mailing lists"
    - lists.view - "View mailing lists"
    - templates.create - "Create email templates"
    - templates.view - "View email templates"

  PURCHASES:
    - bills.approve - "Approve supplier bills"
    - bills.create - "Create supplier bills"
    - bills.view - "View supplier bills"
    - goods_receipts.create - "Create goods receipts"
    - goods_receipts.view - "View goods receipts"
    - purchase_orders.approve - "Approve purchase orders"
    - purchase_orders.create - "Create purchase orders"
    - purchase_orders.delete - "Delete purchase orders"
    - purchase_orders.edit - "Edit purchase orders"
    - purchase_orders.view - "View purchase orders"
    ... and 9 more

  REPORTS:
    - reports.export - "Export reports"

  SALES:
    - delivery_notes.create - "Create delivery notes"
    - delivery_notes.view - "View delivery notes"
    - invoices.create - "Create invoices"
    - invoices.delete - "Delete invoices"
    - invoices.edit - "Edit invoices"
    - invoices.view - "View invoices"
    - orders.approve - "Approve sales orders"
    - orders.create - "Create sales orders"
    - orders.delete - "Delete sales orders"
    - orders.edit - "Edit sales orders"
    ... and 22 more

  SECURITY:
    - mfa.admin_override - "Admin: Override MFA for any user"
    - mfa.manage_own - "Manage own MFA settings"
    - security.view_audit - "View security audit logs"

  STATEMENTS:
    - statements.bulk_generate - "Generate Bulk Statements"
    - statements.email - "Email Statements to Customers"
    - statements.generate - "Generate Customer Statements"
    - statements.view_history - "View Statement History"

  SYSTEM:
    - files.delete - "Delete files and folders"
    - files.manage - "Manage all files and folders"
    - files.upload - "Upload files"

  TAX:
    - tax_exemptions.manage - "Manage tax exemptions"
    - tax_exemptions.view - "View tax exemptions"

  ⚠️  NOTE: These may be used in views or future features.
  Review carefully before deleting.

📊 COVERAGE STATISTICS
--------------------------------------------------------------------------------
  Permissions in database:        385
  Permissions in controllers:     148
  Matching (in both):             129
  Missing from database:          19
  Unused in controllers:          256
  Coverage:                       87.2%

  PERMISSIONS BY MODULE:
    accounting                      13 permissions
    sales                           10 permissions
    forecasting                     10 permissions
    admin                            6 permissions
    bank_import                      6 permissions
    ndas                             6 permissions
    recurring_templates              6 permissions
    manufacturing                    5 permissions
    camera_audit                     5 permissions
    inventory                        5 permissions


================================================================================
SCAN COMPLETE
================================================================================

This was a dry run. Run with --live flag to apply changes.
