<?php
/**
 * NetSuite Order Links Section - NetSuite Module
 * This displays NetSuite order links and information
 * Location: Header - NetSuite anchor point (replaces inline NetSuite code)
 */

use yii\helpers\Html;

// Check if NetSuite is enabled
if (!array_key_exists('netsuite', Yii::$app->params['plugins']) || 
    !Yii::$app->params['plugins']['netsuite']['enabled']) {
    return '';
}

// Parse NetSuite ID data
$ns = empty($model->netsuiteid) == false ? json_decode($model->netsuiteid, 1) : false;
?>

<div class="netsuite-info mb-2">
    <label class="font-weight-bold"><?= $model->getAttributelabel('netsuiteid'); ?>:</label><br>
    <?php if (is_array($ns) == true) { ?>
        <?php foreach ($ns as $key => $array) { ?>
            <?= Html::A($key . ' - ' . $array, "https://4465021.app.netsuite.com/app/accounting/transactions/salesord.nl?id=$array&whence=", [
                'target' => '_blank',
                'class' => 'btn btn-sm btn-outline-primary mr-1 mb-1'
            ]) ?>
            <br />
        <?php } ?>
    <?php } else { ?>
        <?= Html::A($model->netsuiteid, "https://4465021.app.netsuite.com/app/accounting/transactions/salesord.nl?id=$model->netsuiteid&whence=", [
            'target' => '_blank',
            'class' => 'btn btn-sm btn-outline-primary'
        ]) ?>
    <?php } ?>
</div>