Sebagai berikut adalah kode PHP untuk autoInput Nota Transaksi...
dengan amsing-masing Nota terdiri dari random N jumlah item Jenis barang, dan tiap2 jenis barang random M Jumlahnya....
dan setiap Transaksi/Nota terurut dari tanggal tertentu dan bulan tertentu (misal 10 bulan yang lalu) dst.....
<?php
$tanggal=WKT(date("Y-m-d"));
$lamabulan=10;//default
?>
<script type="text/javascript">
function PRINT(tgl){
win=window.open('penjualan/print.php?tgl='+tgl,'win','width=1000, height=400, menubar=0, scrollbars=1, resizable=0, location=0, toolbar=0, status=0'); }
</script>
<script language="JavaScript">
function buka(url) {window.open(url, 'window_baru', 'width=800,height=600,left=320,top=100,resizable=1,scrollbars=1');}
</script>
<div id="accordion">
<h3>Generate Data Invoice</h3>
<div>
<!-- Accordion -->
<form action="" method="post" enctype="multipart/form-data">
<table class="table table-hover">
<tr>
<td height="24"><label for="lamabulan">Lama Bulan Yang Lalu</label>
<td>:<td colspan = "2"><input class="form-control" name="lamabulan" value="<?php echo $lamabulan;?>" type="number" id="lamabulan" value="<?php echo $jumlah;?>" size="30" />
</td>
</tr>
<tr>
<td height="24"><label for="keterangan">Catatan</label>
<td>:<td width="331"><textarea class="form-control" name="keterangan" cols="100" type="text" id="keterangan"><?php echo $keterangan;?> </textarea></td>
</tr>
<tr><td><td>
<td colspan="2">
<input name="Generate" type="submit" class="btn btn-success" id="Generate" value="Generate" />
<a href="?mnu=aoq"><input name="Batal" class="btn btn-danger" type="button" id="Batal" value="Batal" /></a>
</td></tr>
</table>
</form>
</div>
<?php
$sqlc="select distinct(`tanggal`) from `$tbinvoice` order by `tanggal` asc";
$arrc=getData($conn,$sqlc);
foreach($arrc as $dc) {
$tanggal=$dc["tanggal"];
?>
<h3>Data Invoice <?php echo WKT($tanggal);?></h3>
<div>
<br />
Data Invoice <?php echo WKT($tanggal);?>:
<img src='ypathicon/print.png' title='PRINT' OnClick="PRINT('<?php echo $tanggal;?>')">
<br>
<table class="table table-bordered table-striped table-hover">
<tr bgcolor="#CCCCCC">
<th width="3%">No</th>
<th width="10%">IDInvoice</th>
<th width="70%">List Produk</th>
<th width="10%">Menu</th>
</tr>
<?php
$sql="select distinct(`id_invoice`) from `$tbinvoice` where tanggal='$tanggal' order by `id_invoice` desc ";
$jum=getJum($conn,$sql);
if($jum > 0){
$no=1;
$arr=getData($conn,$sql);
foreach($arr as $d) {
$id_invoice=$d["id_invoice"];
$gab="<ol>";
$sqlg="select * from `$tbinvoice` where `id_invoice`='$id_invoice'";
$arrg=getData($conn,$sqlg);
foreach($arrg as $dg) {
$id_produk=$dg["id_produk"];
$np=getProduk($conn,$id_produk);
$jumlah=$dg["jumlah"];
$catatan=$dg["catatan"];
$gab.="<li>$np ($id_produk) : $jumlah item $catatan</li>";
}
$gab.="</ol>";
$color="#dddddd";
if($no %2==0){$color="#eeeeee";}
echo"<tr bgcolor='$color'>
<td>$no</td>
<td>$id_invoice</td>
<td>$gab</td>
<td align='center'>
<a href='?mnu=invoice&pro=hapus&kode=$id_invoice'><img src='ypathicon/h.png' alt='hapus'
onClick='return confirm(\"Apakah Anda benar-benar akan menghapus $id_invoice pada data invoice ?..\")'></a></td>
</tr>";
$no++;
}//while
}//if
else{echo"<tr><td colspan='7'><blink>Maaf, Data invoice belum tersedia...</blink></td></tr>";}
?>
</table>
</div>
<?php } ?>
</div>
</div>
</body>
<!-- Accordion -->
<?php
if(isset($_POST["Simpan"])){
$jum=strip_tags($_POST["i"]);
$id_invoice=strip_tags($_POST["id_invoice"]);
$tanggal=BAL($_POST["tanggal"]);
$keterangan=strip_tags($_POST["keterangan"]);
$sql="delete from `$tbinvoice` where `id_invoice`='$id_invoice'";
$hapus=process($conn,$sql);
$ada=0;
for($i=0;$i<=$jum;$i++){
$id_produk=strip_tags($_POST["idp$i"]);
$jumlah=strip_tags($_POST["jum$i"]);
$pil=strip_tags($_POST["pil$i"]);
$keterangan=strip_tags($_POST["cat$i"]);
if($pil==1 && isset($_POST["pil$i"]) && $jumlah>0){
$ada++;
$sql="INSERT INTO `tbinvoice` (
`id`, `id_invoice`, `id_produk`, `jumlah`, `keterangan`, `tanggal`) VALUES (
'', '$id_invoice', '$id_produk', '$jumlah', '$keterangan','$tanggal')";
$simpan=process($conn,$sql);
}//isset
}//for
if($ada>0){
$sql=" INSERT INTO `$tbinvoice` (
`id_invoice` ,
`tanggal` ,
`keterangan`
) VALUES (
'$id_invoice',
'$tanggal',
'$keterangan'
)";
$simpan=process($conn,$sql);
if($simpan) {echo "<script>alert('Data $id_invoice berhasil disimpan !');document.location.href='?mnu=generate';</script>";}
else{echo"<script>alert('Data $id_invoice gagal disimpan...');document.location.href='?mnu=generate';</script>";}
}
else{
echo"<script>alert('Silakan Lengkapi Data Anda DenganItem yang dipilih berikut Jumlahnya...');document.location.href='?mnu=generate';</script>";
}
}
?>
<?php
if($_GET["pro"]=="hapus"){
$id_invoice=$_GET["kode"];
$sql="delete from `$tbinvoice` where `id_invoice`='$id_invoice'";
$hapus=process($conn,$sql);
if($hapus) {echo "<script>alert('Data invoice $id_invoice berhasil dihapus !');document.location.href='?mnu=invoice';</script>";}
else{echo"<script>alert('Data invoice $id_invoice gagal dihapus...');document.location.href='?mnu=invoice';</script>";}
}
if(isset($_POST["Generate"])){
$keterangan=$_GET["keterangan"];
$lamabulan=$_POST["lamabulan"];//15
$sql="select `id_produk`,`kategori` from `$tbproduk` order by rand()";
$arr=getData($conn,$sql);
$n=0;
foreach($arr as $d) {
$id_produk=$d["id_produk"];
$kategori=$d["kategori"];
$arB[$n]=$id_produk;
$arH[$n]=$kategori;
$n++;
}
$sql0="Truncate `$tbinvoice`";
$simpan0=process($conn,$sql0);
$selthn=floor($lamabulan/12); //1
$selbln=$lamabulan%12;//3
$tahun=date("Y")-$selthn;//13
$bulan=date("m")-$selbln;
if($bulan<=0){$bulan=$bulan+12;$tahun=$tahun-1;}
$TH=$tahun;
$BL=$bulan;
for($b=0;$b<$lamabulan;$b++){//bln thn
if($BL>12){
$BL=1;$TH=$TH+1;
}
for($i=1;$i<24;$i++){//tgl
$ii=$i;
if($ii<10){$ii="0$i";}
$tanggal="$TH-$BL-$ii";
if($tanggal=="0000-00-00"){}
else{
$txharian=rand(1,5);
for($j=0;$j<$txharian;$j++){
$sql="select `id_invoice` from `$tbinvoice` order by `id_invoice` desc";
$q=mysqli_query($conn, $sql);
$jum=mysqli_num_rows($q);
$th=date("y");
$bl=date("m")+0;if($bl<10){$bl="0".$bl;}
$kd="PJL".$th.$bl;//KEG1610001
if($jum > 0){
$d=mysqli_fetch_array($q);
$id_invoiceax=$d["id_invoice"];
$bul=substr($id_invoiceax,5,2);
$tah=substr($id_invoiceax,3,2);
if($bul==$bl && $tah==$th){
$urut=substr($id_invoiceax,7,4)+1;
if($urut<10){$id_invoiceax="$kd"."000".$urut;}
else if($urut<100){$id_invoiceax="$kd"."00".$urut;}
else if($urut<1000){$id_invoiceax="$kd"."0".$urut;}
else{$id_invoiceax="$kd".$urut;}
}//==
else{
$id_invoiceax="$kd"."0001";
}
}//jum>0
else{$id_invoiceax="$kd"."0001";}
$id_invoice=$id_invoiceax;
$banyakProdukdalam1Nota=rand(1,5);//1 nota ada antara 1 sd 5 barang
if($banyakProdukdalam1Nota>5){$banyakProdukdalam1Nota=5;}
$numbers = range(0, $n-1);
shuffle($numbers);
for($k=0;$k<$banyakProdukdalam1Nota;$k++){
$r=$numbers[$k]+0;//rand(1,$n-1);//
if($r>$n-1){
$r=0;//rand(0,$n-1);
}
$id_produk=$arB[$r];//43201
$jumlah=rand(2,10);
$subtotal=$jumlah*$arH[$r];
$catatan="";
$sql1=" INSERT INTO `$tbinvoice` (
`id_invoice` ,`jumlah` ,`id_produk` ,
`tanggal` ,
`keterangan`
) VALUES (
'$id_invoice', '$jumlah', '$id_produk',
'$tanggal',
'Generate $lamabulan Bulan $keterangan '
)";
$simpan1=process($conn,$sql1);
//echo $sql1."<br>";
}//k banyak produk
}//j txharians
}//0000-00-00
}//i
$BL=$BL+1;
}//bulan thn
//sukses generate
echo "<script>alert('Generate Berhasil ');document.location.href='?mnu=generate';</script>";
}//generate
?>
Tidak ada komentar:
Posting Komentar