1. Deskripsi sistem:
Framework : CodeIgniter versi 3.0.6
php: php versi 5.6
nama: Kasku
deskripsi : sistem informasi pencatatan transaksi penjualan dan stok lada oleh CV Ada Jalan Terang (lada Ibu)
2. Asumsi:
Situs ini dapat dipergunakan untuk mencatat segala bentuk transaksi seperti:
- Melakukan Penjualan
- Update Barang dan Stok
- Mencetak laporan keuangan
- Mencetak struk pembelian
- Melihat histori transaksi
Situs ini memiliki user berupa:
- Administrator: dapat mengatur segala flow transaksi di situs
- Akuntan: dapat mengatur laporan keuangan, melihat histori transaksi, dan melihat stok barang
- Kasir: dapat mengatur transaksi penjualan dan pelanggan
- Gudang: dapat mengatur ketersediaan barang
Masing-masing user memiliki tampilan yang berbeda karena tugas yang berbeda
3. Fitur:
- Login dengan 4 jenis user
- Transaksi Penjualan: Transaksi, Histori Penjualan, Data Pelanggan, Laporan Keuangan
- Pencatatan Barang: Update stok(menambah barang, menghapus barang, mengedit barang), melihat stock
- Menambahkan user (untuk admin)
- logout
4. Dokumentasi:
Pertama, membuat database. karena menggunakan hosting, maka jika belum mempunyai hosting, bisa menggunakan free hosting di https://www.000webhost.com/. setelah membuat akun, buatlah nama project yang akan menjadi domain kalian. sertakan password yang mudah diingat.
setelah akun terbuat, upload folder yang berisikan framework yang telah dibuat. lalu buat database nya pada menu Tools > Database Manager.
lalu impor file sql yang digunakan (file sql terdapat pada dokumentasi kode di bawah)
pindah folder yang telah di upload ke folder public_html. dan lakukan konfigurasi pada database.php untuk menghubungkan database dengan situs yang dibuat.
tampilan web:
1. Halaman login:
Daftar akun yang telah terdaftar:
Username: admin
Password: admin
Username: kasir
Password: kasir
Username: gudang
Password: gudang
Username: akuntan
Password: akuntan
2. Halaman yang dapat diakses admin:
Halaman Penjualan
Cetak Penjualan
Hasil Cetak Penjualan
Halaman histori transaksi
halaman list produk
halaman edit list produk
halaman tambah produk
halaman tambah pelanggan
halaman edit pelanggan
halaman list pelanggan
halaman laporan keuangan
hasil download laporan keuangan
halaman daftar user
halaman tambah user
halaman edit user
halaman ubah password
3. Halaman yang dapat diakses kasir:
Halaman Penjualan kasir
Halaman list produk
Halaman list pelanggan
Halaman histori transaksi
Halaman edit pelanggan
Halaman edit pelanggan
Halaman ganti password
4. Halaman yang dapat diakses Gudang:
Halaman list produk
Halaman tambah produk
Halaman Edit produk
Halaman ubah password
5. Halaman yang dapat diakses akuntan:
Halaman list pelanggan
Halaman histori transaksi
Halaman laporan keuangan
Halaman list produk
Halaman ubah password
6. Dokumentasi Source Code:
- Model : adalah class yang membantu CRUD (create, read, update, dan delete) untuk terhubung dengan database. di source code ini terdapat 8 model yaitu:
- M_akses.php : digunakan untuk menghubungkan data pada pj_akses
<?php
class M_akses extends CI_Model
{
function get_all()
{
return $this->db
->where('id_akses !=', 1)
->order_by('level_akses', 'asc')
->get('pj_akses');
}
}
- M_barang: digunakan untuk menghubungkan data pada pj_barang
<?php
class M_barang extends CI_Model
{
function fetch_data_barang($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
a.`id_barang`,
a.`kode_barang`,
a.`nama_barang`,
IF(a.`total_stok` = 0, 'Kosong', a.`total_stok`) AS total_stok,
CONCAT('Rp. ', REPLACE(FORMAT(a.`harga`, 0),',','.') ) AS harga,
a.`keterangan`,
b.`kategori`,
IF(c.`merk` IS NULL, '-', c.`merk` ) AS merk
FROM
`pj_barang` AS a
LEFT JOIN `pj_kategori_barang` AS b ON a.`id_kategori_barang` = b.`id_kategori_barang`
LEFT JOIN `pj_merk_barang` AS c ON a.`id_merk_barang` = c.`id_merk_barang`
, (SELECT @row := 0) r WHERE 1=1
AND a.`dihapus` = 'tidak'
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
a.`kode_barang` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`nama_barang` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR IF(a.`total_stok` = 0, 'Kosong', a.`total_stok`) LIKE '%".$this->db->escape_like_str($like_value)."%'
OR CONCAT('Rp. ', REPLACE(FORMAT(a.`harga`, 0),',','.') ) LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`keterangan` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR b.`kategori` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR c.`merk` LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'a.`kode_barang`',
2 => 'a.`nama_barang`',
3 => 'b.`kategori`',
4 => 'c.`merk`',
5 => 'a.`total_stok`',
6 => '`harga`',
7 => 'a.`keterangan`'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function hapus_barang($id_barang)
{
$dt['dihapus'] = 'ya';
return $this->db
->where('id_barang', $id_barang)
->update('pj_barang', $dt);
}
function tambah_baru($kode, $nama, $id_kategori_barang, $id_merk_barang, $stok, $harga, $keterangan)
{
$dt = array(
'kode_barang' => $kode,
'nama_barang' => $nama,
'total_stok' => $stok,
'harga' => $harga,
'id_kategori_barang' => $id_kategori_barang,
'id_merk_barang' => (empty($id_merk_barang)) ? NULL : $id_merk_barang,
'keterangan' => $keterangan,
'dihapus' => 'tidak'
);
return $this->db->insert('pj_barang', $dt);
}
function cek_kode($kode)
{
return $this->db
->select('id_barang')
->where('kode_barang', $kode)
->where('dihapus', 'tidak')
->limit(1)
->get('pj_barang');
}
function get_baris($id_barang)
{
return $this->db
->select('id_barang, kode_barang, nama_barang, total_stok, harga, id_kategori_barang, id_merk_barang, keterangan')
->where('id_barang', $id_barang)
->limit(1)
->get('pj_barang');
}
function update_barang($id_barang, $kode_barang, $nama, $id_kategori_barang, $id_merk_barang, $stok, $harga, $keterangan)
{
$dt = array(
'kode_barang' => $kode_barang,
'nama_barang' => $nama,
'total_stok' => $stok,
'harga' => $harga,
'id_kategori_barang' => $id_kategori_barang,
'id_merk_barang' => (empty($id_merk_barang)) ? NULL : $id_merk_barang,
'keterangan' => $keterangan
);
return $this->db
->where('id_barang', $id_barang)
->update('pj_barang', $dt);
}
function cari_kode($keyword, $registered)
{
$not_in = '';
$koma = explode(',', $registered);
if(count($koma) > 1)
{
$not_in .= " AND `kode_barang` NOT IN (";
foreach($koma as $k)
{
$not_in .= " '".$k."', ";
}
$not_in = rtrim(trim($not_in), ',');
$not_in = $not_in.")";
}
if(count($koma) == 1)
{
$not_in .= " AND `kode_barang` != '".$registered."' ";
}
$sql = "
SELECT
`kode_barang`, `nama_barang`, `harga`
FROM
`pj_barang`
WHERE
`dihapus` = 'tidak'
AND `total_stok` > 0
AND (
`kode_barang` LIKE '%".$this->db->escape_like_str($keyword)."%'
OR `nama_barang` LIKE '%".$this->db->escape_like_str($keyword)."%'
)
".$not_in."
";
return $this->db->query($sql);
}
function get_stok($kode)
{
return $this->db
->select('nama_barang, total_stok')
->where('kode_barang', $kode)
->limit(1)
->get('pj_barang');
}
function get_id($kode_barang)
{
return $this->db
->select('id_barang, nama_barang')
->where('kode_barang', $kode_barang)
->limit(1)
->get('pj_barang');
}
function update_stok($id_barang, $jumlah_beli)
{
$sql = "
UPDATE `pj_barang` SET `total_stok` = `total_stok` - ".$jumlah_beli." WHERE `id_barang` = '".$id_barang."'
";
return $this->db->query($sql);
}
}
- M_kategori_barang: digunakan untuk menghubungkan data pada pj_kategori_barang
<?php
class M_kategori_barang extends CI_Model
{
function get_all()
{
return $this->db
->select('id_kategori_barang, kategori')
->where('dihapus', 'tidak')
->order_by('kategori', 'asc')
->get('pj_kategori_barang');
}
function fetch_data_kategori($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
id_kategori_barang,
kategori
FROM
`pj_kategori_barang`, (SELECT @row := 0) r WHERE 1=1
AND dihapus = 'tidak'
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
kategori LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'kategori'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function tambah_kategori($kategori)
{
$dt = array(
'kategori' => $kategori,
'dihapus' => 'tidak'
);
return $this->db->insert('pj_kategori_barang', $dt);
}
function hapus_kategori($id_kategori_barang)
{
$dt = array(
'dihapus' => 'ya'
);
return $this->db
->where('id_kategori_barang', $id_kategori_barang)
->update('pj_kategori_barang', $dt);
}
function get_baris($id_kategori_barang)
{
return $this->db
->select('id_kategori_barang, kategori')
->where('id_kategori_barang', $id_kategori_barang)
->limit(1)
->get('pj_kategori_barang');
}
function update_kategori($id_kategori_barang, $kategori)
{
$dt = array(
'kategori' => $kategori
);
return $this->db
->where('id_kategori_barang', $id_kategori_barang)
->update('pj_kategori_barang', $dt);
}
}
- M_Merk_Barang: digunakan untuk menghubungkan data pada pj_merk_barang
<?php
class M_merk_barang extends CI_Model
{
function get_all()
{
return $this->db
->select('id_merk_barang, merk')
->where('dihapus', 'tidak')
->order_by('merk', 'asc')
->get('pj_merk_barang');
}
function fetch_data_merek($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
id_merk_barang,
merk
FROM
`pj_merk_barang`, (SELECT @row := 0) r WHERE 1=1
AND dihapus = 'tidak'
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
merk LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'merk'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function tambah_merek($merek)
{
$dt = array(
'merk' => $merek,
'dihapus' => 'tidak'
);
return $this->db->insert('pj_merk_barang', $dt);
}
function hapus_merek($id_merk_barang)
{
$dt = array(
'dihapus' => 'ya'
);
return $this->db
->where('id_merk_barang', $id_merk_barang)
->update('pj_merk_barang', $dt);
}
function get_baris($id_merk_barang)
{
return $this->db
->select('id_merk_barang, merk')
->where('id_merk_barang', $id_merk_barang)
->limit(1)
->get('pj_merk_barang');
}
function update_merek($id_merk_barang, $merek)
{
$dt = array(
'merk' => $merek
);
return $this->db
->where('id_merk_barang', $id_merk_barang)
->update('pj_merk_barang', $dt);
}
}
- M_pelanggan: digunakan untuk menghubungkan data pada pj_pelanggan
<?php
class M_pelanggan extends CI_Model
{
function get_all()
{
return $this->db
->select('id_pelanggan, nama, alamat, telp, info_tambahan')
->where('dihapus', 'tidak')
->order_by('nama','asc')
->get('pj_pelanggan');
}
function get_baris($id_pelanggan)
{
return $this->db
->select('id_pelanggan, nama, alamat, telp, info_tambahan')
->where('id_pelanggan', $id_pelanggan)
->limit(1)
->get('pj_pelanggan');
}
function fetch_data_pelanggan($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
a.`id_pelanggan`,
a.`nama`,
a.`alamat`,
a.`telp`,
a.`info_tambahan`,
DATE_FORMAT(a.`waktu_input`, '%d %b %Y - %H:%i:%s') AS waktu_input
FROM
`pj_pelanggan` AS a
, (SELECT @row := 0) r WHERE 1=1
AND a.`dihapus` = 'tidak'
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
a.`nama` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`alamat` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`telp` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`info_tambahan` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR DATE_FORMAT(a.`waktu_input`, '%d %b %Y - %H:%i:%s') LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'a.`nama`',
2 => 'a.`alamat`',
3 => 'a.`telp`',
4 => 'a.`info_tambahan`',
5 => 'a.`waktu_input`'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function tambah_pelanggan($nama, $alamat, $telepon, $info, $unique)
{
date_default_timezone_set("Asia/Jakarta");
$dt = array(
'nama' => $nama,
'alamat' => $alamat,
'telp' => $telepon,
'info_tambahan' => $info,
'waktu_input' => date('Y-m-d H:i:s'),
'dihapus' => 'tidak',
'kode_unik' => $unique
);
return $this->db->insert('pj_pelanggan', $dt);
}
function update_pelanggan($id_pelanggan, $nama, $alamat, $telepon, $info)
{
$dt = array(
'nama' => $nama,
'alamat' => $alamat,
'telp' => $telepon,
'info_tambahan' => $info
);
return $this->db
->where('id_pelanggan', $id_pelanggan)
->update('pj_pelanggan', $dt);
}
function hapus_pelanggan($id_pelanggan)
{
$dt = array(
'dihapus' => 'ya'
);
return $this->db
->where('id_pelanggan', $id_pelanggan)
->update('pj_pelanggan', $dt);
}
function get_dari_kode($kode_unik)
{
return $this->db
->select('id_pelanggan')
->where('kode_unik', $kode_unik)
->limit(1)
->get('pj_pelanggan');
}
}
- M_penjualan_detail: digunakan untuk menghubungkan data pada pj_penjualan_detail
<?php
class M_penjualan_detail extends CI_Model
{
function insert_detail($id_master, $id_barang, $jumlah_beli, $harga_satuan, $sub_total)
{
$dt = array(
'id_penjualan_m' => $id_master,
'id_barang ' => $id_barang,
'jumlah_beli' => $jumlah_beli,
'harga_satuan' => $harga_satuan,
'total' => $sub_total
);
return $this->db->insert('pj_penjualan_detail', $dt);
}
function get_detail($id_penjualan)
{
$sql = "
SELECT
b.`kode_barang`,
b.`nama_barang`,
CONCAT('Rp. ', REPLACE(FORMAT(a.`harga_satuan`, 0),',','.') ) AS harga_satuan,
a.`harga_satuan` AS harga_satuan_asli,
a.`jumlah_beli`,
CONCAT('Rp. ', REPLACE(FORMAT(a.`total`, 0),',','.') ) AS sub_total,
a.`total` AS sub_total_asli
FROM
`pj_penjualan_detail` a
LEFT JOIN `pj_barang` b ON a.`id_barang` = b.`id_barang`
WHERE
a.`id_penjualan_m` = '".$id_penjualan."'
ORDER BY
a.`id_penjualan_d` ASC
";
return $this->db->query($sql);
}
}
- M_penjualan_master: digunakan untuk menghubungkan data pada pj_penjualan_master
<?php
class M_penjualan_master extends CI_Model
{
function insert_master($nomor_nota, $tanggal, $id_kasir, $id_pelanggan, $bayar, $grand_total, $catatan)
{
$dt = array(
'nomor_nota' => $nomor_nota,
'tanggal' => $tanggal,
'grand_total' => $grand_total,
'bayar' => $bayar,
'keterangan_lain' => $catatan,
'id_pelanggan' => (empty($id_pelanggan)) ? NULL : $id_pelanggan,
'id_user' => $id_kasir
);
return $this->db->insert('pj_penjualan_master', $dt);
}
function get_id($nomor_nota)
{
return $this->db
->select('id_penjualan_m')
->where('nomor_nota', $nomor_nota)
->limit(1)
->get('pj_penjualan_master');
}
function fetch_data_penjualan($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
a.`id_penjualan_m`,
a.`nomor_nota` AS nomor_nota,
DATE_FORMAT(a.`tanggal`, '%d %b %Y - %H:%i:%s') AS tanggal,
CONCAT('Rp. ', REPLACE(FORMAT(a.`grand_total`, 0),',','.') ) AS grand_total,
IF(b.`nama` IS NULL, 'Umum', b.`nama`) AS nama_pelanggan,
c.`nama` AS kasir,
a.`keterangan_lain` AS keterangan
FROM
`pj_penjualan_master` AS a
LEFT JOIN `pj_pelanggan` AS b ON a.`id_pelanggan` = b.`id_pelanggan`
LEFT JOIN `pj_user` AS c ON a.`id_user` = c.`id_user`
, (SELECT @row := 0) r WHERE 1=1
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
a.`nomor_nota` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR DATE_FORMAT(a.`tanggal`, '%d %b %Y - %H:%i:%s') LIKE '%".$this->db->escape_like_str($like_value)."%'
OR CONCAT('Rp. ', REPLACE(FORMAT(a.`grand_total`, 0),',','.') ) LIKE '%".$this->db->escape_like_str($like_value)."%'
OR IF(b.`nama` IS NULL, 'Umum', b.`nama`) LIKE '%".$this->db->escape_like_str($like_value)."%'
OR c.`nama` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`keterangan_lain` LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'a.`tanggal`',
2 => 'nomor_nota',
3 => 'a.`grand_total`',
4 => 'nama_pelanggan',
5 => 'keterangan',
6 => 'kasir'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function get_baris($id_penjualan)
{
$sql = "
SELECT
a.`nomor_nota`,
a.`grand_total`,
a.`tanggal`,
a.`bayar`,
a.`id_user` AS id_kasir,
a.`id_pelanggan`,
a.`keterangan_lain` AS catatan,
b.`nama` AS nama_pelanggan,
b.`alamat` AS alamat_pelanggan,
b.`telp` AS telp_pelanggan,
b.`info_tambahan` AS info_pelanggan
FROM
`pj_penjualan_master` AS a
LEFT JOIN `pj_pelanggan` AS b ON a.`id_pelanggan` = b.`id_pelanggan`
WHERE
a.`id_penjualan_m` = '".$id_penjualan."'
LIMIT 1
";
return $this->db->query($sql);
}
function hapus_transaksi($id_penjualan, $reverse_stok)
{
if($reverse_stok == 'yes'){
$loop = $this->db
->select('id_barang, jumlah_beli')
->where('id_penjualan_m', $id_penjualan)
->get('pj_penjualan_detail');
foreach($loop->result() as $b)
{
$sql = "
UPDATE `pj_barang` SET `total_stok` = `total_stok` + ".$b->jumlah_beli."
WHERE `id_barang` = '".$b->id_barang."'
";
$this->db->query($sql);
}
}
$this->db->where('id_penjualan_m', $id_penjualan)->delete('pj_penjualan_detail');
return $this->db
->where('id_penjualan_m', $id_penjualan)
->delete('pj_penjualan_master');
}
function laporan_penjualan($from, $to)
{
$sql = "
SELECT
DISTINCT(SUBSTR(a.`tanggal`, 1, 10)) AS tanggal,
(
SELECT
SUM(b.`grand_total`)
FROM
`pj_penjualan_master` AS b
WHERE
SUBSTR(b.`tanggal`, 1, 10) = SUBSTR(a.`tanggal`, 1, 10)
LIMIT 1
) AS total_penjualan
FROM
`pj_penjualan_master` AS a
WHERE
SUBSTR(a.`tanggal`, 1, 10) >= '".$from."'
AND SUBSTR(a.`tanggal`, 1, 10) <= '".$to."'
ORDER BY
a.`tanggal` ASC
";
return $this->db->query($sql);
}
function cek_nota_validasi($nota)
{
return $this->db->select('nomor_nota')->where('nomor_nota', $nota)->limit(1)->get('pj_penjualan_master');
}
}
- M_user: digunakan untuk menghubungkan data pada pj_user
<?php
class M_user extends CI_Model
{
function validasi_login($username, $password)
{
return $this->db
->select('a.id_user, a.username, a.password, a.nama, b.label AS level, b.level_akses AS level_caption', false)
->join('pj_akses b', 'a.id_akses = b.id_akses', 'left')
->where('a.username', $username)
->where('a.password', sha1($password))
->where('a.status', 'Aktif')
->where('a.dihapus', 'tidak')
->limit(1)
->get('pj_user a');
}
function is_valid($u, $p)
{
return $this->db
->select('id_user')
->where('id_user', $u)
->where('password', $p)
->where('status','Aktif')
->where('dihapus','tidak')
->limit(1)
->get('pj_user');
}
function list_kasir()
{
return $this->db
->select('id_user, nama')
->where('status', 'Aktif')
->where('dihapus', 'tidak')
->order_by('nama','asc')
->get('pj_user');
}
function fetch_data_user($like_value = NULL, $column_order = NULL, $column_dir = NULL, $limit_start = NULL, $limit_length = NULL)
{
$sql = "
SELECT
(@row:=@row+1) AS nomor,
a.`id_user`,
a.`username`,
a.`nama`,
a.`status`,
b.`level_akses`,
b.`label`
FROM
`pj_user` AS a
LEFT JOIN `pj_akses` AS b ON a.`id_akses` = b.`id_akses`
, (SELECT @row := 0) r WHERE 1=1
AND a.`dihapus` = 'tidak'
";
$data['totalData'] = $this->db->query($sql)->num_rows();
if( ! empty($like_value))
{
$sql .= " AND ( ";
$sql .= "
a.`username` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`nama` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR a.`status` LIKE '%".$this->db->escape_like_str($like_value)."%'
OR b.`level_akses` LIKE '%".$this->db->escape_like_str($like_value)."%'
";
$sql .= " ) ";
}
$data['totalFiltered'] = $this->db->query($sql)->num_rows();
$columns_order_by = array(
0 => 'nomor',
1 => 'a.`username`',
2 => 'a.`nama`',
3 => 'b.`level_akses`',
4 => 'a.`status`'
);
$sql .= " ORDER BY ".$columns_order_by[$column_order]." ".$column_dir.", nomor ";
$sql .= " LIMIT ".$limit_start." ,".$limit_length." ";
$data['query'] = $this->db->query($sql);
return $data;
}
function hapus_user($id_user)
{
$dt['dihapus'] = 'ya';
return $this->db
->where('id_user', $id_user)
->update('pj_user', $dt);
}
function cek_username($username)
{
return $this->db
->select('id_user')
->where('username', $username)
->where('dihapus', 'tidak')
->limit(1)
->get('pj_user');
}
function tambah_baru($username, $password, $nama, $id_akses, $status)
{
$dt = array(
'username' => $username,
'password' => sha1($password),
'nama' => $nama,
'id_akses' => $id_akses,
'status' => $status,
'dihapus' => 'tidak'
);
return $this->db->insert('pj_user', $dt);
}
function get_baris($id_user)
{
$sql = "
SELECT
a.`id_user`,
a.`username`,
a.`nama`,
a.`id_akses`,
a.`status`,
b.`label`
FROM
`pj_user` a
LEFT JOIN `pj_akses` b ON a.`id_akses` = b.`id_akses`
WHERE
a.`id_user` = '".$id_user."'
LIMIT 1
";
return $this->db->query($sql);
}
function update_user($id_user, $username, $password, $nama, $id_akses, $status)
{
$dt['username'] = $username;
if( ! empty($password)){
$dt['password'] = sha1($password);
}
$dt['nama'] = $nama;
$dt['id_akses'] = $id_akses;
$dt['status'] = $status;
return $this->db
->where('id_user', $id_user)
->update('pj_user', $dt);
}
function cek_password($pass)
{
return $this->db
->select('id_user')
->where('password', sha1($pass))
->where('id_user', $this->session->userdata('ap_id_user'))
->limit(1)
->get('pj_user');
}
function update_password($pass_new)
{
$dt['password'] = sha1($pass_new);
return $this->db
->where('id_user', $this->session->userdata('ap_id_user'))
->update('pj_user', $dt);
}
}
- Controller: adalah bagian codeigniter yang bertugas untuk menangani HTTP Request dan menghubungkan model dengan view. di source code ini terdapat 5 controller:
Barang.php: berisikan method untuk mengatur fitur yang berkaitan dengan barang seperti: menampilkan barang, menghapus barang, mengedit barang, menambah barang, dan lain sebagainya.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Barang extends MY_Controller
{
public function index()
{
$this->load->view('barang/barang_data');
}
public function barang_json()
{
$this->load->model('m_barang');
$level = $this->session->userdata('ap_level');
$requestData = $_REQUEST;
$fetch = $this->m_barang->fetch_data_barang($requestData['search']['value'], $requestData['order'][0]['column'], $requestData['order'][0]['dir'], $requestData['start'], $requestData['length']);
$totalData = $fetch['totalData'];
$totalFiltered = $fetch['totalFiltered'];
$query = $fetch['query'];
$data = array();
foreach($query->result_array() as $row)
{
$nestedData = array();
$nestedData[] = $row['nomor'];
$nestedData[] = $row['kode_barang'];
$nestedData[] = $row['nama_barang'];
$nestedData[] = $row['kategori'];
$nestedData[] = $row['merk'];
$nestedData[] = ($row['total_stok'] == 'Kosong') ? "<font color='red'><b>".$row['total_stok']."</b></font>" : $row['total_stok'];
$nestedData[] = $row['harga'];
$nestedData[] = preg_replace("/\r\n|\r|\n/",'<br />', $row['keterangan']);
if($level == 'admin' OR $level == 'inventory')
{
$nestedData[] = "<a href='".site_url('barang/edit/'.$row['id_barang'])."' id='EditBarang'><i class='fa fa-pencil'></i> Edit</a>";
$nestedData[] = "<a href='".site_url('barang/hapus/'.$row['id_barang'])."' id='HapusBarang'><i class='fa fa-trash-o'></i> Hapus</a>";
}
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}
public function hapus($id_barang)
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_barang');
$hapus = $this->m_barang->hapus_barang($id_barang);
if($hapus)
{
echo json_encode(array(
"pesan" => "<font color='green'><i class='fa fa-check'></i> Data berhasil dihapus !</font>
"));
}
else
{
echo json_encode(array(
"pesan" => "<font color='red'><i class='fa fa-warning'></i> Terjadi kesalahan, coba lagi !</font>
"));
}
}
}
}
public function tambah()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($_POST)
{
$this->load->library('form_validation');
$no = 0;
foreach($_POST['kode'] as $kode)
{
$this->form_validation->set_rules('kode['.$no.']','Kode Barang #'.($no + 1),'trim|required|alpha_numeric|max_length[40]|callback_exist_kode[kode['.$no.']]');
$this->form_validation->set_rules('nama['.$no.']','Nama Barang #'.($no + 1),'trim|required|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('id_kategori_barang['.$no.']','Kategori #'.($no + 1),'trim|required');
$this->form_validation->set_rules('id_merk_barang['.$no.']','Merek #'.($no + 1),'trim');
$this->form_validation->set_rules('stok['.$no.']','Stok #'.($no + 1),'trim|required|numeric|max_length[10]|callback_cek_titik[stok['.$no.']]');
$this->form_validation->set_rules('harga['.$no.']','Harga #'.($no + 1),'trim|required|numeric|min_length[4]|max_length[10]|callback_cek_titik[harga['.$no.']]');
$this->form_validation->set_rules('keterangan['.$no.']','Keterangan #'.($no + 1),'trim|max_length[2000]');
$no++;
}
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('numeric','%s harus angka !');
$this->form_validation->set_message('exist_kode','%s sudah ada di database, pilih kode lain yang unik !');
$this->form_validation->set_message('cek_titik','%s harus angka, tidak boleh ada titik !');
$this->form_validation->set_message('alpha_numeric_spaces', '%s Harus huruf / angka !');
$this->form_validation->set_message('alpha_numeric', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$this->load->model('m_barang');
$no_array = 0;
$inserted = 0;
foreach($_POST['kode'] as $k)
{
$kode = $_POST['kode'][$no_array];
$nama = $_POST['nama'][$no_array];
$id_kategori_barang = $_POST['id_kategori_barang'][$no_array];
$id_merk_barang = $_POST['id_merk_barang'][$no_array];
$stok = $_POST['stok'][$no_array];
$harga = $_POST['harga'][$no_array];
$keterangan = $this->clean_tag_input($_POST['keterangan'][$no_array]);
$insert = $this->m_barang->tambah_baru($kode, $nama, $id_kategori_barang, $id_merk_barang, $stok, $harga, $keterangan);
if($insert){
$inserted++;
}
$no_array++;
}
if($inserted > 0)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<i class='fa fa-check' style='color:green;'></i> Data barang berhasil dismpan."
));
}
else
{
$this->query_error("Oops, terjadi kesalahan, coba lagi !");
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->model('m_kategori_barang');
$this->load->model('m_merk_barang');
$dt['kategori'] = $this->m_kategori_barang->get_all();
$dt['merek'] = $this->m_merk_barang->get_all();
$this->load->view('barang/barang_tambah', $dt);
}
}
else
{
exit();
}
}
public function ajax_cek_kode()
{
if($this->input->is_ajax_request())
{
$kode = $this->input->post('kodenya');
$this->load->model('m_barang');
$cek_kode = $this->m_barang->cek_kode($kode);
if($cek_kode->num_rows() > 0)
{
echo json_encode(array(
'status' => 0,
'pesan' => "<font color='red'>Kode sudah ada</font>"
));
}
else
{
echo json_encode(array(
'status' => 1,
'pesan' => ''
));
}
}
}
public function exist_kode($kode)
{
$this->load->model('m_barang');
$cek_kode = $this->m_barang->cek_kode($kode);
if($cek_kode->num_rows() > 0)
{
return FALSE;
}
return TRUE;
}
public function cek_titik($angka)
{
$pecah = explode('.', $angka);
if(count($pecah) > 1){
return FALSE;
}
return TRUE;
}
public function edit($id_barang = NULL)
{
if( ! empty($id_barang))
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_barang');
if($_POST)
{
$this->load->library('form_validation');
$kode_barang = $this->input->post('kode_barang');
$kode_barang_old = $this->input->post('kode_barang_old');
$callback = '';
if($kode_barang !== $kode_barang_old){
$callback = "|callback_exist_kode[kode_barang]";
}
$this->form_validation->set_rules('kode_barang','Kode Barang','trim|required|alpha_numeric|max_length[40]'.$callback);
$this->form_validation->set_rules('nama_barang','Nama Barang','trim|required|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('id_kategori_barang','Kategori','trim|required');
$this->form_validation->set_rules('id_merk_barang','Merek','trim');
$this->form_validation->set_rules('total_stok','Stok','trim|required|numeric|max_length[10]|callback_cek_titik[total_stok]');
$this->form_validation->set_rules('harga','Harga','trim|required|numeric|min_length[4]|max_length[10]|callback_cek_titik[harga]');
$this->form_validation->set_rules('keterangan','Keterangan','trim|max_length[2000]');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('numeric','%s harus angka !');
$this->form_validation->set_message('exist_kode','%s sudah ada di database, pilih kode lain yang unik !');
$this->form_validation->set_message('cek_titik','%s harus angka, tidak boleh ada titik !');
$this->form_validation->set_message('alpha_numeric_spaces', '%s Harus huruf / angka !');
$this->form_validation->set_message('alpha_numeric', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$nama = $this->input->post('nama_barang');
$id_kategori_barang = $this->input->post('id_kategori_barang');
$id_merk_barang = $this->input->post('id_merk_barang');
$stok = $this->input->post('total_stok');
$harga = $this->input->post('harga');
$keterangan = $this->clean_tag_input($this->input->post('keterangan'));
$update = $this->m_barang->update_barang($id_barang, $kode_barang, $nama, $id_kategori_barang, $id_merk_barang, $stok, $harga, $keterangan);
if($update)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> Data barang berhasil diupdate.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->model('m_kategori_barang');
$this->load->model('m_merk_barang');
$dt['barang'] = $this->m_barang->get_baris($id_barang)->row();
$dt['kategori'] = $this->m_kategori_barang->get_all();
$dt['merek'] = $this->m_merk_barang->get_all();
$this->load->view('barang/barang_edit', $dt);
}
}
}
}
}
public function list_kategori()
{
$this->load->view('barang/kategori/kategori_data');
}
public function list_kategori_json()
{
$this->load->model('m_kategori_barang');
$level = $this->session->userdata('ap_level');
$requestData = $_REQUEST;
$fetch = $this->m_kategori_barang->fetch_data_kategori($requestData['search']['value'], $requestData['order'][0]['column'], $requestData['order'][0]['dir'], $requestData['start'], $requestData['length']);
$totalData = $fetch['totalData'];
$totalFiltered = $fetch['totalFiltered'];
$query = $fetch['query'];
$data = array();
foreach($query->result_array() as $row)
{
$nestedData = array();
$nestedData[] = $row['nomor'];
$nestedData[] = $row['kategori'];
if($level == 'admin' OR $level == 'inventory')
{
$nestedData[] = "<a href='".site_url('barang/edit-kategori/'.$row['id_kategori_barang'])."' id='EditKategori'><i class='fa fa-pencil'></i> Edit</a>";
$nestedData[] = "<a href='".site_url('barang/hapus-kategori/'.$row['id_kategori_barang'])."' id='HapusKategori'><i class='fa fa-trash-o'></i> Hapus</a>";
}
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}
public function tambah_kategori()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('kategori','Kategori','trim|required|max_length[40]|alpha_numeric_spaces');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('alpha_numeric_spaces', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$this->load->model('m_kategori_barang');
$kategori = $this->input->post('kategori');
$insert = $this->m_kategori_barang->tambah_kategori($kategori);
if($insert)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> <b>".$kategori."</b> berhasil ditambahkan.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->view('barang/kategori/kategori_tambah');
}
}
}
public function hapus_kategori($id_kategori_barang)
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_kategori_barang');
$hapus = $this->m_kategori_barang->hapus_kategori($id_kategori_barang);
if($hapus)
{
echo json_encode(array(
"pesan" => "<font color='green'><i class='fa fa-check'></i> Data berhasil dihapus !</font>
"));
}
else
{
echo json_encode(array(
"pesan" => "<font color='red'><i class='fa fa-warning'></i> Terjadi kesalahan, coba lagi !</font>
"));
}
}
}
}
public function edit_kategori($id_kategori_barang = NULL)
{
if( ! empty($id_kategori_barang))
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'inventory')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_kategori_barang');
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('kategori','Kategori','trim|required|max_length[40]|alpha_numeric_spaces');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('alpha_numeric_spaces', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$kategori = $this->input->post('kategori');
$insert = $this->m_kategori_barang->update_kategori($id_kategori_barang, $kategori);
if($insert)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> Data berhasil diupdate.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$dt['kategori'] = $this->m_kategori_barang->get_baris($id_kategori_barang)->row();
$this->load->view('barang/kategori/kategori_edit', $dt);
}
}
}
}
}
public function cek_stok()
{
if($this->input->is_ajax_request())
{
$this->load->model('m_barang');
$kode = $this->input->post('kode_barang');
$stok = $this->input->post('stok');
$get_stok = $this->m_barang->get_stok($kode);
if($stok > $get_stok->row()->total_stok)
{
echo json_encode(array('status' => 0, 'pesan' => "Stok untuk <b>".$get_stok->row()->nama_barang."</b> saat ini hanya tersisa <b>".$get_stok->row()->total_stok."</b> !"));
}
else
{
echo json_encode(array('status' => 1));
}
}
}
}
Laporan.php: berisikan method untuk mengatur fitur laporan keuangan seperti: list laporan penjualan, dan mengekspor data ke excel dan pdf.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Laporan extends MY_Controller
{
function __construct()
{
parent::__construct();
$level = $this->session->userdata('ap_level');
$allowed = array('admin', 'keuangan');
if( ! in_array($level, $allowed))
{
redirect();
}
}
public function index()
{
$this->load->view('laporan/form_laporan');
}
public function penjualan($from, $to)
{
$this->load->model('m_penjualan_master');
$dt['penjualan'] = $this->m_penjualan_master->laporan_penjualan($from, $to);
$dt['from'] = date('d F Y', strtotime($from));
$dt['to'] = date('d F Y', strtotime($to));
$this->load->view('laporan/laporan_penjualan', $dt);
}
public function excel($from, $to)
{
$this->load->model('m_penjualan_master');
$penjualan = $this->m_penjualan_master->laporan_penjualan($from, $to);
if($penjualan->num_rows() > 0)
{
$filename = 'Laporan_Penjualan_'.$from.'_'.$to;
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=".$filename.".xls");
echo "
<h4>Laporan Penjualan Tanggal ".date('d/m/Y', strtotime($from))." - ".date('d/m/Y', strtotime($to))."</h4>
<table border='1' width='100%'>
<thead>
<tr>
<th>No</th>
<th>Tanggal</th>
<th>Total Penjualan</th>
</tr>
</thead>
<tbody>
";
$no = 1;
$total_penjualan = 0;
foreach($penjualan->result() as $p)
{
echo "
<tr>
<td>".$no."</td>
<td>".date('d F Y', strtotime($p->tanggal))."</td>
<td>Rp. ".str_replace(",", ".", number_format($p->total_penjualan))."</td>
</tr>
";
$total_penjualan = $total_penjualan + $p->total_penjualan;
$no++;
}
echo "
<tr>
<td colspan='2'><b>Total Seluruh Penjualan</b></td>
<td><b>Rp. ".str_replace(",", ".", number_format($total_penjualan))."</b></td>
</tr>
</tbody>
</table>
";
}
}
public function pdf($from, $to)
{
$this->load->library('cfpdf');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->SetFont('Arial','',10);
$pdf->Cell(0, 8, "Laporan Penjualan Tanggal ".date('d/m/Y', strtotime($from))." - ".date('d/m/Y', strtotime($to)), 0, 1, 'L');
$pdf->Cell(15, 7, 'No', 1, 0, 'L');
$pdf->Cell(85, 7, 'Tanggal', 1, 0, 'L');
$pdf->Cell(85, 7, 'Total Penjualan', 1, 0, 'L');
$pdf->Ln();
$this->load->model('m_penjualan_master');
$penjualan = $this->m_penjualan_master->laporan_penjualan($from, $to);
$no = 1;
$total_penjualan = 0;
foreach($penjualan->result() as $p)
{
$pdf->Cell(15, 7, $no, 1, 0, 'L');
$pdf->Cell(85, 7, date('d F Y', strtotime($p->tanggal)), 1, 0, 'L');
$pdf->Cell(85, 7, "Rp. ".str_replace(",", ".", number_format($p->total_penjualan)), 1, 0, 'L');
$pdf->Ln();
$total_penjualan = $total_penjualan + $p->total_penjualan;
$no++;
}
$pdf->Cell(100, 7, 'Total Seluruh Penjualan', 1, 0, 'L');
$pdf->Cell(85, 7, "Rp. ".str_replace(",", ".", number_format($total_penjualan)), 1, 0, 'L');
$pdf->Ln();
$pdf->Output();
}
}
Penjualan.php: berisikan method untuk mengatur fitur penjualan seperti: transaksi, histori transaksi, data pelanggan, dan lain sebagainya.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Penjualan extends MY_Controller
{
function __construct()
{
parent::__construct();
if($this->session->userdata('ap_level') == 'inventory'){
redirect();
}
}
public function index()
{
$this->transaksi();
}
public function transaksi()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'kasir')
{
if($_POST)
{
if( ! empty($_POST['kode_barang']))
{
$total = 0;
foreach($_POST['kode_barang'] as $k)
{
if( ! empty($k)){ $total++; }
}
if($total > 0)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('nomor_nota','Nomor Nota','trim|required|max_length[40]|alpha_numeric|callback_cek_nota[nomor_nota]');
$this->form_validation->set_rules('tanggal','Tanggal','trim|required');
$no = 0;
foreach($_POST['kode_barang'] as $d)
{
if( ! empty($d))
{
$this->form_validation->set_rules('kode_barang['.$no.']','Kode Barang #'.($no + 1), 'trim|required|max_length[40]|callback_cek_kode_barang[kode_barang['.$no.']]');
$this->form_validation->set_rules('jumlah_beli['.$no.']','Qty #'.($no + 1), 'trim|numeric|required|callback_cek_nol[jumlah_beli['.$no.']]');
}
$no++;
}
$this->form_validation->set_rules('cash','Total Bayar', 'trim|numeric|required|max_length[17]');
$this->form_validation->set_rules('catatan','Catatan', 'trim|max_length[1000]');
$this->form_validation->set_message('required', '%s harus diisi');
$this->form_validation->set_message('cek_kode_barang', '%s tidak ditemukan');
$this->form_validation->set_message('cek_nota', '%s sudah ada');
$this->form_validation->set_message('cek_nol', '%s tidak boleh nol');
$this->form_validation->set_message('alpha_numeric', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$nomor_nota = $this->input->post('nomor_nota');
$tanggal = $this->input->post('tanggal');
$id_kasir = $this->input->post('id_kasir');
$id_pelanggan = $this->input->post('id_pelanggan');
$bayar = $this->input->post('cash');
$grand_total = $this->input->post('grand_total');
$catatan = $this->clean_tag_input($this->input->post('catatan'));
if($bayar < $grand_total)
{
$this->query_error("Cash Kurang");
}
else
{
$this->load->model('m_penjualan_master');
$master = $this->m_penjualan_master->insert_master($nomor_nota, $tanggal, $id_kasir, $id_pelanggan, $bayar, $grand_total, $catatan);
if($master)
{
$id_master = $this->m_penjualan_master->get_id($nomor_nota)->row()->id_penjualan_m;
$inserted = 0;
$this->load->model('m_penjualan_detail');
$this->load->model('m_barang');
$no_array = 0;
foreach($_POST['kode_barang'] as $k)
{
if( ! empty($k))
{
$kode_barang = $_POST['kode_barang'][$no_array];
$jumlah_beli = $_POST['jumlah_beli'][$no_array];
$harga_satuan = $_POST['harga_satuan'][$no_array];
$sub_total = $_POST['sub_total'][$no_array];
$id_barang = $this->m_barang->get_id($kode_barang)->row()->id_barang;
$insert_detail = $this->m_penjualan_detail->insert_detail($id_master, $id_barang, $jumlah_beli, $harga_satuan, $sub_total);
if($insert_detail)
{
$this->m_barang->update_stok($id_barang, $jumlah_beli);
$inserted++;
}
}
$no_array++;
}
if($inserted > 0)
{
echo json_encode(array('status' => 1, 'pesan' => "Transaksi berhasil disimpan !"));
}
else
{
$this->query_error();
}
}
else
{
$this->query_error();
}
}
}
else
{
echo json_encode(array('status' => 0, 'pesan' => validation_errors("<font color='red'>- ","</font><br />")));
}
}
else
{
$this->query_error("Harap masukan minimal 1 kode barang !");
}
}
else
{
$this->query_error("Harap masukan minimal 1 kode barang !");
}
}
else
{
$this->load->model('m_user');
$this->load->model('m_pelanggan');
$dt['kasirnya'] = $this->m_user->list_kasir();
$dt['pelanggan']= $this->m_pelanggan->get_all();
$this->load->view('penjualan/transaksi', $dt);
}
}
}
public function cek_nota($nota)
{
$this->load->model('m_penjualan_master');
$cek = $this->m_penjualan_master->cek_nota_validasi($nota);
if($cek->num_rows() > 0)
{
return FALSE;
}
return TRUE;
}
public function transaksi_cetak()
{
$nomor_nota = $this->input->get('nomor_nota');
$tanggal = $this->input->get('tanggal');
$id_kasir = $this->input->get('id_kasir');
$id_pelanggan = $this->input->get('id_pelanggan');
$cash = $this->input->get('cash');
$catatan = $this->input->get('catatan');
$grand_total = $this->input->get('grand_total');
$this->load->model('m_user');
$kasir = $this->m_user->get_baris($id_kasir)->row()->nama;
$this->load->model('m_pelanggan');
$pelanggan = 'umum';
if( ! empty($id_pelanggan))
{
$pelanggan = $this->m_pelanggan->get_baris($id_pelanggan)->row()->nama;
}
$this->load->library('cfpdf');
$pdf = new FPDF('P','mm','A5');
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->Cell(25, 4, 'Nota', 0, 0, 'L');
$pdf->Cell(85, 4, $nomor_nota, 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(25, 4, 'Tanggal', 0, 0, 'L');
$pdf->Cell(85, 4, date('d-M-Y H:i:s', strtotime($tanggal)), 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(25, 4, 'Kasir', 0, 0, 'L');
$pdf->Cell(85, 4, $kasir, 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(25, 4, 'Pelanggan', 0, 0, 'L');
$pdf->Cell(85, 4, $pelanggan, 0, 0, 'L');
$pdf->Ln();
$pdf->Ln();
$pdf->Cell(130, 5, '-----------------------------------------------------------------------------------------------------------', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(25, 5, 'Kode', 0, 0, 'L');
$pdf->Cell(40, 5, 'Item', 0, 0, 'L');
$pdf->Cell(25, 5, 'Harga', 0, 0, 'L');
$pdf->Cell(15, 5, 'Qty', 0, 0, 'L');
$pdf->Cell(25, 5, 'Subtotal', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(130, 5, '-----------------------------------------------------------------------------------------------------------', 0, 0, 'L');
$pdf->Ln();
$this->load->model('m_barang');
$this->load->helper('text');
$no = 0;
foreach($_GET['kode_barang'] as $kd)
{
if( ! empty($kd))
{
$nama_barang = $this->m_barang->get_id($kd)->row()->nama_barang;
$nama_barang = character_limiter($nama_barang, 20, '..');
$pdf->Cell(25, 5, $kd, 0, 0, 'L');
$pdf->Cell(40, 5, $nama_barang, 0, 0, 'L');
$pdf->Cell(25, 5, str_replace(',', '.', number_format($_GET['harga_satuan'][$no])), 0, 0, 'L');
$pdf->Cell(15, 5, $_GET['jumlah_beli'][$no], 0, 0, 'L');
$pdf->Cell(25, 5, str_replace(',', '.', number_format($_GET['sub_total'][$no])), 0, 0, 'L');
$pdf->Ln();
$no++;
}
}
$pdf->Cell(130, 5, '-----------------------------------------------------------------------------------------------------------', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(105, 5, 'Total Bayar', 0, 0, 'R');
$pdf->Cell(25, 5, str_replace(',', '.', number_format($grand_total)), 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(105, 5, 'Cash', 0, 0, 'R');
$pdf->Cell(25, 5, str_replace(',', '.', number_format($cash)), 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(105, 5, 'Kembali', 0, 0, 'R');
$pdf->Cell(25, 5, str_replace(',', '.', number_format(($cash - $grand_total))), 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(130, 5, '-----------------------------------------------------------------------------------------------------------', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(25, 5, 'Catatan : ', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(130, 5, (($catatan == '') ? 'Tidak Ada' : $catatan), 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(130, 5, '-----------------------------------------------------------------------------------------------------------', 0, 0, 'L');
$pdf->Ln();
$pdf->Ln();
$pdf->Cell(130, 5, "Terimakasih telah berbelanja dengan kami", 0, 0, 'C');
$pdf->Output();
}
public function ajax_pelanggan()
{
if($this->input->is_ajax_request())
{
$id_pelanggan = $this->input->post('id_pelanggan');
$this->load->model('m_pelanggan');
$data = $this->m_pelanggan->get_baris($id_pelanggan)->row();
$json['telp'] = ( ! empty($data->telp)) ? $data->telp : "<small><i>Tidak ada</i></small>";
$json['alamat'] = ( ! empty($data->alamat)) ? preg_replace("/\r\n|\r|\n/",'<br />', $data->alamat) : "<small><i>Tidak ada</i></small>";
$json['info_tambahan'] = ( ! empty($data->info_tambahan)) ? preg_replace("/\r\n|\r|\n/",'<br />', $data->info_tambahan) : "<small><i>Tidak ada</i></small>";
echo json_encode($json);
}
}
public function ajax_kode()
{
if($this->input->is_ajax_request())
{
$keyword = $this->input->post('keyword');
$registered = $this->input->post('registered');
$this->load->model('m_barang');
$barang = $this->m_barang->cari_kode($keyword, $registered);
if($barang->num_rows() > 0)
{
$json['status'] = 1;
$json['datanya'] = "<ul id='daftar-autocomplete'>";
foreach($barang->result() as $b)
{
$json['datanya'] .= "
<li>
<b>Kode</b> :
<span id='kodenya'>".$b->kode_barang."</span> <br />
<span id='barangnya'>".$b->nama_barang."</span>
<span id='harganya' style='display:none;'>".$b->harga."</span>
</li>
";
}
$json['datanya'] .= "</ul>";
}
else
{
$json['status'] = 0;
}
echo json_encode($json);
}
}
public function cek_kode_barang($kode)
{
$this->load->model('m_barang');
$cek_kode = $this->m_barang->cek_kode($kode);
if($cek_kode->num_rows() > 0)
{
return TRUE;
}
return FALSE;
}
public function cek_nol($qty)
{
if($qty > 0){
return TRUE;
}
return FALSE;
}
public function history()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'kasir' OR $level == 'keuangan')
{
$this->load->view('penjualan/transaksi_history');
}
}
public function history_json()
{
$this->load->model('m_penjualan_master');
$level = $this->session->userdata('ap_level');
$requestData = $_REQUEST;
$fetch = $this->m_penjualan_master->fetch_data_penjualan($requestData['search']['value'], $requestData['order'][0]['column'], $requestData['order'][0]['dir'], $requestData['start'], $requestData['length']);
$totalData = $fetch['totalData'];
$totalFiltered = $fetch['totalFiltered'];
$query = $fetch['query'];
$data = array();
foreach($query->result_array() as $row)
{
$nestedData = array();
$nestedData[] = $row['nomor'];
$nestedData[] = $row['tanggal'];
$nestedData[] = "<a href='".site_url('penjualan/detail-transaksi/'.$row['id_penjualan_m'])."' id='LihatDetailTransaksi'><i class='fa fa-file-text-o fa-fw'></i> ".$row['nomor_nota']."</a>";
$nestedData[] = $row['grand_total'];
$nestedData[] = $row['nama_pelanggan'];
$nestedData[] = preg_replace("/\r\n|\r|\n/",'<br />', $row['keterangan']);
$nestedData[] = $row['kasir'];
if($level == 'admin' OR $level == 'keuangan')
{
$nestedData[] = "<a href='".site_url('penjualan/hapus-transaksi/'.$row['id_penjualan_m'])."' id='HapusTransaksi'><i class='fa fa-trash-o'></i> Hapus</a>";
}
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}
public function detail_transaksi($id_penjualan)
{
if($this->input->is_ajax_request())
{
$this->load->model('m_penjualan_detail');
$this->load->model('m_penjualan_master');
$dt['detail'] = $this->m_penjualan_detail->get_detail($id_penjualan);
$dt['master'] = $this->m_penjualan_master->get_baris($id_penjualan)->row();
$this->load->view('penjualan/transaksi_history_detail', $dt);
}
}
public function hapus_transaksi($id_penjualan)
{
if($this->input->is_ajax_request())
{
$level = $this->session->userdata('ap_level');
if($level == 'admin')
{
$reverse_stok = $this->input->post('reverse_stok');
$this->load->model('m_penjualan_master');
$nota = $this->m_penjualan_master->get_baris($id_penjualan)->row()->nomor_nota;
$hapus = $this->m_penjualan_master->hapus_transaksi($id_penjualan, $reverse_stok);
if($hapus)
{
echo json_encode(array(
"pesan" => "<font color='green'><i class='fa fa-check'></i> Transaksi <b>".$nota."</b> berhasil dihapus !</font>
"));
}
else
{
echo json_encode(array(
"pesan" => "<font color='red'><i class='fa fa-warning'></i> Terjadi kesalahan, coba lagi !</font>
"));
}
}
}
}
public function pelanggan()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'kasir' OR $level == 'keuangan')
{
$this->load->view('penjualan/pelanggan_data');
}
}
public function pelanggan_json()
{
$this->load->model('m_pelanggan');
$level = $this->session->userdata('ap_level');
$requestData = $_REQUEST;
$fetch = $this->m_pelanggan->fetch_data_pelanggan($requestData['search']['value'], $requestData['order'][0]['column'], $requestData['order'][0]['dir'], $requestData['start'], $requestData['length']);
$totalData = $fetch['totalData'];
$totalFiltered = $fetch['totalFiltered'];
$query = $fetch['query'];
$data = array();
foreach($query->result_array() as $row)
{
$nestedData = array();
$nestedData[] = $row['nomor'];
$nestedData[] = $row['nama'];
$nestedData[] = preg_replace("/\r\n|\r|\n/",'<br />', $row['alamat']);
$nestedData[] = $row['telp'];
$nestedData[] = preg_replace("/\r\n|\r|\n/",'<br />', $row['info_tambahan']);
$nestedData[] = $row['waktu_input'];
if($level == 'admin' OR $level == 'kasir' OR $level == 'keuangan')
{
$nestedData[] = "<a href='".site_url('penjualan/pelanggan-edit/'.$row['id_pelanggan'])."' id='EditPelanggan'><i class='fa fa-pencil'></i> Edit</a>";
}
if($level == 'admin')
{
$nestedData[] = "<a href='".site_url('penjualan/pelanggan-hapus/'.$row['id_pelanggan'])."' id='HapusPelanggan'><i class='fa fa-trash-o'></i> Hapus</a>";
}
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}
public function tambah_pelanggan()
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'kasir' OR $level == 'keuangan')
{
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('nama','Nama','trim|required|alpha_spaces|max_length[40]');
$this->form_validation->set_rules('alamat','Alamat','trim|required|max_length[1000]');
$this->form_validation->set_rules('telepon','Telepon / Handphone','trim|required|numeric|max_length[40]');
$this->form_validation->set_rules('info','Info Tambahan Lainnya','trim|max_length[1000]');
$this->form_validation->set_message('alpha_spaces','%s harus alphabet !');
$this->form_validation->set_message('numeric','%s harus angka !');
$this->form_validation->set_message('required','%s harus diisi !');
if($this->form_validation->run() == TRUE)
{
$this->load->model('m_pelanggan');
$nama = $this->input->post('nama');
$alamat = $this->clean_tag_input($this->input->post('alamat'));
$telepon = $this->input->post('telepon');
$info = $this->clean_tag_input($this->input->post('info'));
$unique = time().$this->session->userdata('ap_id_user');
$insert = $this->m_pelanggan->tambah_pelanggan($nama, $alamat, $telepon, $info, $unique);
if($insert)
{
$id_pelanggan = $this->m_pelanggan->get_dari_kode($unique)->row()->id_pelanggan;
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> <b>".$nama."</b> berhasil ditambahkan sebagai pelanggan.</div>",
'id_pelanggan' => $id_pelanggan,
'nama' => $nama,
'alamat' => preg_replace("/\r\n|\r|\n/",'<br />', $alamat),
'telepon' => $telepon,
'info' => (empty($info)) ? "<small><i>Tidak ada</i></small>" : preg_replace("/\r\n|\r|\n/",'<br />', $info)
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->view('penjualan/pelanggan_tambah');
}
}
}
public function pelanggan_edit($id_pelanggan = NULL)
{
if( ! empty($id_pelanggan))
{
$level = $this->session->userdata('ap_level');
if($level == 'admin' OR $level == 'kasir' OR $level == 'keuangan')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_pelanggan');
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('nama','Nama','trim|required|alpha_spaces|max_length[40]');
$this->form_validation->set_rules('alamat','Alamat','trim|required|max_length[1000]');
$this->form_validation->set_rules('telepon','Telepon / Handphone','trim|required|numeric|max_length[40]');
$this->form_validation->set_rules('info','Info Tambahan Lainnya','trim|max_length[1000]');
$this->form_validation->set_message('alpha_spaces','%s harus alphabet !');
$this->form_validation->set_message('numeric','%s harus angka !');
$this->form_validation->set_message('required','%s harus diisi !');
if($this->form_validation->run() == TRUE)
{
$nama = $this->input->post('nama');
$alamat = $this->clean_tag_input($this->input->post('alamat'));
$telepon = $this->input->post('telepon');
$info = $this->clean_tag_input($this->input->post('info'));
$update = $this->m_pelanggan->update_pelanggan($id_pelanggan, $nama, $alamat, $telepon, $info);
if($update)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> Data berhasil diupdate.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$dt['pelanggan'] = $this->m_pelanggan->get_baris($id_pelanggan)->row();
$this->load->view('penjualan/pelanggan_edit', $dt);
}
}
}
}
}
public function pelanggan_hapus($id_pelanggan)
{
$level = $this->session->userdata('ap_level');
if($level == 'admin')
{
if($this->input->is_ajax_request())
{
$this->load->model('m_pelanggan');
$hapus = $this->m_pelanggan->hapus_pelanggan($id_pelanggan);
if($hapus)
{
echo json_encode(array(
"pesan" => "<font color='green'><i class='fa fa-check'></i> Data berhasil dihapus !</font>
"));
}
else
{
echo json_encode(array(
"pesan" => "<font color='red'><i class='fa fa-warning'></i> Terjadi kesalahan, coba lagi !</font>
"));
}
}
}
}
}
Secure.php: berisikan method untuk mengatur fitur login dan logout.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Secure extends MY_Controller
{
public function index()
{
if($this->input->is_ajax_request())
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username','Username','trim|required|min_length[3]|max_length[40]');
$this->form_validation->set_rules('password','Password','trim|required|min_length[3]|max_length[40]');
$this->form_validation->set_message('required','%s Tidak Boleh Kosong !');
if($this->form_validation->run() == TRUE)
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('m_user');
$validasi_login = $this->m_user->validasi_login($username, $password);
if($validasi_login->num_rows() > 0)
{
$data_user = $validasi_login->row();
$session = array(
'ap_id_user' => $data_user->id_user,
'ap_password' => $data_user->password,
'ap_nama' => $data_user->nama,
'ap_level' => $data_user->level,
'ap_level_caption' => $data_user->level_caption
);
$this->session->set_userdata($session);
$URL_home = site_url('penjualan');
if($data_user->level == 'inventory')
{
$URL_home = site_url('barang');
}
if($data_user->level == 'keuangan')
{
$URL_home = site_url('penjualan/history');
}
$json['status'] = 1;
$json['url_home'] = $URL_home;
echo json_encode($json);
}
else
{
$this->query_error("Login Gagal, Cek Kombinasi Username & Password !");
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->view('secure/login_page');
}
}
function logout()
{
$this->session->unset_userdata('ap_id_user');
$this->session->unset_userdata('ap_password');
$this->session->unset_userdata('ap_nama');
$this->session->unset_userdata('ap_level');
$this->session->unset_userdata('ap_level_caption');
redirect();
}
}
User.php: berisikan method untuk mengatur fitur user seperti: tambah user, hapus user, dan lain sebagainya.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends MY_Controller
{
public function index()
{
$level = $this->session->userdata('ap_level');
if($level !== 'admin')
{
exit();
}
else
{
$this->load->view('user/user_data');
}
}
public function user_json()
{
$this->load->model('m_user');
$requestData = $_REQUEST;
$fetch = $this->m_user->fetch_data_user($requestData['search']['value'], $requestData['order'][0]['column'], $requestData['order'][0]['dir'], $requestData['start'], $requestData['length']);
$totalData = $fetch['totalData'];
$totalFiltered = $fetch['totalFiltered'];
$query = $fetch['query'];
$data = array();
foreach($query->result_array() as $row)
{
$nestedData = array();
$nestedData[] = $row['nomor'];
$nestedData[] = $row['username'];
$nestedData[] = $row['nama'];
$nestedData[] = $row['level_akses'];
$nestedData[] = $row['status'];
$nestedData[] = "<a href='".site_url('user/edit/'.$row['id_user'])."' id='EditUser'><i class='fa fa-pencil'></i> Edit</a>";
if($row['label'] !== 'admin')
{
$nestedData[] = "<a href='".site_url('user/hapus/'.$row['id_user'])."' id='HapusUser'><i class='fa fa-trash-o'></i> Hapus</a>";
}
if($row['label'] == 'admin')
{
$nestedData[] = '';
}
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}
public function hapus($id_user)
{
$level = $this->session->userdata('ap_level');
if($level !== 'admin')
{
exit();
}
else
{
if($this->input->is_ajax_request())
{
$this->load->model('m_user');
$hapus = $this->m_user->hapus_user($id_user);
if($hapus)
{
echo json_encode(array(
"pesan" => "<font color='green'><i class='fa fa-check'></i> Data berhasil dihapus !</font>
"));
}
else
{
echo json_encode(array(
"pesan" => "<font color='red'><i class='fa fa-warning'></i> Terjadi kesalahan, coba lagi !</font>
"));
}
}
}
}
public function tambah()
{
$level = $this->session->userdata('ap_level');
if($level !== 'admin')
{
exit();
}
else
{
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username','Username','trim|required|max_length[40]|callback_exist_username[username]|alpha_numeric');
$this->form_validation->set_rules('password','Password','trim|required|max_length[60]');
$this->form_validation->set_rules('nama','Nama Lengkap','trim|required|max_length[50]|alpha_spaces');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('exist_username','%s sudah ada di database, pilih username lain yang unik !');
$this->form_validation->set_message('alpha_spaces', '%s harus alphabet');
$this->form_validation->set_message('alpha_numeric', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$this->load->model('m_user');
$username = $this->input->post('username');
$password = $this->input->post('password');
$nama = $this->input->post('nama');
$id_akses = $this->input->post('id_akses');
$status = $this->input->post('status');
$insert = $this->m_user->tambah_baru($username, $password, $nama, $id_akses, $status);
if($insert > 0)
{
echo json_encode(array(
'status' => 1,
'pesan' => "<i class='fa fa-check' style='color:green;'></i> Data User berhasil dismpan."
));
}
else
{
$this->query_error("Oops, terjadi kesalahan, coba lagi !");
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->model('m_akses');
$dt['akses'] = $this->m_akses->get_all();
$this->load->view('user/user_tambah', $dt);
}
}
}
public function exist_username($username)
{
$this->load->model('m_user');
$cek_user = $this->m_user->cek_username($username);
if($cek_user->num_rows() > 0)
{
return FALSE;
}
return TRUE;
}
public function edit($id_user = NULL)
{
$level = $this->session->userdata('ap_level');
if($level !== 'admin')
{
exit();
}
else
{
if( ! empty($id_user))
{
if($this->input->is_ajax_request())
{
$this->load->model('m_user');
if($_POST)
{
$this->load->library('form_validation');
$username = $this->input->post('username');
$username_old = $this->input->post('username_old');
$callback = '';
if($username !== $username_old){
$callback = "|callback_exist_username[username]";
}
$this->form_validation->set_rules('username','Username','trim|required|alpha_numeric|max_length[40]'.$callback);
$this->form_validation->set_rules('password','Password','trim|max_length[60]');
$this->form_validation->set_rules('nama','Nama Lengkap','trim|required|max_length[50]|alpha_spaces');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('exist_username','%s sudah ada di database, pilih username lain yang unik !');
$this->form_validation->set_message('alpha_spaces', '%s harus alphabet');
$this->form_validation->set_message('alpha_numeric', '%s Harus huruf / angka !');
if($this->form_validation->run() == TRUE)
{
$password = $this->input->post('password');
$nama = $this->input->post('nama');
$id_akses = $this->input->post('id_akses');
$status = $this->input->post('status');
$update = $this->m_user->update_user($id_user, $username, $password, $nama, $id_akses, $status);
if($update)
{
$label = $this->input->post('label');
if($label == 'admin')
{
$this->session->set_userdata('ap_nama', $nama);
}
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> Data user berhasil diupdate.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->model('m_akses');
$dt['user'] = $this->m_user->get_baris($id_user)->row();
$dt['akses'] = $this->m_akses->get_all();
$this->load->view('user/user_edit', $dt);
}
}
}
}
}
public function ubah_password()
{
if($this->input->is_ajax_request())
{
if($_POST)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('pass_old','Password Lama','trim|required|max_length[60]|callback_check_pass[pass_old]');
$this->form_validation->set_rules('pass_new','Password Baru','trim|required|max_length[60]');
$this->form_validation->set_rules('pass_new_confirm','Ulangi Password Baru','trim|required|max_length[60]|matches[pass_new]');
$this->form_validation->set_message('required','%s harus diisi !');
$this->form_validation->set_message('check_pass','%s anda salah !');
if($this->form_validation->run() == TRUE)
{
$this->load->model('m_user');
$pass_new = $this->input->post('pass_new');
$update = $this->m_user->update_password($pass_new);
if($update)
{
$this->session->set_userdata('ap_password', sha1($pass_new));
echo json_encode(array(
'status' => 1,
'pesan' => "<div class='alert alert-success'><i class='fa fa-check'></i> Password berhasil diupdate.</div>"
));
}
else
{
$this->query_error();
}
}
else
{
$this->input_error();
}
}
else
{
$this->load->view('user/change_pass');
}
}
}
public function check_pass($pass)
{
$this->load->model('m_user');
$cek_user = $this->m_user->cek_password($pass);
if($cek_user->num_rows() > 0)
{
return TRUE;
}
return FALSE;
}
}
- View: adalah bagian yang mengatur tampilan pada situs. di source code ini terdapat banyak view yang mengatur tampilan masing-masing fitur yaitu mulai dari login_page, tampilan transaksi, tampilan histori pelanggan, tampilan list produk, dan lain sebagainya. Source code lengkap dan sql dapat diakses di link berikut: Drive PBKK