
<style>
    #InputFile{
        width:227px;
        color:#fff;
    }
    #InputFile > input{
        position:absolute;
        cursor:pointer;
        left:0px;
        top:0px;
        width:100%;
        height:100%;
        opacity:0.01;
    }

</style>
<div class="modal fade" role="dialog" id="UploadExcelFile"  data-backdrop="static" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="bold text-left" id="myModalLabel"><?php print CommonLanguage::getMessage('Import_Data');?></h5>
            </div><!-- end of modal-header -->
            <div class="modal-body">
                <form method="post" enctype="multipart/form-data" id="Upload_Excel" onsubmit="return false">
                    <div class="row">
                        <div class="alert hidden m-t-10" id="UploadAlert"><?php print CommonLanguage::getMessage('Wrong_Type_Files');?></div>
                        <div class=" col-md-12" >
                            <div class="col-md-12" style="margin-top: 10px;margin-bottom: 3px;"><a href="<?php echo SITE_LINK;?>uploads/Templatexlsx/MaterialInStock.xlsx" id="TemplateReference"><i class="fa fa-download"></i> <?php print CommonLanguage::getMessage('Download_Template');?></a></div>
                            <div class="col-md-12" >    
                                <h4><?php print CommonLanguage::getMessage('Upload_Downloaded_File');?> </h4>
                                <button class="btn bg-complete-darker" id="InputFile" style="cursor:pointer;"><i class="fa fa-upload"></i> <?php print CommonLanguage::getMessage('Upload');?> <input type="file" onchange="window.NewCurrentFileUploadadd = event.target.files;ValidateForNewFile(this,'#InputFile')" name="Document_File_Name" value="Upload"></button>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="CancelUpload"><?php print CommonLanguage::getMessage('Close');?></button>
                <button  class="btn bg-complete-darker text-white"  id="SaveExcelSheet"><i class="fa fa-check"></i> <?php print CommonLanguage::getMessage('Save');?></button>
            </div>
        </div>
    </div>
</div>
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully'));?>;
    $(function(){	
        $("#CancelUpload").on("click",function(){
            $("#InputFile >.fa-check,#NewFilewarning2").hide()
            $("#InputFile >input").val('')
        })
    })

    $("#SaveExcelSheet").on("click",function(){
        $("#ValidationAlert").remove();
        var FileName = $.trim($("#InputFile > input").val())
        var FileType = FileName.substring(FileName.lastIndexOf("."));
        if(FileType == ".xlsx"){
            var Data = new FormData(document.getElementById("Upload_Excel"));

            $.ajax({
                url:'StockAjax/UploadExcelFileAjax',
                data:Data,
                method:"POST",
                processData: false,
                contentType: false,
                dataType:"json",
                complete:function(v1,v2){
                    if(v2 == 'success'){
                        if(v1.responseJSON == true){
                            $("#UploadAlert").attr('class','alert alert-success').html(Submitted_Successfully)
                            setTimeout(function(){
                                $("#UploadAlert").addClass("hidden");
                            },2000);
                            $("#InputFile >input").val('')
                            $("#InputFile >.fa-check").hide()
                        }
                    }
                }
            })
        }else{
            $("#UploadAlert").attr('class','alert alert-danger').html("please upload excel file")
            setTimeout(function(){
                $("#UploadAlert").addClass("hidden")

            },2000)
        }
    })
    // ValidateFunction for file
    function ValidateForNewFile(input,inputID){
        var IsFileOK = false;
        $(inputID+" .fa-check").remove()
        if (input.files && input.files[0]){
            var reader = new FileReader();
            reader.onload = function () {
                $(inputID+" > .fa-times").hide()
                $(inputID).append(" <span class='fa fa-check'></span>")
            }
            reader.readAsDataURL(input.files[0]);
            return true;
        }
        return false;
    }

</script>