<div class="box">
	      <div class="box-body">
			<div class="panel panel-success">
            <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-dollar"></i>Nova Poupanca</h3>
            </div>
             <div class="box-body">
<?php
if(isset($_POST['save']))
{
$tid = $_SESSION['tid'];
$customer = mysqli_real_escape_string($link, $_POST['customer']);
$account =  mysqli_real_escape_string($link, $_POST['account']);
$amount_to_save = mysqli_real_escape_string($link, $_POST['amount_to_save']);
$user = mysqli_real_escape_string($link, $_POST['user']);
$remarks = mysqli_real_escape_string($link, $_POST['remarks']);


$insert = mysqli_query($link, "INSERT INTO savings(`id_borrowers`, `account`, `amount`, `remarks`, `user`) VALUES('$customer','$account','$amount_to_save','$remarks','$user')") or die (mysqli_error($link));
if(!$insert)
{
echo '<meta http-equiv="refresh" content="2;url=newpoupanca.php?tid='.$_SESSION['tid'].'">';
echo '<br>';
echo'<span class="itext" style="color: #FF0000">Impossivel efetuar poupanca.....Por favor tente novamente!</span>';
   
}
else{
    mysqli_query($link, "UPDATE balance set amount = amount + '$amount_to_save' WHERE id = 1") or die (mysqli_error($link));
echo '<meta http-equiv="refresh" content="2;url=listpoupancas.php?tid='.$_SESSION['tid'].'">';
echo '<br>';
echo'<span class="itext" style="color: #FF0000">Salvando Poupanca.....Por favor espere!</span>';
}

}
?>




<form class="form-horizontal" method="post" enctype="multipart/form-data" action="">
			  <?php echo '<div class="alert alert-info fade in" >
			  <a href = "#" class = "close" data-dismiss= "alert"> &times;</a>
  				<strong>Note que&nbsp;</strong> &nbsp;&nbsp;Os campos obrigatorios estao assinalados por <span style="color:red"> *</span>.
				</div>'?>
             <div class="box-body">
				
				  
				   <div class="form-group">
                <label for="" class="col-sm-2 control-label" style="color:#009900"><b style="color:red">*</b> Cliente</label>
				 <div class="col-sm-10">
                <select class="customer select2" name="customer" style="width: 100%;" required>
				<option selected="selected">--Selecionar Cliente--</option>
                 <?php
				$get = mysqli_query($link, "SELECT * FROM borrowers order by id") or die (mysqli_error($link));
				while($rows = mysqli_fetch_array($get))
				{
				echo '<option value="'.$rows['id'].'">'.$rows['fname'].'&nbsp;'.$rows['lname'].'</option>';
				}
				?>
                </select>
              </div>
			  </div>
	<script type="text/javascript">
	$(function() {
	    $(".customer").on('change', function(){
	        preecher_select2();
	        preecher_select4();
	    });

	    $(".desc").on('change', function(){
	        preecher_select3();

	    });

		function preecher_select2() {
		    var ida = $(".customer").val();
			$.ajax({
				url: 'numeroConta.php',
				type: 'GET',
				data:{
				    id: ida
				},
				success: function(data) {
					$(".account").html(data);
				},
				error: function() {
					$(".account").html("Ocorreu um erro na tentativa de preencher o select!");
				}
			});
		}
		function preecher_select3() {
		    var idaa = $(".desc").val();
		    var customer = $(".customer").val();
			$.ajax({
				url: 'loan.php',
				type: 'GET',
				data:{
				    desc: idaa,
				    customer: customer
				},
				success: function(data) {
					$(".loan").html(data);
				},
				error: function() {
					$(".loan").html("Ocorreu um erro na tentativa de preencher o select!");
				}
			});
		}
		function preecher_select4() {
		    var ida = $(".customer").val();
			$.ajax({
				url: 'loan_desc.php',
				type: 'GET',
				data:{
				    id: ida
				},
				success: function(data) {
					$(".desc").html(data);
				},
				error: function() {
					$(".desc").html("Ocorreu um erro na tentativa de preencher o select!");
				}
			});
		}

	});
</script>			  
		 <div class="form-group">
                <label for="" class="col-sm-2 control-label" style="color:#009900"><b style="color:red">*</b>Nº de Conta</label>
				 <div class="col-sm-10">
                <select class="account select2" name="account" style="width: 100%;" required>
             
                </select>
              </div>
			  </div>
			 

				  
		<div class="form-group">
                  <label for="" class="col-sm-2 control-label" style="color:#009900"><b style="color:red">*</b> A Poupar</label>
                  <div class="col-sm-10">
                  <input name="amount_to_save" type="number" class="form-control" placeholder="Valor a poupar" required step="0.01">
                  </div>
                  </div>

				  
		<div class="form-group">
                  <label for="" class="col-sm-2 control-label" style="color:#009900">Processado Por</label>
                  <div class="col-sm-10">
                 <?php
$tid = $_SESSION['tid'];
$sele = mysqli_query($link, "SELECT * from user WHERE id = '$tid'") or die (mysqli_error($link));
while($row = mysqli_fetch_array($sele))
{
?>
                  <input name="user" type="text" class="form-control" value="<?php echo $row['name']; ?>" readonly>
<?php } ?>
                  </div>
                  </div>
				  
				  
		 <div class="form-group">
                  	<label for="" class="col-sm-2 control-label" style="color:#009900">Observaçao</label>
                  	<div class="col-sm-10">
					<textarea name="remarks"  class="form-control" rows="4" cols="80"></textarea>
           			 </div>
          </div>

			 </div>
			 
			  <div align="right">
              <div class="box-footer">
                				<button type="reset" class="btn btn-primary btn-flat"><i class="fa fa-times">&nbsp;Limpar</i></button>
                				<button name="save" type="submit" class="btn btn-success btn-flat"><i class="fa fa-save">&nbsp;Processar</i></button>

              </div>
			  </div>
			  </form>
			  

           
</div>	
</div>
</div>	
</div>