Files
shopee-apps/application/delete/controllers/ManageInventorySRV.php
T
2026-06-13 16:02:07 +10:00

161 lines
5.0 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class ManageInventorySRV extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('ModelInventorySRV', 'MISRV');
$this->load->model('ModelType', 'MType');
$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('ModelDvd', 'MDvd');
$this->load->model('ModelRaid', 'MRaid');
$this->load->model('ModelKeyMou', 'MKeyMou');
$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("Action");
} elseif ($jabatan != "ADMIN") {
redirect("Action");
}
$datInventorySRV = $this->MIPC->getDataInventorySRV();
$data = [
'sidebar' => "data inventory",
'navChild' => "data inventory sku",
'server' => $datInventorySRV
];
$this->load->view('inventory/table-inventory', $data);
}
public function add()
{
$username = $this->session->userdata('username');
if ($username == null) {
redirect("Login");
}
$datInventorySRV = $this->MIPC->getDataInventorySRV();
$datType = $this->MType->getDataType();
$datProcessor = $this->MProcessor->getDataProcessor();
$datRam = $this->MRam->getDataRam();
$datHarddisk = $this->MHarddisk->getDataHarddisk();
$datSsd = $this->MSsd->getDataSsd();
$datDvd = $this->MDvd->getDataDvd();
$datRaid = $this->MSp->getDataRaid();
$datKeyMou = $this->MKeyMou->getDataKeyMou();
$data = [
'sidebar' => "data inventory",
'navChild' => "data inventory sku",
'server' => $datInventorySRV,
'type' => $datType,
'processor' => $datProcessor,
'ram' => $datRam,
'hdd' => $datHarddisk,
'ssd' => $datSsd,
'dvd' => $datDvd,
'raid' => $datRaid,
'keymou' => $datKeyMou
];
//var_dump($data);
$this->load->view('inventory/inventory-tambahsrv', $data);
}
public function save()
{
$method = $this->input->post('method');
$id_pc = $this->input->post('id');
$no_notapembelian = $this->input->post('no_notapembelian');
$type = $this->input->post('TYPE');
$processor = $this->input->post('PROCESSOR');
$ram = $this->input->post('RAM');
$hdd = $this->input->post('HDD');
$ssd = $this->input->post('SSD');
$dvd = $this->input->post('DVD');
$raid = $this->input->post('RAID');
$keymou = $this->input->post('KEYMOU');
$this->form_validation->set_rules('no_notapembelian', 'Nota Pembelian', 'required');
$this->form_validation->set_rules('TYPE', 'Pilih Type', 'required');
$this->form_validation->set_rules('PROCESSOR', 'Pilih Processor', 'required');
$this->form_validation->set_rules('RAM', 'Pilih RAM', 'required');
$this->form_validation->set_rules('HDD', 'Pilih HDD', 'required');
$this->form_validation->set_rules('SSD', 'Pilih SSD', 'required');
$this->form_validation->set_rules('DVD', 'Pilih Dvd', 'required');
$this->form_validation->set_rules('RAID', 'Pilih RAID Card', 'required');
$this->form_validation->set_rules('KEYMOU', 'Pilih Keyboard Mouse', 'required');
if ($this->form_validation->run() == FALSE) {
$data = [
'status' => false,
'errors' => [
'no_notapembelian' => form_error('no_notapembelian'),
'TYPE' => form_error('TYPE'),
'PROCESSOR' => form_error('PROCESSOR'),
'RAM' => form_error('RAM'),
'HDD' => form_error('HDD'),
'SSD' => form_error('SSD'),
'DVD' => form_error('DVD'),
'RAID' => form_error('RAID'),
'KEYMOU' => form_error('KEYMOU')
]
];
//$this->output_json($data);//
$this->session->set_flashdata('flashgagal', 'ditambah');
redirect('ManageInventorySRV');
} else {
$input = [
'NO_NOTAPEMBELIAN' => $no_notapembelian,
'ID_TYPE' => $type,
'ID_PROCESSOR' => $processor,
'ID_RAM' => $ram,
'ID_HDD' => $hdd,
'ID_SSD' => $ssd,
'ID_DVD' => $dvd,
'ID_RAID' => $raid,
'ID_KEYMOU' => $keymou
];
$action = $this->MISRV->create('server', $input);
if ($action) {
$this->session->set_flashdata('flash', 'ditambah');
//$this->output_json(['status' => true]);
redirect('ManageInventorySRV');
} else {
$this->session->set_flashdata('flashgagal', 'ditambah');
//$this->output_json(['status' => true]);
redirect('ManageInventorySRV');
}
}
}
public function hapus()
{
$id = $this->input->post('id');
if ($this->MISRV->delete('server', $id, 'ID_SERVER')) {
$this->session->set_flashdata('flash', 'dihapus');
redirect('ManageInventorySRV');
}
}
}