<!DOCTYPE html>
<html>
   <head>

      <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
      <script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
   </head>

<body>
    <?php
    include 'header.php'; 
    
    $notrans     = $_GET['id'];

        $pinj_angs = mysqli_query($koneksi,"select * from pinj_angs where notrans='$notrans'");
            $d = mysqli_fetch_assoc($pinj_angs);
            
        $anggota = mysqli_query($koneksi,"select * from anggota where angg_no='$d[angg_no]'");
            $a = mysqli_fetch_assoc($anggota);
        
      $alamat=''.$a['alamat'].', Kec. '.$a['kec'].' Kab. '.$a['kab'].'' ;    
      
      $hp_no        = $a['hp'] ;   
      $potong_nohp  = substr($hp_no,1,12);
      
      $kd           = '62';
      $nohp_tujuan  = '62'.$potong_nohp ;
      
      $tanggal      = $d['tanggal'] ; 
      $xtanggal     = date('d/m/Y', strtotime($d['tanggal']));
      $bayar        = $d['byrpokok']+$d['byrbunga']+$d['byrlain'] ;
      $xbayar       = number_format("$bayar", 0, ",", ".");
      $keter='Angsuran pinjaman No. '.$d['norek'].' telah kami terima pada tanggal '.$xtanggal.' sejumlah Rp. '.$xbayar.'. Terimakasih';
      $trim_ket = trim($keter)
      
    ?>
	<div class="container">
		<div class="col-lg-8 col-lg-offset-3">
			<h4>Berita Tanda Terima Pembayaran Angsuran </h4>
			<div class="panel panel-success">
				<div class="panel-heading">
					Kirim WA kepada <?php echo $a['nama'] ; ?> No. HP <?php echo $a['hp']; ?>
     <div class="card-header d-flex justify-content-between">
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
        <a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </button>
    </div>   			
				</div>
				</div>
				<div class="panel-body">
					<div class="form-group">
						<label>Dikirim ke Nomor WhatsApp : </label>
						<input type="text" name="phone" class="form-control" placeholder="Nomor Kontak / WhatsApp" id="phone" value=<?php echo $nohp_tujuan; ?> 
					</div>
					<div class="form-group">
						<label><font color="#000fff">Nama : </font></label>
                        <input type="text" class="form-control" name="name" id="name" value="<?php echo $a['nama'] ?>" required="required" >
					</div>
					<div class="form-group">
						<label><font color="#000fff">Alamat : </font></label>
                        <input type="text" class="form-control" name="alamat" id="alamat" value="<?php echo strtoupper($alamat) ?>" required="required" >
					</div>

					<div class="form-group">
						<label><font color="#000fff">Berita : </font></label>
						 <input type="text" class="form-control" name="ket" id="ket" value="<?php echo $keter ?>" required="required" >
					</div>
				</div>	
					<div class="form-group">
						<button class="btn btn-success send">Kirim Pesan via WhatsApp</button>
					</div>
	    

					<div id="text-info"></div>
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		$(document).on('click','.send', function(){
			/* Inputan Formulir */
			var input_name 			= $("#name").val(),
			    input_alamat 		= $("#alamat").val(),
			    input_phone 		= $("#phone").val(),
			    input_ket 	        = $("#ket").val();

			/* Pengaturan Whatsapp */
			var walink 		= 'https://web.whatsapp.com/send',
			    phone 		= $("#phone").val(),
			    text 		= 'PT. SOLUSI DANA BIJAK Sragen, mengucapkan terimakasih,',
			    text_yes	= 'Pesan Anda berhasil terkirim.',
			    text_no 	= 'Isilah formulir terlebih dahulu.';

			/* Smartphone Support */
			if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
				var walink = 'whatsapp://send';
			}

			if(input_name != "" && input_phone != "" && input_ket != ""){
				/* Whatsapp URL */
				var checkout_whatsapp = walink + '?phone=' + phone + '&text=' + text + '%0A%0A' +
				    '*Kepada* : ' + input_name + '%0A' +
				    '*Alamat* : ' + input_alamat + '%0A' +
				    '*Berita* : ' + input_ket + '%0A';

				/* Whatsapp Window Open */
				//window.open(checkout_whatsapp,'_blank');/
				window.open(checkout_whatsapp,'');
				document.getElementById("text-info").innerHTML = '<div class="alert alert-success">'+text_yes+'</div>';
			} else {
				document.getElementById("text-info").innerHTML = '<div class="alert alert-danger">'+text_no+'</div>';
			}
		});
	</script>

</body>
</html>