<?php
	include "../../inc/inc.koneksi.php";
	include "../../inc/fungsi_tanggal.php";	
	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir = $_GET['tgl_akhir'];
	
	
?>

<html>
 <head>	
<script type="text/javascript">
$(document).ready(function(){
	$("#pilih").click(function(){
		var pilih= $("#pilih").val();
		var tglawal = $("#imp_tglaw").val();
		var tglakhir = $("#imp_tglak").val();
		
		$.ajax({
			type	: "POST",
			url	: "std/penjualan/pilih_faktur.php",
			data	: "pilih="+pilih+
					"&tglawal="+tglawal+
					"&tglakhir="+tglakhir,
			dataType	: "json",
			success	: function(data){
				$("#txt_total").val(data.total);				
			}
		});
	});
	
	$("#hitung_jumlah").click(function(){
		var pilih= $("#pilih").val();
		var tglawal = $("#imp_tglaw").val();
		var tglakhir = $("#imp_tglak").val();
		
		$.ajax({
			type	: "POST",
			url	: "std/penjualan/pilih_faktur.php",
			data	: "pilih="+pilih+
					"&tglawal="+tglawal+
					"&tglakhir="+tglakhir,
			dataType	: "json",
			success	: function(data){
				$("#txt_total").val(data.total);				
			}
		});
	});
});
</script>

        <style>
            table {
                border: 1px solid #ddd;
                border-collapse: collapse;
            }
            table td, table th {
                padding: 8px;
                border: 1px solid #ddd;
            }
        </style>
    </head>
    <body>
        <h1>Import Data Penjualan</h1>
        <form action="" method="POST" onsubmit="return konfirmasi()" >
			<p>Total Penjualan : Rp <input type='text' name='txt_total' id='txt_total' size='12' style='font:15px verdana' align='right'> Total Dipilih : Rp <input type='text' name='txt_total' id='txt_total' size='12' style='font:15px verdana' align='right'> <button onclick="std/penjualan/hitung_jumlah.php">Hitung</button> <button type="submit">Import</button></p>
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>Tanggal</th>
						<th>Nomor Faktur</th>
						<th>Pelanggan</th>
                        <th>Jml. Item</th>
                        <th>Jml. Unit</th>
                        <th>Total Harga</th>
						<th>Jenis Bayar</th>
                    </tr>
                </thead>
                <tbody>
                    <?php						
						$sql = mysql_query("SELECT kode_pj,tanggal,nama_pl,count(kode_st) as titem,sum(jml_unit) as junit,sum(jumlah) as tjumlah,jenis_by FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' GROUP BY kode_pj ORDER BY tanggal,kode_pj");
						
						while($r=mysql_fetch_array($sql)){
							?>
								<tr>
									<td><input type="checkbox" name="pilih[]" id='pilih' value="<?php echo $r['kode_pj'];?>"></td>
									<td><?php echo jin_date_str($r['tanggal']);?></td>
									<td><?php echo $r['kode_pj'];?></td>
									<td><?php echo $r['nama_pl'];?></td>
									<td align='center'><?php echo $r['titem'];?></td>
									<td align='right'><?php echo $r['junit'];?></td>
									<td align='right'><?php echo $r['tjumlah'];?></td>
									<td><?php echo $r['jenis_by'];?></td>
								</tr>
							<?php
						}
                    ?>
                </tbody>
            </table>
        </form>
        <script>
            function konfirmasi() {
                return confirm('Import data penjualan yang sudah dipilih ?');
            }
 
            function selectAll(input) {
                let checkboxes = document.querySelectorAll('.pilih');
                checkboxes.forEach(function (checkbox) {
                    checkbox.checked = input.checked;
                });
            }
        </script>
    </body>
</html>