{% load i18n %}


<style>
    .tt{
        font-size:14px;
    }
    .tt div{
        padding-bottom:5px;
    }
    .g{
        color:green;
        margin-right:20px;
    }
    .b{
        color:black;
        margin-right:10px;
        font-style:normal;    
    }

    .timeline h2.active:before {
        background: green;
    }

    .btn-update{
        font-style:normal;
    }
    
</style>


<script type="text/javascript">
    $(document).ready(function(){    
        $("[data-toggle='popover']").popover({html : true }); 

        $('.btn-update').click(function(){
            $.ajax({
                type:'POST',
                data:JSON.stringify({
                    "product":[],
                    "material":[],         
                    "user_id":{{request.user.id}},                
                    "key":"{{key|safe}}",
                    "time":"{{time}}"
                }),
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                url:'/wx/gifts/requisition/update/{{req.id}}/{{req.status_id}}/',
                success:function(data){                    
                    $.RefreshContent('{{request.path}}');
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });        
        });
       
    });
</script>



<ol class="breadcrumb">
        <li>领用核销</li>
        <li>领用日志</li>     
</ol>


<div class='tt'>
    <div>
        方案编号：<span class='b'>{{ req.scheme.code }}</span>    
        方案名称：<span class='b'>{{ req.scheme.name }}</span>
        有效范围：<span class='b'>{{ req.scheme.scope }}</span>
        地区：<span class='b'>{{ req.scheme.region }}</span>
    </div>
    <div>
        客户类型：<span class='b'>{{ req.scheme.agent_type }}</span>
        发放条件：<span class='b'>{{ req.scheme.condition }}</span>
        最晚申请时间：<span class='b'>{{ req.scheme.tm_app_latest|date:'Y-m-d H:i:s' }}</span>
    </div>
    <div>
        销售战区：<span class='b'>{{req.saldiv.name|default_if_none:'(空)' }}</span>
        销售区域：<span class='b'>{{req.subdiv.name|default_if_none:'(空)' }}</span>
        业务姓名：<span class='b'>{{req.salesman.username|default_if_none:'(空)' }}</span>
        创建时间：<span class='b'>{{req.tm|date:'Y-m-d H:i:s'}}</span>
    </div>
    <div>客户名称：<span class='b'>{{req.agent.name}}</span></div>   

</div>




<div class="x_panel" id='prj-product' style='margin-top:10px;'>
        <div class="x_title">
            <h2 style='font-size:15px;'><i class="fa fa-gift"></i> 成品酒/品鉴酒 </h2>
            <ul class="nav navbar-right panel_toolbox">
                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Settings 1</a></li>
                        <li><a href="#">Settings 2</a></li>
                    </ul>
                </li>
                <li><a class="close-link"><i class="fa fa-close"></i></a></li>
            </ul>
            <div class="clearfix"></div>
        </div>
        <div class="x_content">      
            {% for p in req.requisitionproducts_set.all %}
                <div>
                    产品名称：<span class='b'>{{p.product.name}}</span>
                    数量：<span class='b'>{{p.qty}} {{p.get_package_id_display}}</span>                    
                </div>
            {% endfor %}
        </div>
</div>
    
<div class="x_panel" id='prj-material'>
        <div class="x_title">
            <h2 style='font-size:15px;'><i class="fa fa-gift"></i> 促销物料 </h2>
            <ul class="nav navbar-right panel_toolbox">
                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Settings 1</a></li>
                        <li><a href="#">Settings 2</a></li>
                    </ul>
                </li>
                <li><a class="close-link"><i class="fa fa-close"></i></a></li>
            </ul>
            <div class="clearfix"></div>
        </div>
        <div class="x_content">      
            {% for p in req.requisitionmaterials_set.all %}
                <div>
                    物料名称：<span class='b'>{{p.material.name}}</span>
                    数量：<span class='b'>{{p.qty}}</span>                                      
                </div>
            {% endfor %}
        </div>
</div>








<div style='margin-top:20px;' id='requisition-log'>
    <ul class="list-unstyled timeline widget">
        {% for l in logs %}
            <li>
                <div class="block">
                    <div class="block_content">
                        <h2 class="title{%　if l.user　%} active{% endif %}">
                            <a>{{l.status_name}}</a>  
                        
                        </h2>
                        <div class="byline">                          
                            {% if l.user %}
                                <span class='b'>{{l.user}}:</span>
                                <span >{{l.time|date:'Y-m-d H:i:s'}}</span>
                                {% if l.products %}
                                    <button type="button" class="btn btn-success" title="成品酒明细"
                                                        data-container="#requisition-log" data-toggle="popover" data-placement="top" 
                                        data-content="<ul style='padding-left:10px;'>{% for d in l.products %}<li>{{d.name}}:{{d.qty}}</li>{% endfor %}</ul>"
                                    >成品酒</button>                                    
                                {% endif %}
                                {% if l.materials %}
                                    <button type="button" class="btn btn-success"  title="物料明细" 
                                                        data-container="#requisition-log" data-toggle="popover" data-placement="top" 
                                        data-content="<ul style='padding-left:10px;'>{% for d in l.materials %}<li>{{d.name}}:{{d.qty}}</li>{% endfor %}</ul>"
                                    >促销物料</button>    
                                {% endif %}

                                {% ifequal req.status_id l.status_id %}
                                    {% if perms.company.sys_admin %}
                                        {% if l.status_action %}
                                            <button type="button" class="btn btn-update pull-right btn-primary">
                                                {{l.status_action}}
                                            </button>
                                        {% endif %}
                                    {% endif %}
                                {% endifequal%}
                            {% else %}
                                <span>待处理</span>
                            {% endif %}   

                        </div>                        
                            
                    </div>
                </div>
            </li>
        {% endfor %}
    </ul>
</div>
