copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class ManageKontak 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 dataKontak_Sales_A1($id_akun=null) {
|
||||
$id_karyawan = $this->session->userdata('id_karyawan');
|
||||
$datShm = $this->Dashboard->getData_SetHakMaster_byKARYAWAN($id_karyawan);
|
||||
$datAkun = $this->Dashboard->getData_Akun();
|
||||
$datPosisi = $this->Dashboard->getData_Posisi();
|
||||
|
||||
if ($id_akun==NULL) {
|
||||
$title = "Belum Terpilih*";
|
||||
$kontak = $this->Dashboard->getData_Kontak();
|
||||
} else {
|
||||
$dataAkun = $this->Dashboard->getData_Akun($id_akun);
|
||||
$nama_akun = $dataAkun[0]['NAMA_AKUN'];
|
||||
$title = "$nama_akun";
|
||||
$kontak = $this->Dashboard->getData_Kontak($id_akun);
|
||||
}
|
||||
|
||||
$no = 0;
|
||||
foreach ($kontak as $key) {
|
||||
$datSav = $this->Dashboard->getData_SalesVisit_byKONTAK($key['ID_KONTAK']);
|
||||
if ($datSav==TRUE) {
|
||||
$lock = 1;
|
||||
} else {
|
||||
$lock = 0;
|
||||
}
|
||||
$kontak[$no++] += ['LOCK' => $lock];
|
||||
}
|
||||
|
||||
if ($datShm[0]['KONTAK_SHM']==0) {
|
||||
$akses = "Tidak Berhak";
|
||||
$kontak = NULL;
|
||||
} else if ($datShm[0]['KONTAK_SHM']==1) {
|
||||
$akses = "Hanya Baca";
|
||||
} else if ($datShm[0]['KONTAK_SHM']==2) {
|
||||
$akses = "Akses Penuh";
|
||||
}
|
||||
|
||||
$data = [
|
||||
'sidebar' => "dashboard",
|
||||
'navChild' => "",
|
||||
'title' => $title,
|
||||
'kontak' => $kontak,
|
||||
'akun' => $datAkun,
|
||||
'posisi' => $datPosisi,
|
||||
'id_akun' => $id_akun,
|
||||
'hak' => $datShm[0]['KONTAK_SHM'],
|
||||
'akses' => $akses,
|
||||
];
|
||||
$this->load->view('master/Kontak', $data);
|
||||
}
|
||||
|
||||
public function simpankontak_A1() {
|
||||
$method = $this->input->post('method');
|
||||
$id_kontak = $this->input->post('id');
|
||||
$id_akun = $this->input->post('id_akun');
|
||||
$id_posisi = $this->input->post('id_posisi');
|
||||
$nama_kontak = $this->input->post('nama_kontak');
|
||||
$email_kontak = $this->input->post('email_kontak');
|
||||
$telp_kontak = $this->input->post('telp_kontak');
|
||||
$ket_kontak = $this->input->post('ket_kontak');
|
||||
|
||||
$datKontak = $this->Dashboard->getData_Kontak_byNAMA($nama_kontak);
|
||||
foreach ($datKontak as $key) {
|
||||
if ($id_akun==$key['AKUN_ID'] AND $id_posisi==$key['POSISI_ID']) {
|
||||
$this->session->set_flashdata('data_copy', 'error');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
|
||||
$ket_kontak = preg_replace('/\R+/', " " , $ket_kontak);
|
||||
$input = [
|
||||
'AKUN_ID' => $id_akun,
|
||||
'POSISI_ID' => $id_posisi,
|
||||
'NAMA_KONTAK' => $nama_kontak,
|
||||
'EMAIL_KONTAK' => $email_kontak,
|
||||
'TELP_KONTAK' => $telp_kontak,
|
||||
'KET_KONTAK' => $ket_kontak,
|
||||
];
|
||||
$action = $this->Dashboard->create('kontak', $input);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('success', 'ditambah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('failed', 'ditambah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function ubahkontak_A1() {
|
||||
$method = $this->input->post('method');
|
||||
$id_kontak = $this->input->post('id_kontaked');
|
||||
$id_akun = $this->input->post('id_akuned');
|
||||
$id_posisi = $this->input->post('id_posisied');
|
||||
$nama_kontak = $this->input->post('nama_kontaked');
|
||||
$email_kontak = $this->input->post('email_kontaked');
|
||||
$telp_kontak = $this->input->post('telp_kontaked');
|
||||
$ket_kontak = $this->input->post('ket_kontaked');
|
||||
|
||||
$datKontak = $this->Dashboard->getData_Kontak_byNAMA($nama_kontak, $id_kontak);
|
||||
foreach ($datKontak as $key) {
|
||||
if ($id_akun==$key['AKUN_ID'] AND $id_posisi==$key['POSISI_ID']) {
|
||||
$this->session->set_flashdata('data_copy', 'error');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
|
||||
$ket_kontak = preg_replace('/\R+/', " " , $ket_kontak);
|
||||
$update = [
|
||||
'AKUN_ID' => $id_akun,
|
||||
'POSISI_ID' => $id_posisi,
|
||||
'NAMA_KONTAK' => $nama_kontak,
|
||||
'EMAIL_KONTAK' => $email_kontak,
|
||||
'TELP_KONTAK' => $telp_kontak,
|
||||
'KET_KONTAK' => $ket_kontak,
|
||||
];
|
||||
$action = $this->Dashboard->update('kontak', $update, 'ID_KONTAK', $id_kontak);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('success', 'diubah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('failed', 'diubah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function hapuskontak_A1() {
|
||||
$id = $this->input->post('id_kontakdel');
|
||||
|
||||
$datSav = $this->Dashboard->getData_SalesVisit_byKONTAK($id);
|
||||
if ($datSav==TRUE) {
|
||||
$this->session->set_flashdata('data_used', 'error');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
$action = $this->Dashboard->delete('kontak', $id, 'ID_KONTAK');
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('success', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('failed', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function simpan_excel_kontak() {
|
||||
$id_akun = $this->input->post('id_akun');
|
||||
$pilih_tabel = array('No', 'Akun', 'Nama' ,'Posisi', 'Telepon', 'Email', 'Keterangan');
|
||||
$tgl = date('d/m/Y');
|
||||
|
||||
if ($id_akun == NULL ) {
|
||||
$dataExcel = $this->Dashboard->getData_Kontak();
|
||||
} else {
|
||||
$dataExcel = $this->Dashboard->getData_Kontak($id_akun);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'title' => '',
|
||||
'jumlah_kolom' => count($pilih_tabel),
|
||||
'nama_tabel' => $pilih_tabel,
|
||||
'laporan' => $dataExcel,
|
||||
'tgl' => $tgl,
|
||||
];
|
||||
$this->load->view('cetak/excel_kontak', $data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user