{% load i18n %}

<style>

    .inventory-tt .g{
        color:green;
        margin-right:10px;
    }
</style>

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

        var table=$('#tb-dlg').DataTable({
            dom: 'Bfrtip',
            autoWidth: false,
            //2024-12-13 蒙古王标签长度16，导出成EXCEL时会四舍五入
            {% ifequal request.user.ancestor_id 215340 %}
                buttons: [{extend:'csv',text:'导出CSV文件','bom': true}], 
            {% else %}
                buttons: [{extend:'excelHtml5',text:'导出到Excel'}],
            {% endifequal %}  
            language:lng,
            destroy:true,
            data:{{dataset|safe}}
        });

        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();
                }
           });
        });

        
        {% if perms.company.sys_admin %}
            $('.btn-edit').click(function(){ 
                $("#bg-modal").modal('hide');  
                $.RefreshContent('/inventory/edit/batch/{{batch.id}}/');            
            });  
        
        {% endif %}

		
        {% if del_perm %}
            $('.btn-delete').click(function(){
                var msg = "您确定要删除此单据吗？\n\n请确认！";                 
                if (confirm(msg)==true){
                    $.ajax({
                        type:'GET',
                        processData: false,
                        contentType: 'application/json; charset=utf-8',
                        url:'/inventory/delete/batch/{{batch.id}}/',
                        success:function(data){
                                if (data.e==''){
                                    var date_from,date_to,agent_id;        
                                    date_fr=$('#dt_fr').val();
                                    date_to=$('#dt_to').val();
                                    agent_id=$('#agent_id').val();
                                    var params=[];
                                    if(date_fr!=''){params.push('date_fr='+date_fr)};
                                    if(date_to!=''){params.push('date_to='+date_to)};
                                    if(agent_id){params.push('agent_id='+agent_id)};
                                    $("#bg-modal").modal('hide');                
                                    $.RefreshContent('/inventory/agent/list/?'+params.join('&'));   
                                }else{
                                    toastr.error(
                                        data.e,
                                        "错误：",
                                        {timeOut: 800, positionClass: "toast-center-center"}
                                    );                        
                                }      
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert('连接服务器失败');
                                return;
                        }
                    }); 
                
                };        
                         
            });
        {% endif %}
		
    });
</script>

<div class='inventory-tt'>
    <span>单据编号:<span class='g'>{{batch.code}}</span></span>
    <span>产品名称:<span class='g'>{{batch.product}}</span></span>
    {% if batch.plant %}
        <span>工厂名称:<span class='g'>{{batch.plant}}</span></span>

    {% endif %}



    {% ifequal batch.vid 2 %}
        <span>客户名称:<span class='g'>{{batch.customer}}</span></span>
    {% endifequal %}
    {% ifequal batch.vid 4 %}
        <span>退货单位:<span class='g'>{{batch.customer}}</span></span>
    {% endifequal %}
    {% ifequal batch.vid 3 %}
        <span>转入仓库:<span class='g'>{{batch.store_to}}</span></span>
        <span>转出仓库:<span class='g'>{{batch.store_fr}}</span></span>
    {% else %}
        <span>仓库名称:<span class='g'>{{batch.store_fr}}</span></span>
    {% endifequal %}
    <span>操作人:<span class='g'>{{batch.user}}</span></span>
    <span>上传时间:<span class='g'>{{batch.time}}</span></span>
    {% if perms.company.sys_admin %}
         <button type="button" class="btn btn-primary btn-edit" >修改单据</button>
    {% endif %}
    {% if del_perm %}
         <button type="button" class="btn btn-danger btn-delete" >删除单据</button>
    {% endif %}

</div>
<div class="clearfix"></div>


<div id="inventory-list" class="table-responsive">

    <table id="tb-dlg" class="table table-striped table-bordered dt-responsive" width="100%">
        <thead>
            <th style='width:40%;'>{% trans "标签号码" %}</th>
            <th style='width:10%;'>{% trans "标签类型" %}</th>
            <th style='width:50%;'>{% trans "产品名称" %}</th>
        </thead>
        <tbody></tbody>
        <tfoot>
            <th><input  type="text" placeholder="标签号码"></th>
            <th><input  type="text" placeholder="标签类型"></th>
            <th><input  type="text" placeholder="产品名称"></th>
        </tfoot>

    </table>
</div>



