            <div class="block-header">
                <h2>
                  
                     <ol class="breadcrumb breadcrumb-bg-teal">
                                <li><a href="index.php?home"><i class="material-icons">home</i> Home</a></li>
                               <li><a href="index.php?penarikan_kantin"><i class="material-icons">vertical_align_top</i> Penarikan Kantin</a></li>
                                <li class="active"> Penarikan Kantin Add</li>
                            </ol>
                </h2>
            </div>
			<?php 
			
			if(isset($_POST['submit'])){
			$keterangan=noninjection($koneksi,$_POST['keterangan']);
			$idmember=noninjection($koneksi,$_POST['idmember']);
			$nominal=noninjection($koneksi,$_POST['nominal']);
			
			$pin=noninjection($koneksi,$_POST['pin']);
			$task="34567fghjkl;FGHJK09865fghjs12345@#$@#$!@#";
			//tambah data
			if(($idmember<>'') and ($nominal<>'')  )
			{
									
					$pin=md5($pin);
					$pin_encript=md5($pin.$task);
		
			
					$qry_pin=mysqli_query($koneksi,"SELECT * FROM `tb_user` WHERE (email='".$_SESSION['email']."') AND (password='".$_SESSION['password']."') AND (pin='".$pin_encript."')");
					$N_pin=mysqli_num_rows($qry_pin);
					if($N_pin<>0)
					{
					$row_user=mysqli_fetch_array($qry_pin);
					
									$qry_rek=mysqli_query($koneksi,"SELECT * FROM `tb_rekening_kantin`  WHERE idanggota='".$idmember."' order by id desc limit 1");
									$row_rek=mysqli_fetch_array($qry_rek);
									if(mysqli_num_rows($qry_rek)<>0){
									$saldo=$row_rek['saldo']-$nominal;
									} else {$saldo=0;}
					if($saldo >= 0)
					{
					$res=mysqli_query($koneksi,"INSERT INTO `tb_rekening_kantin` (`idanggota`, `keterangan`, `in_out`, `nominal`, `saldo`, `reff`, `reff2`, `reff3`,`iduser`, `tgl`) VALUES ('".$idmember."', '".$keterangan."', 'out', '".$nominal."', '".$saldo."', '".$kategori."', 'Kasir', '-','".$row_user['id']."', current_timestamp());");
				//echo "INSERT INTO `tb_rekening_kantin` (`idanggota`, `keterangan`, `in_out`, `nominal`, `saldo`, `reff`, `reff2`, `reff3`,`iduser`, `tgl`) VALUES ('".$idmember."', '".$keterangan."', 'out', '".$nominal."', '".$saldo."', '".$kategori."', 'Kasir', '-','".$row_user['id']."', current_timestamp());";
					
					if($res){
					$qry_koper=mysqli_query($koneksi,"SELECT * FROM `tb_rekening_koperasi` order by id desc limit 1");
						if(mysqli_num_rows($qry_koper)<>0){
							$row_koper=mysqli_fetch_array($qry_koper);
							$saldo_koper=$row_koper['saldo'];
							
							$saldo_koper=$saldo_koper+$nominal;
						$res_koper=mysqli_query($koneksi,"INSERT INTO `tb_rekening_koperasi` (`idanggota`, `keterangan`, `in_out`, `nominal`, `saldo`, `reff`, `reff2`, `reff3`,`iduser`, `tgl`) VALUES ('".$idmember."', 'Penarikan Kantin, ".$keterangan."', 'in', '".$nominal."', '".$saldo_koper."', '".$idmember."', '".$row_user['nama']."', '-','".$row_user['id']."', current_timestamp());");
					}
					echo ' <div class="alert bg-green alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <strong>Well done!</strong> Simpan Data Sukses.
                            </div>';
							}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Simpan Data Gagal.
                            </div>';
							}
					
					}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Saldo tidak cukup.
                            </div>';
							}
					
					

			} else {echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> PIN Salah.
                            </div>';}
			} else {echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Input Data dengan lengkap.
                            </div>';}
			}
			
			
			
			?>
 <div class="row clearfix">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="card">
                        <div class="header">
                            <h2>PENARIKAN KANTIN ADD</h2>
                           
                        </div>
                        <div class="body">
						
						
                            <form id="form_advanced_validation" method="POST" action="index.php?penarikan_kantin&mn=penarikan_kantin_add">
							
							 <div class="row clearfix">
							      <div class="col-sm-3">
                                <div class="form-group form-float">
                                    <div class="form-line">
                                        <input type="text" class="form-control" name="idmember" id="idmember" onkeyup="func_anggota(this.value);"   required>
                                       
                                    </div>
                                     	<div align="right" >
									
									<a type="button" data-color="light-green" class="btn bg-light-green waves-effect"  data-toggle="modal" data-target="#mdModal"><i class="material-icons" style="cursor:pointer">search</i></a></div>
                                    <div class="help-info">Input ID Member </b></div>
                                </div>
							</div>	
							<div class="col-sm-9">	
								 <div class="row clearfix">
								  <div class="col-sm-3">
                                    <div class="form-group">
                                        <div class="form-line">
                                            <input type="text" class="form-control" name="saldo" id="saldo"   readonly="true" placeholder="Saldo" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-8">
                                    <div class="form-group">
                                        <div class="form-line">
                                           <input type="text" class="form-control" name="nama" id="nama" min="3" max="120"  onchange="cekup();" readonly="true" placeholder="Nama" required>
                                        </div>
                                    </div>
                                </div>
                               
							 </div>	
                            </div>
				 </div>
								
							
                                
								
								 <div class="form-group form-float">
                                    <div class="form-line">
                                        <input type="number" class="form-control" name="nominal"  style="font-size:32px;" onkeypress="return isNumberKey(event);" required>
                                        <label class="form-label">Nominal IDR</label>
                                    </div>
                                    <div class="help-info">Input Nominal dalam IDR</b></div>
                                </div>
								
                                <div class="row clearfix">
                                <div class="col-sm-12">
                                    <div class="form-group">
                                        <div class="form-line">
                                            <textarea rows="4" class="form-control no-resize" name="keterangan" placeholder="Keterangan Penarikan..." required></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
								
	                             
                           		 <div style="font-size:18px; color:#336600;" ><b>Input PIN Petugas</b></div>
                       			<div style="height:20px;"></div>
								
									<div class="form-group form-float">
                                    <div class="form-line">
                                        <input type="password" class="form-control" name="pin" title="Masukkan PIN" required>
                                        <label class="form-label">PIN Transaksi (Petugas)</label>
                                    </div>
                                    <div class="help-info">Input PIN untuk keamanan Transaksi</div>
                                </div>
								
								
								
                                <button class="btn btn-primary waves-effect" name="submit" type="submit" data-toggle="tooltip" data-placement="right" title="Simpan Data">SIMPAN</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!-- #END# Advanced Validation -->
            
             <div class="modal fade" id="mdModal" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header bg-light-green">
                            <h4 class="modal-title" id="defaultModalLabel">CARI DATA</h4>
                        </div>
                        <div class="modal-body" >
                           <div class="table-responsive">
                                <table class="table table-bordered table-striped table-hover js-basic-example dataTable">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                           
                                            <th>Nama</th>
										 
                                           
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr >
                                           <th>ID</th>
                                            <th>Nama</th>
                                           
											
                                        </tr>
                                    </tfoot>
                                    <tbody>
									<?php 
									//mysqli_close($koneksi);

									$koneksi21=koneksi_kantin($_SESSION['npsn']);
									$qry_cari21=mysqli_query($koneksi21,"SELECT * FROM `tb_pos_kat` ");
									while($row2=mysqli_fetch_array($qry_cari21)){
									?>
                                        <tr ondblclick="caridata(`<?php echo $row2['id'];?>`,`<?php echo $row2['nama'];?>`,`<?php echo $_SESSION['npsn'];?>`);">
                                            <td><?php echo $row2['id'];?></td>
                                            <td><?php echo $row2['nama'];?></td>
                                           
                                        </tr>
										<?php }?>
                                      
                                      
                                    </tbody>
                                </table>
                        </div>
						</div>
                        <div class="modal-footer bg-green">
                          
                            <button type="button" class="btn btn-link waves-effect" data-dismiss="modal" style="color:#FFFFFF">CLOSE</button>
                        </div>
                    </div>
                </div>
            </div>
			<script>
		 function caridata(data,nama,npsn)
			 {
			 document.getElementById("idmember").value=data;
			 document.getElementById("nama").value=nama;
			
			$('#mdModal').modal('hide');
			 	ceksaldo(data,npsn);
			 }
			function func_anggota(idmember){
			document.getElementById("nama").value='';document.getElementById("saldo").value='0';
			setCookie("url","https://cashless.sdibanjarmasin.id/ekantin/api/",365);

		var urlget=getCookie("url");
		
			$.ajax({
			type: 'GET',
		 	url: urlget+'anggota_kantin.php?api=AIzaSyARSSmIJjL5LuxZnrjkDnrD&id='+idmember+'&npsn='+npsn,
			 cache: false,
		 	success: function (data) {
		 	var arr  = JSON.parse(data);
			var len = arr.length;		
			var i;
    		for(i = 0; i < len; i++) {
				document.getElementById("idmember").value = arr[i].id;
				document.getElementById("nama").value = arr[i].nama;
				ceksaldo(arr[i].id);
			 }
		 	},
		 	error: function () {
		 		alert('Error : Request Gagal, periksa koneksi Internet');
		 	}
		 });
		 }
		 
		 function ceksaldo(idmember,npsn)
		 {
		     	setCookie("url","https://cashless.sdibanjarmasin.id/koperasi/api/",365);
		     		var urlget=getCookie("url");
		     	$.ajax({
			type: 'GET',
		 	url: urlget+'saldo_kantin.php?api=AIzaSyARSSmIJjL5LuxZnrjkDnrD&id='+idmember+'&npsn='+npsn,
			 cache: false,
		 	success: function (data) {
		 	var arr  = JSON.parse(data);
			var len = arr.length;		
			var i;
    		for(i = 0; i < len; i++) {
				document.getElementById("saldo").value = arr[i].saldo;	
				
			 }
    							
		 	},
		 	error: function () {
		 		alert('Error : Request Gagal, periksa koneksi Internet');
		 	}
		 });
		 }
		
			</script>