Created
February 5, 2013 17:54
-
-
Save setiyawanarif/4716265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Parkir{ | |
public function chekIn($idParkir,$statuss,$nopol,$timestart,$tanggal,$timeend){ | |
$status=false; | |
//$dom = new DOMDocument("1.0","UTF-8"); | |
//$parkirkendaraan = $dom->createElement("parkirkendaraan"); | |
$xml = simplexml_load_file('parkir.xml'); | |
$parkir= $xml->addChild('parkir'); | |
$parkir->addChild("idparkir",$idParkir); | |
$parkir->addChild("status",$statuss); | |
$parkir->addChild("nopol",$nopol); | |
$parkir->addChild("timestart",$timestart); | |
$parkir->addChild("tanggal",$tanggal); | |
$parkir->addChild("timeend",$timeend); | |
if(file_put_contents('parkir.xml',$xml->asXML())==True){ | |
$status=TRUE; | |
}else {$status=FALSE;} | |
return $status; | |
} | |
public function perhitunganLamaHari($tanggalMasuk,$tanggalKeluar){ | |
// memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun | |
// dari tanggal pertama | |
$pecah1 = explode("-", $tanggalMasuk); $date1 = $pecah1[2]; $month1 = $pecah1[1]; $year1 = $pecah1[0]; | |
// memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun | |
// dari tanggal kedua | |
$pecah2 = explode("-",$tanggalKeluar); $date2 = $pecah2[2]; $month2 = $pecah2[1]; $year2 = $pecah2[0]; | |
// menghitung JDN dari masing-masing tanggal | |
$jd1 = GregorianToJD($month1, $date1, $year1); | |
$jd2 = GregorianToJD($month2, $date2, $year2); | |
// hitung selisih hari kedua tanggal | |
$selisih = $jd2-$jd1;//dalam hari | |
return $selisih; | |
} | |
public function perhitunganLamaJam($waktuMasuk,$waktuKeluar){ | |
list($h,$m,$s)= explode(":",$waktuMasuk); | |
$dtAwal=mktime($h,$m,$s,"0","0","0"); | |
list($h,$m,$s)=explode(":", $waktuKeluar); | |
$dtAkhir= mktime($h,$m,$s,"0","0","0"); | |
$dtSelisih= $dtAkhir-$dtAwal; | |
$totalmenit=$dtSelisih/60; | |
$jam = explode(".", $totalmenit/60); | |
$sisamenit=($totalmenit/60)-$jam[0]; | |
$sisamenit2=$sisamenit*60; | |
$hasil= $jam[0]."jam".$sisamenit2."menit"; | |
return abs($hasil); | |
} | |
public function perhitunganLamaMenit($waktuMasuk,$waktuKeluar){ | |
list($h,$m,$s) = explode(":",$waktuMasuk); | |
$dtAwal = mktime($h,$m,$s,"1","1","1"); | |
list($h,$m,$s) = explode(":",$waktuKeluar); | |
$dtAkhir = mktime($h,$m,$s,"1","1","1"); | |
$dtSelisih = $dtAkhir-$dtAwal; | |
$totalmenit=$dtSelisih/60; | |
$jam =explode(".",$totalmenit/60); | |
$sisamenit=($totalmenit/60)-$jam[0]; | |
$sisamenit2=$sisamenit*60; | |
$jml_jam=$jam[0]; | |
return abs($totalmenit); | |
} | |
public function perhitunganBiaya($totalmenit,$jenis){ | |
if($jenis=="1"){//jenis 1 untuk motor | |
$nilaitukar=1000; | |
$hasilhitung=floor(($totalmenit/60)); | |
$hasil =$hasilhitung*$nilaitukar; | |
}else if($jenis=="2"){//jenis 2 untuk mobil | |
$nilaitukar2=3000; | |
$hasilhitung=floor(($totalmenit/60)); | |
$hasil =$hasilhitung*$nilaitukar2; | |
} | |
return $hasil; | |
} | |
public function chekOut($id,$filename = 'parkir.xml'){ | |
$data = simplexml_load_file($filename); | |
for($i = 0, $length = count($data->parkir); $i < $length; $i++){ | |
if($data->parkir[$i]->idparkir == $id){ | |
unset($data->parkir[$i]); | |
$hasil="sukses"; | |
break; | |
} | |
} | |
file_put_contents($filename, $data->saveXML()); | |
return $hasil; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment