310 lines
9.6 KiB
PHP
310 lines
9.6 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageSku extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelSku', 'MSku');
|
|
$this->load->model('ModelDistributor', 'MDistributor');
|
|
$this->load->model('ModelProcessor', 'MProcessor');
|
|
$this->load->model('ModelRam', 'MRam');
|
|
$this->load->model('ModelHarddisk', 'MHarddisk');
|
|
$this->load->model('ModelSsd', 'MSsd');
|
|
$this->load->model('ModelOs', 'MOs');
|
|
$this->load->model('ModelVga', 'MVga');
|
|
$this->load->model('ModelMonitor', 'MMonitor');
|
|
$this->load->model('ModelWarna', 'MWarna');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
}
|
|
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()
|
|
{
|
|
//$username = $this->session->userdata('username');
|
|
//$jabatan = $this->session->userdata('jabatan');
|
|
//if ($username == null) {
|
|
// redirect("Login");
|
|
//} elseif ($jabatan != "ADMIN") {
|
|
// redirect("Login");
|
|
//}
|
|
|
|
$datSku = $this->MSku->getDataSku();
|
|
|
|
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data sku",
|
|
'sku' => $datSku
|
|
];
|
|
|
|
$this->load->view('sku/tabel-sku', $data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
}
|
|
$datDistributor = $this->MDistributor->getDataDistributor();
|
|
$datProcessor = $this->MProcessor->getDataProcessor();
|
|
$datRam = $this->MRam->getDataRam();
|
|
$datHarddisk = $this->MHarddisk->getDataHarddisk();
|
|
$datSsd = $this->MSsd->getDataSsd();
|
|
$datOs = $this->MOs->getDataOs();
|
|
$datVga = $this->MVga->getDataVga();
|
|
$datMonitor = $this->MMonitor->getDataMonitor();
|
|
$datWarna = $this->MWarna->getDataWarna();
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data sku",
|
|
'distributor' => $datDistributor,
|
|
'processor' => $datProcessor,
|
|
'ram' => $datRam,
|
|
'harddisk' => $datHarddisk,
|
|
'ssd' => $datSsd,
|
|
'os' => $datOs,
|
|
'vga' => $datVga,
|
|
'monitor' => $datMonitor,
|
|
'warna' => $datWarna
|
|
|
|
];
|
|
//var_dump($data);
|
|
$this->load->view('sku/sku-tambah', $data);
|
|
}
|
|
public function edit($id)
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
} elseif ($jabatan != "ADMIN") {
|
|
redirect("Login");
|
|
}
|
|
$datSku = $this->MSku->getDataSku($id);
|
|
// var_dump($datUSer[0]['JABATAN_ID']);
|
|
|
|
$datDistributor = $this->MDistributor->getDataDistributor();
|
|
$datProcessor = $this->MProcessor->getDataProcessor();
|
|
$datRam = $this->MRam->getDataRam();
|
|
$datHarddisk = $this->MHarddisk->getDataHarddisk();
|
|
$datSsd = $this->MSsd->getDataSsd();
|
|
$datOs = $this->MOs->getDataOs();
|
|
$datVga = $this->MVga->getDataVga();
|
|
$datMonitor = $this->MMonitor->getDataMonitor();
|
|
$datWarna = $this->MWarna->getDataWarna();
|
|
|
|
$datJabatan = $this->GRamM->getDataRam($datUSer[0]['BARANG_ID']);
|
|
// var_dump($datJabatan[0]);
|
|
$jabatan = $this->JabatanM->getDataJabatan();
|
|
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data karyawan",
|
|
'karyawan' => $datUSer,
|
|
'jbtn' => $datJabatan[0],
|
|
'jabatan' => $jabatan
|
|
];
|
|
|
|
$this->load->view('sku/sku-edit', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$po = $this->input->post('no_po');
|
|
$distributor = $this->input->post('DISTRIBUTOR');
|
|
$sku = $this->input->post('nama_sku');
|
|
$processor = $this->input->post('PROCESSOR');
|
|
$ram = $this->input->post('RAM');
|
|
$harddisk = $this->input->post('HDD');
|
|
$ssd = $this->input->post('SSD');
|
|
$os = $this->input->post('OS');
|
|
$vga = $this->input->post('VGA');
|
|
$monitor = $this->input->post('MONITOR');
|
|
$warna = $this->input->post('WARNA');
|
|
|
|
$this->form_validation->set_rules('no_po', 'Nomor PO', 'required');
|
|
$this->form_validation->set_rules('DISTRIBUTOR', 'Distributor', 'required');
|
|
$this->form_validation->set_rules('nama_sku', 'Nama SKU', 'required');
|
|
$this->form_validation->set_rules('PROCESSOR', 'Processor', 'required');
|
|
$this->form_validation->set_rules('RAM', 'RAM', 'required');
|
|
$this->form_validation->set_rules('HDD', 'HDD', 'required');
|
|
$this->form_validation->set_rules('SSD', 'SSD', 'required');
|
|
$this->form_validation->set_rules('OS', 'OS', 'required');
|
|
$this->form_validation->set_rules('VGA', 'VGA', 'required');
|
|
$this->form_validation->set_rules('MONITOR', 'Monitor', 'required');
|
|
$this->form_validation->set_rules('WARNA', 'Warna', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'no_po' => form_error('no_po'),
|
|
'DISTRIBUTOR' => form_error('DISTRIBUTOR'),
|
|
'nama_sku' => form_error('nama_sku'),
|
|
'PROCESSOR' => form_error('PROCESSOR'),
|
|
'RAM' => form_error('RAM'),
|
|
'HDD' => form_error('HDD'),
|
|
'SSD' => form_error('SSD'),
|
|
'OS' => form_error('OS'),
|
|
'VGA' => form_error('VGA'),
|
|
'MONITOR' => form_error('MONITOR'),
|
|
'WARNA' => form_error('WARNA')
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
$input = [
|
|
'NO_PO' => $po,
|
|
'NAMA_SKU' => $sku,
|
|
'ID_DISTRIBUTOR' => $distributor,
|
|
'ID_PROCESSOR' => $processor,
|
|
'ID_RAM' => $ram,
|
|
'ID_HDD' => $harddisk,
|
|
'ID_SSD' => $ssd,
|
|
'ID_OS' => $os,
|
|
'ID_VGA' => $vga,
|
|
'ID_MONITOR' => $monitor,
|
|
'ID_WARNA' => $warna
|
|
];
|
|
|
|
$action = $this->MSku->create('sku', $input);
|
|
|
|
if ($action) {
|
|
//$this->session->set_flashdata('flash', 'ditambah');
|
|
$this->output_json(['status' => true]);
|
|
redirect('ManageSku');
|
|
} else {
|
|
//$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
$this->output_json(['status' => true]);
|
|
redirect('ManageSku');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function saveedit()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_karyawan = $this->input->post('id_karyawan');
|
|
$jabatan_id = $this->input->post('JABATAN');
|
|
$oldpassword = $this->input->post('oldpassword');
|
|
$newpassword = $this->input->post('newpassword');
|
|
$newpasswordver = $this->input->post('newpasswordver');
|
|
$nama_karyawan = $this->input->post('nama_karyawan');
|
|
$nama_panggilan_karyawan = $this->input->post('nama_panggilan_karyawan');
|
|
$username = $this->input->post('username');
|
|
|
|
if ($method === 'editpass') {
|
|
$this->form_validation->set_rules('oldpassword', 'Old Password', 'required');
|
|
$this->form_validation->set_rules('newpassword', 'New Password', 'required');
|
|
$this->form_validation->set_rules('newpasswordver', 'New Password Verifikasi', 'required|matches[newpassword]');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'oldpassword' => form_error('oldpassword'),
|
|
'newpassword' => form_error('newpassword'),
|
|
'newpasswordver' => form_error('newpasswordver')
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
$datAk = $this->KaryawanM->getDataKaryawan($id_karyawan);
|
|
// var_dump($datAk[0]['PASSWORD']);
|
|
|
|
if ($oldpassword == $datAk[0]['PASSWORD']) {
|
|
// if ($newpassword == $newpasswordver) {
|
|
$input = [
|
|
'PASSWORD' => $newpassword
|
|
];
|
|
$action = $this->KaryawanM->update('karyawan', $input, 'ID_KARYAWAN', $id_karyawan);
|
|
$this->output_json(['status' => true]);
|
|
// } else {
|
|
// $this->output_json([
|
|
// 'status' => false,
|
|
// 'err' => true,
|
|
// 'message' => 'Password Tidak Sama',
|
|
// 'errors' => [
|
|
// 'newpasswordver' => form_error('newpasswordver')
|
|
// ]
|
|
// ]);
|
|
// }
|
|
} else {
|
|
$this->output_json([
|
|
'status' => false,
|
|
'err' => true,
|
|
'message' => 'Password Lama Tidak Sama',
|
|
'errors' => [
|
|
'oldpassword' => form_error('oldpassword')
|
|
]
|
|
]);
|
|
}
|
|
}
|
|
} else if ($method === 'editjabatan') {
|
|
$this->form_validation->set_rules('nama_karyawan', 'Nama Karyawan', 'required');
|
|
$this->form_validation->set_rules('nama_panggilan_karyawan', 'Nama Panggilan', 'required');
|
|
$this->form_validation->set_rules('username', 'Username', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'nama_karyawan' => form_error('nama_karyawan'),
|
|
'nama_panggilan_karyawan' => form_error('nama_panggilan_karyawan'),
|
|
'username' => form_error('username')
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
$input = [
|
|
'JABATAN_ID' => $jabatan_id,
|
|
'NAMA_USER' => $nama_karyawan,
|
|
'NAMA_PANGGILAN' => $nama_panggilan_karyawan,
|
|
'USERNAME' => $username
|
|
];
|
|
|
|
$action = $this->KaryawanM->update('karyawan', $input, 'ID_KARYAWAN', $id_karyawan);
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'diubah');
|
|
$this->output_json(['status' => true, 'id' => $id_karyawan]);
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'diubah');
|
|
$this->output_json(['status' => true, 'id' => $id_karyawan]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MSku->delete('sku', $id, 'ID_SKU')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageSku');
|
|
}
|
|
}
|
|
|
|
public function cek_pass($id, $pass = null)
|
|
{
|
|
if ($pass == null) {
|
|
$this->output_json(['cek' => 'ksng']);
|
|
} else {
|
|
$dat = $this->KaryawanM->cekPass($id, $pass);
|
|
|
|
if ($dat != null) {
|
|
$this->output_json(['cek' => 'benar']);
|
|
} else {
|
|
$this->output_json(['cek' => 'salah']);
|
|
}
|
|
}
|
|
}
|
|
}
|