<!DOCTYPE html>
<html lang="en">
<head>
	
	<!-- header -->
		<?php $this->load->view('admin/common_header'); ?>
	<!-- /header -->

	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/uploaders/fileinput.min.js"></script>
	
	<!-- Bootsrap form validation JS files -->
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/formValidation.js"></script>
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/bootstrap.js"></script>
	

	<!-- Theme JS files -->
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/core/app.js"></script>
	<!-- /theme JS files -->

	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url();?>/assets/boots/js/fileinput.min.js"></script>
	
	<!-- bootsrap switch checkbox JS files -->
    <script src="<?php echo base_url();?>/assets/boots/js/bootstrap-switch.js"></script>

    <!-- notify JS files -->
    <script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/notifications/jgrowl.min.js"></script>
    <style>
		.kv-file-content img.file-preview-image {
	    	width: 150px !important;
	    }
	</style>
   
</head>

<body class="navbar-top-md-md">
	<!-- <div class="pre_loader"></div> -->
	<!-- Fixed navbars wrapper -->
	<div class="navbar-fixed-top">

		<!-- Main navbar -->
		<?php $this->load->view('admin/mainnav'); ?>
		<!-- /main navbar -->


		<!-- Second navbar -->
		<?php $this->load->view('admin/secondnav'); ?>
		<!-- /second navbar -->

	</div>
	<!-- /fixed navbars wrapper -->


	<!-- Page header -->
	<div class="page-header">
		<div class="page-header-content">
			<div class="page-title">
				<h4><i id="icon-bck" class="icon-arrow-left52 position-left"></i> <span class="text-semibold"><?php echo $this->lang->line('lbl_lending_title'); ?></span></h4>

				<ul class="breadcrumb breadcrumb-caret position-right">
					<?php foreach ($breadcrumbs as $breadcrumb) { if(isset($breadcrumb['href'])){?>
					    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
					<?php } else { ?> <li><?php echo $breadcrumb['text']; ?></li><?php } } ?>
				</ul>
			</div>
			<?php $this->load->view('admin/user_header'); ?>
			
		</div>
	</div>
	<!-- /page header -->


	<!-- Page container -->
	<div class="page-container">

		<!-- Page content -->
		<div class="page-content">

			<!-- Main content -->
			<div class="content-wrapper">

				<!-- Horizontal form -->
				<div class="panel panel-flat">
					<div class="panel-heading">
						<h5 class="panel-title">
						<?php 
							if(isset($this->data['gateway_name'])) { 
								$gate_name = $this->data['gateway_name'];
								echo $this->lang->line($gate_name.'_gateway');
							}
							else
							{
								echo $this->lang->line('lbl_lending_title');
							}
						?>
						</h5>
						<div class="heading-elements">
							<ul class="icons-list">
		                		<li><a data-action="collapse"></a></li>
		                		<li><a data-action="close"></a></li>
		                	</ul>
	                	</div>
                	</div>

                	<?php $currency_info = defaultcurrency();?>
					<div class="panel-body">
						<div class="row">
							<div class="col-md-10">

								<form class="form-horizontal paymentsetting" name="lending" action="<?php echo $action;?>" method="post" enctype="multipart/form-data">
									<div>
										<?php 
											if(validation_errors()) { 
												$form_err_data = str_replace('<p>', '', validation_errors());
												$form_err_data = str_replace('</p>', '', $form_err_data);
												$form_err_data = str_replace('.', '', $form_err_data);
										?>
												
												<script type="text/javascript">
												
												(function( $ ) {
													$.jGrowl.defaults.closer = false;
											        var from_daa = '<?php $form_err_data;?>';
													$.jGrowl(from_daa, {
											            header: '<?php echo $this->lang->line("error");?>',
											            theme: 'bg-danger'
											        });
											    
												})(jQuery);


												</script>
										<?php
											}
										?>
									</div>
									<?php
									if(isset($this->data['lending']))
									{
										$lending=$this->data['lending'];
										
										$this->load->library('MyEncrypt');
										$myencrypt = new MyEncrypt;
									

										$minimum_amount=$lending[0]->minimum_amount;
										$maximum_amount=$lending[0]->maximum_amount;
										$profit=$lending[0]->profit;
										$days=$lending[0]->duration;
										$lend_id=$lending[0]->lendingid;
										$payment_id = $myencrypt->encode($lend_id);
										$balance=$lending[0]->balance_sys;

									}
									else
									{
										$this->load->library('MyEncrypt');
										$myencrypt = new MyEncrypt;

										$minimum_amount="";
										$maximum_amount="";
										$profit="";
										$days="";
										$lend_id="";
										$payment_id ="";
										$balance="";

									}

									?>
									<input type="hidden" name="payment_id" id="payment_id" value="<?php echo $payment_id; ?>"/>
									
									<div class="form-group  has-feedback <?php if(form_error('minimum_amount')) echo "has-error";?>">
										<label class="control-label col-lg-3 text-semibold"><?php echo $this->lang->line('lbl_lending_min'); ?> <span class="text-danger">*</span></label>
										<div class="col-lg-4">
											<div class="input-group">
											    <span class="input-group-addon" style="font-size: 18px;"><strong><?php echo $currency_info->currency_symbol;?></strong></span>										
													<input type="text" name="minimum_amount" onkeyup="numchk(this)" id="minimum_amount" class="form-control" placeholder="<?php echo $this->lang->line('place_deposit_amount'); ?>" value="<?php echo $minimum_amount;?>">
											</div>
											<?php echo form_error('minimum_amount', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>	
										</div>
										
									</div>
									<div class="form-group">
									<div class="col-lg-3">
									</div>
									<div class="col-lg-6">
										<div  id="min_err" name="min_err" style="color:red;"></div>	
										</div>
									</div>

									<div class="form-group  has-feedback <?php if(form_error('maximum_amount')) echo "has-error";?>">
										<label class="control-label col-lg-3 text-semibold"><?php echo $this->lang->line('lbl_lending_max'); ?> <span class="text-danger">*</span></label>
										<div class="col-lg-4">
											<div class="input-group">
											    <span class="input-group-addon" style="font-size: 18px;"><strong><?php echo $currency_info->currency_symbol;?></strong></span>										
													<input type="text" name="maximum_amount" onkeyup="numchk(this)" id="maximum_amount" class="form-control" placeholder="<?php echo $this->lang->line('place_deposit_amount'); ?>" value="<?php echo $maximum_amount;?>">
											</div>

											<?php echo form_error('maximum_amount', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>	
											
										</div>

									</div>
									
									<div class="form-group">
									<div class="col-lg-3">
									</div>
									<div class="col-lg-6">
										<div  id="max_err" name="max_err" style="color:red;"></div>	
										</div>
									</div>


									<div class="form-group  has-feedback <?php if(form_error('balance')) echo "has-error";?>">
										<label class="control-label col-lg-3 text-semibold"><?php echo $this->lang->line('lbl_lending_bal'); ?> (%)<span class="text-danger">*</span></label>
										<div class="col-lg-4">
											<input type="text" name="balance" id="balance" onkeyup="numchk(this)" class="form-control" placeholder="<?php echo $this->lang->line('place_deposit_amount'); ?>" value="<?php echo $balance;?>">
											<?php echo form_error('balance', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>	
							            </div>
							            
										
									</div>
									<div class="form-group">
									<div class="col-lg-3">
									</div>
									<div class="col-lg-6">
										<div  id="bal_err" name="bal_err" style="color:red;"></div>	
										</div>
									</div>

								

									<div class="form-group  has-feedback <?php if(form_error('profit')) echo "has-error";?>">
										<label class="control-label col-lg-3 text-semibold"><?php echo $this->lang->line('lbl_lending_profit'); ?> (%)<span class="text-danger">*</span></label>
										<div class="col-lg-4">
											<input type="text" name="profit" id="profit" onkeyup="numchk(this)" class="form-control" placeholder="<?php echo $this->lang->line('place_deposit_amount'); ?>" value="<?php echo $profit;?>">
							            	<?php echo form_error('profit', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>	

							            </div>
										
									</div>
									<div class="form-group">
									<div class="col-lg-3">
									</div>
									<div class="col-lg-6">
										<div  id="profit_err" name="profit_err" style="color:red;"></div>	
										</div>
									</div>
									<div class="form-group  has-feedback <?php if(form_error('days')) echo "has-error";?>">
										<label class="control-label col-lg-3 text-semibold"><?php echo $this->lang->line('lbl_lending_captial'); ?> <span class="text-danger">*</span></label>
										<div class="col-lg-4">
											   	<input type="text" name="days" id="days" onkeyup="numchk(this)" class="form-control" placeholder="<?php echo $this->lang->line('place_deposit_amount'); ?>" value="<?php echo $days;?>">
										<?php echo form_error('days', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>	
							            </div>
							            
									</div>

									<div class="form-group">
									<div class="col-lg-3">
									</div>
									<div class="col-lg-6">
										<div  id="day_err" name="day_err" style="color:red;"></div>	
										</div>
									</div>

									

									
									<div class="text-right col-lg-6">
										<button type="submit" id="submit" name="submit" class="btn btn-primary"><?php echo $this->lang->line('button_update');  ?> <i class="icon-arrow-right14 position-right"></i></button>
									</div>
								</form>

							</div>
							
						</div>
					</div>
				</div>
				<!-- /horizotal form -->

			</div>
			<!-- /main content -->

		</div>
		<!-- /page content -->
		

		<!-- Footer -->
		<div class="footer text-muted">
			<?php echo site_footer();?>
		</div>
		<!-- /footer -->

	</div>
	<!-- /page container -->

	<script type="text/javascript">
		jQuery.noConflict();
		(function( $ ) {
		$(function() {

			$(document).ready(function() {
				
				$.jGrowl.defaults.closer = false;

				<?php if($this->session->flashdata('error_message')) { ?>
					$.jGrowl("<?php echo $this->session->flashdata('error_message');?>", {
			            header: '<?php echo $this->lang->line("error");?>',
			            theme: 'bg-danger'
			        });
	            <?php } ?>
	                    
	            <?php if($this->session->flashdata('success_message')) { ?>
	                $.jGrowl("<?php echo $this->session->flashdata('success_message');?>", {
			            header: '<?php echo $this->lang->line("success");?>',
			            theme: 'bg-success'
			        });
	            <?php } ?>
				});

			
		    
		 	$('#icon-bck').on('click',function() {
				window.history.back();
			});

			$('#submit').on('click',function() {
				
				$flag1=0;
				$flag2=0;
				var min_amt=$("#minimum_amount").val();
				var days=$("#days").val();
				var max_amt=$("#maximum_amount").val();
				var profit=$("#profit").val();
				var payment_id=$("#payment_id").val();
				var balance=$("#balance").val();

				if(min_amt=="")
               {
                  $flag=1;
                  $("#min_err").html('Please Enter Minimum Amount');
               }
               if(balance=="")
               {
                  $flag=1;
                  $("#bal_err").html('Please Enter Balance Percentage');
               }

               if(max_amt=="")
               {
                  $flag=1;
                  $("#max_err").html('Please Enter Maximum Amount');
               }

            	if(min_amt!='')
               {
               		var mq =/^[0-9.]+$/;
					if(!mq.test(min_amt))
               		{
               			$flag=1;
               			$("#min_err").html('Invalid Amount format');
               		}
               		else
               			$flag1=1;


               }
               if(max_amt!='')
               {
               		var mq =/^[0-9.]+$/;
					if(!mq.test(max_amt))
               		{
               			$flag=1;
               			$("#max_err").html('Invalid Amount format');
               		}
               		else
               			$flag2=1;


               }

               if($flag1=='1' && $flag2=='1')
               {

               		if(parseFloat(min_amt)>parseFloat(max_amt))
               		{
               			$flag=1;
               			$("#max_err").html('Minium Amount greater than Maximum Amount');

               		}

               }

               /*if(balance!='')
               {
               		var mq =/^[0-9.]+$/;
					if(!mq.test(bal_err))
               		{
               			$flag=1;
               			$("#bal_err").html('Invalid Amount format');
               		}
               }
               if(profit!='')
               {
               		var mq =/^[0-9.]+$/;
					if(!mq.test(profit))
               		{
               			$flag=1;
               			$("#profit_err").html('Invalid Amount format');
               		}
               }*/




               if(days=="")
               {
                  $flag=1;
                  $("#day_err").html('Please Enter Duration');
               }
               
               if($flag=='1')
               	return false;

               else
               {
               		lending.submit();
               }

               

			

				
			});
		   

		});
		})(jQuery);
	

	function numchk (tag)

{       

  var1=tag.value; // tval is textbox (element) checking for characters only

    s=var1.substr(var1.length-1,1);    

  m=s.charCodeAt(0);            

  if (!((m>=48 && m<=57 )||(m==46) || isNaN(m)))

  {

    //alert ("Invalid input");  

    ch=var1.substr(0,var1.length-1);    

    tag.value=ch;           

  }

}
		

	</script>



</body>
</html>
