<?php

use home\assets\MainAsset;
use yii\helpers\Url;
use home\widgets\Alert;
use home\modules\statement\models\StatementAccount;
use yii\widgets\ActiveForm;
use yii\helpers\StringHelper;
use yii\helpers\ArrayHelper;
use common\assets\My97DatePickerAsset;
use yii\helpers\Html;
use home\modules\customer\models\Category;
use home\modules\customer\models\District;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\rreimbursement\models\Application */

My97DatePickerAsset::register($this);

$assetUrl = $this->getAssetManager()->getBundle(MainAsset::className())->baseUrl;
$this->registerJsFile($assetUrl . '/js/statement.link.js', ['depends' => MainAsset::className()]);

$this->title = '对账单关联客户';
?>

<!--container-->
<div class="container manage-project fix">
    <?= $this->render('@home/views/site/_left-menu') ?>

    <!--manage-left -->
    <div class="manage-right">
        <div id="info" style="display:none;"></div>
        <div class="tab-column tab-manage">
            <div class="tab-right">
                <?php if(Yii::$app->session->get('isSuperAdmin') || Yii::$app->user->can('statement/statement-account/create')) : ?>
                    <button title="新增进账" type="button" data-height="300" data-width='550' data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-title='新增对账单' class="btn btn-default btn-task open-dialog">
                        <i class="icon-plus"></i>
                    </button>
                <?php endif; ?>
                <?php if(Yii::$app->session->get('isSuperAdmin') || Yii::$app->user->can('statement/statement-import/import')) : ?>
                    <button title="导入进账单" type="button" data-height="300" data-width='550' data-url='<?= Url::to(['statement-import/import']) ?>' data-title='导入进账单' class="btn btn-default btn-task open-dialog">
                        <i class="icon-upload-alt"></i>
                    </button>
                <?php endif; ?>
            </div>
            <p class="caption">进账关联选择</p>
        </div>

        <div class="task-title">
            <p class="lefttitle">
                进账详情
            </p>
        </div>

        <div class="mgt10">
            <table class="table task-table taskdetail-table">
                <tr>
                    <td width="10%" class="table-blue">银行流水号</td>
                    <td width="20%"><?= $model->serial_number ?></td>
                    <td width="10%" class="table-blue">日期</td>
                    <td width="20%"><?= date('Y-m-d', $model->payment_time) ?></td>
                    <td width="10%" class="table-blue">摘要</td>
                    <td><?= $model->remark ?></td>
                </tr>
                <tr>
                    <td width="10%" class="table-blue">收款银行</td>
                    <td width="20%"><?= $model->bank_name ?></td>
                    <td width="10%" class="table-blue">收款账号</td>
                    <td colspan="3"><?= $model->account_no ?></td>
                </tr>
                <tr>
                    <td width="10%" class="table-blue">对方银行</td>
                    <td width="20%"><?= $model->remittance_bank ?></td>
                    <td width="10%" class="table-blue">对方账号</td>
                    <td width="20%"><?= $model->remittance_no ?></td>
                    <td width="10%" class="table-blue">对方户名</td>
                    <td id="remittance_user"><?= $model->remittance_user ?></td>
                </tr>
                <tr>
                    <td width="10%" class="table-blue">借方金额(元)</td>
                    <td width="20%"><?= $model->account_debit ?></td>
                    <td width="10%" class="table-blue">贷方金额(元)</td>
                    <td width="20%"><?= $model->account_credit ?></td>
                    <td width="10%" class="table-blue">未关联金额(元)</td>
                    <td><?= number_format((max([$model->account_debit, $model->account_credit]) - $model->allocateAmount), 2, '.', ',') ?></td>
                </tr>
                <tr>
                    <td width="10%" class="table-blue">提交人</td>
                    <td width="20%"><?= $model->user->realname ?></td>
                    <td width="10%" class="table-blue">更新日期</td>
                    <td width="20%" colspan="3"><?= date('Y-m-d', $model->update_time) ?></td>
                </tr>
            </table>
        </div>
        <?php if(!empty($model['customer'])): ?>
            <div class="task-title">
                <p class="lefttitle">
                    已关联客户
                </p>
            </div>
            <div class="mgt10" id='data_list'>
                <table class="table task-table">
                    <tr>
                        <th width="30%">客户名称</th>
                        <th width="20%">类别</th>
                        <th>所属区域</th>
                        <th width="10%">负责人</th>
                        <th>操作</th>
                    </tr>
                    <tr>
                        <td><?= $model['customer']['name'] ?></td>
                        <td><?= $model['customer']['category']['name'] ?></td>
                        <td><?= $model['customer']['district']['name'] ?></td>
                        <td><?= $model['customer']['leader']['realname'] ?></td>
                        <td>
                            <?php if(Yii::$app->session->get('isSuperAdmin') || Yii::$app->user->can('statement/statement-account/delete-link')) : ?>
                                <a href='javascript:void(0);' data-customer_no='<?= $model['customer']['customer_no'] ?>' class='delete_link' style='color:red'>解除</a>
                            <?php else : ?>
                                <a href="javascript:;" class="gray" title="当前没有删除权限">解除</a>
                            <?php endif; ?>
                        </td>

                    </tr>
                </table>
            </div>
        <?php endif; ?>
        <div class="mgt10">
            <div class="task-title-date" >
                <p class="searchfl" id="customer-search-form">
                    <span class="fl">客户名称：</span>
                    <input class="form-control fl date-form-control search-form" id="keywords" value="<?= (isset($get['keywords'])) ? Html::encode($get['keywords']) : $model->remittance_user ?>" name="keywords" >

                    <select class="form-control fl date-form-control search-form" id="customer_category_id"  name="category_id" >
                        <option value="">--客户类别--</option>
                        <?php echo Category::getDropDownTree(isset($get['category_id']) ? $get['category_id'] : ''); ?>
                    </select>

                    <select class="form-control fl date-form-control search-form" id="customer_district_id" name="district_id" >
                        <option value="0">--客户区域--</option>
                        <?php echo District::getDropDownTree(isset($get['district_id']) ? $get['district_id'] : '', 0, true, 'child_ids'); ?>
                    </select>

                    <!--<button type="button" class="btn btn-primary fl task-sou" id="secrch_submit">查询</button>-->
                    <button type="button" title="搜索" class="btn btn-primary fl btn-serch task-sou"  id="secrch_submit">
                        <i class="icon-search"></i>
                    </button>
                    <!--<button type="button" class="btn fl btn-default reset_search_customer">重置</button>-->
                    <button type="button" title="重置" class="btn btn-default fl btn-reset reset_search_customer">
                        <i class="icon-undo"></i>
                    </button>
                </p>
            </div>
        </div>

        <div class="mgt10" id='data_list'>
            <table class="table task-table">
                <tr>
                    <th width="30%">客户名称</th>
                    <th width="20%">类别</th>
                    <th>所属区域</th>
                    <th width="10%">负责人</th>
                    <th>操作</th>
                </tr>
                <tbody id="customer-list">

                </tbody>
            </table>
        </div>
    </div>
    <!--manage-right-->
</div>
<!--container-->

<script>
    var ajaxGetCustomerUrl = "<?= Url::to([$this->context->id . '/ajax-get-customer']) ?>";
    var ajaxAddLinkUrl = "<?= Url::to([$this->context->id . '/create-link']) ?>";
    var ajaxDeleteLinkUrl = "<?= Url::to([$this->context->id . '/delete-link']) ?>";
    var customerNo = "<?= empty($model->statementLink->link_id) ? '' : $model->statementLink->link_id ?>";
    var statementId =<?= $model->statement_id ?>;
</script>