-- Actualizar la tabla maincompany con la configuración de módulos (estructura unificada)
-- Se ha añadido el atributo "model" a cada elemento, generado según la regla:
-- preg_replace('/[^a-zA-Z0-9_]/', '_', strtolower(str_replace(' ', '_', $module['name'])))
-- 29/04/2026

UPDATE maincompany 
SET manage_modules = '{
  "sidebar_modules": [
    { "name": "Home", "path": "/", "enabled": true, "description": "Document_Description", "model": "sidebar_home" },
    { "name": "Alerts", "path": "alerts", "enabled": true, "description": "Document_Description", "model": "sidebar_alerts" },
    {
      "name": "AWB",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_awb",
      "sub_modules": [
        { "name": "AWB", "path": "awb", "enabled": true, "description": "Document_Description", "model": "sidebar_awb" },
        { "name": "HAWB", "path": "hawb", "enabled": true, "description": "Document_Description", "model": "sidebar_hawb" }
      ]
    },
    {
      "name": "Prepack",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_prepack",
      "sub_modules": [
        { "name": "All", "path": "prepack", "enabled": true, "description": "Document_Description", "model": "sidebar_all" },
        { "name": "Unprocessed", "path": "prepack-received", "enabled": true, "description": "Document_Description", "model": "sidebar_unprocessed" }
      ]
    },
    {
      "name": "Packages",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_packages",
      "sub_modules": [
        { "name": "Quick package", "path": "/quick-create", "enabled": true, "description": "Document_Description", "model": "sidebar_quick_package" },
        { "name": "All", "path": "packages", "enabled": true, "description": "Document_Description", "model": "sidebar_all" },
        { "name": "Unprocessed", "path": "packages-unprocessed", "enabled": true, "description": "Document_Description", "model": "sidebar_unprocessed" }
      ]
    },
    {
      "name": "Warehouses",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_warehouses",
      "sub_modules": [
        { "name": "All", "path": "warehouses", "enabled": true, "description": "Document_Description", "model": "sidebar_all" },
        { "name": "Unprocessed", "path": "warehouses-unprocessed", "enabled": true, "description": "Document_Description", "model": "sidebar_unprocessed" }
      ]
    },
    {
      "name": "Shipments",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_shipments",
      "sub_modules": [
        { "name": "All", "path": "shipments", "enabled": true, "description": "Document_Description", "model": "sidebar_all" },
        { "name": "Unprocessed", "path": "shipments-unprocessed", "enabled": true, "description": "Document_Description", "model": "sidebar_unprocessed" }
      ]
    },
    { "name": "Repacking Requests", "path": "repacking", "enabled": true, "description": "Document_Description", "model": "sidebar_repacking_requests" },
    { "name": "Shipping Requests", "path": "shipping-requests", "enabled": true, "description": "Document_Description", "model": "sidebar_shipping_requests" },
    { "name": "Load Units", "path": "loadunits", "enabled": true, "description": "Document_Description", "model": "sidebar_load_units" },
    { "name": "Consolidated", "path": "consolidated", "enabled": true, "description": "Document_Description", "model": "sidebar_consolidated" },
    { "name": "Customers", "path": "customers", "enabled": true, "description": "Document_Description", "model": "sidebar_customers" },
    { "name": "PoBOX", "path": "pobox", "enabled": true, "description": "Document_Description", "model": "sidebar_pobox" },
    { "name": "Invoices", "path": "invoices", "enabled": true, "description": "Document_Description", "model": "sidebar_invoices" },
    { "name": "Payments", "path": "payments", "enabled": true, "description": "Document_Description", "model": "sidebar_payments" },
    {
      "name": "Accounting",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_accounting",
      "sub_modules": [
        { "name": "Suppliers", "path": "suppliers", "enabled": true, "description": "Document_Description", "model": "sidebar_suppliers" },
        { "name": "Expenses", "path": "expenses", "enabled": true, "description": "Document_Description", "model": "sidebar_expenses" },
        { "name": "Expense Payments", "path": "expense-payments", "enabled": true, "description": "Document_Description", "model": "sidebar_expense_payments" },
        { "name": "Expense Categories", "path": "expense-categories", "enabled": true, "description": "Document_Description", "model": "sidebar_expense_categories" }
      ]
    },
    {
      "name": "Pickups",
      "enabled": true,
      "description": "Document_Description",
      "model": "sidebar_pickups",
      "sub_modules": [
        { "name": "List", "path": "pickups", "enabled": true, "description": "Document_Description", "model": "sidebar_list" },
        { "name": "Routes", "path": "routes-pickups", "enabled": true, "description": "Document_Description", "model": "sidebar_routes" }
      ]
    },
    { "name": "Delivery List", "path": "delivery-list", "enabled": true, "description": "Document_Description", "model": "sidebar_delivery_list" },
    { "name": "Quotes", "path": "quotes", "enabled": true, "description": "Document_Description", "model": "sidebar_quotes" }
  ],
  "top_menu_modules": [
    { "name": "Home", "path": "/", "enabled": true, "description": "Document_Description", "model": "topmenu_home" },
    {
      "name": "Administration",
      "enabled": true,
      "description": "Document_Description",
      "model": "topmenu_administration",
      "sub_modules": [
        {
          "name": "Places",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_places",
          "sub_modules": [
            { "name": "Cities", "path": "cities", "enabled": true, "description": "Document_Description", "model": "topmenu_cities" },
            { "name": "States", "path": "states", "enabled": true, "description": "Document_Description", "model": "topmenu_states" },
            { "name": "Countries", "path": "countries", "enabled": true, "description": "Document_Description", "model": "topmenu_countries" },
            { "name": "Regions", "path": "regions", "enabled": true, "description": "Document_Description", "model": "topmenu_regions" },
            { "name": "Sea Ports", "path": "sea-ports", "enabled": true, "description": "Document_Description", "model": "topmenu_sea_ports" }
          ]
        },
        {
          "name": "Transporters",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_transporters",
          "sub_modules": [
            { "name": "Carriers", "path": "carriers", "enabled": true, "description": "Document_Description", "model": "topmenu_carriers" },
            { "name": "Vehicles", "path": "vehicles", "enabled": true, "description": "Document_Description", "model": "topmenu_vehicles" },
            { "name": "Transporters", "path": "transporters", "enabled": true, "description": "Document_Description", "model": "topmenu_transporters" },
            { "name": "Local Transporters", "path": "local-transporters", "enabled": true, "description": "Document_Description", "model": "topmenu_local_transporters" }
          ]
        },
        {
          "name": "Tariffs",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_tariffs",
          "sub_modules": [
            { "name": "Warehouse rate", "path": "warehouse-tariff", "enabled": true, "description": "Document_Description", "model": "topmenu_warehouse_rate" },
            { "name": "Shipment rate", "path": "shipment-tariff", "enabled": true, "description": "Document_Description", "model": "topmenu_shipment_rate" }
          ]
        },
        {
          "name": "Settings",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_settings",
          "sub_modules": [
            { "name": "Agencies", "path": "agencies", "enabled": true, "description": "Document_Description", "model": "topmenu_agencies" },
            { "name": "Account", "path": "accounts", "enabled": true, "description": "Document_Description", "model": "topmenu_account" },
            { "name": "Agents", "path": "agents", "enabled": true, "description": "Document_Description", "model": "topmenu_agents" },
            { "name": "Consolidated Type", "path": "consolidated-type", "enabled": true, "description": "Document_Description", "model": "topmenu_consolidated_type" },
            { "name": "Template Packs", "path": "template-packs", "enabled": true, "description": "Document_Description", "model": "topmenu_template_packs" },
            { "name": "Pack Types", "path": "pack-types", "enabled": true, "description": "Document_Description", "model": "topmenu_pack_types" },
            { "name": "Paid Types", "path": "paid-types", "enabled": true, "description": "Document_Description", "model": "topmenu_paid_types" },
            { "name": "Users", "path": "users", "enabled": true, "description": "Document_Description", "model": "topmenu_users" },
            { "name": "Terms & Conditions", "path": "terms-and-conditions", "enabled": true, "description": "Document_Description", "model": "topmenu_terms_conditions" },
            { "name": "Body Email", "path": "body-email", "enabled": true, "description": "Document_Description", "model": "topmenu_body_email" },
            { "name": "Company", "path": "company", "enabled": true, "description": "Document_Description", "model": "topmenu_company" },
            { "name": "Correlative", "path": "correlative", "enabled": true, "description": "Document_Description", "model": "topmenu_correlative" },
            { "name": "Deployment configuration", "path": "config-deployment", "enabled": true, "description": "Document_Description", "model": "topmenu_deployment_configuration" },
            { "name": "Label configuration", "path": "config-label", "enabled": true, "description": "Document_Description", "model": "topmenu_label_configuration" },
            { "name": "Email setup", "path": "email-setup", "enabled": true, "description": "Document_Description", "model": "topmenu_email_setup" },
            { "name": "Public Links", "path": "public-links", "enabled": true, "description": "Document_Description", "model": "topmenu_public_links" },
            { "name": "Services", "path": "service", "enabled": true, "description": "Document_Description", "model": "topmenu_services" },
            { "name": "Status", "path": "step-status", "enabled": true, "description": "Document_Description", "model": "topmenu_status" }
          ]
        },
        {
          "name": "Warehouse Management",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_warehouse_management",
          "sub_modules": [
            { "name": "Zones", "path": "zones", "enabled": true, "description": "Document_Description", "model": "topmenu_zones" },
            { "name": "Locations", "path": "locations", "enabled": true, "description": "Document_Description", "model": "topmenu_locations" },
            { "name": "Branches", "path": "branches", "enabled": true, "description": "Document_Description", "model": "topmenu_branches" }
          ]
        },
        {
          "name": "AWB Stock Inventory",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_awb_stock_inventory",
          "sub_modules": [
            { "name": "Stock Items", "path": "awb-stock-items", "enabled": true, "description": "Document_Description", "model": "topmenu_stock_items" },
            { "name": "Batches", "path": "batches", "enabled": true, "description": "Document_Description", "model": "topmenu_batches" }
          ]
        },
        {
          "name": "Third-Party Apps",
          "enabled": true,
          "description": "Document_Description",
          "model": "topmenu_third_party_apps",
          "sub_modules": [
            { "name": "QuickBooks", "path": "quickbooks-setup", "enabled": true, "description": "Document_Description", "model": "topmenu_quickbooks" },
            { "name": "Zoom Envios", "path": "zoom-carrier-setup", "enabled": true, "description": "Document_Description", "model": "topmenu_zoom_envios" },
            { "name": "PayPal", "path": "paypal-config", "enabled": true, "description": "Document_Description", "model": "topmenu_paypal" },
            { "name": "Whatsapp", "path": "whatsapp-templates", "enabled": true, "description": "Document_Description", "model": "topmenu_whatsapp" }
          ]
        }
      ]
    }
  ]
}'
WHERE id >= 1;