<?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>Payment</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">Payment</div>
<div class="panel-body add-client">
    <form action="<?php echo site_url('Payment/process_payment') ?>" method="post">

        <div class="col-sm-6">
            <div class="form-group">
                <label for="sending_type">Payment Type</label>
                <select name="payment_type" id="payment_type" class="form-control" required>
                    <option value="">Select Payment Type</option>
                    <option value="individual" <?php if(set_value("payment_type")=="individual") echo 'selected="selected"' ?>>Individual</option>
                    <option value="organisation" <?php if(set_value("payment_type")=="organisation") echo 'selected="selected"' ?>>Organisation</option>
                </select>
            </div>
        </div>
		<div class="col-md-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-md-6">
		<div class="form-group">
		<label for="date_of_sending">Date Of Sending</label>
		<input type="text" class="form-control" value="<?php echo set_value("date_of_sending"); ?>" name="date_of_sending" id="date_of_sending" required>
		</div></div>
	<div class="col-md-6">
		<div class="form-group">
		<label for="sender_fullname">Sender Fullname</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-md-6 individual-class">
		<div class="form-group">
		<label for="shipping_city">Shipping City</label>
		<input type="text" class="form-control" value="<?php echo set_value("shipping_city"); ?>" name="shipping_city" id="shipping_city">
		</div></div>
	<div class="col-md-6 individual-class">
		<div class="form-group">
		<label for="sender_phone">Sender Phone</label>
		<input type="text" class="form-control" value="<?php echo set_value("sender_phone"); ?>" name="sender_phone" id="sender_phone">
		</div></div>
	<div class="col-md-6">
		<div class="form-group">
		<label for="payable_amount">Payable Amount</label>
		<input type="text" class="form-control" value="<?php echo set_value("payable_amount"); ?>" name="payable_amount" id="payable_amount" required>
		</div></div>
	<div class="col-md-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-md-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-md-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-md-6 individual-class">
		<div class="form-group">
		<label for="recipent_passport">Recipent Passport</label>
		<input type="text" class="form-control" value="<?php echo set_value("recipent_passport"); ?>" name="recipent_passport" id="recipent_passport">
		</div></div>
	<div class="col-md-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-md-6 individual-class">
		<div class="form-group">
		<label for="payment_city">Payment City</label>
		<input type="text" class="form-control" value="<?php echo set_value("payment_city"); ?>" name="payment_city" id="payment_city">
		</div></div>
	<div class="col-md-6">
		<div class="form-group">
		<label for="Recipient_CNI">Recipient CNI</label>
		<input type="text" class="form-control" value="<?php echo set_value("Recipient_CNI"); ?>" name="Recipient_CNI" id="Recipient_CNI">
		</div></div>
	<div class="col-md-6 organisation-class">
		<div class="form-group">
		<label for="Recipient_Phone">Recipient Phone</label>
		<input type="text" class="form-control" value="<?php echo set_value("Recipient_Phone"); ?>" name="Recipient_Phone" id="Recipient_Phone">
		</div></div>
	<div class="col-md-6 organisation-class">
		<div class="form-group">
		<label for="Recipient_address">Recipient Address</label>
		<input type="text" class="form-control" value="<?php echo set_value("Recipient_address"); ?>" name="Recipient_address" id="Recipient_address">
		</div></div>
	<div class="col-md-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-md-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-md-6">
		<div class="form-group">
		<label for="paying_date">Paying Date</label>
		<input type="text" required class="form-control" value="<?php echo set_value("paying_date"); ?>" name="paying_date" id="paying_date">
		</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,#paying_date").datepicker();
	$("#sending_code").prop('readOnly', true);
	
	  $("#date_of_sending").prop('readOnly', true);
	  $("#sender_fullname").prop('readOnly', true);
	  $("#sender_phone").prop('readOnly', true);
	  $("#payable_amount").prop('readOnly', true);
	  $("#secret_question").prop('readOnly', true);
	  $("#secret_answer").prop('readOnly', true);
	  $("#recipent_fullname").prop('readOnly', true);
	  $("#Recipient_Phone").prop('readOnly', true);
	  $("#Recipient_CNI").prop('readOnly', true);
	  $("#Distribution_Number").prop('readOnly', true);
	  $("#Name_of_project").prop('readOnly', true);

    if($("#payment_type").val()=="organisation"){
	   $(".organisation-class").fadeIn();
       $(".individual-class").fadeOut();
	}else if($("#payment_type").val()=="individual"){
	   $(".organisation-class").fadeOut();
	}
	
	    $("#payment_type").change(function(){
       if($(this).val()=="organisation"){
           $(".organisation-class").fadeIn();
           $(".individual-class").fadeOut();
		   $("#sending_code").attr('readOnly', false);
       }else if($(this).val()=="individual"){
           $(".individual-class").fadeIn();
           $(".organisation-class").fadeOut();
		   $('#sending_code').attr('readOnly', false);
       }

    });

	$("#sending_code").keyup(function(){
      if($(this).val()!=""){
		 $.ajax({method:"POST",
		 url:"<?php echo site_url('payment/varify_payment') ?>/"+$(this).val()+"/"+$("#payment_type").val(),
		 success:function(data){
		 
		  if(data!="null"){
		  var json = JSON.parse(data);
          $("#date_of_sending").val(json['sending_date']).prop('readOnly', true);
		  $("#sender_fullname").val(json['sender_fullname']).prop('readOnly', true);
		  $("#sender_phone").val(json['telephone']).prop('readOnly', true);
		  $("#payable_amount").val(json['sending_amount']).prop('readOnly', true);
		  $("#secret_question").val(json['secret_question']).prop('readOnly', true);
		  $("#secret_answer").val(json['secret_answer']).prop('readOnly', true);
		  $("#recipent_fullname").val(json['recipent_fullname']).prop('readOnly', true);
	      $("#Recipient_Phone").val(json['recipent_phone']).prop('readOnly', true);
		  $("#Recipient_CNI").val(json['recipent_CNI']).prop('readOnly', true);	  
		  $("#Distribution_Number").val(json['distribution_number']).prop('readOnly', true);
		  $("#Name_of_project").val(json['name_of_project']).prop('readOnly', true);
		  }else{
		  $("#date_of_sending").val("").prop('readOnly', true);
		  $("#sender_fullname").val("").prop('readOnly', true);
		  $("#sender_phone").val("").prop('readOnly', true);
		  $("#payable_amount").val("").prop('readOnly', true);
		  $("#secret_question").val("").prop('readOnly', true);
		  $("#secret_answer").val("").prop('readOnly', true);
		  $("#recipent_fullname").val("").prop('readOnly', true);
	      $("#Recipient_Phone").val("").prop('readOnly', true);
		  $("#Recipient_CNI").val("").prop('readOnly', true);
		  $("#Distribution_Number").val("").prop('readOnly', true);
		  $("#Name_of_project").val("").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_code").keypress(function (e) {
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
      return false;
    }
   });*/
	


});

</script>
</body>

</html>
