Anda di halaman 1dari 372

BAB 5

Mega Proyek 75 Juta Aplikasi


Inventory Berbasis Web

Wah.. pasti kalian langsung buka halaman ini ya?.. ngaku … kalian penasaran
dengan Mega Proyek 75 Juta??.. yukk.. penulis bahas secara gambling baik cara
membuat maupun cara penggunaannya.
Disini kita akan menggunakan smarty php dalam membangun aplikasi, untuk
tahu bagaimana penggunaan menggunakan smarty php dan apa itu smarty php,
penulis telah menyediakan FREE EBOOK yang bisa Anda temukan pada CD
terlampir.
Sebelum masuk ke dalam pembahasan membangun aplikasi mega proyek, buat
terlebih dahulu file dengan nama header.php yang skripnya sebagai berikut :

<?php
date_default_timezone_set('ASIA/JAKARTA');
error_reporting(0);
session_start();
// include all files are required
include "includes/connection.php";
include "includes/debug.php";
include "includes/page_function.php";
include "includes/fungsi_rupiah.php";
include "includes/fungsi_indotgl.php";

require('libs/Smarty.class.php');

// create new object


$smarty = new Smarty;

$year = date('Y');

// staff detail
$queryUser = "SELECT lastLogin, photo FROM as_staffs WHERE staffID
= '$_SESSION[staffID]'";
$sqlUser = mysqli_query($connect, $queryUser);

// fetch data
$dtUser = mysqli_fetch_array($sqlUser);

$queryAuthorize = "SELECT * FROM as_modules WHERE status = 'Y'";

1
$sqlAuthorize = mysqli_query($connect, $queryAuthorize);

while ($dtAuthorize = mysqli_fetch_array($sqlAuthorize))


{
$dataAuthorize[] = array( 'modulID' =>
$dtAuthorize['modulID'],

'authorize' => $dtAuthorize['authorize']);


}
$smarty->assign("dataAuthorize", $dataAuthorize);

// session login info


$smarty->assign("loginStaffName", $_SESSION['staffName']);
$smarty->assign("loginStaffNickName", $_SESSION['staffNickName']);
$smarty->assign("loginStaffPosition", $_SESSION['position']);
$smarty->assign("loginLastLogin", $dtUser['lastLogin']);
$smarty->assign("loginPhoto", $dtUser['photo']);
$smarty->assign("loginStaffLevel", $_SESSION['level']);
?>

Nah.. dalam file header.php banyak sekali perintah memanggil (include) file php
lainnya.. untuk hal tersebut Anda bisa temukan filenya pada cd terlampir, yaitu
pada folder Final Project/inventory/includes.
Selanjutnya kita langsung saja masuk ke dalam pembahasan inti.

5.1 Master Data


Master data biasanya dianggap sebagai pusat data.. karena apa?.. karena jika
tidak ada master data, maka aktifitas lain tidak berjalan.. secara, bagaimana kita
ingin melakukan transaksi penjualan jika data produknya (master data) saja
belum kita input? Untuk itu, pada sub bab ini kita akan bahas tuntas mengenai
master data.

5.1.1 Staff
Master data staff digunakan untuk menyimpan seluruh daftar staff perusahaan,
dari sini lah pengguna mendapatkan username dan password untuk masuk ke
dalam aplikasi inventory. Kita akan langsung membuat seluruh fungsi (create,
read, update, delete) dalam 1 file.
Buat file dengan nama staffs.php, adapun skripnya sebagai berikut :

<?php
// include header
include "header.php";
// set the tpl page
$page = "staffs.tpl";

2
$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '1'";
$sqlAuthorizeStaff = mysqli_query($connect,
$queryAuthorizeStaff);
$dataAuthorizeStaff =
mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'],
$_SESSION['level']) === FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is staff and action is delete


if ($module == 'staff' && $act == 'delete')
{
// insert method into a variable
$staffID = $_GET['staffID'];

// delete staff
$queryStaff = "DELETE FROM as_staffs WHERE staffID = '$staffID'";
$sqlStaff = mysqli_query($connect, $queryStaff);

// redirect to the staff page


header("Location: staffs.php?msg=Data staff berhasil dihapus");
} // close bracket

// if the module is staff and action is search


elseif ($module == 'staff' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

if ($q != '')
{
$queryStaff = "SELECT * FROM as_staffs WHERE
staffCode LIKE '%$q%' OR staffName LIKE '%$q%' AND staffID != '1'
ORDER BY staffName ASC";
}
else
{
$queryStaff = "SELECT * FROM as_staffs WHERE
staffID != '' ORDER BY staffName ASC";
}

3
$sqlStaff = mysqli_query($connect, $queryStaff);

// fetch data
$i = 1;
while ($dtStaff = mysqli_fetch_array($sqlStaff))
{
if ($dtStaff['level'] == '1')
{
$level = "ADMINISTRATOR";
}
elseif ($dtStaff['level'] == '2')
{
$level = "SALES";
}
elseif ($dtStaff['level'] == '3')
{
$level = "KASIR";
}
elseif ($dtStaff['level'] == '4')
{
$level = "SPV";
}
elseif ($dtStaff['level'] == '5')
{
$level = "TOP";
}
else
{
$level = "-";
}

$dataStaff[] = array( 'staffID' => $dtStaff['staffID'],


'staffCode' => $dtStaff['staffCode'],
'staffName' => $dtStaff['staffName'],
'address' => $dtStaff['address'],
'phone' => $dtStaff['phone'],
'position' => $dtStaff['position'],
'status' => $dtStaff['status'],
'level' => $level,
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataStaff", $dataStaff);
$smarty->assign("q", $q);
}

// if module is staff and action is delete photo


elseif ($module == 'staff' && $act == 'deletephoto')
{
$staffID = $_GET['staffID'];
$photo = $_GET['photo'];

$queryStaff = "UPDATE as_staffs SET photo = '' WHERE


staffID = '$staffID'";
$sqlStaff = mysqli_query($connect, $queryStaff);

4
if ($sqlStaff)
{
unlink("img/staffs/".$photo);
unlink("img/staffs/thumb/small_".$photo);
}

// redirect to the staff page


header("Location: staffs.php?msg=Foto staff berhasil dihapus");
}

else
{
// create new object pagination
$p = new PaginationStaff;
// limit 20 data for page
$limit = 20;
$position = $p->searchPosition($limit);

// showing up the staff data


$queryStaff = "SELECT * FROM as_staffs WHERE staffID !=
'1' ORDER BY staffCode ASC LIMIT $position,$limit";
$sqlStaff = mysqli_query($connect, $queryStaff);

// fetch data
$i = 1 + $position;
while ($dtStaff = mysqli_fetch_array($sqlStaff))
{
if ($dtStaff['level'] == '1')
{
$level = "ADMINISTRATOR";
}
elseif ($dtStaff['level'] == '2')
{
$level = "SALES";
}
elseif ($dtStaff['level'] == '3')
{
$level = "KASIR";
}
elseif ($dtStaff['level'] == '4')
{
$level = "SPV";
}
elseif ($dtStaff['level'] == '5')
{
$level = "TOP";
}
else
{
$level = "-";
}

$dataStaff[] = array( 'staffID' => $dtStaff['staffID'],


'staffCode' => $dtStaff['staffCode'],
'staffName' => $dtStaff['staffName'],
'address' => $dtStaff['address'],

5
'phone' => $dtStaff['phone'],
'position' => $dtStaff['position'],
'status' => $dtStaff['status'],
'level' => $level,
'no' => $i);
$i++;
}

$smarty->assign("dataStaff", $dataStaff);

// count data
$queryCountStaff = "SELECT * FROM as_staffs";
$sqlCountStaff = mysqli_query($connect, $queryCountStaff);
$amountData = mysqli_num_rows($sqlCountStaff);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);

// set module
$queryModule = "SELECT * FROM as_modules WHERE status =
'Y' ORDER BY modulName ASC";
$sqlModule = mysqli_query($connect, $queryModule);

// fetch data
$k = 1;
while ($dtModule = mysqli_fetch_array($sqlModule))
{
$dataModule[] = array( 'moduleID' => $dtModule['modulID'],
'moduleName' => $dtModule['modulName'],
'no' => $k);
$k++;
}

$smarty->assign("dataModule", $dataModule);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Staff");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan pengolahan data master staff atau pegawai.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Staff");
}

// include footer
include "footer.php";
?>

Selanjutnya buat file dengan nama staffs.tpl dan simpan dalam folder templates,
adapun skripnya sebagai berikut :

{include file="header.tpl"}

6
<link rel="stylesheet" type="text/css" media="all"
href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery.
fancybox.js?v=2.0.6"></script>

<script type="text/javascript" src="design/js/ajaxupload.3.5.js" >


</script>
<link rel="stylesheet" type="text/css" href="design/css/Ajaxfile-
upload.css" />

{literal}
<script>
$(document).ready(function() {

$('.dropdown-menu').on('click', function(e) {
if($(this).hasClass('dropdown-menu-form')) {
e.stopPropagation();
}
});

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

// Image 1
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'upload_staff.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|jpeg)$/.test(ext))){
// extension is not allowed
mestatus.text('Hanya ekstensi .JPG/JPEG yang diijinkan.');
return false;
}
//mestatus.html('<img src="images/ajax-loader.gif"
height="16" width="16">');
mestatus.html('');
},
onComplete: function(file, response){
//On completion clear the status
mestatus.text('');
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response!=="error"){

7
$('<li></li>').appendTo('#files').html('<img
src="img/staffs/'+response+'" alt="" height="100"/><br
/>').addClass('success');

$('<li></li>').appendTo('#photostaff').html('<input
type="hidden" id="photo" name="photo"
value="'+response+'">').addClass('nameupload');

} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#staff").submit(function() { return false; });


$("#staff2").submit(function() { return false; });

$("#send").on("click", function(){
var staffCode = $("#staffCode").val();
var staffName = $("#staffName").val();
var address = $("#address").val();
var address2 = $("#address2").val();
var village = $("#village").val();
var district = $("#district").val();
var city = $("#city").val();
var zipCode = $("#zipCode").val();
var province = $("#province").val();
var phone = $("#phone").val();
var position = $("#position").val();
var part = $("#part").val();
var statusStaff = $("#statusStaff").val();
var level = $("#level").val();
var photo = $("#photo").val();
var email = $("#email").val();
var password = $("#password").val();

if (staffCode != '' && staffName != '' && statusStaff !=


'' && level != '' && email != '' && password != ''){

$.ajax({
type: 'POST',
url: 'save_staff.php',
dataType: 'JSON',
data:{
staffCode: staffCode,
staffName: staffName,
address: address,
address2: address2,
village: village,
district: district,
city: city,
zipCode: zipCode,
province: province,
phone: phone,

8
position: position,
part: part,
statusStaff: statusStaff,
level: level,
photo: photo,
email: email,
password: password
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "staffs.php?msg=Data berhasil disimpan";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">

{include file="user_panel.tpl"}

{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<!-- Right side column. Contains the navbar and content of the
page -->
<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

9
<!-- TO DO List -->
<div class="box box-primary">
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Staff / Pegawai</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">

<form method="GET" action="staffs.php">


<input type="hidden" name="module" value="staff">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>

<input type="text" value="{$q}" id="q" name="q"


class="form-control" placeholder="Pencarian : Kode atau Nama
Staff" style="float: right; width: 270px;" required>

<a href="#inline" class="modalbox" style="float:


left;"><button class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>

<a href="print_staffs.php?act=print&q={$q}" style="float:


left;" target="_blank"><button type="button" class="btn btn-
default pull-right"><i class="fa fa-print"></i> Print
PDF</button></a>

&nbsp;&nbsp;&nbsp;
</form>

</div>
</div>
</div><!-- /.box-header -->

{if $module == 'staff' AND $act == 'search'}

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">

<thead>
<tr>
<th>NO</th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA STAFF <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>POSITION <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>LEVEL <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>

</thead>

<tbody>

10
{section name=dataStaff loop=$dataStaff}
<tr>
<td>{$dataStaff[dataStaff].no}</td>
<td>{$dataStaff[dataStaff].staffCode}</td>
<td>{$dataStaff[dataStaff].staffName}</td>
<td>{$dataStaff[dataStaff].phone}</td>
<td>{$dataStaff[dataStaff].position}</td>
<td>{$dataStaff[dataStaff].status}</td>
<td>{$dataStaff[dataStaff].level}</td>
<td>
<a title="Edit" href="edit_staffs.php?module=staff&act=edit&
staffID={$dataStaff[dataStaff].staffID}" data-width="900" data-
height="420" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>

<a title="Delete" href="staffs.php?module=staff&act=delete&


staffID={$dataStaff[dataStaff].staffID}" onclick="return
confirm('Anda Yakin ingin menghapus staff
{$dataStaff[dataStaff].staffName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>

{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


{else}
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA STAFF <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>POSITION <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>LEVEL <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>
</thead>

<tbody>
{section name=dataStaff loop=$dataStaff}
<tr>
<td>{$dataStaff[dataStaff].no}</td>
<td>{$dataStaff[dataStaff].staffCode}</td>
<td>{$dataStaff[dataStaff].staffName}</td>
<td>{$dataStaff[dataStaff].phone}</td>
<td>{$dataStaff[dataStaff].position}</td>
<td>{$dataStaff[dataStaff].status}</td>
<td>{$dataStaff[dataStaff].level}</td>

11
<td>
<a title="Edit" href="edit_staffs.php?module=staff&act=edit&
staffID={$dataStaff[dataStaff].staffID}" data-width="900" data-
height="420" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="staffs.php?module=staff&act=delete&
staffID={$dataStaff[dataStaff].staffID}" onclick="return
confirm('Anda Yakin ingin menghapus staff
{$dataStaff[dataStaff].staffName}?');"><img
src="img/icons/delete.png" width="18"></a>

</td>
</tr>
{/section}
</tbody>

</table>
</div>

</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td align="center"><h3><b>DATABASE STAFF</b></h3></td>
</tr>
<tr>
<td>
<form id="staff" name="staff" method="POST" action="#">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="170">Kode</td>
<td width="5">:</td>
<td><input type="text" id="staffCode"
name="staffCode" class="form-control" placeholder="Kode Staff"
style="width: 270px;" required></td>
<td width="50"></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>DATA PRIBADI</b></span></td>
<td></td>
<td colspan="3"><span style="font-size:
16px;"><b>DATA PERUSAHAAN</b></span></td>
</tr>

12
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Nama Lengkap</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="staffName"
name="staffName" class="form-control" placeholder="Nama Staff"
style="width: 270px;" required></td>
<td></td>
<td>Jabatan</td>
<td>:</td>
<td><input type="text" id="position"
name="position" class="form-control" placeholder="Jabatan /
Posisi" style="width: 270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Alamat 1</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="address"
name="address" class="form-control" placeholder="Alamat 1"
style="width: 270px;"></td>
<td></td>
<td>Bagian</td>
<td>:</td>
<td><input type="text" id="part" name="part" class="form-
control" placeholder="Bagian" style="width: 270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Alamat 2</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="address2"
name="address2" class="form-control" placeholder="Alamat 2"
style="width: 270px;"></td>
<td></td>
<td>Level</td>
<td>:</td>
<td>
<select id="level" name="level" class="form-control"
style="width: 270px;" required>
<option value=""></option>
<option value="1">Administrator</option>
<option value="2">Sales</option>
<option value="3">Kasir</option>
<option value="4">SPV</option>
<option value="5">Top</option>
</select>
</td>
</tr>

<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Kelurahan</td>
<td style="background-color: #FFFFFF;">:</td>

13
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="village"
name="village" class="form-control" placeholder="Kelurahan"
style="width: 270px;"></td>
<td></td>
<td>Status</td>
<td>:</td>
<td>
<select id="statusStaff" name="statusStaff"
class="form-control" style="width: 270px;" required>
<option value=""></option>
<option value="Y">Y [Aktif]</option>
<option value="N">N [Tidak Aktif]</option>
</select>
</td>
</tr>

<tr valign="top">
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Kecamatan</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="district"
name="district" class="form-control" placeholder="Kecamatan"
style="width: 270px;"></td>
<td></td>
<td>Password</td>
<td>:</td>
<td><input type="text" value="123456" id="password"
name="password" class="form-control" placeholder="Password"
style="width: 270px;" required></td>
</tr>
<tr valign="top">
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Kota</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="city" name="city" class="form-
control" placeholder="Kota" style="width: 270px;"></td>
<td></td>
<td>Photo</td>
<td>:</td>
<td rowspan="4">
<div id="me" class="styleall" style="cursor:pointer;">
<label>
<button class="btn btn-warning">Browse</button>
</label>
</div>
<span id="mestatus"></span>
<div id="photostaff">
<li class="nameupload"></li>
</div>
<div id="files">
<li class="success"></li>
</div>

</td>

14
</tr>
<tr valign="top">
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Kode Pos</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="number" id="zipCode" name="zipCode"
class="form-control" placeholder="Kode Pos" style="width:
270px;"></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Propinsi</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="province"
name="province" class="form-control" placeholder="Propinsi"
style="width: 270px;"></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Telp / HP</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="phone" name="phone"
class="form-control" placeholder="Nomor Telepon Staff"
style="width: 270px;"></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; border-bottom:
1px solid #000000; background-color: #FFFFFF;">Email</td>
<td style="border-bottom: 1px solid #000000; background-
color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; border-bottom:
1px solid #000000; background-color: #FFFFFF;"><input type="email"
id="email" name="email" class="form-control" placeholder="Email"
style="width: 270px;" required></td>
<td></td>
<td colspan="3"></td>
</tr>
</table>
<br>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>
{/if}
</div><!-- /.box -->
</section><!-- /.Left col -->

15
</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Proses simpan staff ini berjalan secara Ajax dan JSON, untuk itu kita buat file
untuk proses simpan, Buat file dengan nama save_staff.php, adapun skripnya
sebagai berikut :

<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$staffCode = mysqli_real_escape_string($connect,
$_POST['staffCode']);
$staffName = mysqli_real_escape_string($connect,
$_POST['staffName']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$address2 = mysqli_real_escape_string($connect,
$_POST['address2']);
$village = mysqli_real_escape_string($connect, $_POST['village']);
$district = mysqli_real_escape_string($connect,
$_POST['district']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$zipCode = $_POST['zipCode'];
$province = mysqli_real_escape_string($connect,
$_POST['province']);
$phone = mysqli_real_escape_string($connect, $_POST['phone']);
$position = mysqli_real_escape_string($connect,
$_POST['position']);
$part = mysqli_real_escape_string($connect, $_POST['part']);
$statusStaff = $_POST['statusStaff'];
$level = $_POST['level'];
$photo = $_POST['photo'];
//$authorize = $_POST['authorize'];
//$authorizeTotal = COUNT($authorize);
$email = mysqli_real_escape_string($connect, $_POST['email']);
$password = md5($_POST['password']);

for ($i = 0; $i < $authorizeTotal; $i++)


{
if ($i == 0)
{
$auto .= "-".$authorize[$i]."-";
}
else
{
$auto .= $authorize[$i]."-";
}
}

16
if ($staffCode != '' && $staffName != '' && $statusStaff != '' &&
$level != '' && $email != '' && $password != ''){

// set photo to thumbnail


if ($photo != '')
{
$file = "img/staffs/".$photo;
$realPic = imagecreatefromjpeg($file);
$width = imagesx($realPic);
$height = imagesy($realPic);

$thumbWidth = 70;
$thumbHeight = 100;
$thumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbPic, $realPic, 0, 0, 0, 0, $thumbWidth,
$thumbHeight, $width, $height);

imagejpeg($thumbPic, "img/staffs/thumb/small_".$photo);
imagedestroy($realPic);
imagedestroy($thumbPic);
} // close bracket

$queryStaff = "INSERT INTO as_staffs( staffCode,


staffName,
address,
address2,
village,
district,
city,
zipCode,
province,
phone,
position,
part,
status,
level,
photo,
email,
password,
lastLogin,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$staffCode',
'$staffName',
'$address',
'$address2',
'$village',
'$district',
'$city',
'$zipCode',
'$province',
'$phone',
'$position',
'$part',
'$statusStaff',

17
'$level',
'$photo',
'$email',
'$password',
'',
'$createdDate',
'$staffID',
'',
'')";

$sqlStaff = mysqli_query($connect, $queryStaff);

if ($sqlStaff)
{
echo json_encode(OK);
}
}
exit();
?>

Selanjutnya buat 3 buah file untuk proses edit, diantaranya edit_staff.php,


save_edit_staff.php dan edit_staff.tpl (simpan dalam folder templates),
adapun masig-masing skripnya sebagai berikut :
edit_staffs.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_staffs.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'staff' && $act == 'edit')


{
// insert method into a variable
$staffID = $_GET['staffID'];

// showing up the staff data based on staff id


$queryStaff = "SELECT * FROM as_staffs WHERE
staffID = '$staffID'";
$sqlStaff = mysqli_query($connect, $queryStaff);

18
// fetch data
$dataStaff = mysqli_fetch_array($sqlStaff);

// assign fetch data to the tpl


$smarty->assign("staffID", $dataStaff['staffID']);
$smarty->assign("staffCode", $dataStaff['staffCode']);
$smarty->assign("staffName", $dataStaff['staffName']);
$smarty->assign("address", $dataStaff['address']);
$smarty->assign("address2", $dataStaff['address2']);
$smarty->assign("village", $dataStaff['village']);
$smarty->assign("district", $dataStaff['district']);
$smarty->assign("city", $dataStaff['city']);
$smarty->assign("zipCode", $dataStaff['zipCode']);
$smarty->assign("province", $dataStaff['province']);
$smarty->assign("phone", $dataStaff['phone']);
$smarty->assign("position", $dataStaff['position']);
$smarty->assign("part", $dataStaff['part']);
$smarty->assign("statusStaff", $dataStaff['status']);
$smarty->assign("level", $dataStaff['level']);
$smarty->assign("photo", $dataStaff['photo']);
$smarty->assign("email", $dataStaff['email']);
//close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

save_edit_staff.php
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$staffID2 = $_POST['staffID2'];
$staffCode = $_POST['staffCode'];
$staffName = mysqli_real_escape_string($connect,
$_POST['staffName']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$address2 = mysqli_real_escape_string($connect,
$_POST['address2']);
$village = mysqli_real_escape_string($connect, $_POST['village']);
$district = mysqli_real_escape_string($connect,
$_POST['district']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$zipCode = $_POST['zipCode'];
$province = mysqli_real_escape_string($connect,

19
$_POST['province']);
$phone = mysqli_real_escape_string($connect, $_POST['phone']);
$position = mysqli_real_escape_string($connect,
$_POST['position']);
$part = mysqli_real_escape_string($connect, $_POST['part']);
$statusStaff = $_POST['statusStaff'];
$level = $_POST['level'];
$photo = $_POST['photo'];
$foto = $_POST['foto'];
$email = mysqli_real_escape_string($connect, $_POST['email']);
$password = $_POST['password'];

if ($staffID2 != '' && $staffCode != '' && $staffName != '' &&


$statusStaff != '' && $level != '' && $email != ''){

// set photo to thumbnail


if ($photo != '')
{
unlink("img/staffs/".$foto);
unlink("img/staffs/thumb/small_".$foto);

$file = "img/staffs/".$photo;
$realPic = imagecreatefromjpeg($file);
$width = imagesx($realPic);
$height = imagesy($realPic);

$thumbWidth = 70;
$thumbHeight = 100;

$thumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);


imagecopyresampled($thumbPic, $realPic, 0, 0, 0, 0, $thumbWidth,
$thumbHeight, $width, $height);

imagejpeg($thumbPic, "img/staffs/thumb/small_".$photo);

imagedestroy($realPic);
imagedestroy($thumbPic);

if ($password != '')
{
$passwd = md5($password);
$queryStaff = "UPDATE as_staffs SET staffCode = '$staffCode',
staffName = '$staffName',
address = '$address',
address2 = '$address2',
village = '$village',
district = '$district',
city = '$city',
zipCode = '$zipCode',
province = '$province',
phone = '$phone',
position = '$position',
part = '$part',
status = '$statusStaff',
level = '$level',
photo = '$photo',
email = '$email',

20
password = '$passwd',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE staffID = '$staffID2'";
}
else
{
$queryStaff = "UPDATE as_staffs SET staffCode = '$staffCode',
staffName = '$staffName',
address = '$address',
address2 = '$address2',
village = '$village',
district = '$district',
city = '$city',
zipCode = '$zipCode',
province = '$province',
phone = '$phone',
position = '$position',
part = '$part',
status = '$statusStaff',
level = '$level',
photo = '$photo',
email = '$email',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE staffID = '$staffID2'";
}
}

else
{
if ($password != '')
{
$passwd = md5($password);

$queryStaff = "UPDATE as_staffs SET staffCode = '$staffCode',


staffName = '$staffName',
address = '$address',
address2 = '$address2',
village = '$village',
district = '$district',
city = '$city',
zipCode = '$zipCode',
province = '$province',
phone = '$phone',
position = '$position',
part = '$part',
status = '$statusStaff',
level = '$level',
email = '$email',
password = '$passwd',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE staffID = '$staffID2'";
}
else
{

21
$queryStaff = "UPDATE as_staffs SET staffCode = '$staffCode',
staffName = '$staffName',
address = '$address',
address2 = '$address2',
village = '$village',
district = '$district',
city = '$city',
zipCode = '$zipCode',
province = '$province',
phone = '$phone',
position = '$position',
part = '$part',
status = '$statusStaff',
level = '$level',
email = '$email',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE staffID = '$staffID2'";
}
}

$sqlStaff = mysqli_query($connect, $queryStaff);

if ($sqlStaff)
{
echo json_encode(OK);
}
}
exit();
?>

edit_staffs.tpl

<script src="design/js/jquery-1.8.1.min.js" type="text/


javascript"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<script type="text/javascript" src="design/js/ajaxupload.3.5.js"


></script>
<link rel="stylesheet" type="text/css" href="design/css/Ajaxfile-
upload.css" />

<body style='background-color: #EEE; color: #333;'>


{literal}
<script>
$(document).ready(function() {

22
$('.dropdown-menu').on('click', function(e) {
if($(this).hasClass('dropdown-menu-form')) {
e.stopPropagation();
}
});

$("#staff").submit(function() { return false; });

// Image 1
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'upload_staff.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|jpeg)$/.test(ext))){
// extension is not allowed
mestatus.text('Hanya ekstensi .JPG/JPEG yang diijinkan.');
return false;
}
//mestatus.html('<img src="images/ajax-loader.gif" height="16"
width="16">');
mestatus.html('');
},
onComplete: function(file, response){
//On completion clear the status
mestatus.text('');
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response!=="error"){
$('<li></li>').appendTo('#files').html('<img
src="img/staffs/'+response+'" alt="" height="100"/><br
/>').addClass('success');

$('<li></li>').appendTo('#photostaff').html('<input
type="hidden" id="photo" name="photo"
value="'+response+'">').addClass('nameupload');
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});

$("#deletephoto").on("click", function(){
parent.jQuery.fancybox.close();
});

$("#send").on("click", function(){
var staffID2 = $("#staffID2").val();
var staffCode = $("#staffCode").val();
var staffName = $("#staffName").val();
var address = $("#address").val();
var address2 = $("#address2").val();
var village = $("#village").val();
var district = $("#district").val();

23
var city = $("#city").val();
var zipCode = $("#zipCode").val();
var province = $("#province").val();
var phone = $("#phone").val();
var position = $("#position").val();
var part = $("#part").val();
var statusStaff = $("#statusStaff").val();
var level = $("#level").val();
var photo = $("#photo").val();
var email = $("#email").val();
var password = $("#password").val();

if (staffID2 != '' && staffCode != '' && staffName


!= '' && statusStaff != '' && level != '' && email != ''){

$.ajax({
type: 'POST',
url: 'save_edit_staff.php',
dataType: 'JSON',
data:{
staffID2: staffID2,
staffCode: staffCode,
staffName: staffName,
address: address,
address2: address2,
village: village,
district: district,
city: city,
zipCode: zipCode,
province: province,
phone: phone,
position: position,
part: part,
statusStaff: statusStaff,
level: level,
photo: photo,
email: email,
password: password
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'staff' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td align="center"><h3><b>DATABASE STAFF</b></h3></td>
</tr>

24
<tr>
<td>
<form id="staff" name="staff" method="POST" action="#">
<input type="hidden" id="staffID2" name="staffID2"
value="{$staffID}">
<input type="hidden" id="foto" name="foto" value="{$photo}">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130" style="font-size: 14px;">Kode</td>
<td width="5" style="font-size: 14px;">:</td>
<td><input type="text" value="{$staffCode}"
id="staffCode" name="staffCode" class="form-control"
placeholder="Kode Customer" style="width: 270px;" required></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>DATA PRIBADI</b></span></td>
<td width="50"></td>
<td colspan="3"><span style="font-size:
16px;"><b>DATA PERUSAHAAN</b></span></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Nama Lengkap</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="staffName"
value="{$staffName}" name="staffName" class="form-control"
placeholder="Nama Staff" style="width: 270px;" required></td>
<td></td>
<td style="font-size: 14px;">Jabatan</td>
<td style="font-size: 14px;">:</td>
<td><input type="text" id="position"
value="{$position}" name="position" class="form-control"
placeholder="Jabatan / Posisi" style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Alamat 1</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="address"
value="{$address}" name="address" class="form-control"
placeholder="Alamat 1" style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px;">Bagian</td>
<td style="font-size: 14px;">:</td>
<td><input type="text" id="part" value="{$part}"
name="part" class="form-control" placeholder="Bagian"
style="width: 270px;"></td>
</tr>
<tr>

25
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Alamat 2</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="address2"
value="{$address2}" name="address2" class="form-control"
placeholder="Alamat 2" style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px;">Level</td>
<td style="font-size: 14px;">:</td>
<td>
<select id="level" name="level" class="form-control"
style="width: 270px;" required>
<option value=""></option>
<option value="1" {if $level == '1'} SELECTED
{/if}>Administrator</option>
<option value="2" {if $level == '2'} SELECTED {/if}>Sales</option>
<option value="3" {if $level == '3'} SELECTED {/if}>Kasir</option>
<option value="4" {if $level == '4'} SELECTED {/if}>SPV</option>
<option value="5" {if $level == '5'} SELECTED {/if}>Top</option>
</select>
</td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Kelurahan</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="village" value="{$village}"
name="village" class="form-control" placeholder="Kelurahan"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px;">Status</td>
<td style="font-size: 14px;">:</td>
<td>
<select id="statusStaff" name="statusStaff" class="form-
control" style="width: 270px;" required>
<option value=""></option>
<option value="Y" {if $statusStaff == 'Y'} SELECTED
{/if}>Y [Aktif]</option>
<option value="N" {if $statusStaff == 'N'} SELECTED
{/if}>N [Tidak Aktif]</option>
</select>
</td>
</tr>
<tr valign="top">
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Kecamatan</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" value="{$district}" id="district"
name="district" class="form-control" placeholder="Kecamatan"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px;">Password</td>
<td style="font-size: 14px;">:</td>

26
<td><input type="text" id="password"
name="password" class="form-control" placeholder="Password"
style="width: 270px;"> <br> <span style="font-size: 10pt;">*)
Kosongkan, jika password tidak ingin diubah</span></td>
</tr>
<tr valign="top">
<td style="font-size: 14px; border-left:
1px solid #000000; background-color: #FFFFFF;">Kota</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" value="{$city}"
id="city" name="city" class="form-control" placeholder="Kota"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px;">Photo</td>
<td style="font-size: 14px;">:</td>
<td rowspan="4">
<div id="me" class="styleall" style="cursor:pointer;">
<label>
<button class="btn btn-warning">Browse</button>
</label>
</div>
<span id="mestatus"></span>
<div id="photostaff">
<li class="nameupload"></li>
</div>
<div id="files">
<li class="success">
{if $photo != ''}
<img src="img/staffs/thumb/small_{$photo}"> <br><br>
<span style="font-size: 14px;"><a id="deletephoto"
href="staffs.php?module=staff&act=deletephoto&staffID={$staffID}&p
hoto={$photo}">Hapus Foto</a></span>

{/if}
</li>
</div>
</td>
</tr>
<tr valign="top">
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Kode Pos</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="number" id="zipCode"
value="{$zipCode}" name="zipCode" class="form-control"
placeholder="Kode Pos" style="width: 270px;"></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Propinsi</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" value="{$province}"

27
id="province" name="province" class="form-control"
placeholder="Propinsi" style="width: 270px;"></td>
<td></td>
<td
colspan="3"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Telp / HP</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text" id="phone"
value="{$phone}" name="phone" class="form-control"
placeholder="Nomor Telepon Staff" style="width: 270px;"></td>
<td></td>
<td colspan="3"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; border-bottom: 1px solid #000000; background-color:
#FFFFFF;">Email</td>
<td style="font-size: 14px; background-color:
#FFFFFF; border-bottom: 1px solid #000000;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF; border-bottom: 1px solid
#000000;"><input type="email" id="email" value="{$email}"
name="email" class="form-control" placeholder="Email"
style="width: 270px;" required></td>
<td></td>
<td colspan="3"></td>
</tr>
</table>
<br>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>

{/if}
</body>

Hasil skrip diatas akan menampilkan hasil seperti pada gambar berikut :

Gambar 5.1. Menampilkan data staff

28
Gambar 5.2. Menambah data staff

Gambar 5.3. Mengubah data staff

29
5.1.2 Customer
Master data customer digunakan untuk menyimpan seluruh daftar customer
perusahaan.
Buat file dengan nama customers.php, adapun skripnya sebagai berikut :

<?php
// include header
include "header.php";
// set the tpl page
$page = "customers.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '2'";
$sqlAuthorizeStaff = mysqli_query($connect,
$queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is customer and action is delete


if ($module == 'customer' && $act == 'delete')
{
// insert method into a variable
$customerID = $_GET['customerID'];
$page = $_GET['page'];

// delete customer
$queryCustomer = "DELETE FROM as_customers WHERE
customerID = '$customerID'";
$sqlCustomer = mysqli_query($connect, $queryCustomer);

// redirect to the customer page


header("Location: customers.php?page=".$page);
} // close bracket

// if module is customer and act is search

30
elseif ($module == 'customer' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryCustomer = "SELECT * FROM as_customers WHERE customerCode


LIKE '%$q%' OR customerName LIKE '%$q%' OR city LIKE '%$q%'";
$sqlCustomer = mysqli_query($connect, $queryCustomer);

// fetch data
$i = 1;
while ($dtCustomer = mysqli_fetch_array($sqlCustomer))
{
$dataCustomer[] = array('customerID' => $dtCustomer['customerID'],
'customerCode' => $dtCustomer['customerCode'],
'customerName' => $dtCustomer['customerName'],
'contactPerson' => $dtCustomer['contactPerson'],
'city' => $dtCustomer['city'],
'phone1' => $dtCustomer['phone1'],
'limitBalance' => rupiah($dtCustomer['limitBalance']),
'disc1' => $dtCustomer['disc1'],
'disc2' => $dtCustomer['disc2'],
'disc3' => $dtCustomer['disc3'],
'note' => $dtCustomer['note'],
'npwp' => $dtCustomer['npwp'],
'pkpName' => $dtCustomer['pkpName'],
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataCustomer", $dataCustomer);
$smarty->assign("q", $q);
}

else
{
// create new object pagination
$p = new PaginationCustomer;
// limit 20 data for page
$limit = 20;
$position = $p->searchPosition($limit);

// showing up the customer data


$queryCustomer = "SELECT * FROM as_customers ORDER BY
customerCode ASC LIMIT $position,$limit";
$sqlCustomer = mysqli_query($connect, $queryCustomer);

// fetch data
$i = 1 + $position;
while ($dtCustomer = mysqli_fetch_array($sqlCustomer))
{
$dataCustomer[] = array('customerID' => $dtCustomer['customerID'],
'customerCode' => $dtCustomer['customerCode'],
'customerName' => $dtCustomer['customerName'],
'contactPerson' => $dtCustomer['contactPerson'],
'city' => $dtCustomer['city'],
'phone1' => $dtCustomer['phone1'],

31
'limitBalance' => rupiah($dtCustomer['limitBalance']),
'disc1' => $dtCustomer['disc1'],
'disc2' => $dtCustomer['disc2'],
'disc3' => $dtCustomer['disc3'],
'note' => $dtCustomer['note'],
'npwp' => $dtCustomer['npwp'],
'pkpName' => $dtCustomer['pkpName'],
'no' => $i);
$i++;
}

$smarty->assign("dataCustomer", $dataCustomer);
// count data
$queryCountCustomer = "SELECT * FROM as_customers";
$sqlCountCustomer = mysqli_query($connect, $queryCountCustomer);
$amountData = mysqli_num_rows($sqlCountCustomer);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Customer");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pengolahan data master customer.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Customer");
}

// include footer
include "footer.php";
?>

Selanjutnya buat file dengan nama customers.tpl dan simpan dalam folder
templates, adapun skripnya sebagai berikut :

{include file="header.tpl"}

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>

{literal}
<script>
$(document).ready(function() {
$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");

32
},
'afterClose':function () {
window.location.reload();
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#customer").submit(function() { return false; });


$("#customer2").submit(function() { return false; });

$("#send").on("click", function(){
var customerCode = $("#customerCode").val();
var customerName = $("#customerName").val();
var contactPerson = $("#contactPerson").val();
var address = $("#address").val();
var address2 = $("#address2").val();
var village = $("#village").val();
var district = $("#district").val();
var city = $("#city").val();
var zipCode = $("#zipCode").val();
var province = $("#province").val();
var phone1 = $("#phone1").val();
var phone2 = $("#phone2").val();
var phone3 = $("#phone3").val();
var fax1 = $("#fax1").val();
var fax2 = $("#fax2").val();
var fax3 = $("#fax3").val();
var phonecp1 = $("#phonecp1").val();
var phonecp2 = $("#phonecp2").val();
var email = $("#email").val();
var limitBalance = $("#limitBalance").val();
var discount1 = $("#discount1").val();
var discount2 = $("#discount2").val();
var discount3 = $("#discount3").val();
var note = $("#note").val();
var npwp = $("#npwp").val();
var pkpName = $("#pkpName").val();
var staffCode = $("#staffCode").val();

if (customerCode != '' && customerName != ''){

$.ajax({
type: 'POST',
url: 'save_customer.php',
dataType: 'JSON',
data:{
customerCode: customerCode,
customerName: customerName,
contactPerson: contactPerson,
address: address,
address2: address2,
village: village,
district: district,
city: city,
zipCode: zipCode,

33
province: province,
phone1: phone1,
phone2: phone2,
phone3: phone3,
fax1: fax1,
fax2: fax2,
fax3: fax3,
phonecp1: phonecp1,
phonecp2: phonecp2,
email: email,
limitBalance: limitBalance,
discount1: discount1,
discount2: discount2,
discount3: discount3,
note: note,
npwp: npwp,
pkpName: pkpName,
staffCode: staffCode
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "customers.php?msg=Data berhasil disimpan";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<section class="sidebar">

{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
</aside>

<aside class="right-side">
{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

34
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Customer</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">

<form method="GET" action="customers.php">


<input type="hidden" name="module" value="customer">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$q}" id="q" name="q"
class="form-control" placeholder="Pencarian : Kode, nama toko atau
kota" style="float: right; width: 275px;" required>

<a href="#inline" class="modalbox" style="float:


left;"><button class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>

<a href="print_customers.php?act=print&q={$q}" style="


float: left;" target="_blank"><button type="button" class="btn
btn-default pull-right"><i class="fa fa-print"></i> Print
PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

{if $module == 'customer' AND $act == 'search'}


<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA CUSTOMER <i class="fa fa-sort"></i></th>
<th>KONTAK PERSON <i class="fa fa-sort"></i></th>
<th>KOTA <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>LIMIT <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataCustomer loop=$dataCustomer}
<tr>
<td>{$dataCustomer[dataCustomer].no}</td>
<td>{$dataCustomer[dataCustomer].customerCode}</td>
<td>{$dataCustomer[dataCustomer].customerName}</td>

35
<td>{$dataCustomer[dataCustomer].contactPerson}</td>
<td>{$dataCustomer[dataCustomer].city}</td>
<td>{$dataCustomer[dataCustomer].phone1}</td>
<td>{$dataCustomer[dataCustomer].limitBalance}</td>
<td>
<a title="Edit" href="edit_customers.php?module=customer
&act=edit&customerID={$dataCustomer[dataCustomer].customerID}"
data-width="900" data-height="180" class="various2
fancybox.iframe"><img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="customers.php?module=customer
&act=delete&customerID={$dataCustomer[dataCustomer].customerID}&pa
ge={$page}" onclick="return confirm('Anda Yakin ingin menghapus
customer {$dataCustomer[dataCustomer].customerName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}

</tbody>
</table>
</div>
</div><!-- /.box-body -->

{else}
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA CUSTOMER <i class="fa fa-sort"></i></th>
<th>KONTAK PERSON <i class="fa fa-sort"></i></th>
<th>KOTA <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>LIMIT <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataCustomer loop=$dataCustomer}
<tr>
<td>{$dataCustomer[dataCustomer].no}</td>
<td>{$dataCustomer[dataCustomer].customerCode}</td>
<td>{$dataCustomer[dataCustomer].customerName}</td>
<td>{$dataCustomer[dataCustomer].contactPerson}</td>
<td>{$dataCustomer[dataCustomer].city}</td>
<td>{$dataCustomer[dataCustomer].phone1}</td>
<td>{$dataCustomer[dataCustomer].limitBalance}</td>
<td>
<a title="Edit" href="edit_customers.php?module=customer&
act=edit&customerID={$dataCustomer[dataCustomer].customerID}"
data-width="900" data-height="180" class="various2
fancybox.iframe"><img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="customers.php?module=customer&act=delete
&customerID={$dataCustomer[dataCustomer].customerID}&page={$page}"
onclick="return confirm('Anda Yakin ingin menghapus customer

36
{$dataCustomer[dataCustomer].customerName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td align="center"><h3><b>MASTER DATA CUSTOMER</b></h3></td>
</tr>
<tr>
<td>
<form id="customer" name="customer" method="POST" action="#">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">Kode Customer</td>
<td width="5">:</td>
<td><input type="text" id="customerCode"
name="customerCode" class="form-control" placeholder="Kode
Customer" style="width: 270px;" required></td>
<td colspan="4"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>IDENTITAS CUSTOMER</b></span></td>
<td></td>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>ORANG YANG DIHUBUNGI</b></span></td>
</tr>
<tr>
<td width="150" style="border-left: 1px solid
#000000; background-color: #FFFFFF;">Nama Customer</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="customerName"
name="customerName" class="form-control" placeholder="Nama
Customer" style="width: 270px;" required></td>
<td width="50"></td>

37
<td width="140" style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Nama Lengkap</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="contactPerson"
name="contactPerson" class="form-control" placeholder="Kontak
Person" style="width: 270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Alamat 1</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="address" name="address"
class="form-control" placeholder="Alamat" style="width:
270px;"></td><td></td>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">No. HP 1</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="phonecp1" name="phonecp1"
class="form-control" placeholder="No. Handphone 1" style="width:
270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Alamat 2</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="address2" name="address2"
class="form-control" placeholder="Alamat" style="width:
270px;"></td><td></td>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">No. HP 2</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="phonecp2" name="phonecp2"
class="form-control" placeholder="No. Handphone 2" style="width:
270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Kelurahan</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="village" name="village"
class="form-control" placeholder="Kelurahan" style="width:
270px;"></td><td></td>
<td style="border-bottom: 1px solid #000000; border-left: 1px
solid #000000; background-color: #FFFFFF;">Email</td>
<td style="border-bottom: 1px solid #000000; background-color:
#FFFFFF;">:</td>
<td style="border-bottom: 1px solid #000000; border-right:
1px solid #000000; background-color: #FFFFFF;"><input type="email"
id="email" name="email" class="form-control" placeholder="Email"
style="width: 270px;"></td>
</tr>

38
<tr>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Kecamatan</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="district" name="district"
class="form-control" placeholder="Kecamatan" style="width:
270px;"></td>
<td colspan="4"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Kota/Kode Pos</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="city" name="city"
class="form-control" placeholder="Kota" style="width: 160px;
float: left; margin-right: 5px;"> <input type="number"
id="zipCode" name="zipCode" class="form-control" placeholder="Kode
Pos" style="width: 105px;"></td><td></td>
<td align="center" style="border-left: 1px solid #000000;
border-right: 1px solid #000000; border-top: 1px solid #000000;
background-color: #999999;" colspan="3"><span style="font-size:
16px;"><b>IDENTITAS PAJAK</b></span></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Propinsi</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="province" name="province"
class="form-control" placeholder="Propinsi" style="width:
270px;"></td><td></td>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Nomor NPWP</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="npwp" name="npwp"
class="form-control" placeholder="Nomor NPWP" style="width:
270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Telepon</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="phone1" name="phone1"
class="form-control" placeholder="Telepon 1" style="width: 85px;
float: left; margin-right: 5px;">
<input type="text" id="phone2" name="phone2" class="form-control"
placeholder="Telepon 2" style="width: 87px; float: left; margin-
right: 5px;">
<input type="text" id="phone3" name="phone3" class="form-control"
placeholder="Telepon 3" style="width: 87px;">
</td><td></td>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Nama PKP</td>

39
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="pkpName" name="pkpName"
class="form-control" placeholder="Nama PKP" style="width:
270px;"></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Faksimile</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="fax1" name="fax1"
class="form-control" placeholder="Fax 1" style="width: 85px;
float: left; margin-right: 5px;">
<input type="text" id="fax2" name="fax2" class="form-
control" placeholder="Fax 2" style="width: 87px; float: left;
margin-right: 5px;">
<input type="text" id="fax3" name="fax3" class="form-
control" placeholder="Fax 3" style="width: 87px;">
</td><td></td>
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Note</td>
<td style="background-color: #FFFFFF;">:</td>
<td rowspan="2" style="border-bottom: 1px solid #000000;
border-right: 1px solid #000000; background-color:
#FFFFFF;"><textarea id="note" name="note" class="form-control"
placeholder="Keterangan" style="width: 270px; height:
72px;"></textarea></td>
</tr>
<tr valign="top">
<td style="border-left: 1px solid #000000;
background-color: #FFFFFF;">Diskon</td>
<td style="background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="number" id="discount1"
name="discount1" class="form-control" placeholder="Disc 1"
style="width: 85px; float: left; margin-right: 5px;">
<input type="number" id="discount2" name="discount2"
class="form-control" placeholder="Disc 2" style="width: 87px;
float: left; margin-right: 5px;">
<input type="number" id="discount3" name="discount3"
class="form-control" placeholder="Disc 3" style="width: 87px;">
</td>
<td></td>
<td colspan="2" style="background-color: #FFFFFF; border-
left: 1px solid #000000; border-bottom: 1px solid #000000;"></td>
</tr>
<tr>
<td style="border-bottom: 1px solid #000000; border-left: 1px
solid #000000; background-color: #FFFFFF;">Limit/Kode Sales</td>
<td style="border-bottom: 1px solid #000000; background-color:
#FFFFFF;">:</td>
<td style="border-bottom: 1px solid #000000; border-right: 1px
solid #000000; background-color: #FFFFFF;"><input type="number"
id="limitBalance" name="limitBalance" class="form-control"
placeholder="Limit" style="width: 165px; float: left; margin-
right: 5px;">

40
<input type="text" id="staffCode" name="staffCode" class="form-
control" placeholder="Kode Sales" style="width: 100px;">
</td>
<td colspan="4"></td>
</tr>
</table><br>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>
{/if}
</div><!-- /.box -->
</section><!-- /.Left col -->
</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Karena proses simpan ini berjalan secara ajax, maka kita buat file pemroses
simpannya, beri nama file tersebut save_customer.php, adapun skripnya
sebagai berikut :

<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$customerCode = mysqli_real_escape_string($connect,
$_POST['customerCode']);
$customerName = mysqli_real_escape_string($connect,
$_POST['customerName']);
$contactPerson = mysqli_real_escape_string($connect,
$_POST['contactPerson']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$address2 = mysqli_real_escape_string($connect,
$_POST['address2']);
$village = mysqli_real_escape_string($connect, $_POST['village']);
$district = mysqli_real_escape_string($connect,
$_POST['district']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$zipCode = $_POST['zipCode'];
$province = mysqli_real_escape_string($connect,
$_POST['province']);
$phone1 = mysqli_real_escape_string($connect, $_POST['phone1']);
$phone2 = mysqli_real_escape_string($connect, $_POST['phone2']);
$phone3 = mysqli_real_escape_string($connect, $_POST['phone3']);
$fax1 = mysqli_real_escape_string($connect, $_POST['fax1']);
$fax2 = mysqli_real_escape_string($connect, $_POST['fax2']);
$fax3 = mysqli_real_escape_string($connect, $_POST['fax3']);
$phonecp1 = mysqli_real_escape_string($connect,

41
$_POST['phonecp1']);
$phonecp2 = mysqli_real_escape_string($connect,
$_POST['phonecp2']);
$limitBalance = mysqli_real_escape_string($connect,
$_POST['limitBalance']);
$email = mysqli_real_escape_string($connect, $_POST['email']);
$discount1 = mysqli_real_escape_string($connect,
$_POST['discount1']);
$discount2 = mysqli_real_escape_string($connect,
$_POST['discount2']);
$discount3 = mysqli_real_escape_string($connect,
$_POST['discount3']);
$note = mysqli_real_escape_string($connect, $_POST['note']);
$npwp = mysqli_real_escape_string($connect, $_POST['npwp']);
$pkpName = mysqli_real_escape_string($connect, $_POST['pkpName']);
$staffCode = mysqli_real_escape_string($connect,
$_POST['staffCode']);

if ($customerCode != '' && $customerName != ''){


$queryCustomer = "INSERT INTO as_customers( customerCode,
customerName,
contactPerson,
address,
address2,
village,
district,
city,
zipCode,
province,
phone1,
phone2,
phone3,
fax1,
fax2,
fax3,
phonecp1,
phonecp2,
email,
limitBalance,
disc1,
disc2,
disc3,
note,
npwp,
pkpName,
staffCode,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$customerCode',
'$customerName',
'$contactPerson',
'$address',
'$address2',
'$village',
'$district',

42
'$city',
'$zipCode',
'$province',
'$phone1',
'$phone2',
'$phone3',
'$fax1',
'$fax2',
'$fax3',
'$phonecp1',
'$phonecp2',
'$email',
'$limitBalance',
'$discount1',
'$discount2',
'$discount3',
'$note',
'$npwp',
'$pkpName',
'$staffCode',
'$createdDate',
'$staffID',
'',
'')";

$sqlCustomer = mysqli_query($connect, $queryCustomer);


if ($sqlCustomer)
{
echo json_encode(OK);
}
}
exit();
?>

Jika skrip diatas adalah perintah untuk menampilkan dan menambah data
customer, maka berikut adalah perintah mengubah data customer, buat 2 buah
file, masing-masing dengan nama edit_customers.php dan edit_customer.tpl
yang masing-masing skripnya sebagai berikut :
edit_customers.php

<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_customers.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

43
else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'customer' && $act == 'edit')


{
// insert method into a variable
$customerID = $_GET['customerID'];

$queryCustomer = "SELECT * FROM as_customers WHERE customerID =


'$customerID'";
$sqlCustomer = mysqli_query($connect, $queryCustomer);

// fetch data
$dataCustomer = mysqli_fetch_array($sqlCustomer);

// assign fetch data to the tpl


$smarty->assign("customerID", $dataCustomer['customerID']);
$smarty->assign("customerCode", $dataCustomer['customerCode']);
$smarty->assign("customerName", $dataCustomer['customerName']);
$smarty->assign("contactPerson", $dataCustomer['contactPerson']);
$smarty->assign("address", $dataCustomer['address']);
$smarty->assign("address2", $dataCustomer['address2']);
$smarty->assign("village", $dataCustomer['village']);
$smarty->assign("district", $dataCustomer['district']);
$smarty->assign("city", $dataCustomer['city']);
$smarty->assign("zipCode", $dataCustomer['zipCode']);
$smarty->assign("province", $dataCustomer['province']);
$smarty->assign("phone1", $dataCustomer['phone1']);
$smarty->assign("phone2", $dataCustomer['phone2']);
$smarty->assign("phone3", $dataCustomer['phone3']);
$smarty->assign("fax1", $dataCustomer['fax1']);
$smarty->assign("fax2", $dataCustomer['fax2']);
$smarty->assign("fax3", $dataCustomer['fax3']);
$smarty->assign("phonecp1", $dataCustomer['phonecp1']);
$smarty->assign("phonecp2", $dataCustomer['phonecp2']);
$smarty->assign("email", $dataCustomer['email']);
$smarty->assign("limitBalance", $dataCustomer['limitBalance']);
$smarty->assign("disc1", $dataCustomer['disc1']);
$smarty->assign("disc2", $dataCustomer['disc2']);
$smarty->assign("disc3", $dataCustomer['disc3']);
$smarty->assign("note", $dataCustomer['note']);
$smarty->assign("npwp", $dataCustomer['npwp']);
$smarty->assign("pkpName", $dataCustomer['pkpName']);
$smarty->assign("staffCode", $dataCustomer['staffCode']);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

44
// include footer
include "footer.php";
?>

edit_customer.tpl

<script src="design/js/jquery-1.8.1.min.js" type="text/


javascript"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>
<link rel="stylesheet" type="text/css" media="all"
href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery.
fancybox.js?v=2.0.6"></script>

<body style='background-color: #EEEEEE; color: #000;'>


{literal}
<script>
$(document).ready(function() {
$("#customer").submit(function() { return false; });
$("#send").on("click", function(){
var customerID = $("#customerID").val();
var customerCode = $("#customerCode").val();
var customerName = $("#customerName").val();
var contactPerson = $("#contactPerson").val();
var address = $("#address").val();
var address2 = $("#address2").val();
var village = $("#village").val();
var district = $("#district").val();
var city = $("#city").val();
var zipCode = $("#zipCode").val();
var province = $("#province").val();
var phone1 = $("#phone1").val();
var phone2 = $("#phone2").val();
var phone3 = $("#phone3").val();
var fax1 = $("#fax1").val();
var fax2 = $("#fax2").val();
var fax3 = $("#fax3").val();
var phonecp1 = $("#phonecp1").val();
var phonecp2 = $("#phonecp2").val();
var email = $("#email").val();
var limitBalance = $("#limitBalance").val();
var discount1 = $("#discount1").val();
var discount2 = $("#discount2").val();
var discount3 = $("#discount3").val();
var note = $("#note").val();
var npwp = $("#npwp").val();
var pkpName = $("#pkpName").val();
var staffCode = $("#staffCode").val();

if (customerID != '' && customerCode != '' && customerName != ''){

45
$.ajax({
type: 'POST',
url: 'save_edit_customer.php',
dataType: 'JSON',
data:{
customerID: customerID,
customerCode: customerCode,
customerName: customerName,
contactPerson: contactPerson,
address: address,
address2: address2,
village: village,
district: district,
city: city,
zipCode: zipCode,
province: province,
phone1: phone1,
phone2: phone2,
phone3: phone3,
fax1: fax1,
fax2: fax2,
fax3: fax3,
phonecp1: phonecp1,
phonecp2: phonecp2,
email: email,
limitBalance: limitBalance,
discount1: discount1,
discount2: discount2,
discount3: discount3,
note: note,
npwp: npwp,
pkpName: pkpName,
staffCode: staffCode
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'customer' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td align="center"><h3><b>MASTER DATA CUSTOMER</b></h3></td>
</tr>
<tr>
<td>
<form id="customer" name="customer" method="POST" action="#">
<input type="hidden" id="customerID" name="customerID"
value="{$customerID}">

46
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150" style="font-size: 14px;">Kode Customer</td>
<td width="5" style="font-size: 14px;">:</td>
<td><input type="text" value="{$customerCode}"
id="customerCode" name="customerCode" class="form-control"
placeholder="Kode Customer" style="width: 270px;" required></td>
<td colspan="4"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>IDENTITAS CUSTOMER</b></span></td>
<td></td>
<td colspan="3" align="center" bgcolor="#999999"
style="border-left: 1px solid #000000; border-top: 1px solid
#000000; border-right: 1px solid #000000;"><span style="font-size:
16px;"><b>ORANG YANG DIHUBUNGI</b></span></td>
</tr>
<tr>
<td width="150" style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Nama Customer</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="font-size: 14px; border-right: 1px solid #000000;
background-color: #FFFFFF;"><input type="text"
value="{$customerName}" id="customerName" name="customerName"
class="form-control" placeholder="Nama Customer" style="width:
270px;" required></td>
<td width="50"></td>
<td width="140" style="font-size: 14px; border-left: 1px
solid #000000; background-color: #FFFFFF;">Nama Lengkap</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="contactPerson"
value="{$contactPerson}" name="contactPerson" class="form-control"
placeholder="Kontak Person" style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Alamat 1</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="address" name="address"
value="{$address}" class="form-control" placeholder="Alamat"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px; border-left: 1px solid #000000;
background-color: #FFFFFF;">No. HP 1</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="phonecp1" name="phonecp1"
value="{$phonecp1}" class="form-control" placeholder="No.
Handphone 1" style="width: 270px;"></td>
</tr>
<tr>

47
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Alamat 2</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="address2" name="address2"
value="{$address2}" class="form-control" placeholder="Alamat"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">No. HP 2</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="phonecp2" name="phonecp2"
value="{$phonecp2}" class="form-control" placeholder="No.
Handphone 2" style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Kelurahan</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="village" name="village"
value="{$village}" class="form-control" placeholder="Kelurahan"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px; border-bottom: 1px solid #000000;
border-left: 1px solid #000000; background-color:
#FFFFFF;">Email</td>
<td style="font-size: 14px; border-bottom: 1px solid #000000;
background-color: #FFFFFF;">:</td>
<td style="border-bottom: 1px solid #000000; border-right: 1px
solid #000000; background-color: #FFFFFF;"><input type="email"
id="email" value="{$email}" name="email" class="form-control"
placeholder="Email" style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid #000000;
background-color: #FFFFFF;">Kecamatan</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="district" name="district"
value="{$district}" class="form-control" placeholder="Kecamatan"
style="width: 270px;"></td>
<td colspan="4"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Kota/Kode Pos</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="city" name="city" value="{$city}"
class="form-control" placeholder="Kota" style="width: 170px;
float: left;"> <input type="number" id="zipCode"
value="{$zipCode}" name="zipCode" class="form-control"
placeholder="Kode Pos" style="width: 100px;"></td>
<td></td>

48
<td align="center" style="border-left: 1px solid #000000;
border-right: 1px solid #000000; border-top: 1px solid #000000;
background-color: #999999;" colspan="3"><span style="font-size:
16px;"><b>IDENTITAS PAJAK</b></span></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Propinsi</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="province" name="province"
value="{$province}" class="form-control" placeholder="Propinsi"
style="width: 270px;"></td>
<td></td>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Nomor NPWP</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-
color: #FFFFFF;"><input type="text" id="npwp" name="npwp"
value="{$npwp}" class="form-control" placeholder="Nomor NPWP"
style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Telepon</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="phone1" name="phone1"
value="{$phone1}" class="form-control" placeholder="Telepon 1"
style="width: 90px; float: left;">
<input type="text" value="{$phone2}" id="phone2" name="phone2"
class="form-control" placeholder="Telepon 2" style="width: 90px;
float: left;">
<input type="text" value="{$phone3}" id="phone3" name="phone3"
class="form-control" placeholder="Telepon 3" style="width: 90px;">
</td>
<td></td>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Nama PKP</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="pkpName" name="pkpName"
value="{$pkpName}" class="form-control" placeholder="Nama PKP"
style="width: 270px;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Faksimile</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="text" id="fax1" name="fax1" value="{$fax1}"
class="form-control" placeholder="Fax 1" style="width: 90px;
float: left;">
<input type="text" id="fax2" value="{$fax2}" name="fax2"
class="form-control" placeholder="Fax 2" style="width: 90px;
float: left;">

49
<input type="text" id="fax3" name="fax3" value="{$fax3}"
class="form-control" placeholder="Fax 3" style="width: 90px;">
</td>
<td></td>
<td style="border-left: 1px solid #000000; background-
color: #FFFFFF;">Note</td>
<td style="background-color: #FFFFFF;">:</td>
<td rowspan="2" style="border-bottom: 1px solid #000000;
border-right: 1px solid #000000; background-color:
#FFFFFF;"><textarea id="note" value="{$note}" name="note"
class="form-control" placeholder="Keterangan" style="width: 270px;
height: 72px;">{$note}</textarea></td>
</tr>
<tr valign="top">
<td style="font-size: 14px; border-left: 1px solid
#000000; background-color: #FFFFFF;">Diskon</td>
<td style="font-size: 14px; background-color: #FFFFFF;">:</td>
<td style="border-right: 1px solid #000000; background-color:
#FFFFFF;"><input type="number" id="discount1" name="discount1"
value="{$disc1}" class="form-control" placeholder="Diskon 1"
style="width: 90px; float: left;">
<input type="number" id="discount2" value="{$disc2}"
name="discount2" class="form-control" placeholder="Diskon 2"
style="width: 90px; float: left;">
<input type="number" id="discount3" value="{$disc3}"
name="discount3" class="form-control" placeholder="Diskon 3"
style="width: 90px;">
</td>
<td></td>
<td colspan="2" style="background-color: #FFFFFF; border-left: 1px
solid #000000; border-bottom: 1px solid #000000;"></td>
</tr>
<tr>
<td style="font-size: 14px; border-bottom: 1px solid #000000;
border-left: 1px solid #000000; background-color:
#FFFFFF;">Limit/Kode Sales</td>
<td style="font-size: 14px; border-bottom: 1px solid #000000;
background-color: #FFFFFF;">:</td>
<td style="border-bottom: 1px solid #000000; border-right: 1px
solid #000000; background-color: #FFFFFF;"><input type="number"
value="{$limitBalance}" id="limitBalance" name="limitBalance"
class="form-control" placeholder="Limit" style="width: 170px;
float: left;">
<input type="text" id="staffCode" value="{$staffCode}"
name="staffCode" class="form-control" placeholder="Kode Sales"
style="width: 100px;">
</td>
<td colspan="4"></td>
</tr>
</table><br>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>

{/if}

50
</body>

Sama halnya dengan proses tambah data, proses ubah data customer ini juga
berjalan secara ajax, oleh sebab itu buat file dengan nama
save_edit_customer.php yang skripnya sebagai berikut :

<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$customerID = $_POST['customerID'];
$customerCode = mysqli_real_escape_string($connect,
$_POST['customerCode']);
$customerName = mysqli_real_escape_string($connect,
$_POST['customerName']);
$contactPerson = mysqli_real_escape_string($connect,
$_POST['contactPerson']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$address2 = mysqli_real_escape_string($connect,
$_POST['address2']);
$village = mysqli_real_escape_string($connect, $_POST['village']);
$district = mysqli_real_escape_string($connect,
$_POST['district']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$zipCode = $_POST['zipCode'];
$province = mysqli_real_escape_string($connect,
$_POST['province']);
$phone1 = mysqli_real_escape_string($connect, $_POST['phone1']);
$phone2 = mysqli_real_escape_string($connect, $_POST['phone2']);
$phone3 = mysqli_real_escape_string($connect, $_POST['phone3']);
$fax1 = mysqli_real_escape_string($connect, $_POST['fax1']);
$fax2 = mysqli_real_escape_string($connect, $_POST['fax2']);
$fax3 = mysqli_real_escape_string($connect, $_POST['fax3']);
$phonecp1 = mysqli_real_escape_string($connect,
$_POST['phonecp1']);
$phonecp2 = mysqli_real_escape_string($connect,
$_POST['phonecp2']);
$limitBalance = mysqli_real_escape_string($connect,
$_POST['limitBalance']);
$email = mysqli_real_escape_string($connect, $_POST['email']);
$discount1 = mysqli_real_escape_string($connect,
$_POST['discount1']);
$discount2 = mysqli_real_escape_string($connect,
$_POST['discount2']);
$discount3 = mysqli_real_escape_string($connect,
$_POST['discount3']);
$note = mysqli_real_escape_string($connect, $_POST['note']);
$npwp = mysqli_real_escape_string($connect, $_POST['npwp']);
$pkpName = mysqli_real_escape_string($connect, $_POST['pkpName']);
$staffCode = mysqli_real_escape_string($connect,
$_POST['staffCode']);

if ($customerID != '' && $customerCode != '' && $customerName !=

51
''){

$queryCustomer = "UPDATE as_customers SET customerCode =


'$customerCode',
customerName = '$customerName',
contactPerson = '$contactPerson',
address = '$address',
address2 = '$address2',
village = '$village',
district = '$district',
city = '$city',
zipCode = '$zipCode',
province = '$province',
phone1 = '$phone1',
phone2 = '$phone2',
phone3 = '$phone3',
fax1 = '$fax1',
fax2 = '$fax2',
fax3 = '$fax3',
phonecp1 = '$phonecp1',
phonecp2 = '$phonecp2',
email = '$email',
limitBalance = '$limitBalance',
disc1 = '$disc1',
disc2 = '$disc2',
disc3 = '$disc3',
note = '$note',
npwp = '$npwp',
pkpName = '$pkpName',
staffCode = '$staffCode',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE customerID = '$customerID'";
$sqlCustomer = mysqli_query($connect, $queryCustomer);

if ($sqlCustomer)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil seluruh skrip diatas akan menghasilkan sebuah halaman master data
customer, yang bisa dilihat pada gambar-gambar berikut :

52
Gambar 5.4. Menampilkan data customer

Gambar 5.5. Menambah data staff

53
Gambar 5.6. Mengubah data staff

5.1.3 Kategori
Master data kategori digunakan untuk menyimpan dan mengolah data-data
kategori terkait produk dalam perusahaan kita. Disini kita akan mengulas tuntas
pembuatan master data kategori.
Buat file dengan nama categories.php yang skripnya sebagai berikut :

<?php
// include header
include "header.php";
// set the tpl page
$page = "categories.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();

54
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'4'";
$sqlAuthorizeStaff = mysqli_query($connect,
$queryAuthorizeStaff);
$dataAuthorizeStaff =
mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is category and action is delete


if ($module == 'category' && $act == 'delete')
{
// insert method into a variable
$categoryID = $_GET['categoryID'];

// delete categories
$queryCategory = "DELETE FROM as_categories WHERE categoryID =
'$categoryID'";
$sqlCategory = mysqli_query($connect, $queryCategory);

// redirect to the categories page


header("Location: categories.php");
} // close bracket

// if module is category and act is search


elseif ($module == 'category' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryCategory = "SELECT * FROM as_categories WHERE


categoryName LIKE '%$q%' ORDER BY categoryName ASC";
$sqlCategory = mysqli_query($connect, $queryCategory);

// fetch data
$i = 1;
while ($dtCategory = mysqli_fetch_array($sqlCategory))
{
$dataCategory[] = array('categoryID' => $dtCategory['categoryID'],
'categoryName' => $dtCategory['categoryName'],
'status' => $dtCategory['status'],
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataCategory", $dataCategory);
$smarty->assign("q", $q);
}

55
else
{
// create new object pagination
$p = new PaginationCategory;
// limit 20 data for page
$limit = 20;
$position = $p->searchPosition($limit);

// showing up the categories data


$queryCategory = "SELECT * FROM as_categories ORDER BY
categoryName ASC LIMIT $position,$limit";
$sqlCategory = mysqli_query($connect, $queryCategory);

// fetch data
$i = 1 + $position;
while ($dtCategory = mysqli_fetch_array($sqlCategory))
{
$dataCategory[] = array('categoryID' => $dtCategory['categoryID'],
'categoryName' => $dtCategory['categoryName'],
'status' => $dtCategory['status'],
'no' => $i);
$i++;
}

$smarty->assign("dataCategory", $dataCategory);

// count data
$queryCountCategory = "SELECT * FROM as_categories";
$sqlCountCategory = mysqli_query($connect,
$queryCountCategory);
$amountData = mysqli_num_rows($sqlCountCategory);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Kategori");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan pengolahan data master kategori produk.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Kategori");
}

// include footer
include "footer.php";
?>

Selanjutnya buat file dengan nama categories.tpl dan simpan dalam folder
templates, adapun skripnya sebagai berikut :

{include file="header.tpl"}

56
<link rel="stylesheet" type="text/css" media="all"
href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#category").submit(function() { return false; });


$("#category2").submit(function() { return false; });

$("#send").on("click", function(){
var categoryName = $("#categoryName").val();
var categoryStatus = $("#categoryStatus").val();
if (categoryName != '' && categoryStatus != ''){

$.ajax({
type: 'POST',
url: 'save_category.php',
dataType: 'JSON',
data:{
categoryName: categoryName,
categoryStatus: categoryStatus
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "categories.php";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

57
{include file="navigation.tpl"}
</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">>
<section class="sidebar">

{include file="user_panel.tpl"}
{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Kategori</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">

<form method="GET" action="categories.php">


<input type="hidden" name="module" value="category">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" id="q" name="q" value="{$q}"
class="form-control" placeholder="Pencarian : Nama Kategori"
style="float: right; width: 270px;" required>

<a href="#inline" class="modalbox" style="float:


left;"><button class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_categories.php?act=print&q={$q}" style=
"float: left;" target="_blank"><button type="button" class="btn
btn-default pull-right"><i class="fa fa-print"></i> Print
PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

{if $module == 'category' AND $act == 'search'}

58
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NAMA KATEGORI <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataCategory loop=$dataCategory}
<tr>
<td>{$dataCategory[dataCategory].no}</td>
<td>{$dataCategory[dataCategory].categoryName}</td>
<td>{$dataCategory[dataCategory].status}</td>
<td>
<a title="Edit" href="edit_categories.php?module=category&act=
edit&categoryID={$dataCategory[dataCategory].categoryID}" data-
width="450" data-height="180" class="various2 fancybox.iframe">
<img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="categories.php?module=category&act=delete&
categoryID={$dataCategory[dataCategory].categoryID}"
onclick="return confirm('Anda Yakin ingin menghapus kategori
{$dataCategory[dataCategory].categoryName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->

{else}

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NAMA KATEGORI <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataCategory loop=$dataCategory}
<tr>
<td>{$dataCategory[dataCategory].no}</td>
<td>{$dataCategory[dataCategory].categoryName}</td>
<td>{$dataCategory[dataCategory].status}</td>
<td>
<a title="Edit"
href="edit_categories.php?module=category&act=edit&

59
categoryID={$dataCategory[dataCategory].categoryID}" data-
width="450" data-height="180" class="various2 fancybox.iframe">
<img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="categories.php?module=category&act=delete&
categoryID={$dataCategory[dataCategory].categoryID}"
onclick="return confirm('Anda Yakin ingin menghapus kategori
{$dataCategory[dataCategory].categoryName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Kategori</h3></td>
</tr>
<tr>
<td>
<form id="category" name="category" method="POST" action="#">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Nama Kategori</td>
<td width="5">:</td>
<td><input type="text" id="categoryName"
name="categoryName" class="form-control" placeholder="Nama
kategori" style="width: 270px;" required></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="categoryStatus" id="categoryStatus"
class="form-control" required>
<option value="">- Pilih Status -</option>
<option value="Y">Y (Aktif)</option>
<option value="N">N (Tidak Aktif)</option>
</select></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>

60
{/if}
</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Karena skrip tambah data diatas berjalan secara ajax, maka akan buat file untuk
proses simpannya, beri nama file tersebut save_category.php adapun skripnya
sebagai berikut :

<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$categoryName = mysqli_real_escape_string($connect,
$_POST['categoryName']);
$categoryStatus = $_POST['categoryStatus'];

if ($categoryName != '' && $categoryStatus != ''){


$queryCategory = "INSERT INTO as_categories(categoryName,
status,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$categoryName',
'$categoryStatus',
'$createdDate',
'$staffID',
'',
'')";

$sqlCategory = mysqli_query($connect, $queryCategory);

if ($sqlCategory)
{
echo json_encode(OK);
}
}
exit();
?>

Skrip diatas adalah skrip untuk menampilkan data kategori dan menambah data
kategori, selanjutnya kita akan buat 3 buah file yang akan digunakan untuk

61
mengubah data kategori, diantaranya edit_categories.php, edit_categories.tpl
dan save_edit_category.php, adapun masing-masing skripnya sebagai berikut :
edit_categories.php

<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_categories.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'category' && $act == 'edit')


{
// insert method into a variable
$categoryID = $_GET['categoryID'];

$queryCategory = "SELECT * FROM as_categories WHERE categoryID =


'$categoryID'";
$sqlCategory = mysqli_query($connect, $queryCategory);

// fetch data
$dataCategory = mysqli_fetch_array($sqlCategory);

// assign fetch data to the tpl


$smarty->assign("categoryID", $dataCategory['categoryID']);
$smarty->assign("categoryName", $dataCategory['categoryName']);
$smarty->assign("categoryStatus", $dataCategory['status']);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

62
edit_categories.tpl
<script src="design/js/jquery-1.8.1.min.js" type="text/
javascript"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {
$("#category").submit(function() { return false; });
$("#send").on("click", function(){
var categoryID = $("#categoryID").val();
var categoryName = $("#categoryName").val();
var categoryStatus = $("#categoryStatus").val();

if (categoryID != '' && categoryName != '' && categoryStatus !=


''){

$.ajax({
type: 'POST',
url: 'save_edit_category.php',
dataType: 'JSON',
data:{
categoryID: categoryID,
categoryName: categoryName,
categoryStatus: categoryStatus
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'category' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Ubah Kategori</h3></td>
</tr>
<tr>

63
<td>
<form id="category" name="category" method="POST" action="#">
<input type="hidden" id="categoryID" name="categoryID"
value="{$categoryID}">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Nama Kategori</td>
<td width="5">:</td>
<td><input type="text" id="categoryName"
name="categoryName" value="{$categoryName}" class="form-control"
placeholder="Nama kategori" style="width: 270px;" required></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="categoryStatus" id="categoryStatus" class="form-
control" placeholder="Nama kategori" required>
<option value="">- Pilih Status -</option>
<option value="Y" {if $categoryStatus == 'Y'} SELECTED {/if}>Y
(Aktif)</option>
<option value="N" {if $categoryStatus == 'N'}
SELECTED {/if}>N (Tidak Aktif)</option>
</select></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
{/if}
</body>

save_edit_category.php
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$categoryID = $_POST['categoryID'];
$categoryName = mysqli_real_escape_string($connect,
$_POST['categoryName']);
$categoryStatus = $_POST['categoryStatus'];

if ($categoryID != '' && $categoryName != '' && $categoryStatus !=


''){

$queryCategory = "UPDATE as_categories SET categoryName =


'$categoryName',
status = '$categoryStatus',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE categoryID = '$categoryID'";

64
$sqlCategory = mysqli_query($connect, $queryCategory);

if ($sqlCategory)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil seluruh skrip diatas akan menampilkan master data kategori yang bisa
dilihat pada gambar-gambar berikut :

Gambar 5.7. Menampilkan data kategori

Gambar 5.8. Menambah data kategori

65
Gambar 5.9. Mengubah data kategori

5.1.4 Produk
Master data produk digunakan untuk menyimpan dan mengolah seluruh data
produk yang dimiliki perusahaan. Disini kita akan buat seluruh proses sekaligus
termasuk didalamnya ada proses upload gambar produk, semuanya akan
dilakukan secara ajax.. so ikuti saja.. buat beberapa file dengan masing-masing
nama file dan skrip sebagai berikut :
products.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "products.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{

66
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '5'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is product and action is delete


if ($module == 'product' && $act == 'delete')
{
// insert method into a variable
$productID = $_GET['productID'];
$pic = $_GET['pic'];

// delete product
$queryProduct = "DELETE FROM as_products WHERE productID =
'$productID'";
$sqlProduct = mysqli_query($connect, $queryProduct);

if ($sqlProduct)
{
if ($pic != '')
{
unlink("img/products/".$pic);
unlink("img/products/thumb/small_".$pic);
}
}

// redirect to the product page


header("Location: products.php");
} // close bracket

// if module is product and action is search


elseif ($module == 'product' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryProduct = "SELECT * FROM as_products WHERE productCode LIKE


'%$q%' OR productName LIKE '%$q%' ORDER BY productName ASC";
$sqlProduct = mysqli_query($connect, $queryProduct);

// fetch data
$i = 1;
while ($dtProduct = mysqli_fetch_array($sqlProduct))
{
if ($dtProduct['unit'] == '1')
{
$unit = "SET";
}
else
{
$unit = "PCS";
}

67
// count stock total based on productID
$queryStock = "SELECT SUM(stock) as stockAmount FROM
as_stock_products WHERE productID = '$dtProduct[productID]'";
$sqlStock = mysqli_query($connect, $queryStock);
$dataStock = mysqli_fetch_array($sqlStock);

$dataProduct[] = array('productID' => $dtProduct['productID'],


'productCode' => $dtProduct['productCode'],
'productName' => $dtProduct['productName'],
'categoryID' => $dtProduct['categoryID'],
'unit' => $unit,
'unitPrice1' => rupiah($dtProduct['unitPrice1']),
'unitPrice2' => rupiah($dtProduct['unitPrice2']),
'unitPrice3' => rupiah($dtProduct['unitPrice3']),
'hpp' => rupiah($dtProduct['hpp']),
'purchasePrice' => rupiah($dtProduct['purchasePrice']),
'note' => $dtProduct['note'],
'stockAmount' => $dataStock['stockAmount'],
'image' => $dtProduct['image'],
'minimumStock' => $dtProduct['minimumStock'],
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataProduct", $dataProduct);
$smarty->assign("q", $q);
}

// if module is product and action is delete image


elseif ($module == 'product' && $act == 'deleteimage')
{
$productID = $_GET['productID'];
$picture = $_GET['picture'];

$queryProduct = "UPDATE as_products SET image = '' WHERE


productID = '$productID'";
$sqlProduct = mysqli_query($connect, $queryProduct);

if ($sqlProduct)
{
unlink("img/products/".$picture);
unlink("img/products/thumb/small_".$picture);
}

// redirect to the product page


header("Location: products.php");
}

else
{
// get last sort product number
$queryNoProduct = "SELECT productCode FROM as_products
ORDER BY productCode DESC LIMIT 1";
$sqlNoProduct = mysqli_query($connect, $queryNoProduct);
$numsNoProduct = mysqli_num_rows($sqlNoProduct);
$dataNoProduct = mysqli_fetch_array($sqlNoProduct);

68
$start = substr($dataNoProduct['productCode'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoProduct == '0')
{
$productNo = "0000";
}
elseif ($tempNo == 1)
{
$productNo = "0000";
}
elseif ($tempNo == 2)
{
$productNo = "000";
}
elseif ($tempNo == 3)
{
$productNo = "00";
}
elseif ($tempNo == 4)
{
$productNo = "0";
}
elseif ($tempNo == 5)
{
$productNo = "";
}

$productCode = $productNo.$next;

$smarty->assign("productCode", $productCode);

// create new object pagination


$p = new PaginationProduct;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the product data


$queryProduct = "SELECT * FROM as_products ORDER BY
productCode ASC LIMIT $position,$limit";
$sqlProduct = mysqli_query($connect, $queryProduct);

// fetch data
$i = 1 + $position;
while ($dtProduct = mysqli_fetch_array($sqlProduct))
{
if ($dtProduct['unit'] == '1')
{
$unit = "SET";
}
else
{
$unit = "PCS";
}
// count stock total based on productID

69
$queryStock = "SELECT SUM(stock) as stockAmount
FROM as_stock_products WHERE productID = '$dtProduct[productID]'";
$sqlStock = mysqli_query($connect, $queryStock);
$dataStock = mysqli_fetch_array($sqlStock);

$dataProduct[] = array('productID' => $dtProduct['productID'],


'productCode' => $dtProduct['productCode'],
'productName' => $dtProduct['productName'],
'categoryID' => $dtProduct['categoryID'],
'unit' => $unit,
'unitPrice1' => rupiah($dtProduct['unitPrice1']),
'unitPrice2' => rupiah($dtProduct['unitPrice2']),
'unitPrice3' => rupiah($dtProduct['unitPrice3']),
'hpp' => rupiah($dtProduct['hpp']),
'purchasePrice' => rupiah($dtProduct['purchasePrice']),
'note' => $dtProduct['note'],
'stockAmount' => $dataStock['stockAmount'],
'image' => $dtProduct['image'],
'minimumStock' => $dtProduct['minimumStock'],
'no' => $i);
$i++;
}

$smarty->assign("dataProduct", $dataProduct);

// count data
$queryCountProduct = "SELECT * FROM as_products";
$sqlCountProduct = mysqli_query($connect, $queryCountProduct);
$amountData = mysqli_num_rows($sqlCountProduct);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);

// showing up the categories data


$queryCategory = "SELECT * FROM as_categories WHERE status
= 'Y' ORDER BY categoryName ASC";
$sqlCategory = mysqli_query($connect, $queryCategory);

// fetch data
while ($dtCategory = mysqli_fetch_array($sqlCategory))
{
$dataCategory[] = array('categoryID' => $dtCategory['categoryID'],
'categoryName' => $dtCategory['categoryName']);
}

// assign to the tpl


$smarty->assign("dataCategory", $dataCategory);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Produk");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan pengolahan data master produk.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Produk");

70
}

// include footer
include "footer.php";
?>

products.tpl (simpan ke dalam folder templates)


{include file="header.tpl"}
<link rel="stylesheet" type="text/css" media="all"
href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>
<script type="text/javascript" src="design/js/ajaxupload.3.5.js"
></script>
<link rel="stylesheet" type="text/css" href="design/css/Ajaxfile-
upload.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$(".various3").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

// Image
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'upload_product.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|jpeg)$/.test(ext))){
// extension is not allowed

71
mestatus.text('Hanya ekstensi .JPG/JPEG yang diijinkan.');
return false;
}
mestatus.html('');
},
onComplete: function(file, response){
//On completion clear the status
mestatus.text('');
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response!=="error"){

$('<li></li>').appendTo('#files').html('<img
src="img/products/'+response+'" alt="" height="70"/><br
/>').addClass('success');
$('<li></li>').appendTo('#photoproduct').html('<input
type="hidden" id="image" name="image"
value="'+response+'">').addClass('nameupload');

} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#product").submit(function() { return false; });


$("#product2").submit(function() { return false; });

$("#send").on("click", function(){
var productCode = $("#productCode").val();
var productName = $("#productName").val();
var categoryID = $("#categoryID").val();
var unit = $("#unit").val();
var unitPrice1 = $("#unitPrice1").val();
var unitPrice2 = $("#unitPrice2").val();
var unitPrice3 = $("#unitPrice3").val();
var hpp = $("#hpp").val();
var purchasePrice = $("#purchasePrice").val();
var note = $("#note").val();
var image = $("#image").val();
var minimumStock = $("#minimumStock").val();

if (productCode != '' && productName != '' && categoryID != '' &&


unit != '' && unitPrice1 != '' && unitPrice2 != '' && unitPrice3
!= '' && hpp != '' && purchasePrice != '' && minimumStock != ''){

$.ajax({
type: 'POST',
url: 'save_product.php',
dataType: 'JSON',
data:{
productCode: productCode,
productName: productName,

72
categoryID: categoryID,
unit: unit,
unitPrice1: unitPrice1,
unitPrice2: unitPrice2,
unitPrice3: unitPrice3,
hpp: hpp,
purchasePrice: purchasePrice,
note: note,
image: image,
minimumStock: minimumStock
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "products.php";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">
<div class="box-header">

73
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Produk</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">

<form method="GET" action="products.php">


<input type="hidden" name="module" value="product">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$q}" id="q" name="q"
class="form-control" placeholder="Pencarian : Kode atau Nama
Produk" style="float: right; width: 270px;" required>
<a href="#inline" class="modalbox" style="float:
left;"><button class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_products.php?act=print&q={$q}" style="
float: left;" target="_blank"><button type="button" class="btn
btn-default pull-right"><i class="fa fa-print"></i> Print
PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>

</div>
</div>
</div><!-- /.box-header -->

{if $module == 'product' AND $act == 'search'}


<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE - NAMA PRODUK <i class="fa fa-sort"></i></th>
<th>SATUAN <i class="fa fa-sort"></i></th>
<th>HARGA 1 <i class="fa fa-sort"></i></th>
<th>HARGA 2 <i class="fa fa-sort"></i></th>
<th>HARGA 3 <i class="fa fa-sort"></i></th>
<th>HPP <i class="fa fa-sort"></i></th>
<th>STOCK <i class="fa fa-sort"></i></th>
<th width="80">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataProduct loop=$dataProduct}
<tr>
<td>{$dataProduct[dataProduct].no}</td>
<td>{$dataProduct[dataProduct].productName}</td>
<td align="center">{$dataProduct[dataProduct].unit}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice1}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice2}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice3}</td>
<td align="right">{$dataProduct[dataProduct].hpp}</td>
<td align="center">{$dataProduct[dataProduct].stockAmount}</td>
<td>
<a title="Stok Gudang" href="edit_stock.php?module=product
&act=stock&productID={$dataProduct[dataProduct].productID}" data-

74
width="900" data-height="420" class="various3 fancybox.iframe">
<img src="img/icons/gudang.png" width="18"></a>
<a title="Edit" href="edit_products.php?module=product&act=edit
&productID={$dataProduct[dataProduct].productID}" data-width="900"
data-height="420" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="products.php?module=product&act=delete&
productID={$dataProduct[dataProduct].productID}&pic={$dataProduct[
dataProduct].image}" onclick="return confirm('Anda Yakin ingin
menghapus produk {$dataProduct[dataProduct].productName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}

</tbody>
</table>
</div>
</div><!-- /.box-body -->

{else}
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE - NAMA PRODUK <i class="fa fa-sort"></i></th>
<th>SATUAN <i class="fa fa-sort"></i></th>
<th>HARGA 1 <i class="fa fa-sort"></i></th>
<th>HARGA 2 <i class="fa fa-sort"></i></th>
<th>HARGA 3 <i class="fa fa-sort"></i></th>
<th>HPP <i class="fa fa-sort"></i></th>
<th>STOCK <i class="fa fa-sort"></i></th>
<th width="80">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataProduct loop=$dataProduct}
<tr>
<td>{$dataProduct[dataProduct].no}</td>
<td>{$dataProduct[dataProduct].productName}</td>
<td align="center">{$dataProduct[dataProduct].unit}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice1}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice2}</td>
<td align="right">{$dataProduct[dataProduct].unitPrice3}</td>
<td align="right">{$dataProduct[dataProduct].hpp}</td>
<td align="center">{$dataProduct[dataProduct].stockAmount}</td>
<td>
<a title="Stok Gudang" href="edit_stock.php?module=
product&act=stock&productID={$dataProduct[dataProduct].productID}"
data-width="900" data-height="420" class="various3 fancybox
.iframe"><img src="img/icons/gudang.png" width="18"></a>
<a title="Edit" href="edit_products.php?module=product
&act=edit&productID={$dataProduct[dataProduct].productID}" data-
width="900" data-height="420" class="various2 fancybox.iframe">
<img src="img/icons/edit.png" width="18"></a>

75
<a title="Delete" href="products.php?module=product&act=delete&
productID={$dataProduct[dataProduct].productID}&pic={$dataProduct[
dataProduct].image}" onclick="return confirm('Anda Yakin ingin
menghapus produk {$dataProduct[dataProduct].productName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}

</tbody>
</table>
</div>
</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Produk</h3></td>
</tr>
<tr>
<td>
<form id="product" name="product" method="POST" action="#">
<table cellpadding="7" cellspacing="7">
<tr valign="top">
<td width="130">Kode Produk</td>
<td width="5">:</td>
<td>
<input type="hidden" value="{$productCode}"
id="productCode" name="productCode">
<input type="text" value="{$productCode}"
id="productCode" name="productCode" class="form-control"
placeholder="Kode Produk" style="width: 270px;" DISABLED>
</td>
<td width="120">Harga Beli</td>
<td width="5">:</td>
<td><input type="number" id="purchasePrice"
name="purchasePrice" class="form-control" placeholder="Harga Beli"
style="width: 270px;" required></td>
</tr>
<tr>
<td>Nama Produk</td>
<td>:</td>
<td><input type="text" id="productName"
name="productName" class="form-control" placeholder="Nama Produk"
style="width: 270px;" required></td>
<td>Minimum Stok</td>
<td>:</td>

76
<td><input type="number" id="minimumStock"
name="minimumStock" class="form-control" placeholder="Minimum
Stok" style="width: 270px;" required></td>
</tr>
<tr valign="top">
<td>Kategori</td>
<td>:</td>
<td>
<select id="categoryID" name="categoryID" class="form-
control" style="width: 270px;" required>
<option value=""></option>
{section name=dataCategory loop=$dataCategory}
<option value="{$dataCategory[dataCategory].categoryID}">{$data
Category[dataCategory].categoryName}</option>
{/section}
</select>
</td>
<td>Note</td>
<td>:</td>
<td><input type="text" id="note" name="note" class="form-
control" placeholder="Note" style="width: 270px;"></td>
</tr>
<tr valign="top">
<td>Satuan</td>
<td>:</td>
<td>
<select id="unit" name="unit" class="form-control"
style="width: 270px;" required>
<option value=""></option>
<option value="1">SET</option>
<option value="2">PCS</option>
</select>
</td>
<td>Gambar</td>
<td>:</td>
<td rowspan="8">
<div id="me" class="styleall" style="cursor:pointer;">
<label>
<button class="btn btn-warning">Browse</button>
</label>
</div>
<span id="mestatus"></span>
<div id="photoproduct">
<li class="nameupload"></li>
</div>

<div id="files">
<li class="success"></li>
</div>

</td>
</tr>
<tr>
<td>Harga Unit 1</td>
<td>:</td>

77
<td><input type="number" id="unitPrice1"
name="unitPrice1" class="form-control" placeholder="Harga Satuan
1" style="width: 270px;" required></td>
</tr>
<tr>
<td>Harga Unit 2</td>
<td>:</td>
<td><input type="number" id="unitPrice2"
name="unitPrice2" class="form-control" placeholder="Harga Satuan
2" style="width: 270px;" required></td>
</tr>
<tr>
<td>Harga Unit 3</td>
<td>:</td>
<td><input type="number" id="unitPrice3"
name="unitPrice3" class="form-control" placeholder="Harga Satuan
3" style="width: 270px;" required></td>
</tr>
<tr>
<td>HPP</td>
<td>:</td>
<td><input type="number" id="hpp" name="hpp" class="form-control"
placeholder="HPP" style="width: 270px;" required></td>
</tr>
</table>

<button id="send" class="btn btn-primary">Simpan</button>


</form>
</td>
</tr>
</table>
</div>
{/if}
</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

upload_product.php
<?php
$uploaddir = 'img/products/';
$file = $uploaddir ."asfa_".date('Ymdhis').basename($_FILES
['uploadfile']['name']);
$file_name= "cmp_".date('Ymdhis').$_FILES['uploadfile']['name'];

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file))
{
echo "$file_name";
}
else {

78
echo "error";
}
?>

save_product.php
<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$productCode = $_POST['productCode'];
$productName = $productCode."
".mysqli_real_escape_string($connect, $_POST['productName']);
$categoryID = $_POST['categoryID'];
$unit = $_POST['unit'];
$unitPrice1 = mysqli_real_escape_string($connect,
$_POST['unitPrice1']);
$unitPrice2 = mysqli_real_escape_string($connect,
$_POST['unitPrice2']);
$unitPrice3 = mysqli_real_escape_string($connect,
$_POST['unitPrice3']);
$hpp = mysqli_real_escape_string($connect, $_POST['hpp']);
$purchasePrice = mysqli_real_escape_string($connect,
$_POST['purchasePrice']);
$note = mysqli_real_escape_string($connect, $_POST['note']);
$image = $_POST['image'];
$minimumStock = mysqli_real_escape_string($connect,
$_POST['minimumStock']);

if ($productCode != '' && $productName != '' && $unit != '' &&


$purchasePrice != '' && $hpp != '' && $unitPrice1 != '' &&
$unitPrice2 != '' && $unitPrice3 != '' && $minimumStock != ''){

// set image to thumbnail


if ($image != '')
{
$file = "img/products/".$image;
$realPic = imagecreatefromjpeg($file);
$width = imagesx($realPic);
$height = imagesy($realPic);

$thumbWidth = 100;
$thumbHeight = 70;

$thumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);


imagecopyresampled($thumbPic, $realPic, 0, 0, 0, 0, $thumbWidth,
$thumbHeight, $width, $height);

imagejpeg($thumbPic, "img/products/thumb/small_".$image);

imagedestroy($realPic);
imagedestroy($thumbPic);
} // close bracket

79
$queryProduct = "INSERT INTO as_products( productCode,
productName,
categoryID,
unit,
unitPrice1,
unitPrice2,
unitPrice3,
hpp,
purchasePrice,
note,
image,
minimumStock,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$productCode',
'$productName',
'$categoryID',
'$unit',
'$unitPrice1',
'$unitPrice2',
'$unitPrice3',
'$hpp',
'$purchasePrice',
'$note',
'$image',
'$minimumStock',
'$createdDate',
'$staffID',
'',
'')";

$sqlProduct = mysqli_query($connect, $queryProduct);

if ($sqlProduct)
{
echo json_encode(OK);
}
}
exit();
?>

edit_products.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_products.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";

80
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'product' && $act == 'edit')


{
// insert method into a variable
$productID = $_GET['productID'];

// showing up the product data based on product id


$queryProduct = "SELECT * FROM as_products WHERE productID
= '$productID'";
$sqlProduct = mysqli_query($connect, $queryProduct);

// fetch data
$dataProduct = mysqli_fetch_array($sqlProduct);

// assign fetch data to the tpl


$smarty->assign("productID", $dataProduct['productID']);
$smarty->assign("productCode", $dataProduct['productCode']);
$smarty->assign("productName", $dataProduct['productName']);
$smarty->assign("categoryID", $dataProduct['categoryID']);
$smarty->assign("unit", $dataProduct['unit']);
$smarty->assign("unitPrice1", $dataProduct['unitPrice1']);
$smarty->assign("unitPrice2", $dataProduct['unitPrice2']);
$smarty->assign("unitPrice3", $dataProduct['unitPrice3']);
$smarty->assign("hpp", $dataProduct['hpp']);
$smarty->assign("purchasePrice", $dataProduct['purchasePrice']);
$smarty->assign("note", $dataProduct['note']);
$smarty->assign("stockAmount", $dataProduct['stockAmount']);
$smarty->assign("image", $dataProduct['image']);
$smarty->assign("minimumStock", $dataProduct['minimumStock']);

// showing up the categories data


$queryCategory = "SELECT * FROM as_categories WHERE status = 'Y'
ORDER BY categoryName ASC";
$sqlCategory = mysqli_query($connect, $queryCategory);

// fetch data
while ($dtCategory = mysqli_fetch_array($sqlCategory))
{
$dataCategory[] = array('categoryID' => $dtCategory['categoryID'],
'categoryName' => $dtCategory['categoryName']);
}

// assign to the tpl file


$smarty->assign("dataCategory", $dataCategory);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);

81
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

edit_products.tpl (simpan dalam folder templates)


<script src="design/js/jquery-1.8.1.min.js" type="text/javascript
"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<script type="text/javascript" src="design/js/ajaxupload.3.5.js" >


</script>
<link rel="stylesheet" type="text/css" href="design/css/Ajaxfile-
upload.css" />

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {

$("#product").submit(function() { return false; });

// Image
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'upload_product.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|jpeg)$/.test(ext))){
// extension is not allowed
mestatus.text('Hanya ekstensi .JPG/JPEG yang diijinkan.');
return false;
}
//mestatus.html('<img src="images/ajax-loader.gif" height="16"
width="16">');
mestatus.html('');
},
onComplete: function(file, response){
//On completion clear the status
mestatus.text('');

82
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response!=="error"){

$('<li></li>').appendTo('#files').html('<img
src="img/products/'+response+'" alt="" height="100"/><br
/>').addClass('success');
$('<li></li>').appendTo('#photoproduct').html('<input
type="hidden" id="image" name="image"
value="'+response+'">').addClass('nameupload');

} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});

$("#deleteimage").on("click", function(){
parent.jQuery.fancybox.close();
});

$("#send").on("click", function(){
var productID = $("#productID").val();
var productName = $("#productName").val();
var categoryID = $("#categoryID").val();
var unit = $("#unit").val();
var unitPrice1 = $("#unitPrice1").val();
var unitPrice2 = $("#unitPrice2").val();
var unitPrice3 = $("#unitPrice3").val();
var hpp = $("#hpp").val();
var purchasePrice = $("#purchasePrice").val();
var note = $("#note").val();
var image = $("#image").val();
var picture = $("#picture").val();
var minimumStock = $("#minimumStock").val();

if (productID != '' && productName != '' && categoryID != '' &&


unit != '' && unitPrice1 != '' && unitPrice2 != '' && unitPrice3
!= '' && hpp != '' && purchasePrice != '' && minimumStock != ''){

$.ajax({
type: 'POST',
url: 'save_edit_product.php',
dataType: 'JSON',
data:{
productID: productID,
productName: productName,
categoryID: categoryID,
unit: unit,
unitPrice1: unitPrice1,
unitPrice2: unitPrice2,
unitPrice3: unitPrice3,
hpp: hpp,
purchasePrice: purchasePrice,
note: note,
image: image,

83
picture: picture,
minimumStock: minimumStock
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'product' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Ubah Produk</h3></td>
</tr>
<tr>
<td>
<form id="product" name="product" method="POST" action="#">
<input type="hidden" id="productID" name="productID"
value="{$productID}">
<input type="hidden" id="picture" name="picture" value="{$image}">
<table cellpadding="7" cellspacing="7">
<tr valign="top">
<td width="130" style="font-family: 'Helvetica
Neue',Helvetica,Arial,sans-serif; font-size: 14px;">Kode
Produk</td>
<td width="5" style="font-family: 'Helvetica
Neue',Helvetica,Arial,sans-serif; font-size: 14px;">:</td>
<td>
<input type="hidden" value="{$productCode}" id="productCode"
name="productCode">
<input type="text" value="{$productCode}" id="productCode"
name="productCode" class="form-control" placeholder="Kode Produk"
style="width: 270px;" DISABLED>
</td>
<td width="120" style="font-family: 'Helvetica
Neue',Helvetica,Arial,sans-serif; font-size: 14px;">Harga
Beli</td>
<td width="5" style="font-family: 'Helvetica
Neue',Helvetica,Arial,sans-serif; font-size: 14px;">:</td>
<td><input type="number" value="{$purchasePrice}"
id="purchasePrice" name="purchasePrice" class="form-control"
placeholder="Harga Beli" style="width: 270px;" required></td>
</tr>
<tr>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Nama Produk</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>

84
<td><input type="text" value="{$productName}" id="productName"
name="productName" class="form-control" placeholder="Nama Produk"
style="width: 270px;" required></td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Minimum Stok</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="number" value="{$minimumStock}" id="minimumStock"
name="minimumStock" class="form-control" placeholder="Minimum
Stok" style="width: 270px;" required></td>
</tr>
<tr valign="top">
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Kategori</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td>
<select id="categoryID" name="categoryID"
class="form-control" style="width: 270px;" required>
<option value=""></option>
{section name=dataCategory loop=$dataCategory}
{if $categoryID == $dataCategory[dataCategory].categoryID}
<option value="{$dataCategory[dataCategory].categoryID}"
SELECTED>{$dataCategory[dataCategory].categoryName}</option>
{else}
<option value="{$dataCategory[dataCategory].categoryID}">
{$dataCategory[dataCategory].categoryName}</option>
{/if}
{/section}
</select>
</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Note</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width:
270px;"></td>
</tr>
<tr valign="top">
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Satuan</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td>
<select id="unit" name="unit" class="form-control"
style="width: 270px;" required>
<option value=""></option>
<option value="1" {if $unit == '1'} SELECTED {/if}>SET</option>
<option value="2" {if $unit == '2'} SELECTED {/if}>PCS</option>
</select>
</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Gambar</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td rowspan="8">

85
<div id="me" class="styleall" style="cursor:pointer;">
<label>
<button class="btn btn-warning">Browse</button>
</label>
</div>
<span id="mestatus"></span>
<div id="photoproduct">
<li class="nameupload"></li>
</div>
<div id="files">
<li class="success">
{if $image != ''}
<img src="img/products/thumb/small_{$image}"><br>
<span style="font-size: 10pt;"><a id="deleteimage"
href="products.php?module=product&act=deleteimage&productID={$prod
uctID}&picture={$image}">Hapus Gambar</a></span>
{/if}
</li>
</div>
</td>
</tr>
<tr>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Harga Unit 1</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="number" value="{$unitPrice1}" id="unitPrice1"
name="unitPrice1" class="form-control" placeholder="Harga Satuan
1" style="width: 270px;" required></td>
</tr>
<tr>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Harga Unit 2</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="number" value="{$unitPrice2}" id="unitPrice2"
name="unitPrice2" class="form-control" placeholder="Harga Satuan
2" style="width: 270px;" required></td>
</tr>
<tr>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">Harga Unit 3</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="number" value="{$unitPrice3}" id="unitPrice3"
name="unitPrice3" class="form-control" placeholder="Harga Satuan
3" style="width: 270px;" required></td>
</tr>
<tr>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">HPP</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-
serif; font-size: 14px;">:</td>
<td><input type="number" value="{$hpp}" id="hpp" name="hpp"
class="form-control" placeholder="HPP" style="width: 270px;"
required></td>
</tr>

86
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
{/if}
</body>

save_edit_product.php
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$productID = $_POST['productID'];
$productName = mysqli_real_escape_string($connect,
$_POST['productName']);
$categoryID = $_POST['categoryID'];
$unit = $_POST['unit'];
$unitPrice1 = mysqli_real_escape_string($connect,
$_POST['unitPrice1']);
$unitPrice2 = mysqli_real_escape_string($connect,
$_POST['unitPrice2']);
$unitPrice3 = mysqli_real_escape_string($connect,
$_POST['unitPrice3']);
$hpp = mysqli_real_escape_string($connect, $_POST['hpp']);
$purchasePrice = mysqli_real_escape_string($connect,
$_POST['purchasePrice']);
$note = mysqli_real_escape_string($connect, $_POST['note']);
$image = $_POST['image'];
$picture = $_POST['picture'];
$minimumStock = mysqli_real_escape_string($connect,
$_POST['minimumStock']);

if ($productID != '' && $productName != '' && $unit != '' &&


$purchasePrice != '' && $hpp != '' && $unitPrice1 != '' &&
$unitPrice2 != '' && $unitPrice3 != '' && $minimumStock != ''){

// set image to thumbnail


if ($image != '')
{
unlink("img/products/".$picture);
unlink("img/products/thumb/small_".$picture);

$file = "img/products/".$image;
$realPic = imagecreatefromjpeg($file);
$width = imagesx($realPic);
$height = imagesy($realPic);

$thumbWidth = 100;
$thumbHeight = 70;

$thumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);


imagecopyresampled($thumbPic, $realPic, 0, 0, 0, 0, $thumbWidth,

87
$thumbHeight, $width, $height);

imagejpeg($thumbPic, "img/products/thumb/small_".$image);

imagedestroy($realPic);
imagedestroy($thumbPic);

$queryProduct = "UPDATE as_products SET productName =


'$productName',
categoryID = '$categoryID',
unit = '$unit',
unitPrice1 = '$unitPrice1',
unitPrice2 = '$unitPrice2',
unitPrice3 = '$unitPrice3',
hpp = '$hpp',
purchasePrice = '$purchasePrice',
note = '$note',
image = '$image',
minimumStock = '$minimumStock',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE productID = '$productID'";
}

else
{
$queryProduct = "UPDATE as_products SET productName =
'$productName',
categoryID = '$categoryID',
unit = '$unit',
unitPrice1 = '$unitPrice1',
unitPrice2 = '$unitPrice2',
unitPrice3 = '$unitPrice3',
hpp = '$hpp',
purchasePrice = '$purchasePrice',
note = '$note',
minimumStock = '$minimumStock',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE productID = '$productID'";
}

$sqlProduct = mysqli_query($connect, $queryProduct);

if ($sqlProduct)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil seluruh skrip diatas akan menghasilkan master data produk yang bisa
dilihat melalui gambar-gambar berikut :

88
Gambar 5.10. Menampilkan data produk

Gambar 5.11. Menambah data produk

89
Gambar 5.12. Mengubah data produk

Gambar 5.13. Melihat stok gudang

5.1.5 Supplier
Master data supplier digunakan untuk menyimpan dan mengolah data-data
supplier atau pemasok perusahaan kita, disini penulis akan berikan tuntas skrip-
skrip yang dibutuhkan, buat beberapa file berikut, dimana masing-masing
skripnya bisa dilihat sebagai berikut :
suppliers.php
<?php

90
// include header
include "header.php";
// set the tpl page
$page = "suppliers.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'6'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is supplier and action is delete


if ($module == 'supplier' && $act == 'delete')
{
// insert method into a variable
$supplierID = $_GET['supplierID'];

// delete supplier
$querySupplier = "DELETE FROM as_suppliers WHERE supplierID =
'$supplierID'";
$sqlSupplier = mysqli_query($connect, $querySupplier);

// redirect to the supplier page


header("Location: suppliers.php");
} // close bracket

// if module is supplier and action is search


elseif ($module == 'supplier' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

$querySupplier = "SELECT * FROM as_suppliers WHERE


supplierCode LIKE '%$q%' OR supplierName LIKE '%$q%' ORDER BY
supplierName ASC";
$sqlSupplier = mysqli_query($connect, $querySupplier);

// fetch data
$i = 1;
while ($dtSupplier = mysqli_fetch_array($sqlSupplier))

91
{
$dataSupplier[] = array('supplierID' => $dtSupplier['supplierID'],
'supplierCode' => $dtSupplier['supplierCode'],
'supplierName' => $dtSupplier['supplierName'],
'address' => $dtSupplier['address'],
'phone' => $dtSupplier['phone'],
'fax' => $dtSupplier['fax'],
'contactPerson' => $dtSupplier['contactPerson'],
'email' => $dtSupplier['email'],
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataSupplier", $dataSupplier);
$smarty->assign("q", $q);
}

else
{
// get last sort supplier number
$queryNoSupplier = "SELECT supplierCode FROM as_suppliers
ORDER BY supplierCode DESC LIMIT 1";
$sqlNoSupplier = mysqli_query($connect, $queryNoSupplier);
$numsNoSupplier = mysqli_num_rows($sqlNoSupplier);
$dataNoSupplier = mysqli_fetch_array($sqlNoSupplier);

$start = substr($dataNoSupplier['supplierCode'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoSupplier == '0')
{
$supplierNo = "0000";
}
elseif ($tempNo == 1)
{
$supplierNo = "0000";
}
elseif ($tempNo == 2)
{
$supplierNo = "000";
}
elseif ($tempNo == 3)
{
$supplierNo = "00";
}
elseif ($tempNo == 4)
{
$supplierNo = "0";
}
elseif ($tempNo == 5)
{
$supplierNo = "";
}

$supplierCode = $supplierNo.$next;

92
$smarty->assign("supplierCode", $supplierCode);

// create new object pagination


$p = new PaginationSupplier;
// limit 20 data for page
$limit = 20;
$position = $p->searchPosition($limit);

// showing up the supplier data


$querySupplier = "SELECT * FROM as_suppliers ORDER BY
supplierCode ASC LIMIT $position,$limit";
$sqlSupplier = mysqli_query($connect, $querySupplier);

// fetch data
$i = 1 + $position;
while ($dtSupplier = mysqli_fetch_array($sqlSupplier))
{
$dataSupplier[] = array('supplierID' => $dtSupplier['supplierID'],
'supplierCode' => $dtSupplier['supplierCode'],
'supplierName' => $dtSupplier['supplierName'],
'address' => $dtSupplier['address'],
'phone' => $dtSupplier['phone'],
'fax' => $dtSupplier['fax'],
'contactPerson' => $dtSupplier['contactPerson'],
'email' => $dtSupplier['email'],
'no' => $i);
$i++;
}

$smarty->assign("dataSupplier", $dataSupplier);

// count data
$queryCountSupplier = "SELECT * FROM as_suppliers";
$sqlCountSupplier = mysqli_query($connect, $queryCountSupplier);
$amountData = mysqli_num_rows($sqlCountSupplier);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Supplier");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pengolahan data master supplier.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Supplier");
}

// include footer
include "footer.php";
?>

93
suppliers.tpl (simpan didalam folder templates)
{include file="header.tpl"}

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#supplier").submit(function() { return false; });


$("#supplier2").submit(function() { return false; });

$("#send").on("click", function(){
var supplierCode = $("#supplierCode").val();
var supplierName = $("#supplierName").val();
var contactPerson = $("#contactPerson").val();
var address = $("#address").val();
var city = $("#city").val();
var phone = $("#phone").val();
var fax = $("#fax").val();
var email = $("#email").val();

if (supplierCode != '' && supplierName != ''){

$.ajax({
type: 'POST',
url: 'save_supplier.php',
dataType: 'JSON',
data:{
supplierCode: supplierCode,
supplierName: supplierName,
contactPerson: contactPerson,
address: address,
city: city,
phone: phone,
fax: fax,
email: email
},

94
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "suppliers.php";
}
});
}
});
});
</script>
{/literal}

<header class="header">
{include file="logo.tpl"}
{include file="navigation.tpl"}
</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Supplier</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="suppliers.php">
<input type="hidden" name="module" value="supplier">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$q}" id="q" name="q"
class="form-control" placeholder="Pencarian : Kode atau Nama
Supplier" style="float: right; width: 270px;" required>

95
<a href="#inline" class="modalbox" style="float: left;"><button
class="btn btn-default pull-right"><i class="fa fa-plus"></i>
Add</button></a>
<a href="print_suppliers.php?act=print&q={$q}" style="float:
left;" target="_blank"><button type="button" class="btn btn-
default pull-right"><i class="fa fa-print"></i> Print
PDF</button></a>&nbsp;&nbsp;&nbsp;

</form>
</div>
</div>
</div><!-- /.box-header -->

{if $module == 'supplier' AND $act == 'search'}


<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA SUPPLIER <i class="fa fa-sort"></i></th>
<th>KONTAK PERSON <i class="fa fa-sort"></i></th>
<th>ALAMAT <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>FAX <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSupplier loop=$dataSupplier}
<tr>
<td>{$dataSupplier[dataSupplier].no}</td>
<td>{$dataSupplier[dataSupplier].supplierCode}</td>
<td>{$dataSupplier[dataSupplier].supplierName}</td>
<td>{$dataSupplier[dataSupplier].contactPerson}</td>
<td>{$dataSupplier[dataSupplier].address}</td>
<td>{$dataSupplier[dataSupplier].phone}</td>
<td>{$dataSupplier[dataSupplier].fax}</td>
<td>
<a title="Edit" href="edit_suppliers.php?module=supplier&act=
edit&supplierID={$dataSupplier[dataSupplier].supplierID}" data-
width="450" data-height="180" class="various2 fancybox.iframe">
<img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="suppliers.php?module=supplier&act=delete
&supplierID={$dataSupplier[dataSupplier].supplierID}"
onclick="return confirm('Anda Yakin ingin menghapus supplier
{$dataSupplier[dataSupplier].supplierName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->

96
{else}
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE <i class="fa fa-sort"></i></th>
<th>NAMA SUPPLIER <i class="fa fa-sort"></i></th>
<th>KONTAK PERSON <i class="fa fa-sort"></i></th>
<th>ALAMAT <i class="fa fa-sort"></i></th>
<th>TLP <i class="fa fa-sort"></i></th>
<th>FAX <i class="fa fa-sort"></i></th>
<th width="60">AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSupplier loop=$dataSupplier}
<tr>
<td>{$dataSupplier[dataSupplier].no}</td>
<td>{$dataSupplier[dataSupplier].supplierCode}</td>
<td>{$dataSupplier[dataSupplier].supplierName}</td>
<td>{$dataSupplier[dataSupplier].contactPerson}</td>
<td>{$dataSupplier[dataSupplier].address}</td>
<td>{$dataSupplier[dataSupplier].phone}</td>
<td>{$dataSupplier[dataSupplier].fax}</td>
<td>
<a title="Edit" href="edit_suppliers.php?module=supplier&act=edit&
supplierID={$dataSupplier[dataSupplier].supplierID}" data-
width="450" data-height="180" class="various2 fancybox.iframe">
<img src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="suppliers.php?module=supplier&act=delete&
supplierID={$dataSupplier[dataSupplier].supplierID}"
onclick="return confirm('Anda Yakin ingin menghapus supplier
{$dataSupplier[dataSupplier].supplierName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Supplier</h3></td>

97
</tr>
<tr>
<td>
<form id="supplier" name="supplier" method="POST" action="#">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Kode</td>
<td width="5">:</td>
<td>
<input type="hidden" value="{$supplierCode}" id="supplierCode"
name="supplierCode">
<input type="text" value="{$supplierCode}" id="supplierCode"
name="supplierCode" class="form-control" placeholder="Kode
Supplier" style="width: 270px;" DISABLED>
</td>
</tr>
<tr>
<td>Nama Supplier</td>
<td>:</td>
<td><input type="text" id="supplierName"
name="supplierName" class="form-control" placeholder="Nama
Supplier" style="width: 270px;" required></td>
</tr>
<tr>
<td>Kontak Person</td>
<td>:</td>
<td><input type="text" id="contactPerson"
name="contactPerson" class="form-control" placeholder="Kontak
Person" style="width: 270px;"></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input type="text" id="address" name="address" class="form-
control" placeholder="Alamat" style="width: 270px;"></td>
</tr>
<tr>
<td>Kota</td>
<td>:</td>
<td><input type="text" id="city" name="city" class="form-control"
placeholder="Kota" style="width: 270px;"></td>
</tr>
<tr>
<td>Telepon</td>
<td>:</td>
<td><input type="text" id="phone" name="phone" class="form-
control" placeholder="Telepon" style="width: 270px;"></td>
</tr>
<tr>
<td>Fax</td>
<td>:</td>
<td><input type="text" id="fax" name="fax" class="form-
control" placeholder="Fax" style="width: 270px;"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>

98
<td><input type="email" id="email" name="email" class="form-
control" placeholder="Email" style="width: 270px;"></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>
{/if}
</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

save_supplier.php
<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$supplierCode = mysqli_real_escape_string($connect,
$_POST['supplierCode']);
$supplierName = mysqli_real_escape_string($connect,
$_POST['supplierName']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$phone = mysqli_real_escape_string($connect, $_POST['phone']);
$fax = mysqli_real_escape_string($connect, $_POST['fax']);
$contactPerson = mysqli_real_escape_string($connect,
$_POST['contactPerson']);
$email = mysqli_real_escape_string($connect, $_POST['email']);

if ($supplierCode != '' && $supplierName != ''){

$querySupplier = "INSERT INTO as_suppliers(


supplierCode,
supplierName,
address,
city,
phone,
fax,
contactPerson,
email,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)

99
VALUES( '$supplierCode',
'$supplierName',
'$address',
'$city',
'$phone',
'$fax',
'$contactPerson',
'$email',
'$createdDate',
'$staffID',
'',
'')";

$sqlSupplier = mysqli_query($connect, $querySupplier);

if ($sqlSupplier)
{
echo json_encode(OK);
}
}
exit();
?>

edit_suppliers.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_suppliers.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'supplier' && $act == 'edit')


{
// insert method into a variable
$supplierID = $_GET['supplierID'];

// showing up the supplier data based on supplier id


$querySupplier = "SELECT * FROM as_suppliers WHERE supplierID =
'$supplierID'";
$sqlSupplier = mysqli_query($connect, $querySupplier);

// fetch data

100
$dataSupplier = mysqli_fetch_array($sqlSupplier);

// assign fetch data to the tpl


$smarty->assign("supplierID", $dataSupplier['supplierID']);
$smarty->assign("supplierCode", $dataSupplier['supplierCode']);
$smarty->assign("supplierName", $dataSupplier['supplierName']);
$smarty->assign("address", $dataSupplier['address']);
$smarty->assign("city", $dataSupplier['city']);
$smarty->assign("phone", $dataSupplier['phone']);
$smarty->assign("fax", $dataSupplier['fax']);
$smarty->assign("contactPerson", $dataSupplier['contactPerson']);
$smarty->assign("email", $dataSupplier['email']);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

edit_suppliers.tpl (simpan didalam folder templates)


<script src="design/js/jquery-1.8.1.min.js" type="text/javascript
"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {

$("#supplier").submit(function() { return false; });


$("#send").on("click", function(){
var supplierID = $("#supplierID").val();
var supplierName = $("#supplierName").val();
var contactPerson = $("#contactPerson").val();
var address = $("#address").val();
var city = $("#city").val();
var phone = $("#phone").val();
var fax = $("#fax").val();
var email = $("#email").val();

101
if (supplierID != '' && supplierName != ''){

$.ajax({
type: 'POST',
url: 'save_edit_supplier.php',
dataType: 'JSON',
data:{
supplierID: supplierID,
supplierName: supplierName,
contactPerson: contactPerson,
address: address,
city: city,
phone: phone,
fax: fax,
email: email
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'supplier' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Ubah Supplier</h3></td>
</tr>
<tr>
<td>
<form id="supplier" name="supplier" method="POST" action="#">
<input type="hidden" id="supplierID" name="supplierID"
value="{$supplierID}">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Kode</td>
<td width="5">:</td>
<td><input type="text" value="{$supplierCode}"
id="supplierCode" name="supplierCode" class="form-control"
placeholder="Kode Supplier" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>Nama Supplier</td>
<td>:</td>
<td><input type="text" value="{$supplierName}"
id="supplierName" name="supplierName" class="form-control"
placeholder="Nama Supplier" style="width: 270px;" required></td>
</tr>
<tr>
<td>Kontak Person</td>
<td>:</td>

102
<td><input type="text" value="{$contactPerson}"
id="contactPerson" name="contactPerson" class="form-control"
placeholder="Kontak Person" style="width: 270px;"></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input type="text" value="{$address}" id="address"
name="address" class="form-control" placeholder="Alamat"
style="width: 270px;"></td>
</tr>
<tr>
<td>Kota</td>
<td>:</td>
<td><input type="text" value="{$city}" id="city" name="city"
class="form-control" placeholder="Kota" style="width:
270px;"></td>
</tr>
<tr>
<td>Telepon</td>
<td>:</td>
<td><input type="text" value="{$phone}" id="phone"
name="phone" class="form-control" placeholder="Telepon"
style="width: 270px;"></td>
</tr>
<tr>
<td>Fax</td>
<td>:</td>
<td><input type="text" value="{$fax}" id="fax" name="fax"
class="form-control" placeholder="Fax" style="width: 270px;"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="email" value="{$email}" id="email"
name="email" class="form-control" placeholder="Email"
style="width: 270px;"></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>

{/if}
</body>

save_edit_supplier.php
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];

103
$supplierID = $_POST['supplierID'];
$supplierName = mysqli_real_escape_string($connect,
$_POST['supplierName']);
$contactPerson = mysqli_real_escape_string($connect,
$_POST['contactPerson']);
$address = mysqli_real_escape_string($connect, $_POST['address']);
$city = mysqli_real_escape_string($connect, $_POST['city']);
$phone = mysqli_real_escape_string($connect, $_POST['phone']);
$fax = mysqli_real_escape_string($connect, $_POST['fax']);
$email = mysqli_real_escape_string($connect, $_POST['email']);

if ($supplierID != '' && $supplierName != ''){

$querySupplier = "UPDATE as_suppliers SET supplierName =


'$supplierName',
address = '$address',
city = '$city',
phone = '$phone',
fax = '$fax',
contactPerson = '$contactPerson',
email = '$email',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE supplierID = '$supplierID'";

$sqlSupplier = mysqli_query($connect, $querySupplier);

if ($sqlSupplier)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil seluruh skrip diatas akan menghasilkan halaman master data supplier
dimana hasilnya bisa dilihat melalui gambar-gambar berikut :

Gambar 5.14. Menampilkan data supplier

104
Gambar 5.15. Menambah data supplier

105
Gambar 5.16. Mengubah data supplier

5.1.6 Gudang
Master data gudang digunakan untuk menyimpan dan mengolah gudang yang
ada di perusahaan kita. Disini kita akan membuat sekaligus proses aktifitas yang
ada di master data gudang.
Buat beberapa file dengan masing-masing skrip berikut :

106
factories.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "factories.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '12'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is factory and action is delete


if ($module == 'factory' && $act == 'delete')
{
// insert method into a variable
$factoryID = $_GET['factoryID'];

// delete factories
$queryFactory = "DELETE FROM as_factories WHERE factoryID
= '$factoryID'";
$sqlFactory = mysqli_query($connect, $queryFactory);

// redirect to the factory page


header("Location: factories.php");
} // close bracket

// if the module is factory and action is search


elseif ($module == 'factory' && $act == 'search')
{
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryFactory = "SELECT * FROM as_factories WHERE


factoryCode LIKE '%$q%' OR factoryName LIKE '%$q%' ORDER BY
factoryName ASC";
$sqlFactory = mysqli_query($connect, $queryFactory);

107
// fetch data
$i = 1;
while ($dtFactory = mysqli_fetch_array($sqlFactory))
{
if ($dtFactory['factoryType'] == '1')
{
$factoryType = "TETAP";
}
else
{
$factoryType = "SEMENTARA (SEWA)";
}

$dataFactory[] = array('factoryID' => $dtFactory['factoryID'],


'factoryCode' => $dtFactory['factoryCode'],
'factoryName' => $dtFactory['factoryName'],
'factoryType' => $factoryType,
'status' => $dtFactory['status'],
'note' => $dtFactory['note'],
'no' => $i);
$i++;
}

// assign
$smarty->assign("dataFactory", $dataFactory);
$smarty->assign("q", $q);
}

else
{
// get last sort factory number
$queryNoFactory = "SELECT factoryCode FROM as_factories ORDER BY
factoryCode DESC LIMIT 1";
$sqlNoFactory = mysqli_query($connect, $queryNoFactory);
$numsNoFactory = mysqli_num_rows($sqlNoFactory);
$dataNoFactory = mysqli_fetch_array($sqlNoFactory);

$start = substr($dataNoFactory['factoryCode'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoFactory == '0')
{
$factoryNo = "0000";
}
elseif ($tempNo == 1)
{
$factoryNo = "0000";
}
elseif ($tempNo == 2)
{
$factoryNo = "000";
}
elseif ($tempNo == 3)
{
$factoryNo = "00";
}

108
elseif ($tempNo == 4)
{
$factoryNo = "0";
}
elseif ($tempNo == 5)
{
$factoryNo = "";
}

$factoryCode = $factoryNo.$next;

$smarty->assign("factoryCode", $factoryCode);

// create new object pagination


$p = new PaginationFactory;
// limit 20 data for page
$limit = 20;
$position = $p->searchPosition($limit);

// showing up the factories data


$queryFactory = "SELECT * FROM as_factories ORDER BY
factoryCode ASC LIMIT $position,$limit";
$sqlFactory = mysqli_query($connect, $queryFactory);

// fetch data
$i = 1 + $position;
while ($dtFactory = mysqli_fetch_array($sqlFactory))
{
if ($dtFactory['factoryType'] == '1')
{
$factoryType = "TETAP";
}
else
{
$factoryType = "SEMENTARA (SEWA)";
}

$dataFactory[] = array('factoryID' => $dtFactory['factoryID'],


'factoryCode' => $dtFactory['factoryCode'],
'factoryName' => $dtFactory['factoryName'],
'factoryType' => $factoryType,
'status' => $dtFactory['status'],
'note' => $dtFactory['note'],
'no' => $i);
$i++;
}

$smarty->assign("dataFactory", $dataFactory);

// count data
$queryCountFactory = "SELECT * FROM as_factories";
$sqlCountFactory = mysqli_query($connect, $queryCountFactory);
$amountData = mysqli_num_rows($sqlCountFactory);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

109
$smarty->assign("pageLink", $pageLink);
}

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Gudang / Pabrik");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pengolahan data master gudang atau pabrik.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Gudang / Pabrik");
}

// include footer
include "footer.php";
?>

factories.tpl
{include file="header.tpl"}

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#factory").submit(function() { return false; });


$("#factory").submit(function() { return false; });

$("#send").on("click", function(){
var factoryCode = $("#factoryCode").val();
var factoryName = $("#factoryName").val();
var factoryType = $("#factoryType").val();
var status = $("#status").val();
var note = $("#note").val();

if (factoryCode != '' && factoryName != '' && factoryType != '' &&


status != ''){

110
$.ajax({
type: 'POST',
url: 'save_factory.php',
dataType: 'JSON',
data:{
factoryCode: factoryCode,
factoryName: factoryName,
factoryType: factoryType,
status: status,
note: note
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "factories.php";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

111
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Gudang / Pabrik</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="factories.php">
<input type="hidden" name="module" value="factory">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$q}" id="q" name="q"
class="form-control" placeholder="Pencarian : Kode atau Nama
Gudang" style="float: right; width: 270px;" required>
<a href="#inline" class="modalbox" style="float: left;"><button
class="btn btn-default pull-right"><i class="fa fa-plus"></i>
Add</button></a>
<a href="print_factories.php?act=print&q={$q}" style="float:
left;" target="_blank"><button class="btn btn-default pull-right"
type="button"><i class="fa fa-print"></i> Print PDF</button></a>
&nbsp;&nbsp;&nbsp;
</form>

</div>
</div>
</div><!-- /.box-header -->

{if $module == 'factory' AND $act == 'search'}


<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE GUDANG <i class="fa fa-sort"></i></th>
<th>NAMA GUDANG <i class="fa fa-sort"></i></th>
<th>TIPE <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataFactory loop=$dataFactory}
<tr>
<td>{$dataFactory[dataFactory].no}</td>
<td>{$dataFactory[dataFactory].factoryCode}</td>
<td>{$dataFactory[dataFactory].factoryName}</td>
<td>{$dataFactory[dataFactory].factoryType}</td>
<td>{$dataFactory[dataFactory].status}</td>
<td>
<a title="Edit" href="edit_factories.php?module=factory&act=edit&
factoryID={$dataFactory[dataFactory].factoryID}" data-width="450"
data-height="180" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
<a title="Delete"
href="factories.php?module=factory&act=delete&factoryID=
{$dataFactory[dataFactory].factoryID}" onclick="return
confirm('Anda Yakin ingin menghapus gudang {$dataFactory

112
[dataFactory].factoryName}?');"><img src="img/icons/delete.png"
width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{else}
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>KODE GUDANG <i class="fa fa-sort"></i></th>
<th>NAMA GUDANG <i class="fa fa-sort"></i></th>
<th>TIPE <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataFactory loop=$dataFactory}
<tr>
<td>{$dataFactory[dataFactory].no}</td>
<td>{$dataFactory[dataFactory].factoryCode}</td>
<td>{$dataFactory[dataFactory].factoryName}</td>
<td>{$dataFactory[dataFactory].factoryType}</td>
<td>{$dataFactory[dataFactory].status}</td>
<td>
<a title="Edit" href="edit_factories.php?module=factory&act=edit&
factoryID={$dataFactory[dataFactory].factoryID}" data-width="450"
data-height="180" class="various2 fancybox.iframe"> <img
src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="factories.php?module=factory&act=delete&
factoryID={$dataFactory[dataFactory].factoryID}" onclick="return
confirm('Anda Yakin ingin menghapus gudang
{$dataFactory[dataFactory].factoryName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>

113
</div>
</div><!-- /.box-header -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Gudang / Pabrik</h3></td>
</tr>
<tr>
<td>
<form id="factory" name="factory" method="POST" action="#">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Kode Gudang</td>
<td width="5">:</td>
<td><input type="hidden" value="{$factoryCode}" id="factoryCode"
name="factoryCode">
<input type="text" value="{$factoryCode}" id="factoryCode"
name="factoryCode" class="form-control" placeholder="Kode Gudang"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>Nama Gudang</td>
<td>:</td>
<td><input type="text" id="factoryName" name="factoryName"
class="form-control" placeholder="Nama Gudang" style="width:
270px;" required></td>
</tr>
<tr>
<td>Tipe</td>
<td>:</td>
<td><select name="factoryType" id="factoryType" class="form-
control" required>
<option value="">- Pilih Status -</option>
<option value="1">Tetap</option>
<option value="2">Sementara (Sewa)</option>
</select></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status" id="status" class="form-control"
required>
<option value="">- Pilih Status -</option>
<option value="Y">Y (Aktif)</option>
<option value="N">N (Tidak Aktif)</option>
</select></td>
</tr>
<tr valign="top">
<td>Note</td>
<td>:</td>
<td><textarea class="textarea" name="note" id="note"
placeholder="Note" style="width: 100%; height: 125px; font-size:
14px; line-height: 18px; border: 1px solid #dddddd; padding:
10px;"></textarea></td>
</tr>
</table>

114
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>
{/if}
</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

save_factory.php
<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$factoryCode = $_POST['factoryCode'];
$factoryName = mysqli_real_escape_string($connect,
$_POST['factoryName']);
$factoryType = $_POST['factoryType'];
$status = $_POST['status'];
$note = mysqli_real_escape_string($connect, $_POST['note']);

if ($factoryCode != '' && $factoryName != '' && $factoryType != ''


&& $status != ''){

$queryFactory = "INSERT INTO as_factories( factoryCode,


factoryName,
factoryType,
status,
note,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$factoryCode',
'$factoryName',
'$factoryType',
'$status',
'$note',
'$createdDate',
'$staffID',
'',
'')";

$sqlFactory = mysqli_query($connect, $queryFactory);

115
if ($sqlFactory)
{
echo json_encode(OK);
}

}
exit();
?>

edit_factory.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_factories.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'factory' && $act == 'edit')


{
// insert method into a variable
$factoryID = $_GET['factoryID'];

// showing up the factory data based on factory id


$queryFactory = "SELECT * FROM as_factories WHERE factoryID =
'$factoryID'";
$sqlFactory = mysqli_query($connect, $queryFactory);

// fetch data
$dataFactory = mysqli_fetch_array($sqlFactory);

// assign fetch data to the tpl


$smarty->assign("factoryID", $dataFactory['factoryID']);
$smarty->assign("factoryCode", $dataFactory['factoryCode']);
$smarty->assign("factoryName", $dataFactory['factoryName']);
$smarty->assign("factoryType", $dataFactory['factoryType']);
$smarty->assign("status", $dataFactory['status']);
$smarty->assign("note", $dataFactory['note']);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

116
} // close bracket

// include footer
include "footer.php";
?>

edit_factories.tpl
<script src="design/js/jquery-1.8.1.min.js" type="text/
javascript"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {

$("#factory").submit(function() { return false; });


$("#send").on("click", function(){
var factoryID = $("#factoryID").val();
var factoryName = $("#factoryName").val();
var factoryType = $("#factoryType").val();
var status = $("#status").val();
var note = $("#note").val();

if (factoryID != '' && factoryName != '' && factoryType !=


'' && status != ''){

$.ajax({
type: 'POST',
url: 'save_edit_factory.php',
dataType: 'JSON',
data:{
factoryID: factoryID,
factoryName: factoryName,
factoryType: factoryType,
status: status,
note: note
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}

117
});
}
});
});
</script>
{/literal}

{if $module == 'factory' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Ubah Gudang / Pabrik</h3></td>
</tr>
<tr>
<td>
<form id="factory" name="factory" method="POST" action="#">
<input type="hidden" id="factoryID" name="factoryID"
value="{$factoryID}">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Kode Gudang</td>
<td width="5">:</td>
<td><input type="text" id="factoryCode"
name="factoryCode" value="{$factoryCode}" class="form-control"
placeholder="Kode Gudang" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>Nama Gudang</td>
<td>:</td>
<td><input type="text" id="factoryName"
name="factoryName" value="{$factoryName}" class="form-control"
placeholder="Nama Gudang" style="width: 270px;" required></td>
</tr>
<tr>
<td>Tipe</td>
<td>:</td>
<td><select name="factoryType" id="factoryType" class="form-
control" required>
<option value="">- Pilih Status -</option>
<option value="1" {if $factoryType == '1'} SELECTED
{/if}>Tetap</option>
<option value="2" {if $factoryType == '2'} SELECTED
{/if}>Sementara (Sewa)</option>
</select></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status" id="status" class="form-
control" required>
<option value="">- Pilih Status -</option>
<option value="Y" {if $status == 'Y'} SELECTED
{/if}>Y (Aktif)</option>
<option value="N" {if $status == 'N'} SELECTED
{/if}>N (Tidak Aktif)</option>
</select></td>
</tr>
<tr valign="top">

118
<td>Note</td>
<td>:</td>
<td><textarea class="textarea" name="note"
id="note" placeholder="Note" style="width: 100%; height: 125px;
font-size: 14px; line-height: 18px; border: 1px solid #dddddd;
padding: 10px;">{$note}</textarea></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
{/if}
</body>

save_edit_factory.php

<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$factoryID = $_POST['factoryID'];
$factoryName = mysqli_real_escape_string($connect,
$_POST['factoryName']);
$factoryType = $_POST['factoryType'];
$status = $_POST['status'];
$note = mysqli_real_escape_string($connect, $_POST['note']);

if ($factoryID != '' && $factoryName != '' && $factoryType != ''


&& $status != ''){

$queryFactory = "UPDATE as_factories SET factoryName =


'$factoryName',
factoryType = '$factoryType',
status = '$status',
note = '$note',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE factoryID = '$factoryID'";

$sqlFactory = mysqli_query($connect, $queryFactory);

if ($sqlFactory)
{
echo json_encode(OK);
}
}
exit();
?>

119
Hasil seluruh skrip diatas, akan menampilkan halaman master data gudang yang
dapat dilihat pada gambar-gambar berikut :

Gambar 5.17. Menampilkan data gudang

Gambar 5.18. Menambahkan data gudang

120
Gambar 5.19. Mengubah data gudang

5.1.7 Level Authorize


Kita bisa melakukan otorisasi level, maksudnya adalah kita bisa
mengkonfigurasikan agar level administrator bisa melakukan / akses ke halaman
apa saja, misalnya kita bisa men-set agar admin bisa mengakses halaman master
data saja, itu bisa kita lakukan, nah, halaman ini digunakan untuk mengolah data
tersebut.
Buat beberapa file dengan nama dan skrip sebagai berikut :

121
authorize.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "authorize.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '25'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff =
mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// showing up the modules data


$queryModule = "SELECT * FROM as_modules ORDER BY modulID ASC";
$sqlModule = mysqli_query($connect, $queryModule);

// fetch data
$i = 1;
while ($dtModule = mysqli_fetch_array($sqlModule))
{
$a = str_replace("1", " Administrator", $dtModule['authorize']);
$b = str_replace("2", " Sales", $a);
$c = str_replace("3", " Kasir", $b);
$d = str_replace("4", " Spv", $c);
$e = str_replace("5", " Top", $d);
$f = str_replace("0", "", $e);
$g = str_replace(",,,", ",", $f);
$h = str_replace(",,", ",", $g);

$dataModule[] = array( 'modulID' => $dtModule['modulID'],


'modulName' => $dtModule['modulName'],
'authorize' => $h,
'status' => $dtModule['status'],
'no' => $i);
$i++;
}

122
$smarty->assign("dataModule", $dataModule);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Manajemen Level Authorize");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pengolahan data master otorisasi level.");
$smarty->assign("breadcumbMenuName", "Master Data");
$smarty->assign("breadcumbMenuSubName", "Level Authorize");
}

// include footer
include "footer.php";
?>

authorize.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#authorize").submit(function() { return false; });


$("#authorize2").submit(function() { return false; });
});
</script>
{/literal}

<header class="header">
{include file="logo.tpl"}
{include file="navigation.tpl"}
</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->

123
<aside class="left-side sidebar-offcanvas">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">

{include file="user_panel.tpl"}
{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>
<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Data Otorisasi Level</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_authorize.php?act=print" target="_blank"><button
class="btn btn-default pull-right"><i class="fa fa-print"></i>
Print PDF</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NAMA MODUL <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>OTORISASI <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataModule loop=$dataModule}
<tr>
<td>{$dataModule[dataModule].no}</td>
<td>{$dataModule[dataModule].modulName}</td>
<td>{$dataModule[dataModule].status}</td>
<td>{$dataModule[dataModule].authorize}</td>
<td>

124
<a title="Edit" href="edit_authorize.php?module=authorize&act=
edit&modulID={$dataModule[dataModule].modulID}" data-width="450"
data-height="180" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->

</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

edit_authorize.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_authorize.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

if ($module == 'authorize' && $act == 'edit')


{
// insert method into a variable
$modulID = $_GET['modulID'];

// showing up the modules data based on modul id


$queryModul = "SELECT * FROM as_modules WHERE modulID =
'$modulID'";
$sqlModul = mysqli_query($connect, $queryModul);

// fetch data
$dataModul = mysqli_fetch_array($sqlModul);

125
$authorize = explode(",", $dataModul['authorize']);

// assign fetch data to the tpl


$smarty->assign("modulID", $dataModul['modulID']);
$smarty->assign("modulName", $dataModul['modulName']);
$smarty->assign("status", $dataModul['status']);
$smarty->assign("adm", $authorize[0]);
$smarty->assign("sls", $authorize[1]);
$smarty->assign("ksr", $authorize[2]);
$smarty->assign("spv", $authorize[3]);
$smarty->assign("top", $authorize[4]);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

edit_authorize.tpl (simpan didalam folder templates)


<script src="design/js/jquery-1.8.1.min.js" type="text/
javascript"> </script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {

$("#authorize").submit(function() { return false; });

$("#send").on("click", function(){
var modulID = $("#modulID").val();
var status = $("#status").val();
if ($("#authorize1").is(':checked')){
var authorize1 = "1,";
}
else{
var authorize1 = "0,";
}

126
if ($("#authorize2").is(':checked')){
var authorize2 = "2,";
}
else{
var authorize2 = "0,";
}

if ($("#authorize3").is(':checked')){
var authorize3 = "3,";
}
else{
var authorize3 = "0,";
}

if ($("#authorize4").is(':checked')){
var authorize4 = "4,";
}
else{
var authorize4 = "0,";
}

if ($("#authorize5").is(':checked')){
var authorize5 = "5";
}
else{
var authorize5 = "0";
}

if (modulID != ''){

$.ajax({
type: 'POST',
url: 'save_edit_authorize.php',
dataType: 'JSON',
data:{
modulID: modulID,
status: status,
authorize1: authorize1,
authorize2: authorize2,
authorize3: authorize3,
authorize4: authorize4,
authorize5: authorize5
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'authorize' AND $act == 'edit'}

127
<table width="95%" align="center">
<tr>
<td align="center"><h3><b>OTORISASI LEVEL</b></h3></td>
</tr>
<tr>
<td>
<form id="authorize" name="authorize" method="POST" action="#">
<input type="hidden" id="modulID" name="modulID"
value="{$modulID}">
<table cellpadding="7" cellspacing="7">
<tr>
<td width="140">Nama Modul</td>
<td width="5">:</td>
<td><input type="text" id="modulName" name="modulName"
value="{$modulName}" class="form-control" placeholder="Nama Modul"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status" id="status" class="form-control"
required>
<option value="">- Pilih Status -</option>
<option value="Y" {if $status == 'Y'} SELECTED {/if}>Y
(Aktif)</option>
<option value="N" {if $status == 'N'} SELECTED {/if}>N
(Tidak Aktif)</option>
</select></td>
</tr>
<tr valign="top">
<td>Level</td>
<td>:</td>
<td> <input type="checkbox" id="authorize1" name="authorize1"
{if $adm == '1'} CHECKED {/if}> Administrator <br>
<input type="checkbox" id="authorize2" name="authorize2"
{if $sls == '2'} CHECKED {/if}> Sales <br>
<input type="checkbox" id="authorize3" name="authorize3"
{if $ksr == '3'} CHECKED {/if}> Kasir <br>
<input type="checkbox" id="authorize4" name="authorize4"
{if $spv == '4'} CHECKED {/if}> Spv <br>
<input type="checkbox" id="authorize5" name="authorize5"
{if $top == '5'} CHECKED {/if}> Top <br>
</td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>

{/if}
</body>

save_edit_authorize.php

128
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$modulID = $_POST['modulID'];
$status = $_POST['status'];
$authorize1 = $_POST['authorize1'];
$authorize2 = $_POST['authorize2'];
$authorize3 = $_POST['authorize3'];
$authorize4 = $_POST['authorize4'];
$authorize5 = $_POST['authorize5'];

if ($modulID != '' && $status != ''){

$authorize = $authorize1.$authorize2.$authorize3.
$authorize4.$authorize5;

$queryModul = "UPDATE as_modules SET authorize = '$authorize',


status = '$status',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE modulID = '$modulID'";

$sqlModul = mysqli_query($connect, $queryModul);

if ($sqlModul)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil seluruh skrip diatas akan menghasilkan halaman master level authorize
dimana hasilnya bisa dilihat melalui gambar-gambar berikut :

129
Gambar 5.20. Menampilkan data level otorisasi

Gambar 5.21. Mengubah data level otorisasi

130
5.2 Transaksi Pembelian
Transaksi pembelian didalamnya mengandung proses purchase order,
penerimaan barang, transaksi pembelian (pembuatan faktur) dan pembayaran
transaksi. Digunakan apabila kita ingin memesan barang kepada supplier. Disini
kita membahas bagaimana membuat proses tersebut.

5.2.1 Purchase Order


Sepertiyang sudah dijelaskan, purchase order ada surat tembusan kepada
supplier mengenai barang yang ingin kita pesan.
Buat beberapa file dengan masing-masing skrip berikut :
spb.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "spb.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'14'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is spb and action is delete


if ($module == 'spb' && $act == 'delete')
{
// insert method into a variable
$spbID = $_GET['spbID'];
$spbFaktur = $_GET['spbFaktur'];

131
$spbNo = $_GET['spbNo'];

// delete spb
$querySpb = "DELETE FROM as_spb WHERE spbID = '$spbID' AND
spbFaktur = '$spbFaktur'";
$sqlSpb = mysqli_query($connect, $querySpb);

// delete spb detail


$querySpbDetail = "DELETE FROM as_detail_spb WHERE spbNo =
'$spbNo' AND spbFaktur = '$spbFaktur'";
$sqlSpbDetail = mysqli_query($connect, $querySpbDetail);

// redirect to the spb page


header("Location: spb.php");
} // close bracket

// if module is spb and act is detailspb


elseif ($module == 'spb' && $act == 'finish')
{
$spbNo = $_GET['spbNo'];
$spbFaktur = $_GET['spbFaktur'];

// showing up the main spb


$querySpb = "SELECT * FROM as_spb WHERE spbNo = '$spbNo'
AND spbFaktur = '$spbFaktur'";
$sqlSpb = mysqli_query($connect, $querySpb);
$dataSpb = mysqli_fetch_array($sqlSpb);

// assign to the tpl


$smarty->assign("spbID", $dataSpb['spbID']);
$smarty->assign("spbNo", $dataSpb['spbNo']);
$smarty->assign("supplierID", $dataSpb['supplierID']);
$smarty->assign("supplierName", $dataSpb['supplierName']);
$smarty->assign("staffID", $dataSpb['staffID']);
$smarty->assign("staffName", $dataSpb['staffName']);
$smarty->assign("orderDate", tgl_indo2($dataSpb['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSpb['needDate']));
$smarty->assign("status", $dataSpb['status']);
$smarty->assign("note", $dataSpb['note']);
$smarty->assign("spbFaktur", $spbFaktur);

// showing up the detail spb


$queryDetail = "SELECT * FROM as_detail_spb WHERE
spbNo = '$spbNo' AND spbFaktur = '$spbFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

// fetch data
$i = 1;
while ($dtDetail = mysqli_fetch_array($sqlDetail))
{
$subtotal = $dtDetail['qty'] * $dtDetail['price'];
$dataDetail[] = array( 'detailID' => $dtDetail['detailID'],
'productID' => $dtDetail['productID'],
'productName' => $dtDetail['productName'],
'price' => rupiah($dtDetail['price']),
'subtotal' => rupiah($subtotal),
'qty' => $dtDetail['qty'],

132
'note' => $dtDetail['note'],
'no' => $i
);
$grandtotal += $subtotal;
$i++;
}

// assign to the tpl


$smarty->assign("grandtotal", rupiah($grandtotal));
$smarty->assign("dataDetail", $dataDetail);
$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Purchase Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi purchase order.");
$smarty->assign("breadcumbMenuName", "Purchase Order");
$smarty->assign("breadcumbMenuSubName", "Detail Purchase Order");
$smarty->assign("pageNumber", $_GET['page']);
}

// if module is spb and act is detailspb


elseif ($module == 'spb' && $act == 'detailtrf')
{
$spbID = $_GET['spbID'];
$spbFaktur = $_GET['spbFaktur'];

$q = mysqli_real_escape_string($connect, $_GET['q']);

// showing up the main spb


$querySpb = "SELECT * FROM as_spb WHERE spbID =
'$spbID' AND spbFaktur = '$spbFaktur'";
$sqlSpb = mysqli_query($connect, $querySpb);
$dataSpb = mysqli_fetch_array($sqlSpb);

// assign to the tpl


$smarty->assign("spbID", $dataSpb['spbID']);
$smarty->assign("spbNo", $dataSpb['spbNo']);
$smarty->assign("supplierID", $dataSpb['supplierID']);
$smarty->assign("supplierName", $dataSpb['supplierName']);
$smarty->assign("staffID", $dataSpb['staffID']);
$smarty->assign("staffName", $dataSpb['staffName']);
$smarty->assign("orderDate", tgl_indo2($dataSpb['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSpb['needDate']));
$smarty->assign("status", $dataSpb['status']);
$smarty->assign("note", $dataSpb['note']);
$smarty->assign("spbFaktur", $spbFaktur);

// showing up the detail spb


$queryDetail = "SELECT * FROM as_detail_spb WHERE spbNo =
'$dataSpb[spbNo]' AND spbFaktur = '$spbFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

// fetch data
$i = 1;
while ($dtDetail = mysqli_fetch_array($sqlDetail))
{
$subtotal = $dtDetail['qty'] * $dtDetail['price'];
$dataDetail[] = array( 'detailID' => $dtDetail['detailID'],

133
'productID' => $dtDetail['productID'],
'productName' => $dtDetail['productName'],
'price' => rupiah($dtDetail['price']),
'subtotal' => rupiah($subtotal),
'qty' => $dtDetail['qty'],
'note' => $dtDetail['note'],
'no' => $i
);
$grandtotal += $subtotal;
$i++;
}

$smarty->assign("q", $q);

// assign to the tpl


$smarty->assign("grandtotal", rupiah($grandtotal));
$smarty->assign("dataDetail", $dataDetail);
$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Purchase Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi purchase order.");
$smarty->assign("breadcumbMenuName", "Purchase Order");
$smarty->assign("breadcumbMenuSubName", "Detail Purchase Order");
$smarty->assign("pageNumber", $_GET['page']);
}

//if module is spb and act is input


elseif ($module == 'spb' && $act == 'input')
{
$spbFaktur = $_SESSION['spbFaktur'];
$spbNo = $_POST['spbNo'];
$note = mysqli_real_escape_string($connect, $_POST['note']);
$nDate = explode("-", $_POST['needDate']);
$oDate = explode("-", $_POST['orderDate']);
$needDate = $nDate[2]."-".$nDate[1]."-".$nDate[0];
$orderDate = $oDate[2]."-".$oDate[1]."-".$oDate[0];

// update spb
$querySpb = "UPDATE as_spb SET note = '$note' WHERE
spbFaktur = '$spbFaktur' AND spbNo = '$spbNo'";
mysqli_query($connect, $querySpb);

// showing up the temp detail spb


$queryTempSpb = "SELECT * FROM as_temp_detail_spb WHERE spbNo =
'$spbNo' AND spbFaktur = '$spbFaktur'";
$sqlTempSpb = mysqli_query($connect, $queryTempSpb);
// fetch data
while ($dataSpb = mysqli_fetch_array($sqlTempSpb))
{
$querySaveSpb = "INSERT INTO as_detail_spb (
spbNo,
spbFaktur,
productID,
productName,
price,
qty,
note,

134
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$dataSpb[spbNo]',
'$dataSpb[spbFaktur]',
'$dataSpb[productID]',
'$dataSpb[productName]',
'$dataSpb[price]',
'$dataSpb[qty]',
'$dataSpb[note]',
'$dataSpb[createdDate]',
'$dataSpb[createdUserID]',
'',
'')";
$save = mysqli_query($connect, $querySaveSpb);
}

// delete temp detail spb


$queryDelete = "DELETE FROM as_temp_detail_spb WHERE spbNo
= '$spbNo' AND spbFaktur = '$spbFaktur'";
mysqli_query($connect, $queryDelete);

// redirect to the spb page


header("Location: spb.php?module=spb&act=finish&spbNo=".$spbNo.
"&spbFaktur=".$spbFaktur);
}

// if module is spb and act is deletedetail


elseif ($module == 'spb' && $act == 'deletedetail')
{
$detailID = $_GET['detailID'];

// delete data
$querySpb = "DELETE FROM as_temp_detail_spb WHERE
detailID = '$detailID'";
$sqlSpb = mysqli_query($connect, $querySpb);

// redirect to the add transfer page


header("Location: spb.php?module=spb&act=add");
}

// if module is spb and act is cancel


elseif ($module == 'spb' && $act == 'cancel')
{
$spbFaktur = $_SESSION['spbFaktur'];

$queryDetail = "DELETE FROM as_temp_detail_spb WHERE


spbFaktur = '$spbFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

if ($sqlDetail)
{
$querySpb = "DELETE FROM as_spb WHERE spbFaktur = '$spbFaktur'";
$sqlSpb = mysqli_query($connect, $querySpb);
}

135
// redirect to the spb page
header("Location: spb.php");
}

// if module is spb and act is add


elseif ($module == 'spb' && $act == 'add')
{
$staffID = $_SESSION['staffID'];
$createdDate = date('Y-m-d H:i:s');

// get last sort spb number ID


$queryNoSpb = "SELECT spbNo FROM as_detail_spb ORDER BY spbNo DESC
LIMIT 1";
$sqlNoSpb = mysqli_query($connect, $queryNoSpb);
$numsNoSpb = mysqli_num_rows($sqlNoSpb);
$dataNoSpb = mysqli_fetch_array($sqlNoSpb);

$start = substr($dataNoSpb['spbNo'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoSpb == '0')
{
$spbNo = "00000";
}
elseif ($tempNo == 1)
{
$spbNo = "00000";
}
elseif ($tempNo == 2)
{
$spbNo = "0000";
}
elseif ($tempNo == 3)
{
$spbNo = "000";
}
elseif ($tempNo == 4)
{
$spbNo = "00";
}
elseif ($tempNo == 5)
{
$spbNo = "0";
}
elseif ($tempNo == 6)
{
$spbNo = "";
}

$spbCode = "PO".$spbNo.$next;

$smarty->assign("breadcumbTitle", "Purchase Order");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi purchase order.");
$smarty->assign("breadcumbMenuName", "Purchase Order");

136
$smarty->assign("breadcumbMenuSubName", "Tambah Transaksi
Purchase Order");

// save into the transfer table


$date = date('Y-m-d');

// showing up the supplier


$querySupplier = "SELECT * FROM as_suppliers ORDER BY
supplierName ASC";
$sqlSupplier = mysqli_query($connect, $querySupplier);
while ($dtSupplier = mysqli_fetch_array($sqlSupplier))
{
$dataSupplier[] = array('supplierID' => $dtSupplier['supplierID'],
'supplierCode' => $dtSupplier['supplierCode'],
'supplierName' => $dtSupplier['supplierName']);
}

$smarty->assign("dataSupplier", $dataSupplier);

// count spb based on spbFaktur


$showSpb1 = "SELECT * FROM as_spb WHERE spbFaktur =
'$_SESSION[spbFaktur]'";
$sqlSpb1 = mysqli_query($connect, $showSpb1);
$numsSpb = mysqli_num_rows($sqlSpb1);

if ($numsSpb == 0)
{
$orderDate = date('Y-m-d');
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$querySpb = "INSERT INTO as_spb(spbNo,
spbFaktur,
supplierID,
supplierName,
staffID,
staffName,
orderDate,
needDate,
note,
status,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$spbCode',
'$_SESSION[spbFaktur]',
'',
'',
'$_SESSION[staffID]',
'$sName',
'$orderDate',
'$orderDate',
'',
'',
'$createdDate',
'$staffID',
'',
'')";

137
mysqli_query($connect, $querySpb);
}

// count spb based on spbFaktur


$showSpb = "SELECT * FROM as_spb WHERE spbFaktur =
'$_SESSION[spbFaktur]'";
$sqlSpb = mysqli_query($connect, $showSpb);
$dataSpb = mysqli_fetch_array($sqlSpb);
$numsSpb = mysqli_num_rows($sqlSpb);

$smarty->assign("supplierID", $dataSpb['supplierID']);

if ($dataSpb['needDate'] == '0000-00-00')
{
$needDate = tgl_indo2(date('Y-m-d'));
}
else
{
$needDate = tgl_indo2($dataSpb['needDate']);
}

if ($dataSpb['orderDate'] == '0000-00-00')
{
$orderDate = tgl_indo2(date('Y-m-d'));
}
else
{
$orderDate = tgl_indo2($dataSpb['orderDate']);
}

$smarty->assign("spbNo", $spbCode);
$smarty->assign("orderDateIndo", $orderDate);
$smarty->assign("needDateIndo", $needDate);
$smarty->assign("spbFaktur", $_SESSION['spbFaktur']);
$smarty->assign("note", $dataSpb['note']);

// query detil spb


$queryDetilSpb = "SELECT * FROM as_temp_detail_spb WHERE
spbFaktur = '$_SESSION[spbFaktur]' AND spbNo = '$spbCode' ORDER BY
detailID ASC";
$sqlDetilSpb = mysqli_query($connect, $queryDetilSpb);
$numsDetilSpb = mysqli_num_rows($sqlDetilSpb);

// fetch data
$i = 1;
while ($dtDetilSpb = mysqli_fetch_array($sqlDetilSpb))
{
$subtotal = $dtDetilSpb['price'] * $dtDetilSpb['qty'];
$dataDetilSpb[] = array( 'detailID' =>
$dtDetilSpb['detailID'],
'productName' => $dtDetilSpb['productName'],
'price' => rupiah($dtDetilSpb['price']),
'qty' => $dtDetilSpb['qty'],
'note' => $dtDetilSpb['note'],
'subtotal' => rupiah($subtotal),
'no' => $i);
$i++;

138
}

// assign to the tpl


$smarty->assign("dataDetilSpb", $dataDetilSpb);
$smarty->assign("numsDetilSpb", $numsDetilSpb);
} // close bracket

// if the module is spb and act is search


elseif ($module == 'spb' && $act == 'search')
{
$_SESSION['spbFaktur'] = date('Ymdhis');
$smarty->assign("spbFaktur", $_SESSION['spbFaktur']);

$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the spb data


if ($sDate != '' || $eDate != '')
{
$querySpb = "SELECT * FROM as_spb WHERE spbNo LIKE '%$q%' AND
orderDate BETWEEN '$startDate' AND '$endDate' ORDER BY spbID
DESC";
}
else
{
$querySpb = "SELECT * FROM as_spb WHERE spbNo LIKE
'%$q%' ORDER BY spbID DESC";
}

$sqlSpb = mysqli_query($connect, $querySpb);

// fetch data
$i = 1 + $position;
while ($dtSpb = mysqli_fetch_array($sqlSpb))
{
$dataSpb[] = array( 'spbID' => $dtSpb['spbID'],
'spbNo' => $dtSpb['spbNo'],
'spbFaktur' => $dtSpb['spbFaktur'],
'supplierName' => $dtSpb['supplierName'],
'staffName' => $dtSpb['staffName'],
'orderDate' => tgl_indo2($dtSpb['orderDate']),
'needDate' => tgl_indo2($dtSpb['needDate']),
'total' => rupiah($dtSpb['total']),
'status' => $dtSpb['status'],
'no' => $i);
$i++;
}

139
$smarty->assign("dataSpb", $dataSpb);

$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Purchase Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi purchase order.");
$smarty->assign("breadcumbMenuName", "Purchase Order");
$smarty->assign("breadcumbMenuSubName", "Purchase Order");
}

else
{
$_SESSION['spbFaktur'] = date('Ymdhis');
$smarty->assign("spbFaktur", $_SESSION['spbFaktur']);
// create new object pagination
$p = new PaginationSpb;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the spb data


$querySpb = "SELECT * FROM as_spb ORDER BY spbID DESC LIMIT
$position,$limit";
$sqlSpb = mysqli_query($connect, $querySpb);

// fetch data
$i = 1 + $position;
while ($dtSpb = mysqli_fetch_array($sqlSpb))
{
$dataSpb[] = array( 'spbID' => $dtSpb['spbID'],
'spbNo' => $dtSpb['spbNo'],
'spbFaktur' => $dtSpb['spbFaktur'],
'supplierName' => $dtSpb['supplierName'],
'staffName' => $dtSpb['staffName'],
'orderDate' => tgl_indo2($dtSpb['orderDate']),
'needDate' => tgl_indo2($dtSpb['needDate']),
'total' => rupiah($dtSpb['total']),
'status' => $dtSpb['status'],
'no' => $i);
$i++;
}

$smarty->assign("dataSpb", $dataSpb);

// count data
$queryCountSpb = "SELECT * FROM as_spb";
$sqlCountSpb = mysqli_query($connect, $queryCountSpb);
$amountData = mysqli_num_rows($sqlCountSpb);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);

140
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Purchase Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi purchase order.");
$smarty->assign("breadcumbMenuName", "Purchase Order");
$smarty->assign("breadcumbMenuSubName", "Purchase Order");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

spb.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>
<script type='text/javascript' src="design/js/jquery.autocomplete
.js"></script>
<link rel="stylesheet" type="text/css" href="design/css/jquery
.autocomplete.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#orderDate" ).datepicker({
changeMonth: true,
changeYear: true,

141
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#needDate').change(function () {
var spbNo = $("#spbNo").val();
var needDate = $("#needDate").val();

$.ajax({
type: 'POST',
url: 'save_spb_needdate.php',
dataType: 'JSON',
data:{
spbNo: spbNo,
needDate: needDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
});

$('#orderDate').change(function () {
var spbNo = $("#spbNo").val();
var orderDate = $("#orderDate").val();

$.ajax({
type: 'POST',
url: 'save_spb_orderdate.php',
dataType: 'JSON',
data:{
spbNo: spbNo,
orderDate: orderDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
});

$('#note').change(function () {

142
var spbNo = $("#spbNo").val();
var note = $("#note").val();

$.ajax({
type: 'POST',
url: 'save_spb_note.php',
dataType: 'JSON',
data:{
spbNo: spbNo,
note: note
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
});

$( "#needDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c+1'
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#spb").submit(function() { return false; });


$("#spb2").submit(function() { return false; });

$("#productBarcode").autocomplete("product_spb_autocomplete.php",
{
width: 310
}).result(function(event, item, a) {
var myarr = item[0].split(" # ");
document.getElementById('productBarcode').value = myarr[0];
document.getElementById('productName1').value = myarr[1];
document.getElementById('productName').value = myarr[1];
document.getElementById('productID').value = myarr[2];
document.getElementById('price').value = myarr[3];
});

$("#supplierID").change(function(e){
var supplierID = $("#supplierID").val();

$.ajax({
type: 'POST',
url: 'save_spb_supplier.php',
dataType: 'JSON',
data:{
supplierID: supplierID
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}

143
});
});

$("#send2").on("click", function(){
var spbNo = $("#spbNo").val();
var productID = $("#productID").val();
var productName1 = $("#productName1").val();
var qty = parseInt($("#qty").val());
var price = parseInt($("#price").val());
var desc = $("#desc").val();

if (qty != '' && spbNo != '' && productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_spb.php',
dataType: 'JSON',
data:{
qty: qty,
price: price,
spbNo: spbNo,
productID: productID,
productName1: productName1,
desc: desc
},
beforeSend: function (data) {
$('#send2').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}
{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

144
{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

{if $module == 'spb' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Tambah Purchase Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="spb.php?module=spb&act=cancel" onclick="return
confirm('Anda Yakin ingin membatalkan PO ini?');"><button
class="btn btn-default pull-right">Batal Trx</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<form method="POST" action="spb.php?module=spb&act=input">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">NO PO / TGL</td>
<td width="5">:</td>
<td><input type="hidden" id="spbNo" name="spbNo" value="{$spbNo}">
<input type="text" id="spbNo" name="spbNo" value="{$spbNo}"
class="form-control" placeholder="NO PO" style="width: 110px;
float: left" DISABLED>
<input type="text" id="orderDate" name="orderDate"
value="{$orderDateIndo}" class="form-control" placeholder="Tanggal
PO" style="width: 160px;" required>
</td>
</tr>
<tr>

145
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="needDate" name="needDate"
value="{$needDateIndo}" class="form-control" placeholder="Tanggal
Dibutuhkan" style="width: 270px;" required></td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td>
<select id="supplierID" name="supplierID" class="form-control"
style="width: 270px;" required>
<option value=""></option>
{section name=dataSupplier loop=$dataSupplier}
{if $dataSupplier[dataSupplier].supplierID == $supplierID}
<option value="{$dataSupplier[dataSupplier].supplierID}"
SELECTED>{$dataSupplier[dataSupplier].supplierName}
[{$dataSupplier[dataSupplier].supplierCode}]</option>
{else}
<option value="{$dataSupplier[dataSupplier].supplierID}">
{$dataSupplier[dataSupplier].supplierName}
[{$dataSupplier[dataSupplier].supplierCode}]</option>
{/if}
{/section}
</select>
</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td><input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width:
270px;"></td>
</tr>
<tr>
<td colspan="3">
<br>
{if $numsDetilSpb < 10}
<a href="#inline" class="modalbox"><button class="btn btn-
default pull-left"><i class="fa fa-plus"></i> Add</button></a>
{/if}
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
<th>AKSI</th>
</tr>

146
</thead>
<tbody>
{section name=dataDetilSpb loop=$dataDetilSpb}
<tr>
<td>{$dataDetilSpb[dataDetilSpb].no}</td>
<td>{$dataDetilSpb[dataDetilSpb].productName}</td>
<td style='text-align: right;'>{$dataDetilSpb[dataDetil
Spb].price}</td>
<td style='text-align: center;'>{$dataDetilSpb[dataDetil
Spb].qty}</td>
<td style='text-align: right;'>{$dataDetilSpb[dataDetil
Spb].subtotal}</td>
<td>{$dataDetilSpb[dataDetilSpb].note}</td>
<td>
<a title="Edit" href="edit_spb.php?module=spb&act=edit&detailID=
{$dataDetilSpb[dataDetilSpb].detailID}" data-width="450" data-
height="180" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="spb.php?module=spb&act=deletedetail&
detailID={$dataDetilSpb[dataDetilSpb].detailID}" onclick="return
confirm('Anda Yakin ingin menghapus item produk
{$dataDetilSpb[dataDetilSpb].productName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
<br>
<br>
{if $numsDetilSpb > 0}
<button type="submit" class="btn btn-
primary">Simpan</button>
{else}
<button type="button" class="btn btn-
primary">Simpan</button>
{/if}
</form>

</div><!-- /.box-body -->


<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Item</h3></td>
</tr>
<tr>
<td>
<form id="spb" name="spb" method="POST" action="#">
<input type="hidden" id="spbNo" name="spbNo" value="{$spbNo}">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">Kode Produk</td>
<td width="5">:</td>
<td><input type="text" id="productBarcode"
name="productBarcode" class="form-control" placeholder="Kode atau
Nama Produk" style="width: 270px;" required></td>

147
</tr>
<tr>
<td colspan="2"></td>
<td><input type="hidden" id="productID" name="productID">
<input type="hidden" id="productName1" name="productName1">
<input type="text" id="productName" name="productName"
class="form-control" placeholder="Nama Produk" style="width:
270px;" DISABLED>
</td>
</tr>
<tr>
<td>Harga Satuan</td>
<td>:</td>
<td><input type="number" id="price" name="price" class="form-
control" placeholder="Harga Satuan" style="width: 270px;"
required></td>
</tr>
<tr>
<td>Qty</td>
<td>:</td>
<td><input type="number" id="qty" name="qty" class="form-control"
placeholder="Qty Produk" style="width: 270px;" required></td>
</tr>
<tr>
<td>Note</td>
<td>:</td>
<td><input type="text" id="desc" name="desc" class="form-
control" placeholder="Note" style="width: 270px;"></td>
</tr>
</table>
<button id="send2" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>

{elseif $module == 'spb' AND $act == 'detailtrf'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Detail Purchase Order</h3>
<div class="box-tools pull-right">

<div class="box-footer clearfix no-border">


<a href="print_unit_spb.php?module=spb&act=print&spbID={$spbID}
&spbFaktur={$spbFaktur}" target="_blank"><button class="btn btn-
default pull-right">Print</button></a>
{if $q != ''}
<a href="spb.php?module=spb&act=search&q={$q}&page={$pageNumber}">
<button class="btn btn-default pull-right">Back</button></a>
{else}
<a href="spb.php?page={$pageNumber}"><button class="btn btn-
default pull-right">Back</button></a>
{/if}
</div>
</div>
</div><!-- /.box-header -->

148
<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">ID TRX / TGL</td>
<td width="5">:</td>
<td>{$spbNo} / {$orderDate}</td>
</tr>
<tr>
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td>{$needDate}</td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td>{$supplierName}</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td>{$note}</td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
</table>
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
</tr>
</thead>
<tbody>
{section name=dataDetail loop=$dataDetail}
<tr>
<td>{$dataDetail[dataDetail].no}</td>
<td>{$dataDetail[dataDetail].productName}</td>
<td style="text-align: right;">{$dataDetail[dataDetail]
.price}</td>
<td style="text-align: center;">{$dataDetail[dataDetail]
.qty}</td>
<td style="text-align: right;">{$dataDetail[dataDetail].
subtotal}</td>
<td>{$dataDetail[dataDetail].note}</td>
</tr>
{/section}
<tr>
<td colspan="4"></td>
<td style="text-align: right;">{$grandtotal}</td>
<td></td>
</tr>

149
</tbody>
</table>
</div>
</div><!-- /.box-body -->

{elseif $module == 'spb' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Detail Purchase Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_spb.php?module=spb&act=print&spbID={$spbID}&
spbFaktur={$spbFaktur}" target="_blank"><button class="btn btn-
default pull-right">Print</button></a>
<a href="spb.php"><button class="btn btn-default pull-
right">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">ID TRX / TGL</td>
<td width="5">:</td>
<td>{$spbNo} / {$orderDate}</td>
</tr>
<tr>
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td>{$needDate}</td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td>{$supplierName}</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td>{$note}</td>
</tr>

150
<tr>
<td colspan="3"><br></td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
</tr>
</thead>
<tbody>
{section name=dataDetail loop=$dataDetail}
<tr>
<td>{$dataDetail[dataDetail].no}</td>
<td>{$dataDetail[dataDetail].productName}</td>
<td style="text-align: right;">{$dataDetail[dataDetail].
price}</td>
<td style="text-align: center;">{$dataDetail[dataDetail].
qty}</td>
<td style="text-align: right;">{$dataDetail[dataDetail].
subtotal}</td>
<td>{$dataDetail[dataDetail].note}</td>
</tr>
{/section}
<tr>
<td colspan="4"></td>
<td style="text-align: right;">{$grandtotal}</td>
<td></td>
</tr>
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{elseif $module == 'spb' && $act == 'search'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="spb.php">
<input type="hidden" name="module" value="spb">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-right"><i
class="fa fa-search"></i> Search</button>
<input type="text" id="endDate" name="endDate" value="{$endDate}"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">

151
<input type="text" id="startDate" name="startDate"
value="{$startDate}" class="form-control" placeholder="Periode
Awal" style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor PO" style="float: right;
width: 270px;" required>
<a href="spb.php?module=spb&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_spb.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO PO <i class="fa fa-sort"></i></th>
<th>TGL PO <i class="fa fa-sort"></i></th>
<th>TGL DIBUTUHKAN <i class="fa fa-sort"></i></th>
<th>SUPPLIER <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSpb loop=$dataSpb}
<tr>
<td>{$dataSpb[dataSpb].no}</td>
<td>{$dataSpb[dataSpb].spbNo}</td>
<td>{$dataSpb[dataSpb].orderDate}</td>
<td>{$dataSpb[dataSpb].needDate}</td>
<td>{$dataSpb[dataSpb].supplierName}</td>
<td>{$dataSpb[dataSpb].status}</td>
<td>{$dataSpb[dataSpb].staffName}</td>
<td>
<a title="Detail" href="spb.php?module=spb&act=detailtrf&spbID={
$dataSpb[dataSpb].spbID}&spbFaktur={$dataSpb[dataSpb].spbFaktur}&q
={$q}&page={$page}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="spb.php?module=spb&act=delete&spbID={
$dataSpb[dataSpb].spbID}&spbFaktur={$dataSpb[dataSpb].spbFaktur}&s
pbNo={$dataSpb[dataSpb].spbNo}" onclick="return confirm('Anda
Yakin ingin menghapus transaksi {$dataSpb[dataSpb].spbNo}?');">
<img src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>

152
</div>
</div><!-- /.box-body -->

{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="spb.php">
<input type="hidden" name="module" value="spb">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" id="endDate" name="endDate" value="{$endDate}"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" id="startDate" name="startDate"
value="{$startDate}" class="form-control" placeholder="Periode
Awal" style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor PO" style="float: right;
width: 270px;">
<a href="spb.php?module=spb&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_spb.php?act=print&q={$q}" style="float: left;"
target="_blank"><button type="button" class="btn btn-default pull-
right"><i class="fa fa-print"></i> Print PDF</button></a>
&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->
<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO PO <i class="fa fa-sort"></i></th>
<th>TGL PO <i class="fa fa-sort"></i></th>
<th>TGL DIBUTUHKAN <i class="fa fa-sort"></i></th>
<th>SUPPLIER <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSpb loop=$dataSpb}
<tr>
<td>{$dataSpb[dataSpb].no}</td>
<td>{$dataSpb[dataSpb].spbNo}</td>
<td>{$dataSpb[dataSpb].orderDate}</td>
<td>{$dataSpb[dataSpb].needDate}</td>
<td>{$dataSpb[dataSpb].supplierName}</td>
<td>{$dataSpb[dataSpb].status}</td>

153
<td>{$dataSpb[dataSpb].staffName}</td>
<td>
<a title="Detail" href="spb.php?module=spb&act=detailtrf&spbID={
$dataSpb[dataSpb].spbID}&spbFaktur={$dataSpb[dataSpb].spbFaktur}&p
age={$page}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="spb.php?module=spb&act=delete&spbID={
$dataSpb[dataSpb].spbID}&spbFaktur={$dataSpb[dataSpb].spbFaktur}&s
pbNo={$dataSpb[dataSpb].spbNo}" onclick="return confirm('Anda
Yakin ingin menghapus transaksi {$dataSpb[dataSpb].spbNo}?');">
<img src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->


</section><!-- /.Left col -->
</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

save_spb.php
<?php
// include header
include "header.php";

$createdDate = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];

$productID = $_POST['productID'];
$spbNo = $_POST['spbNo'];
$productName = mysqli_real_escape_string($connect,
$_POST['productName1']);
$qty = $_POST['qty'];
$price = $_POST['price'];
$note = mysqli_real_escape_string($connect, $_POST['desc']);
$spbFaktur = $_SESSION['spbFaktur'];

154
if ($productID != '' && $spbNo != '' && $qty != ''){

$querySpb = "INSERT INTO as_temp_detail_spb ( spbNo,


spbFaktur,
productID,
productName,
price,
qty,
note,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$spbNo',
'$spbFaktur',
'$productID',
'$productName',
'$price',
'$qty',
'$note',
'$createdDate',
'$staffID',
'',
'')";
$sqlSpb = mysqli_query($connect, $querySpb);

if ($sqlSpb)
{
echo json_encode(OK);
}
}
exit();
?>

edit_spb.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "edit_spb.tpl";

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
// get variable
$module = $_GET['module'];
$act = $_GET['act'];

155
if ($module == 'spb' && $act == 'edit')
{
// insert method into a variable
$detailID = $_GET['detailID'];

// showing up the spb data based on spb id


$querySpb = "SELECT * FROM as_temp_detail_spb WHERE detailID =
'$detailID'";
$sqlSpb = mysqli_query($connect, $querySpb);

// fetch data
$dataSpb = mysqli_fetch_array($sqlSpb);

// count spb based on spbFaktur


$showSpb = "SELECT * FROM as_spb WHERE spbFaktur =
'$_SESSION[spbFaktur]'";
$sqlSpb = mysqli_query($connect, $showSpb);
$dtSpb = mysqli_fetch_array($sqlSpb);
$numsTransfer = mysqli_num_rows($sqlTransfer);

// assign fetch data to the tpl


$smarty->assign("detailID", $dataSpb['detailID']);
$smarty->assign("spbNo", $dataSpb['spbNo']);
$smarty->assign("spbFaktur", $dataSpb['spbFaktur']);
$smarty->assign("productID", $dataSpb['productID']);
$smarty->assign("productName", $dataSpb['productName']);
$smarty->assign("qty", $dataSpb['qty']);
$smarty->assign("price", $dataSpb['price']);
$smarty->assign("note", $dataSpb['note']);
} //close bracket

// assign code to the tpl


$smarty->assign("code", $_GET['code']);
$smarty->assign("module", $_GET['module']);
$smarty->assign("act", $_GET['act']);

} // close bracket

// include footer
include "footer.php";
?>

edit_spb.tpl (simpan didalam folder templates)


<script src="design/js/jquery-1.8.1.min.js" type="text/
javascript"></script>
<link href="design/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="design/css/AdminLTE.css" rel="stylesheet"
type="text/css" />
<script src="design/js/bootstrap.min.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">

156
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>

<body style='background-color: #FFF; color: #000;'>


{literal}
<script>
$(document).ready(function() {

$("#spb").submit(function() { return false; });


$("#send").on("click", function(){
var detailID = $("#detailID").val();
var price = parseInt($("#price").val());
var qty = parseInt($("#qty").val());
var desc = $("#desc").val();

if (detailID != '' && qty != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_edit_spb.php',
dataType: 'JSON',
data:{
detailID: detailID,
qty: qty,
price: price,
desc: desc
},
beforeSend: function (data) {
$('#send').hide();
},
success: function(data) {
parent.jQuery.fancybox.close();
}
});
}
});
});
</script>
{/literal}

{if $module == 'spb' AND $act == 'edit'}


<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Ubah Item</h3></td>
</tr>
<tr>
<td>
<form id="spb" name="spb" method="POST" action="#">
<input type="hidden" id="detailID" name="detailID"
value="{$detailID}">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="140">Kode Produk</td>
<td width="5">:</td>

157
<td><input type="text" id="productBarcode"
value="{$productID}" name="productBarcode" class="form-control"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td colspan="2"></td>
<td><input type="text" value="{$productName}"
id="productName" name="productName" class="form-control"
placeholder="Nama Produk" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>Harga Satuan</td>
<td>:</td>
<td><input type="number" value="{$price}"
id="price" name="price" class="form-control" placeholder="Harga
Satuan" style="width: 270px;" required></td>
</tr>
<tr>
<td>Qty</td>
<td>:</td>
<td><input type="number" value="{$qty}" id="qty"
name="qty" class="form-control" placeholder="Qty Produk"
style="width: 270px;" required></td>
</tr>
<tr>
<td>Note</td>
<td>:</td>
<td><input type="text" value="{$note}" id="desc" name="desc"
class="form-control" placeholder="Note" style="width:
270px;"></td>
</tr>
</table>
<button id="send" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
{/if}
</body>

save_edit_spb.php
<?php
// include header
include "header.php";

$modified_date = date('Y-m-d H:i:s');


$staffID = $_SESSION['staffID'];
$detailID = $_POST['detailID'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$note = mysqli_real_escape_string($connect, $_POST['desc']);

if ($detailID != '' && $qty != ''){

$querySpb = "UPDATE as_temp_detail_spb SET price =

158
'$price',
qty = '$qty',
note = '$note',
modifiedDate = '$modified_date',
modifiedUserID = '$staffID'
WHERE detailID = '$detailID'";

$sqlSpb = mysqli_query($connect, $querySpb);

if ($sqlSpb)
{
echo json_encode(OK);
}
}
exit();
?>

Hasil skrip diatas akan menghasilkan proses purchase order yang bisa dilihat
pada gambar-gambar berikut :

Gambar 5.22. Data purchase order

159
Gambar 5.23. Menambah barang purchase order

5.2.2 Bukti Barang Masuk


Setelah barang kita pesan kepada supplier, supplier kemudian akan
mengirimkan barangnya kepada kita, setelah itu kita akan lakukan form
penerimaan barang, nah, halaman ini difungsikan untuk mencocokkan data yang
kita pesan dan data yang kita terima. Kita akan bahas file apa saja yang
dibutuhkan untuk membuat transaksi penerimaan barang.
Buat beberapa file dengan masing-masing skrip berikut :
bbm.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "bbm.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')

160
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'13'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is bbm and action is delete


if ($module == 'bbm' && $act == 'delete')
{
// insert method into a variable
$bbmID = $_GET['bbmID'];
$bbmNo = $_GET['bbmNo'];
$bbmFaktur = $_GET['bbmFaktur'];

$queryBD = "SELECT * FROM as_detail_bbm WHERE bbmNo =


'$bbmNo' AND bbmFaktur = '$bbmFaktur'";
$sqlBD = mysqli_query($connect, $queryBD);

// fetch data
while ($dataBD = mysqli_fetch_array($sqlBD))
{
$querySP = "UPDATE as_stock_products SET stock=stock-
$dataBD[receiveQty] WHERE productID = '$dataBD[productID]' AND
factoryID = '$dataBD[factoryID]'";
mysqli_query($connect, $querySP);
}

// delete bbm
$queryBbm = "DELETE FROM as_bbm WHERE bbmID = '$bbmID' AND
bbmNo = '$bbmNo' AND bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $queryBbm);

// delete bbm detail


$queryBbmDetail = "DELETE FROM as_detail_bbm WHERE bbmNo =
'$bbmNo' AND bbmFaktur = '$bbmFaktur'";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

// redirect to the bbm page


header("Location: bbm.php");
} // close bracket

// if the module is bbm and act is input


elseif ($module == 'bbm' && $act == 'input')
{

161
$bbmFaktur = $_SESSION['bbmFaktur'];
$modifiedDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$bbmNo = $_POST['bbmNo'];
$bbmID = $_POST['bbmID'];
$spbNo = $_POST['spbNo'];
$supplierID = $_POST['supplierID'];
$supplierName = $_POST['supplierName'];
$supplierAddress = mysqli_real_escape_string($connect,
$_POST['supplierAddress']);
$rDate = explode("-", $_POST['receiveDate']);
$receiveDate = $rDate[2]."-".$rDate[1]."-".$rDate[0];
$oDate = explode("-", $_POST['orderDate']);
$orderDate = $oDate[2]."-".$oDate[1]."-".$oDate[0];
$nDate = explode("-", $_POST['needDate']);
$needDate = $nDate[2]."-".$nDate[1]."-".$nDate[0];
$note = mysqli_real_escape_string($connect, $_POST['note']);
$detailID = $_POST['detailID'];
$countDetailID = COUNT($detailID);
$productID = $_POST['productID'];
$productName = $_POST['productName'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$receiveQty = $_POST['receiveQty'];
$status = $_POST['status'];
$factory = $_POST['factory'];
$notedetail = $_POST['notedetail'];

$dataSpb = mysqli_fetch_array(mysqli_query($connect,
"SELECT spbID FROM as_spb WHERE spbNo = '$spbNo'"));

for ($i = 0; $i < $countDetailID; $i++)


{
$f = explode("#", $factory[$i]);
$factoryID = $f[0];
$factoryName = $f[1]." ".$f[2];
$productNm = mysqli_real_escape_string($connect,
$productName[$i]);
$notedet = mysqli_real_escape_string($connect, $notedetail[$i]);
$total = $price[$i] * $receiveQty[$i];

$queryInsert = "INSERT INTO as_detail_bbm ( bbmNo,


bbmFaktur,
productID,
productName,
price,
qty,
receiveQty,
receiveStatus,
factoryID,
factoryName,
note,
createdDate,
createdUserID)
VALUES( '$bbmNo',
'$bbmFaktur',

162
'$productID[$i]',
'$productNm',
'$price[$i]',
'$qty[$i]',
'$receiveQty[$i]',
'$status[$i]',
'$factoryID',
'$factoryName',
'$notedet',
'$modifiedDate',
'$staffID')";
mysqli_query($connect, $queryInsert);
$queryStock = "UPDATE as_stock_products SET
stock=stock+$receiveQty[$i] WHERE factoryID = '$factoryID' AND
productID = '$productID[$i]'";
mysqli_query($connect, $queryStock);

$grandtotal += $total;
}

// update bbm
$queryBbm = "UPDATE as_bbm SET spbID = '$dataSpb[spbID]',
spbNo = '$spbNo',
supplierID = '$supplierID',
supplierName = '$supplierName',
supplierAddress = '$supplierAddress',
staffID = '$staffID',
staffName = '$sName',
receiveDate = '$receiveDate',
orderDate = '$orderDate',
needDate = '$needDate',
total = '$grandtotal',
note = '$note',
modifiedDate = '$modifiedDate',
modifiedUserID = '$staffID'
WHERE bbmID = '$bbmID' AND bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $queryBbm);
$_SESSION['bbmFaktur'] = "";

header("Location: bbm.php?module=bbm&act=finish&bbmNo=".
$bbmNo."&bbmFaktur=".$bbmFaktur);
}

// if the module is bbm and act is detailbbm


elseif ($module == 'bbm' && $act == 'detailbbm')
{
$bbmID = $_GET['bbmID'];
$bbmFaktur = $_GET['bbmFaktur'];
$bbmNo = $_GET['bbmNo'];
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryBbm = "SELECT * FROM as_bbm WHERE bbmID = '$bbmID'


AND bbmNo = '$bbmNo' AND bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $queryBbm);
$dataBbm = mysqli_fetch_array($sqlBbm);

// assign to the tpl

163
$smarty->assign("bbmFaktur", $dataBbm['bbmFaktur']);
$smarty->assign("bbmID", $dataBbm['bbmID']);
$smarty->assign("bbmNo", $dataBbm['bbmNo']);
$smarty->assign("spbID", $dataBbm['spbID']);
$smarty->assign("spbNo", $dataBbm['spbNo']);
$smarty->assign("supplierID", $dataBbm['supplierID']);
$smarty->assign("supplierName", $dataBbm['supplierName']);
$smarty->assign("supplierAddress", $dataBbm['supplierAddress']);
$smarty->assign("staffID", $dataBbm['staffID']);
$smarty->assign("staffName", $dataBbm['staffName']);
$smarty->assign("receiveDate",
tgl_indo2($dataBbm['receiveDate']));
$smarty->assign("orderDate", tgl_indo2($dataBbm['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataBbm['needDate']));
$smarty->assign("note", $dataBbm['note']);

// show the bbm detail


$queryBbmDetail = "SELECT * FROM as_detail_bbm WHERE bbmNo
= '$bbmNo' AND bbmFaktur = '$bbmFaktur' ORDER BY detailID ASC";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

$i = 1;
while ($dtBbmDetail = mysqli_fetch_array($sqlBbmDetail))
{
$dataBbmDetail[] = array( 'detailID' =>
$dtBbmDetail['detailID'],
'bbmNo' => $dtBbmDetail['bbmNo'],
'bbmFaktur' => $dtBbmDetail['bbmFaktur'],
'productID' => $dtBbmDetail['productID'],
'productName' => $dtBbmDetail['productName'],
'price' => $dtBbmDetail['price'],
'qty' => $dtBbmDetail['qty'],
'receiveQty' => $dtBbmDetail['receiveQty'],
'status' => $dtBbmDetail['receiveStatus'],
'factoryID' => $dtBbmDetail['factoryID'],
'factoryName' => $dtBbmDetail['factoryName'],
'note' => $dtBbmDetail['note'],
'no' => $i
);
$i++;
}

$smarty->assign("dataBbmDetail", $dataBbmDetail);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $_GET['q']);

$smarty->assign("breadcumbTitle", "Bukti Barang Masuk");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi penerimaan barang / bukti barang masuk.");
$smarty->assign("breadcumbMenuName", "Bukti Barang Masuk");
$smarty->assign("breadcumbMenuSubName", "Bukti Barang Masuk");
}

// if the module bbm and act is cancel


elseif ($module == 'bbm' && $act == 'cancel')
{
$bbmFaktur = $_SESSION['bbmFaktur'];

164
// delete bbm
$queryBbm = "DELETE FROM as_bbm WHERE bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $queryBbm);

$_SESSION['bbmFaktur'] = "";

header("Location: bbm.php");
}

// if module bbm and act is finish


elseif ($module == 'bbm' && $act == 'finish')
{
$bbmNo = $_GET['bbmNo'];
$bbmFaktur = $_GET['bbmFaktur'];

$queryBbm = "SELECT * FROM as_bbm WHERE bbmNo = '$bbmNo'


AND bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $queryBbm);
$dataBbm = mysqli_fetch_array($sqlBbm);

$smarty->assign("bbmID", $dataBbm['bbmID']);
$smarty->assign("bbmNo", $dataBbm['bbmNo']);
$smarty->assign("bbmFaktur", $dataBbm['bbmFaktur']);
$smarty->assign("spbID", $dataBbm['spbID']);
$smarty->assign("spbNo", $dataBbm['spbNo']);
$smarty->assign("supplierID", $dataBbm['supplierID']);
$smarty->assign("supplierName", $dataBbm['supplierName']);
$smarty->assign("staffID", $dataBbm['staffID']);
$smarty->assign("staffName", $dataBbm['staffName']);
$smarty->assign("receiveDate",
tgl_indo2($dataBbm['receiveDate']));
$smarty->assign("orderDate", tgl_indo2($dataBbm['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataBbm['needDate']));
$smarty->assign("note", $dataBbm['note']);

// show the bbm detail


$queryBbmDetail = "SELECT * FROM as_detail_bbm WHERE bbmNo
= '$bbmNo' AND bbmFaktur = '$bbmFaktur'";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

// fetch data
$k = 1;
while ($dtBbmDetail = mysqli_fetch_array($sqlBbmDetail))
{
if ($dtBbmDetail['receiveStatus'] == 'Y')
{
$status = "Y";
}
else
{
$status = "N";
}

$dataBbmDetail[] = array( 'detailID' =>


$dtBbmDetail['detailID'],
'bbmNo' => $dtBbmDetail['bbmNo'],
'bbmFaktur' => $dtBbmDetail['bbmFaktur'],

165
'productName' => $dtBbmDetail['productName'],
'price' => rupiah($dtBbmDetail['price']),
'qty' => $dtBbmDetail['qty'],
'receiveQty' => $dtBbmDetail['receiveQty'],
'status' => $status,
'factoryName' => $dtBbmDetail['factoryName'],
'note' => $dtBbmDetail['note'],
'no' => $k
);
$k++;
}

$smarty->assign("dataBbmDetail", $dataBbmDetail);
$smarty->assign("breadcumbTitle", "Bukti Barang Masuk");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi penerimaan barang / bukti barang masuk.");
$smarty->assign("breadcumbMenuName", "Bukti Barang Masuk");
$smarty->assign("breadcumbMenuSubName", "Bukti Barang Masuk");
}

// if the module bbm and act is add


elseif ($module == 'bbm' && $act == 'add')
{
$bbmFaktur = $_SESSION['bbmFaktur'];

// get last sort bbm number ID


$queryNoBbm = "SELECT bbmNo FROM as_bbm ORDER BY bbmNo DESC LIMIT
1";
$sqlNoBbm = mysqli_query($connect, $queryNoBbm);
$numsNoBbm = mysqli_num_rows($sqlNoBbm);
$dataNoBbm = mysqli_fetch_array($sqlNoBbm);

$start = substr($dataNoBbm['bbmNo'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoBbm == '0')
{
$bbmNo = "00000";
}
elseif ($tempNo == 1)
{
$bbmNo = "00000";
}
elseif ($tempNo == 2)
{
$bbmNo = "0000";
}
elseif ($tempNo == 3)
{
$bbmNo = "000";
}
elseif ($tempNo == 4)
{
$bbmNo = "00";
}
elseif ($tempNo == 5)

166
{
$bbmNo = "0";
}
elseif ($tempNo == 6)
{
$bbmNo = "";
}

$bbmCode = "BB".$bbmNo.$next;

// count bbm based on bbmNo


$showBbm = "SELECT * FROM as_bbm WHERE bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $showBbm);
$numsBbm = mysqli_num_rows($sqlBbm);

if ($numsBbm == 0)
{
$receiveDate = date('Y-m-d');
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$queryBbm = "INSERT INTO as_bbm(bbmFaktur,
bbmNo,
spbID,
spbNo,
supplierID,
supplierName,
staffID,
staffName,
receiveDate,
orderDate,
needDate,
total,
note,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$bbmFaktur',
'$bbmCode',
'',
'',
'',
'',
'$_SESSION[staffID]',
'$sName',
'$receiveDate',
'',
'',
'',
'',
'$createdDate',
'$staffID',
'',
'')";
mysqli_query($connect, $queryBbm);
}

// count bbm based on bbmNo

167
$showBbm = "SELECT * FROM as_bbm WHERE bbmFaktur = '$bbmFaktur'";
$sqlBbm = mysqli_query($connect, $showBbm);
$dataBbm = mysqli_fetch_array($sqlBbm);

$smarty->assign("bbmNo", $dataBbm['bbmNo']);
$smarty->assign("bbmID", $dataBbm['bbmID']);

if ($dataBbm['receiveDate'] == '0000-00-00')
{
$receiveDate = date('Y-m-d');
}
else
{
$receiveDate = $dataBbm['receiveDate'];
}

$smarty->assign("receiveDate", tgl_indo2($receiveDate));
$smarty->assign("note", $dataBbm['note']);

// show the spb data based on spbNo


$spbNo = mysqli_real_escape_string($connect, $_GET['spbNo']);
$querySpb = "SELECT * FROM as_spb WHERE spbNo = '$spbNo'";
$sqlSpb = mysqli_query($connect, $querySpb);
$dataSpb = mysqli_fetch_array($sqlSpb);
$numsSpb = mysqli_num_rows($sqlSpb);

$smarty->assign("numsSpb", $numsSpb);

// show the bbm data


$queryBbm = "SELECT A.bbmID FROM as_bbm A INNER JOIN
as_detail_bbm B ON B.bbmNo=A.bbmNo WHERE A.spbNo = '$spbNo'";
$sqlBbm = mysqli_query($connect, $queryBbm);
$numsBbm = mysqli_num_rows($sqlBbm);

$smarty->assign("numsBbm", $numsBbm);

// assign to the bbm tpl


$smarty->assign("spbNo", $spbNo);
$smarty->assign("supplierName", $dataSpb['supplierName']);
$smarty->assign("supplierAddress", $dataSpb['supplierAddress']);
$smarty->assign("supplierID", $dataSpb['supplierID']);
$smarty->assign("orderDate", tgl_indo2($dataSpb['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSpb['needDate']));

// show the spb detail based on spbNo


$i = 1;
$querySpbDetail = "SELECT * FROM as_detail_spb WHERE spbNo
= '$spbNo' AND spbFaktur = '$dataSpb[spbFaktur]'";
$sqlSpbDetail = mysqli_query($connect, $querySpbDetail);
while ($dataSpbDetail = mysqli_fetch_array($sqlSpbDetail))
{
$subtotal = $dataSpbDetail['qty'] * $dataSpbDetail['price'];
$dataDetail[] = array( 'detailID' => $dataSpbDetail['detailID'],
'spbNo' => $dataSpbDetail['spbNo'],
'spbFaktur' => $dataSpbDetail['spbFaktur'],
'productID' => $dataSpbDetail['productID'],
'productName' => $dataSpbDetail['productName'],

168
'price' => $dataSpbDetail['price'],
'qty' => $dataSpbDetail['qty'],
'subtotal' => $subtotal,
'note' => $dataSpbDetail['note'],
'no' => $i
);
$i++;
}

// assign to the spb tpl


$smarty->assign("dataDetail", $dataDetail);

// show the factories data


$queryFactory = "SELECT * FROM as_factories WHERE status =
'Y' ORDER BY factoryCode ASC";
$sqlFactory = mysqli_query($connect, $queryFactory);

while ($dtFactory = mysqli_fetch_array($sqlFactory))


{
$dataFactory[] = array('factoryID' => $dtFactory['factoryID'],
'factoryCode' => $dtFactory['factoryCode'],
'factoryName' => $dtFactory['factoryName']);
}

$smarty->assign("dataFactory", $dataFactory);

$smarty->assign("breadcumbTitle", "Bukti Barang Masuk");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi penerimaan barang / bukti barang masuk.");
$smarty->assign("breadcumbMenuName", "Bukti Barang Masuk");
$smarty->assign("breadcumbMenuSubName", "Bukti Barang Masuk");
}

elseif ($module == 'bbm' && $act == 'search')


{
$bbmFaktur = date('Ymdhis');
$_SESSION['bbmFaktur'] = $bbmFaktur;
$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the bbm data


if ($sDate != '' || $eDate != '')
{
$queryBbm = "SELECT * FROM as_bbm WHERE bbmNo LIKE '%$q%' AND
receiveDate BETWEEN '$startDate' AND '$endDate' ORDER BY bbmID
DESC";
}

169
else
{
$queryBbm = "SELECT * FROM as_bbm WHERE bbmNo LIKE
'%$q%' ORDER BY bbmID DESC";
}
$sqlBbm = mysqli_query($connect, $queryBbm);

// fetch data
$i = 1 + $position;
while ($dtBbm = mysqli_fetch_array($sqlBbm))
{
$dataBbm[] = array( 'bbmID' => $dtBbm['bbmID'],
'bbmNo' => $dtBbm['bbmNo'],
'bbmFaktur' => $dtBbm['bbmFaktur'],
'spbID' => $dtBbm['spdID'],
'spbNo' => $dtBbm['spbNo'],
'supplierID' => $dtBbm['supplierID'],
'supplierName' => $dtBbm['supplierName'],
'staffID' => $dtBbm['staffID'],
'staffName' => $dtBbm['staffName'],
'receiveDate' => tgl_indo2($dtBbm['receiveDate']),
'note' => $dtBbm['note'],
'no' => $i);
$i++;
}

$smarty->assign("dataBbm", $dataBbm);

$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Bukti Barang Masuk");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi penerimaan barang / bukti barang masuk.");
$smarty->assign("breadcumbMenuName", "Bukti Barang Masuk");
$smarty->assign("breadcumbMenuSubName", "Bukti Barang Masuk");
}

else
{
$bbmFaktur = date('Ymdhis');
$_SESSION['bbmFaktur'] = $bbmFaktur;

// create new object pagination


$p = new PaginationBbm;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the bbm data


$queryBbm = "SELECT * FROM as_bbm ORDER BY bbmID DESC
LIMIT $position,$limit";
$sqlBbm = mysqli_query($connect, $queryBbm);

// fetch data
$i = 1 + $position;

170
while ($dtBbm = mysqli_fetch_array($sqlBbm))
{
$dataBbm[] = array( 'bbmID' => $dtBbm['bbmID'],
'bbmNo' => $dtBbm['bbmNo'],
'bbmFaktur' => $dtBbm['bbmFaktur'],
'spbID' => $dtBbm['spdID'],
'spbNo' => $dtBbm['spbNo'],
'supplierID' => $dtBbm['supplierID'],
'supplierName' => $dtBbm['supplierName'],
'staffID' => $dtBbm['staffID'],
'staffName' => $dtBbm['staffName'],
'receiveDate' => tgl_indo2($dtBbm['receiveDate']),
'note' => $dtBbm['note'],
'no' => $i);
$i++;
}

$smarty->assign("dataBbm", $dataBbm);

// count data
$queryCountBbm = "SELECT * FROM as_bbm";
$sqlCountBbm = mysqli_query($connect, $queryCountBbm);
$amountData = mysqli_num_rows($sqlCountBbm);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Bukti Barang Masuk");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi penerimaan barang / bukti barang masuk.");
$smarty->assign("breadcumbMenuName", "Bukti Barang Masuk");
$smarty->assign("breadcumbMenuSubName", "Bukti Barang Masuk");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

bbm.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

171
<link rel="stylesheet" type="text/css" media="all"
href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>
<script type='text/javascript' src="design/js/jquery
.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#receiveDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#receiveDate').change(function () {
var bbmNo = $("#bbmNo").val();
var bbmID = $("#bbmID").val();
var spbNo = $("#spbNo").val();
var receiveDate = $("#receiveDate").val();

$.ajax({
type: 'POST',
url: 'save_bbm_receivedate.php',
dataType: 'JSON',
data:{

172
bbmNo: bbmNo,
bbmID: bbmID,
receiveDate: receiveDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "bbm.php?module=bbm&act=add&spbNo=" +
spbNo;
}
});
});

$('#note').change(function () {
var bbmNo = $("#bbmNo").val();
var bbmID = $("#bbmID").val();
var spbNo = $("#spbNo").val();
var note = $("#note").val();

$.ajax({
type: 'POST',
url: 'save_bbm_note.php',
dataType: 'JSON',
data:{
bbmNo: bbmNo,
bbmID: bbmID,
spbNo: spbNo,
note: note
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "bbm.php?module=bbm&act=add&spbNo=" +
spbNo;
}
});
});

$('#spbNo').change(function () {
var spbNo = $("#spbNo").val();

window.location.href = "bbm.php?module=bbm&act=add&spbNo=" +
spbNo;
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#bbm").submit(function() { return false; });


$("#bbm2").submit(function() { return false; });

$("#send2").on("click", function(){
var bbmNo = $("#bbmNo").val();
var productID = $("#productID").val();
var productName1 = $("#productName1").val();
var qty = parseInt($("#qty").val());
var price = parseInt($("#price").val());
var desc = $("#desc").val();

173
if (qty != '' && spbNo != '' && productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_spb.php',
dataType: 'JSON',
data:{
qty: qty,
price: price,
spbNo: spbNo,
productID: productID,
productName1: productName1,
desc: desc
},
beforeSend: function (data) {
$('#send2').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}
{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<aside class="left-side sidebar-offcanvas">
<section class="sidebar">

{include file="user_panel.tpl"}
{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

174
<!-- TO DO List -->
<div class="box box-primary">

{if $module == 'bbm' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-
button";window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Tambah Penerimaan Barang</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="bbm.php?module=bbm&act=cancel" onclick="return
confirm('Anda Yakin ingin membatalkan bukti barang masuk
ini?');"><button class="btn btn-default pull-right">Batal
Trx</button></a>

</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<form method="POST" action="bbm.php?module=bbm&act=input">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">ID / TGL PENERIMAAN</td>
<td width="5">:</td>
<td><input type="hidden" id="bbmNo" name="bbmNo" value="{$bbmNo}">
<input type="hidden" id="bbmID" name="bbmID" value="{$bbmID}">
<input type="text" id="bbmNo" name="bbmNo" value="{$bbmNo}"
class="form-control" placeholder="ID BBM" style="width: 110px;
float: left" DISABLED>
<input type="text" id="receiveDate" name="receiveDate"
value="{$receiveDate}" class="form-control" placeholder="Tanggal
Penerimaan" style="width: 160px;" required>
</td>
</tr>
<tr valign="top">
<td>NO PO</td>
<td>:</td>
<td><input type="text" id="spbNo" name="spbNo"
value="{$spbNo}" class="form-control" placeholder="Nomor PO"
style="width: 270px;" required>
{if $numsSpb == '0' AND $spbNo != ''}

175
<font color="#f56954">Nomor PO tidak ditemukan.</font>
{/if}

{if $numsBbm > 0 AND $spbNo != ''}

<font color="#f56954">Nomor PO sudah digunakan.</font>


{/if}
</td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td>{if $numsBbm == '0' AND $spbNo != ''}
<input type="hidden" id="supplierID" name="supplierID"
value="{$supplierID}">
<input type="hidden" id="supplierName" name="supplierName"
value="{$supplierName}">
<input type="hidden" id="supplierAddress" name="supplierAddress"
value="{$supplierAddress}">
<input type="text" id="supplierName" name="supplierName"
value="{$supplierName}" class="form-control"
placeholder="Supplier" style="width: 270px;" DISABLED>
{else}
<input type="text" id="supplierName" name="supplierName"
class="form-control" placeholder="Supplier" style="width: 270px;"
DISABLED>
{/if}
</td>
</tr>
<tr>
<td>TGL PO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="hidden" id="orderDate" name="orderDate"
value="{$orderDate}"><input type="hidden" id="needDate"
name="needDate" value="{$needDate}">

{if $numsBbm == '0' AND $spbNo != ''}


<input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
{else}
<input type="text" id="orderDate" name="orderDate" class="form-
control" placeholder="Tgl Order" style="float: left; width:
135px;" DISABLED><input type="text" id="orderDate" name="needDate"
class="form-control" placeholder="Tgl Dibutuhkan" style="width:
135px;" DISABLED></td>
{/if}
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td>{if $numsBbm == '0' AND $spbNo != ''}
<input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width: 270px;">

176
{else}
<input type="text" id="note" name="note" class="form-control"
placeholder="Note" style="width: 270px;">
{/if}</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>NOTE</th>
<th>JML ORDER</th>
<th>JML DITERIMA</th>
<th>TERIMA</th>
<th>GUDANG</th>
</tr>
</thead>
<tbody>
{if $numsBbm == '0' AND $spbNo != ''}
{section name=dataDetail loop=$dataDetail}
<tr>
<td>{$dataDetail[dataDetail].no} <input type="hidden"
name="detailID[]" id="detailID" value="{$dataDetail[dataDetail]
.detailID}"></td>
<td>{$dataDetail[dataDetail].productName} <input type="hidden"
name="productName[]" id="productName"
value="{$dataDetail[dataDetail].productName}"> <input
type="hidden" name="productID[]" id="productID"
value="{$dataDetail[dataDetail].productID}"></td>
<td>{$dataDetail[dataDetail].note} <input type="hidden"
name="notedetail[]" id="notedetail" value="{$dataDetail[data
Detail].note}"></td>
<td style='text-align: center;'>{$dataDetail[dataDetail].qty}
<input type="hidden" name="qty[]" id="qty"
value="{$dataDetail[dataDetail].qty}"> <input type="hidden"
name="price[]" id="price" value="{$dataDetail[dataDetail].price}">
</td>
<td><input type="number" value="0" id="receiveQty"
name="receiveQty[]" class="form-control" placeholder="Jml"
style="width: 100px;" required></td>
<td>
<select id="status" name="status[]" class="form-control"
style="width: 100px;" required>
<option value=""></option>
<option value="Y">YA</option>
<option value="N">TIDAK</option>
</select>
</td>
<td>

177
<select id="factory" name="factory[]" class="form-control"
style="width: 180px;" required>
<option value=""></option>
{section name=dataFactory loop=$dataFactory}
<option value="{$dataFactory[dataFactory].factoryID}#{$dataFactory
[dataFactory].factoryCode}#{$dataFactory[dataFactory].factoryName}
">{$dataFactory[dataFactory].factoryCode} {$dataFactory[data
Factory].factoryName}</option>
{/section}
</select>
</td>
</tr>
{/section}
{/if}
</tbody>
</table>
</div>
<br><br>
{if $numsSpb > 0}
{if $numsBbm > 0 AND $spbNo != ''}
{else}
<button type="submit" class="btn btn-primary">Simpan</button>
{/if}
{/if}
</form>

</div><!-- /.box-body -->

{elseif $module == 'bbm' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.locationhash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-back-
button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Bukti Penerimaan Barang</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_bbm.php?module=bbm&act=print&bbmID={$bbmID}
&bbmNo={$bbmNo}&bbmFaktur={$bbmFaktur}" target="_blank"><button
class="btn btn-default pull-right">Print</button></a>
<a href="bbm.php"><button class="btn btn-default pull-
right">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

178
<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">ID / TGL PENERIMAAN</td>
<td width="5">:</td>
<td><input type="text" id="bbmNo" name="bbmNo"
value="{$bbmNo}" class="form-control" placeholder="ID BBM"
style="width: 110px; float: left" DISABLED>
<input type="text" id="receiveDate" name="receiveDate"
value="{$receiveDate}" class="form-control" placeholder="Tanggal
Penerimaan" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO PO</td>
<td>:</td>
<td><input type="text" id="spbNo" name="spbNo"
value="{$spbNo}" class="form-control" placeholder="Nomor PO"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td><input type="text" id="supplierName"
name="supplierName" value="{$supplierName}" class="form-control"
placeholder="Supplier" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>TGL PO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td><input type="text" value="{$note}" id="note"
name="note" class="form-control" placeholder="Note" style="width:
270px;" DISABLED></td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>

179
<th>NOTE</th>
<th>JML ORDER</th>
<th>JML DITERIMA</th>
<th>TERIMA</th>
<th>GUDANG</th>
</tr>
</thead>
<tbody>
{section name=dataBbmDetail loop=$dataBbmDetail}
<tr>
<td>{$dataBbmDetail[dataBbmDetail].no}</td>
<td>{$dataBbmDetail[dataBbmDetail].productName}</td>
<td>{$dataBbmDetail[dataBbmDetail].note}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.qty}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.receiveQty}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.status}</td>
<td>{$dataBbmDetail[dataBbmDetail].factoryName}</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{elseif $module == 'bbm' AND $act == 'detailbbm'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Bukti Penerimaan Barang</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_bbm.php?module=bbm&act=print&bbmID={$bbmID}&
bbmNo={$bbmNo}&bbmFaktur={$bbmFaktur}" target="_blank"><button
class="btn btn-default pull-right">Print</button></a>
{if $q != ''}
<a href="bbm.php?module=bbm&act=search&q={$q}&page={$page}">
<button class="btn btn-default pull-right">Back</button></a>
{else}
<a href="bbm.php?page={$page}"><button class="btn btn-default
pull-right">Back</button></a>
{/if}
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">ID / TGL PENERIMAAN</td>
<td width="5">:</td>
<td><input type="text" id="bbmNo" name="bbmNo"
value="{$bbmNo}" class="form-control" placeholder="ID BBM"
style="width: 110px; float: left" DISABLED>

180
<input type="text" id="receiveDate" name="receiveDate"
value="{$receiveDate}" class="form-control" placeholder="Tanggal
Penerimaan" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO PO</td>
<td>:</td>
<td><input type="text" id="spbNo" name="spbNo"
value="{$spbNo}" class="form-control" placeholder="Nomor PO"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>SUPPLIER</td>
<td>:</td>
<td><input type="text" id="supplierName"
name="supplierName" value="{$supplierName}" class="form-control"
placeholder="Supplier" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>TGL PO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td><input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>NOTE</th>
<th>JML ORDER</th>
<th>JML DITERIMA</th>
<th>TERIMA</th>
<th>GUDANG</th>
</tr>
</thead>
<tbody>

181
{section name=dataBbmDetail loop=$dataBbmDetail}
<tr>
<td>{$dataBbmDetail[dataBbmDetail].no}</td>
<td>{$dataBbmDetail[dataBbmDetail].productName}</td>
<td>{$dataBbmDetail[dataBbmDetail].note}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.qty}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.receiveQty}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.status}</td>
<td>{$dataBbmDetail[dataBbmDetail].factoryName}</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div><!-- /.box-body -->

{elseif $module == 'bbm' AND $act == 'search'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="bbm.php">
<input type="hidden" name="module" value="bbm">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor Bukti Barang Masuk"
style="float: right; width: 270px;" required>
<a href="bbm.php?module=bbm&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_bbm.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO BBM <i class="fa fa-sort"></i></th>

182
<th>NO PO <i class="fa fa-sort"></i></th>
<th>SUPPLIER <i class="fa fa-sort"></i></th>
<th>TGL PENERIMAAN <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataBbm loop=$dataBbm}
<tr>
<td>{$dataBbm[dataBbm].no}</td>
<td>{$dataBbm[dataBbm].bbmNo}</td>
<td>{$dataBbm[dataBbm].spbNo}</td>
<td>{$dataBbm[dataBbm].supplierName}</td>
<td>{$dataBbm[dataBbm].receiveDate}</td>
<td>{$dataBbm[dataBbm].staffName}</td>
<td>
<a title="Detail" href="bbm.php?module=bbm&act=detailbbm&bbmID=
{$dataBbm[dataBbm].bbmID}&bbmNo={$dataBbm[dataBbm].bbmNo}&bbmFaktu
r={$dataBbm[dataBbm].bbmFaktur}&q={$q}&page={$page}"><img
src="img/icons/view.png" width="18"></a>
<a title="Delete" href="bbm.php?module=bbm&act=delete&bbmID=
{$dataBbm[dataBbm].bbmID}&bbmFaktur={$dataBbm[dataBbm].bbmFaktur}&
bbmNo={$dataBbm[dataBbm].bbmNo}" onclick="return confirm('Anda
Yakin ingin membatalkan transaksi {$dataBbm[dataBbm].bbmNo}?');">
<img src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="bbm.php">
<input type="hidden" name="module" value="bbm">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate"
name="endDate" class="form-control" placeholder="Periode Akhir"
style="float: right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}"
class="form-control" placeholder="Pencarian : No Bukti Barang
Masuk" style="float: right; width: 270px;">
<a href="bbm.php?module=bbm&act=add" style="float:
left;"><button type="button" class="btn btn-default pull-right"><i
class="fa fa-plus"></i> Add</button></a>

183
<a href="print_bbm.php?act=print&q={$q}&startDate={$startDate}
&endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO BBM <i class="fa fa-sort"></i></th>
<th>NO PO <i class="fa fa-sort"></i></th>
<th>SUPPLIER <i class="fa fa-sort"></i></th>
<th>TGL PENERIMAAN <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataBbm loop=$dataBbm}
<tr>
<td>{$dataBbm[dataBbm].no}</td>
<td>{$dataBbm[dataBbm].bbmNo}</td>
<td>{$dataBbm[dataBbm].spbNo}</td>
<td>{$dataBbm[dataBbm].supplierName}</td>
<td>{$dataBbm[dataBbm].receiveDate}</td>
<td>{$dataBbm[dataBbm].staffName}</td>
<td>
<a title="Detail" href="bbm.php?module=bbm&act=detailbbm&bbmID=
{$dataBbm[dataBbm].bbmID}&bbmNo={$dataBbm[dataBbm].bbmNo}&bbmFaktu
r={$dataBbm[dataBbm].bbmFaktur}&page={$page}"><img
src="img/icons/view.png" width="18"></a>
<a title="Delete" href="bbm.php?module=bbm&act=delete&bbmID=
{$dataBbm[dataBbm].bbmID}&bbmFaktur={$dataBbm[dataBbm].bbmFaktur}&
bbmNo={$dataBbm[dataBbm].bbmNo}" onclick="return confirm('Anda
Yakin ingin membatalkan transaksi {$dataBbm[dataBbm].bbmNo}?');">
<img src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>

184
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->


</section><!-- /.Left col -->
</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil seluruh skrip diatas akan menghasilkan halaman penerimaan barang yang
bisa dilihat pada gambar-gambar berikut :

Gambar 5.24. Form penerimaan barang

185
Gambar 5.25. Cetak bukti penerimaan barang

5.2.3 Transaksi Pembelian


Setelah kita menerima barang, biasanya akan dibuatkan faktur pembelian,
halaman ini difungsikan untuk membuat transaksi pembelian (faktur).
Buat beberapa file dengan masing-masing skrip berikut :
in.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "in.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'8'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

186
if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is in and action is delete


if ($module == 'in' && $act == 'delete')
{
// insert method into a variable
$inID = $_GET['invoiceID'];
$inNo = $_GET['invoiceNo'];

// delete invoice
$queryInvoice = "DELETE FROM as_buy_transactions WHERE
invoiceID = '$inID' AND invoiceNo = '$inNo'";
$sqlInvoice = mysqli_query($connect, $queryInvoice);

// delete debt
$queryDebt = "DELETE FROM as_debts WHERE invoiceID =
'$inID' AND invoiceNo = '$inNo'";
$sqlDebt = mysqli_query($connect, $queryDebt);

// redirect to the in page


header("Location: in.php");
} // close bracket

// if the module is in and action is cancel


elseif ($module == 'in' && $act == 'cancel')
{
$bbmNo = $_GET['bbmNo'];

$queryBbm = "SELECT productID, detailID, receiveQty FROM


as_detail_bbm WHERE bbmNo = '$bbmNo'";
$sqlBbm = mysqli_query($connect, $queryBbm);

while ($dataBbm = mysqli_fetch_array($sqlBbm))


{
$queryProduct = "SELECT hpp FROM as_products WHERE productID =
'$dataBbm[productID]'";
$sqlProduct = mysqli_query($connect, $queryProduct);
$dataProduct = mysqli_fetch_array($sqlProduct);

$update = "UPDATE as_detail_bbm SET price =


'$dataProduct[hpp]' WHERE detailID = '$dataBbm[detailID]' AND
productID = '$dataBbm[productID]'";
mysqli_query($connect, $update);

$total = $dataProduct['hpp'] * $dataBbm['receiveQty'];


$settotal += $total;
}

$queryUpdate = "UPDATE as_bbm SET total = '$settotal'


WHERE bbmNo = '$bbmNo'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);

187
// redirect to the in page
header("Location: in.php");
}

// if the module is in and act is input


elseif ($module == 'in' && $act == 'input')
{
$createdDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$invoiceNo = mysqli_real_escape_string($connect,
$_POST['invoiceNo']);
$iDate = explode("-", $_POST['invoiceDate']);
$invoiceDate = $iDate[2]."-".$iDate[1]."=".$iDate[0];
$bbmNo = mysqli_real_escape_string($connect, $_POST['bbmNo']);
$spbNo = mysqli_real_escape_string($connect, $_POST['spbNo']);
$supplierID = $_POST['supplierID'];
$supplierName = mysqli_real_escape_string($connect,
$_POST['supplierName']);
$supplierAddress = mysqli_real_escape_string($connect,
$_POST['supplierAddress']);
$paymentType = $_POST['paymentType'];
$xDate = explode("-", $_POST['expiredDate']);
$expiredDate = $xDate[2]."-".$xDate[1]."-".$xDate[0];
$ppnType = $_POST['ppnType'];
$ppn = $_POST['ppn'];
$total = $_POST['total'];
$basic = $_POST['basic'];
$grandtotal = $_POST['grandtotal'];
//$pay = $_POST['pay'];
//$debt = $_POST['debt'];
$discount = $_POST['discount'];

// get last sort debt


$queryNoDebt = "SELECT debtNo FROM as_debts ORDER BY
debtNo DESC LIMIT 1";
$sqlNoDebt = mysqli_query($connect, $queryNoDebt);
$numsNoDebt = mysqli_num_rows($sqlNoDebt);
$dataNoDebt = mysqli_fetch_array($sqlNoDebt);

$start = substr($dataNoDebt['debtNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoDebt == '0')
{
$deNo = "00000";
}
elseif ($tempNo == 1)
{
$deNo = "00000";
}
elseif ($tempNo == 2)
{
$deNo = "0000";
}
elseif ($tempNo == 3)

188
{
$deNo = "000";
}
elseif ($tempNo == 4)
{
$deNo = "00";
}
elseif ($tempNo == 5)
{
$deNo = "0";
}
elseif ($tempNo == 6)
{
$deNo = "";
}

$debtNo = "DB".$deNo.$next;

$queryBuy = "INSERT INTO as_buy_transactions ( invoiceNo,


invoiceDate,
bbmNo,
spbNo,
paymentType,
expiredPayment,
ppnType,
ppn,
total,
basic,
discount,
grandtotal,
supplierID,
supplierName,
supplierAddress,
staffID,
staffName,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$invoiceNo',
'$invoiceDate',
'$bbmNo',
'$spbNo',
'$paymentType',
'$expiredDate',
'$ppnType',
'$ppn',
'$total',
'$basic',
'$discount',
'$grandtotal',
'$supplierID',
'$supplierName',
'$supplierAddress',
'$staffID',
'$sName',
'$createdDate',

189
'$staffID',
'',
'')";

$sqlBuy = mysqli_query($connect, $queryBuy);

$invoiceID = mysqli_insert_id($connect);

if ($sqlBuy)
{

$queryDebt = "INSERT INTO as_debts (debtNo,


invoiceID,
invoiceNo,
supplierID,
supplierName,
supplierAddress,
debtTotal,
incomingTotal,
status,
staffID,
staffName,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)

VALUES( '$debtNo',
'$invoiceID',
'$invoiceNo',
'$supplierID',
'$supplierName',
'$supplierAddress',
'$grandtotal',
'0',
'1',
'$staffID',
'$sName',
'$createdDate',
'$staffID',
'',
'')";

mysqli_query($connect, $queryDebt);

$queryDetailBbm = "SELECT productID, price FROM as_detail_bbm


WHERE bbmNo = '$bbmNo'";
$sqlDetailBbm = mysqli_query($connect, $queryDetailBbm);

while ($dataDetailBbm = mysqli_fetch_array($sqlDetailBbm))


{
$queryProduct = "UPDATE as_products SET purchasePrice =
'$dataDetailBbm[price]', hpp = '$dataDetailBbm[price]' WHERE
productID = '$dataDetailBbm[productID]'";
mysqli_query($connect, $queryProduct);
}

190
}

header("Location:
in.php?module=in&act=finish&bbmNo=".$bbmNo."&invoiceNo=".$invoiceN
o."&invoiceID=".$invoiceID);
}

// if the module is in and act is detailin


elseif ($module == 'in' && $act == 'detailin')
{
$bbmNo = $_GET['bbmNo'];
$q = mysqli_real_escape_string($connect, $_GET['q']);
$invoiceID = $_GET['invoiceID'];
$invoiceNo = $_GET['invoiceNo'];

$queryBuy = "SELECT * FROM as_buy_transactions WHERE bbmNo


= '$bbmNo' AND invoiceID = '$invoiceID' AND invoiceNo =
'$invoiceNo'";
$sqlBuy = mysqli_query($connect, $queryBuy);
$dataBuy = mysqli_fetch_array($sqlBuy);

if ($dataBuy['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment = tgl_indo2($dataBuy['expiredPayment']);
}

if ($dataBuy['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dataBuy['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = rupiah(0);
}

// assign to the tpl


$smarty->assign("invoiceID", $dataBuy['invoiceID']);
$smarty->assign("invoiceNo", $dataBuy['invoiceNo']);
$smarty->assign("invoiceDate",
tgl_indo2($dataBuy['invoiceDate']));
$smarty->assign("bbmNo", $dataBuy['bbmNo']);
$smarty->assign("spbNo", $dataBuy['spbNo']);
$smarty->assign("paymentType", $paymentType);
$smarty->assign("expiredPayment", $expiredPayment);
$smarty->assign("ppnType", $ppnType);
$smarty->assign("ppn", $ppn);
$smarty->assign("discount", rupiah($dataBuy['discount']));
$smarty->assign("basic", rupiah($dataBuy['basic']));
$smarty->assign("total", rupiah($dataBuy['total']));

191
$smarty->assign("grandtotal", rupiah($dataBuy['grandtotal']));
$smarty->assign("pay", rupiah($dataBuy['pay']));
$smarty->assign("supplierID", $dataBuy['supplierID']);
$smarty->assign("supplierName", $dataBuy['supplierName']);
$smarty->assign("supplierAddress", $dataBuy['supplierAddress']);
$smarty->assign("staffID", $dataBuy['staffID']);
$smarty->assign("staffName", $dataBuy['staffName']);

// show debt
$queryDebt = "SELECT debtTotal FROM as_debts WHERE invoiceNo =
'$_GET[invoiceNo]' AND invoiceID = '$_GET[invoiceID]'";
$sqlDebt = mysqli_query($connect, $queryDebt);
$dataDebt = mysqli_fetch_array($sqlDebt);

$smarty->assign("debt", rupiah($dataDebt['debtTotal']));

// show the bbm detail


$queryBbmDetail = "SELECT * FROM as_detail_bbm WHERE bbmNo
= '$dataBuy[bbmNo]' ORDER BY detailID ASC";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

$i = 1;
while ($dtBbmDetail = mysqli_fetch_array($sqlBbmDetail))
{
$subtotal = rupiah($dtBbmDetail['receiveQty'] *
$dtBbmDetail['price']);
$dataBbmDetail[] = array( 'detailID' =>
$dtBbmDetail['detailID'],
'bbmNo' => $dtBbmDetail['bbmNo'],
'bbmFaktur' => $dtBbmDetail['bbmFaktur'],
'productID' => $dtBbmDetail['productID'],
'productName' => $dtBbmDetail['productName'],
'pricerp' => rupiah($dtBbmDetail['price']),
'qty' => $dtBbmDetail['qty'],
'receiveQty' => $dtBbmDetail['receiveQty'],
'subtotal' => $subtotal,
'no' => $i

);
$i++;
}

$smarty->assign("dataBbmDetail", $dataBbmDetail);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("breadcumbTitle", "Transaksi Pembelian");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

// if module in and act is finish


elseif ($module == 'in' && $act == 'finish')
{
$bbmNo = $_GET['bbmNo'];

192
$invoiceID = $_GET['invoiceID'];
$invoiceNo = $_GET['invoiceNo'];

$queryBuy = "SELECT * FROM as_buy_transactions WHERE bbmNo =


'$bbmNo' AND invoiceID = '$invoiceID' AND invoiceNo =
'$invoiceNo'";
$sqlBuy = mysqli_query($connect, $queryBuy);
$dataBuy = mysqli_fetch_array($sqlBuy);

if ($dataBuy['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment = tgl_indo2($dataBuy['expiredPayment']);
}

if ($dataBuy['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dataBuy['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = rupiah(0);
}

// assign to the tpl


$smarty->assign("invoiceID", $dataBuy['invoiceID']);
$smarty->assign("invoiceNo", $dataBuy['invoiceNo']);
$smarty->assign("invoiceDate",
tgl_indo2($dataBuy['invoiceDate']));
$smarty->assign("bbmNo", $dataBuy['bbmNo']);
$smarty->assign("spbNo", $dataBuy['spbNo']);
$smarty->assign("paymentType", $paymentType);
$smarty->assign("expiredPayment", $expiredPayment);
$smarty->assign("ppnType", $ppnType);
$smarty->assign("ppn", $ppn);
$smarty->assign("discount", rupiah($dataBuy['discount']));
$smarty->assign("basic", rupiah($dataBuy['basic']));
$smarty->assign("total", rupiah($dataBuy['total']));
$smarty->assign("grandtotal", rupiah($dataBuy['grandtotal']));
$smarty->assign("pay", rupiah($dataBuy['pay']));
$smarty->assign("supplierID", $dataBuy['supplierID']);
$smarty->assign("supplierName", $dataBuy['supplierName']);
$smarty->assign("supplierAddress", $dataBuy['supplierAddress']);
$smarty->assign("staffID", $dataBuy['staffID']);
$smarty->assign("staffName", $dataBuy['staffName']);

// show debt
$queryDebt = "SELECT debtTotal FROM as_debts WHERE invoiceNo =
'$_GET[invoiceNo]' AND invoiceID = '$_GET[invoiceID]'";
$sqlDebt = mysqli_query($connect, $queryDebt);

193
$dataDebt = mysqli_fetch_array($sqlDebt);

$smarty->assign("debt", rupiah($dataDebt['debtTotal']));

// show the bbm detail


$queryBbmDetail = "SELECT * FROM as_detail_bbm WHERE bbmNo
= '$dataBuy[bbmNo]' ORDER BY detailID ASC";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

$i = 1;
while ($dtBbmDetail = mysqli_fetch_array($sqlBbmDetail))
{
$subtotal = rupiah($dtBbmDetail['receiveQty'] *
$dtBbmDetail['price']);
$dataBbmDetail[] = array( 'detailID' =>
$dtBbmDetail['detailID'],
'bbmNo' => $dtBbmDetail['bbmNo'],
'bbmFaktur' => $dtBbmDetail['bbmFaktur'],
'productID' => $dtBbmDetail['productID'],
'productName' => $dtBbmDetail['productName'],
'pricerp' => rupiah($dtBbmDetail['price']),
'qty' => $dtBbmDetail['qty'],
'receiveQty' => $dtBbmDetail['receiveQty'],
'subtotal' => $subtotal,
'no' => $i
);
$i++;
}

$smarty->assign("dataBbmDetail", $dataBbmDetail);
$smarty->assign("page", $_GET['page']);
$smarty->assign("breadcumbTitle", "Transaksi Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

// if the module in and act is add


elseif ($module == 'in' && $act == 'add')
{
// get last sort in number ID
$queryNoIn = "SELECT invoiceNo FROM as_buy_transactions
ORDER BY invoiceNo DESC LIMIT 1";
$sqlNoIn = mysqli_query($connect, $queryNoIn);
$numsNoIn = mysqli_num_rows($sqlNoIn);
$dataNoIn = mysqli_fetch_array($sqlNoIn);

$start = substr($dataNoIn['invoiceNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoIn == '0')
{
$inNo = "00000";
}
elseif ($tempNo == 1)

194
{
$inNo = "00000";
}
elseif ($tempNo == 2)
{
$inNo = "0000";
}
elseif ($tempNo == 3)
{
$inNo = "000";
}
elseif ($tempNo == 4)
{
$inNo = "00";
}
elseif ($tempNo == 5)
{
$inNo = "0";
}
elseif ($tempNo == 6)
{
$inNo = "";
}

$invoiceNo = $inNo.$next;

$smarty->assign("invoiceNo", $invoiceNo);
$smarty->assign("invoiceDate", tgl_indo2(date('Y-m-d')));

$bbmNo = $_GET['bbmNo'];

// show the bbm


$queryBbm = "SELECT * FROM as_bbm WHERE bbmNo = '$bbmNo'";
$sqlBbm = mysqli_query($connect, $queryBbm);
$dataBbm = mysqli_fetch_array($sqlBbm);
$numsBbm = mysqli_num_rows($sqlBbm);

$smarty->assign("numsBbm", $numsBbm);

// show the bbm data


$queryBBuy = "SELECT invoiceID FROM as_buy_transactions
WHERE bbmNo = '$bbmNo'";
$sqlBBuy = mysqli_query($connect, $queryBBuy);
$numsBBuy = mysqli_num_rows($sqlBBuy);

$smarty->assign("numsBBuy", $numsBBuy);

// assign to the tpl


$smarty->assign("bbmID", $dataBbm['bbmID']);
$smarty->assign("bbmNo", $_GET['bbmNo']);
$smarty->assign("spbID", $dataBbm['spbID']);
$smarty->assign("spbNo", $dataBbm['spbNo']);
$smarty->assign("supplierID", $dataBbm['supplierID']);
$smarty->assign("supplierName", $dataBbm['supplierName']);
$smarty->assign("supplierAddress", $dataBbm['supplierAddress']);
$smarty->assign("staffID", $dataBbm['staffID']);
$smarty->assign("staffName", $dataBbm['staffName']);

195
$smarty->assign("receiveDate",
tgl_indo2($dataBbm['receiveDate']));
$smarty->assign("orderDate", tgl_indo2($dataBbm['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataBbm['needDate']));
$smarty->assign("total", number_format($dataBbm['total'],
2, '.', ''));
$smarty->assign("totalrp", rupiah($dataBbm['total']));
$smarty->assign("note", $dataBbm['note']);

$queryBbmDetail = "SELECT * FROM as_detail_bbm WHERE bbmNo


= '$dataBbm[bbmNo]' AND bbmFaktur = '$dataBbm[bbmFaktur]' ORDER BY
detailID ASC";
$sqlBbmDetail = mysqli_query($connect, $queryBbmDetail);

$i = 1;
while ($dtBbmDetail = mysqli_fetch_array($sqlBbmDetail))
{
$subtotal = $dtBbmDetail['receiveQty'] * $dtBbmDetail['price'];
$dataBbmDetail[] = array( 'detailID' =>
$dtBbmDetail['detailID'],
'bbmNo' => $dtBbmDetail['bbmNo'],
'bbmFaktur' => $dtBbmDetail['bbmFaktur'],
'productID' => $dtBbmDetail['productID'],
'productName' => $dtBbmDetail['productName'],
'price' => $dtBbmDetail['price'],
'pricerp' => rupiah($dtBbmDetail['price']),
'qty' => $dtBbmDetail['qty'],
'receiveQty' => $dtBbmDetail['receiveQty'],
'status' => $dtBbmDetail['receiveStatus'],
'factoryID' => $dtBbmDetail['factoryID'],
'factoryName' => $dtBbmDetail['factoryName'],
'subtotal' => rupiah($subtotal),
'note' => $dtBbmDetail['note'],
'no' => $i
);
$i++;
}

$smarty->assign("dataBbmDetail", $dataBbmDetail);

$smarty->assign("breadcumbTitle", "Transaksi Pembelian");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

elseif ($module == 'in' && $act == 'search')


{
$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);

196
$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the buy data


if ($sDate != '' || $eDate != '')
{
$queryBuy = "SELECT * FROM as_buy_transactions
WHERE invoiceNo LIKE '%$q%' AND invoiceDate BETWEEN '$startDate'
AND '$endDate' ORDER BY invoiceNo DESC";
}
else
{
$queryBuy = "SELECT * FROM as_buy_transactions
WHERE invoiceNo LIKE '%$q%' ORDER BY invoiceNo DESC";
}
$sqlBuy = mysqli_query($connect, $queryBuy);

// fetch data
$i = 1 + $position;
while ($dtBuy = mysqli_fetch_array($sqlBuy))
{
if ($dtBuy['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment = tgl_indo2($dtBuy['expiredPayment']);
}

if ($dtBuy['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dtBuy['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = "";
}

$dataBuy[] = array( 'invoiceID' => $dtBuy['invoiceID'],


'invoiceNo' => $dtBuy['invoiceNo'],
'invoiceDate' => tgl_indo2($dtBuy['invoiceDate']),
'bbmNo' => $dtBuy['bbmNo'],
'spbNo' => $dtBuy['spbNo'],
'paymentType' => $paymentType,
'expiredPayment' => $expiredPayment,
'ppnType' => $ppnType,
'ppn' => $ppn,
'total' => rupiah($dtBuy['total']),
'grandtotal' => rupiah($dtBuy['grandtotal']),
'pay' => rupiah($dtBuy['pay']),

197
'staffID' => $dtBuy['staffID'],
'staffName' => $dtBuy['staffName'],
'no' => $i);
$i++;
}

$smarty->assign("dataBuy", $dataBuy);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Transaksi Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

else
{
// create new object pagination
$p = new PaginationIn;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the buy data


$queryBuy = "SELECT * FROM as_buy_transactions ORDER BY
invoiceID DESC LIMIT $position,$limit";
$sqlBuy = mysqli_query($connect, $queryBuy);

// fetch data
$i = 1 + $position;
while ($dtBuy = mysqli_fetch_array($sqlBuy))
{
if ($dtBuy['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment =
tgl_indo2($dtBuy['expiredPayment']);
}

if ($dtBuy['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dtBuy['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = "";
}

198
$dataBuy[] = array( 'invoiceID' => $dtBuy['invoiceID'],
'invoiceNo' => $dtBuy['invoiceNo'],
'invoiceDate' => tgl_indo2($dtBuy['invoiceDate']),
'bbmNo' => $dtBuy['bbmNo'],
'spbNo' => $dtBuy['spbNo'],
'paymentType' => $paymentType,
'expiredPayment' => $expiredPayment,
'ppnType' => $ppnType,
'ppn' => $ppn,
'total' => rupiah($dtBuy['total']),
'grandtotal' => rupiah($dtBuy['grandtotal']),
'pay' => rupiah($dtBuy['pay']),
'staffID' => $dtBuy['staffID'],
'staffName' => $dtBuy['staffName'],
'no' => $i);
$i++;
}

$smarty->assign("dataBuy", $dataBuy);

// count data
$queryCountBuy = "SELECT * FROM as_buy_transactions";
$sqlCountBuy = mysqli_query($connect, $queryCountBuy);
$amountData = mysqli_num_rows($sqlCountBuy);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Transaksi Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

in.tpl (Simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}

199
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript" src="design/js/fancybox/jquery
.fancybox.js?v=2.0.6"></script>
<script type='text/javascript' src="design/js/jquery
.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}
<script>
function toRp(amount, decimalSeparator, thousandsSeparator,
nDecimalDigits){
var num = parseFloat( amount ); //convert to float
//default values
decimalSeparator = decimalSeparator || ',';
thousandsSeparator = thousandsSeparator || ',';
nDecimalDigits = nDecimalDigits == null? 2 : nDecimalDigits;

var fixed = num.toFixed(nDecimalDigits);


var parts = new RegExp('^(-
?\\d{1,3})((?:\\d{3})+)(\\.(\\d{' + nDecimalDigits +
'}))?$').exec(fixed);

if(parts){ //num >= 1000 || num < = -1000


return parts[1] + parts[2].replace(/\d{3}/g,
thousandsSeparator + '$&') + (parts[4] ? decimalSeparator +
parts[4] : '');
}else{
return fixed.replace('.', decimalSeparator);
}
}

function sum() {
var total = eval($("#total").val());
var ppn = eval($("#ppn").val());
var discount = eval($("#discount").val());
var basic = eval($("#basic").val());
var grandtotal = eval($("#grandtotal").val());
var ppnType = $("#ppnType").val();

// ppn
if (ppnType == '1') {
// dasar pengenaan pajak
var basicproccess = eval(total - discount);
var basicproccessrp = toRp(basicproccess);
var ppnproccess = eval(0.1 * basicproccess);
var ppnproccessrp = toRp(ppnproccess);

// grandtotal
var grandtotalproccess = eval(basicproccess + ppnproccess);
var grandtotalproccessrp = toRp(grandtotalproccess);
document.getElementById('ppn').value = ppnproccess.toFixed(2);
document.getElementById('ppnrp').value = ppnproccessrp;
document.getElementById('basic').value = basicproccess.toFixed(2);

200
document.getElementById('basicrp').value = basicproccessrp;
document.getElementById('grandtotal').value =
grandtotalproccess.toFixed(2);
document.getElementById('grandtotalrp').value =
grandtotalproccessrp;
}
else{
// dasar pengenaan pajak
var basicproccess = eval(total - discount);
var basicproccessrp = toRp(basicproccess);
var ppnproccess = 0;
// grandtotal
var grandtotalproccess = eval(basicproccess + ppnproccess);
var grandtotalproccessrp = toRp(grandtotalproccess);
var ppnproccessrp = toRp(ppnproccess);
document.getElementById('ppn').value = 0;
document.getElementById('ppnrp').value = 0;
document.getElementById('basic').value = basicproccess.toFixed(2);
document.getElementById('basicrp').value = basicproccessrp;
document.getElementById('grandtotal').value =
grandtotalproccess.toFixed(2);
document.getElementById('grandtotalrp').value =
grandtotalproccessrp;
}
}

$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$("#paymentType").change(function(e){
var paymentType = $("#paymentType").val();

$("#searchStatus").empty();

if (paymentType == '2'){

var newinput3 = $('<input type="text"


id="expiredDate" name="expiredDate" class="form-control"
style="width: 170px;" placeholder="Jatuh Tempo" required>');

newinput3.appendTo('#searchStatus').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-0:c+1'
});

201
}
});

$("#ppnType").change(function(e){
var ppnType = $("#ppnType").val();
var discount = eval($("#discount").val());
var total = eval($("#total").val());

document.getElementById("ppn").value = 0;
document.getElementById("ppnrp").value = 0;

if (ppnType == '1'){
var sisatotal = eval(total - discount);
var ppnValue = eval(0.1 * sisatotal);
var grandtotal = eval(sisatotal + ppnValue);
var ppnrp = toRp(ppnValue);
var basicrp = toRp(sisatotal);
var grandtotalrp = toRp(grandtotal);

document.getElementById("ppn").value = ppnValue.toFixed(2);
document.getElementById("ppnrp").value = ppnrp;
document.getElementById("basic").value = sisatotal.toFixed(2);
document.getElementById("basicrp").value = basicrp;
document.getElementById("grandtotalrp").value = grandtotalrp;
document.getElementById("grandtotal").value =
grandtotal.toFixed(2);
}
else {
var sisagrand = eval(total - discount);
var sisagrandrp = toRp(sisagrand);
document.getElementById("ppn").value = 0;
document.getElementById("ppnrp").value = 0;
document.getElementById("basic").value = sisagrand.toFixed(2);
document.getElementById("basicrp").value = sisagrandrp;
document.getElementById("grandtotalrp").value = sisagrandrp;
document.getElementById("grandtotal").value =
sisagrand.toFixed(2);
}
});

$( "#invoiceDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,

202
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#bbmNo').change(function () {
var bbmNo = $("#bbmNo").val();

window.location.href = "in.php?module=in&act=add&bbmNo=" + bbmNo;


});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#bbm").submit(function() { return false; });


$("#bbm2").submit(function() { return false; });

$("#send2").on("click", function(){
var bbmNo = $("#bbmNo").val();
var productID = $("#productID").val();
var productName1 = $("#productName1").val();
var qty = parseInt($("#qty").val());
var price = parseInt($("#price").val());
var desc = $("#desc").val();

if (qty != '' && spbNo != '' && productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_spb.php',
dataType: 'JSON',
data:{
qty: qty,
price: price,
spbNo: spbNo,
productID: productID,
productName1: productName1,
desc: desc
},
beforeSend: function (data) {
$('#send2').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "spb.php?module=spb&act=add";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

203
</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

{if $module == 'in' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Tambah Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="in.php?module=in&act=cancel&bbmNo={$bbmNo}"
onclick="return confirm('Anda Yakin ingin membatalkan transaksi
pembelian ini?');"><button class="btn btn-default pull-
right">Batal Trx</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">

204
<form method="POST" action="in.php?module=in&act=input">
<input type="hidden" id="supplierID" name="supplierID"
value="{$supplierID}">
<input type="hidden" id="supplierName" name="supplierName"
value="{$supplierName}">
<input type="hidden" id="supplierAddress" name="supplierAddress"
value="{$supplierAddress}">
<input type="hidden" id="spbNo" name="spbNo" value="{$spbNo}">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO FAKTUR / TGL</td>
<td width="5">:</td>
<td><input type="hidden" id="invoiceNo" name="invoiceNo"
value="TB{$invoiceNo}">
<input type="text" id="invoiceNo" name="invoiceNo"
value="TB{$invoiceNo}" class="form-control" placeholder="ID BBM"
style="width: 110px; float: left" DISABLED>
<input type="text" id="invoiceDate" name="invoiceDate"
value="{$invoiceDate}" class="form-control" placeholder="Tanggal
Transaksi Pembelian" style="width: 160px;" required>
</td>
</tr>
<tr valign="top">
<td>NO BBM</td>
<td>:</td>
<td><input type="text" id="bbmNo" name="bbmNo"
value="{$bbmNo}" class="form-control" placeholder="Nomor BBM"
style="width: 270px;" required>
{if $numsBbm == '0' AND $bbmNo != ''}
<font color="#f56954">Nomor bukti barang masuk tidak
ditemukan.</font>
{/if}
{if $numsBBuy > 0 AND $bbmNo != ''}
<font color="#f56954">Nomor bukti barang masuk sudah
digunakan.</font>
{/if}
</td>
</tr>
<tr>
<td>TIPE BAYAR</td>
<td>:</td>
<td><select id="paymentType" name="paymentType"
class="form-control" style="width: 100px; float: left;" required>
<option value=""></option>
<option value="1">Tunai</option>
<option value="2">Termin</option>
</select>
<div id="searchStatus"></div>
</td>
</tr>
<tr>
<td>PPN</td>
<td>:</td>
<td><select id="ppnType" name="ppnType" class="form-
control" style="width: 100px; float: left;" required>
<option value=""></option>
<option value="1">PPN</option>

205
<option value="2">No PPN</option>
</select>
</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>KOREKSI HARGA</th>
</tr>
</thead>
<tbody>
{if $numsBbm > 0 AND $bbmNo != ''}
{if $numsBBuy == '0' AND $bbmNo != ''}
{section name=dataBbmDetail loop=$dataBbmDetail}
<tr>
<td>{$dataBbmDetail[dataBbmDetail].no}</td>
<td>{$dataBbmDetail[dataBbmDetail].productName}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.pricerp}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.receiveQty}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.subtotal}</td>
<td><a title="Koreksi Harga" href="edit_in.php?module=in&act=edit
&detailID={$dataBbmDetail[dataBbmDetail].detailID}&bbmNo={$bbmNo}"
data-width="450" data-height="180" class="various2 fancybox
.iframe"><img src="img/icons/edit.png" width="18"></a></td>
</tr>
{/section}
{/if}
{/if}
</tbody>
</table>
</div>
<br>
{if $numsBbm > 0 AND $bbmNo != ''}
{if $numsBBuy == '0' AND $bbmNo != ''}
<table cellpadding="3" cellspacing="3">
<tr>
<td width="190">JUMLAH HARGA BELI</td>
<td width="5">:</td>
<td><input type="hidden" id="total" name="total" value="{$total}">
<input type="text" id="total" name="total" value="{$totalrp}"
class="form-control" style="width: 270px;" DISABLED>
</td>

206
</tr>
<tr>
<td>POTONGAN</td>
<td>:</td>
<td><input type="text" id="discount" name="discount"
value="0" class="form-control" style="width: 270px;"
onkeyup="sum();" required></td>
</tr>
<tr>
<td>DASAR PENGENAAN PAJAK</td>
<td>:</td>
<td><input type="hidden" id="basic" name="basic" value="{$total}">
<input type="text" id="basicrp" name="basicrp" value="{$totalrp}"
class="form-control" style="width: 270px;" DISABLED>
</td>
</tr>
<tr>
<td>PPN (10%)</td>
<td>:</td>
<td><input type="hidden" id="ppn" name="ppn" value="0">
<input type="text" id="ppnrp" name="ppnrp" value="0"
class="form-control" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>GRANDTOTAL</td>
<td>:</td>
<td><input type="hidden" id="grandtotal" name="grandtotal"
value="{$total}">
<input type="text" id="grandtotalrp" name="grandtotalrp"
value="{$totalrp}" class="form-control" style="width: 270px;"
DISABLED>
</td>
</tr>
</table>
<br>
<button type="submit" class="btn btn-primary">Simpan</button>
{/if}
{/if}
</form>
</div><!-- /.box-body -->

{elseif $module == 'in' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

207
<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Faktur Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_in.php?module=in&act=print&invoiceID=
{$invoiceID}&bbmNo={$bbmNo}&invoiceNo={$invoiceNo}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>
<a href="in.php"><button class="btn btn-default pull-
right">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO FAKTUR / TGL</td>
<td width="5">:</td>
<td><input type="text" id="invoiceNo" name="invoiceNo"
value="{$invoiceNo}" class="form-control" placeholder="Nomor
Faktur" style="width: 110px; float: left" DISABLED>
<input type="text" id="invoiceDate" name="invoiceDate"
value="{$invoiceDate}" class="form-control" placeholder="Tanggal
Penerimaan" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO BBM</td>
<td>:</td>
<td><input type="text" id="bbmNo" name="bbmNo"
value="{$bbmNo}" class="form-control" placeholder="Nomor PO"
style="width: 270px;" DISABLED></td>
</tr>
<tr valign="top">
<td>TIPE BAYAR</td>
<td>:</td>
<td><input type="text" id="paymentType" name="paymentType"
value="{$paymentType}" class="form-control" placeholder="Tipe
Bayar" style="width: 135px; float: left;" DISABLED>
<input type="text" id="expiredDate" name="expiredDate"
value="{$expiredPayment}" class="form-control" placeholder="Jatuh
Tempo" style="width: 135px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>PPN /</td>
<td>:</td>
<td><input type="text" id="ppnType" name="ppnType"
value="{$ppnType}" class="form-control" placeholder="PPN"
style="width: 80px; float: left;" DISABLED>
</td>
</tr>
<tr>
<td colspan="3">
<br>

208
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA</th>
<th>QTY</th>
<th>SUBTOTAL</th>
</tr>
</thead>
<tbody>
{section name=dataBbmDetail loop=$dataBbmDetail}
<tr>
<td>{$dataBbmDetail[dataBbmDetail].no}</td>
<td>{$dataBbmDetail[dataBbmDetail].productName}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.pricerp}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.receiveQty}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.subtotal}</td>
</tr>
{/section}
</tbody>
</table>
</div>
<br>
<table cellpadding="3" cellspacing="3">
<tr>
<td width="190">JUMLAH HARGA BELI</td>
<td width="5">:</td>
<td><input type="text" id="total" name="total" value="{$total}"
class="form-control" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>POTONGAN</td>
<td>:</td>
<td><input type="text" id="discount" name="discount"
value="{$discount}" class="form-control" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td>DASAR PENGENAAN PAJAK</td>
<td>:</td>
<td><input type="text" id="basicrp" name="basicrp"
value="{$basic}" class="form-control" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td>PPN (10%)</td>
<td>:</td>

209
<td><input type="text" id="ppnrp" name="ppnrp"
value="{$ppn}" class="form-control" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td>GRANDTOTAL</td>
<td>:</td>
<td><input type="text" id="grandtotalrp"
name="grandtotalrp" value="{$grandtotal}" class="form-control"
style="width: 270px;" DISABLED></td>
</tr>
</table>
</div><!-- /.box-body -->

{elseif $module == 'in' AND $act == 'detailin'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Faktur Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_in.php?module=in&act=print&invoiceID=
{$invoiceID}&bbmNo={$bbmNo}&invoiceNo={$invoiceNo}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>
{if $q != ''}
<a href="in.php?module=in&act=search&q={$q}"><button
class="btn btn-default pull-right">Back</button></a>
{else}
<a href="in.php?page={$page}"><button class="btn btn-
default pull-right">Back</button></a>
{/if}
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO FAKTUR / TGL</td>
<td width="5">:</td>
<td><input type="text" id="invoiceNo" name="invoiceNo"
value="{$invoiceNo}" class="form-control" placeholder="Nomor
Faktur" style="width: 110px; float: left" DISABLED>
<input type="text" id="invoiceDate" name="invoiceDate"
value="{$invoiceDate}" class="form-control" placeholder="Tanggal
Penerimaan" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO BBM</td>
<td>:</td>
<td><input type="text" id="bbmNo" name="bbmNo"
value="{$bbmNo}" class="form-control" placeholder="Nomor PO"
style="width: 270px;" DISABLED></td>
</tr>
<tr valign="top">
<td>TIPE BAYAR</td>

210
<td>:</td>
<td><input type="text" id="paymentType" name="paymentType"
value="{$paymentType}" class="form-control" placeholder="Tipe
Bayar" style="width: 135px; float: left;" DISABLED>
<input type="text" id="expiredDate" name="expiredDate"
value="{$expiredPayment}" class="form-control" placeholder="Jatuh
Tempo" style="width: 135px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>PPN</td>
<td>:</td>
<td><input type="text" id="ppnType" name="ppnType"
value="{$ppnType}" class="form-control" placeholder="PPN"
style="width: 80px; float: left;" DISABLED>
</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA</th>
<th>QTY</th>
<th>SUBTOTAL</th>
</tr>
</thead>
<tbody>
{section name=dataBbmDetail loop=$dataBbmDetail}
<tr>
<td>{$dataBbmDetail[dataBbmDetail].no}</td>
<td>{$dataBbmDetail[dataBbmDetail].productName}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.pricerp}</td>
<td style='text-align: center;'>{$dataBbmDetail[dataBbmDetail]
.receiveQty}</td>
<td style='text-align: right;'>{$dataBbmDetail[dataBbmDetail]
.subtotal}</td>
</tr>
{/section}
</tbody>
</table>
</div>
<br>
<table cellpadding="3" cellspacing="3">
<tr>
<td width="190">JUMLAH HARGA BELI</td>
<td width="5">:</td>

211
<td><input type="text" id="total" name="total" value="{$total}"
class="form-control" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>POTONGAN</td>
<td>:</td>
<td><input type="text" id="discount" name="discount"
value="{$discount}" class="form-control" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td>DASAR PENGENAAN PAJAK</td>
<td>:</td>
<td><input type="text" id="basicrp" name="basicrp"
value="{$basic}" class="form-control" style="width: 270px;"
DISABLED></td>
</tr>
<tr>
<td>PPN (10%)</td>
<td>:</td>
<td><input type="text" id="ppnrp" name="ppnrp" value="{$ppn}"
class="form-control" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>GRANDTOTAL</td>
<td>:</td>
<td><input type="text" id="grandtotalrp"
name="grandtotalrp" value="{$grandtotal}" class="form-control"
style="width: 270px;" DISABLED></td>
</tr>
</table>

</div><!-- /.box-body -->

{elseif $module == 'in' AND $act == 'search'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="in.php">
<input type="hidden" name="module" value="in">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" value="{$q}" id="q" name="q" class="form-
control" placeholder="Pencarian : Nomor Faktur Pembelian"
style="float: right; width: 270px;">
<a href="in.php?module=in&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>

212
<a href="print_in.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO INVOICE <i class="fa fa-sort"></i></th>
<th>TGL <i class="fa fa-sort"></i></th>
<th>NO BBM <i class="fa fa-sort"></i></th>
<th>GRANDTOTAL <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataBuy loop=$dataBuy}
<tr>
<td>{$dataBuy[dataBuy].no}</td>
<td>{$dataBuy[dataBuy].invoiceNo}</td>
<td>{$dataBuy[dataBuy].invoiceDate}</td>
<td>{$dataBuy[dataBuy].bbmNo}</td>
<td>{$dataBuy[dataBuy].grandtotal}</td>
<td>{$dataBuy[dataBuy].staffName}</td>
<td>
<a title="Detail" href="in.php?module=in&act=detailin&invoiceID=
{$dataBuy[dataBuy].invoiceID}&invoiceNo={$dataBuy[dataBuy].invoice
No}&bbmNo={$dataBuy[dataBuy].bbmNo}&q={$q}&page={$page}"><img
src="img/icons/view.png" width="18"></a>
<a title="Delete" href="in.php?module=in&act=delete&invoiceID=
{$dataBuy[dataBuy].invoiceID}&invoiceNo={$dataBuy[dataBuy].invoice
No}&bbmNo={$dataBuy[dataBuy].bbmNo}&" onclick="return
confirm('Anda Yakin ingin membatalkan transaksi
{$dataBuy[dataBuy].invoiceNo}? penghapusan ini akan membatalkan
seluruh hutang dan pembayaran terkait transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">

213
<div class="box-footer clearfix no-border">
<form method="GET" action="in.php">
<input type="hidden" name="module" value="in">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate"
name="endDate" class="form-control" placeholder="Periode Akhir"
style="float: right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" value="{$q}" id="q" name="q"
class="form-control" placeholder="Pencarian : Nomor Faktur
Pembelian" style="float: right; width: 270px;">
<a href="in.php?module=in&act=add" style="float:
left;"><button type="button" class="btn btn-default pull-right"><i
class="fa fa-plus"></i> Add</button></a>
<a href="print_in.php?act=print&q={$q}" style="float: left;"
target="_blank"><button type="button" class="btn btn-default pull-
right"><i class="fa fa-print"></i> Print PDF</button></a>
&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO INVOICE <i class="fa fa-sort"></i></th>
<th>TGL <i class="fa fa-sort"></i></th>
<th>NO BBM <i class="fa fa-sort"></i></th>
<th>GRANDTOTAL <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataBuy loop=$dataBuy}
<tr>
<td>{$dataBuy[dataBuy].no}</td>
<td>{$dataBuy[dataBuy].invoiceNo}</td>
<td>{$dataBuy[dataBuy].invoiceDate}</td>
<td>{$dataBuy[dataBuy].bbmNo}</td>
<td>{$dataBuy[dataBuy].grandtotal}</td>
<td>{$dataBuy[dataBuy].staffName}</td>
<td>
<a title="Detail" href="in.php?module=in&act=detailin&invoiceID=
{$dataBuy[dataBuy].invoiceID}&invoiceNo={$dataBuy[dataBuy].invoice
No}&bbmNo={$dataBuy[dataBuy].bbmNo}&page={$page}"><img
src="img/icons/view.png" width="18"></a>
<a title="Delete" href="in.php?module=in&act=delete&invoiceID=
{$dataBuy[dataBuy].invoiceID}&invoiceNo={$dataBuy[dataBuy].invoice

214
No}&bbmNo={$dataBuy[dataBuy].bbmNo}&" onclick="return
confirm('Anda Yakin ingin membatalkan transaksi
{$dataBuy[dataBuy].invoiceNo}? penghapusan ini akan membatalkan
seluruh hutang dan pembayaran terkait transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil seluruh skrip diatas akan menghasilkan halaman transaksi pembelian


(faktur) yang hasilnya dapat dilihat pada gambar-gambar berikut :

Gambar 5.26. Transaksi pembelian

215
Gambar 5.27. Cetak transaksi pembelian

5.2.4 Pembayaran Transaksi Pembelian


Halaman ini digunakan untuk membayar transaksi pembelian yang telah
dilakukan. Kita juga akan bahas file apa saja yang diperlukan untuk membuat
pembayaran transaksi pembelian ini.
Buat beberapa file dengan masing-masing skrip berikut :
pay_in.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "pay_in.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '26'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);

216
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is pay in and action is delete


if ($module == 'payin' && $act == 'delete')
{
// insert method into a variable
$invoiceNo = $_GET['invoiceNo'];
$paymentID = $_GET['paymentID'];
$paymentNo = $_GET['paymentNo'];
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryPayment = "SELECT total, invoiceID FROM as_buy_payments


WHERE paymentID = '$paymentID' AND paymentNo = '$paymentNo'";
$sqlPayment = mysqli_query($connect, $queryPayment);
$dataPayment = mysqli_fetch_array($sqlPayment);

$total = $dataPayment['total'];

$queryUpdate = "UPDATE as_debts SET


incomingTotal=incomingTotal-$total WHERE invoiceNo = '$invoiceNo'
AND invoiceID = '$dataPayment[invoiceID]'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);

if ($sqlUpdate)
{
$queryPay = "DELETE FROM as_buy_payments WHERE
paymentID = '$paymentID' AND paymentNo = '$paymentNo'";
$sqlPay = mysqli_query($connect, $queryPay);
}

// redirect to the pay in page


if ($q != '')
{
header("Location: pay_in.php?module=payin&act=search&q=".$q");
}
else
{
header("Location: pay_in.php");
}
} // close bracket

// if the module is in and action is cancel


elseif ($module == 'in' && $act == 'cancel')
{
$bbmNo = $_GET['bbmNo'];

$queryBbm = "SELECT productID, detailID, receiveQty FROM


as_detail_bbm WHERE bbmNo = '$bbmNo'";
$sqlBbm = mysqli_query($connect, $queryBbm);

while ($dataBbm = mysqli_fetch_array($sqlBbm))

217
{
$queryProduct = "SELECT hpp FROM as_products WHERE productID =
'$dataBbm[productID]'";
$sqlProduct = mysqli_query($connect, $queryProduct);
$dataProduct = mysqli_fetch_array($sqlProduct);

$update = "UPDATE as_detail_bbm SET price =


'$dataProduct[hpp]' WHERE detailID = '$dataBbm[detailID]' AND
productID = '$dataBbm[productID]'";
mysqli_query($connect, $update);

$total = $dataProduct['hpp'] * $dataBbm['receiveQty'];


$settotal += $total;
}

$queryUpdate = "UPDATE as_bbm SET total = '$settotal' WHERE bbmNo


= '$bbmNo'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);

// redirect to the in page


header("Location: in.php");
}

// if the module is in and act is input


elseif ($module == 'payin' && $act == 'input')
{
$createdDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];

$paymentNo = $_POST['paymentNo'];
$pDate = explode("-", $_POST['paymentDate']);
$paymentDate = $pDate[2]."-".$pDate[1]."-".$pDate[0];
$invoiceID = $_POST['invoiceID'];
$invoiceNo = mysqli_real_escape_string($connect,
$_POST['invoiceNo']);
$spbNo = $_POST['spbNo'];
$payType = $_POST['payType'];
$bankNo = mysqli_real_escape_string($connect, $_POST['bankNo']);
$bankName = mysqli_real_escape_string($connect,
$_POST['bankName']);
$bankAC = mysqli_real_escape_string($connect, $_POST['bankAC']);
$eDate = explode("-", $_POST['effectiveDate']);
$effectiveDate = $eDate[2]."-".$eDate[1]."-".$eDate[0];
$total = mysqli_real_escape_string($connect, $_POST['total']);
$supplierID = $_POST['supplierID'];
$supplierName = mysqli_real_escape_string($connect,
$_POST['supplierName']);
$supplierAddress = mysqli_real_escape_string($connect,
$_POST['supplierAddress']);
$ref = mysqli_real_escape_string($connect, $_POST['ref']);
$note = mysqli_real_escape_string($connect, $_POST['note']);

// save in to the database


$queryPay = "INSERT INTO as_buy_payments ( paymentNo,
invoiceID,
invoiceNo,

218
spbNo,
paymentDate,
payType,
bankNo,
bankName,
bankAC,
effectiveDate,
total,
supplierID,
supplierName,
supplierAddress,
ref,
note,
staffID,
staffName,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$paymentNo',
'$invoiceID',
'$invoiceNo',
'$spbNo',
'$paymentDate',
'$payType',
'$bankNo',
'$bankName',
'$bankAC',
'$effectiveDate',
'$total',
'$supplierID',
'$supplierName',
'$supplierAddress',
'$ref',
'$note',
'$staffID',
'$sName',
'$createdDate',
'$staffID',
'',
'')";

$sqlPay = mysqli_query($connect, $queryPay);

$paymentID = mysqli_insert_id($connect);

if ($sqlPay)
{
$queryUpdate = "UPDATE as_debts SET
incomingTotal=incomingTotal+$total WHERE invoiceNo = '$invoiceNo'
AND invoiceID = '$invoiceID'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);
}

header("Location:
pay_in.php?module=payin&act=finish&paymentNo=".$paymentNo."&paymen
tID=".$paymentID."&invoiceNo=".$invoiceNo);

219
}

// if the module is pay in and act is detail pay in


elseif ($module == 'payin' && $act == 'detailpayin')
{
$paymentID = $_GET['paymentID'];
$paymentNo = $_GET['paymentNo'];
$invoiceNo = $_GET['invoiceNo'];
$q = mysqli_real_escape_string($connect, $_GET['q']);

// show the buy transaction


$queryBuy = "SELECT * FROM as_buy_transactions WHERE
invoiceNo = '$invoiceNo'";
$sqlBuy = mysqli_query($connect, $queryBuy);
$dataBuy = mysqli_fetch_array($sqlBuy);

// show the debt


$queryDebt = "SELECT * FROM as_debts WHERE invoiceNo =
'$invoiceNo' AND invoiceID = '$dataBuy[invoiceID]'";
$sqlDebt = mysqli_query($connect, $queryDebt);
$dataDebt = mysqli_fetch_array($sqlDebt);

// show the payment


$queryPay = "SELECT * FROM as_buy_payments WHERE paymentNo =
'$paymentNo' AND paymentID = '$paymentID' AND invoiceNo =
'$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$queryTotal = "SELECT SUM(total) as total FROM


as_buy_payments WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// debt
$debt = $dataTotal['total'] - $dataBuy['grandtotal'];

if ($dataPay['payType'] == '1')
{
$payType = "TUNAI";
}
elseif ($dataPay['payType'] == '2')
{
$payType = "TRANSFER";
}
elseif ($dataPay['payType'] == '3')
{
$payType = "CEK";
}
else
{
$payType = "GIRO";
}

if ($dataPay['effectiveDate'] == '0000-00-00')
{
$effectiveDate = "-";

220
}
else
{
$effectiveDate = tgl_indo2($dataPay['effectiveDate']);
}

// assign
$smarty->assign("q", $q);
$smarty->assign("paymentNo", $dataPay['paymentNo']);
$smarty->assign("paymentID", $dataPay['paymentID']);
$smarty->assign("paymentDate",
tgl_indo2($dataPay['paymentDate']));
$smarty->assign("invoiceNo", $dataPay['invoiceNo']);
$smarty->assign("pay", rupiah($total));
$smarty->assign("total", rupiah($dataPay['total']));
$smarty->assign("debt", rupiah($debt));
$smarty->assign("supplierName", $dataBuy['supplierName']);
$smarty->assign("supplierAddress", $dataBuy['supplierAddress']);
$smarty->assign("payType", $payType);
$smarty->assign("bankNo", $dataPay['bankNo']);
$smarty->assign("bankName", $dataPay['bankName']);
$smarty->assign("effectiveDate", $effectiveDate);
$smarty->assign("bankAC", $dataPay['bankAC']);
$smarty->assign("total", rupiah($dataPay['total']));
$smarty->assign("ref", $dataPay['ref']);
$smarty->assign("note", $dataPay['note']);

$smarty->assign("breadcumbTitle", "Pembayaran Transaksi


Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan pembayaran transaksi pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Pembayaran Transaksi");
}

// if module in and act is finish


elseif ($module == 'payin' && $act == 'finish')
{
$paymentNo = $_GET['paymentNo'];
$paymentID = $_GET['paymentID'];
$invoiceNo = $_GET['invoiceNo'];

// show the buy transaction


$queryBuy = "SELECT * FROM as_buy_transactions WHERE invoiceNo =
'$invoiceNo'";
$sqlBuy = mysqli_query($connect, $queryBuy);
$dataBuy = mysqli_fetch_array($sqlBuy);

// show the debt


$queryDebt = "SELECT * FROM as_debts WHERE invoiceNo =
'$invoiceNo' AND invoiceID = '$dataBuy[invoiceID]'";
$sqlDebt = mysqli_query($connect, $queryDebt);
$dataDebt = mysqli_fetch_array($sqlDebt);

// show the payment

221
$queryPay = "SELECT * FROM as_buy_payments WHERE paymentNo =
'$paymentNo' AND paymentID = '$paymentID' AND invoiceNo =
'$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$queryTotal = "SELECT SUM(total) as total FROM


as_buy_payments WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// debt
$debt = $dataBuy['grandtotal'] - $dataTotal['total'];

if ($dataPay['payType'] == '1')
{
$payType = "TUNAI";
}
elseif ($dataPay['payType'] == '2')
{
$payType = "TRANSFER";
}
elseif ($dataPay['payType'] == '3')
{
$payType = "CEK";
}
else
{
$payType = "GIRO";
}

if ($dataPay['effectiveDate'] == '0000-00-00')
{
$effectiveDate = "-";
}
else
{
$effectiveDate = tgl_indo2($dataPay['effectiveDate']);
}

// assign
$smarty->assign("paymentNo", $dataPay['paymentNo']);
$smarty->assign("paymentID", $dataPay['paymentID']);
$smarty->assign("paymentDate",
tgl_indo2($dataPay['paymentDate']));
$smarty->assign("invoiceNo", $dataPay['invoiceNo']);
$smarty->assign("pay", rupiah($total));
$smarty->assign("total", rupiah($dataPay['total']));
$smarty->assign("debt", rupiah($debt));
$smarty->assign("supplierName", $dataBuy['supplierName']);
$smarty->assign("supplierAddress", $dataBuy['supplierAddress']);
$smarty->assign("payType", $payType);
$smarty->assign("bankNo", $dataPay['bankNo']);
$smarty->assign("bankName", $dataPay['bankName']);
$smarty->assign("effectiveDate", $effectiveDate);
$smarty->assign("bankAC", $dataPay['bankAC']);
$smarty->assign("total", rupiah($dataPay['total']));

222
$smarty->assign("ref", $dataPay['ref']);
$smarty->assign("note", $dataPay['note']);

$smarty->assign("breadcumbTitle", "Pembayaran Transaksi


Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan pembayaran transaksi pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Pembayaran Transaksi");
}

// if the module in and act is add


elseif ($module == 'payin' && $act == 'add')
{
$invoiceNo = mysqli_real_escape_string($connect,
$_GET['invoiceNo']);

// get last sort in number pay ID


$queryNoPayIn = "SELECT paymentNo FROM as_buy_payments
ORDER BY paymentNo DESC LIMIT 1";
$sqlNoPayIn = mysqli_query($connect, $queryNoPayIn);
$numsNoPayIn = mysqli_num_rows($sqlNoPayIn);
$dataNoPayIn = mysqli_fetch_array($sqlNoPayIn);

$start = substr($dataNoPayIn['paymentNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoPayIn == '0')
{
$inNo = "00000";
}
elseif ($tempNo == 1)
{
$inNo = "00000";
}
elseif ($tempNo == 2)
{
$inNo = "0000";
}
elseif ($tempNo == 3)
{
$inNo = "000";
}
elseif ($tempNo == 4)
{
$inNo = "00";
}
elseif ($tempNo == 5)
{
$inNo = "0";
}
elseif ($tempNo == 6)
{
$inNo = "";
}

223
$payInNo = "PP".$inNo.$next;

// total grandtotal
$queryTotal = "SELECT grandtotal, invoiceID, spbNo,
supplierID, supplierName, supplierAddress FROM as_buy_transactions
WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$numsTotal = mysqli_num_rows($sqlTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// count payment
$queryPay = "SELECT SUM(total) as total FROM
as_buy_payments WHERE invoiceNo = '$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$debt = $dataTotal['grandtotal'] - $dataPay['total'];

$smarty->assign("payInNo", $payInNo);
$smarty->assign("payInDate", tgl_indo2(date('Y-m-d')));
$smarty->assign("invoiceNo", $invoiceNo);
$smarty->assign("invoiceID", $dataTotal['invoiceID']);
$smarty->assign("numsTotal", $numsTotal);
$smarty->assign("spbNo", $dataTotal['spbNo']);
$smarty->assign("debt", rupiah($debt));
$smarty->assign("debto", $debt);
$smarty->assign("supplierID", $dataTotal['supplierID']);
$smarty->assign("supplierName", $dataTotal['supplierName']);
$smarty->assign("supplierAddress", $dataTotal['supplierAddress']);

$smarty->assign("breadcumbTitle", "Transaksi Pembelian");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
transaksi pembelian, faktur pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Transaksi Pembelian");
}

elseif ($module == 'payin' && $act == 'search')


{
$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the pay in data


if ($sDate != '' && $eDate != '')
{

224
$queryPay = "SELECT * FROM as_buy_payments WHERE
paymentNo LIKE '%$q%' AND paymentDate BETWEEN '$startDate' AND
'$endDate' ORDER BY paymentDate DESC";
}
else
{
$queryPay = "SELECT * FROM as_buy_payments WHERE
paymentNo LIKE '%$q%' ORDER BY paymentDate DESC";
}

$sqlPay = mysqli_query($connect, $queryPay);

// fetch data
$i = 1 + $position;
while ($dtPay = mysqli_fetch_array($sqlPay))
{
if ($dtPay['payType'] == '1')
{
$payType = "TUNAI";
$effectiveDate = "";
}
else
{
$payType = "CEK";
$effectiveDate = tgl_indo2($dtPay['effectiveDate']);
}

$dataPay[] = array( 'paymentID' => $dtPay['paymentID'],


'invoiceNo' => $dtPay['invoiceNo'],
'invoiceID' => $dtPay['invoiceID'],
'paymentNo' => $dtPay['paymentNo'],
'paymentDate' => tgl_indo2($dtPay['paymentDate']),
'payType' => $payType,
'spbNo' => $dtPay['spbNo'],
'invoiceNo' => $dtPay['invoiceNo'],
'cek' => $dtPay['bankNo'],
'total' => rupiah($dtPay['total']),
'supplierName' => $dtPay['supplierName'],
'staffName' => $dtPay['staffName'],
'no' => $i);
$i++;
}

$smarty->assign("dataPay", $dataPay);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Pembayaran Transaksi
Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pembayaran transaksi pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Pembayaran Transaksi");
}

else
{

225
// create new object pagination
$p = new PaginationPayIn;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the pay in data


$queryPay = "SELECT * FROM as_buy_payments ORDER BY
paymentDate DESC LIMIT $position,$limit";
$sqlPay = mysqli_query($connect, $queryPay);

// fetch data
$i = 1 + $position;
while ($dtPay = mysqli_fetch_array($sqlPay))
{
if ($dtPay['payType'] == '1')
{
$payType = "TUNAI";
$effectiveDate = "";
}
else
{
$payType = "CEK";
$effectiveDate = tgl_indo2($dtPay['effectiveDate']);
}

$dataPay[] = array( 'paymentID' => $dtPay['paymentID'],


'invoiceNo' => $dtPay['invoiceNo'],
'invoiceID' => $dtPay['invoiceID'],
'paymentNo' => $dtPay['paymentNo'],
'paymentDate' => tgl_indo2($dtPay['paymentDate']),
'payType' => $payType,
'spbNo' => $dtPay['spbNo'],
'invoiceNo' => $dtPay['invoiceNo'],
'cek' => $dtPay['bankNo'],
'total' => rupiah($dtPay['total']),
'supplierName' => $dtPay['supplierName'],
'staffName' => $dtPay['staffName'],
'no' => $i);
$i++;
}

$smarty->assign("dataPay", $dataPay);

// count data
$queryCountPay = "SELECT * FROM as_buy_payments";
$sqlCountPay = mysqli_query($connect, $queryCountPay);
$amountData = mysqli_num_rows($sqlCountPay);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);

226
$smarty->assign("breadcumbTitle", "Pembayaran Transaksi
Pembelian");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
pembayaran transaksi pembelian.");
$smarty->assign("breadcumbMenuName", "Transaksi Pembelian");
$smarty->assign("breadcumbMenuSubName", "Pembayaran Transaksi");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

pay_in.tpl (Simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>
<script type='text/javascript'
src="design/js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#paymentDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'

227
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#effectiveDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c:c+1'
});

$('#invoiceNo').change(function () {
var invoiceNo = $("#invoiceNo").val();

window.location.href =
"pay_in.php?module=payin&act=add&invoiceNo=" + invoiceNo;
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

228
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

{if $module == 'payin' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Pembayaran Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="pay_in.php" onclick="return confirm('Anda Yakin
ingin membatalkan pembayaran transaksi pembelian ini?');"><button
type="button" class="btn btn-default pull-right">Batal
Trx</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
{if $numsTotal == '0' && $invoiceNo != ''}
<span style="color: #f56954;">Nomor Faktur tidak ditemukan.</span>
{/if}
{if $numsTotal > 0}
{if $debto <= '0'}
<span style="color: green;">Nomor Faktur ini telah lunas
dibayarkan.</span>
{/if}
{/if}
<form method="POST" action="pay_in.php?module=payin&act=input">
<input type="hidden" id="supplierID" name="supplierID"
value="{$supplierID}">
<input type="hidden" id="supplierName" name="supplierName"
value="{$supplierName}">
<input type="hidden" id="supplierAddress" name="supplierAddress"
value="{$supplierAddress}">
<input type="hidden" id="spbNo" name="spbNo" value="{$spbNo}">
<input type="hidden" id="invoiceID" name="invoiceID"
value="{$invoiceID}">

229
<table cellpadding="3" cellspacing="3" width="100%">
<tr>
<td width="150">NO PAYMENT / TGL</td>
<td width="5">:</td>
<td><input type="hidden" id="paymentNo" name="paymentNo"
value="{$payInNo}">
<input type="text" id="paymentNo" name="paymentNo"
value="{$payInNo}" class="form-control" placeholder="NOMOR
PAYMENT" style="width: 110px; float: left" DISABLED>
<input type="text" id="paymentDate" name="paymentDate"
value="{$payInDate}" class="form-control" placeholder="Tanggal
Payment" style="width: 190px;" required>
</td>
</tr>
<tr valign="top">
<td>NOMOR FAKTUR</td>
<td>:</td>
<td><input type="text" id="invoiceNo" name="invoiceNo"
value="{$invoiceNo}" class="form-control" placeholder="Nomor
Faktur" style="width: 300px;" required></td>
</tr>
<tr valign="top">
<td>TERHUTANG</td>
<td>:</td>
<td><input type="text" id="debt" name="debt"
value="{$valas} {$debt}" class="form-control" placeholder="Total
Terhutang" style="width: 300px;" DISABLED></td>
</tr>
<tr>
<td>DIBAYARKAN KEPADA</td>
<td>:</td>
<td>
<input type="text" id="supplierName" name="supplierName"
value="{$supplierName}" class="form-control" placeholder="Nama
Supplier" style="width: 300px;" DISABLED>
</td>
</tr>
<tr>
<td>PEMBAYARAN</td>
<td>:</td>
<td><select id="payType" name="payType" class="form-
control" style="width: 125px; float: left;" required>
<option value=""></option>
<option value="1">Tunai</option>
<option value="2">Transfer</option>
<option value="3">Cek</option>
<option value="4">Giro</option>
</select>
<input type="text" id="bankNo" name="bankNo" class="form-control"
placeholder="Nomor Rek / Cek / Giro" style="width: 175px;
float:left;">
</td>
</tr>
<tr>
<td>NAMA BANK</td>
<td>:</td>
<td>

230
<input type="text" id="bankName" name="bankName" class="form-
control" placeholder="Nama Bank" style="width: 175px; float:
left;">
<input type="text" id="effectiveDate" name="effectiveDate"
class="form-control" placeholder="Tanggal Efektif" style="width:
125px;">
</td>
</tr>
<tr>
<td>NAMA AKUN</td>
<td>:</td>
<td>
<input type="text" id="bankAC" name="bankAC" class="form-control"
placeholder="Nama Akun (Pemegang)" style="width:300px;
float:left;">
</td>
</tr>
<tr>
<td>JUMLAH</td>
<td>:</td>
<td>
<input type="text" id="total" name="total" class="form-control"
placeholder="Jumlah" style="width: 300px;" required>
</td>
</tr>
<tr>
<td>REFERENSI</td>
<td>:</td>
<td>
<input type="text" id="ref" name="ref" class="form-control"
placeholder="Referensi" style="width: 300px;">
</td>
</tr>
<tr valign="top">
<td>NOTE</td>
<td>:</td>
<td>
<textarea id="note" name="note" class="form-control"
placeholder="Note" style="width: 300px;"></textarea>
</td>
</tr>
</table>
{if $numsTotal > 0}
{if $debto > 0}
<button type="submit" class="btn btn-primary">Simpan</button>
{/if}
{/if}
</form>

</div><!-- /.box-body -->

{elseif $module == 'payin' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";

231
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Pembayaran Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_payin.php?module=payin&act=print&invoiceNo
={$invoiceNo}&paymentNo={$paymentNo}&paymentID={$paymentID}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>
<a href="pay_in.php"><button class="btn btn-default pull-
right">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3" width="100%">
<tr>
<td width="150">NO PAYMENT / TGL</td>
<td width="5">:</td>
<td>{$paymentNo} / {$paymentDate}</td>
</tr>
<tr valign="top">
<td>NOMOR FAKTUR</td>
<td>:</td>
<td>{$invoiceNo}</td>
</tr>
<tr valign="top">
<td>TERHUTANG</td>
<td>:</td>
<td>{$debt}</td>
</tr>
<tr>
<td>DIBAYARKAN KEPADA</td>
<td>:</td>
<td>{$supplierName}</td>
</tr>
<tr>
<td></td>
<td></td>
<td>{$supplierAddress}</td>
</tr>
<tr>
<td>PEMBAYARAN</td>
<td>:</td>
<td>{$payType}</td>

232
</tr>
<tr>
<td>NO REK/CEK/GIRO</td>
<td>:</td>
<td>{$bankNo}</td>
</tr>
<tr>
<td>NAMA BANK</td>
<td>:</td>
<td>{$bankName}</td>
</tr>
<tr>
<td>TGL EFEKTIF</td>
<td>:</td>
<td>{$effectiveDate}</td>
</tr>
<tr>
<td>NAMA AKUN</td>
<td>:</td>
<td>{$bankAC}</td>
</tr>
<tr>
<td>JUMLAH</td>
<td>:</td>
<td>{$total}</td>
</tr>
<tr>
<td>REFERENSI</td>
<td>:</td>
<td>{$ref}</td>
</tr>
<tr valign="top">
<td>NOTE</td>
<td>:</td>
<td>{$note}</td>
</tr>
</table>
</div><!-- /.box-body -->

{elseif $module == 'payin' AND $act == 'detailpayin'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Pembayaran Transaksi Pembelian</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_payin.php?module=payin&act=print&invoiceNo=
{$invoiceNo}&paymentNo={$paymentNo}&paymentID={$paymentID}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>
{if $q != ''}
<a href="pay_in.php?module=payin&act=search&q={$q}"><button
class="btn btn-default pull-right">Back</button></a>
{else}
<a href="pay_in.php?page={$page}"><button class="btn btn-default
pull-right">Back</button></a>
{/if}
</div>

233
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3" width="100%">
<tr>
<td width="150">NO PAYMENT / TGL</td>
<td width="5">:</td>
<td>{$paymentNo} / {$paymentDate}</td>
</tr>
<tr valign="top">
<td>NOMOR FAKTUR</td>
<td>:</td>
<td>{$invoiceNo}</td>
</tr>
<tr valign="top">
<td>TERHUTANG</td>
<td>:</td>
<td>{$debt}</td>
</tr>
<tr>
<td>DIBAYARKAN KEPADA</td>
<td>:</td>
<td>{$supplierName}</td>
</tr>
<tr>
<td></td>
<td></td>
<td>{$supplierAddress}</td>
</tr>
<tr>
<td>PEMBAYARAN</td>
<td>:</td>
<td>{$payType}</td>
</tr>
<tr>
<td>NO REK/CEK/GIRO</td>
<td>:</td>
<td>{$bankNo}</td>
</tr>
<tr>
<td>NAMA BANK</td>
<td>:</td>
<td>{$bankName}</td>
</tr>
<tr>
<td>TGL EFEKTIF</td>
<td>:</td>
<td>{$effectiveDate}</td>
</tr>
<tr>
<td>NAMA AKUN</td>
<td>:</td>
<td>{$bankAC}</td>
</tr>
<tr>
<td>JUMLAH</td>

234
<td>:</td>
<td>{$total}</td>
</tr>
<tr>
<td>REFERENSI</td>
<td>:</td>
<td>{$ref}</td>
</tr>
<tr valign="top">
<td>NOTE</td>
<td>:</td>
<td>{$note}</td>
</tr>
</table>

</div><!-- /.box-body -->

{elseif $module == 'payin' AND $act == 'search'}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="pay_in.php">
<input type="hidden" name="module" value="payin">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-right"><i
class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" value="{$q}" id="q" name="q" class="form-
control" placeholder="Pencarian : Nomor Bukti Pembayaran"
style="float: right; width: 270px;" required>
<a href="pay_in.php?module=payin&act=add" style="float:
left;"><button type="button" class="btn btn-default pull-right"><i
class="fa fa-plus"></i> Add</button></a>
<a href="print_pay_in.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO PAYMENT <i class="fa fa-sort"></i></th>
<th>TGL <i class="fa fa-sort"></i></th>

235
<th>NO INVOICE <i class="fa fa-sort"></i></th>
<th>NO PO <i class="fa fa-sort"></i></th>
<th>VIA <i class="fa fa-sort"></i></th>
<th>TOTAL <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataPay loop=$dataPay}
<tr>
<td>{$dataPay[dataPay].no}</td>
<td>{$dataPay[dataPay].paymentNo}</td>
<td>{$dataPay[dataPay].paymentDate}</td>
<td>{$dataPay[dataPay].invoiceNo}</td>
<td>{$dataPay[dataPay].spbNo}</td>
<td>{$dataPay[dataPay].payType}</td>
<td>{$dataPay[dataPay].total}</td>
<td>{$dataPay[dataPay].staffName}</td>
<td>
<a title="Detail" href="pay_in.php?module=payin&act=detailpayin
&paymentID={$dataPay[dataPay].paymentID}&invoiceNo={$dataPay[dataP
ay].invoiceNo}&paymentNo={$dataPay[dataPay].paymentNo}&q={$q}&page
={$page}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="pay_in.php?module=payin&act=delete&
invoiceNo={$dataPay[dataPay].invoiceNo}&paymentNo={$dataPay[dataPa
y].paymentNo}&paymentID={$dataPay[dataPay].paymentID}&q={$q}"
onclick="return confirm('Anda Yakin ingin membatalkan nomor
pembayaran {$dataPay[dataPay].paymentNo}? penghapusan ini akan
membatalkan pembayaran transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="pay_in.php">
<input type="hidden" name="module" value="payin">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-right"><i
class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">

236
<input type="text" value="{$q}" id="q" name="q" class="form-
control" placeholder="Pencarian : Nomor Bukti Pembayaran"
style="float: right; width: 270px;">
<a href="pay_in.php?module=payin&act=add" style="float:
left;"><button type="button" class="btn btn-default pull-right"><i
class="fa fa-plus"></i> Add</button></a>
<a href="print_pay_in.php?act=print&q={$q}&startDate={$startDate}
&endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO PAYMENT <i class="fa fa-sort"></i></th>
<th>TGL <i class="fa fa-sort"></i></th>
<th>NO INVOICE <i class="fa fa-sort"></i></th>
<th>NO PO <i class="fa fa-sort"></i></th>
<th>VIA <i class="fa fa-sort"></i></th>
<th>TOTAL <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataPay loop=$dataPay}
<tr>
<td>{$dataPay[dataPay].no}</td>
<td>{$dataPay[dataPay].paymentNo}</td>
<td>{$dataPay[dataPay].paymentDate}</td>
<td>{$dataPay[dataPay].invoiceNo}</td>
<td>{$dataPay[dataPay].spbNo}</td>
<td>{$dataPay[dataPay].payType}</td>
<td>{$dataPay[dataPay].total}</td>
<td>{$dataPay[dataPay].staffName}</td>
<td>
<a title="Detail" href="pay_in.php?module=payin&act=detailpayin
&paymentID={$dataPay[dataPay].paymentID}&invoiceNo={$dataPay[dataP
ay].invoiceNo}&paymentNo={$dataPay[dataPay].paymentNo}&page={$page
}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="pay_in.php?module=payin&act=delete
&invoiceNo={$dataPay[dataPay].invoiceNo}&paymentNo={$dataPay[dataP
ay].paymentNo}&paymentID={$dataPay[dataPay].paymentID}"
onclick="return confirm('Anda Yakin ingin membatalkan nomor
pembayaran {$dataPay[dataPay].paymentNo}? penghapusan ini akan
membatalkan pembayaran transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}

237
</tbody>
</table>
</div>
</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->


</section><!-- /.Left col -->
</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil seluruh skrip diatas akan menghasilkan halaman pembayaran transaksi


pembelian yang bisa dilihat pada gambar-gambar berikut :

Gambar 5.28. Pembayaran transaksi pembelian

238
Gambar 5.29. Bukti pembayaran transaksi pembelian

5.3 Transaksi Penjualan


Transaksi penjualan didalamnya mengandung proses sales order, delivery order,
transaksi penjualan (pembuatan faktur) dan pembayaran transaksi. Digunakan
apabila customer kita ingin memesan barang kepada kita. Disini kita membahas
bagaimana membuat proses tersebut.

5.3.1 Sales Order


Sepertiyang sudah dijelaskan, sales order ada surat tembusan kepada kita dari
customer mengenai barang yang ingin kita pesan.
Buat beberapa file dengan masing-masing skrip berikut :
so.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "so.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit

239
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '28'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is so and action is delete


if ($module == 'so' && $act == 'delete')
{
// insert method into a variable
$soID = $_GET['soID'];
$soFaktur = $_GET['soFaktur'];
$soNo = $_GET['soNo'];

// delete sales order


$querySo = "DELETE FROM as_sales_order WHERE soID =
'$soID' AND soFaktur = '$soFaktur'";
$sqlSo = mysqli_query($connect, $querySo);

// delete sales order detail


$querySoDetail = "DELETE FROM as_detail_so WHERE soNo =
'$soNo' AND soFaktur = '$soFaktur'";
$sqlSoDetail = mysqli_query($connect, $querySoDetail);

// redirect to the sales order page


header("Location: so.php");
} // close bracket

// if module is sales order and act is finish


elseif ($module == 'so' && $act == 'finish')
{
$soNo = $_GET['soNo'];
$soFaktur = $_GET['soFaktur'];

// showing up the main sales order


$querySo = "SELECT * FROM as_sales_order WHERE soNo =
'$soNo' AND soFaktur = '$soFaktur'";
$sqlSo = mysqli_query($connect, $querySo);
$dataSo = mysqli_fetch_array($sqlSo);

// assign to the tpl


$smarty->assign("soID", $dataSo['soID']);
$smarty->assign("soNo", $dataSo['soNo']);
$smarty->assign("customerID", $dataSo['customerID']);
$smarty->assign("customerName", $dataSo['customerName']);
$smarty->assign("customerAddress", $dataSo['customerAddress']);

240
$smarty->assign("staffID", $dataSo['staffID']);
$smarty->assign("staffName", $dataSo['staffName']);
$smarty->assign("orderDate", tgl_indo2($dataSo['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSo['needDate']));
$smarty->assign("status", $dataSo['status']);
$smarty->assign("note", $dataSo['note']);
$smarty->assign("soFaktur", $soFaktur);

// showing up the detail sales order


$queryDetail = "SELECT * FROM as_detail_so WHERE soNo =
'$soNo' AND soFaktur = '$soFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

// fetch data
$i = 1;
while ($dtDetail = mysqli_fetch_array($sqlDetail))
{
$subtotal = $dtDetail['qty'] * $dtDetail['price'];
$dataDetail[] = array( 'detailID' => $dtDetail['detailID'],
'productID' => $dtDetail['productID'],
'productName' => $dtDetail['productName'],
'price' => rupiah($dtDetail['price']),
'subtotal' => rupiah($subtotal),
'qty' => $dtDetail['qty'],
'note' => $dtDetail['note'],
'no' => $i
);
$grandtotal += $subtotal;
$i++;
}

// assign to the tpl


$smarty->assign("grandtotal", rupiah($grandtotal));
$smarty->assign("dataDetail", $dataDetail);
$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Sales Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi sales order.");
$smarty->assign("breadcumbMenuName", "Sales Order");
$smarty->assign("breadcumbMenuSubName", "Detail Sales Order");
$smarty->assign("pageNumber", $_GET['page']);
}

// if module is sales order and act is detailso


elseif ($module == 'so' && $act == 'detailso')
{
$soID = $_GET['soID'];
$soFaktur = $_GET['soFaktur'];

$q = mysqli_real_escape_string($connect, $_GET['q']);

// showing up the main so


$querySo = "SELECT * FROM as_sales_order WHERE soID =
'$soID' AND soFaktur = '$soFaktur'";
$sqlSo = mysqli_query($connect, $querySo);
$dataSo = mysqli_fetch_array($sqlSo);

241
// assign to the tpl
$smarty->assign("soID", $dataSo['soID']);
$smarty->assign("soNo", $dataSo['soNo']);
$smarty->assign("customerID", $dataSo['supplierID']);
$smarty->assign("customerName", $dataSo['customerName']);
$smarty->assign("customerAddress", $dataSo['customerAddress']);
$smarty->assign("staffID", $dataSo['staffID']);
$smarty->assign("staffName", $dataSo['staffName']);
$smarty->assign("orderDate", tgl_indo2($dataSo['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSo['needDate']));
$smarty->assign("status", $dataSo['status']);
$smarty->assign("note", $dataSo['note']);
$smarty->assign("soFaktur", $soFaktur);

// showing up the detail so


$queryDetail = "SELECT * FROM as_detail_so WHERE soNo =
'$dataSo[soNo]' AND soFaktur = '$soFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

// fetch data
$i = 1;
while ($dtDetail = mysqli_fetch_array($sqlDetail))
{
$subtotal = $dtDetail['qty'] * $dtDetail['price'];
$dataDetail[] = array( 'detailID' => $dtDetail['detailID'],
'productID' => $dtDetail['productID'],
'productName' => $dtDetail['productName'],
'price' => rupiah($dtDetail['price']),
'subtotal' => rupiah($subtotal),
'qty' => $dtDetail['qty'],
'note' => $dtDetail['note'],
'no' => $i
);
$grandtotal += $subtotal;
$i++;
}

$smarty->assign("q", $q);

// assign to the tpl


$smarty->assign("grandtotal", rupiah($grandtotal));
$smarty->assign("dataDetail", $dataDetail);
$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Sales Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi sales order.");
$smarty->assign("breadcumbMenuName", "Sales Order");
$smarty->assign("breadcumbMenuSubName", "Detail Sales Order");
$smarty->assign("pageNumber", $_GET['page']);
}

//if module is so and act is input


elseif ($module == 'so' && $act == 'input')
{
$soFaktur = $_SESSION['soFaktur'];
$soNo = $_POST['soNo'];
$note = mysqli_real_escape_string($connect, $_POST['note']);

242
$nDate = explode("-", $_POST['needDate']);
$oDate = explode("-", $_POST['orderDate']);
$needDate = $nDate[2]."-".$nDate[1]."-".$nDate[0];
$orderDate = $oDate[2]."-".$oDate[1]."-".$oDate[0];

// update so
$querySo = "UPDATE as_sales_order SET note = '$note' WHERE
soFaktur = '$soFaktur' AND soNo = '$soNo'";
mysqli_query($connect, $querySo);

// showing up the temp detail sales order


$queryTempSo = "SELECT * FROM as_temp_detail_so WHERE soNo
= '$soNo' AND soFaktur = '$soFaktur'";
$sqlTempSo = mysqli_query($connect, $queryTempSo);
// fetch data
while ($dataSo = mysqli_fetch_array($sqlTempSo))
{
$querySaveSo = "INSERT INTO as_detail_so (soNo,
soFaktur,
productID,
productName,
price,
qty,
note,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$dataSo[soNo]',
'$dataSo[soFaktur]',
'$dataSo[productID]',
'$dataSo[productName]',
'$dataSo[price]',
'$dataSo[qty]',
'$dataSo[note]',
'$dataSo[createdDate]',
'$dataSo[createdUserID]',
'',
'')";
$save = mysqli_query($connect, $querySaveSo);
}

// delete temp detail sales order


$queryDelete = "DELETE FROM as_temp_detail_so WHERE soNo =
'$soNo' AND soFaktur = '$soFaktur'";
mysqli_query($connect, $queryDelete);

// redirect to the finish page


header("Location:
so.php?module=so&act=finish&soNo=".$soNo."&soFaktur=".$soFaktur");
}

// if module is so and act is deletedetail


elseif ($module == 'so' && $act == 'deletedetail')
{
$detailID = $_GET['detailID'];

243
// delete data
$querySo = "DELETE FROM as_temp_detail_so WHERE detailID =
'$detailID'";
$sqlSo = mysqli_query($connect, $querySo);

// redirect to the add add sales order page


header("Location: so.php?module=so&act=add");
}

// if module is so and act is cancel


elseif ($module == 'so' && $act == 'cancel')
{
$soFaktur = $_SESSION['soFaktur'];

$queryDetail = "DELETE FROM as_temp_detail_so WHERE soFaktur =


'$soFaktur'";
$sqlDetail = mysqli_query($connect, $queryDetail);

if ($sqlDetail)
{
$querySo = "DELETE FROM as_sales_order WHERE soFaktur =
'$soFaktur'";
$sqlSo = mysqli_query($connect, $querySo);
}

// redirect to the sales order page


header("Location: so.php");
}

// if module is so and act is add


elseif ($module == 'so' && $act == 'add')
{
$staffID = $_SESSION['staffID'];
$createdDate = date('Y-m-d H:i:s');

// get last sort sales order number ID


$queryNoSo = "SELECT soNo FROM as_detail_so ORDER BY soNo DESC
LIMIT 1";
$sqlNoSo = mysqli_query($connect, $queryNoSo);
$numsNoSo = mysqli_num_rows($sqlNoSo);
$dataNoSo = mysqli_fetch_array($sqlNoSo);

$start = substr($dataNoSo['soNo'],0-5);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoSo == '0')
{
$sNo = "00000";
}
elseif ($tempNo == 1)
{
$sNo = "00000";
}
elseif ($tempNo == 2)
{
$sNo = "0000";

244
}
elseif ($tempNo == 3)
{
$sNo = "000";
}
elseif ($tempNo == 4)
{
$sNo = "00";
}
elseif ($tempNo == 5)
{
$sNo = "0";
}
elseif ($tempNo == 6)
{
$sNo = "";
}

$soNo = "SO".$sNo.$next;

$smarty->assign("breadcumbTitle", "Sales Order");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi sales order.");
$smarty->assign("breadcumbMenuName", "Sales Order");
$smarty->assign("breadcumbMenuSubName", "Tambah Transaksi Sales
Order");

// save into the transfer table


$date = date('Y-m-d');

// showing up the customer


$queryCustomer = "SELECT * FROM as_customers ORDER BY customerName
ASC";
$sqlCustomer = mysqli_query($connect, $queryCustomer);
while ($dtCustomer = mysqli_fetch_array($sqlCustomer))
{
$dataCustomer[] = array('customerID' => $dtCustomer['customerID'],
'customerCode' => $dtCustomer['customerCode'],
'customerName' => $dtCustomer['customerName']);
}

$smarty->assign("dataCustomer", $dataCustomer);

// count so based on soFaktur


$showSo1 = "SELECT * FROM as_sales_order WHERE soFaktur =
'$_SESSION[soFaktur]'";
$sqlSo1 = mysqli_query($connect, $showSo1);
$numsSo = mysqli_num_rows($sqlSo1);

if ($numsSo == 0)
{
$orderDate = date('Y-m-d');
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$querySo = "INSERT INTO as_sales_order( soNo,
soFaktur,
customerID,
customerName,

245
customerAddress,
staffID,
staffName,
orderDate,
needDate,
note,
status,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$soNo',
'$_SESSION[soFaktur]',
'',
'',
'',
'$_SESSION[staffID]',
'$sName',
'$orderDate',
'$orderDate',
'',
'',
'$createdDate',
'$staffID',
'',
'')";
mysqli_query($connect, $querySo);
}

// count sales order based on soFaktur


$showSo = "SELECT * FROM as_sales_order WHERE soFaktur =
'$_SESSION[soFaktur]'";
$sqlSo = mysqli_query($connect, $showSo);
$dataSo = mysqli_fetch_array($sqlSo);
$numsSo = mysqli_num_rows($sqlSo);

$smarty->assign("customerID", $dataSo['customerID']);

if ($dataSo['needDate'] == '0000-00-00')
{
$needDate = tgl_indo2(date('Y-m-d'));
}
else
{
$needDate = tgl_indo2($dataSo['needDate']);
}

if ($dataSo['orderDate'] == '0000-00-00')
{
$orderDate = tgl_indo2(date('Y-m-d'));
}
else
{
$orderDate = tgl_indo2($dataSo['orderDate']);
}

$smarty->assign("soNo", $soNo);

246
$smarty->assign("orderDateIndo", $orderDate);
$smarty->assign("needDateIndo", $needDate);
$smarty->assign("soFaktur", $_SESSION['soFaktur']);
$smarty->assign("note", $dataSo['note']);

// query detil sales order


$queryDetilSo = "SELECT * FROM as_temp_detail_so WHERE soFaktur =
'$_SESSION[soFaktur]' AND soNo = '$soNo' ORDER BY detailID ASC";
$sqlDetilSo = mysqli_query($connect, $queryDetilSo);
$numsDetilSo = mysqli_num_rows($sqlDetilSo);

// fetch data
$i = 1;
while ($dtDetilSo = mysqli_fetch_array($sqlDetilSo))
{
$subtotal = $dtDetilSo['price'] * $dtDetilSo['qty'];
$dataDetilSo[] = array('detailID' => $dtDetilSo['detailID'],
'productName' => $dtDetilSo['productName'],
'price' => rupiah($dtDetilSo['price']),
'qty' => $dtDetilSo['qty'],
'note' => $dtDetilSo['note'],
'subtotal' => rupiah($subtotal),
'no' => $i);
$i++;
}

// assign to the tpl


$smarty->assign("dataDetilSo", $dataDetilSo);
$smarty->assign("numsDetilSo", $numsDetilSo);
} // close bracket

// if the module is so and act is search


elseif ($module == 'so' && $act == 'search')
{
$_SESSION['soFaktur'] = date('Ymdhis');
$smarty->assign("soFaktur", $_SESSION['soFaktur']);

$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the sales order data


if ($sDate != '' && $eDate != '')
{
$querySo = "SELECT * FROM as_sales_order WHERE soNo LIKE '%$q%'
AND orderDate BETWEEN '$startDate' AND '$endDate' ORDER BY soID
DESC";
}

247
else
{
$querySo = "SELECT * FROM as_sales_order WHERE soNo LIKE '%$q%'
ORDER BY soID DESC";
}

$sqlSo = mysqli_query($connect, $querySo);

// fetch data
$i = 1 + $position;
while ($dtSo = mysqli_fetch_array($sqlSo))
{
$dataSo[] = array( 'soID' => $dtSo['soID'],
'soNo' => $dtSo['soNo'],
'soFaktur' => $dtSo['soFaktur'],
'customerName' => $dtSo['customerName'],
'staffName' => $dtSo['staffName'],
'orderDate' => tgl_indo2($dtSo['orderDate']),
'needDate' => tgl_indo2($dtSo['needDate']),
'total' => rupiah($dtSo['total']),
'status' => $dtSo['status'],
'no' => $i);
$i++;
}

$smarty->assign("dataSo", $dataSo);

$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Sales Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi sales order.");
$smarty->assign("breadcumbMenuName", "Sales Order");
$smarty->assign("breadcumbMenuSubName", "Sales Order");
}

else
{
$_SESSION['soFaktur'] = date('Ymdhis');
$smarty->assign("soFaktur", $_SESSION['soFaktur']);
// create new object pagination
$p = new PaginationSo;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the sales order data


$querySo = "SELECT * FROM as_sales_order ORDER BY soID DESC LIMIT
$position,$limit";
$sqlSo = mysqli_query($connect, $querySo);

// fetch data
$i = 1 + $position;
while ($dtSo = mysqli_fetch_array($sqlSo))
{

248
$dataSo[] = array( 'soID' => $dtSo['soID'],
'soNo' => $dtSo['soNo'],
'soFaktur' => $dtSo['soFaktur'],
'customerName' => $dtSo['customerName'],
'staffName' => $dtSo['staffName'],
'orderDate' => tgl_indo2($dtSo['orderDate']),
'needDate' => tgl_indo2($dtSo['needDate']),
'total' => rupiah($dtSo['total']),
'status' => $dtSo['status'],
'no' => $i);
$i++;
}

$smarty->assign("dataSo", $dataSo);

// count data
$queryCountSo = "SELECT * FROM as_sales_order";
$sqlCountSo = mysqli_query($connect, $queryCountSo);
$amountData = mysqli_num_rows($sqlCountSo);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Sales Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi sales order.");
$smarty->assign("breadcumbMenuName", "Sales Order");
$smarty->assign("breadcumbMenuSubName", "Sales Order");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

so.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>

249
<script type='text/javascript'
src="design/js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#orderDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#needDate').change(function () {
var soNo = $("#soNo").val();
var needDate = $("#needDate").val();

$.ajax({
type: 'POST',
url: 'save_so_needdate.php',
dataType: 'JSON',
data:{
soNo: soNo,
needDate: needDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";

250
}
});
});

$('#orderDate').change(function () {
var soNo = $("#soNo").val();
var orderDate = $("#orderDate").val();

$.ajax({
type: 'POST',
url: 'save_so_orderdate.php',
dataType: 'JSON',
data:{
soNo: soNo,
orderDate: orderDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";
}
});
});

$('#note').change(function () {
var soNo = $("#soNo").val();
var note = $("#note").val();

$.ajax({
type: 'POST',
url: 'save_so_note.php',
dataType: 'JSON',
data:{
soNo: soNo,
note: note
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";
}
});
});

$( "#needDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c+1'
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#so").submit(function() { return false; });


$("#so2").submit(function() { return false; });

$("#productBarcode").autocomplete("product_so_autocomplete.php", {
width: 310

251
}).result(function(event, item, a) {
var myarr = item[0].split(" # ");
document.getElementById('productBarcode').value = myarr[0];
document.getElementById('productName1').value = myarr[1];
document.getElementById('productName').value = myarr[1];
document.getElementById('productID').value = myarr[2];
document.getElementById('unitPrice1').value = myarr[3];
document.getElementById('unitPrice2').value = myarr[4];
document.getElementById('unitPrice3').value = myarr[5];
document.getElementById('price').value = myarr[6];
});

$("#customerID").change(function(e){
var customerID = $("#customerID").val();

$.ajax({
type: 'POST',
url: 'save_so_customer.php',
dataType: 'JSON',
data:{
customerID: customerID
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";
}
});
});

$("#send2").on("click", function(){
var soNo = $("#soNo").val();
var productID = $("#productID").val();
var productName1 = $("#productName1").val();
var qty = parseInt($("#qty").val());
var price = parseInt($("#price").val());
var desc = $("#desc").val();

if (qty != '' && soNo != '' && productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_so.php',
dataType: 'JSON',
data:{
qty: qty,
price: price,
soNo: soNo,
productID: productID,
productName1: productName1,
desc: desc
},
beforeSend: function (data) {
$('#send2').hide();
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";

252
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}
{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<aside class="left-side sidebar-offcanvas">
<section class="sidebar">
{include file="user_panel.tpl"}
{include file="side_menu.tpl"}
</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

{if $module == 'so' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>

253
<h3 class="box-title">Tambah Sales Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="so.php?module=so&act=cancel" onclick="return
confirm('Anda Yakin ingin membatalkan SO ini?');"><button
class="btn btn-default pull-right">Batal Trx</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<form method="POST" action="so.php?module=so&act=input">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">NO SO / TGL</td>
<td width="5">:</td>
<td><input type="hidden" id="soNo" name="soNo" value="{$soNo}">
<input type="text" id="soNo" name="soNo" value="{$soNo}"
class="form-control" placeholder="NO SO" style="width: 110px;
float: left" DISABLED>
<input type="text" id="orderDate" name="orderDate"
value="{$orderDateIndo}" class="form-control" placeholder="Tanggal
PO" style="width: 160px;" required>
</td>
</tr>
<tr>
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="needDate" name="needDate"
value="{$needDateIndo}" class="form-control" placeholder="Tanggal
Dibutuhkan" style="width: 270px;" required></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td>
<select id="customerID" name="customerID" class="form-control"
style="width: 270px;" required>
<option value=""></option>
{section name=dataCustomer loop=$dataCustomer}
{if $dataCustomer[dataCustomer].customerID == $customerID}
<option value="{$dataCustomer[dataCustomer].customerID}"
SELECTED>{$dataCustomer[dataCustomer].customerName}
[{$dataCustomer[dataCustomer].customerCode}]</option>
{else}
<option value="{$dataCustomer[dataCustomer].customerID}">
{$dataCustomer[dataCustomer].customerName}
[{$dataCustomer[dataCustomer].customerCode}]</option>
{/if}
{/section}
</select>
</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>

254
<td><input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width:
270px;"></td>
</tr>
<tr>
<td colspan="3">
<br>
{if $numsDetilSo < 10}
<a href="#inline" class="modalbox"><button class="btn btn-default
pull-left"><i class="fa fa-plus"></i> Add</button></a>
{/if}
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataDetilSo loop=$dataDetilSo}
<tr>
<td>{$dataDetilSo[dataDetilSo].no}</td>
<td>{$dataDetilSo[dataDetilSo].productName}</td>
<td style='text-align: right;'>{$dataDetilSo[dataDetilSo]
.price}</td>
<td style='text-align: center;'>{$dataDetilSo[dataDetilSo]
.qty}</td>
<td style='text-align: right;'>{$dataDetilSo[dataDetilSo]
.subtotal}</td>
<td>{$dataDetilSo[dataDetilSo].note}</td>
<td>
<a title="Edit" href="edit_so.php?module=so&act=edit&detailID
={$dataDetilSo[dataDetilSo].detailID}" data-width="550" data-
height="230" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a>
<a title="Delete" href="so.php?module=so&act=deletedetail&detailID
={$dataDetilSo[dataDetilSo].detailID}" onclick="return
confirm('Anda Yakin ingin menghapus item produk
{$dataDetilSo[dataDetilSo].productName}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
<br>

255
<br>
{if $numsDetilSo > 0}
<button type="submit" class="btn btn-primary">Simpan</button>
{else}
<button type="button" class="btn btn-primary">Simpan</button>
{/if}
</form>

</div><!-- /.box-body -->

<div id="inline">
<table width="95%" align="center">
<tr>
<td colspan="3"><h3>Tambah Item</h3></td>
</tr>
<tr>
<td>
<form id="so" name="so" method="POST" action="#">
<input type="hidden" id="soNo" name="soNo" value="{$soNo}">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="140">Kode Produk</td>
<td width="5">:</td>
<td><input type="text" id="productBarcode"
name="productBarcode" class="form-control" placeholder="Kode atau
Nama Produk" style="width: 360px;" required></td>
</tr>
<tr>
<td colspan="2"></td>
<td><input type="hidden" id="productID" name="productID">
<input type="hidden" id="productName1" name="productName1">
<input type="text" id="productName" name="productName"
class="form-control" placeholder="Nama Produk" style="width:
360px;" DISABLED>
</td>
</tr>
<tr>
<td>Harga Satuan</td>
<td>:</td>
<td><input id="unitPrice1" name="unitPrice1" class="form-control"
placeholder="Harga 1" style="width: 120px; float: left;" DISABLED>
<input id="unitPrice2" name="unitPrice2" class="form-control"
placeholder="Harga 2" style="width: 120px; float: left;" DISABLED>
<input id="unitPrice3" name="unitPrice3" class="form-control"
placeholder="Harga 3" style="width: 120px;;" DISABLED>
</td>
</tr>
<tr>
<td>Masukan Harga</td>
<td>:</td>
<td><input type="number" id="price" name="price"
class="form-control" placeholder="Harga Satuan" style="width:
360px;" required></td>
</tr>
<tr>
<td>Qty</td>
<td>:</td>

256
<td><input type="number" id="qty" name="qty" class="form-control"
placeholder="Qty Produk" style="width: 360px;" required></td>
</tr>
<tr>
<td>Note</td>
<td>:</td>
<td><input type="text" id="desc" name="desc" class="form-
control" placeholder="Note" style="width: 360px;"></td>
</tr>
</table>
<button id="send2" class="btn btn-primary">Simpan</button>
</form>
</td>
</tr>
</table>
</div>

{elseif $module == 'so' AND $act == 'detailso'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Detail Sales Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_so.php?module=so&act=print&soID={$soID}&
soFaktur={$soFaktur}" target="_blank"><button class="btn btn-
default pull-right">Print</button></a>
{if $q != ''}
<a href="so.php?module=so&act=search&q={$q}&page={$pageNumber}">
<button class="btn btn-default pull-right">Back</button></a>
{else}
<a href="so.php?page={$pageNumber}"><button class="btn btn-default
pull-right">Back</button></a>
{/if}
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">NO SO / TGL</td>
<td width="5">:</td>
<td>{$soNo} / {$orderDate}</td>
</tr>
<tr>
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td>{$needDate}</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td>{$customerName}</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>

257
<td>{$note}</td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
</tr>
</thead>
<tbody>
{section name=dataDetail loop=$dataDetail}
<tr>
<td>{$dataDetail[dataDetail].no}</td>
<td>{$dataDetail[dataDetail].productName}</td>
<td style="text-align: right;">{$dataDetail[dataDetail]
.price}</td>
<td style="text-align: center;">{$dataDetail[dataDetail]
.qty}</td>
<td style="text-align: right;">{$dataDetail[dataDetail]
.subtotal}</td>
<td>{$dataDetail[dataDetail].note}</td>
</tr>
{/section}
<tr>
<td colspan="4"></td>
<td style="text-align: right;">{$grandtotal}</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div><!-- /.box-body -->

{elseif $module == 'so' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>

258
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Detail Sales Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_so.php?module=so&act=print&soID={$soID}&
soFaktur={$soFaktur}" target="_blank"><button class="btn btn-
default pull-right">Print</button></a>
<a href="so.php"><button class="btn btn-default pull-right
">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="130">NO SO / TGL</td>
<td width="5">:</td>
<td>{$soNo} / {$orderDate}</td>
</tr>
<tr>
<td>TGL DIBUTUHKAN</td>
<td>:</td>
<td>{$needDate}</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td>{$customerName}</td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td>{$note}</td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>HARGA SATUAN</th>
<th>QTY</th>
<th>SUBTOTAL</th>
<th>NOTE</th>
</tr>
</thead>
<tbody>
{section name=dataDetail loop=$dataDetail}

259
<tr>
<td>{$dataDetail[dataDetail].no}</td>
<td>{$dataDetail[dataDetail].productName}</td>
<td style="text-align: right;">{$dataDetail[dataDetail]
.price}</td>
<td style="text-align: center;">{$dataDetail[dataDetail].qty}</td>
<td style="text-align: right;">{$dataDetail[dataDetail]
.subtotal}</td>
<td>{$dataDetail[dataDetail].note}</td>
</tr>
{/section}
<tr>
<td colspan="4"></td>
<td style="text-align: right;">{$grandtotal}</td>
<td></td>
</tr>
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{elseif $module == 'so' && $act == 'search'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="so.php">
<input type="hidden" name="module" value="so">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" id="endDate" name="endDate"
value="{$endDate}" class="form-control" placeholder="Periode
Akhir" style="float: right; width: 115px;">
<input type="text" id="startDate" name="startDate"
value="{$startDate}" class="form-control" placeholder="Periode
Awal" style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor SO" style="float: right;
width: 270px;">
<a href="so.php?module=so&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_so.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>

260
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO SO <i class="fa fa-sort"></i></th>
<th>TGL SO <i class="fa fa-sort"></i></th>
<th>TGL DIBUTUHKAN <i class="fa fa-sort"></i></th>
<th>SUPPLIER <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSo loop=$dataSo}
<tr>
<td>{$dataSo[dataSo].no}</td>
<td>{$dataSo[dataSo].soNo}</td>
<td>{$dataSo[dataSo].orderDate}</td>
<td>{$dataSo[dataSo].needDate}</td>
<td>{$dataSo[dataSo].customerName}</td>
<td>{$dataSo[dataSo].status}</td>
<td>{$dataSo[dataSo].staffName}</td>
<td>
<a title="Detail" href="so.php?module=so&act=detailso&soID=
{$dataSo[dataSo].soID}&soFaktur={$dataSo[dataSo].soFaktur}&q={$q}&
page={$page}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="so.php?module=so&act=delete&soID=
{$dataSo[dataSo].soID}&soFaktur={$dataSo[dataSo].soFaktur}&soNo={$
dataSo[dataSo].soNo}" onclick="return confirm('Anda Yakin ingin
menghapus transaksi {$dataSo[dataSo].soNo}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="so.php">
<input type="hidden" name="module" value="so">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-right"><i
class="fa fa-search"></i> Search</button>
<input type="text" id="endDate" name="endDate" value="{$endDate}"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" id="startDate" name="startDate"
value="{$startDate}" class="form-control" placeholder="Periode
Awal" style="float: right; width: 115px;">

261
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor SO" style="float: right;
width: 270px;">
<a href="so.php?module=so&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_so.php?act=print&q={$q}" style="float: left;"
target="_blank"><button type="button" class="btn btn-default pull-
right"><i class="fa fa-print"></i> Print PDF</button></a>
&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO SO <i class="fa fa-sort"></i></th>
<th>TGL SO <i class="fa fa-sort"></i></th>
<th>TGL DIBUTUHKAN <i class="fa fa-sort"></i></th>
<th>CUSTOMER <i class="fa fa-sort"></i></th>
<th>STATUS <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataSo loop=$dataSo}
<tr>
<td>{$dataSo[dataSo].no}</td>
<td>{$dataSo[dataSo].soNo}</td>
<td>{$dataSo[dataSo].orderDate}</td>
<td>{$dataSo[dataSo].needDate}</td>
<td>{$dataSo[dataSo].customerName}</td>
<td>{$dataSo[dataSo].status}</td>
<td>{$dataSo[dataSo].staffName}</td>
<td>
<a title="Detail" href="so.php?module=so&act=detailso&soID=
{$dataSo[dataSo].soID}&soFaktur={$dataSo[dataSo].soFaktur}&page={$
page}"><img src="img/icons/view.png" width="18"></a>
<a title="Delete" href="so.php?module=so&act=delete&soID=
{$dataSo[dataSo].soID}&soFaktur={$dataSo[dataSo].soFaktur}&soNo={$
dataSo[dataSo].soNo}" onclick="return confirm('Anda Yakin ingin
menghapus transaksi {$dataSo[dataSo].soNo}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

262
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil skrip diatas akan menghasilkan halaman sales oder yang bisa dilihat pada
gambar-gambar berikut :

Gambar 5.30. Sales order

263
Gambar 5.31. Tambah item sales order

Gambar 5.32. Cetak sales order

5.3.2 Delivery Order

264
Setelah kita menerima sales order, kemudian kita siapkan barang sesuai dengan
apa yang dipesan maka selanjutnya kita akan mengirimkan barang tersebut ke
customer, nah dibutuhkan surat delivery order atau istilah kerennya adalah surat
jalan. Halaman ini digunakan untuk membuat delivery order.
Buat beberapa file dengan masing-masing skrip berikut :
do.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "do.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE modulID =
'29'";
$sqlAuthorizeStaff = mysqli_query($connect, $queryAuthorizeStaff);
$dataAuthorizeStaff = mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'], $_SESSION['level'])
=== FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is do and action is delete


if ($module == 'do' && $act == 'delete')
{
// insert method into a variable
$doID = $_GET['doID'];
$doNo = $_GET['doNo'];
$doFaktur = $_GET['doFaktur'];

$queryDo = "SELECT * FROM as_detail_do WHERE doNo =


'$doNo' AND doFaktur = '$doFaktur'";
$sqlDo = mysqli_query($connect, $queryDo);

// fetch data
while ($dataDo = mysqli_fetch_array($sqlDo))
{

265
$querySP = "UPDATE as_stock_products SET
stock=stock+$dataDo[deliveredQty] WHERE productID =
'$dataDo[productID]' AND factoryID = '$dataDo[factoryID]'";
mysqli_query($connect, $querySP);
}

// delete do
$queryDo2 = "DELETE FROM as_delivery_order WHERE doID =
'$doID' AND doNo = '$doNo' AND doFaktur = '$doFaktur'";
$sqlDo2 = mysqli_query($connect, $queryDo2);

// delete delivery order detail


$queryDoDetail = "DELETE FROM as_detail_do WHERE doNo =
'$doNo' AND doFaktur = '$doFaktur'";
$sqlDoDetail = mysqli_query($connect, $queryDoDetail);

// redirect to the delivery order page


header("Location: do.php");
} // close bracket

// if the module is do and act is input


elseif ($module == 'do' && $act == 'input')
{
$doFaktur = $_SESSION['doFaktur'];
$modifiedDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$doNo = $_POST['doNo'];
$doID = $_POST['doID'];
$soNo = $_POST['soNo'];
$customerID = $_POST['customerID'];
$customerName = $_POST['customerName'];
$customerAddress = mysqli_real_escape_string($connect,
$_POST['customerAddress']);
$dDate = explode("-", $_POST['deliveredDate']);
$deliveredDate = $dDate[2]."-".$dDate[1]."-".$dDate[0];
$oDate = explode("-", $_POST['orderDate']);
$orderDate = $oDate[2]."-".$oDate[1]."-".$oDate[0];
$nDate = explode("-", $_POST['needDate']);
$needDate = $nDate[2]."-".$nDate[1]."-".$nDate[0];
$note = mysqli_real_escape_string($connect, $_POST['note']);
$detailID = $_POST['detailID'];
$countDetailID = COUNT($detailID);
$productID = $_POST['productID'];
$productName = $_POST['productName'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$deliveredQty = $_POST['deliveredQty'];
$status = $_POST['status'];
$factory = $_POST['factory'];
$notedetail = $_POST['notedetail'];

$dataSo = mysqli_fetch_array(mysqli_query($connect,
"SELECT soID FROM as_sales_order WHERE soNo = '$soNo'"));

for ($i = 0; $i < $countDetailID; $i++)


{

266
$f = explode("#", $factory[$i]);
$factoryID = $f[0];
$factoryName = $f[1]." ".$f[2];
$productNm = mysqli_real_escape_string($connect,
$productName[$i]);
$notedet = mysqli_real_escape_string($connect, $notedetail[$i]);
$total = $price[$i] * $deliveredQty[$i];

if ($status[$i] == 'Y')
{
$queryInsert = "INSERT INTO as_detail_do ( doNo,
doFaktur,
productID,
productName,
price,
qty,
deliveredQty,
deliveredStatus,
factoryID,
factoryName,
note,
createdDate,
createdUserID)
VALUES( '$doNo',
'$doFaktur',
'$productID[$i]',
'$productNm',
'$price[$i]',
'$qty[$i]',
'$deliveredQty[$i]',
'$status[$i]',
'$factoryID',
'$factoryName',
'$notedet',
'$modifiedDate',
'$staffID')";
mysqli_query($connect, $queryInsert);

$queryStock = "UPDATE as_stock_products SET stock=stock-


$deliveredQty[$i] WHERE factoryID = '$factoryID' AND productID =
'$productID[$i]'";
mysqli_query($connect, $queryStock);

$grandtotal += $total;
}
}

// update delivery order


$queryDo = "UPDATE as_delivery_order SET soID =
'$dataSo[soID]',
soNo = '$soNo',
customerID = '$customerID',
customerName = '$customerName',
customerAddress = '$customerAddress',
staffID = '$staffID',
staffName = '$sName',
deliveredDate = '$deliveredDate',

267
orderDate = '$orderDate',
needDate = '$needDate',
total = '$grandtotal',
note = '$note',
modifiedDate = '$modifiedDate',
modifiedUserID = '$staffID'
WHERE doID = '$doID' AND doFaktur = '$doFaktur'";
$sqlDo = mysqli_query($connect, $queryDo);

$_SESSION['doFaktur'] = "";

header("Location:
do.php?module=do&act=finish&doNo=".$doNo."&doFaktur=".$doFaktur);
}

// if the module is do and act is detaildo


elseif ($module == 'do' && $act == 'detaildo')
{
$doID = $_GET['doID'];
$doFaktur = $_GET['doFaktur'];
$doNo = $_GET['doNo'];
$q = mysqli_real_escape_string($connect, $_GET['q']);

$queryDo = "SELECT * FROM as_delivery_order WHERE doID =


'$doID' AND doNo = '$doNo' AND doFaktur = '$doFaktur'";
$sqlDo = mysqli_query($connect, $queryDo);
$dataDo = mysqli_fetch_array($sqlDo);

// assign to the tpl


$smarty->assign("doFaktur", $dataDo['doFaktur']);
$smarty->assign("doID", $dataDo['doID']);
$smarty->assign("doNo", $dataDo['doNo']);
$smarty->assign("soID", $dataDo['soID']);
$smarty->assign("soNo", $dataDo['soNo']);
$smarty->assign("customerID", $dataDo['customerID']);
$smarty->assign("customerName", $dataDo['customerName']);
$smarty->assign("customerAddress", $dataDo['customerAddress']);
$smarty->assign("staffID", $dataDo['staffID']);
$smarty->assign("staffName", $dataDo['staffName']);
$smarty->assign("deliveredDate",
tgl_indo2($dataDo['deliveredDate']));
$smarty->assign("orderDate", tgl_indo2($dataDo['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataDo['needDate']));
$smarty->assign("note", $dataDo['note']);

// show the delivered order detail


$queryDoDetail = "SELECT * FROM as_detail_do WHERE doNo =
'$doNo' AND doFaktur = '$doFaktur' ORDER BY detailID ASC";
$sqlDoDetail = mysqli_query($connect, $queryDoDetail);

$i = 1;
while ($dtDoDetail = mysqli_fetch_array($sqlDoDetail))
{
$dataDoDetail[] = array( 'detailID' =>
$dtDoDetail['detailID'],
'doNo' => $dtDoDetail['doNo'],
'doFaktur' => $dtDoDetail['doFaktur'],

268
'productID' => $dtDoDetail['productID'],
'productName' => $dtDoDetail['productName'],
'price' => $dtDoDetail['price'],
'qty' => $dtDoDetail['qty'],
'deliveredQty' => $dtDoDetail['deliveredQty'],
'status' => $dtDoDetail['deliveredStatus'],
'factoryID' => $dtDoDetail['factoryID'],
'factoryName' => $dtDoDetail['factoryName'],
'note' => $dtDoDetail['note'],
'no' => $i
);
$i++;
}

$smarty->assign("dataDoDetail", $dataDoDetail);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $_GET['q']);

$smarty->assign("breadcumbTitle", "Delivery Order");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi delivery order.");
$smarty->assign("breadcumbMenuName", "Delivery Order");
$smarty->assign("breadcumbMenuSubName", "Delivery Order");
}

// if the module do and act is cancel


elseif ($module == 'do' && $act == 'cancel')
{
$doFaktur = $_SESSION['doFaktur'];

// delete delivery order


$queryDo = "DELETE FROM as_delivery_order WHERE doFaktur =
'$doFaktur'";
$sqlDo = mysqli_query($connect, $queryDo);

$_SESSION['doFaktur'] = "";

header("Location: do.php");
}

// if module do and act is finish


elseif ($module == 'do' && $act == 'finish')
{
$doNo = $_GET['doNo'];
$doFaktur = $_GET['doFaktur'];

$queryDo = "SELECT * FROM as_delivery_order WHERE doNo =


'$doNo' AND doFaktur = '$doFaktur'";
$sqlDo = mysqli_query($connect, $queryDo);
$dataDo = mysqli_fetch_array($sqlDo);

$smarty->assign("doID", $dataDo['doID']);
$smarty->assign("doNo", $dataDo['doNo']);
$smarty->assign("doFaktur", $dataDo['doFaktur']);
$smarty->assign("soID", $dataDo['soID']);
$smarty->assign("soNo", $dataDo['soNo']);
$smarty->assign("customerID", $dataDo['customerID']);

269
$smarty->assign("customerName", $dataDo['customerName']);
$smarty->assign("staffID", $dataDo['staffID']);
$smarty->assign("staffName", $dataDo['staffName']);
$smarty->assign("deliveredDate",
tgl_indo2($dataDo['deliveredDate']));
$smarty->assign("orderDate", tgl_indo2($dataDo['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataDo['needDate']));
$smarty->assign("note", $dataDo['note']);

// show the do detail


$queryDoDetail = "SELECT * FROM as_detail_do WHERE doNo =
'$doNo' AND doFaktur = '$doFaktur'";
$sqlDoDetail = mysqli_query($connect, $queryDoDetail);

// fetch data
$k = 1;
while ($dtDoDetail = mysqli_fetch_array($sqlDoDetail))
{
if ($dtDoDetail['deliveredStatus'] == 'Y')
{
$status = "Y";
}
else
{
$status = "N";
}

$dataDoDetail[] = array( 'detailID' =>


$dtDoDetail['detailID'],
'doNo' => $dtDoDetail['doNo'],
'doFaktur' => $dtDoDetail['doFaktur'],
'productName' => $dtDoDetail['productName'],
'price' => rupiah($dtDoDetail['price']),
'qty' => $dtDoDetail['qty'],
'deliveredQty' => $dtDoDetail['deliveredQty'],
'status' => $status,
'factoryName' => $dtDoDetail['factoryName'],
'note' => $dtDoDetail['note'],
'no' => $k
);
$k++;
}

$smarty->assign("dataDoDetail", $dataDoDetail);
$smarty->assign("breadcumbTitle", "Delivery Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk melakukan
transaksi delivery order.");
$smarty->assign("breadcumbMenuName", "Delivery Order");
$smarty->assign("breadcumbMenuSubName", "Delivery Order");
}

// if the module do and act is add


elseif ($module == 'do' && $act == 'add')
{
$doFaktur = $_SESSION['doFaktur'];

// get last sort bbm number ID

270
$queryNoDo = "SELECT doNo FROM as_delivery_order ORDER BY doNo
DESC LIMIT 1";
$sqlNoDo = mysqli_query($connect, $queryNoDo);
$numsNoDo = mysqli_num_rows($sqlNoDo);
$dataNoDo = mysqli_fetch_array($sqlNoDo);

$start = substr($dataNoDo['doNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoDo == '0')
{
$dNo = "00000";
}
elseif ($tempNo == 1)
{
$dNo = "00000";
}
elseif ($tempNo == 2)
{
$dNo = "0000";
}
elseif ($tempNo == 3)
{
$dNo = "000";
}
elseif ($tempNo == 4)
{
$dNo = "00";
}
elseif ($tempNo == 5)
{
$dNo = "0";
}
elseif ($tempNo == 6)
{
$dNo = "";
}

$doNo = "DO".$dNo.$next;

// count delivery order based on doNo


$showDo = "SELECT * FROM as_delivery_order WHERE doFaktur =
'$doFaktur'";
$sqlDo = mysqli_query($connect, $showDo);
$numsDo = mysqli_num_rows($sqlDo);

if ($numsDo == 0)
{
$deliveredDate = date('Y-m-d');
$sName = $_SESSION['staffCode']." ".$_SESSION['staffName'];
$queryDo = "INSERT INTO as_delivery_order ( doFaktur,
doNo,
soID,
soNo,
customerID,
customerName,

271
staffID,
staffName,
deliveredDate,
orderDate,
needDate,
total,
note,
createdDate,
createdUserID,
modifiedDate,
modifiedUserID)
VALUES( '$doFaktur',
'$doNo',
'',
'',
'',
'',
'$_SESSION[staffID]',
'$sName',
'$deliveredDate',
'',
'',
'',
'',
'$createdDate',
'$staffID',
'',
'')";
mysqli_query($connect, $queryDo);
}

// count delivery order based on doNo


$showDo = "SELECT * FROM as_delivery_order WHERE doFaktur =
'$doFaktur'";
$sqlDo = mysqli_query($connect, $showDo);
$dataDo = mysqli_fetch_array($sqlDo);

$smarty->assign("doNo", $dataDo['doNo']);
$smarty->assign("doID", $dataDo['doID']);

if ($dataDo['deliveredDate'] == '0000-00-00')
{
$deliveredDate = date('Y-m-d');
}
else
{
$deliveredDate = $dataDo['deliveredDate'];
}

$smarty->assign("deliveredDate", tgl_indo2($deliveredDate));
$smarty->assign("note", $dataDo['note']);

// show the sales order data based on soNo


$soNo = mysqli_real_escape_string($connect, $_GET['soNo']);
$querySo = "SELECT * FROM as_sales_order WHERE soNo = '$soNo'";
$sqlSo = mysqli_query($connect, $querySo);
$dataSo = mysqli_fetch_array($sqlSo);

272
$numsSo = mysqli_num_rows($sqlSo);

$smarty->assign("numsSo", $numsSo);

// show the delivery order data


$queryDo = "SELECT A.doID FROM as_delivery_order A INNER
JOIN as_detail_do B ON B.doNo=A.doNo WHERE A.soNo = '$soNo'";
$sqlDo = mysqli_query($connect, $queryDo);
$numsDo = mysqli_num_rows($sqlDo);

$smarty->assign("numsDo", $numsDo);

// assign to the do tpl


$smarty->assign("soNo", $soNo);
$smarty->assign("customerName", $dataSo['customerName']);
$smarty->assign("customerAddress", $dataSo['customerAddress']);
$smarty->assign("customerID", $dataSo['customerID']);
$smarty->assign("orderDate", tgl_indo2($dataSo['orderDate']));
$smarty->assign("needDate", tgl_indo2($dataSo['needDate']));

// show the so detail based on soNo


$i = 1;
$querySoDetail = "SELECT * FROM as_detail_so WHERE soNo =
'$soNo' AND soFaktur = '$dataSo[soFaktur]'";
$sqlSoDetail = mysqli_query($connect, $querySoDetail);
while ($dataSoDetail = mysqli_fetch_array($sqlSoDetail))
{
$subtotal = $dataSoDetail['qty'] * $dataSoDetail['price'];

// show the factories data


$queryFactory = "SELECT A.factoryID, A.factoryCode,
A.factoryName, B.stock FROM as_factories A LEFT JOIN
as_stock_products B ON A.factoryID=B.factoryID WHERE A.status =
'Y' AND B.productID = '$dataSoDetail[productID]' ORDER BY
A.factoryCode ASC";
$sqlFactory = mysqli_query($connect, $queryFactory);

$dataFactory = array();

while ($dtFactory = mysqli_fetch_array($sqlFactory))


{
$dataFactory[] = array('factoryID' => $dtFactory['factoryID'],
'factoryCode' => $dtFactory['factoryCode'],
'factoryName' => $dtFactory['factoryName'],
'stock' => $dtFactory['stock']);
}

$dataDetail[] = array( 'detailID' => $dataSoDetail['detailID'],


'soNo' => $dataSoDetail['spbNo'],
'soFaktur' => $dataSoDetail['spbFaktur'],
'productID' => $dataSoDetail['productID'],
'productName' => $dataSoDetail['productName'],
'price' => $dataSoDetail['price'],
'qty' => $dataSoDetail['qty'],
'subtotal' => $subtotal,
'note' => $dataSoDetail['note'],
'dataFactory' => $dataFactory,

273
'no' => $i
);
$i++;
}

// assign to the spb tpl


$smarty->assign("dataDetail", $dataDetail);

//$smarty->assign("dataFactory", $dataFactory);

$smarty->assign("breadcumbTitle", "Delivery Order");


$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi delivery order.");
$smarty->assign("breadcumbMenuName", "Delivery Order");
$smarty->assign("breadcumbMenuSubName", "Delivery Order");
}

elseif ($module == 'do' && $act == 'search')


{
$doFaktur = date('Ymdhis');
$_SESSION['doFaktur'] = $doFaktur;
$q = mysqli_real_escape_string($connect, $_GET['q']);
$sDate = mysqli_real_escape_string($connect, $_GET['startDate']);
$eDate = mysqli_real_escape_string($connect, $_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-".$e2Date[0];

// showing up the do data


if ($sDate != '' && $eDate != '')
{
$queryDo = "SELECT * FROM as_delivery_order WHERE doNo
LIKE '%$q%' AND deliveredDate BETWEEN '$startDate' AND '$endDate'
ORDER BY doID DESC";
}
else
{
$queryDo = "SELECT * FROM as_delivery_order WHERE doNo
LIKE '%$q%' ORDER BY doID DESC";
}

$sqlDo = mysqli_query($connect, $queryDo);

// fetch data
$i = 1 + $position;
while ($dtDo = mysqli_fetch_array($sqlDo))
{
$dataDo[] = array( 'doID' => $dtDo['doID'],
'doNo' => $dtDo['doNo'],
'doFaktur' => $dtDo['doFaktur'],
'soID' => $dtDo['soID'],

274
'soNo' => $dtDo['soNo'],
'customerID' => $dtDo['customerID'],
'customerName' => $dtDo['customerName'],
'staffID' => $dtDo['staffID'],
'staffName' => $dtDo['staffName'],
'deliveredDate' => tgl_indo2($dtDo['deliveredDate']),
'note' => $dtDo['note'],
'no' => $i);
$i++;
}

$smarty->assign("dataDo", $dataDo);

$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Delivery Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi delivery order.");
$smarty->assign("breadcumbMenuName", "Delivery Order");
$smarty->assign("breadcumbMenuSubName", "Delivery Order");
}

else
{
$doFaktur = date('Ymdhis');
$_SESSION['doFaktur'] = $doFaktur;

// create new object pagination


$p = new PaginationDo;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the do data


$queryDo = "SELECT * FROM as_delivery_order ORDER BY doID
DESC LIMIT $position,$limit";
$sqlDo = mysqli_query($connect, $queryDo);

// fetch data
$i = 1 + $position;
while ($dtDo = mysqli_fetch_array($sqlDo))
{
$dataDo[] = array( 'doID' => $dtDo['doID'],
'doNo' => $dtDo['doNo'],
'doFaktur' => $dtDo['doFaktur'],
'soID' => $dtDo['soID'],
'soNo' => $dtDo['soNo'],
'customerID' => $dtDo['customerID'],
'customerName' => $dtDo['customerName'],
'staffID' => $dtDo['staffID'],
'staffName' => $dtDo['staffName'],
'deliveredDate' => tgl_indo2($dtDo['deliveredDate']),
'note' => $dtDo['note'],
'no' => $i);
$i++;

275
}

$smarty->assign("dataDo", $dataDo);

// count data
$queryCountDo = "SELECT * FROM as_delivery_order";
$sqlCountDo = mysqli_query($connect, $queryCountDo);
$amountData = mysqli_num_rows($sqlCountDo);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'], $amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Delivery Order");
$smarty->assign("breadcumbTitleSmall", "Halaman untuk
melakukan transaksi delivery order.");
$smarty->assign("breadcumbMenuName", "Delivery Order");
$smarty->assign("breadcumbMenuSubName", "Delivery Order");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

do.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>
<script type='text/javascript'
src="design/js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}
<script>
$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,

276
scrolling: 'no',
afterLoad: function(){
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#deliveredDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#deliveredDate').change(function () {
var doNo = $("#doNo").val();
var doID = $("#doID").val();
var soNo = $("#soNo").val();
var deliveredDate = $("#deliveredDate").val();

$.ajax({
type: 'POST',
url: 'save_do_delivereddate.php',
dataType: 'JSON',
data:{
doNo: doNo,
doID: doID,
deliveredDate: deliveredDate
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "do.php?module=do&act=add&soNo=" + soNo;
}
});
});

$('#note').change(function () {
var doNo = $("#doNo").val();
var doID = $("#doID").val();
var soNo = $("#soNo").val();

277
var note = $("#note").val();

$.ajax({
type: 'POST',
url: 'save_do_note.php',
dataType: 'JSON',
data:{
doNo: doNo,
doID: doID,
soNo: soNo,
note: note
},
success: function(data) {
setTimeout("$.fancybox.close()", 1000);
window.location.href = "do.php?module=do&act=add&soNo=" + soNo;
}
});
});

$('#soNo').change(function () {
var soNo = $("#soNo").val();

window.location.href = "do.php?module=do&act=add&soNo=" + soNo;


});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#do").submit(function() { return false; });


$("#do2").submit(function() { return false; });

$("#send2").on("click", function(){
var doNo = $("#doNo").val();
var productID = $("#productID").val();
var productName1 = $("#productName1").val();
var qty = parseInt($("#qty").val());
var price = parseInt($("#price").val());
var desc = $("#desc").val();

if (qty != '' && soNo != '' && productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_so.php',
dataType: 'JSON',
data:{
qty: qty,
price: price,
soNo: soNo,
productID: productID,
productName1: productName1,
desc: desc
},
beforeSend: function (data) {
$('#send2').hide();
},
success: function(data) {

278
setTimeout("$.fancybox.close()", 1000);
window.location.href = "so.php?module=so&act=add";
}
});
}
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<aside class="left-side sidebar-offcanvas">
<section class="sidebar">

{include file="user_panel.tpl"}
{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">

<!-- TO DO List -->


<div class="box box-primary">

{if $module == 'do' AND $act == 'add'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};

279
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Tambah Surat Jalan</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="do.php?module=do&act=cancel" onclick="return
confirm('Anda Yakin ingin membatalkan surat jalan ini?');"><button
class="btn btn-default pull-right">Batal Trx</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<form method="POST" action="do.php?module=do&act=input">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO DO / TGL</td>
<td width="5">:</td>
<td><input type="hidden" id="doNo" name="doNo" value="{$doNo}">
<input type="hidden" id="doID" name="doID" value="{$doID}">
<input type="text" id="doNo" name="doNo" value="{$doNo}"
class="form-control" placeholder="NO DO" style="width: 110px;
float: left" DISABLED>
<input type="text" id="deliveredDate" name="deliveredDate"
value="{$deliveredDate}" class="form-control" placeholder="Tanggal
DO" style="width: 160px;" required>
</td>
</tr>
<tr valign="top">
<td>NO SO</td>
<td>:</td>
<td><input type="text" id="soNo" name="soNo"
value="{$soNo}" class="form-control" placeholder="Nomor SO"
style="width: 270px;" required>
{if $numsSo == '0' AND $soNo != ''}
<font color="#f56954">Nomor SO tidak ditemukan.</font>
{/if}
{if $numsDo > 0 AND $soNo != ''}
<font color="#f56954">Nomor SO sudah digunakan.</font>
{/if}
</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td>{if $numsDo == '0' AND $soNo != ''}
<input type="hidden" id="customerID" name="customerID"
value="{$customerID}">
<input type="hidden" id="customerName" name="customerName"
value="{$customerName}">
<input type="hidden" id="customerAddress" name="customerAddress"
value="{$customerAddress}">

280
<input type="text" id="customerName" name="customerName"
value="{$customerName}" class="form-control"
placeholder="Customer" style="width: 270px;" DISABLED>
{else}
<input type="text" id="customerName" name="customerName"
class="form-control" placeholder="Customer" style="width: 270px;"
DISABLED>
{/if}
</td>
</tr>
<tr>
<td>TGL SO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="hidden" id="orderDate" name="orderDate"
value="{$orderDate}"><input type="hidden" id="needDate"
name="needDate" value="{$needDate}">
{if $numsDo == '0' AND $soNo != ''}
<input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
{else}
<input type="text" id="orderDate" name="orderDate" class="form-
control" placeholder="Tgl Order" style="float: left; width:
135px;" DISABLED><input type="text" id="orderDate" name="needDate"
class="form-control" placeholder="Tgl Dibutuhkan" style="width:
135px;" DISABLED></td>
{/if}
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td>{if $numsDo == '0' AND $soNo != ''}
<input type="text" value="{$note}" id="note" name="note"
class="form-control" placeholder="Note" style="width: 270px;">
{else}
<input type="text" id="note" name="note" class="form-control"
placeholder="Note" style="width: 270px;">
{/if}</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>NOTE</th>
<th>JML ORDER</th>

281
<th>JML DIKIRIM</th>
<th>KIRIM</th>
<th>DARI GUDANG</th>
</tr>
</thead>
<tbody>
{if $numsDo == '0' AND $soNo != ''}
{section name=dataDetail loop=$dataDetail}
<tr>
<td>{$dataDetail[dataDetail].no} <input type="hidden"
name="detailID[]" id="detailID"
value="{$dataDetail[dataDetail].detailID}"></td>
<td>{$dataDetail[dataDetail].productName} <input type="hidden"
name="productName[]" id="productName"
value="{$dataDetail[dataDetail].productName}"> <input
type="hidden" name="productID[]" id="productID"
value="{$dataDetail[dataDetail].productID}"></td>
<td>{$dataDetail[dataDetail].note} <input type="hidden"
name="notedetail[]" id="notedetail"
value="{$dataDetail[dataDetail].note}"></td>
<td style='text-align: center;'>{$dataDetail[dataDetail].qty}
<input type="hidden" name="qty[]" id="qty"
value="{$dataDetail[dataDetail].qty}"> <input type="hidden"
name="price[]" id="price"
value="{$dataDetail[dataDetail].price}"></td>
<td><input type="number" value="0" id="deliveredQty"
name="deliveredQty[]" class="form-control" placeholder="Jml"
style="width: 100px;" required></td>
<td>
<select id="status" name="status[]" class="form-control"
style="width: 100px;" required>
<option value=""></option>
<option value="Y">YA</option>
<option value="N">TIDAK</option>
</select>
</td>
<td>
<select id="factory" name="factory[]" class="form-control"
style="width: 180px;" required>
<option value=""></option>
{section name=dataFactory
loop=$dataDetail[dataDetail].dataFactory}
<option value="{$dataDetail[dataDetail].dataFactory[dataFactory]
.factoryID}#{$dataDetail[dataDetail].dataFactory[dataFactory].fact
oryCode}#{$dataDetail[dataDetail].dataFactory[dataFactory].factory
Name}">{$dataDetail[dataDetail].dataFactory[dataFactory].factoryCo
de} {$dataDetail[dataDetail].dataFactory[dataFactory].factoryName}
[Stok : {$dataDetail[dataDetail].dataFactory[dataFactory].stock}]
</option>
{/section}
</select>
</td>
</tr>
{/section}
{/if}
</tbody>
</table>

282
</div>
<br><br>
{if $numsSo > 0}
{if $numsDo > 0 AND $soNo != ''}
{else}
<button type="submit" class="btn btn-primary">Simpan</button>
{/if}
{/if}
</form>

</div><!-- /.box-body -->

{elseif $module == 'do' AND $act == 'finish'}


{literal}
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {


if (e.keyCode === 116) {
return false;
}
};
</script>
{/literal}

<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Delivery Order</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_do.php?module=do&act=print&doID={$doID}&doNo=
{$doNo}&doFaktur={$doFaktur}" target="_blank"><button class="btn
btn-default pull-right">Print</button></a>
<a href="do.php"><button class="btn btn-default pull-
right">Close</button></a>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO DO / TGL</td>
<td width="5">:</td>
<td><input type="text" id="doNo" name="doNo"
value="{$doNo}" class="form-control" placeholder="ID BBM"
style="width: 110px; float: left" DISABLED>
<input type="text" id="deliveredDate" name="deliveredDate"
value="{$deliveredDate}" class="form-control" placeholder="Tanggal
DO" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO SO</td>

283
<td>:</td>
<td><input type="text" id="soNo" name="soNo"
value="{$soNo}" class="form-control" placeholder="Nomor SO"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td><input type="text" id="customerName"
name="customerName" value="{$customerName}" class="form-control"
placeholder="Customer" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>TGL SO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td><input type="text" value="{$note}" id="note"
name="note" class="form-control" placeholder="Note" style="width:
270px;" DISABLED></td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>NOTE</th>
<th>JML ORDER</th>
<th>JML DIKIRIM</th>
<th>KIRIM</th>
<th>DARI GUDANG</th>
</tr>
</thead>
<tbody>
{section name=dataDoDetail loop=$dataDoDetail}
<tr>
<td>{$dataDoDetail[dataDoDetail].no}</td>
<td>{$dataDoDetail[dataDoDetail].productName}</td>
<td>{$dataDoDetail[dataDoDetail].note}</td>
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.qty}</td>

284
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.deliveredQty}</td>
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.status}</td>
<td>{$dataDoDetail[dataDoDetail].factoryName}</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

{elseif $module == 'do' AND $act == 'detaildo'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<h3 class="box-title">Surat Jalan</h3>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<a href="print_unit_do.php?module=do&act=print&doID={$doID}&doNo=
{$doNo}&doFaktur={$doFaktur}" target="_blank"><button class="btn
btn-default pull-right">Print</button></a>
{if $q != ''}
<a href="do.php?module=do&act=search&q={$q}&page={$page}"><button
class="btn btn-default pull-right">Back</button></a>
{else}
<a href="do.php?page={$page}"><button class="btn btn-default pull-
right">Back</button></a>
{/if}
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<table cellpadding="3" cellspacing="3">
<tr>
<td width="150">NO DO / TGL</td>
<td width="5">:</td>
<td><input type="text" id="doNo" name="doNo"
value="{$doNo}" class="form-control" placeholder="NO DO"
style="width: 110px; float: left" DISABLED>
<input type="text" id="deliveredDate" name="deliveredDate"
value="{$deliveredDate}" class="form-control" placeholder="Tanggal
DO" style="width: 160px;" DISABLED>
</td>
</tr>
<tr valign="top">
<td>NO SO</td>
<td>:</td>
<td><input type="text" id="soNo" name="soNo"
value="{$soNo}" class="form-control" placeholder="Nomor SO"
style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>

285
<td><input type="text" id="customerName"
name="customerName" value="{$customerName}" class="form-control"
placeholder="Customer" style="width: 270px;" DISABLED></td>
</tr>
<tr>
<td>TGL SO/DIBUTUHKAN</td>
<td>:</td>
<td><input type="text" id="orderDate" name="orderDate"
value="{$orderDate}" class="form-control" placeholder="Tgl Order"
style="float: left; width: 135px;" DISABLED><input type="text"
id="orderDate" name="needDate" value="{$needDate}" class="form-
control" placeholder="Tgl Dibutuhkan" style="width: 135px;"
DISABLED></td>
</tr>
<tr>
<td>NOTE</td>
<td>:</td>
<td><input type="text" value="{$note}" id="note"
name="note" class="form-control" placeholder="Note" style="width:
270px;" DISABLED></td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
</table>

<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO</th>
<th>NAMA PRODUK</th>
<th>NOTE</th>
<th>JML ORDER</th>
<th>JML DIKIRIM</th>
<th>TERIMA</th>
<th>GUDANG</th>
</tr>
</thead>
<tbody>
{section name=dataDoDetail loop=$dataBbmDetail}
<tr>
<td>{$dataDoDetail[dataDoDetail].no}</td>
<td>{$dataDoDetail[dataDoDetail].productName}</td>
<td>{$dataDoDetail[dataDoetail].note}</td>
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.qty}</td>
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.receiveQty}</td>
<td style='text-align: center;'>{$dataDoDetail[dataDoDetail]
.status}</td>
<td>{$dataDoDetail[dataDoDetail].factoryName}</td>
</tr>
{/section}
</tbody>

286
</table>
</div>

</div><!-- /.box-body -->

{elseif $module == 'do' AND $act == 'search'}


<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="do.php">
<input type="hidden" name="module" value="do">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-right"><i
class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor DO" style="float: right;
width: 270px;">
<a href="do.php?module=do&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_do.php?act=print&q={$q}&startDate={$startDate}&
endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>
</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>NO <i class="fa fa-sort"></i></th>
<th>NO DO <i class="fa fa-sort"></i></th>
<th>NO SO <i class="fa fa-sort"></i></th>
<th>CUSTOMER <i class="fa fa-sort"></i></th>
<th>TGL PENGIRIMAN <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataDo loop=$dataDo}
<tr>
<td>{$dataDo[dataDo].no}</td>
<td>{$dataDo[dataDo].doNo}</td>
<td>{$dataDo[dataDo].soNo}</td>
<td>{$dataDo[dataDo].customerName}</td>

287
<td>{$dataDo[dataDo].deliveredDate}</td>
<td>{$dataDo[dataDo].staffName}</td>
<td>
<a title="Detail" href="do.php?module=do&act=detaildo&doID=
{$dataDo[dataDo].doID}&doNo={$dataDo[dataDo].doNo}&doFaktur={$data
Do[dataDo].doFaktur}&q={$q}&page={$page}"><img
src="img/icons/view.png" width="18"></a>
<a title="Delete" href="do.php?module=do&act=delete&doID=
{$dataDo[dataDo].doID}&doFaktur={$dataDo[dataDo].doFaktur}&doNo={$
dataDo[dataDo].doNo}" onclick="return confirm('Anda Yakin ingin
membatalkan transaksi {$dataDo[dataDo].doNo}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->


{else}
<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-right">
<div class="box-footer clearfix no-border">
<form method="GET" action="do.php">
<input type="hidden" name="module" value="do">
<input type="hidden" name="act" value="search">
<button type="submit" class="btn btn-default pull-
right"><i class="fa fa-search"></i> Search</button>
<input type="text" value="{$endDate}" id="endDate" name="endDate"
class="form-control" placeholder="Periode Akhir" style="float:
right; width: 115px;">
<input type="text" value="{$startDate}" id="startDate"
name="startDate" class="form-control" placeholder="Periode Awal"
style="float: right; width: 115px;">
<input type="text" id="q" name="q" value="{$q}" class="form-
control" placeholder="Pencarian : Nomor DO" style="float: right;
width: 270px;" required>
<a href="do.php?module=do&act=add" style="float: left;"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
plus"></i> Add</button></a>
<a href="print_do.php?act=print&q={$q}&startDate={$startDate}
&endDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>&nbsp;&nbsp;&nbsp;
</form>

</div>
</div>
</div><!-- /.box-header -->

<div class="box-body">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>

288
<th>NO <i class="fa fa-sort"></i></th>
<th>NO DO <i class="fa fa-sort"></i></th>
<th>NO SO <i class="fa fa-sort"></i></th>
<th>CUSTOMER <i class="fa fa-sort"></i></th>
<th>TGL PENGIRIMAN <i class="fa fa-sort"></i></th>
<th>DIBUAT OLEH <i class="fa fa-sort"></i></th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
{section name=dataDo loop=$dataDo}
<tr>
<td>{$dataDo[dataDo].no}</td>
<td>{$dataDo[dataDo].doNo}</td>
<td>{$dataDo[dataDo].soNo}</td>
<td>{$dataDo[dataDo].customerName}</td>
<td>{$dataDo[dataDo].deliveredDate}</td>
<td>{$dataDo[dataDo].staffName}</td>
<td>
<a title="Detail" href="do.php?module=do&act=detaildo&bbmID=
{$dataDo[dataDo].doID}&doNo={$dataDo[dataDo].doNo}&doFaktur={$data
Do[dataDo].doFaktur}&page={$page}"><img src="img/icons/view.png"
width="18"></a>
<a title="Delete" href="do.php?module=do&act=delete&doID=
{$dataDo[dataDo].doID}&doFaktur={$dataDo[dataDo].doFaktur}&doNo={$
dataDo[dataDo].doNo}" onclick="return confirm('Anda Yakin ingin
membatalkan transaksi {$dataDo[dataDo].doNo}?');"><img
src="img/icons/delete.png" width="18"></a>
</td>
</tr>
{/section}
</tbody>
</table>
</div>

</div><!-- /.box-body -->

<div class="box-header">
<i class="ion ion-clipboard"></i>
<div class="box-tools pull-left">
<ul class="pagination pagination-sm inline">
{$pageLink}
</ul>
</div>
</div><!-- /.box-header -->
{/if}

</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

289
Hasil seluruh skrip diatas akan menghasilkan delivery order yang bisa dilihat
pada gambar-gambar berikut :

Gambar 5.33. Delivery order

Gambar 5.34. Cetak delivery order

5.3.3 Transaksi Penjualan


Transaksi Penjualan biasanya dilakukan bersamaan atau setelah delivery order,
digunakan mencatat transaksi final yang dilakukan customer.

290
Buat beberapa file dengan masing-masing skrip berikut :
out.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "out.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '9'";
$sqlAuthorizeStaff = mysqli_query($connect,
$queryAuthorizeStaff);
$dataAuthorizeStaff =
mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'],
$_SESSION['level']) === FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is out and action is delete


if ($module == 'out' && $act == 'delete')
{
// insert method into a variable
$inID = $_GET['invoiceID'];
$inNo = $_GET['invoiceNo'];

// delete invoice
$queryInvoice = "DELETE FROM as_sales_transactions
WHERE invoiceID = '$inID' AND invoiceNo = '$inNo'";
$sqlInvoice = mysqli_query($connect,
$queryInvoice);

// delete receive
$queryReceive = "DELETE FROM as_receivables WHERE
invoiceID = '$inID' AND invoiceNo = '$inNo'";
$sqlReceive = mysqli_query($connect,
$queryReceive);

// redirect to the in page

291
header("Location: out.php?msg=Data transaksi
penjualan berhasil dihapus");
} // close bracket

// if the module is out and action is cancel


elseif ($module == 'out' && $act == 'cancel')
{
$doNo = $_GET['doNo'];

$queryDo = "SELECT productID, detailID,


deliveredQty FROM as_detail_do WHERE doNo = '$doNo'";
$sqlDo = mysqli_query($connect, $queryDo);

while ($dataDo = mysqli_fetch_array($sqlDo))


{
$queryProduct = "SELECT hpp FROM
as_products WHERE productID = '$dataDo[productID]'";
$sqlProduct = mysqli_query($connect,
$queryProduct);
$dataProduct =
mysqli_fetch_array($sqlProduct);

$update = "UPDATE as_detail_do SET price =


'$dataProduct[hpp]' WHERE detailID = '$dataDo[detailID]' AND
productID = '$dataDo[productID]'";
mysqli_query($connect, $update);

$total = $dataProduct['hpp'] *
$dataDo['deliveredQty'];
$settotal += $total;
}

$queryUpdate = "UPDATE as_delivery_order SET total


= '$settotal' WHERE doNo = '$doNo'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);

// redirect to the out page


header("Location: out.php?msg=Transaksi penjualan
dibatalkan.");
}

// if the module is out and act is input


elseif ($module == 'out' && $act == 'input')
{
$createdDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']."
".$_SESSION['staffName'];
$invoiceNo = mysqli_real_escape_string($connect,
$_POST['invoiceNo']);
$iDate = explode("-", $_POST['invoiceDate']);
$invoiceDate = $iDate[2]."-".$iDate[1]."-
".$iDate[0];
$doNo = mysqli_real_escape_string($connect,
$_POST['doNo']);
$soNo = mysqli_real_escape_string($connect,
$_POST['soNo']);

292
$customerID = $_POST['customerID'];
$customerName = mysqli_real_escape_string($connect,
$_POST['customerName']);
$customerAddress =
mysqli_real_escape_string($connect, $_POST['customerAddress']);
$paymentType = $_POST['paymentType'];
$xDate = explode("-", $_POST['expiredDate']);
$expiredDate = $xDate[2]."-".$xDate[1]."-
".$xDate[0];
$ppnType = $_POST['ppnType'];
$ppn = $_POST['ppn'];
$total = $_POST['total'];
$basic = $_POST['basic'];
$grandtotal = $_POST['grandtotal'];
//$pay = $_POST['pay'];
//$debt = $_POST['debt'];
$discount = $_POST['discount'];

// get last sort receive


$queryNoReceive = "SELECT receiveNo FROM
as_receivables ORDER BY receiveNo DESC LIMIT 1";
$sqlNoReceive = mysqli_query($connect,
$queryNoReceive);
$numsNoReceive = mysqli_num_rows($sqlNoReceive);
$dataNoReceive = mysqli_fetch_array($sqlNoReceive);

$start = substr($dataNoReceive['receiveNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoReceive == '0')
{
$reNo = "00000";
}
elseif ($tempNo == 1)
{
$reNo = "00000";
}
elseif ($tempNo == 2)
{
$reNo = "0000";
}
elseif ($tempNo == 3)
{
$reNo = "000";
}
elseif ($tempNo == 4)
{
$reNo = "00";
}
elseif ($tempNo == 5)
{
$reNo = "0";
}
elseif ($tempNo == 6)
{
$reNo = "";

293
}

$receiveNo = "DB".$reNo.$next;

$querySales = "INSERT INTO as_sales_transactions (


invoiceNo,

invoiceDate,

doNo,

soNo,

paymentType,

expiredPayment,

ppnType,

ppn,

total,

basic,

discount,

grandtotal,

customerID,

customerName,

customerAddress,

staffID,

staffName,

createdDate,

createdUserID,

modifiedDate,

modifiedUserID)

VALUES( '$invoiceNo',

'$invoiceDate',

294
'$doNo',

'$soNo',

'$paymentType',

'$expiredDate',

'$ppnType',

'$ppn',

'$total',

'$basic',

'$discount',

'$grandtotal',

'$customerID',

'$customerName',

'$customerAddress',

'$staffID',

'$sName',

'$createdDate',

'$staffID',

'',

'')";

$sqlSales = mysqli_query($connect, $querySales);

$invoiceID = mysqli_insert_id($connect);

if ($sqlSales)
{
//if ($paymentType == '2')
//{
$queryReceive = "INSERT INTO
as_receivables(receiveNo,

295
invoiceID,

invoiceNo,

customerID,

customerName,

customerAddress,

receiveTotal,

incomingTotal,

status,

staffID,

staffName,

createdDate,

createdUserID,

modifiedDate,

modifiedUserID)

VALUES( '$receiveNo',

'$invoiceID',

'$invoiceNo',

'$customerID',

'$customerName',

'$customerAddress',

'$grandtotal',

'0',

296
'1',

'$staffID',

'$sName',

'$createdDate',

'$staffID',

'',

'')";

mysqli_query($connect,
$queryReceive);
//}
}

header("Location:
out.php?module=out&act=finish&doNo=".$doNo."&invoiceNo=".$invoiceN
o."&invoiceID=".$invoiceID);
}

// if the module is out and act is detailin


elseif ($module == 'out' && $act == 'detailout')
{
$doNo = $_GET['doNo'];
$q = mysqli_real_escape_string($connect,
$_GET['q']);
$invoiceID = $_GET['invoiceID'];
$invoiceNo = $_GET['invoiceNo'];

$querySales = "SELECT * FROM as_sales_transactions


WHERE doNo = '$doNo' AND invoiceID = '$invoiceID' AND invoiceNo =
'$invoiceNo'";
$sqlSales = mysqli_query($connect, $querySales);
$dataSales = mysqli_fetch_array($sqlSales);

if ($dataSales['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment =
tgl_indo2($dataSales['expiredPayment']);
}

if ($dataSales['ppnType'] == '1')
{
$ppnType = "PPN";

297
$ppn = rupiah($dataSales['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = rupiah(0);
}

// assign to the tpl


$smarty->assign("invoiceID",
$dataSales['invoiceID']);
$smarty->assign("invoiceNo",
$dataSales['invoiceNo']);
$smarty->assign("invoiceDate",
tgl_indo2($dataSales['invoiceDate']));
$smarty->assign("doNo", $dataSales['doNo']);
$smarty->assign("soNo", $dataSales['soNo']);
$smarty->assign("paymentType", $paymentType);
$smarty->assign("expiredPayment", $expiredPayment);
$smarty->assign("ppnType", $ppnType);
$smarty->assign("ppn", $ppn);
$smarty->assign("discount",
rupiah($dataSales['discount']));
$smarty->assign("basic",
rupiah($dataSales['basic']));
$smarty->assign("total",
rupiah($dataSales['total']));
$smarty->assign("grandtotal",
rupiah($dataSales['grandtotal']));
$smarty->assign("pay", rupiah($dataSales['pay']));
$smarty->assign("customerID",
$dataSales['customerID']);
$smarty->assign("customerName",
$dataSales['customerName']);
$smarty->assign("customerAddress",
$dataSales['customerAddress']);
$smarty->assign("staffID", $dataSales['staffID']);
$smarty->assign("staffName",
$dataSales['staffName']);

// show receivable
$queryReceive = "SELECT receiveTotal FROM
as_receivables WHERE invoiceNo = '$_GET[invoiceNo]' AND invoiceID
= '$_GET[invoiceID]'";
$sqlReceive = mysqli_query($connect,
$queryReceive);
$dataReceive = mysqli_fetch_array($sqlReceive);

$smarty->assign("receive",
rupiah($dataReceive['receiveTotal']));

// show the do detail


$queryDoDetail = "SELECT * FROM as_detail_do WHERE
doNo = '$dataSales[doNo]' ORDER BY doID ASC";
$sqlDoDetail = mysqli_query($connect,
$queryDoDetail);

298
$i = 1;
while ($dtDoDetail =
mysqli_fetch_array($sqlDoDetail))
{
$subtotal =
rupiah($dtDoDetail['deliveredQty'] * $dtDoDetail['price']);

$dataDoDetail[] = array( 'detailID'


=> $dtDoDetail['doID'],

'doNo' => $dtDoDetail['doNo'],

'doFaktur' => $dtDoDetail['doFaktur'],

'productID' => $dtDoDetail['productID'],

'productName' => $dtDoDetail['productName'],

'pricerp' => rupiah($dtDoDetail['price']),

'qty' => $dtDoDetail['qty'],

'deliveredQty' => $dtDoDetail['deliveredQty'],

'subtotal' => $subtotal,

'no' => $i

);
$i++;
}

$smarty->assign("dataDoDetail", $dataDoDetail);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

// if module out and act is finish


elseif ($module == 'out' && $act == 'finish')
{
$doNo = $_GET['doNo'];
$invoiceID = $_GET['invoiceID'];
$invoiceNo = $_GET['invoiceNo'];

$querySales = "SELECT * FROM as_sales_transactions


WHERE doNo = '$doNo' AND invoiceID = '$invoiceID' AND invoiceNo =
'$invoiceNo'";
$sqlSales = mysqli_query($connect, $querySales);

299
$dataSales = mysqli_fetch_array($sqlSales);

if ($dataSales['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment =
tgl_indo2($dataSales['expiredPayment']);
}

if ($dataSales['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dataSales['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = rupiah(0);
}

// assign to the tpl


$smarty->assign("invoiceID",
$dataSales['invoiceID']);
$smarty->assign("invoiceNo",
$dataSales['invoiceNo']);
$smarty->assign("invoiceDate",
tgl_indo2($dataSales['invoiceDate']));
$smarty->assign("doNo", $dataSales['doNo']);
$smarty->assign("soNo", $dataSales['soNo']);
$smarty->assign("paymentType", $paymentType);
$smarty->assign("expiredPayment", $expiredPayment);
$smarty->assign("ppnType", $ppnType);
$smarty->assign("ppn", $ppn);
$smarty->assign("discount",
rupiah($dataSales['discount']));
$smarty->assign("basic",
rupiah($dataSales['basic']));
$smarty->assign("total",
rupiah($dataSales['total']));
$smarty->assign("grandtotal",
rupiah($dataSales['grandtotal']));
$smarty->assign("pay", rupiah($dataSales['pay']));
$smarty->assign("customerID",
$dataSales['customerID']);
$smarty->assign("customerName",
$dataSales['customerName']);
$smarty->assign("customerAddress",
$dataSales['customerAddress']);
$smarty->assign("staffID", $dataSales['staffID']);
$smarty->assign("staffName",
$dataSales['staffName']);

300
// show receive
$queryReceive = "SELECT receiveTotal FROM
as_receivables WHERE invoiceNo = '$_GET[invoiceNo]' AND invoiceID
= '$_GET[invoiceID]'";
$sqlReceive = mysqli_query($connect,
$queryReceive);
$dataReceive = mysqli_fetch_array($sqlReceive);

$smarty->assign("receive",
rupiah($dataReceive['receiveTotal']));

// show the do detail


$queryDoDetail = "SELECT * FROM as_detail_do WHERE
doNo = '$dataSales[doNo]' ORDER BY doID ASC";
$sqlDoDetail = mysqli_query($connect,
$queryDoDetail);

$i = 1;
while ($dtDoDetail =
mysqli_fetch_array($sqlDoDetail))
{
$subtotal =
rupiah($dtDoDetail['deliveredQty'] * $dtDoDetail['price']);

$dataDoDetail[] = array( 'detailID'


=> $dtDoDetail['doID'],

'doNo' => $dtDoDetail['doNo'],

'doFaktur' => $dtDoDetail['doFaktur'],

'productID' => $dtDoDetail['productID'],

'productName' => $dtDoDetail['productName'],

'pricerp' => rupiah($dtDoDetail['price']),

'qty' => $dtDoDetail['qty'],

'deliveredQty' => $dtDoDetail['deliveredQty'],

'subtotal' => $subtotal,

'no' => $i

);
$i++;
}

$smarty->assign("dataDoDetail", $dataDoDetail);
$smarty->assign("page", $_GET['page']);

$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");

301
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

// if the module out and act is add


elseif ($module == 'out' && $act == 'add')
{
// get last sort out number ID
$queryNoOut = "SELECT invoiceNo FROM
as_sales_transactions ORDER BY invoiceNo DESC LIMIT 1";
$sqlNoOut = mysqli_query($connect, $queryNoOut);
$numsNoOut = mysqli_num_rows($sqlNoOut);
$dataNoOut = mysqli_fetch_array($sqlNoOut);

$start = substr($dataNoOut['invoiceNo'],2-7);
$next = $start + 1;
$tempNo = strlen($next);

if ($numsNoOut == '0')
{
$outNo = "00000";
}
elseif ($tempNo == 1)
{
$outNo = "00000";
}
elseif ($tempNo == 2)
{
$outNo = "0000";
}
elseif ($tempNo == 3)
{
$outNo = "000";
}
elseif ($tempNo == 4)
{
$outNo = "00";
}
elseif ($tempNo == 5)
{
$outNo = "0";
}
elseif ($tempNo == 6)
{
$outNo = "";
}

$invoiceNo = "TJ".$outNo.$next;

$smarty->assign("invoiceNo", $invoiceNo);
$smarty->assign("invoiceDate", tgl_indo2(date('Y-m-
d')));

$doNo = $_GET['doNo'];

302
// show the bbm
$queryDo = "SELECT * FROM as_delivery_order WHERE
doNo = '$doNo'";
$sqlDo = mysqli_query($connect, $queryDo);
$dataDo = mysqli_fetch_array($sqlDo);
$numsDo = mysqli_num_rows($sqlDo);

$smarty->assign("numsDo", $numsDo);

// show the do data


$querySSales = "SELECT invoiceID FROM
as_sales_transactions WHERE doNo = '$doNo'";
$sqlSSales = mysqli_query($connect, $querySSales);
$numsSSales = mysqli_num_rows($sqlSSales);

$smarty->assign("numsSSales", $numsSSales);

// assign to the tpl


$smarty->assign("doID", $dataDo['doID']);
$smarty->assign("doNo", $_GET['doNo']);
$smarty->assign("soID", $dataDo['soID']);
$smarty->assign("soNo", $dataDo['soNo']);
$smarty->assign("customerID",
$dataDo['customerID']);
$smarty->assign("customerName",
$dataDo['customerName']);
$smarty->assign("customerAddress",
$dataDo['customerAddress']);
$smarty->assign("staffID", $dataDo['staffID']);
$smarty->assign("staffName", $dataDo['staffName']);
$smarty->assign("deliveredDate",
tgl_indo2($dataDo['deliveredDate']));
$smarty->assign("orderDate",
tgl_indo2($dataDo['orderDate']));
$smarty->assign("needDate",
tgl_indo2($dataDo['needDate']));
$smarty->assign("total",
number_format($dataDo['total'], 2, '.', ''));
$smarty->assign("totalrp",
rupiah($dataDo['total']));
$smarty->assign("note", $dataDo['note']);

// show up the do detail


// show the do detail
$queryDoDetail = "SELECT * FROM as_detail_do WHERE
doNo = '$dataDo[doNo]' AND doFaktur = '$dataDo[doFaktur]' ORDER BY
doID ASC";
$sqlDoDetail = mysqli_query($connect,
$queryDoDetail);

$i = 1;
while ($dtDoDetail =
mysqli_fetch_array($sqlDoDetail))
{
$subtotal = $dtDoDetail['deliveredQty'] *
$dtDoDetail['price'];

303
$dataDoDetail[] = array( 'detailID'
=> $dtDoDetail['doID'],

'doNo' => $dtDoDetail['doNo'],

'doFaktur' => $dtDoDetail['doFaktur'],

'productID' => $dtDoDetail['productID'],

'productName' => $dtDoDetail['productName'],

'price' => $dtDoDetail['price'],

'pricerp' => rupiah($dtDoDetail['price']),

'qty' => $dtDoDetail['qty'],

'deliveredQty' => $dtDoDetail['deliveredQty'],

'status' => $dtDoDetail['deliveredStatus'],

'factoryID' => $dtDoDetail['factoryID'],

'factoryName' => $dtDoDetail['factoryName'],

'subtotal' => rupiah($subtotal),

'note' => $dtDoDetail['note'],

'no' => $i

);
$i++;
}

$smarty->assign("dataDoDetail", $dataDoDetail);

$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

elseif ($module == 'out' && $act == 'search')


{
$q = mysqli_real_escape_string($connect,
$_GET['q']);
$sDate = mysqli_real_escape_string($connect,
$_GET['startDate']);
$eDate = mysqli_real_escape_string($connect,
$_GET['endDate']);

$smarty->assign("startDate", $sDate);

304
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-
".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-
".$e2Date[0];

// showing up the sales data


if ($sDate != '' && $eDate != '')
{
$querySales = "SELECT * FROM
as_sales_transactions WHERE invoiceNo LIKE '%$q%' AND invoiceDate
BETWEEN '$startDate' AND '$endDate' ORDER BY invoiceNo DESC";
}
else
{
$querySales = "SELECT * FROM
as_sales_transactions WHERE invoiceNo LIKE '%$q%' ORDER BY
invoiceNo DESC";
}

$sqlSales = mysqli_query($connect, $querySales);

// fetch data
$i = 1 + $position;
while ($dtSales = mysqli_fetch_array($sqlSales))
{
if ($dtSales['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment =
tgl_indo2($dtSales['expiredPayment']);
}

if ($dtSales['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dtSales['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = "";
}

$dataSales[] = array( 'invoiceID' =>


$dtSales['invoiceID'],

'invoiceNo' => $dtSales['invoiceNo'],

305
'invoiceDate' => tgl_indo2($dtSales['invoiceDate']),

'doNo' => $dtSales['doNo'],

'soNo' => $dtSales['soNo'],

'paymentType' => $paymentType,

'expiredPayment' => $expiredPayment,

'ppnType' => $ppnType,

'ppn' => $ppn,

'total' => rupiah($dtSales['total']),

'grandtotal' => rupiah($dtSales['grandtotal']),

'pay' => rupiah($dtSales['pay']),

'staffID' => $dtSales['staffID'],

'staffName' => $dtSales['staffName'],

'no' => $i);


$i++;
}

$smarty->assign("dataSales", $dataSales);
$smarty->assign("page", $_GET['page']);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

else
{
// create new object pagination
$p = new PaginationOut;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the sales data


$querySales = "SELECT * FROM as_sales_transactions
ORDER BY invoiceID DESC LIMIT $position,$limit";
$sqlSales = mysqli_query($connect, $querySales);

306
// fetch data
$i = 1 + $position;
while ($dtSales = mysqli_fetch_array($sqlSales))
{
if ($dtSales['paymentType'] == '1')
{
$paymentType = "TUNAI";
$expiredPayment = "";
}
else
{
$paymentType = "TERMIN";
$expiredPayment =
tgl_indo2($dtSales['expiredPayment']);
}

if ($dtSales['ppnType'] == '1')
{
$ppnType = "PPN";
$ppn = rupiah($dtSales['ppn']);
}
else
{
$ppnType = "NO PPN";
$ppn = "";
}

$dataSales[] = array( 'invoiceID' =>


$dtSales['invoiceID'],

'invoiceNo' => $dtSales['invoiceNo'],

'invoiceDate' => tgl_indo2($dtSales['invoiceDate']),

'doNo' => $dtSales['doNo'],

'soNo' => $dtSales['soNo'],

'paymentType' => $paymentType,

'expiredPayment' => $expiredPayment,

'ppnType' => $ppnType,

'ppn' => $ppn,

'total' => rupiah($dtSales['total']),

'grandtotal' => rupiah($dtSales['grandtotal']),

'pay' => rupiah($dtSales['pay']),

'staffID' => $dtSales['staffID'],

'staffName' => $dtSales['staffName'],

'no' => $i);

307
$i++;
}

$smarty->assign("dataSales", $dataSales);

// count data
$queryCountSales = "SELECT * FROM
as_sales_transactions";
$sqlCountSales = mysqli_query($connect,
$queryCountSales);
$amountData = mysqli_num_rows($sqlCountSales);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'],
$amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

out.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>
<script type='text/javascript'
src="design/js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

308
{literal}
<script>
function toRp(amount, decimalSeparator,
thousandsSeparator, nDecimalDigits){
var num = parseFloat( amount ); //convert
to float
//default values
decimalSeparator = decimalSeparator || ',';
thousandsSeparator = thousandsSeparator ||
',';
nDecimalDigits = nDecimalDigits == null? 2
: nDecimalDigits;

var fixed = num.toFixed(nDecimalDigits);


//limit or add decimal digits
//separate begin [$1], middle [$2] and
decimal digits [$4]
var parts = new RegExp('^(-
?\\d{1,3})((?:\\d{3})+)(\\.(\\d{' + nDecimalDigits +
'}))?$').exec(fixed);

if(parts){ //num >= 1000 || num < = -1000


return parts[1] +
parts[2].replace(/\d{3}/g, thousandsSeparator + '$&') + (parts[4]
? decimalSeparator + parts[4] : '');
}else{
return fixed.replace('.',
decimalSeparator);
}
}

function sum() {
var total = eval($("#total").val());
var ppn = eval($("#ppn").val());
var discount = eval($("#discount").val());
var basic = eval($("#basic").val());
var grandtotal =
eval($("#grandtotal").val());
//var pay = eval($("#pay").val());
var ppnType = $("#ppnType").val();

// ppn
if (ppnType == '1') {
// dasar pengenaan pajak
var basicproccess = eval(total -
discount);
var basicproccessrp =
toRp(basicproccess);
var ppnproccess = eval(0.1 *
basicproccess);
var ppnproccessrp =
toRp(ppnproccess);

// grandtotal
var grandtotalproccess =
eval(basicproccess + ppnproccess);

309
var grandtotalproccessrp =
toRp(grandtotalproccess);
// piutang
//var receiveproccess =
eval(grandtotalproccess - pay);
//var receiveproccessrp =
toRp(receiveproccess);

document.getElementById('ppn').value =
ppnproccess.toFixed(2);

document.getElementById('ppnrp').value = ppnproccessrp;

document.getElementById('basic').value =
basicproccess.toFixed(2);

document.getElementById('basicrp').value =
basicproccessrp;

document.getElementById('grandtotal').value =
grandtotalproccess.toFixed(2);

document.getElementById('grandtotalrp').value =
grandtotalproccessrp;

//document.getElementById('receive').value =
receiveproccess.toFixed(2);

//document.getElementById('receiverp').value =
receiveproccessrp;
}
else{
// dasar pengenaan pajak
var basicproccess = eval(total -
discount);
var basicproccessrp =
toRp(basicproccess);
var ppnproccess = 0;
// grandtotal
var grandtotalproccess =
eval(basicproccess + ppnproccess);
var grandtotalproccessrp =
toRp(grandtotalproccess);
// terhutang
//var receiveproccess =
eval(grandtotalproccess - pay);
//var receiveproccessrp =
toRp(receiveproccess);

var ppnproccessrp =
toRp(ppnproccess);

document.getElementById('ppn').value = 0;

document.getElementById('ppnrp').value = 0;

310
document.getElementById('basic').value =
basicproccess.toFixed(2);

document.getElementById('basicrp').value =
basicproccessrp;

document.getElementById('grandtotal').value =
grandtotalproccess.toFixed(2);

document.getElementById('grandtotalrp').value =
grandtotalproccessrp;

//document.getElementById('receive').value =
receiveproccess.toFixed(2);

//document.getElementById('receiverp').value =
receiveproccessrp;
}
}

$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width =
$(this.element).data("width");
this.height =
$(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$("#paymentType").change(function(e){
var paymentType =
$("#paymentType").val();

$("#searchStatus").empty();

if (paymentType == '2'){

var newinput3 = $('<input


type="text" id="expiredDate" name="expiredDate" class="form-
control" style="width: 170px;" placeholder="Jatuh Tempo"
required>');

newinput3.appendTo('#searchStatus').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-
yy",
yearRange: 'c-0:c+1'

311
});
}
});

$("#ppnType").change(function(e){
var ppnType = $("#ppnType").val();
var discount =
eval($("#discount").val());
var total =
eval($("#total").val());
//var pay = eval($("#pay").val());

document.getElementById("ppn").value = 0;

document.getElementById("ppnrp").value = 0;

if (ppnType == '1'){
var sisatotal = eval(total -
discount);
var ppnValue = eval(0.1 *
sisatotal);
var grandtotal =
eval(sisatotal + ppnValue);
//var receive =
eval(grandtotal - pay);

var ppnrp = toRp(ppnValue);


var basicrp =
toRp(sisatotal);
var grandtotalrp =
toRp(grandtotal);
//var receiverp =
toRp(receive);

document.getElementById("ppn").value =
ppnValue.toFixed(2);

document.getElementById("ppnrp").value = ppnrp;

document.getElementById("basic").value =
sisatotal.toFixed(2);

document.getElementById("basicrp").value = basicrp;

document.getElementById("grandtotalrp").value =
grandtotalrp;

document.getElementById("grandtotal").value =
grandtotal.toFixed(2);

//document.getElementById("receiverp").value = receiverp;

//document.getElementById("receive").value =
receive.toFixed(2);
}

312
else {
var sisagrand = eval(total -
discount);
var sisagrandrp =
toRp(sisagrand);
//var receive =
eval(sisagrand - pay);
//var receiverp =
toRp(receive);

document.getElementById("ppn").value = 0;

document.getElementById("ppnrp").value = 0;

document.getElementById("basic").value =
sisagrand.toFixed(2);

document.getElementById("basicrp").value = sisagrandrp;

document.getElementById("grandtotalrp").value =
sisagrandrp;

document.getElementById("grandtotal").value =
sisagrand.toFixed(2);

//document.getElementById("receiverp").value = receiverp;

//document.getElementById("receive").value =
receive.toFixed(2);
}
});

$( "#invoiceDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$('#doNo').change(function () {
var doNo = $("#doNo").val();

313
window.location.href =
"out.php?module=out&act=add&doNo=" + doNo;
});

$(".modalbox").fancybox();
$(".modalbox2").fancybox();

$("#do").submit(function() { return false;


});
$("#do2").submit(function() { return false;
});

$("#send2").on("click", function(){
var doNo = $("#doNo").val();
var productID =
$("#productID").val();
var productName1 =
$("#productName1").val();
var qty =
parseInt($("#qty").val());
var price =
parseInt($("#price").val());
var desc = $("#desc").val();

if (qty != '' && soNo != '' &&


productID != '' && price != ''){

$.ajax({
type: 'POST',
url: 'save_so.php',
dataType: 'JSON',
data:{
qty: qty,
price:
price,
soNo: soNo,
productID:
productID,

productName1: productName1,
desc: desc
},
beforeSend: function
(data) {

$('#send2').hide();
},
success:
function(data) {

setTimeout("$.fancybox.close()", 1000);

window.location.href = "so.php?module=so&act=add&msg=Data
berhasil disimpan";
}
});
}

314
});
});
</script>
{/literal}

<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<!-- sidebar: style can be found in sidebar.less --
>
<section class="sidebar">

{include file="user_panel.tpl"}

{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<!-- Right side column. Contains the navbar and content of


the page -->
<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12
connectedSortable">

<!-- TO DO List -->


<div class="box box-
primary">

{if $module == 'out'


AND $act == 'add'}
{literal}

<script>

window.location.hash="no-back-button";

window.location.hash="Again-No-back-button";//again
because google chrome don't insert first hash into history

315
window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {

if (e.keyCode === 116) {

return false;

};

</script>
{/literal}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Tambah Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a
href="out.php?module=out&act=cancel&doNo={$doNo}" onclick="return
confirm('Anda Yakin ingin membatalkan transaksi penjualan
ini?');"><button class="btn btn-default pull-right">Batal
Trx</button></a>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">
<form
method="POST" action="out.php?module=out&act=input">

<input type="hidden" id="customerID" name="customerID"


value="{$customerID}">

<input type="hidden" id="customerName" name="customerName"


value="{$customerName}">

<input type="hidden" id="customerAddress"


name="customerAddress" value="{$customerAddress}">

316
<input type="hidden" id="soNo" name="soNo"
value="{$soNo}">

<table cellpadding="3" cellspacing="3">

<tr>

<td width="150">NO FAKTUR / TGL</td>

<td width="5">:</td>

<td><input type="hidden" id="invoiceNo"


name="invoiceNo" value="{$invoiceNo}">

<input type="text" id="invoiceNo"


name="invoiceNo" value="{$invoiceNo}" class="form-control"
placeholder="ID BBM" style="width: 110px; float: left" DISABLED>

<input type="text" id="invoiceDate"


name="invoiceDate" value="{$invoiceDate}" class="form-control"
placeholder="Tanggal Transaksi Pembelian" style="width: 160px;"
required>

</td>

</tr>

<tr valign="top">

<td>NO DO</td>

<td>:</td>

<td><input type="text" id="doNo" name="doNo"


value="{$doNo}" class="form-control" placeholder="Nomor DO"
style="width: 270px;" required>

{if $numsDo == '0' AND $doNo != ''}

<font color="#f56954">Nomor
delivery order tidak ditemukan.</font>

{/if}

{if $numsSSales > 0 AND $doNo != ''}

<font color="#f56954">Nomor
delivery order sudah digunakan.</font>

{/if}

</td>

</tr>

<tr>

317
<td>TIPE BAYAR</td>

<td>:</td>

<td><select id="paymentType" name="paymentType"


class="form-control" style="width: 100px; float: left;" required>

<option value=""></option>

<option value="1">Tunai</option>

<option value="2">Termin</option>

</select>

<div id="searchStatus"></div>

</td>

</tr>

<tr>

<td>PPN</td>

<td>:</td>

<td><select id="ppnType" name="ppnType"


class="form-control" style="width: 100px; float: left;" required>

<option value=""></option>

<option value="1">PPN</option>

<option value="2">No PPN</option>

</select>

</td>

</tr>

<tr>

<td colspan="3">

<br>

</td>

</tr>

</table>

<div
class="table-responsive">

318
<table id="example1" class="table table-bordered table-
striped">

<thead>

<tr>

<th>NO</th>

<th>NAMA PRODUK</th>

<th>HARGA</th>

<th>QTY</th>

<th>SUBTOTAL</th>

<th>KOREKSI HARGA</th>

</tr>

</thead>

<tbody>

{if $numsDo > 0 AND $doNo != ''}

{if $numsSSales == '0' AND $doNo !=


''}

{section name=dataDoDetail
loop=$dataDoDetail}

<tr>

<td>{$dataDoDetail[dataDoDetail].no}</td>

<td>{$dataDoDetail[dataDoDetail].productName}</td>

<td
style='text-align:
right;'>{$dataDoDetail[dataDoDetail].pricerp}</td>

<td
style='text-align:
center;'>{$dataDoDetail[dataDoDetail].deliveredQty}</td>

<td
style='text-align:
right;'>{$dataDoDetail[dataDoDetail].subtotal}</td>

<td><a
title="Koreksi Harga"
href="edit_out.php?module=out&act=edit&detailID={$dataDoDetail[dat

319
aDoDetail].detailID}&doNo={$doNo}" data-width="450" data-
height="180" class="various2 fancybox.iframe"><img
src="img/icons/edit.png" width="18"></a></td>

</tr>

{/section}

{/if}

{/if}

</tbody>

</table>

</div>
<br>
{if
$numsDo > 0 AND $doNo != ''}

{if $numsSSales == '0' AND $doNo != ''}

<table cellpadding="3" cellspacing="3">

<tr>

<td width="190">JUMLAH HARGA


BELI</td>

<td width="5">:</td>

<td><input type="hidden" id="total"


name="total" value="{$total}">

<input type="text"
id="total" name="total" value="{$totalrp}" class="form-control"
style="width: 270px;" DISABLED>

</td>

</tr>

<tr>

<td>POTONGAN</td>

<td>:</td>

<td><input type="text"
id="discount" name="discount" value="0" class="form-control"
style="width: 270px;" onkeyup="sum();" required></td>

</tr>

<tr>

320
<td>DASAR PENGENAAN PAJAK</td>

<td>:</td>

<td><input type="hidden" id="basic"


name="basic" value="{$total}">

<input type="text"
id="basicrp" name="basicrp" value="{$totalrp}" class="form-
control" style="width: 270px;" DISABLED>

</td>

</tr>

<tr>

<td>PPN (10%)</td>

<td>:</td>

<td><input type="hidden" id="ppn"


name="ppn" value="0">

<input type="text"
id="ppnrp" name="ppnrp" value="0" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>

<tr>

<td>GRANDTOTAL</td>

<td>:</td>

<td><input type="hidden"
id="grandtotal" name="grandtotal" value="{$total}">

<input type="text"
id="grandtotalrp" name="grandtotalrp" value="{$totalrp}"
class="form-control" style="width: 270px;" DISABLED>

</td>

</tr>

<!--<tr>

<td>TITIP BAYAR</td>

<td>:</td>

<td><input type="text" id="pay"


name="pay" value="0" class="form-control" style="width: 270px;"
onkeyup="sum();" required></td>

321
</tr>

<tr>

<td>TERHUTANG</td>

<td>:</td>

<td><input type="hidden"
id="receive" name="receive" value="0">

<input type="text"
id="receiverp" name="receiverp" value="0" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>-->

</table>

<br>

<button type="submit" class="btn btn-


primary">Simpan</button>

{/if}
{/if}

</form>

</div><!--
/.box-body -->

{elseif $module ==
'out' AND $act == 'finish'}
{literal}

<script>

window.location.hash="no-back-button";

window.location.hash="Again-No-back-button";//again
because google chrome don't insert first hash into history

window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {

if (e.keyCode === 116) {

return false;

322
};

</script>
{/literal}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Faktur Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a
href="print_unit_out.php?module=out&act=print&invoiceID={$invoiceI
D}&doNo={$doNo}&invoiceNo={$invoiceNo}" target="_blank"><button
class="btn btn-default pull-right">Print</button></a>

<a href="out.php"><button class="btn btn-default


pull-right">Close</button></a>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<table cellpadding="3" cellspacing="3">

<tr>

<td width="150">NO FAKTUR / TGL</td>

<td width="5">:</td>

<td><input type="text" id="invoiceNo"


name="invoiceNo" value="{$invoiceNo}" class="form-control"
placeholder="Nomor Faktur" style="width: 110px; float: left"
DISABLED>

<input type="text" id="invoiceDate"


name="invoiceDate" value="{$invoiceDate}" class="form-control"
placeholder="Tanggal Pengiriman" style="width: 160px;" DISABLED>

</td>

</tr>

<tr valign="top">

323
<td>NO DO</td>

<td>:</td>

<td><input type="text" id="doNo" name="doNo"


value="{$doNo}" class="form-control" placeholder="Nomor DO"
style="width: 270px;" DISABLED></td>

</tr>

<tr valign="top">

<td>TIPE BAYAR</td>

<td>:</td>

<td><input type="text" id="paymentType"


name="paymentType" value="{$paymentType}" class="form-control"
placeholder="Tipe Bayar" style="width: 135px; float: left;"
DISABLED>

<input type="text" id="expiredDate"


name="expiredDate" value="{$expiredPayment}" class="form-control"
placeholder="Jatuh Tempo" style="width: 135px;" DISABLED>

</td>

</tr>

<tr valign="top">

<td>PPN</td>

<td>:</td>

<td><input type="text" id="ppnType" name="ppnType"


value="{$ppnType}" class="form-control" placeholder="PPN"
style="width: 80px; float: left;" DISABLED>

</td>

</tr>

<tr>

<td colspan="3">

<br>

</td>

</tr>

</table>

324
<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO</th>

<th>NAMA PRODUK</th>

<th>HARGA</th>

<th>QTY</th>

<th>SUBTOTAL</th>

</tr>

</thead>

<tbody>

{section name=dataDoDetail
loop=$dataDoDetail}

<tr>

<td>{$dataDoDetail[dataDoDetail].no}</td>

<td>{$dataDoDetail[dataDoDetail].productName}</td>

<td style='text-align:
right;'>{$dataDoDetail[dataDoDetail].pricerp}</td>

<td style='text-align:
center;'>{$dataDoDetail[dataDoDetail].deliveredQty}</td>

<td style='text-align:
right;'>{$dataDoDetail[dataDoDetail].subtotal}</td>

</tr>

{/section}

</tbody>

</table>

</div>
<br>

325
<table cellpadding="3" cellspacing="3">

<tr>

<td width="190">JUMLAH HARGA JUAL</td>

<td width="5">:</td>

<td><input type="text" id="total" name="total"


value="{$total}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>POTONGAN</td>

<td>:</td>

<td><input type="text" id="discount"


name="discount" value="{$discount}" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>

<tr>

<td>DASAR PENGENAAN PAJAK</td>

<td>:</td>

<td><input type="text" id="basicrp" name="basicrp"


value="{$basic}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>PPN (10%)</td>

<td>:</td>

<td><input type="text" id="ppnrp" name="ppnrp"


value="{$ppn}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>GRANDTOTAL</td>

<td>:</td>

326
<td><input type="text" id="grandtotalrp"
name="grandtotalrp" value="{$grandtotal}" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>

<!--<tr>

<td>TITIP BAYAR</td>

<td>:</td>

<td><input type="text" id="pay" name="pay"


value="{$pay}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>TERHUTANG</td>

<td>:</td>

<td><input type="text" id="debtrp" name="debtrp"


value="{$debt}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>-->

</table>

</div><!--
/.box-body -->

{elseif $module ==
'out' AND $act == 'detailout'}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Faktur Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a
href="print_unit_out.php?module=out&act=print&invoiceID={$invoiceI
D}&doNo={$doNo}&invoiceNo={$invoiceNo}" target="_blank"><button
class="btn btn-default pull-right">Print</button></a>

{if $q != ''}

327
<a
href="out.php?module=out&act=search&q={$q}"><button class="btn
btn-default pull-right">Back</button></a>

{else}

<a href="out.php?page={$page}"><button
class="btn btn-default pull-right">Back</button></a>

{/if}

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<table cellpadding="3" cellspacing="3">

<tr>

<td width="150">NO FAKTUR / TGL</td>

<td width="5">:</td>

<td><input type="text" id="invoiceNo"


name="invoiceNo" value="{$invoiceNo}" class="form-control"
placeholder="Nomor Faktur" style="width: 110px; float: left"
DISABLED>

<input type="text" id="invoiceDate"


name="invoiceDate" value="{$invoiceDate}" class="form-control"
placeholder="Tanggal Pengiriman" style="width: 160px;" DISABLED>

</td>

</tr>

<tr valign="top">

<td>NO DO</td>

<td>:</td>

<td><input type="text" id="doNo" name="doNo"


value="{$doNo}" class="form-control" placeholder="Nomor DO"
style="width: 270px;" DISABLED></td>

</tr>

<tr valign="top">

<td>TIPE BAYAR</td>

328
<td>:</td>

<td><input type="text" id="paymentType"


name="paymentType" value="{$paymentType}" class="form-control"
placeholder="Tipe Bayar" style="width: 135px; float: left;"
DISABLED>

<input type="text" id="expiredDate"


name="expiredDate" value="{$expiredPayment}" class="form-control"
placeholder="Jatuh Tempo" style="width: 135px;" DISABLED>

</td>

</tr>

<tr valign="top">

<td>PPN</td>

<td>:</td>

<td><input type="text" id="ppnType" name="ppnType"


value="{$ppnType}" class="form-control" placeholder="PPN"
style="width: 80px; float: left;" DISABLED>

</td>

</tr>

<tr>

<td colspan="3">

<br>

</td>

</tr>

</table>

<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO</th>

<th>NAMA PRODUK</th>

329
<th>HARGA</th>

<th>QTY</th>

<th>SUBTOTAL</th>

</tr>

</thead>

<tbody>

{section name=dataDoDetail
loop=$dataDoDetail}

<tr>

<td>{$dataDoDetail[dataDoDetail].no}</td>

<td>{$dataDoDetail[dataDoDetail].productName}</td>

<td style='text-align:
right;'>{$dataDoDetail[dataDoDetail].pricerp}</td>

<td style='text-align:
center;'>{$dataDoDetail[dataDoDetail].deliveredQty}</td>

<td style='text-align:
right;'>{$dataDoDetail[dataDoDetail].subtotal}</td>

</tr>

{/section}

</tbody>

</table>

</div>
<br>

<table cellpadding="3" cellspacing="3">

<tr>

<td width="190">JUMLAH HARGA JUAL</td>

<td width="5">:</td>

<td><input type="text" id="total" name="total"


value="{$total}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

330
<tr>

<td>POTONGAN</td>

<td>:</td>

<td><input type="text" id="discount"


name="discount" value="{$discount}" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>

<tr>

<td>DASAR PENGENAAN PAJAK</td>

<td>:</td>

<td><input type="text" id="basicrp" name="basicrp"


value="{$basic}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>PPN (10%)</td>

<td>:</td>

<td><input type="text" id="ppnrp" name="ppnrp"


value="{$ppn}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>GRANDTOTAL</td>

<td>:</td>

<td><input type="text" id="grandtotalrp"


name="grandtotalrp" value="{$grandtotal}" class="form-control"
style="width: 270px;" DISABLED></td>

</tr>

<!--<tr>

<td>TITIP BAYAR</td>

<td>:</td>

<td><input type="text" id="pay" name="pay"

331
value="{$pay}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>

<tr>

<td>TERHUTANG</td>

<td>:</td>

<td><input type="text" id="debtrp" name="debtrp"


value="{$debt}" class="form-control" style="width: 270px;"
DISABLED></td>

</tr>-->

</table>

</div><!--
/.box-body -->

{elseif $module ==
'out' AND $act == 'search'}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<form method="GET" action="out.php">

<input type="hidden" name="module"


value="out">

<input type="hidden" name="act"


value="search">

<button type="submit" class="btn btn-


default pull-right"><i class="fa fa-search"></i> Search</button>

<input type="text" value="{$endDate}"


id="endDate" name="endDate" class="form-control"
placeholder="Periode Akhir" style="float: right; width: 115px;">

<input type="text" value="{$startDate}"


id="startDate" name="startDate" class="form-control"
placeholder="Periode Awal" style="float: right; width: 115px;">

<input type="text" value="{$q}" id="q"

332
name="q" class="form-control" placeholder="Pencarian : Nomor
Faktur Penjualan" style="float: right; width: 270px;" required>

<a href="out.php?module=out&act=add"
style="float: left;"><button type="button" class="btn btn-default
pull-right"><i class="fa fa-plus"></i> Add</button></a>

<a
href="print_out.php?act=print&q={$q}&startDate={$startDate}&endDat
e={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>

&nbsp;&nbsp;&nbsp;

</form>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO <i class="fa fa-


sort"></i></th>

<th>NO INVOICE <i class="fa fa-


sort"></i></th>

<th>TGL <i class="fa fa-


sort"></i></th>

<th>NO DO <i class="fa fa-


sort"></i></th>

<th>GRANDTOTAL <i class="fa fa-


sort"></i></th>

<th>DIBUAT OLEH <i class="fa fa-


sort"></i></th>

<th>AKSI</th>

</tr>

333
</thead>

<tbody>

{section name=dataSales loop=$dataSales}

<tr>

<td>{$dataSales[dataSales].no}</td>

<td>{$dataSales[dataSales].invoiceNo}</td>

<td>{$dataSales[dataSales].invoiceDate}</td>

<td>{$dataSales[dataSales].doNo}</td>

<td>{$dataSales[dataSales].grandtotal}</td>

<td>{$dataSales[dataSales].staffName}</td>

<td>

<a title="Detail"
href="out.php?module=out&act=detailout&invoiceID={$dataSales[dataS
ales].invoiceID}&invoiceNo={$dataSales[dataSales].invoiceNo}&doNo=
{$dataSales[dataSales].doNo}&q={$q}&page={$page}"><img
src="img/icons/view.png" width="18"></a>

<a title="Delete"
href="out.php?module=out&act=delete&invoiceID={$dataSales[dataSale
s].invoiceID}&invoiceNo={$dataSales[dataSales].invoiceNo}&doNo={$d
ataSales[dataSales].doNo}&" onclick="return confirm('Anda Yakin
ingin membatalkan transaksi {$dataSales[dataSales].invoiceNo}?
penghapusan ini akan membatalkan seluruh hutang dan pembayaran
konsumen terkait transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>

</td>

</tr>

{/section}

</tbody>

</table>

</div>

334
</div><!--
/.box-body -->

{else}
<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<form method="GET" action="out.php">

<input type="hidden" name="module"


value="out">

<input type="hidden" name="act"


value="search">

<button type="submit" class="btn btn-


default pull-right"><i class="fa fa-search"></i> Search</button>

<input type="text" value="{$endDate}"


id="endDate" name="endDate" class="form-control"
placeholder="Periode Akhir" style="float: right; width: 115px;">

<input type="text" value="{$startDate}"


id="startDate" name="startDate" class="form-control"
placeholder="Periode Awal" style="float: right; width: 115px;">

<input type="text" value="{$q}" id="q"


name="q" class="form-control" placeholder="Pencarian : Nomor
Faktur Penjualan" style="float: right; width: 270px;">

<a href="out.php?module=out&act=add"
style="float: left;"><button type="button" class="btn btn-default
pull-right"><i class="fa fa-plus"></i> Add</button></a>

<a href="print_out.php?act=print&q={$q}"
style="float: left;" target="_blank"><button type="button"
class="btn btn-default pull-right"><i class="fa fa-print"></i>
Print PDF</button></a>

&nbsp;&nbsp;&nbsp;

</form>

</div>

</div>
</div><!--
/.box-header -->

335
<div
class="box-body">

<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO <i class="fa fa-


sort"></i></th>

<th>NO INVOICE <i class="fa fa-


sort"></i></th>

<th>TGL <i class="fa fa-


sort"></i></th>

<th>NO DO <i class="fa fa-


sort"></i></th>

<th>GRANDTOTAL <i class="fa fa-


sort"></i></th>

<th>DIBUAT OLEH <i class="fa fa-


sort"></i></th>

<th>AKSI</th>

</tr>

</thead>

<tbody>

{section name=dataSales loop=$dataSales}

<tr>

<td>{$dataSales[dataSales].no}</td>

<td>{$dataSales[dataSales].invoiceNo}</td>

<td>{$dataSales[dataSales].invoiceDate}</td>

<td>{$dataSales[dataSales].doNo}</td>

336
<td>{$dataSales[dataSales].grandtotal}</td>

<td>{$dataSales[dataSales].staffName}</td>

<td>

<a title="Detail"
href="out.php?module=out&act=detailout&invoiceID={$dataSales[dataS
ales].invoiceID}&invoiceNo={$dataSales[dataSales].invoiceNo}&doNo=
{$dataSales[dataSales].doNo}&page={$page}"><img
src="img/icons/view.png" width="18"></a>

<a title="Delete"
href="out.php?module=out&act=delete&invoiceID={$dataSales[dataSale
s].invoiceID}&invoiceNo={$dataSales[dataSales].invoiceNo}&doNo={$d
ataSales[dataSales].doNo}&" onclick="return confirm('Anda Yakin
ingin membatalkan transaksi {$dataSales[dataSales].invoiceNo}?
penghapusan ini akan membatalkan seluruh hutang dan pembayaran
konsumen terkait transaksi ini.');"><img
src="img/icons/delete.png" width="18"></a>

</td>

</tr>

{/section}

</tbody>

</table>

</div>

</div><!--
/.box-body -->

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-left">

<ul class="pagination pagination-sm inline">

{$pageLink}

</ul>

</div>
</div><!--
/.box-header -->
{/if}

337
</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil skrip diatas akan menghasilkan halaman transaksi penjualan yang hasilnya
bisa dilihat pada gambar-gambar berikut :

Gambar 5.35. Transaksi penjualan

Gambar 5.36. Cetak transaksi penjualan

338
5.3.4 Pembayaran Transaksi Penjualan
Halaman ini digunakan untuk membayar transaksi penjualan yang telah
dilakukan. Kita juga akan bahas file apa saja yang diperlukan untuk membuat
pembayaran transaksi penjualan ini.
Buat beberapa file dengan masing-masing skrip berikut :
pay_out.php
<?php
// include header
include "header.php";
// set the tpl page
$page = "pay_out.tpl";

$module = $_GET['module'];
$act = $_GET['act'];

// if session is null, showing up the text and exit


if ($_SESSION['staffID'] == '' && $_SESSION['email'] == '')
{
// show up the text and exit
echo "Anda tidak berhak akses modul ini.";
exit();
}

else
{
$queryAuthorizeStaff = "SELECT * FROM as_modules WHERE
modulID = '27'";
$sqlAuthorizeStaff = mysqli_query($connect,
$queryAuthorizeStaff);
$dataAuthorizeStaff =
mysqli_fetch_array($sqlAuthorizeStaff);

if (strpos($dataAuthorizeStaff['authorize'],
$_SESSION['level']) === FALSE){
echo "Anda tidak berhak akses modul ini.";
exit();
}

// if module is pay out and action is delete


if ($module == 'payout' && $act == 'delete')
{
// insert method into a variable
$invoiceNo = $_GET['invoiceNo'];
$paymentID = $_GET['paymentID'];
$paymentNo = $_GET['paymentNo'];
$q = mysqli_real_escape_string($connect,
$_GET['q']);

$queryPayment = "SELECT total, invoiceID FROM


as_sales_payments WHERE paymentID = '$paymentID' AND paymentNo =
'$paymentNo'";

339
$sqlPayment = mysqli_query($connect,
$queryPayment);
$dataPayment = mysqli_fetch_array($sqlPayment);

$total = $dataPayment['total'];

$queryUpdate = "UPDATE as_receivables SET


incomingTotal=incomingTotal-$total WHERE invoiceNo = '$invoiceNo'
AND invoiceID = '$dataPayment[invoiceID]'";
$sqlUpdate = mysqli_query($connect, $queryUpdate);

if ($sqlUpdate)
{
$queryPay = "DELETE FROM as_sales_payments
WHERE paymentID = '$paymentID' AND paymentNo = '$paymentNo'";
$sqlPay = mysqli_query($connect,
$queryPay);
}

// redirect to the pay in page


if ($q != '')
{
header("Location:
pay_out.php?module=payout&act=search&q=".$q."&msg=Data transaksi
penjualan berhasil dihapus");
}
else
{
header("Location: pay_out.php?msg=Data
transaksi penjualan berhasil dihapus");
}
} // close bracket

// if the module is pay out and act is input


elseif ($module == 'payout' && $act == 'input')
{
$createdDate = date('Y-m-d H:i:s');
$staffID = $_SESSION['staffID'];
$sName = $_SESSION['staffCode']."
".$_SESSION['staffName'];

$paymentNo = $_POST['paymentNo'];
$pDate = explode("-", $_POST['paymentDate']);
$paymentDate = $pDate[2]."-".$pDate[1]."-
".$pDate[0];
$invoiceID = $_POST['invoiceID'];
$invoiceNo = mysqli_real_escape_string($connect,
$_POST['invoiceNo']);
$soNo = $_POST['soNo'];
$payType = $_POST['payType'];
$bankNo = mysqli_real_escape_string($connect,
$_POST['bankNo']);
$bankName = mysqli_real_escape_string($connect,
$_POST['bankName']);
$bankAC = mysqli_real_escape_string($connect,
$_POST['bankAC']);
$eDate = explode("-", $_POST['effectiveDate']);

340
$effectiveDate = $eDate[2]."-".$eDate[1]."-
".$eDate[0];
$total = mysqli_real_escape_string($connect,
$_POST['total']);
$customerID = $_POST['customerID'];
$customerName = mysqli_real_escape_string($connect,
$_POST['customerName']);
$customerAddress =
mysqli_real_escape_string($connect, $_POST['customerAddress']);
$ref = mysqli_real_escape_string($connect,
$_POST['ref']);
$note = mysqli_real_escape_string($connect,
$_POST['note']);

// save in to the database


$queryPay = "INSERT INTO as_sales_payments
(paymentNo,

invoiceID,

invoiceNo,

soNo,

paymentDate,

payType,

bankNo,

bankName,

bankAC,

effectiveDate,

total,

customerID,

customerName,

customerAddress,

ref,

note,

staffID,

staffName,

createdDate,

createdUserID,

modifiedDate,

341
modifiedUserID)

VALUES( '$paymentNo',

'$invoiceID',

'$invoiceNo',

'$soNo',

'$paymentDate',

'$payType',

'$bankNo',

'$bankName',

'$bankAC',

'$effectiveDate',

'$total',

'$customerID',

'$customerName',

'$customerAddress',

'$ref',

'$note',

'$staffID',

'$sName',

'$createdDate',

'$staffID',

'',

'')";

$sqlPay = mysqli_query($connect, $queryPay);

$paymentID = mysqli_insert_id($connect);

if ($sqlPay)
{
$queryUpdate = "UPDATE as_receivables SET
incomingTotal=incomingTotal+$total WHERE invoiceNo = '$invoiceNo'
AND invoiceID = '$invoiceID'";

342
$sqlUpdate = mysqli_query($connect,
$queryUpdate);
}

header("Location:
pay_out.php?module=payout&act=finish&paymentNo=".$paymentNo."&paym
entID=".$paymentID."&invoiceNo=".$invoiceNo);
}

// if the module is pay out and act is detail pay out


elseif ($module == 'payout' && $act == 'detailpayout')
{
$paymentID = $_GET['paymentID'];
$paymentNo = $_GET['paymentNo'];
$invoiceNo = $_GET['invoiceNo'];
$q = mysqli_real_escape_string($connect,
$_GET['q']);

// show the sales transaction


$querySales = "SELECT * FROM as_sales_transactions
WHERE invoiceNo = '$invoiceNo'";
$sqlSales = mysqli_query($connect, $querySales);
$dataSales = mysqli_fetch_array($sqlSales);

// show the receivables


$queryReceive = "SELECT * FROM as_receivables WHERE
invoiceNo = '$invoiceNo' AND invoiceID = '$dataBuy[invoiceID]'";
$sqlReceive = mysqli_query($connect,
$queryReceive);
$dataReceive = mysqli_fetch_array($sqlReceive);

// show the payment


$queryPay = "SELECT * FROM as_sales_payments WHERE
paymentNo = '$paymentNo' AND paymentID = '$paymentID' AND
invoiceNo = '$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$queryTotal = "SELECT SUM(total) as total FROM


as_sales_payments WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// receive
$receive = $dataTotal['total'] -
$dataSales['grandtotal'];

if ($dataPay['payType'] == '1')
{
$payType = "TUNAI";
}
elseif ($dataPay['payType'] == '2')
{
$payType = "TRANSFER";
}
elseif ($dataPay['payType'] == '3')
{

343
$payType = "CEK";
}
else
{
$payType = "GIRO";
}

if ($dataPay['effectiveDate'] == '0000-00-00')
{
$effectiveDate = "-";
}
else
{
$effectiveDate =
tgl_indo2($dataPay['effectiveDate']);
}

// assign
$smarty->assign("q", $q);
$smarty->assign("paymentNo",
$dataPay['paymentNo']);
$smarty->assign("paymentID",
$dataPay['paymentID']);
$smarty->assign("paymentDate",
tgl_indo2($dataPay['paymentDate']));
$smarty->assign("invoiceNo",
$dataPay['invoiceNo']);
$smarty->assign("pay", rupiah($total));
$smarty->assign("total",
rupiah($dataPay['total']));
$smarty->assign("receive", rupiah($receive));
$smarty->assign("customerName",
$dataSales['customerName']);
$smarty->assign("customerAddress",
$dataSales['customerAddress']);
$smarty->assign("payType", $payType);
$smarty->assign("bankNo", $dataPay['bankNo']);
$smarty->assign("bankName", $dataPay['bankName']);
$smarty->assign("effectiveDate", $effectiveDate);
$smarty->assign("bankAC", $dataPay['bankAC']);
$smarty->assign("total",
rupiah($dataPay['total']));
$smarty->assign("ref", $dataPay['ref']);
$smarty->assign("note", $dataPay['note']);

$smarty->assign("breadcumbTitle", "Pembayaran
Transaksi Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan pembayaran transaksi penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Pembayaran
Transaksi");
}

// if module out and act is finish


elseif ($module == 'payout' && $act == 'finish')

344
{
$paymentNo = $_GET['paymentNo'];
$paymentID = $_GET['paymentID'];
$invoiceNo = $_GET['invoiceNo'];

// show the sales transaction


$querySales = "SELECT * FROM as_sales_transactions
WHERE invoiceNo = '$invoiceNo'";
$sqlSales = mysqli_query($connect, $querySales);
$dataSales = mysqli_fetch_array($sqlSales);

// show the receive


$queryReceive = "SELECT * FROM as_receivables WHERE
invoiceNo = '$invoiceNo' AND invoiceID = '$dataSales[invoiceID]'";
$sqlReceive = mysqli_query($connect,
$queryReceive);
$dataReceive = mysqli_fetch_array($sqlReceive);

// show the payment


$queryPay = "SELECT * FROM as_sales_payments WHERE
paymentNo = '$paymentNo' AND paymentID = '$paymentID' AND
invoiceNo = '$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$queryTotal = "SELECT SUM(total) as total FROM


as_sales_payments WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// receive
$receive = $dataSales['grandtotal'] -
$dataTotal['total'];

if ($dataPay['payType'] == '1')
{
$payType = "TUNAI";
}
elseif ($dataPay['payType'] == '2')
{
$payType = "TRANSFER";
}
elseif ($dataPay['payType'] == '3')
{
$payType = "CEK";
}
else
{
$payType = "GIRO";
}

if ($dataPay['effectiveDate'] == '0000-00-00')
{
$effectiveDate = "-";
}
else
{

345
$effectiveDate =
tgl_indo2($dataPay['effectiveDate']);
}

// assign
$smarty->assign("paymentNo",
$dataPay['paymentNo']);
$smarty->assign("paymentID",
$dataPay['paymentID']);
$smarty->assign("paymentDate",
tgl_indo2($dataPay['paymentDate']));
$smarty->assign("invoiceNo",
$dataPay['invoiceNo']);
$smarty->assign("pay", rupiah($total));
$smarty->assign("total",
rupiah($dataPay['total']));
$smarty->assign("receive", rupiah($receive));
$smarty->assign("customerName",
$dataSales['customerName']);
$smarty->assign("customerAddress",
$dataSales['customerAddress']);
$smarty->assign("payType", $payType);
$smarty->assign("bankNo", $dataPay['bankNo']);
$smarty->assign("bankName", $dataPay['bankName']);
$smarty->assign("effectiveDate", $effectiveDate);
$smarty->assign("bankAC", $dataPay['bankAC']);
$smarty->assign("total",
rupiah($dataPay['total']));
$smarty->assign("ref", $dataPay['ref']);
$smarty->assign("note", $dataPay['note']);

$smarty->assign("breadcumbTitle", "Pembayaran
Transaksi Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan pembayaran transaksi penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Pembayaran
Transaksi");
}

// if the module out and act is add


elseif ($module == 'payout' && $act == 'add')
{
$invoiceNo = mysqli_real_escape_string($connect,
$_GET['invoiceNo']);

// get last sort out number pay ID


$queryNoPayOut = "SELECT paymentNo FROM
as_sales_payments ORDER BY paymentNo DESC LIMIT 1";
$sqlNoPayOut = mysqli_query($connect,
$queryNoPayOut);
$numsNoPayOut = mysqli_num_rows($sqlNoPayOut);
$dataNoPayOut = mysqli_fetch_array($sqlNoPayOut);

$start = substr($dataNoPayOut['paymentNo'],2-7);
$next = $start + 1;

346
$tempNo = strlen($next);

if ($numsNoPayOut == '0')
{
$outNo = "00000";
}
elseif ($tempNo == 1)
{
$outNo = "00000";
}
elseif ($tempNo == 2)
{
$outNo = "0000";
}
elseif ($tempNo == 3)
{
$outNo = "000";
}
elseif ($tempNo == 4)
{
$outNo = "00";
}
elseif ($tempNo == 5)
{
$outNo = "0";
}
elseif ($tempNo == 6)
{
$outNo = "";
}

$payOutNo = "PJ".$outNo.$next;

// total grandtotal
$queryTotal = "SELECT grandtotal, invoiceID, soNo,
customerID, customerName, customerAddress FROM
as_sales_transactions WHERE invoiceNo = '$invoiceNo'";
$sqlTotal = mysqli_query($connect, $queryTotal);
$numsTotal = mysqli_num_rows($sqlTotal);
$dataTotal = mysqli_fetch_array($sqlTotal);

// count payment
$queryPay = "SELECT SUM(total) as total FROM
as_sales_payments WHERE invoiceNo = '$invoiceNo'";
$sqlPay = mysqli_query($connect, $queryPay);
$dataPay = mysqli_fetch_array($sqlPay);

$receive = $dataTotal['grandtotal'] -
$dataPay['total'];

$smarty->assign("payOutNo", $payOutNo);
$smarty->assign("payOutDate", tgl_indo2(date('Y-m-
d')));
$smarty->assign("invoiceNo", $invoiceNo);
$smarty->assign("invoiceID",
$dataTotal['invoiceID']);
$smarty->assign("numsTotal", $numsTotal);

347
$smarty->assign("soNo", $dataTotal['soNo']);
$smarty->assign("receive", rupiah($receive));
$smarty->assign("receiveo", $receive);
$smarty->assign("customerID",
$dataTotal['customerID']);
$smarty->assign("customerName",
$dataTotal['customerName']);
$smarty->assign("customerAddress",
$dataTotal['customerAddress']);

$smarty->assign("breadcumbTitle", "Transaksi
Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan transaksi penjualan, faktur penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Transaksi
Penjualan");
}

elseif ($module == 'payout' && $act == 'search')


{
$q = mysqli_real_escape_string($connect,
$_GET['q']);
$sDate = mysqli_real_escape_string($connect,
$_GET['startDate']);
$eDate = mysqli_real_escape_string($connect,
$_GET['endDate']);

$smarty->assign("startDate", $sDate);
$smarty->assign("endDate", $eDate);

$s2Date = explode("-", $sDate);


$e2Date = explode("-", $eDate);

$startDate = $s2Date[2]."-".$s2Date[1]."-
".$s2Date[0];
$endDate = $e2Date[2]."-".$e2Date[1]."-
".$e2Date[0];

// showing up the pay out data


if ($sDate != '' && $eDate != '')
{
$queryPay = "SELECT * FROM
as_sales_payments WHERE paymentNo LIKE '%$q%' AND paymentDate
BETWEEN '$startDate' AND '$endDate' ORDER BY paymentDate DESC";
}
else
{
$queryPay = "SELECT * FROM
as_sales_payments WHERE paymentNo LIKE '%$q%' ORDER BY paymentDate
DESC";
}

$sqlPay = mysqli_query($connect, $queryPay);

// fetch data

348
$i = 1 + $position;
while ($dtPay = mysqli_fetch_array($sqlPay))
{
if ($dtPay['payType'] == '1')
{
$payType = "TUNAI";
$effectiveDate = "";
}
else
{
$payType = "CEK";
$effectiveDate =
tgl_indo2($dtPay['effectiveDate']);
}

$dataPay[] = array( 'paymentID' =>


$dtPay['paymentID'],

'invoiceNo' => $dtPay['invoiceNo'],

'invoiceID' => $dtPay['invoiceID'],

'paymentNo' => $dtPay['paymentNo'],

'paymentDate' => tgl_indo2($dtPay['paymentDate']),

'payType' => $payType,

'invoiceNo' => $dtPay['invoiceNo'],

'soNo' => $dtPay['soNo'],


'cek'
=> $dtPay['bankNo'],

'total' => rupiah($dtPay['total']),

'customerName' => $dtPay['customerName'],

'staffName' => $dtPay['staffName'],


'no'
=> $i);
$i++;
}

$smarty->assign("dataPay", $dataPay);
$smarty->assign("q", $q);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Pembayaran
Transaksi Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan pembayaran transaksi penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Pembayaran
Transaksi");
}

349
else
{
// create new object pagination
$p = new PaginationPayOut;
// limit 20 data for page
$limit = 30;
$position = $p->searchPosition($limit);

// showing up the pay out data


$queryPay = "SELECT * FROM as_sales_payments ORDER
BY paymentDate DESC LIMIT $position,$limit";
$sqlPay = mysqli_query($connect, $queryPay);

// fetch data
$i = 1 + $position;
while ($dtPay = mysqli_fetch_array($sqlPay))
{
if ($dtPay['payType'] == '1')
{
$payType = "TUNAI";
$effectiveDate = "";
}
else
{
$payType = "CEK";
$effectiveDate =
tgl_indo2($dtPay['effectiveDate']);
}

$dataPay[] = array( 'paymentID' =>


$dtPay['paymentID'],

'invoiceNo' => $dtPay['invoiceNo'],

'invoiceID' => $dtPay['invoiceID'],

'paymentNo' => $dtPay['paymentNo'],

'paymentDate' => tgl_indo2($dtPay['paymentDate']),

'payType' => $payType,

'soNo' => $dtPay['soNo'],

'invoiceNo' => $dtPay['invoiceNo'],


'cek'
=> $dtPay['bankNo'],

'total' => rupiah($dtPay['total']),

'customerName' => $dtPay['customerName'],

'staffName' => $dtPay['staffName'],


'no'
=> $i);
$i++;

350
}

$smarty->assign("dataPay", $dataPay);

// count data
$queryCountPay = "SELECT * FROM as_sales_payments";
$sqlCountPay = mysqli_query($connect,
$queryCountPay);
$amountData = mysqli_num_rows($sqlCountPay);

$amountPage = $p->amountPage($amountData, $limit);


$pageLink = $p->navPage($_GET['page'],
$amountPage);

$smarty->assign("pageLink", $pageLink);
$smarty->assign("page", $_GET['page']);

$smarty->assign("msg", $_GET['msg']);
$smarty->assign("breadcumbTitle", "Pembayaran
Transaksi Penjualan");
$smarty->assign("breadcumbTitleSmall", "Halaman
untuk melakukan pembayaran transaksi penjualan.");
$smarty->assign("breadcumbMenuName", "Transaksi
Penjualan");
$smarty->assign("breadcumbMenuSubName", "Pembayaran
Transaksi");
}

$smarty->assign("module", $module);
$smarty->assign("act", $act);
}

// include footer
include "footer.php";
?>

pay_out.tpl (simpan didalam folder templates)


{include file="header.tpl"}

<style>
div.ui-datepicker{
font-size:14px;
}
</style>

<link rel="stylesheet" type="text/css" media="all"


href="design/js/fancybox/jquery.fancybox.css">
<script type="text/javascript"
src="design/js/fancybox/jquery.fancybox.js?v=2.0.6"></script>
<script type='text/javascript'
src="design/js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css"
href="design/css/jquery.autocomplete.css" />

{literal}

351
<script>

$(document).ready(function() {

$(".various2").fancybox({
fitToView: false,
scrolling: 'no',
afterLoad: function(){
this.width =
$(this.element).data("width");
this.height =
$(this.element).data("height");
},
'afterClose':function () {
window.location.reload();
}
});

$( "#paymentDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c-1:c-0'
});

$( "#startDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#endDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '2014:c-0'
});

$( "#effectiveDate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: 'c:c+1'
});

$('#invoiceNo').change(function () {
var invoiceNo =
$("#invoiceNo").val();

window.location.href =
"pay_out.php?module=payout&act=add&invoiceNo=" + invoiceNo;
});
});
</script>
{/literal}

352
<header class="header">

{include file="logo.tpl"}

{include file="navigation.tpl"}

</header>

<div class="wrapper row-offcanvas row-offcanvas-left">


<!-- Left side column. contains the logo and sidebar -->
<aside class="left-side sidebar-offcanvas">
<!-- sidebar: style can be found in sidebar.less --
>
<section class="sidebar">

{include file="user_panel.tpl"}

{include file="side_menu.tpl"}

</section>
<!-- /.sidebar -->
</aside>

<!-- Right side column. Contains the navbar and content of


the page -->
<aside class="right-side">

{include file="breadcumb.tpl"}

<!-- Main content -->


<section class="content">

<!-- Main row -->


<div class="row">
<!-- Left col -->
<section class="col-lg-12
connectedSortable">

<!-- TO DO List -->


<div class="box box-
primary">

{if $module ==
'payout' AND $act == 'add'}
{literal}

<script>

window.location.hash="no-back-button";

window.location.hash="Again-No-back-button";//again
because google chrome don't insert first hash into history

window.onhashchange=function(){window.location.hash="no-
back-button";}

353
document.onkeydown = function (e) {

if (e.keyCode === 116) {

return false;

};

</script>
{/literal}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Pembayaran Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a href="pay_out.php" onclick="return confirm('Anda


Yakin ingin membatalkan pembayaran transaksi penjualan
ini?');"><button type="button" class="btn btn-default pull-
right">Batal Trx</button></a>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">
{if
$numsTotal == '0' && $invoiceNo != ''}

<span style="color: #f56954;">Nomor Faktur tidak


ditemukan.</span>
{/if}
{if
$numsTotal > 0}

{if $receiveo <= '0'}

<span style="color: green;">Nomor Faktur ini telah


lunas dibayarkan.</span>

{/if}
{/if}
<form
method="POST" action="pay_out.php?module=payout&act=input">

354
<input type="hidden" id="customerID" name="customerID"
value="{$customerID}">

<input type="hidden" id="customerName" name="customerName"


value="{$customerName}">

<input type="hidden" id="customerAddress"


name="customerAddress" value="{$customerAddress}">

<input type="hidden" id="soNo" name="soNo"


value="{$soNo}">

<input type="hidden" id="invoiceID" name="invoiceID"


value="{$invoiceID}">

<table cellpadding="3" cellspacing="3" width="100%">

<tr>

<td width="150">NO PAYMENT / TGL</td>

<td width="5">:</td>

<td><input type="hidden" id="paymentNo"


name="paymentNo" value="{$payOutNo}">

<input type="text" id="paymentNo"


name="paymentNo" value="{$payOutNo}" class="form-control"
placeholder="NOMOR PAYMENT" style="width: 110px; float: left"
DISABLED>

<input type="text" id="paymentDate"


name="paymentDate" value="{$payOutDate}" class="form-control"
placeholder="Tanggal Payment" style="width: 190px;" required>

</td>

</tr>

<tr valign="top">

<td>NOMOR FAKTUR</td>

<td>:</td>

<td><input type="text" id="invoiceNo"


name="invoiceNo" value="{$invoiceNo}" class="form-control"
placeholder="Nomor Faktur" style="width: 300px;" required></td>

</tr>

<tr valign="top">

<td>TERHUTANG</td>

<td>:</td>

355
<td><input type="text" id="receive" name="receive"
value="{$receive}" class="form-control" placeholder="Total
Piutang" style="width: 300px;" DISABLED></td>

</tr>

<tr>

<td>DIBAYARKAN KEPADA</td>

<td>:</td>

<td>

<input type="text" id="customerName"


name="customerName" value="{$customerName}" class="form-control"
placeholder="Nama Customerr" style="width: 300px;" DISABLED>

</td>

</tr>

<tr>

<td>PEMBAYARAN</td>

<td>:</td>

<td><select id="payType" name="payType"


class="form-control" style="width: 125px; float: left;" required>

<option value=""></option>

<option value="1">Tunai</option>

<option value="2">Transfer</option>

<option value="3">Cek</option>

<option value="4">Giro</option>

</select>

<input type="text" id="bankNo"


name="bankNo" class="form-control" placeholder="Nomor Rek / Cek /
Giro" style="width: 175px; float:left;">

</td>

</tr>

<tr>

<td>NAMA BANK</td>

<td>:</td>

356
<td>

<input type="text" id="bankName"


name="bankName" class="form-control" placeholder="Nama Bank"
style="width: 175px; float: left;">

<input type="text" id="effectiveDate"


name="effectiveDate" class="form-control" placeholder="Tanggal
Efektif" style="width: 125px;">

</td>

</tr>

<tr>

<td>NAMA AKUN</td>

<td>:</td>

<td>

<input type="text" id="bankAC"


name="bankAC" class="form-control" placeholder="Nama Akun
(Pemegang)" style="width:300px; float:left;">

</td>

</tr>

<tr>

<td>JUMLAH</td>

<td>:</td>

<td>

<input type="text" id="total" name="total"


class="form-control" placeholder="Jumlah" style="width: 300px;"
required>

</td>

</tr>

<tr>

<td>REFERENSI</td>

<td>:</td>

<td>

<input type="text" id="ref" name="ref"

357
class="form-control" placeholder="Referensi" style="width:
300px;">

</td>

</tr>

<tr valign="top">

<td>NOTE</td>

<td>:</td>

<td>

<textarea id="note" name="note"


class="form-control" placeholder="Note" style="width:
300px;"></textarea>

</td>

</tr>

</table>
{if
$numsTotal > 0}

{if $receiveo > 0}

<button type="submit" class="btn btn-


primary">Simpan</button>

{/if}
{/if}

</form>

</div><!--
/.box-body -->

{elseif $module ==
'payout' AND $act == 'finish'}
{literal}

<script>

window.location.hash="no-back-button";

window.location.hash="Again-No-back-button";//again
because google chrome don't insert first hash into history

window.onhashchange=function(){window.location.hash="no-
back-button";}

document.onkeydown = function (e) {

358
if (e.keyCode === 116) {

return false;

};

</script>
{/literal}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Pembayaran Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a
href="print_unit_payout.php?module=payout&act=print&invoiceNo={$in
voiceNo}&paymentNo={$paymentNo}&paymentID={$paymentID}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>

<a href="pay_out.php"><button class="btn btn-


default pull-right">Close</button></a>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<table cellpadding="3" cellspacing="3" width="100%">

<tr>

<td width="150">NO PAYMENT / TGL</td>

<td width="5">:</td>

<td>{$paymentNo} / {$paymentDate}</td>

</tr>

<tr valign="top">

<td>NOMOR FAKTUR</td>

359
<td>:</td>

<td>{$invoiceNo}</td>

</tr>

<tr valign="top">

<td>PIUTANG</td>

<td>:</td>

<td>{$receive}</td>

</tr>

<tr>

<td>DIBAYARKAN KEPADA</td>

<td>:</td>

<td>{$customerName}</td>

</tr>

<tr>

<td></td>

<td></td>

<td>{$customerAddress}</td>

</tr>

<tr>

<td>PEMBAYARAN</td>

<td>:</td>

<td>{$payType}</td>

</tr>

<tr>

<td>NO REK/CEK/GIRO</td>

<td>:</td>

<td>{$bankNo}</td>

</tr>

360
<tr>

<td>NAMA BANK</td>

<td>:</td>

<td>{$bankName}</td>

</tr>

<tr>

<td>TGL EFEKTIF</td>

<td>:</td>

<td>{$effectiveDate}</td>

</tr>

<tr>

<td>NAMA AKUN</td>

<td>:</td>

<td>{$bankAC}</td>

</tr>

<tr>

<td>JUMLAH</td>

<td>:</td>

<td>{$total}</td>

</tr>

<tr>

<td>REFERENSI</td>

<td>:</td>

<td>{$ref}</td>

</tr>

<tr valign="top">

<td>NOTE</td>

<td>:</td>

361
<td>{$note}</td>

</tr>

</table>

</div><!--
/.box-body -->

{elseif $module ==
'payout' AND $act == 'detailpayout'}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<h3
class="box-title">Pembayaran Transaksi Penjualan</h3>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<a
href="print_unit_payout.php?module=payout&act=print&invoiceNo={$in
voiceNo}&paymentNo={$paymentNo}&paymentID={$paymentID}"
target="_blank"><button class="btn btn-default pull-
right">Print</button></a>

{if $q != ''}

<a
href="pay_out.php?module=payout&act=search&q={$q}"><button
class="btn btn-default pull-right">Back</button></a>

{else}

<a href="pay_out.php?page={$page}"><button
class="btn btn-default pull-right">Back</button></a>

{/if}

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<table cellpadding="3" cellspacing="3" width="100%">

<tr>

<td width="150">NO PAYMENT / TGL</td>

362
<td width="5">:</td>

<td>{$paymentNo} / {$paymentDate}</td>

</tr>

<tr valign="top">

<td>NOMOR FAKTUR</td>

<td>:</td>

<td>{$invoiceNo}</td>

</tr>

<tr valign="top">

<td>PIUTANG</td>

<td>:</td>

<td>{$receive}</td>

</tr>

<tr>

<td>DIBAYARKAN KEPADA</td>

<td>:</td>

<td>{$customerName}</td>

</tr>

<tr>

<td></td>

<td></td>

<td>{$customerAddress}</td>

</tr>

<tr>

<td>PEMBAYARAN</td>

<td>:</td>

<td>{$payType}</td>

</tr>

363
<tr>

<td>NO REK/CEK/GIRO</td>

<td>:</td>

<td>{$bankNo}</td>

</tr>

<tr>

<td>NAMA BANK</td>

<td>:</td>

<td>{$bankName}</td>

</tr>

<tr>

<td>TGL EFEKTIF</td>

<td>:</td>

<td>{$effectiveDate}</td>

</tr>

<tr>

<td>NAMA AKUN</td>

<td>:</td>

<td>{$bankAC}</td>

</tr>

<tr>

<td>JUMLAH</td>

<td>:</td>

<td>{$total}</td>

</tr>

<tr>

<td>REFERENSI</td>

<td>:</td>

364
<td>{$ref}</td>

</tr>

<tr valign="top">

<td>NOTE</td>

<td>:</td>

<td>{$note}</td>

</tr>

</table>

</div><!--
/.box-body -->

{elseif $module ==
'payout' AND $act == 'search'}

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<form method="GET" action="pay_out.php">

<input type="hidden" name="module"


value="payout">

<input type="hidden" name="act"


value="search">

<button type="submit" class="btn btn-


default pull-right"><i class="fa fa-search"></i> Search</button>

<input type="text" value="{$endDate}"


id="endDate" name="endDate" class="form-control"
placeholder="Periode Akhir" style="float: right; width: 115px;">

<input type="text" value="{$startDate}"


id="startDate" name="startDate" class="form-control"
placeholder="Periode Awal" style="float: right; width: 115px;">

<input type="text" value="{$q}" id="q"


name="q" class="form-control" placeholder="Pencarian : Nomor Bukti
Pembayaran" style="float: right; width: 270px;" required>

365
<a href="pay_out.php?module=payout&act=add"
style="float: left;"><button type="button" class="btn btn-default
pull-right"><i class="fa fa-plus"></i> Add</button></a>

<a
href="print_pay_out.php?act=print&q={$q}&startDate={$startDate}&en
dDate={$endDate}" style="float: left;" target="_blank"><button
type="button" class="btn btn-default pull-right"><i class="fa fa-
print"></i> Print PDF</button></a>

&nbsp;&nbsp;&nbsp;

</form>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO <i class="fa fa-


sort"></i></th>

<th>NO PAYMENT <i class="fa fa-


sort"></i></th>

<th>TGL <i class="fa fa-


sort"></i></th>

<th>NO INVOICE <i class="fa fa-


sort"></i></th>

<th>NO SO <i class="fa fa-


sort"></i></th>

<th>VIA <i class="fa fa-


sort"></i></th>

<th>TOTAL <i class="fa fa-


sort"></i></th>

<th>DIBUAT OLEH <i class="fa fa-


sort"></i></th>

366
<th>AKSI</th>

</tr>

</thead>

<tbody>

{section name=dataPay loop=$dataPay}

<tr>

<td>{$dataPay[dataPay].no}</td>

<td>{$dataPay[dataPay].paymentNo}</td>

<td>{$dataPay[dataPay].paymentDate}</td>

<td>{$dataPay[dataPay].invoiceNo}</td>

<td>{$dataPay[dataPay].soNo}</td>

<td>{$dataPay[dataPay].payType}</td>

<td>{$dataPay[dataPay].total}</td>

<td>{$dataPay[dataPay].staffName}</td>

<td>

<a title="Detail"
href="pay_out.php?module=payout&act=detailpayout&paymentID={$dataP
ay[dataPay].paymentID}&invoiceNo={$dataPay[dataPay].invoiceNo}&pay
mentNo={$dataPay[dataPay].paymentNo}&q={$q}&page={$page}"><img
src="img/icons/view.png" width="18"></a>

<a title="Delete"
href="pay_out.php?module=payout&act=delete&invoiceNo={$dataPay[dat
aPay].invoiceNo}&paymentNo={$dataPay[dataPay].paymentNo}&paymentID
={$dataPay[dataPay].paymentID}&q={$q}" onclick="return
confirm('Anda Yakin ingin membatalkan nomor pembayaran
{$dataPay[dataPay].paymentNo}? penghapusan ini akan membatalkan
pembayaran transaksi ini.');"><img src="img/icons/delete.png"
width="18"></a>

</td>

</tr>

367
{/section}

</tbody>

</table>

</div>

</div><!--
/.box-body -->

{else}
<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-right">

<div class="box-footer clearfix no-border">

<form method="GET" action="pay_out.php">

<input type="hidden" name="module"


value="payout">

<input type="hidden" name="act"


value="search">

<button type="submit" class="btn btn-


default pull-right"><i class="fa fa-search"></i> Search</button>

<input type="text" value="{$endDate}"


id="endDate" name="endDate" class="form-control"
placeholder="Periode Akhir" style="float: right; width: 115px;">

<input type="text" value="{$startDate}"


id="startDate" name="startDate" class="form-control"
placeholder="Periode Awal" style="float: right; width: 115px;">

<input type="text" value="{$q}" id="q"


name="q" class="form-control" placeholder="Pencarian : Nomor Bukti
Pembayaran" style="float: right; width: 270px;">

<a href="pay_out.php?module=payout&act=add"
style="float: left;"><button type="button" class="btn btn-default
pull-right"><i class="fa fa-plus"></i> Add</button></a>

<a
href="print_pay_out.php?act=print&q={$q}" style="float: left;"
target="_blank"><button type="button" class="btn btn-default pull-
right"><i class="fa fa-print"></i> Print PDF</button></a>

368
&nbsp;&nbsp;&nbsp;

</form>

</div>

</div>
</div><!--
/.box-header -->

<div
class="box-body">

<div
class="table-responsive">

<table id="example1" class="table table-bordered table-


striped">

<thead>

<tr>

<th>NO <i class="fa fa-


sort"></i></th>

<th>NO PAYMENT <i class="fa fa-


sort"></i></th>

<th>TGL <i class="fa fa-


sort"></i></th>

<th>NO INVOICE <i class="fa fa-


sort"></i></th>

<th>NO SO <i class="fa fa-


sort"></i></th>

<th>VIA <i class="fa fa-


sort"></i></th>

<th>TOTAL <i class="fa fa-


sort"></i></th>

<th>DIBUAT OLEH <i class="fa fa-


sort"></i></th>

<th>AKSI</th>

</tr>

</thead>

<tbody>

{section name=dataPay loop=$dataPay}

369
<tr>

<td>{$dataPay[dataPay].no}</td>

<td>{$dataPay[dataPay].paymentNo}</td>

<td>{$dataPay[dataPay].paymentDate}</td>

<td>{$dataPay[dataPay].invoiceNo}</td>

<td>{$dataPay[dataPay].soNo}</td>

<td>{$dataPay[dataPay].payType}</td>

<td>{$dataPay[dataPay].total}</td>

<td>{$dataPay[dataPay].staffName}</td>

<td>

<a title="Detail"
href="pay_out.php?module=payout&act=detailpayout&paymentID={$dataP
ay[dataPay].paymentID}&invoiceNo={$dataPay[dataPay].invoiceNo}&pay
mentNo={$dataPay[dataPay].paymentNo}&page={$page}"><img
src="img/icons/view.png" width="18"></a>

<a title="Delete"
href="pay_out.php?module=payout&act=delete&invoiceNo={$dataPay[dat
aPay].invoiceNo}&paymentNo={$dataPay[dataPay].paymentNo}&paymentID
={$dataPay[dataPay].paymentID}" onclick="return confirm('Anda
Yakin ingin membatalkan nomor pembayaran
{$dataPay[dataPay].paymentNo}? penghapusan ini akan membatalkan
pembayaran transaksi ini.');"><img src="img/icons/delete.png"
width="18"></a>

</td>

</tr>

{/section}

</tbody>

</table>

</div>

370
</div><!--
/.box-body -->

<div
class="box-header">
<i
class="ion ion-clipboard"></i>
<div
class="box-tools pull-left">

<ul class="pagination pagination-sm inline">

{$pageLink}

</ul>

</div>
</div><!--
/.box-header -->
{/if}

</div><!-- /.box -->

</section><!-- /.Left col -->


</div><!-- /.row (main row) -->
</section><!-- /.content -->
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

{include file="footer.tpl"}

Hasil seluruh skrip diatas akan menghasilkan halaman pembayaran transaksi


penjualan seperti yang bisa dilihat pada gambar-gambar berikut :

371
Gambar 5.37. Pembayaran transaksi penjualan

Gambar 5.38. Cetak pembayaran transaksi penjualan

372

Anda mungkin juga menyukai