{% load i18n %}


<ol class="breadcrumb">
    <li>  {% trans "进出存报表" %}</li> 
    <li> {{voucher.name}}</li> 
</ol>



<script type="text/javascript">
    $(document).ready(function(){    

        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
        $('.datepicker').datepicker('setDate',new Date());
        setDatePickerZh();    

        $('#product_label').autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/product/',
                    dataType: "json",
                    data: {
                        term:   $("#product_label").val() ,//搜索栏里的内容
                        //company_id:  $('#id_company').val() ,//额外参数
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            select: function (event, ui) {
                $("#product_id").val(ui.item.value);
                $("#product_label").val(ui.item.label);
                return false;
            }
        });
        $('#agent_label').autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/agent/',
                    dataType: "json",
                    data: {
                        term:   $("#agent_label").val() ,//搜索栏里的内容
                        //company_id:  $('#id_company').val() ,//额外参数
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            select: function (event, ui) {
                $("#agent_id").val(ui.item.value);
                $("#agent_label").val(ui.item.label);
                return false;
            }
        });




        {% ifequal voucher.id 2 %}
        
        {% endifequal %}    




        

        $('.btn-qry').click(function(){           
            var product_id='',agent_id='',code='';            
            
            if (!$.isEmpty($('#product_id').val())){
                product_id=$('#product_id').val();
            };
            if (!$.isEmpty($('#agent_id').val())){
                agent_id=$('#agent_id').val();
            };
            if (!$.isEmpty($('#code').val())){
                code=$('#code').val();
            };          

           

            date_fr=$('#dt_fr').val();
            date_to=$('#dt_to').val();
            
            var params=[];
           
            if(product_id!=''){
                params.push('product_id='+product_id);
                params.push('product_label='+$('#product_label').val());
            };
            if(agent_id!=''){
                params.push('agent_id='+agent_id);
                params.push('agent_label='+$('#agent_label').val());
            };
            if(code!=''){
                params.push('code='+code);               
            };

            
            if(date_fr!=''){params.push('date_fr='+date_fr)};
            if(date_to!=''){params.push('date_to='+date_to)};

            if(params.length==0){
                bootbox.alert("{% trans '请先输入查询条件！'%}");
            }else{
                $.RefreshContent('{{request.path}}?'+params.join('&'));
            }
        });

        {% ifnotequal params.dt_fr '' %}
            $('#dt_fr').val('{{params.dt_fr}}');
        {% endifnotequal  %}
        {% ifnotequal params.dt_to '' %}
            $('#dt_to').val('{{params.dt_to}}');
        {% endifnotequal  %}
       
        {% ifnotequal params.product_id '' %}
            $('#product_id').val('{{params.product_id}}');
            $("#product_label").val('{{params.product_label}}');
        {% endifnotequal  %}

         {% ifnotequal params.agent_id '' %}
            $('#agent_id').val('{{params.agent_id}}');
            $("#agent_label").val('{{params.agent_label}}');
        {% endifnotequal  %}
       
        var table=$('#tb').DataTable({
            //"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            //"bLengthChange":true,
            dom: 'Bfrtip',
            autoWidth: false,
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
            language:lng,           
            data:{{data}}
        });       
        
        table.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });  
        

        $('#tb').on("click","td a",function(event){

            $(event.target.parentNode).addClass('row_selected');

             event.preventDefault();
             $.OpenDlg($(this).attr('href'),'{{voucher.name}}-明细列表',1000,700);


            //$.RefreshContent($(this).attr('href'));  
            //return false;
            //$("#dlgDiv").dialog("open")
        });   


    });
</script>

<form role="form"  class="form-inline" style="margin-top:0px;">
    <div class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "开始日期"%}</span>
        <input class="datepicker form-control" id="dt_fr" />
    </div>
    <div class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "结束日期"%}</span>
        <input class="datepicker form-control" id="dt_to" />
    </div>
    
    {% ifequal user.company.level_id 1 %}
        <div class="col-sm-2 input-group">        
            <input class="form-control" id="product_label"   placeholder='所有产品' />
            <input type='hidden' id='product_id' />
        </div>
        {% ifequal voucher.id 2 %}
            <div class="col-sm-2 input-group">        
                <input class="form-control" id="agent_label"   placeholder='所有经销商' />
                <input type='hidden' id='agent_id' />
            </div>
        {% endifequal %}
        {% ifequal voucher.id 1 %}
            <div class="col-sm-2 input-group">        
                <input class="form-control" id="code" placeholder='所有生产批次' />           
            </div>
        {% endifequal %}
    {% endifequal %}


    <div style="float:right;">

        <span class='input-group-btn'>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查找' %}
            </a>
        </span>
        <!--
        <button class="btn btn-sm btn-primary btn-qry" type="button"><i class="fa fa-search"></i> {% trans '查找' %}</button>
        -->
    </div>
</form>
<div class="clearfix"></div>
<div id="inventory-list" class="table-responsive">
    <div class='x_panel'>    
    <table id="tb" class="table table-striped table-bordered dt-responsive" width="100%" >
        <thead>
            <tr>
                <th  style='width:9%'>{% trans "上传时间" %}</th>
                {% ifequal voucher.id 1 %}
                    {% ifequal user.company.level_id 1 %}
                        {% ifnotequal user.company.id 1644 %}
                            <th  style='width:6%'>{% trans "生产批次" %}</th>
                        {% else %}
                            <th  style='width:6%'>{% trans "单据编号" %}</th>
                        {% endifnotequal %}
                    {% else %}
                        <th  style='width:6%'>{% trans "单据编号" %}</th>
                    {% endifequal %}
                {% else %}
                    <th  style='width:6%'>{% trans "单据编号" %}</th>
                {% endifequal %}

                {% ifequal voucher.id 2 %}
                    <th  style='width:16%'>{% trans "客户名称" %}</th>
                    {% if user.company.cfg_company.saldiv_report %}
                        <th  style='width:7%'>{% trans "战区" %}</th>
                        <th  style='width:7%'>{% trans "分区" %}</th>
                    {% endif %}
                {% endifequal %}  
                {% ifequal voucher.id 7 %}
                    <th  style='width:16%'>{% trans "客户名称" %}</th>
                    {% if user.company.cfg_company.saldiv_report %}
                        <th  style='width:7%'>{% trans "战区" %}</th>
                        <th  style='width:7%'>{% trans "分区" %}</th>
                    {% endif %}
                {% endifequal %} 


                {% ifequal voucher.id 4 %}
                    <th  style='width:20%'>{% trans "退货客户" %}</th>
                {% endifequal %} 

                <th  style='width:15%'>{% trans "产品名称" %}</th>


                {% ifequal voucher.id 1 %}
                    {% if user.company.is_manufacturing %}
                        {% ifequal user.company.id 16716 %}
                            <th  style='width:20%'>{% trans "工厂名称" %}</th>
                        {% else %}
                            {% ifequal user.company.id 100425 %}
                                <th  style='width:9%'>{% trans "工厂名称" %}</th>
                                <th  style='width:8%'>{% trans "车间" %}</th>
                                <th  style='width:5%'>{% trans "产线" %}</th>
                                <th  style='width:5%'>{% trans "班组" %}</th>
                            {% else %}
                                <th  style='width:6%'>{% trans "质检员" %}</th>
                            {% endifequal %}
                        {% endifequal %}
                    {% endif %}
                {% endifequal %} 


                {% ifequal voucher.id 3 %}
                    <th  style='width:10%'>{% trans "转入" %}</th>
                    <th  style='width:10%'>{% trans "转出" %}</th>
                {% else %}
                    <th  style='width:8%'>{% trans "仓库名称" %}</th>
                {% endifequal %}




                <th  style='width:6%'>{% trans "操作人" %}</th>
                <th  style='width:5%'>{% trans "箱数" %}</th>
                <th  style='width:5%'>{% trans "盒数" %}</th>
                <th  style='width:5%'>{% trans "瓶数" %}</th>
                {% ifequal voucher.id 2 %}  
                    {% ifequal user.company.id 19257 %} 
                        <th  style='width:5%'>{% trans "客户上级" %}</th> 
                    {% endifequal %}
                    {% ifequal user.company.id 20445 %} 
                        <th  style='width:5%'>{% trans "品牌推荐" %}</th> 
                    {% endifequal %}
                {% endifequal %}      
                {% ifequal voucher.id 7 %}  
                    {% ifequal user.company.id 19257 %} 
                        <th  style='width:5%'>{% trans "客户上级" %}</th> 
                    {% endifequal %}
                    {% ifequal user.company.id 20445 %} 
                        <th  style='width:5%'>{% trans "品牌推荐" %}</th> 
                    {% endifequal %}
                {% endifequal %}     
            </tr>            
        </thead>
        <tbody></tbody>
        <tfoot>
            <th><input type="text" placeholder="{% trans "上传时间" %}"></th>
            <th><input type="text" placeholder="{% trans "单号" %}"></th>

            {% ifequal voucher.id 2 %}
                <th><input type="text" placeholder="{% trans "客户名称" %}"></th>
                {% if user.company.cfg_company.saldiv_report %}
                    <th><input type="text" placeholder="{% trans "战区" %}"></th>
                    <th><input type="text" placeholder="{% trans "分区" %}"></th>
                {% endif %}
            {% endifequal %} 
            {% ifequal voucher.id 7 %}
                <th><input type="text" placeholder="{% trans "客户名称" %}"></th>
                {% if user.company.cfg_company.saldiv_report %}
                    <th><input type="text" placeholder="{% trans "战区" %}"></th>
                    <th><input type="text" placeholder="{% trans "分区" %}"></th>
                {% endif %}
            {% endifequal %} 



            {% ifequal voucher.id 4 %}
                <th><input type="text" placeholder="{% trans "退货客户" %}"></th>
            {% endifequal %} 



            <th><input type="text" placeholder="{% trans "产品名称" %}"></th>
                {% ifequal voucher.id 1 %}
                    {% if user.company.is_manufacturing %}
                        <th><input type="text" placeholder="{% trans "工厂名称" %}"></th>
                    {% endif %}
                {% endifequal %}
            {% ifequal voucher.id 3 %}
                <th><input type="text" placeholder="{% trans "转入" %}"></th>
                <th><input type="text" placeholder="{% trans "转出" %}"></th>
            {% else %}
                <th><input type="text" placeholder="{% trans "仓库名称" %}"></th>
            {% endifequal %}

            <th><input type="text" placeholder="{% trans "操作人" %}"></th>
            <th><input type="text" placeholder="{% trans "箱数" %}"></th>
            <th><input type="text" placeholder="{% trans "盒数" %}"></th>
            <th><input type="text" placeholder="{% trans "瓶数" %}"></th>  

            {% ifequal voucher.id 2 %}
                {% ifequal user.company.id 19257 %}                
                    <th><input type="text" placeholder="{% trans "客户上级" %}"></th>
                {% endifequal %}
                {% ifequal user.company.id 20445 %}                
                    <th><input type="text" placeholder="{% trans "品牌推荐" %}"></th>
                {% endifequal %}
            {% endifequal %}   
            {% ifequal voucher.id 7 %}
                {% ifequal user.company.id 19257 %}                
                    <th><input type="text" placeholder="{% trans "客户上级" %}"></th>
                {% endifequal %}
                {% ifequal user.company.id 20445 %}                
                    <th><input type="text" placeholder="{% trans "品牌推荐" %}"></th>
                {% endifequal %}
            {% endifequal %} 
        </tfoot>
    </table>   
    </div>
</div>
