<style type="text/css">
    #editabledatatable_wrapper{
        width: 98%;
    }
    .table-scrollable {
        border: none;
    }
    .dataTables_filter input {
        display: none !important;
    }
    #searchtext, #fromdate, #todate {
        padding: 7px;
        -webkit-border-radius: 0 !important;
        -webkit-background-clip: padding-box !important;
        -moz-border-radius: 0 !important;
        -moz-background-clip: padding !important;
        border-radius: 0 !important;
        background-clip: padding-box !important;
        color: #858585;
        background-color: #fbfbfb;
        border: 1px solid #d5d5d5;
        font-family: inherit;
        -webkit-transition: -webkit-box-shadow .45s,border-color .45s ease-in-out;
        -moz-transition: -moz-box-shadow .45s,border-color .45s ease-in-out;
        -o-transition: box-shadow .45s,border-color .45s ease-in-out;
        transition: box-shadow .45s,border-color .45s ease-in-out;
        -webkit-box-shadow: none;
        -moz-box-shadow: none;
        box-shadow: none;
    }
    #fromdate, #todate {
        width: 105px;
    }
</style>
<!-- Page Content -->
<div class="page-content">
    <!-- Page Header -->
    <div class="page-header position-relative">
        <div class="header-title">
            <h1>
                <?php echo $this->lang->line("PURCHASE")." ".$this->lang->line("INVOICE"); ?>
            </h1>
        </div>
        <!--Header Buttons-->
        <div class="header-buttons">
            <a class="sidebar-toggler" href="#">
                <i class="fa fa-arrows-h"></i>
            </a>
            <a class="refresh" id="refresh-toggler" href="">
                <i class="glyphicon glyphicon-refresh"></i>
            </a>
            <a class="fullscreen" id="fullscreen-toggler" href="#">
                <i class="glyphicon glyphicon-fullscreen"></i>
            </a>
        </div>
        <!--Header Buttons End-->
    </div>
    <!-- /Page Header -->
    <!-- Page Body -->
    <div class="page-body">
        <div class="row">
            <div class="col-xs-12 col-md-12">
                <div class="widget">
                   
                    <div class="widget-body">
                        <div class="table-toolbar">
                            <div class="form-group">
                                <a class="btn btn-success shiny new" href="<?php echo base_url(); ?>inventory/purchaseinvoice/createnew/"
                                   class="btn btn-default">
                                    <i class="fa fa-plus"></i>
                                </a>
                                <a class="btn btn-danger shiny new" href="<?php echo base_url(); ?>inventory/purchaseinvoice/createnew/-1"
                                   class="btn btn-default">
                                    <i class="fa fa-minus"></i>
                                </a>
                                
                                <select class="dt-column_div" id="purchaseinvoicetype" name="purchaseinvoicetype" >
                                    <option value=""><?php echo $this->lang->line("SEARCHBYSTATUS"); ?></option>
                                    <option value="1"><?php echo $this->lang->line("CREATED"); ?></option>
                                    <option value="2"><?php echo $this->lang->line("SUBMITTED"); ?></option>
                                    <option value="-1"><?php echo $this->lang->line("RETURNED"); ?></option>
                                    <option value="-2"><?php echo $this->lang->line("RETURNSUBMITTED"); ?></option>
                                </select>
                                
                                <input type="text" name="searchtext" id="searchtext" placeholder="<?php echo $this->lang->line("SEARCH"); ?> ... " />
                                <span> <?php echo $this->lang->line("FROM"); ?> </span>
                                <span class="input-icon icon-right" style="width:108px;">
                                    <input type="text" id="fromdate" name="fromdate" class="datepickertxt"
                                        placeholder="<?php echo $this->lang->line("FROMDATE"); ?>" readonly 
                                        value="<?php echo date("d-m-Y", strtotime(date("d-m-Y", strtotime( date("d-m-Y") ) ) . "-1 month" ) ); ?>" />
                                    <i class="fa fa-calendar"></i>
                                </span>
                                <span> <?php echo $this->lang->line("TO"); ?> </span>
                                <span class="input-icon icon-right" style="width:108px;">
                                    <input type="text" id="todate" name="todate" class="datepickertxt"
                                           placeholder="<?php echo $this->lang->line("TODATE"); ?>" readonly value="<?php echo date("d-m-Y"); ?>" />
                                    <i class="fa fa-calendar"></i>
                                </span>
                            </div>
                            
                            <div id="confirmmodal" class="modal fade" role="dialog">
                                <div class="modal-dialog">
                                    <!-- Modal content-->
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <h4 class="modal-title"><?php echo $this->lang->line("AREYOUSURETODELETE"); ?></h4>
                                        </div>
                                        <div class="modal-footer">
                                            <input type="hidden" id="okid" value="">
                                            <button type="button" class="btn btn-success" onclick="return deleteFunction()"><?php echo $this->lang->line("OK"); ?></button>
                                            <button type="button" class="btn btn-danger" data-dismiss="modal"><?php echo $this->lang->line("CLOSE"); ?></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
<div class="table-responsive">
    <?php
    if ($this->session->flashdata('msg')!='') {
    ?>
        <div class="alert <?php if ($this->session->flashdata('msgt')=='S') { ?> alert-success 
            <?php } else if($this->session->flashdata('msgt')=='E') { ?> alert-danger <?php } ?>">
                <a href="#" class="close" data-dismiss="alert">&times;</a>
            <?php echo $this->session->flashdata('msg'); $this->session->unset_userdata('msg');?>
        </div>
    <?php
    }
    ?>
    <div id="myTable_processing" class="dataTables_processing" style="display: none;">Processing...</div>
    <table class="table table-striped table-hover table-bordered editable" id="purchaseinvoicedatatable">
        <thead>
            <tr role="row">
                <th style="width: 70px;">
                    <?php echo $this->lang->line("SLNO"); ?>
                </th>
                <th style="width: 100px;">
                    <?php echo $this->lang->line("INVOICEDATE"); ?>
                </th>
                <th style="width: 120px;">
                    <?php echo $this->lang->line("INVOICENO"); ?>
                </th>
                <th style="width: 300px;">
                    <?php echo $this->lang->line("VENDOR"); ?>
                </th>
                <th class="text-align-right" style="width: 100px;">
                    <?php echo $this->lang->line("TOTAL"); ?>
                </th>
                <th class="text-align-right" style="width: 100px;">
                    <?php echo $this->lang->line("PAID"); ?>
                </th>
                <th class="text-align-right" style="width: 100px;">
                    <?php echo $this->lang->line("BALANCE"); ?>
                </th>
                <th style="width: 50px;">
                    <?php echo $this->lang->line("STATUS"); ?>
                </th>
                <th style="width: 50px;">
                    <?php echo $this->lang->line("ACTION"); ?>
                </th>
                
            </tr>
        </thead>
    </table>
</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /Page Body -->
    </div>
    <!-- /Page Content -->
</div>
<!-- /Page Container -->
<!-- Main Container -->
</div>

<script src="<?= site_url() ?>assets/js/datetime/bootstrap-datepicker.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#purchaseinvoicedatatable').DataTable({
        "serverSide": true,
        "bProcessing": true,
        "aLengthMenu": [
            [50, 300, 1000],
            [50, 300, 1000]
        ],
        "sPaginationType": "bootstrap",
        "sDom": "Tflt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
        "tableTools": {
            "aButtons": ["copy"]
        },
        "ajax":{
            "url": "<?php echo base_url(); ?>inventory/purchaseinvoice/listpurchaseinvoice",
            "dataType": "json",
            "type": "POST",
            "data": function(d){
                d.purchaseinvoicetype = $('#purchaseinvoicetype').val();
                d.fromdate = $('#fromdate').val();
                d.todate = $('#todate').val();
                d.searchtext = $('#searchtext').val();
            }
        },
        "oLanguage": {
            "sEmptyTable":     "<?php echo $this->lang->line("NOTHINGFOUND"); ?>",
            "sInfo":           "<?php echo $this->lang->line("SHOWINGPAGE"); ?> _START_ <?php echo $this->lang->line("TO"); ?> _END_ <?php echo $this->lang->line("OF"); ?> _TOTAL_ <?php echo $this->lang->line("ENTRIES"); ?>",
            "sInfoEmpty":      "<?php echo $this->lang->line("SHOWINGPAGE"); ?> 0 <?php echo $this->lang->line("TO"); ?> 0 <?php echo $this->lang->line("OF"); ?> 0 <?php echo $this->lang->line("ENTRIES"); ?>",
            "sInfoPostFix":    "",
            "sInfoThousands":  ",",
            "sLengthMenu":     "<?php echo $this->lang->line("SHOW"); ?> _MENU_ <?php echo $this->lang->line("ENTRIES"); ?>",
            "sLoadingRecords": "<?php echo $this->lang->line("LOADING"); ?>",
            "sProcessing":     "<?php echo $this->lang->line("PROCESSING"); ?>",
            "sSearch":         "",
            "sZeroRecords":    "<?php echo $this->lang->line("NORECORDSAVAILABLE"); ?>",
            "oPaginate": {
                "sFirst":    "<?php echo $this->lang->line("FIRST"); ?>",
                "sLast":     "<?php echo $this->lang->line("LAST"); ?>",
                "sNext":     "<?php echo $this->lang->line("NEXT"); ?>",
                "sPrevious": "<?php echo $this->lang->line("PREVIOUS"); ?>"
            }
        },
        "columns": [
                { "data": "sl",
                  "bSortable": true},
              { "data": "DELIVERYDATE" ,
                  "bSortable": true},
                { "data": "REFERENCE",
                  "bSortable": true},
                { "data": "name",
                  "bSortable": true},
                { "data": "TOTALAMOUNT" ,
                  "bSortable": true},
                { "data": "PAIDAMOUNT",
                  "bSortable": true},
                { "data": "BALANCE",
                  "bSortable": true},
                { "data": "STATUS",
                  "bSortable": true},
                { "data": "ID",
                  "bSortable": true},
            ]	 
        });
        
        $('#purchaseinvoicetype').on( 'change', function (e) {
            table.draw();
        });
        
        $('#searchtext').on( 'keyup', function (e) {
            if(e.which == 13) {
                table.draw();
            }
        });
        
        $('.datepickertxt').datepicker().on('changeDate', function (ev) { 
            $('.datepicker').hide();
            table.draw();
        });
        
    });

    



    function confirmFunction(id) {
        $("#okid").val(id);
    }

    function deleteFunction() {
        id = $("#okid").val();
        $.ajax({
            url: base_url + 'inventory/purchaseinvoice/deletepurchaseinvoicecontroller/' + id,
            success: function (data) {
                location.reload(true);
                $("#confirmmodal").hide();
                $("#modal-success").show();

            }
        });
    }
    $("#fromdate").datepicker({format: 'dd-mm-yyyy', setDate: new Date()});
    $("#todate").datepicker({format: 'dd-mm-yyyy', setDate: new Date()});
    
    $(document).ajaxStop(function () {
        $('.dataTables_processing').hide();
    });

    $(document).ajaxStart(function () {
        $('.dataTables_processing').show();
    }); 
    
</script>

