<?php 
use yii\helpers\{Html, Url};
use yii\bootstrap4\ActiveForm;

$itemstoupdate = [
    'service' => 'Update Services',
    'activities' => 'Update Activities / Jobs',
    'asset' => 'Assets',
    'remove' => 'Remove old Asset',
];

?>
<script>
   var fromassets = '<?= json_encode(array_column($fromAssets, 'id')); ?>';
   var toassets = '<?= $toAssets['id']; ?>';
</script>
<div class="asset-merge">
    <div class="row">
        <div class="col-md-6">
            <h4>
                From
            </h4>
                <?php foreach($fromAssets as $key => $asset){ ?>
                    <?php if($asset['id'] !== $toAssets['id']){ ?>
                        <i><?= $asset['serialnumber']; ?> - <?= $asset['model']; ?></i> <br/>
                    <?php } ?>
                <?php } ?>
        
        </div>
        <div class="col-md-6">
            <h4>
                To
            </h4>
            <i>
                <?= $toAssets['serialnumber']; ?> - <?= isset($toAssets['product']['product_name'])  ? $toAssets['product']['product_name'] : null; ?>
            </i> 
        </div>
    </div>
    <p>
        Please select the Items to Action
    </p>
    <?php $form = ActiveForm::Begin(['method' => 'post']); ?>
        <?php foreach($itemstoupdate as $action => $label){ ?>
            <div class="row">
                <div class="col-12">  
                    <?= Html::checkbox("Options[$action]", '', ['label' => $label]); ?>
                </div>
            </div>
        <?php } ?>
        
    <?php ActiveForm::end(); ?>
</div>

<script>
   $(document).on("click",".btn-merge",function() {
		options = $('input[name^="Options"]').serialize();
        $.ajax({
            type:'post', 
            url: '/NGauge/asset/mergedata',
            data: {
                from: fromassets,
                to: toassets,
                options: options
            }, 
            success:function(result){
                $('#LGmodal .modal-body').html(result.message);
                $('#LGmodal .modal-body').append(result.errors);
                if(result.status == 200){
                    $('#LGmodal .close').click();
                }
            }
        })
    })
</script>