<?php
use yii\helpers\Url;
use yii\helpers\StringHelper;
use yii\helpers\ArrayHelper;
use home\modules\sale\models\Opportunity;

?>
<div class="p15">

    <table class="table task-table ">
        <tbody>
            <tr>
                <th width="24%">机会名称</th>
                <th width="26%">客户名称</th>
                <th width="10%">发现人</th>
                <th width="10%">所有人</th>
                <th width="10%">阶段</th>
                <th width="10%">成交日期</th>
                <th width="10%">操作</th>
            </tr>
            <?php if (!empty($opportunitys)) : ?>
            <?php foreach ($opportunitys as $model) : ?>
            <tr>
                <td class="theleft-min" title="<?= $model->name ?>">
                    <a href="<?= Url::to(['/sale/opportunity/detail', 'id' => $model->opportunity_id, 'from' => Url::to('')]) ?>">
                        <?= StringHelper::truncate($model->name, 11) ?>
                    </a>
                </td>
                <?php if (isset($model->customer)) : ?>
                    <td class="theleft-min" title="<?= $model->customer->name ?>">
                        <a target="_blank" href="<?= Url::to(['/customer/customer/detail', 'id' => $model->customer->customer_id]) ?>">
                            <?= StringHelper::truncate($model->customer->name, 12) ?>
                        </a>
                    </td>
                <?php else : ?>
                    <td class="theleft-min" title="">
                        
                    </td>
                <?php endif; ?>

                <td><?= ArrayHelper::getValue(\common\api\User::getOne($model->discoverer_id), 'realname'); ?></td>
                <td><?= ArrayHelper::getValue(\common\api\User::getOne($model->leader_id), 'realname'); ?></td>

                <td><?= isset($model->category) ? $model->category->name : '' ?></td>

                <td><?= date('Y-m-d', $model->due_date) ?></td>

                <td align="center" >
                    <?php if(Opportunity::readAccess('home/schedule/link-sale_opportunity')) : ?>
                        <a href="javascript:;" data-url="<?= Url::to(['/schedule/create', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity', 'link_customer_no' => $model['customer_no']]) ?>" data-title="添加日程"  data-width="600" data-height="380" class="open-dialog" >日程</a>
                    <?php else : ?>
                        <a href="javascript:;" class="gray" title="当前没有权限添加日程">日程</a>
                    <?php endif; ?>
                    <a href="javascript:;" class="open-dialog" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity']) ?>" data-reload="false" data-title="任务报销" data-width="700">报销</a>
                </td>
            </tr>
            <?php endforeach; ?>
            <tr><td colspan="7"><a href="<?= Url::to(['/sale/opportunity/index', 'type' => 'lead']) ?>" >更多销售机会...</a></td></tr>
            <?php else : ?>
            <tr><td colspan="7">暂无数据...</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
