# NetSuite Module - Settings Configuration

## Accessing NetSuite Settings

You can access the NetSuite settings configuration page at:

**URL:** `/netsuite-settings/index`

Or use the full path:
```
https://yourdomain.com/netsuite-settings/index
```

## Configuration Options

The settings page allows you to configure:

1. **Enable/Disable Integration** - Toggle NetSuite integration on/off
2. **Environment** - Choose between Sandbox (testing) or Production (live)
3. **Account ID** - Your NetSuite Account ID
4. **Consumer Key** - OAuth 1.0 Consumer Key from NetSuite
5. **Consumer Secret** - OAuth 1.0 Consumer Secret from NetSuite
6. **Token ID** - Token ID from NetSuite Token-Based Authentication
7. **Token Secret** - Token Secret from NetSuite Token-Based Authentication

## How to Get Your Credentials

1. Log in to your NetSuite account
2. Go to **Setup → Integration → Manage Integrations**
3. Create a new integration or select an existing one
4. Copy the **Consumer Key** and **Consumer Secret**
5. Go to **Setup → Users/Roles → Access Tokens**
6. Create a new token for the integration
7. Copy the **Token ID** and **Token Secret**
8. Enter all credentials in the settings form

## Settings Storage

Settings are stored in:
```
modules/netsuite/config/ns.php
```

This file is automatically loaded during module initialization and merged into `Yii::$app->params['netsuite']`.

Example ns.php structure:
```php
<?php
return [
    'enabled' => true,
    'account_id' => 'your_account_id',
    'consumer_key' => 'your_consumer_key',
    'consumer_secret' => 'your_consumer_secret',
    'token_id' => 'your_token_id',
    'token_secret' => 'your_token_secret',
    'environment' => 'production', // or 'sandbox'
];
```

### How It Works

1. Settings are saved to `modules/netsuite/config/ns.php` when you submit the form
2. During application initialization, `Module::init()` loads this file
3. The configuration is merged into `Yii::$app->params['netsuite']`
4. Your application can access settings via `Yii::$app->params['netsuite']`

## Features

- **Visual Settings Form** - Easy-to-use interface for managing credentials
- **Test Connection** - Button to verify credentials are working
- **Environment Toggle** - Switch between sandbox and production
- **Secure Storage** - Credentials stored in params-local.php (not in version control)
- **Help Documentation** - Built-in instructions and links to NetSuite docs

## Security Notes

- Add `modules/netsuite/config/ns.php` to your `.gitignore` file
- Never commit `ns.php` to version control (it contains sensitive credentials)
- Use sandbox environment for testing
- Rotate credentials periodically
- Restrict access to settings page to administrators only
- Ensure proper file permissions (644 or 600) on ns.php

## Troubleshooting

If you can't access the settings page:

1. Check that the NetSuite module is enabled in your application
2. Verify you have proper user permissions
3. Clear application cache if needed
4. Check the URL routing configuration

## Future Enhancements

Planned features:
- Real connection testing with NetSuite API
- Credential validation
- Integration health monitoring
- Activity logs
