{% load i18n %}

<style>

    .inventory-tt .g{
        color:green;
        margin-right:10px;
    }
    #tb-dlg tbody .btn{
        padding-bottom:0px;
        margin-bottom:0px;    
    }
</style>





<script type="text/javascript">    
    $(document).ready(function(){    
        
        var table;
        function refreshData(){
            $.ajax({
                type:'GET',
                processData: false,  
                contentType: 'application/json; charset=utf-8',
                url:'/inventory/stock/report/preclose_data/',
                success:function(data){  
                    if(data.e){
                        toastr.error(data.e, "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                        return;
                    };

                    var table=$('#tb-dlg').DataTable({
                        dom: 'Bfrtip',
                        autoWidth: false,
                        buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
                        language:lng,            
                        destroy:true,
                        data:data.periods,
                        order: [[ 1, 'desc' ]]  
                    });      
                    table.column(0).visible(false);
        
                    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-dlg tbody').on('click','.btn',function(){   
            $.ajax({
                type:'POST',
                url:'/inventory/stock/close/',
                processData: false,  
                data:JSON.stringify({'year':$(this).attr('yr'),'month':$(this).attr('mn')}),
                contentType: 'application/json; charset=utf-8',
                    
                success:function(data){  
                    if(data.e){
                        toastr.error(data.e, "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                        return;                            
                    }else{
                        refreshData();
                    }                        
                }
            });
        });       

        refreshData();
    });
</script>



<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>id</th>
            <th style='width:15%;'>{% trans "会计期" %}</th>
            <th style='width:20%;'>{% trans "开始日期" %}</th>
            <th style='width:20%;'>{% trans "结束日期" %}</th>
            <th>{% trans "期结时间" %}</th>
            
        </thead><tbody></tbody>
        <tfoot>
            <th></th>
            <th><input  type="text" placeholder="会计期"></th>
            <th><input  type="text" placeholder="开始日期"></th>
            <th><input  type="text" placeholder="结束日期"></th>
            <th><input  type="text" placeholder="期结时间"></th>           
        </tfoot>
    
    </table>       
</div>



