<?php $this->load->view('theme/include/header'); ?>

<!--Start Main Content-->
<section>
<div class="main-content">
<div class="row">
<div class="inner-contatier">
<div class="col-md-12 col-lg-12 col-sm-12 content-title"><h4>Send Money</h4></div>
<div class="col-md-10 col-lg-10 col-sm-10">

<?php
$message = $this->session->userdata('success');
if ($message) {
?>
<!-- Alert Box -->
<div class="alert my-alert alert-success">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>Success! </strong><?php echo $message; ?>
</div>
<?php
} else {
$message = $this->session->userdata('error');
if ($message) {
    ?>
    <!-- Alert Box -->
    <div class="alert my-alert alert-danger">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <strong>Alert! </strong><?php echo $message; ?>
    </div>
    <?php
}
}
if (validation_errors()) {
?>
<!-- Alert Box //validation error -->
<div class="alert my-alert alert-danger">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <?php echo validation_errors('<i class="fa fa-times"> ', '</i></br>'); ?>
</div>
<?php } ?>

<!--Start Panel-->
<div class="panel panel-default" style="margin-bottom:100px;">
<!-- Default panel contents -->
<div class="panel-heading">Send Money</div>
<div class="panel-body add-client">
    <form action="<?php echo site_url('Transfer/save') ?>" method="post">

        <div class="col-sm-6">
            <div class="form-group">
                <label for="sending_type">Sending Type</label>
                <select name="sending_type" id="sending_type" class="form-control" required>
                    <option value="">Select Sending Type</option>
                    <option value="individual" <?php if(set_value("sending_type")=="individual") echo 'selected="selected"' ?>>Individual</option>
                    <option value="organisation" <?php if(set_value("sending_type")=="organisation") echo 'selected="selected"' ?>>Organisation</option>
                </select>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="sending_code">Sending Code</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sending_code"); ?>" name="sending_code"
                       id="sending_code" required>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="sending_date">Sending Date</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sending_date"); ?>" name="sending_date"
                       id="sending_date" required>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="sender_fullname">Sender Fullname/NGO Name</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sender_fullname"); ?>"
                       name="sender_fullname" id="sender_fullname" required>
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="sender_city">Sender City</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sender_city"); ?>" name="sender_city"
                       id="sender_city">
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="sender_passport">Sender Passport/CNI</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sender_passport"); ?>"
                       name="sender_passport" id="sender_passport">
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="passport_exp_date">Passport Exp Date</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("passport_exp_date"); ?>"
                       name="passport_exp_date" id="passport_exp_date">
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="sending_amount">Sending Amount</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("sending_amount"); ?>" name="sending_amount"
                       id="sending_amount" required>
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="cost">Cost</label>
                <input type="text" class="form-control" value="<?php echo set_value("cost"); ?>"
                       name="cost" id="cost" readonly="true" required>
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="total_amount">Total Amount</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("total_amount"); ?>" name="total_amount"
                       id="total_amount" readonly="true" required>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="telephone">Telephone</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("telephone"); ?>" name="telephone"
                       id="telephone" required>
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="secret_question">Secret Question</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("secret_question"); ?>"
                       name="secret_question" id="secret_question">
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="secret_answer">Secret Answer</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("secret_answer"); ?>" name="secret_answer"
                       id="secret_answer">
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="recipent_fullname">Recipent Fullname</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("recipent_fullname"); ?>"
                       name="recipent_fullname" id="recipent_fullname" required>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="recipent_phone">Recipent Phone</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("recipent_phone"); ?>" name="recipent_phone"
                       id="recipent_phone" required>
            </div>
        </div>
        <div class="col-sm-6 individual-class">
            <div class="form-group">
                <label for="recipent_city">Recipent City</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("recipent_city"); ?>" name="recipent_city"
                       id="recipent_city">
            </div>
        </div>
		
		<div class="col-sm-6">
            <div class="form-group">
                <label for="recipent_city">Recipent CNI</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("recipent_CNI"); ?>" name="recipent_CNI"
                       id="recipent_CNI" required>
            </div>
        </div>
		
        <div class="col-sm-6 organisation-class">
            <div class="form-group">
                <label for="org_address">Org Address</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("org_address"); ?>" name="org_address"
                       id="org_address">
            </div>
        </div>
        <div class="col-sm-6 organisation-class">
            <div class="form-group">
                <label for="distribution_number">Distribution Number</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("distribution_number"); ?>"
                       name="distribution_number" id="distribution_number">
            </div>
        </div>
        <div class="col-sm-6 organisation-class">
            <div class="form-group">
                <label for="name_of_project">Name Of Project</label>
                <input type="text" class="form-control"
                       value="<?php echo set_value("name_of_project"); ?>"
                       name="name_of_project" id="name_of_project">
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="agent_id">Agent</label>
                <select name="agent_id" class="form-control" required> 
                    <option value="<?php echo $this->session->userdata('id') ?>"><?php echo $this->session->userdata('username') ?></option>
                </select>
            </div>
        </div>

        <div class="col-sm-12">
            <button type="submit" class="mybtn btn-submit"><i class="fa fa-check"></i> Process Transfer
            </button>
        </div>

    </form>
</div>
<!--End Panel Body-->
</div>
<!--End Panel-->
</div>


</div><!--End Inner container--->
</div><!--End Row-->
</div><!--End Main-content DIV-->
</section><!--End Main-content Section-->

<?php $this->load->view('theme/include/footer'); ?>

<script type="text/javascript">
$(document).ready(function () {

    $("#passport_exp_date,#sending_date").datepicker();
	
    	
    if($("#sending_type").val()=="organisation"){
	   $(".organisation-class").fadeIn();
       $(".individual-class").css("display","none");
	}else if($("#sending_type").val()=="individual"){
	   $(".organisation-class").css("display","none");
	}

    $("#sending_type").change(function(){
       if($(this).val()=="organisation"){
           $(".organisation-class").fadeIn();
           $(".individual-class").fadeOut();
		   $("#sending_code").val("");
		   $("#sending_code").attr('readOnly', false);
       }else if($(this).val()=="individual"){
           $(".individual-class").fadeIn();
           $(".organisation-class").fadeOut();
		   var d = new Date();
		   y=d.getFullYear().toString().substr(2, 2);
		   m = ("0" + (d.getMonth() + 1)).slice(-2)+1;
		   r=Math.floor((Math.random() * 100000) + 1);
		   $("#sending_code").val(y+""+m+""+r);
		   $('#sending_code').prop('readOnly', true);
       }

    });

    //amount
    $('#sending_amount,#cost,#total_amount').keypress(function(event) {
        if ((event.which != 46 || $(this).val().indexOf('.') != -1) &&
            (event.which < 48 || event.which > 57)) { event.preventDefault();
        }
    });
	
	$("#sending_amount").keyup(function(){
	    if($("#sending_type").val()!="organisation"){
			 if($(this).val()!=""){
			 $.ajax({method:"POST",url:"<?php echo site_url('Transfer/calculate_fee') ?>/"+$(this).val(),success:function(data){
			 $("#cost").val(data);
			 $("#total_amount").val(parseFloat(data)+parseFloat($("#sending_amount").val()));
			 }});
			 }else{
			 $("#cost").val("0");
			 $("#total_amount").val("0");
			 }
	      }else{
		     $("#cost").val("0");
		     $("#total_amount").val($("#sending_amount").val());
		}	 
	});


});

</script>
</body>

</html>
