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

188 lines
5.2 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class ManageService extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('ModelService', 'MS');
$this->load->model('ModelPelanggan', 'MPe');
$this->load->model('ModelProgress', 'MPr');
$this->load->model('ModelBarang', 'MB');
$this->load->model('ModelOperator', 'MO');
$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");
}
$datService = $this->MS->getDataService2();
$data = [
'sidebar' => "data master service",
'navChild' => "data proses service",
'service' => $datService
];
$this->load->view('master/Service', $data);
}
public function add()
{
$method = $this->input->post('method');
$id_barang = $this->input->post('id_barang');
$sn_progress = $this->input->post('sn_progress');
$garansi_progress = $this->input->post('garansi_progress');
$keluhan_progress = $this->input->post('keluhan_progress');
$keterangan_progress = $this->input->post('keterangan_progress');
$username = $this->session->userdata('username');
if ($username == null) {
redirect("Login");
}
$datService = $this->MS->getDataService();
$datProgress = $this->MS->getDataProgress();
$datPelanggan = $this->MS->getDataPelanggan();
$datOperator = $this->MS->getDataOperator();
$datBarang = $this->MS->getDataBarang();
if ($method == null) {
$data = [
'sidebar' => "data master service",
'navChild' => "data proses service",
'service' => $datService,
'progress' => $datProgress,
'pelanggan' => $datPelanggan,
'operator' => $datOperator,
'barang' => $datBarang
];
$this->load->view('proses/TambahService', $data);
} else if ($method === 'add') {
$this->form_validation->set_rules('id_barang', 'Barang', 'required');
if ($this->form_validation->run() == FALSE) {
$data = [
'status' => false,
'errors' => [
'id_barang' => form_error('id_barang')
]
];
$this->output_json($data);
} else {
$method = null;
$input = [
'BARANG_ID' => $id_barang,
'SN_PROGRESS' => $sn_progress,
'GARANSI_PROGRESS' => $garansi_progress,
'KELUHAN_PROGRESS' => $keluhan_progress,
'KETERANGAN_PROGRESS' => $keterangan_progress
];
$action = $this->MS->create('progress', $input);
if ($action) {
$this->output_json(['status' => true]);
} else {
$this->output_json(['status' => false]);
}
}
}
}
public function edit()
{
$id_progress = $this->input->post('id_progress');
$sn_progress = $this->input->post('sn_progressed');
$id_barang = $this->input->post('id_baranged');
$garansi_progress = $this->input->post('garansi_progressed');
$keluhan_progress = $this->input->post('keluhan_progressed');
$keterangan_progress = $this->input->post('keterangan_progressed');
$method = $this->input->post('method');
$input = [
'BARANG_ID' => $id_barang,
'SN_PROGRESS' => $sn_progress,
'GARANSI_PROGRESS' => $garansi_progress,
'KELUHAN_PROGRESS' => $keluhan_progress,
'KETERANGAN_PROGRESS' => $keterangan_progress
];
$action = $this->MS->update('progress', $input, 'ID_PROGRESS', $id_progress);
if ($action) {
$this->session->set_flashdata('flash_ser_pro', 'diubah');
redirect('ManageService/add');
} else {
$this->session->set_flashdata('flashgagal', 'diubah');
redirect('ManageService/add');
}
}
public function save()
{
$id_pelanggan = $this->input->post('id_pelanggan');
$id_operator = $this->input->post('id_operator');
$kode_service = $this->input->post('kode_service');
$inputservice = [
'PELANGGAN_ID' => $id_pelanggan,
'OPERATOR_ID' => $id_operator,
'KODE_SERVICE' => $kode_service
];
$actionservice = $this->MS->create('service', $inputservice);
if ($actionservice) {
$cariservice = $this->MS->getIDService($kode_service);
$cariprogress = $this->MS->getIDProgress();
if (is_array($cariprogress) || is_object($cariprogress)) {
foreach ($cariprogress as $key) {
$up = [
'SERVICE_ID' => $cariservice[0]['ID_SERVICE']
];
$uppel = $this->MS->update('progress', $up, 'ID_PROGRESS', $key['ID_PROGRESS']);
}
}
if ($uppel) {
$this->session->set_flashdata('flash_ser_pro', 'ditambah');
redirect('ManageService');
} else {
$this->session->set_flashdata('flashgagal', 'ditambah');
redirect('ManageService');
}
} else {
$this->session->set_flashdata('flashgagal', 'ditambah');
redirect('ManageService');
}
}
public function hapus()
{
$id_service = $this->input->post('id');
if ($this->MS->delete('progress', $id_progress, 'ID_PROGRESS')) {
$this->session->set_flashdata('flash_ser_pro', 'dihapus');
redirect('ManageService/add');
}
}
}