329 lines
10 KiB
PHP
329 lines
10 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageBarang extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelDashboard', 'Dashboard');
|
|
$this->load->model('AllModels', 'Amod');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
$this->Dashboard->ceklogin();
|
|
}
|
|
public function output_json($data, $encode = true)
|
|
{
|
|
if ($encode) $data = json_encode($data);
|
|
$this->output->set_content_type('application/json')->set_output($data);
|
|
}
|
|
|
|
public function index() {
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$datShm = $this->Dashboard->getData_SetHakMaster_byKARYAWAN($id_karyawan);
|
|
if (strpos($jabatan,"GUDANG")!==FALSE OR $jabatan=="ADMINISTRATOR" OR $jabatan=="ADMIN ITP") {
|
|
$datJenis = $this->Dashboard->getData_Jenis_0_1_2();
|
|
} else {
|
|
$datJenis = $this->Dashboard->getData_Jenis_2();
|
|
}
|
|
|
|
$datMerk = $this->Dashboard->getData_Merk();
|
|
$datModel = $this->Dashboard->getData_Model();
|
|
$datProduk = $this->Dashboard->getData_Produk();
|
|
$datBarLatest = $this->Dashboard->getData_Barang_orderDESC_limit10();
|
|
$tgl_now = date('d/m/Y');
|
|
|
|
$datSba = $this->Dashboard->getData_SetBarang_byKARYAWAN($id_karyawan);
|
|
if ($datSba==FALSE) {
|
|
$id_jenis = 1;
|
|
$id_merk = 1;
|
|
$id_model = 1;
|
|
$id_produk = 1;
|
|
$nama_sba = NULL;
|
|
} else {
|
|
$id_jenis = $datSba[0]['JENIS_ID'];
|
|
$id_merk = $datSba[0]['MERK_ID'];
|
|
$id_model = $datSba[0]['MODEL_ID'];
|
|
$id_produk = $datSba[0]['PRODUK_ID'];
|
|
$nama_sba = $datSba[0]['NAMA_SBA'];
|
|
}
|
|
|
|
$datBarang = $this->Dashboard->getData_Barang_byKODE_byJENIS_byMERK_byMODEL_byPRODUK($nama_sba, $id_jenis, $id_merk, $id_model, $id_produk);
|
|
|
|
$no = 0;
|
|
foreach ($datBarang as $key) {
|
|
$datDb = $this->Dashboard->getData_DaftarBeli_byBARANG($key['ID_BARANG']);
|
|
$datDo = $this->Dashboard->getData_DaftarOrder_byBARANG($key['ID_BARANG']);
|
|
$datSnStock = $this->Dashboard->getData_SnStock_byBARANG($key['ID_BARANG']);
|
|
$datIo = $this->Dashboard->getData_TransaksiStock_byBARANG($key['ID_BARANG']);
|
|
|
|
if ($datDb==TRUE OR $datDo==TRUE OR $datSnStock==TRUE OR $datIo==TRUE) {
|
|
$lock = 1;
|
|
} else {
|
|
$lock = 0;
|
|
}
|
|
$datBarang[$no++] += ['LOCK' => $lock];
|
|
}
|
|
|
|
if ($datShm[0]['BARANG_SHM']==0) {
|
|
$akses = "Tidak Berhak";
|
|
$datBarang = NULL;
|
|
$datBarLatest = NULL;
|
|
} else if ($datShm[0]['BARANG_SHM']==1) {
|
|
$akses = "Hanya Baca";
|
|
} else if ($datShm[0]['BARANG_SHM']==2) {
|
|
$akses = "Akses Penuh";
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "dashboard",
|
|
'navChild' => "",
|
|
'barang' => $datBarang,
|
|
'bar_latest' => $datBarLatest,
|
|
'jenis' => $datJenis,
|
|
'merk' => $datMerk,
|
|
'model' => $datModel,
|
|
'produk' => $datProduk,
|
|
'id_jenis' => $id_jenis,
|
|
'id_merk' => $id_merk,
|
|
'id_model' => $id_model,
|
|
'nama_sba' => $nama_sba,
|
|
'tgl_now' => $tgl_now,
|
|
'hak' => $datShm[0]['BARANG_SHM'],
|
|
'akses' => $akses,
|
|
];
|
|
$this->load->view('master/Barang', $data);
|
|
}
|
|
|
|
public function simpanset_AA1() {
|
|
$method = $this->input->post('method');
|
|
$id_jenis = $this->input->post('id_jenis');
|
|
$id_merk = $this->input->post('id_merk');
|
|
$id_model = $this->input->post('id_model');
|
|
$id_produk = $this->input->post('id_produk');
|
|
$nama_sba = $this->input->post('nama_sba');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$tgl = date('Y-m-d H:i:s');
|
|
|
|
$nama_sba = strtoupper($nama_sba);
|
|
|
|
$datSba = $this->Dashboard->getData_SetBarang_byKARYAWAN($id_karyawan);
|
|
if ($datSba==FALSE) {
|
|
$input = [
|
|
'JENIS_ID' => $id_jenis,
|
|
'MERK_ID' => $id_merk,
|
|
'MODEL_ID' => $id_model,
|
|
'PRODUK_ID' => $id_produk,
|
|
'NAMA_SBA' => $nama_sba,
|
|
'KARYAWAN_ID' => $id_karyawan,
|
|
'LAST_SBA' => $tgl,
|
|
];
|
|
$action = $this->Dashboard->create('set_barang', $input);
|
|
$set = 1;
|
|
} else {
|
|
$update = [
|
|
'JENIS_ID' => $id_jenis,
|
|
'MERK_ID' => $id_merk,
|
|
'MODEL_ID' => $id_model,
|
|
'PRODUK_ID' => $id_produk,
|
|
'NAMA_SBA' => $nama_sba,
|
|
'LAST_SBA' => $tgl,
|
|
];
|
|
$action = $this->Dashboard->update('set_barang', $update, 'ID_SBA', $datSba[0]['ID_SBA']);
|
|
$set = 2;
|
|
}
|
|
|
|
if ($set==1) {
|
|
$this->session->set_flashdata('filter_success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else if ($set==2) {
|
|
$this->session->set_flashdata('filter_success', 'diperbaruhi');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('filter_failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function simpan() {
|
|
$method = $this->input->post('method');
|
|
$id_barang = $this->input->post('id');
|
|
$id_jenis = $this->input->post('id_jenis');
|
|
$id_merk = $this->input->post('id_merk');
|
|
$id_model = $this->input->post('id_model');
|
|
$id_produk = $this->input->post('id_produk');
|
|
$kode_barang = $this->input->post('kode_barang');
|
|
$nama_barang = $this->input->post('nama_barang');
|
|
$tgl = date('m/d/Y');
|
|
|
|
$datBarangKode = $this->Dashboard->getData_Barang_byKODE($kode_barang);
|
|
$datBarangNama = $this->Dashboard->getData_Barang_byNAMA($nama_barang);
|
|
if ($datBarangKode==TRUE OR $datBarangNama==TRUE) {
|
|
$this->session->set_flashdata('data_copy', 'error');
|
|
redirect('ManageBarang');
|
|
}
|
|
|
|
if ($id_model == "") {
|
|
$id_model = NULL;
|
|
}
|
|
|
|
if ($id_produk == "") {
|
|
$id_produk = NULL;
|
|
}
|
|
|
|
$kode_barang = preg_replace('/"/', 'INCH', $kode_barang);
|
|
$nama_barang = preg_replace('/"/', 'INCH', $nama_barang);
|
|
|
|
$input = [
|
|
'JENIS_ID' => $id_jenis,
|
|
'MERK_ID' => $id_merk,
|
|
'MODEL_ID' => $id_model,
|
|
'PRODUK_ID' => $id_produk,
|
|
'NAMA_BARANG' => $nama_barang,
|
|
'KODE_BARANG' => $kode_barang,
|
|
'STATUS_BARANG' => '1'
|
|
];
|
|
$action = $this->Dashboard->create('barang', $input);
|
|
|
|
$id_barang = $this->Dashboard->getID_BarangMax();
|
|
$id_barang = $id_barang[0]['ID_BARANG'];
|
|
$input = [
|
|
'ID_KUANTITI' => $id_barang,
|
|
'GLOBAL_KUANTITI' => '0',
|
|
'ANTIK_KUANTITI' => '0',
|
|
'PROYEK_KUANTITI' => '0',
|
|
'PROSES_KUANTITI' => '0',
|
|
'PCM_KUANTITI' => '0',
|
|
'ITP_KUANTITI' => '0',
|
|
'PEMINJAMAN_KUANTITI' => '0',
|
|
'PENDING_KUANTITI' => '0',
|
|
'KONSINYASI_KUANTITI' => '0',
|
|
'MUTASI_KUANTITI' => '0',
|
|
'SERVICE_KUANTITI' => '0',
|
|
'HARGA_AVG' => '0.00'
|
|
];
|
|
$action = $this->Dashboard->create('kuantiti', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect('ManageBarang');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect('ManageBarang');
|
|
}
|
|
}
|
|
|
|
public function ubah() {
|
|
$method = $this->input->post('method');
|
|
$id_barang = $this->input->post('id_baranged');
|
|
$id_jenis = $this->input->post('id_jenised');
|
|
$id_merk = $this->input->post('id_merked');
|
|
$id_model = $this->input->post('id_modeled');
|
|
$id_produk = $this->input->post('id_produked');
|
|
$kode_barang = $this->input->post('kode_baranged');
|
|
$nama_barang = $this->input->post('nama_baranged');
|
|
|
|
$datBarangKode = $this->Dashboard->getData_Barang_byKODE($kode_barang, $id_barang);
|
|
$datBarangNama = $this->Dashboard->getData_Barang_byNAMA($nama_barang, $id_barang);
|
|
if ($datBarangKode==TRUE OR $datBarangNama==TRUE) {
|
|
$this->session->set_flashdata('data_copy', 'error');
|
|
redirect('ManageBarang');
|
|
}
|
|
|
|
$datBarang = $this->Dashboard->getData_Barang($id_barang);
|
|
$datJenis = $this->Dashboard->getData_Jenis_byID($id_jenis);
|
|
if ($datBarang[0]['TYPE_JENIS']!=$datJenis[0]['TYPE_JENIS']) {
|
|
$this->session->set_flashdata('type_error', 'error');
|
|
redirect('ManageBarang');
|
|
}
|
|
|
|
if ($id_model == "") {
|
|
$id_model = NULL;
|
|
}
|
|
|
|
if ($id_produk == "") {
|
|
$id_produk = NULL;
|
|
}
|
|
|
|
$kode_barang = preg_replace('/"/', 'INCH', $kode_barang);
|
|
$nama_barang = preg_replace('/"/', 'INCH', $nama_barang);
|
|
|
|
$update = [
|
|
'NAMA_BARANG' => $nama_barang,
|
|
'KODE_BARANG' => $kode_barang,
|
|
'JENIS_ID' => $id_jenis,
|
|
'MERK_ID' => $id_merk,
|
|
'MODEL_ID' => $id_model,
|
|
'PRODUK_ID' => $id_produk
|
|
];
|
|
$action = $this->Dashboard->update('barang', $update, 'ID_BARANG', $id_barang);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect('ManageBarang');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect('ManageBarang');
|
|
}
|
|
}
|
|
|
|
public function hapus() {
|
|
$id_barang = $this->input->post('id_barangdel');
|
|
|
|
$datDb = $this->Dashboard->getData_DaftarBeli_byBARANG($id_barang);
|
|
$datDo = $this->Dashboard->getData_DaftarOrder_byBARANG($id_barang);
|
|
$datIo = $this->Dashboard->getData_TransaksiStock_byBARANG($id_barang);
|
|
$datSnStock = $this->Dashboard->getData_SnStock_byBARANG($id_barang);
|
|
|
|
if ($datDb == TRUE OR $datDo == TRUE OR $datIo == TRUE OR $datSnStock == TRUE) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect('ManageBarang');
|
|
}
|
|
|
|
$action = $this->Dashboard->delete('kuantiti', $id_barang, 'ID_KUANTITI');
|
|
$action = $this->Dashboard->delete('barang', $id_barang, 'ID_BARANG');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect('ManageBarang');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect('ManageBarang');
|
|
}
|
|
|
|
}
|
|
|
|
public function simpan_excel_barang() {
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$pilih_tabel = array('No', 'Jenis', 'Merk', 'Model', 'Kode Barang', 'Nama Barang');
|
|
$tgl = date('d/m/Y');
|
|
|
|
$datSba = $this->Dashboard->getData_SetBarang_byKARYAWAN($id_karyawan);
|
|
if ($datSba==FALSE) {
|
|
$id_jenis = 1;
|
|
$id_merk = 1;
|
|
$id_model = 1;
|
|
$nama_sba = NULL;
|
|
} else {
|
|
$id_jenis = $datSba[0]['JENIS_ID'];
|
|
$id_merk = $datSba[0]['MERK_ID'];
|
|
$id_model = $datSba[0]['MODEL_ID'];
|
|
$nama_sba = $datSba[0]['NAMA_SBA'];
|
|
}
|
|
|
|
$dataLaporan = $this->Dashboard->getData_Barang_byKODE_byJENIS_byMERK_byMODEL($nama_sba, $id_jenis, $id_merk, $id_model);
|
|
|
|
$data = [
|
|
'title' => '',
|
|
'jumlah_kolom' => count($pilih_tabel),
|
|
'nama_tabel' => $pilih_tabel,
|
|
'laporan' => $dataLaporan,
|
|
'tgl' => $tgl,
|
|
];
|
|
$this->load->view('cetak/excel_barang', $data);
|
|
}
|
|
|
|
}
|