Rumus Koneksi:
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = '2018_profit';
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$sql="select * from `$tbadmin` order by `kode_admin` desc";
$q=mysqli_query($conn, $sql);
$jum=mysqli_num_rows($q);
$kd="ADM";
if($jum > 0){
$d=mysqli_fetch_array($q);
$idmax=$d["kode_admin"];
$urut=substr($idmax,3,2)+1;//01
if($urut<10){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}
else{$idmax="$kd"."01";}
$kode_admin=$idmax;
AutoDIgit Year-Moon-AI:
$sql="select `kode_po` from `$tbpo` order by `kode_po` 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="NPO".$th.$bl;//KEG1610001
if($jum > 0){
$d=mysqli_fetch_array($q);
$idmax=$d["kode_po"];
$bul=substr($idmax,5,2);
$tah=substr($idmax,3,2);
if($bul==$bl && $tah==$th){
$urut=substr($idmax,7,3)+1;
if($urut<10){$idmax="$kd"."00".$urut;}
else if($urut<100){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}//==
else{
$idmax="$kd"."001";
}
}//jum>0
else{$idmax="$kd"."001";}
$kode_po=$idmax;
Librari / Fungsi mysqli:
<?php function RP($rupiah){return number_format($rupiah,"2",",",".");}?>
<?php
function WKT($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);
$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>
<?php
function WKTP($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,2,2);
$judul_bln=array(1=> "Jan", "Feb", "Mar", "Apr", "Mei","Jun", "Jul", "Agu", "Sep","Okt", "Nov", "Des");
$wk=$tanggal." ".$judul_bln[(int)$bulan]."'".$tahun;
return $wk;
}
?>
<?php
function BAL($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}
else if($arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}
else if($arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}
else if($arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember"){$bul="11";}
else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
<?php
function BALP($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Jan"){$bul="01";}
else if($arr[1]=="Feb"){$bul="02";}
else if($arr[1]=="Mar"){$bul="03";}
else if($arr[1]=="Apr"){$bul="04";}
else if($arr[1]=="Mei"){$bul="05";}
else if($arr[1]=="Jun"){$bul="06";}
else if($arr[1]=="Jul"){$bul="07";}
else if($arr[1]=="Agu"){$bul="08";}
else if($arr[1]=="Sep"){$bul="09";}
else if($arr[1]=="Okt"){$bul="10";}
else if($arr[1]=="Nov"){$bul="11";}
else if($arr[1]=="Nop"){$bul="11";}
else if($arr[1]=="Des"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
<?php
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if($rs){
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s=true;
}
}
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
function getJum($conn,$sql){
$rs=$conn->query($sql);
$jum= $rs->num_rows;
$rs->free();
return $jum;
}
function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}
function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
// echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}
function getAdmin($conn,$kode){
$field="username";
$sql="SELECT `$field` FROM `tb_admin` where `kode_admin`='$kode'";
$rs=$conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
?>
MENU LOGIN:
<?php
session_start();
?>
<table width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=#B19B68>
<tr><td class=textp> Otentikasi</td></tr>
<tr><td><table width=100% cellspacing=5 cellpadding=0 bgcolor=#F8EED7>
<tr><td class=textblack>
<b>Otentikasi Data </b>
<form name="formLogin" method="post" action="">
<table width="284" border="0">
<tr>
<th colspan="2" bgcolor="#FF00FF"><marquee>
Silakan Tulis Data Login Anda / Register untuk membuat Acoount Baru
</marquee></th>
</tr>
<tr>
<td width="67">Username</td>
<td width="207">:
<input type="text" name="user" id="user" /></td>
</tr>
<tr>
<td>Password:</td>
<td>:
<input type="password" name="pass" id="pass">
</td>
</tr>
<tr>
<td colspan="2" align="right" valign="middle">
<input type="submit" name="Login" id="Login" value="Login">
<input type="Reset" name="Reset" id="Reset" value="Reset">
</td>
</tr>
</table>
</form>
</table></td></tr></table><br>
<?php
if(isset($_POST["Login"])){
$usr=$_POST["user"];
$pas=$_POST["pass"];
$sql1="select * from `$tbadmin` where `username`='$usr' and `password`='$pas' and `status`='Aktif'";
//$sql2="select * from `$tbadmin` where `username`='$usr' and `password`='$pas' and `status`='Aktif'";
//$sql3="select * from `$tbadmin` where `username`='$usr' and `password`='$pas' and `status`='Aktif'";
if(getJum($conn,$sql1)>0){
$d=getField($conn,$sql1);
$kode=$d["kode_admin"];
$nama=$d["username"];
$_SESSION["cid"]=$kode;
$_SESSION["cnama"]=$nama;
$_SESSION["cstatus"]="Administrator";
echo "<script>alert('Otentikasi ".$_SESSION["cstatus"]." ".$_SESSION["cnama"]." (".$_SESSION["cid"].") berhasil Login!');
document.location.href='index.php?mnu=home';</script>";
}
//elseif(getJum($conn,$sql2)>0){
// }
else{
session_destroy();
echo "<script>alert('Otentikasi Login GAGAL !,Silakan cek data Anda kembali...');
document.location.href='index.php?mnu=login';</script>";
}
}
?>
Login:a
Pass:a
Download
Display Ahir:
NB:
buat database 2018_profit lalu import database di folder app_profit
lalu copas app_profit di htdoc
dan jalankan login sebagai admin dengan usernamenya a, password a
coba latihan input semua tabel dahulu mb
atau langusng masuk ke pembuatan proyek
klik tombol xls u masuk ke detail (one to many)
lalu masuk ke menu PO
dan masukkan harga pengajuannya
secara default harga pengajuan dibuat sama dengan harga estimasi di awal
.....
Tidak ada komentar:
Posting Komentar