<div class="row align-items-center">
    <div class="col-sm-6">
        <div class="page-title-box">
            <h4 class="font-size-18">Donation List</h4>
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item"><a href="javascript: void(0);">Donation</a></li>
                <li class="breadcrumb-item active"> Donation List</li>
            </ol>
        </div>
    </div>   
    <div class="col-sm-6">
        <div class="float-right d-none d-md-block">
            <a class="btn btn-primary waves-effect waves-light" href="<?php echo base_url(); ?>DonationController">
                <i class="mdi mdi-plus mr-2"></i> Donation
            </a>
        </div>
    </div>
</div>

<?php
if ($this->session->flashdata('alert_success')) {
    ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_success'); ?>
</div>
<?php
}

if ($this->session->flashdata('alert_danger')) {
    ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_danger'); ?>
</div>
<?php
}

if ($this->session->flashdata('alert_warning')) {
    ?>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
    <strong>Success!</strong> <?php echo $this->session->flashdata('alert_warning'); ?>
</div>
<?php
}
if (validation_errors()) {
    ?>
<!-- <div class="alert alert-danger alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php echo validation_errors(); ?>
</div> -->
<?php
}
?>


<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                 <!-- <button type="button" class="btn btn-info btn-sm" id="excel" onclick="exportReportToExcel(this)">Export to Excel</button>  -->
                <table id="dmstable" class="table table-striped table-bordered dt-responsive nowrap"
                style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                <thead>
                    <tr>
                        <th>S.No</th>
                        <th>Rept No</th>                      
                        <th>Name</th>
                        <th>Mobile</th>
                        <th>Amount</th>
                        <th>Donation Type</th>
                        <th>Month</th>
                        <th>Mail</th>
                        <th>Print</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(isset($donation)){ 
                        $i=1;
                        foreach($donation as $row){  
                    ?>
                        <tr>
                            <td><?= $i ?></td>
                            <td><?= $row->receipt_no ?></td>
                            <td><?= $row->first_name.' '.$row->last_name ?></td>
                            <td><?= $row->mobile_no ?></td>
                            <td><?= $row->donation_amount ?></td>
                            <td><?= $row->donation_type ?></td>
                            <td><?= date("F", mktime(0, 0, 0, $row->receipt_month, 10)) ?></td>                           
                            <td><a  href="javascript:sendMail('<?= $row->donation_id ?>')" class="btn btn-primary"><i class="fa fa-envelope" aria-hidden="true"></i></a></td>
                            <td><a href="javascript:deleteYear('<?= $row->id ?>')" class="btn btn-danger"><i class="fa fa-print"></i></a></td>
                        </tr>
                    <?php  $i++; } }?>
                    
                </tbody>
        </table>
        <?php
       // if (empty($result)) {?>
            <!-- <tr>
                <h4 style="text-align:center;">NO RESULT FOUND</h4>
            </tr> -->
        <?php // }
        ?>
    </div>
</div>
</div>
</div>


<script>

function sendMail(id){
    $.ajax({
        url: "<?php echo site_url() ?>/DonationController/sendMailPDF/"+id,
        method: "GET",          
        success: function(result) {
           if(result == 1){
            alert("Mail send Success");
           }
        },
        error: function(error) {
            console.log(error);
        }
    });
}

function editYear(id){
    $.ajax({
        url: "<?php echo site_url() ?>/settingsController/getYearData/"+id,
        method: "GET",          
        success: function(result) {
            var data = JSON.parse(result);             
            if(data.length > 0){
                $('#year_id').val(data[0].id);
                $('#statuss').select2("val",data[0].status);
                $('#year').val(data[0].year);
                $('#Title').text("Edit Financial year");
                document.documentElement.scrollTop = 0;
            }
            
            
        },
        error: function(error) {
            console.log(error);
        }
    });
}

function deleteYear(id){
    if(confirm("If you want to delete?")===true){
    $.ajax({
        url: "<?php echo site_url() ?>/settingsController/deleteYear/"+id,
        method: "GET",          
        success: function(result) {
            if(result > 0){
                window.location.reload();
            }
        },
        error: function(error) {
            console.log(error);
        }
    });
}
}

    $('#dmstable').DataTable();
function get_region(zone_id) {
    $.ajax({
        url: "<?php echo site_url() ?>/users/manage_dealers/get_region",
        method: "POST",
        type: "ajax",
        data: {
            zone_id: zone_id
        },
        success: function(result) {
            var data = JSON.parse(result);
            $('#region')
                .find('option')
                .remove();
            $.each(data, function(key, value) {
                var option = '<option value="' + value.region_id + '">' + value.region_name +
                    '</option>';
                $('#region').append(option);
            });
        },
        error: function(error) {
            console.log(error);
        }
    });
}
</script>