<?php
use yii\helpers\Url;
use yii\helpers\StringHelper;
use yii\helpers\ArrayHelper;
use home\modules\contract\models\Contract;
use common\models\User;

?>
<div class="p15">

    <table class="table task-table ">
        <tbody>
            <tr>
                <th width="24%">合同名称</th>
                <th width="20%">客户名称</th>
                <th width="10%">所有人</th>
                <th width="16%">合同金额</th>
                <th width="10%">已回款</th>
                <th width="10%">已开票</th>
            </tr>
            <?php if (!empty($contracts)) : ?>
            <?php foreach ($contracts as $model) : ?>
            <tr>
                <?php if (Contract::readAccess('contract/contract/detail')) : ?>
                    <td class="theleft-min" title="<?= $model['name']; ?>"><a href="<?= Url::to(['/contract/contract/detail', 'id' => $model['contract_id']]) ?>"><?=
                            StringHelper::truncate($model['name'], 5, '')
                            ?></a>
                    </td>
                <?php else : ?>
                    <td class="theleft-min"><?= $model['contract_no'] ?></td>
                    <td class="theleft-min" title="<?= $model['name']; ?>"><?= StringHelper::truncate($model['name'], 5, '') ?></td>
                <?php endif; ?>
                <!-- 真实客户 -->
                <?php if (Contract::readAccess('customer/customer/detail')) : ?>
                    <td class="theleft-min" title="<?= $model['realCustomer']['name'] ?>" >
                        <a target="_blank" href="<?= Url::to(['/customer/customer/detail', 'id' => $model['realCustomer']['customer_id'], 'from' => Url::to('')]) ?>  ">
                            <?=
                            StringHelper::truncate($model['realCustomer']['name'], 8, '')
                            ?>
                        </a>
                    </td>
                <?php else : ?>
                    <td class="theleft-min" title="<?= $model['realCustomer']['name'] ?>" >
                        <?=
                        StringHelper::truncate(!empty($model['realCustomer']['simple_name']) ? $model['realCustomer']['simple_name'] : $model['realCustomer']['name'], 4, '')
                        ?>
                    </td>
                <?php endif; ?>

                <td title="<?= $model['user']['realname'] ?>"><?= StringHelper::truncate($model['user']['realname'], 5, '') ?></td>
                <!-- 金额(元) -->
                <td class="theright-min">
                    <?= number_format($model['money'], 2, '.', ',') ?>
                </td>
                <!-- 已回款 -->
                <td class="theright-min"><?= number_format($model['receivableMoney'], 2, '.', ',') ?></td>
                <!-- 已开票 -->
                <td class="theright-min"><?= number_format($model['billingMoney'], 2, '.', ',') ?></td>

            </tr>
            <?php endforeach; ?>
            <tr><td colspan="7"><a href="<?= Url::to(['/contract/contract/index']) ?>" >更多合同...</a></td></tr>
            <?php else : ?>
            <tr><td colspan="7">暂无数据...</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
