Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***************************
- FILENAME : pln.php
- PURPOSE : calculate electric cost usage
- CREATED DATE : 2013-08-23
- UPDATED DATE :
- CREATED BY : CAHYA DSN
- ***************************/
- $data=array();
- $jenis_pilih=$type_daya=$pemakaian=0;
- if(isset($_POST['submit']))
- {
- $data=$_POST;
- $jenis_pilih=$data['jenis'];
- $type_daya=$data['daya'];
- $pemakaian=$data['pemakaian'];
- }
- $jenis=array('Pra Bayar','Pasca Bayar');
- $tarif=array(
- array('gol_tarif'=>'R-1/TR',
- 'batas_daya'=>'sd 450 VA',
- 'biaya_beban'=>11000,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>30,'biaya'=>169),
- 'blok2'=>array('min'=>30,'max'=>60,'biaya'=>460),
- 'blok3'=>array('min'=>60,'max'=>-1,'biaya'=>495)
- ),
- 'pra_bayar'=>415,
- 'rm'=>0),
- array('gol_tarif'=>'R-1/TR',
- 'batas_daya'=>'900 VA',
- 'biaya_beban'=>20000,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>20,'biaya'=>275),
- 'blok2'=>array('min'=>20,'max'=>60,'biaya'=>445),
- 'blok3'=>array('min'=>60,'max'=>-1,'biaya'=>495)
- ),
- 'pra_bayar'=>605,
- 'rm'=>0),
- array('gol_tarif'=>'R-1/TR',
- 'batas_daya'=>'1300 VA',
- 'biaya_beban'=>0,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>-1,'biaya'=>928)),
- 'pra_bayar'=>928,
- 'rm'=>37120),
- array('gol_tarif'=>'R-1/TR',
- 'batas_daya'=>'2200 VA',
- 'biaya_beban'=>0,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>-1,'biaya'=>947)),
- 'pra_bayar'=>947,
- 'rm'=>37880),
- array('gol_tarif'=>'R-2/TR',
- 'batas_daya'=>'3500 sd 5500 VA',
- 'biaya_beban'=>0,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>-1,'biaya'=>1075)),
- 'pra_bayar'=>1075,
- 'rm'=>43000),
- array('gol_tarif'=>'R-3/TR',
- 'batas_daya'=>'6600 VA ke atas',
- 'biaya_beban'=>20000,
- 'biaya_pemakaian'=>array('blok1'=>array('min'=>0,'max'=>55,'biaya'=>1290),
- 'blok2'=>array('min'=>55,'max'=>-1,'biaya'=>1380)
- ),
- 'pra_bayar'=>1347,
- 'rm'=>51600)
- );
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Tarif Listrik</title>
- <style>
- * {font-family:verdana,arial,sans-serif;font-size:12px;}
- input,select {background-color:#ffc;border:solid 1px #999;}
- .kwh {width:50px;text-align:right;}
- .navigasi {background-color:#ccf;text-align:right;}
- .tombol{height: 25px;width:60px;-moz-border-radius: 4px;border-radius: 4px;}
- table {boder:solid 1px #999;padding:2px;}
- th {background-color:#ccc;padding:2px;}
- </style>
- </head>
- <body>
- <form method='post'>
- <table>
- <tr>
- <th colspan='2'>HITUNG PEMAKAIAN LISTRIK</th>
- </tr>
- <tr>
- <td>
- Daya
- </td>
- <td>
- <select name='daya' id='daya'>
- <?php
- $i=-1;
- foreach($tarif as $dt)
- {
- echo "<option value='".++$i."'".($i==$type_daya?" selected='selected'":"").">"
- .$dt['batas_daya']
- ."</option>\n";
- }
- ?>
- </select>
- </td>
- </tr>
- <tr>
- <td>
- Jenis
- </td>
- <td>
- <select name='jenis' id='jenis'>
- <?php
- $i=-1;
- foreach($jenis as $dt)
- {
- echo "<option value='".++$i."'".($i==$jenis_pilih?" selected='selected'":"").">{$dt}</option>\n";
- }
- ?>
- </select>
- </td>
- </tr>
- <tr>
- <td>
- Pemakaian
- </td>
- <td>
- <input type='text' name='pemakaian' id='pemakaian'
- value='<?php echo empty($pemakaian)?'':$pemakaian;?>' class='kwh' /> kWh
- </td>
- </tr>
- <tr class='navigasi'>
- <td colspan='2'>
- <input type='submit' name='submit' value='hitung' class='tombol'/>
- </td>
- </tr>
- </table>
- </form>
- <?php
- $jumlah=0;
- $biaya=array();
- $harga=0;
- if($jenis_pilih==0){
- $jumlah=$pemakaian*$tarif[$data['daya']]['pra_bayar'];
- }
- else
- {
- $biaya=$tarif[$data['daya']]['biaya_pemakaian'];
- foreach($biaya as $byr)
- {
- if($byr['max']==-1){
- if($pemakaian>$byr['min'])
- $harga=$byr['biaya'];
- }
- else
- {
- if($pemakaian>$byr['min'] && $pemakaian<=$byr['max'])
- $harga=$byr['biaya'];
- }
- }
- $jumlah=$pemakaian*$harga+$tarif[$data['daya']]['biaya_beban'];
- $jumlah=$jumlah<$tarif[$data['daya']]['rm']?$tarif[$data['daya']]['rm']:$jumlah;
- }
- $hasil=array('gol_tarif'=>$tarif[$data['daya']]['gol_tarif'],
- 'type daya'=>$tarif[$data['daya']]['batas_daya'],
- 'jenis'=>$jenis[$jenis_pilih],
- 'pemakaian'=>$pemakaian.' kWh',
- 'jumlah'=>'Rp.'.number_format($jumlah));
- ?>
- <pre>
- <?php
- print_r($hasil);
- ?>
- </pre>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement