<?php  use Cake\ORM\TableRegistry;
    $products = TableRegistry::get('Products');  
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
      <?= $this->element('admin_sidebar') ?>
</nav>
<div class="companies index large-9 medium-8 columns content">
    <div class="col-md-3">
        <h3><?= __('Companies') ?></h3>
    </div>
	<div class="search-wrapper">  
        <div class="col-md-7">
            <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>
        </div>
        <div class="col-md-2">
            <div class="btn-link"><?= $this->Html->link(__('Add Company'), ['action' => 'add'],['class'=>'green-btn', 'title' => 'Add New Companies', 'type' => 'button']) ?></div>
        </div>
	</div>
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th style="width:40px;" scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('company') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Associate With') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Product Type') ?></th>
                <th scope="col" class="actions"><?= __('Actions') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php $srlno = ($this->request->params['paging']['Companies']['page']-1) * $this->request->params['paging']['Companies']['perPage'];
            $j = 1;
            
            foreach ($companies as $company): $srlno++; ?>
            <tr>
                <td><?=$srlno ?></td>
                <td><?= h($company->company) ?></td>
                <td><?= h($company->associatewith) ?></td>
               <td>
		<?php
			if($company->productid > 0){
			//pr($company->productid);
			$productids = explode(",",  $company["productid"]);
				foreach($productids as $productid){
				$productdata = $products->find()->where(['id' => $productid]);
				$data2 = $productdata->toArray();
					echo $productname = $data2[0]->productname.'<br/>';
				} 
			}
		?>
	     </td>
                <td class="actions">
                    <?= $this->Html->link(__('View'), ['action' => 'view', $company->id],['class' => 'view','title'=>__('View')]) ?>
                    <?= $this->Html->link(__('Edit'), ['action' => 'edit', $company->id],['class' => 'edit','title'=>__('Edit')]) ?>
                    <!--<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $company->id], ['class' => 'delete','title'=>__('Delete'),'confirm' => __('Are you sure you want to delete # {0}?', $company->id)]) ?>-->
                </td>
            </tr>
            <?php 
            $j++;
            endforeach; ?>
        </tbody>
    </table>
<div class="btn-link"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
    <div class="paginator">
        <ul class="pagination">
             <?= $this->Paginator->first(__('First', true), array('class' => 'disabled')); ?>
            <?= $this->Paginator->prev('< ' . __('previous',true), array('class' => 'disabled')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('next' . ' >',true), array('class' => 'disabled')) ?>
		 <?=  $this->Paginator->last(__('Last', true), array('class' => 'disabled')); ?>
        </ul>
        <p><?= $this->Paginator->counter() ?></p>
    </div>
</div>