
<script src="<?php echo base_url("js/jquery.min.js"); ?>"></script> <!-- Load library jquery -->


<div class="row border border-info p-2 border-">
	<div class="col-md-5 ">
		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">No. Pend </label>
			<div class="col-sm-10">
				<input type="text" value="<?= $invoice->no_pendaftaran ?>" name="no_pendaftaran" id="no_pendaftaran" class="form-control" placeholder="Masukkan No. Pendaftaran"  readonly> 
			</div>
		</div>

		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">Nama Lengkap <span class="text-danger"></span></label>
			<div class="col-sm-10">
				<input type="text"  value="<?= $invoice->nama_lengkap ?>" name="nama_lengkap" id="nama_lengkap" class="form-control" placeholder="Nama Lengkap"
					readonly required>
			</div>
		</div>

		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">Sekolah Asal <span class="text-danger"></span></label>
			<div class="col-sm-10">
				<input type="text"  value="<?= $invoice->sekolah_asal ?>" name="sekolah_asal" id="sekolah_asal" class="form-control" placeholder="Sekolah Asal"
					readonly>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">Kompetensi<span class="text-danger"></span></label>
			<div class="col-sm-10">
				<input type="text"  value="<?= $invoice->kompetensi ?>" name="kompetensi" id="kompetensi" class="form-control" placeholder="Kompetensi"
					readonly>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">No. Invoice<span class="text-danger"></span></label>
			<div class="col-sm-10">
				<input type="text"  value="<?= $invoice->no_invoice ?>" name="noinvoice" id="noinvoice" class="form-control"
					placeholder="Sekolah Asal" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label class="col-sm-2 control-label text-left">Biaya PPDB Rp.<span class="text-danger"></span></label>
			<div class="col-sm-10">
				<input type="text" value="<?php 
                echo number_format($invoice->biaya, 0, ',', '.');
                
                ?>" name="biayappdb" id="biayappdb" class="form-control" placeholder="Biaya PPDB"
					readonly>
				<input type="hidden" name="realbiaya" id="realbiaya" value="<?= $invoice->biaya ?>">
			</div>
		</div>




	</div>
	<div class="col-md-3">
		<div class="form-group row">
			<label for="level" class="col-sm-5 col-form-label">Potongan Gel. 1 </label>
			<div class="col-sm-7">
				<input type="text" value="<?= number_format($invoice->pot_gel, 0, ',', '.'); ?>"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="level" class="col-sm-5 col-form-label">Potongan DP Gel. 1</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_dp, 0, ',', '.'); ?>" name="potongan_dp" id="potongan_dp"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="potongan_yatim" class="col-sm-5 col-form-label">Potongan YATIM</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_yatim, 0, ',', '.'); ?>" id="potongan_yatim" name="potongan_yatim"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Potongan SPP 50%</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_spp, 0, ',', '.'); ?>" id="potongan_spp" name="potongan_spp"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Potongan Kembar</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_kembar, 0, ',', '.'); ?>" id="potongan_kembar" name="potongan_kembar"
					class="form-control" readonly>
			</div>
		</div>
	</div>
	<div class="col-md-4">
		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Potongan Yayasan</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_yayasan, 0, ',', '.'); ?>" id="potongan_yayasan" name="potongan_yayasan"
					class="form-control" readonly>
			</div>
		</div>
		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Potongan SKTM</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_sktm, 0, ',', '.'); ?>" id="potongan_sktm" name="potongan_sktm"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Potongan Lainnya</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->pot_lain, 0, ',', '.'); ?>" id="potongan_lainnya" name="potongan_lainnya"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Ketentuan Bayar</label>
			<div class="col-sm-7">
				<input type="text" id="total" name="total"  value="<?= number_format($invoice->ketentuan, 0, ',', '.'); ?>" class="form-control text-bold display-3" readonly>
			</div>
		</div>


	</div>
</div>
<hr>

<div class="row border border-info p-2">

	<div class="col-md-12">
		

	<table class    = 'table table-bordered table-striped w-100' id = 'example1'>
    <thead>
    <tr>
    <th >NO.</th>
    <th >NO. TRANS</th>
    <th >TANGGAL</th>
    <th >KEWAJIBAN</th>
    <th >KETERANGAN</th>
    <th >BAYAR</th>
    <th >OPERATOR</th>
    <th >AKSI</th>
    </tr>
    </thead>
    <tbody>
    <?php 
	// $key=0;
	foreach ( $transaksi as $key => $value ) {
        ?>
        <tr>
        <td><?php echo $key+1;
        ?></td>
        <td><b><?php echo $value->no_trans ?></b>        
        </td>
        <td><?php $timestamp = strtotime($value->tgl_bayar);
		// Menggunakan date() untuk mengonversi UNIX timestamp ke dalam format yang diinginkan
		$tanggal_bayar = date("d-M-Y", $timestamp);
		// Menampilkan tanggal yang sudah diubah formatnya
		echo $tanggal_bayar; ?></td>
        <td><?php echo number_format($invoice->ketentuan) ?></td>
        <td><b><?php echo $value->angsuran ?></b>       
        </td>
        <td><?php echo number_format( $value->bayar ) ?></td>
        <td><?php echo $value->operator ?></td>
        <td>
				<div class  = "btn-group">            
                	<a id="bedit"  class="btn btn-warning btn-sm bedit" data="<?= $value->no_trans ?>">
						<i class  = "fa fa-edit"></i>
					</a>					
					<?php if($this->session->userdata('level')=="Administrator") { ?>
					<a href    = "<?php echo base_url('invoice/deletetransaksi/'.$value->no_trans . '?no_pendaftaran=' . $invoice->no_pendaftaran); ?>" class="btn btn-danger btn-sm" onclick="return confirm('Yakin ingin menghapus data Transaksi invoice <?php echo $invoice->nama_lengkap ?> [ <?php echo $value->no_trans ?> ] ..?')">
						<i class  = "fa fa-trash"></i>
					</a>
					<?php } ?>                    
				</div>
			</td>
        </tr>

        <?php }
        ?>
        </tbody>
        </table>
	</div>




	
</div>
<hr>
<h5 class="text-bold text-white mb-4 bg-info text-center "><?= $invoice->no_invoice ?> <strong>/* </strong>BIAYA : Rp.<?php  echo number_format($invoice->biaya, 0, ',', '.'); ?> <strong>/* </strong> POTONGAN : Rp.<?php  echo number_format($invoice->pot_gel + $invoice->pot_dp + $invoice->pot_yatim + $invoice->pot_spp + $invoice->pot_kembar + $invoice->pot_yayasan +  $invoice->pot_sktm + $invoice->pot_lain, 0, ',', '.'); ?>
<strong> /* </strong>BAYAR : Rp.<?= number_format($invoice->ketentuan, 0, ',', '.'); ?>  </h5> 
<?php
//form edit open
echo form_open(base_url('invoice/simpantransaksi'));
?>

<div class="row">
	<div class="col-md-6">
		
		<div class="form-group row">
			<label for="level" class="col-sm-5 col-form-label">No. Transaksi </label>
			<div class="col-sm-7">
				<input type="text" name="notr" id="notr" value="<?= $notr ?>"
					class="form-control" readonly>
			</div>
		</div>

		<div class="form-group row">
			<label for="level" class="col-sm-5 col-form-label">Ketentuan Bayar</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->ketentuan, 0, ',', '.'); ?>" name="potongan_dp" id="potongan_dp"
					class="form-control" readonly>
			</div>
		</div>


		<div class="form-group row">
			<label for="level" class="col-sm-5 col-form-label">Sudah Dibayarkan</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($sudahbayar, 0, ',', '.'); ?>" name="potongan_dp" id="potongan_dp"
					class="form-control" readonly>
			</div>
		</div>

	

		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Kekurangan 
				
			<?php 
			$kekurangan = $invoice->ketentuan - $sudahbayar;
			
			if($kekurangan < 1) 
			{
			?>
			<small><a class="badge badge-success text-white">LUNAS</a></small>
			<?php } ?>
			</label>
			<div class="col-sm-7">
				<input type="text" onchange="calculateTotal()" value="<?= number_format($invoice->ketentuan - $sudahbayar, 0, ',', '.'); ?>" id="potongan_spp" name="potongan_spp"
					class="form-control" readonly> 
			</div>
		</div>

		




	</div>
	<div class="col-md-6">
		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Keterangan Cicilan <span class="text-danger">*</span></label>
			<div class="col-sm-7">
				<select  id="keterangan_cicilan" name="keterangan_cicilan" class="form-control" required>
					<option value="" >Pilih Ketarangan</option>					
					<option value="ANGSURAN 1" >Angsuran 1</option>
					<option value="ANGSURAN 2" >Angsuran 2</option>
					<option value="ANGSURAN 3" >Angsuran 3</option>
					<option value="ANGSURAN 4" >Angsuran 4</option>
					<option value="ANGSURAN 5" >Angsuran 5</option>
				</select>
			</div>

		</div>
		<div class="form-group row">
			<label for="total" class="col-sm-5 col-form-label">Besar Cicilan <span class="text-danger">*</span></label>
			<div class="col-sm-7">
				<input type="text"   id="besarcicilan" name="besarcicilan"
					class="form-control" required>
				<input type="hidden" name="editkah" id="editkah">
				<input type="hidden" name="nopen" value="<?= $invoice->no_pendaftaran ?>">
				<input type="hidden" name="noin" value="<?= $invoice->no_invoice ?>">
				
			</div>
		</div>
        <div class="form-group row">
	
	<div class="col-sm-12">
	<a target="_blank" href="<?php echo base_url('invoice/cetaktransaksi/').$invoice->no_pendaftaran ?>" class="btn btn-success">
			<i class="fa fa-print"></i> Cetak
		</a>
		<button type="submit" class="btn btn-primary">
			<i class="fa fa-save"></i> Simpan Data
		</button>
		
		<a href="<?php echo base_url('invoice') ?>" class="btn btn-default">
			<i class="fa fa-backward"></i> Kembali
		</a>

		
	</div>
</div>

		


	</div>
</div>

<!---simpan,reset,kembali-->


<?php
//form close
echo form_close();
?>

<script>

function removeNonNumericChars(input) {
        return input.replace(/\D/g, '');
    }

    // Fungsi untuk mengubah format input harga
    function formatHarga(input) {
        var num = removeNonNumericChars(input.value);
        var formattedNum = new Intl.NumberFormat('id-ID').format(num);
        input.value = formattedNum;
    }

    // Fungsi untuk menghapus format input harga sebelum disubmit
    function unformatHarga(input) {
        input.value = removeNonNumericChars(input.value);
    }

    // Mengaitkan fungsi formatHarga dengan event onkeyup untuk input harga
    document.getElementById('besarcicilan').addEventListener('keyup', function() {
        formatHarga(this);
    });
	

    $(document).ready(function() {
        // Menangani peristiwa saat tombol "bedit" diklik
        $(document).on('click', '.bedit', function() {
            // Mengambil nilai atribut data dari tombol "bedit"
            var noTrans = $(this).attr('data');

            // Mengirim permintaan AJAX ke controller untuk mengambil data invoice
            $.ajax({
                url: '<?php echo base_url("invoice/fungsi_edit_invoice"); ?>',
                type: 'POST',
                data: {no_trans: noTrans},
                dataType: 'json',
                success: function(response) {
                    // Mengisi nilai pada form dengan data yang diterima dari controller
                    $('#keterangan_cicilan').val(response.angsuran);
                    $('#besarcicilan').val(response.bayar);
                    $('#notr').val(response.no_trans);
                    $('#editkah').val("editkah");
                },
                error: function(xhr, status, error) {
                    // Menangani kesalahan jika permintaan gagal
                    console.error(xhr.responseText);
                }
            });
        });
    });
</script>

