Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

LECTURE NOTES

ISYS6307 – Data & Information


Management
Week 10

PHP Framework: Case Limitation of


Item Supplies
LEARNING OUTCOMES

LO 3 : Organize data in information as a necessity to make business decision support

OUTLINE MATERI :

1. Introduction

2. Model

3. View

4. Control

5. Dashboard
ISI MATERI

A. Introduction
Seiring dengan perkembangan teknologi, dan banyaknya programmer PHP yang
berkontribusi sehingga terjadi persamaan persepsi diantara programmer maka framework
programming PHP dapat diluncurkan. Framework PHP memiliki sifat MVC yang telah
dijelaskan pada materi sebelumnya.

B. Model
Supaya bahasa pemrograman bisa terkoneksi ke database pada framework
dinamakan model. Berikut contoh source model untuk master barang sebagai berikut:
<?php

/**
* This is the model class for table "barang".
*
* The followings are the available columns in table 'barang':
* @property string $kode_barang
* @property string $nama_barang
* @property integer $satuan
* @property integer $stok_akhir
* @property integer $harga
* @property integer $penggunaan_tahun
* @property integer $safety_stok
* @property integer $rop
* @property integer $eoq
*/
class Barang extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Barang the static model class

<<Kode mtk – Nama mtk>>


*/
public $jumlah;
public static function model($className=__CLASS__)
{
return parent::model($className);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
return 'barang';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those
attributes that
// will receive user inputs.
return array(
array('kode_barang, nama_barang, satuan,
stok_akhir, harga, penggunaan_tahun, safety_stok, rop, eoq',
'required'),
array('satuan, stok_akhir, harga,
penggunaan_tahun, safety_stok, rop, eoq', 'numerical',
'integerOnly'=>true),
array('kode_barang', 'length', 'max'=>25),
array('nama_barang', 'length', 'max'=>50),
// The following rule is used by search().
// Please remove those attributes that should
not be searched.

ISYS6307 – Data and Information Management


array('kode_barang, nama_barang, satuan,
stok_akhir, harga, penggunaan_tahun, safety_stok, rop, eoq', 'safe',
'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and
the related
// class name for the relations automatically
generated below.
return array(
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'kode_barang' => 'Kode Barang',
'nama_barang' => 'Nama Barang',
'satuan' => 'Satuan',
'stok_akhir' => 'Stok Akhir',
'harga' => 'Harga',
'penggunaan_tahun' => 'Penggunaan/Tahun',
'safety_stok' => 'Safety Stok',
'rop' => 'Rop',
'eoq' => 'Eoq',
);
}

ISYS6307 – Data and Information Management


/**
* Retrieves a list of models based on the current
search/filter conditions.
* @return CActiveDataProvider the data provider that can
return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to
remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('kode_barang',$this-
>kode_barang,true);
$criteria->compare('nama_barang',$this-
>nama_barang,true);
$criteria->compare('satuan',$this->satuan);
$criteria->compare('stok_akhir',$this->stok_akhir);
$criteria->compare('harga',$this->harga);
$criteria->compare('penggunaan_tahun',$this-
>penggunaan_tahun);
$criteria->compare('safety_stok',$this->safety_stok);
$criteria->compare('rop',$this->rop);
$criteria->compare('eoq',$this->eoq);

return new CActiveDataProvider($this, array(


'criteria'=>$criteria,
));
}
}

C. View
View pada framework terdiri dari beberapa file seperti file tampilan utama, file
form, dll. Source code untuk file index.php, sebagai berikut
<?php

ISYS6307 – Data and Information Management


/* @var $this BarangController */
/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(
'Barangs',
);

$this->menu=array(
array('label'=>'Create Barang', 'url'=>array('create')),
array('label'=>'Manage Barang', 'url'=>array('admin')),
);
?>

<h1>Barangs</h1>

<?php $this->widget('zii.widgets.CListView', array(


'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
Untuk viewnya sendiri sebagai berikut:
<?php
/* @var $this BarangController */
/* @var $model Barang */

$this->breadcrumbs=array(
'Barangs'=>array('index'),
$model->kode_barang,
);

$this->menu=array(
array('label'=>'List Barang', 'url'=>array('index')),
array('label'=>'Create Barang', 'url'=>array('create')),
array('label'=>'Update Barang', 'url'=>array('update',
'id'=>$model->kode_barang)),
array('label'=>'Delete Barang', 'url'=>'#',
'linkOptions'=>array('submit'=>array('delete','id'=>$model-

ISYS6307 – Data and Information Management


>kode_barang),'confirm'=>'Are you sure you want to delete this
item?')),
array('label'=>'Manage Barang', 'url'=>array('admin')),
);
?>

<h1>View Barang #<?php echo $model->kode_barang; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(


'data'=>$model,
'attributes'=>array(
'kode_barang',
'nama_barang',
'satuan',
'stok_akhir',
'harga',
'penggunaan_tahun',
'safety_stok',
'rop',
'eoq',
),
)); ?>

D. Control
Supaya data yang diinput melalui view memiliki validitas yang baik dan sesuai
dengan atribut tabelnya, diperlukan control. Salah satu control yang dibuat untuk barang
sebagai berikut:
<?php

class BarangController extends Controller


{
/**
* @var string the default layout for the views.
Defaults to '//layouts/column2', meaning

ISYS6307 – Data and Information Management


* using two-column layout. See
'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access
control for CRUD operations
'postOnly + delete', // we only allow
deletion via POST request
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl'
filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to
perform 'index' and 'view' actions

ISYS6307 – Data and Information Management


'actions'=>array('index','view','delete','manage','adm
in','create','update'),
'expression'=>'$user-
>getLevel()==1',
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

/**
* Displays a particular model.
* @param integer $id the ID of the model to be
displayed
*/
public function actionManage()
{
$this->layout = 'columna';
$model=new Barang('search');
$model->unsetAttributes(); // clear any
default values
if(isset($_GET['Barang']))
$model->attributes=$_GET['Barang'];

$this->render('manage',array(
'model'=>$model,
));
}

ISYS6307 – Data and Information Management


/**
* Displays a particular model.
* @param integer $id the ID of the model to be
displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be
redirected to the 'view' page.
*/
public function actionCreate()
{
$this->layout = 'columna';
$model=new Barang;
$bp=YII::app()->db->createCommand("SELECT
BIAYA_PEMESANAN FROM RULES LIMIT 1")->queryScalar();
$bpe=YII::app()->db->createCommand("SELECT
BIAYA_PENYIMPANAN FROM RULES LIMIT 1")->queryScalar();
$lt=YII::app()->db->createCommand("SELECT
LEAD_TIME FROM RULES LIMIT 1")->queryScalar();
// Uncomment the following line if AJAX
validation is needed
// $this->performAjaxValidation($model);

ISYS6307 – Data and Information Management


if(isset($_POST['Barang']))
{
$model->attributes=$_POST['Barang'];
$rop = $model->safety_stok + ($model-
>penggunaan_tahun/365) * $lt;
$model->rop = round($rop,
0,PHP_ROUND_HALF_UP);
$r_eoq = ( 2 * $model->penggunaan_tahun
* (($bp/100) * $model->harga)) / (($bpe/100) * $model-
>harga);
$model->eoq = round(sqrt($r_eoq), 0,
PHP_ROUND_HALF_UP);
if($model->save())
$this->redirect(array('manage'));
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be
redirected to the 'view' page.
* @param integer $id the ID of the model to be
updated
*/
public function actionUpdate($id)
{
$this->layout = 'columna';

ISYS6307 – Data and Information Management


$model=$this->loadModel($id);
$bp=YII::app()->db->createCommand("SELECT
BIAYA_PEMESANAN FROM RULES LIMIT 1")->queryScalar();
$bpe=YII::app()->db->createCommand("SELECT
BIAYA_PENYIMPANAN FROM RULES LIMIT 1")->queryScalar();
$lt=YII::app()->db->createCommand("SELECT
LEAD_TIME FROM RULES LIMIT 1")->queryScalar();

// Uncomment the following line if AJAX


validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Barang']))
{
$model->attributes=$_POST['Barang'];
$model->attributes=$_POST['Barang'];
$rop = $model->safety_stok + ($model-
>penggunaan_tahun/365) * $lt;
$model->rop = round($rop,
0,PHP_ROUND_HALF_UP);
$r_eoq = ( 2 * $model->penggunaan_tahun
* (($bp/100) * $model->harga)) / (($bpe/100) * $model-
>harga);
$model->eoq = round(sqrt($r_eoq), 0,
PHP_ROUND_HALF_UP);
if($model->save())
$this->redirect(array('manage'));
}

$this->render('update',array(
'model'=>$model,

ISYS6307 – Data and Information Management


));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be
redirected to the 'admin' page.
* @param integer $id the ID of the model to be
deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion


via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this-
>redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl']
: array('admin'));
}

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new
CActiveDataProvider('Barang');
$this->render('index',array(
'dataProvider'=>$dataProvider,

ISYS6307 – Data and Information Management


));
}

/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Barang('search');
$model->unsetAttributes(); // clear any
default values
if(isset($_GET['Barang']))
$model->attributes=$_GET['Barang'];

$this->render('admin',array(
'model'=>$model,
));
}

/**
* Returns the data model based on the primary
key given in the GET variable.
* If the data model is not found, an HTTP
exception will be raised.
* @param integer $id the ID of the model to be
loaded
* @return Barang the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{

ISYS6307 – Data and Information Management


$model=Barang::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The
requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param Barang $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) &&
$_POST['ajax']==='barang-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
E. Dashboard
Supaya memudahkan dalam pembacaan data lebih mudah dibuat informasi dalam
bentuk grafik atau dashboard. Sourcecodenya sebagai berikut:
<style type="text/css">
body{
font-family: Century Gothic,CenturyGothic,AppleGothic,sans-
serif !important;
}
</style>
<div class="indexx">

ISYS6307 – Data and Information Management


<div class="wrapper wrapper-content" style="padding: 20px 10px
10px;">
<!-- /.row -->

<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3><?php $tot=YII::app()->db-
>createCommand("SELECT COUNT(KODE_BARANG) from BARANG")->queryScalar();
echo $tot ?></h3>

<p>Barang</p>
</div>
<div class="icon">
<i class="fa fa-cubes"></i>
</div>
<a href="index.php?r=barang/manage" class="small-box-
footer">
Detail <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3><?php $tot2=YII::app()->db-
>createCommand("SELECT COUNT(KODE_BARANG) from BARANG_MASUK")-
>queryScalar();
echo $tot2 ?></h3>

<p>Barang Masuk</p>
</div>
<div class="icon">

ISYS6307 – Data and Information Management


<i class="fa fa-truck"></i>
</div>
<a href="index.php?r=barangMasuk/manage"
class="small-box-footer">
Detail <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3><?php $tot3=YII::app()->db-
>createCommand("SELECT COUNT(KODE_BARANG) from BARANG_KELUAR")-
>queryScalar();
echo $tot3?></h3>

<p>Barang Keluar</p>
</div>
<div class="icon">
<i class="fa fa-external-link"></i>
</div>
<a href="index.php?r=barangKeluar/manage"
class="small-box-footer">
Detail <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3><?php $tot4=YII::app()->db-
>createCommand("SELECT COUNT(USER_ID) from user")->queryScalar();
echo $tot4?></h3>

ISYS6307 – Data and Information Management


<p>Manajemen User</p>
</div>
<div class="icon">
<i class="fa fa-users"></i>
</div>
<a href="index.php?r=User/manage" class="small-box-
footer">
Detail <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
</div>
</div><!--index-->

<div class="row">
<div class="col-lg-8" style="padding-left:
25px;padding-right: 25px;">
<div class="panel panel-default">
<!-- /.panel-heading -->
<div class="panel-body">
<?php
$sqlbar="SELECT * FROM BARANG";
$rsqlbar=Barang::model()-
>findAllBySql("$sqlbar");
foreach ($rsqlbar as $rb) {
if ($rb->stok_akhir <= $rb->rop){ ?>
<div class="alert alert-warning"
style="margin-bottom: 5px;">
<strong>Warning!</strong> Barang dengan kode
<?php echo '<a href=index.php?r=barang/manage >'.$rb-
>kode_barang.'</a>' ?> harus di order kembali, <a
href="mailto:supplier@gmail.com">Klik</a> untuk email supplier!
</div>
<?php }else{

ISYS6307 – Data and Information Management


echo null;
}
}
?>
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
<div class="panel panel-default">
<!-- /.panel-heading -->
<div class="panel-body">
<thead>
<tr>
<?php
$label=array();
$nilai=array();

$sqll='SELECT KODE_BARANG FROM


BARANG';
$rsql=User::model()-
>findAllBySql("$sqll");

foreach ($rsql as $b=>$rsql1) {

$sql2="SELECT nama_barang,
stok_akhir AS jumlah FROM BARANG GROUP BY nama_barang";
$rsql2=Barang::model()-
>findAllBySql("$sql2");

foreach($rsql2 as $c=>$ck)
{
$label[$c]=$ck-
>nama_barang;
$nilai[$c]=(int)$ck-
>jumlah;

ISYS6307 – Data and Information Management


}
$this-
>widget('application.extensions.Highcharts.HighchartsWidget', array(
'options'=>array(
'chart'=>
array('defaultSeriesType'=>'column',),
'title' => array('text' =>
''),

'legend'=>array('enabled'=>true),

'xAxis'=>array('categories'=>$label,

'title'=>array('text'=>''),),
'yAxis'=> array(
'min'=> 0,
'title'=> array(
'text'=>'jumlah'
),
),
'series' => array(
array('data' => $nilai)
),
'tooltip' =>
array('formatter' => 'js:function(){ return "<b>"+this.point.name+"</b>
:"+this.y; }'),
'tooltip' => array(
'formatter' => 'js:function()
{return "<b>"+ this.x +"</b><br/>"+"Jumlah : "+ this.y; }'
),

'plotOptions'=>array('pie'=>(array(

'allowPointSelect'=>true,

'showInLegend'=>true,

ISYS6307 – Data and Information Management


'cursor'=>'pointer',
)
)
),

'credits'=>array('enabled'=>false),
)
));
?>
</tr>
</thead>
<!-- /.row -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-8 -->
<div class="col-lg-4">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-bell fa-fw"></i> 10 Barang
Masuk Terakhir
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="list-group">
<?php
$sqlf='SELECT * FROM BARANG_MASUK ORDER BY
TANGGAL DESC LIMIT 10';
$rsqlf=BarangMasuk::model()-
>findAllBySql("$sqlf");
foreach ($rsqlf as $rsqlf) {
?>
<a href="index.php?r=BarangMasuk/manage"
class="list-group-item" target="_blank">

ISYS6307 – Data and Information Management


<i class="fa fa-file fa-fw"></i> <?php
echo $rsqlf->kode_barang." (".$rsqlf->jumlah.")" ?>
<span class="pull-right text-muted
small"><em><?php echo $rsqlf->tanggal ?></em>
</span>
</a>
<?php } ?>
</div>
<!-- /.list-group -->
<a href="index.php?r=barangMasuk/manage"
class="btn btn-default btn-block">Lihat Semua Barang Masuk</a>
</div>
<!-- /.panel-body -->
</div>

<div class="chat-panel panel panel-info">


<div class="panel-heading">
<i class="fa fa-comments fa-fw"></i>
Aktivitas Admin
<div class="btn-group pull-right">
<button type="button" class="btn btn-
default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu slidedown"
style="color:#000000;">
<li>
<a href="#">
<i class="fa fa-refresh fa-fw"></i>
Refresh
</a>
</li>
<li>
<a href="#">
<i class="fa fa-check-circle fa-
fw"></i> Ada
</a>

ISYS6307 – Data and Information Management


</li>
<li>
<a href="#">
<i class="fa fa-times fa-fw"></i>
Sibuk
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<i class="fa fa-sign-out fa-fw"></i>
Keluar
</a>
</li>
</ul>
</div>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<ul class="chat">
<li class="left clearfix">
<span class="chat-img pull-left">
<img
src="http://placehold.it/50/55C1E7/fff" alt="User Avatar" class="img-
circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<strong class="primary-font">Mikha
Tanihatoe</strong>
<small class="pull-right text-muted">
<i class="fa fa-clock-o fa-fw"></i>
15 mins ago
</small>
</div>
<p>

ISYS6307 – Data and Information Management


Input Barang, input data Barang
Keluar terbaru.
</p>
</div>
</li>
<li class="right clearfix">
<span class="chat-img pull-right">
<img
src="http://placehold.it/50/FA6F57/fff" alt="User Avatar" class="img-
circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<small class=" text-muted">
<i class="fa fa-clock-o fa-fw"></i>
17 mins ago</small>
<strong class="pull-right primary-
font">Operator</strong>
</div>
<p>
Kelola Barang Masuk, maintenance
sistem, mengatur slider web yang tersendat karena javascript yang tidak
terbaca.
</p>
</div>
</li>
<li class="left clearfix">
<span class="chat-img pull-left">
<img
src="http://placehold.it/50/55C1E7/fff" alt="User Avatar" class="img-
circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<strong class="primary-font">Mikha
Tanihatoe</strong>

ISYS6307 – Data and Information Management


<small class="pull-right text-
muted">
<i class="fa fa-clock-o fa-
fw"></i> 56 mins ago</small>
</div>
<p>
perbaiki sistem yang bugs
meliputi : data barang masuk, data barang keluar, invoice, dll.
</p>
</div>
</li>
<li class="right clearfix">
<span class="chat-img pull-right">
<img
src="http://placehold.it/50/FA6F57/fff" alt="User Avatar" class="img-
circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<small class=" text-muted">
<i class="fa fa-clock-o fa-
fw"></i> 3 Days ago</small>
<strong class="pull-right
primary-font">Operator</strong>
</div>
<p>
Perbaikan koneksi database
postgre yang down.
</p>
</div>
</li>
</ul>
</div>
<!-- /.panel-body -->
<div class="panel-footer">
<div class="input-group">

ISYS6307 – Data and Information Management


<input id="btn-input" type="text"
class="form-control input-sm" placeholder="Type your message here..."
/>
<span class="input-group-btn">
<button class="btn btn-warning btn-
sm" id="btn-chat">
Send
</button>
</span>
</div>
</div>
<!-- /.panel-footer -->
</div>
<!-- /.panel .chat-panel -->
</div>
<!-- /.col-lg-4 -->
</div><br><br>
Adapun tampilannya sebagai berikut

Gambar 10.1

ISYS6307 – Data and Information Management


KESIMPULAN

1. PHP Framework memudahkan programmer dalam membuat aplikasi.


2. Contoh source code model digunakan untuk menghubungkan antara Bahasa
pemrograman ke database.
3. Contoh source code model digunakan untuk menghubungkan model dan view.
4. Contoh source code view digunakan untuk menampilkan data ke user view.

ISYS6307 – Data and Information Management


DAFTAR PUSTAKA

Doug Bierer, Altaf Hussain, Branko Ajzele. (2016). PHP 7: Real World Application
Development. Published by Packt Publishing Ltd. Livery Place 35 Livery Street. Birmingham
B3 2PB, UK. ISBN 978-1-78712-900-9

ISYS6307 – Data and Information Management

You might also like