145 lines
4.2 KiB
PHP
145 lines
4.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageCustomer extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelDashboard', 'Dashboard');
|
|
$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');
|
|
$datShm = $this->Dashboard->getData_SetHakMaster_byKARYAWAN($id_karyawan);
|
|
$datCustomer = $this->Dashboard->getData_Customer();
|
|
|
|
$no = 0;
|
|
foreach ($datCustomer as $key) {
|
|
$datRekapPajak = $this->Dashboard->getData_RekapPajak_byCUSTOMER($key['ID_CUSTOMER']);
|
|
if ($datRekapPajak==TRUE) {
|
|
$lock = 1;
|
|
} else {
|
|
$lock = 0;
|
|
}
|
|
$datCustomer[$no++] += ['LOCK' => $lock];
|
|
}
|
|
|
|
if ($datShm[0]['CUSTOMER_SHM']==0) {
|
|
$akses = "Tidak Berhak";
|
|
$datCustomer = NULL;
|
|
} else if ($datShm[0]['CUSTOMER_SHM']==1) {
|
|
$akses = "Hanya Baca";
|
|
} else if ($datShm[0]['CUSTOMER_SHM']==2) {
|
|
$akses = "Akses Penuh";
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "dashboard",
|
|
'navChild' => "",
|
|
'customer' => $datCustomer,
|
|
'hak' => $datShm[0]['CUSTOMER_SHM'],
|
|
'akses' => $akses,
|
|
];
|
|
$this->load->view('master/Customer', $data);
|
|
}
|
|
|
|
public function simpan() {
|
|
$method = $this->input->post('method');
|
|
$id_customer = $this->input->post('id');
|
|
$nama_customer = $this->input->post('nama_customer');
|
|
$npwp_customer = $this->input->post('npwp_customer');
|
|
$alamat_customer = $this->input->post('alamat_customer');
|
|
|
|
$nama_customer = strtoupper($nama_customer);
|
|
$alamat_customer = strtoupper($alamat_customer);
|
|
$alamat_customer = preg_replace('/\R+/', " " , $alamat_customer);
|
|
|
|
$datCustomer = $this->Dashboard->getData_Customer_byALAMAT($alamat_customer);
|
|
if ($datCustomer==TRUE) {
|
|
$this->session->set_flashdata('data_same', 'error');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
$input = [
|
|
'NAMA_CUSTOMER' => $nama_customer,
|
|
'NPWP_CUSTOMER' => $npwp_customer,
|
|
'ALAMAT_CUSTOMER' => $alamat_customer
|
|
];
|
|
$action = $this->Dashboard->create('customer', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect('ManageCustomer');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
}
|
|
|
|
public function ubah() {
|
|
$method = $this->input->post('method');
|
|
$id_customer = $this->input->post('id_customered');
|
|
$nama_customer = $this->input->post('nama_customered');
|
|
$npwp_customer = $this->input->post('npwp_customered');
|
|
$alamat_customer = $this->input->post('alamat_customered');
|
|
|
|
$nama_customer = strtoupper($nama_customer);
|
|
$alamat_customer = strtoupper($alamat_customer);
|
|
$alamat_customer = preg_replace('/\R+/', " " , $alamat_customer);
|
|
|
|
$datCustomer = $this->Dashboard->getData_Customer_byALAMAT($alamat_customer, $id_customer);
|
|
if ($datCustomer==TRUE) {
|
|
$this->session->set_flashdata('data_same', 'error');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
$update = [
|
|
'NAMA_CUSTOMER' => $nama_customer,
|
|
'NPWP_CUSTOMER' => $npwp_customer,
|
|
'ALAMAT_CUSTOMER' => $alamat_customer
|
|
];
|
|
$action = $this->Dashboard->update('customer', $update, 'ID_CUSTOMER', $id_customer);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect('ManageCustomer');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
}
|
|
|
|
public function hapus() {
|
|
$id_customer = $this->input->post('id_customerdel');
|
|
|
|
$datCustomer = $this->Dashboard->getData_RekapPajak_byCUSTOMER($id_customer);
|
|
if ($datCustomer==TRUE) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
$action = $this ->Dashboard->delete('customer', $id_customer, 'ID_CUSTOMER');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect('ManageCustomer');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect('ManageCustomer');
|
|
}
|
|
|
|
}
|
|
|
|
}
|