<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<style>
.row_spc {
    margin: 20px !important;
}
</style>
<div class="row align-items-center">
    <div class="col-sm-6">
        <div class="page-title-box">
            <h4 class="font-size-18">Donation</h4>
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item"><a href="javascript: void(0);">Donation</a></li>
                <li class="breadcrumb-item active">Add</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/donationList/">
                <i class="mdi mdi-plus mr-2"></i> View 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>ERROR!</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-lg-12">
        <div class="card">
            <div class="card-body">
                <form action="<?php echo base_url();?>DonationController/addDonation" method="post" enctype="multipart/form-data">
                    <div class="row row_spc">
                        <div class="col-md-3">
                            <label class="required">User</label> <br>
                            <input type="radio" name="userCheck" value="1" onclick="get_type(this.value)"> New
                            <input type="radio" name="userCheck" value="0" onclick="get_type(this.value)"> Existing
                        </div>
                        <div class="col-md-3">
                            <label class="required">Receipt No</label>
                            <input name="receipt_no" required id="receipt_no" type="text" class="form-control"
                                placeholder="Enter Receipt No" value="" autofocus>
                        </div>
                        <div class="col-md-3">
                            <label class="required">Receipt Month</label>
                            <select name="receipt_month" required id="receipt_month" class="form-control">
                                <option>-- Select --</option>
                                <?php for($i=1;$i<=12;$i++){ ?>
                                <option value="<?= $i ?>"><?= date("F", mktime(0, 0, 0, $i, 10));?></option>    
                                <?php } ?>
                            </select>                           
                        </div>
                        <div class="col-md-3">
                            <label class="required">Financial Year</label>
                            <input name="financial_year" id="financial_year" type="text" class="form-control"
                                placeholder=""
                                value="<?php echo (isset($year))? $year:''; ?>">
                        </div>
                    </div>
                    <div class="row row_spc" id="userDiv" >
                        <div class="col-md-6">
                            <label>Select Users</label>
                            <select name="user_id" class="form-control">
                                <option>-- select --</option>
                                 <?php if(isset($users)){ foreach($users as $row) { ?> 
                                        <option value="<?php echo $row->user_id ?>"><?php echo $row->first_name ?></option>
                                 <?php  } } ?>
                               
                            </select>

                        </div>
                    </div>
                    <div class="row row_spc">
                        <div class="col-md-3">
                            <label class="required">First Name</label>
                            <input name="first_name" required id="first_name" type="text" class="form-control"
                                placeholder="Enter First Name"
                                value="<?php echo (isset($_POST['f_name']))?$_POST['f_name']:''; ?>" autofocus>
                        </div>
                        <div class="col-md-3">
                            <label class="required">Last Name</label>
                            <input name="last_name" required id="last_name" type="text" class="form-control"
                                placeholder="Enter Last Name"
                                value="<?php echo (isset($_POST['f_name']))?$_POST['f_name']:''; ?>" autofocus>
                        </div>
                        <div class="col-md-3">
                            <label class="required">Email</label>
                            <input name="email" required id="email" type="email" class="form-control" placeholder="Enter Email"
                                value="<?php echo (isset($_POST['doj']))?$_POST['doj']:''; ?>">
                        </div>
                        <div class="col-md-3">
                            <label class="required">Mobile Number</label>
                            <input name="mobile_no" required id="mobile_no" type="text" class="form-control"
                                placeholder="Enter Mobile Number" onkeyup="check();"
                                value="<?php echo (isset($_POST['mobile_no']))?$_POST['mobile_no']:''; ?>">
                            <span id="message"></span>
                        </div>
                    </div>
                    <div class="row row_spc">
                        <div class="col-md-3">
                            <label>Address</label>
                            <textarea name="address"  id="address" class="form-control"
                                placeholder="Enter Address"></textarea>
                        </div>
                        <div class="col-md-3">
                            <label class="required">PAN Number</label>
                            <input name="pan_number"  required id="pan_number" type="text" class="form-control"
                                placeholder="Enter PAN Number"
                                value="<?php echo (isset($_POST['ac_name']))?$_POST['ac_name']:''; ?>">
                        </div>
                        <div class="col-md-3">
                            <label class="required">Donation Type</label>
                            <select name="donation_type" required class="form-control">
                                <option>-- select --</option>
                                <option value="1">Monthly</option>
                                <option value="2">One Time</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="required">Donation Amount</label>
                            <input name="donation_amount" required id="donation_amount" type="text" class="form-control"
                                placeholder="Enter Amount" value="">
                        </div>
                    </div>
                    <div class="row row_spc">
                        <div class="col-md-3">
                            <label class="required">Mode of Payment</label>
                            <select name="payment_mode" required class="form-control">
                                <option>-- select --</option>
                                <option value="1">Cash</option>
                                <option value="2">Cheque</option>
                                <option value="3">Online</option>
                                <option value="4">NEFT</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label>Trans/Cheque Number</label>
                            <input name="transaction_no" id="transaction_no" type="text" class="form-control"
                                placeholder="Transaction No">
                        </div>
                        <div class="col-md-3">
                            <label class="required">Transaction/Cheque Date</label>
                            <input name="transaction_date" id="transaction_date" type="date" class="form-control"                                
                                value="<?php echo (isset($_POST['no_holiday']))?$_POST['no_holiday']:''; ?>">
                        </div>
                        <div class="col-md-3">
                            <label class="required">Bank & Branch Name</label>
                            <input name="branch_name" id="branch_name" type="text" class="form-control"
                                placeholder="Enter Branch" onkeyup="check();"
                                value="<?php echo (isset($_POST['mobile_no']))?$_POST['mobile_no']:''; ?>">
                            <span id="message"></span>
                        </div>
                    </div>
            </div>
        </div>
        <div class="form-group mb-0">
            <div>
                <button name="submit" type="submit" class="btn btn-primary waves-effect waves-light mr-1">
                    Submit
                </button>
                <a href="<?php echo base_url(); ?>users/employee" class="btn btn-secondary waves-effect">Cancel </a>
            </div>
        </div>
        </form>
    </div>
</div>
</div>
</div>
<style type="text/css">
.required:after {
    content: " *" !important;
    color: red !important;
}
</style>
<script type="text/javascript">
$('#work').change(function() {
    if ($('#work').val() == '1') {
        $('.experience').show();
    } else {
        $('.experience').hide();
    }
}).change();

setTimeout(() => {
    $('#userDiv').hide();
}, 1000);
function get_type(val){
    if(val==1){
        $('#userDiv').hide();
    }else{
        $('#userDiv').show();
    }
}


function check() {

    var mobile = document.getElementById('mobile_no');


    var message = document.getElementById('message');

    var goodColor = "#0C6";
    var badColor = "#FF9B37";

    if (mobile.value.length != 10) {
        mobile.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "required 10 digits, match requested format!"
    } else {
        mobile.style.backgroundColor = goodColor;
        message.style.color = goodColor;
        message.innerHTML = ""
    }
}
</script>
<script>
$('#emp_status').select2();
</script>