<?php defined('BASEPATH') or exit('No direct script access allowed');

class Update_model extends CI_Model
{
    // Hapus Data Arisan Proses
    function hapusDataArisan($regist_arisan)
    {
        $this->db->like('ket_cadangan', $regist_arisan, 'both');
        $this->db->delete('anggota_hp_cadangan');
        $this->db->where('regist_arisan', $regist_arisan);
        $this->db->delete('p_arisan_anggota');
        $this->db->where('id', $regist_arisan);
        $this->db->delete('p_arisan');
    }
    function ubahDataArisan($regist_arisan)
    {
        $data = array(
            'target_anggota'   => htmlspecialchars($this->input->post('ttl_anggota')),
            'tagihan_iuran'   => htmlspecialchars($this->input->post('tagihan_iuran')),
            'tempo'   => htmlspecialchars($this->input->post('tempo')),
            'hg_standar'   => htmlspecialchars($this->input->post('hg_modal')),
            'admin_arisan'   => htmlspecialchars($this->input->post('fee_admin')),
            'hg_target'   => htmlspecialchars($this->input->post('hg_jual'))
        );
        $this->db->where('id', $regist_arisan);
        $this->db->update('p_arisan', $data);
    }
    // Ubah data Arisan Motor
    function ubahDataArisanMotor($regist_arisan)
    {
        $hg_jual                  = htmlspecialchars($this->input->post('hg_standar')) + htmlspecialchars($this->input->post('admin_arisan')) + htmlspecialchars($this->input->post('dana_kehilangan'));
        $data = array(
            'target_anggota'         => htmlspecialchars($this->input->post('target_anggota')),
            'tagihan_iuran'       => htmlspecialchars($this->input->post('tagihan_iuran')),
            'tempo'               => htmlspecialchars($this->input->post('target_anggota')),
            'hg_standar'            => htmlspecialchars($this->input->post('hg_standar')),
            'hg_target'             => $hg_jual,
            'admin_arisan'           => htmlspecialchars($this->input->post('admin_arisan')),
            'dana_kehilangan'     => htmlspecialchars($this->input->post('dana_kehilangan')),
            'ket_arisan'          => htmlspecialchars($this->input->post('nm_kelompok'))
        );
        $this->db->where('id', $regist_arisan);
        $this->db->update('p_arisan', $data);
    }
    // Menambahkan anggota arisan heboh Beranda
    function UpdateDataAnggotaArisanHebohBeranda1($alamat_id, $buat_noregist_undian, $anggota_id)
    {
        $cek_data_anggota = $this->db->get_where('tbl_anggota', ['id' => $anggota_id])->row_array();
        $link_foto_lama   = $cek_data_anggota['foto_ktp'];
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Gagal Upload Foto KTP</div>');
            redirect('arisan');
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $alamat_id,
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $anggota_id);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
            $berkas_lama = './assets/foto_ktp/' . $link_foto_lama . '';
            unlink($berkas_lama);
            $data_tambah_arisan = array(
                'id_arisan'             => htmlspecialchars($this->input->post('id_arisan')),
                'id_anggota'            => $anggota_id,
                'no_regist'             => $buat_noregist_undian['regist_arisan'],
                'no_arisan'             => $buat_noregist_undian['undian_arisan'],
                'status'                => 'AKTIF',
                'login_id'              => $this->session->userdata('isloggedin')
            );
            $this->db->insert('tbl_arisan_anggota', $data_tambah_arisan);
        endif;
    }
    function UpdateDataAnggotaArisanHebohBeranda2($alamat_id, $buat_noregist_undian, $anggota_id)
    {
        $cek_data_anggota = $this->db->get_where('tbl_anggota', ['id' => $anggota_id])->row_array();
        $link_foto_lama   = $cek_data_anggota['foto_ktp'];
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Gagal Upload Foto KTP</div>');
            redirect('arisan');
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $alamat_id,
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $anggota_id);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
            $berkas_lama = './assets/foto_ktp/' . $link_foto_lama . '';
            unlink($berkas_lama);
            $data_tambah_arisan = array(
                'id_arisan'             => htmlspecialchars($this->input->post('id_arisan')),
                'id_anggota'            => $anggota_id,
                'no_regist'             => $buat_noregist_undian['regist_arisan'],
                'no_arisan'             => $buat_noregist_undian['undian_arisan'],
                'status'                => 'AKTIF',
                'login_id'              => $this->session->userdata('isloggedin')
            );
            $this->db->insert('tbl_arisan_anggota', $data_tambah_arisan);
            $hp_cadangan = array(
                'anggota_id'             => $anggota_id,
                'no_hp'                  => htmlspecialchars($this->input->post('no_hp')),
                'ket_cadangan'           => 'Nomor Cadangan Nomor Registrasi ' . $buat_noregist_undian['regist_arisan']
            );
            $this->db->insert('tbl_hpcadangan', $hp_cadangan);
        endif;
    }
    // Menambahkan anggota arisan motor Beranda
    function UpdateDataAnggotaArisanMotorBeranda1($alamat_id, $buat_noregist_undian, $anggota_id)
    {
        $cek_data_anggota = $this->db->get_where('tbl_anggota', ['id' => $anggota_id])->row_array();
        $link_foto_lama   = $cek_data_anggota['foto_ktp'];
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Gagal Upload Foto KTP</div>');
            redirect('arisan');
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $alamat_id,
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $anggota_id);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
            $berkas_lama = './assets/foto_ktp/' . $link_foto_lama . '';
            unlink($berkas_lama);
            $data_tambah_arisan = array(
                'id_arisan'             => htmlspecialchars($this->input->post('id_arisan')),
                'id_anggota'            => $anggota_id,
                'no_regist'             => $buat_noregist_undian['regist_arisan'],
                'no_arisan'             => $buat_noregist_undian['undian_arisan'],
                'status'                => 'AKTIF',
                'login_id'              => $this->session->userdata('isloggedin')
            );
            $this->db->insert('tbl_arisan_anggota', $data_tambah_arisan);
        endif;
    }
    function UpdateDataAnggotaArisanMotorBeranda2($alamat_id, $buat_noregist_undian, $anggota_id)
    {
        $cek_data_anggota = $this->db->get_where('tbl_anggota', ['id' => $anggota_id])->row_array();
        $link_foto_lama   = $cek_data_anggota['foto_ktp'];
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Gagal Upload Foto KTP</div>');
            redirect('arisan');
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $alamat_id,
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $anggota_id);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
            $berkas_lama = './assets/foto_ktp/' . $link_foto_lama . '';
            unlink($berkas_lama);
            $data_tambah_arisan = array(
                'id_arisan'             => htmlspecialchars($this->input->post('id_arisan')),
                'id_anggota'            => $anggota_id,
                'no_regist'             => $buat_noregist_undian['regist_arisan'],
                'no_arisan'             => $buat_noregist_undian['undian_arisan'],
                'status'                => 'AKTIF',
                'login_id'              => $this->session->userdata('isloggedin')
            );
            $this->db->insert('tbl_arisan_anggota', $data_tambah_arisan);
            $hp_cadangan = array(
                'anggota_id'             => $anggota_id,
                'no_hp'                  => htmlspecialchars($this->input->post('no_hp')),
                'ket_cadangan'           => 'Nomor Cadangan Nomor Registrasi ' . $buat_noregist_undian['regist_arisan']
            );
            $this->db->insert('tbl_hpcadangan', $hp_cadangan);
        endif;
    }
    // Menambahkan data Anggota pada Arisan Heboh
    function gantiAnggotaArisanHebohBaru($data_inputan, $alamat_id, $regist_undian, $produk_id)
    {
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Gagal Upload Foto KTP</div>');
            if ($produk_id == 21) :
                redirect('arisan/data/kelompok_heboh/kelompok/' . $this->encrypt->encode($data_inputan['arisan_id']));
            else :
                redirect('arisan/data/kelompok_motor/kelompok/' . $this->encrypt->encode($data_inputan['arisan_id']));
            endif;
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nik'               => htmlspecialchars($this->input->post('nik')),
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $alamat_id,
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'no_hp'             => htmlspecialchars($this->input->post('no_hp')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->insert('anggota', $data_anggota_koperasi);
            $cek_anggota = $this->db->get_where('anggota', ['nik' => htmlspecialchars($this->input->post('nik'))])->row_array();
            $data_tambah_arisan = array(
                'anggota_id'            => $cek_anggota['id'],
                'status'                => 'AKTIF',
            );
            $this->db->where('regist_undian', $regist_undian);
            $this->db->update('p_arisan_anggota', $data_tambah_arisan);
            // Tambah Nomor Cadangan
            $data_cadangan = array(
                'anggota_id'   => $cek_anggota['id'],
                'no_hp'        => $data_inputan['no_hp'],
                'ket_cadangan' => 'Nomor ' . $data_inputan['no_hp'] . ' di daftarkan sebagai nomor Cadangan Anggota Arisan Heboh ' . $regist_undian
            );
            $this->db->insert('anggota_hp_cadangan', $data_cadangan);
        endif;
    }
    function anggotaKoperasiMundur($regist_undian)
    {
        $data = array(
            'status'        => 'MUNDUR'
        );
        $this->db->where('regist_undian', $regist_undian);
        $this->db->update('p_arisan_anggota', $data);
    }
    function anggotaKoperasiMundurHapus($regist_undian)
    {
        $this->db->where('regist_undian', $regist_undian);
        $this->db->delete('p_arisan_anggota');
    }
    function terimaAnggota($cek_pengajuan)
    {
        $this->db->where('id', $cek_pengajuan['id']);
        $this->db->delete('p_arisan_pengajuan');
    }
    // Aktivasi produk arisan heboh
    function aktifDataArisan($regist_arisan)
    {
        $data = array(
            'status_arisan'        => 'AKTIF',
            'tgl_undian'           => htmlspecialchars($this->input->post('tgl_undian'))
        );
        $this->db->where('id', $regist_arisan);
        $this->db->update('p_arisan', $data);
        $this->db->where('regist_arisan', $regist_arisan);
        $this->db->delete('p_arisan_pengajuan');
    }
    function aktifDataArisanMotor($regist_arisan, $tgl_undian, $undian_ke)
    {
        $data_jadwal = array(
            'regist_arisan'    => $regist_arisan,
            'tgl_undian'       => $tgl_undian,
            'undian_ke'        => $undian_ke,
            'lelang_ke'        => 1,
            'status_undian'    => 'BELUM'
        );
        $this->db->insert('p_arisan_jadwal', $data_jadwal);
        $data = array(
            'status_arisan'   => 'AKTIF',
            'tgl_undian' => htmlspecialchars($this->input->post('tgl_undian'))
        );
        $this->db->where('id', $regist_arisan);
        $this->db->update('p_arisan', $data);
        $this->db->where('regist_arisan', $regist_arisan);
        $this->db->delete('p_arisan_pengajuan');
    }
    function hapusAnggotaKeluarga($anggota_id)
    {
        $this->db->where('anggota_id', $anggota_id);
        $this->db->delete('p_arisan_anggota_keluarga');
    }
    function hapusDataKeluarga($id_keluarga)
    {
        $this->db->where('arisan_keluarga_id', $id_keluarga);
        $this->db->delete('tbl_arisan_keluarga_detail');
        $this->db->where('id', $id_keluarga);
        $this->db->delete('tbl_arisan_keluarga');
    }
    function ubahJadwalArisan($regist_arisan)
    {
        $data = array(
            'tgl_undian'   => htmlspecialchars($this->input->post('tgl_undian'))
        );
        $this->db->where('regist_arisan', $regist_arisan);
        $this->db->where('undian_ke', htmlspecialchars($this->input->post('undian_ke')));
        $this->db->update('p_arisan_jadwal', $data);
    }
    function ubahDataAnggotaLelang($jadwal_id, $nomor_urut)
    {
        $data = array(
            'status_lelang' => 'MENANG'
        );
        $this->db->where('lelang_ke', $jadwal_id);
        $this->db->where('regist_undian', $nomor_urut);
        $this->db->where('total_lelang', htmlspecialchars($this->input->post('saldo_masuk')));
        $this->db->update('tbl_arisan_lelang', $data);
    }
    function ubahDataJadwalMotor($jadwal_id, $nomor_urut)
    {
        $data = array(
            'status_undian' => 'SELESAI',
            'pemenang_id'   => $nomor_urut,
            'updated_at'    => date("Y-m-d H:i:s")
        );
        $this->db->where('id', $jadwal_id);
        $this->db->update('tbl_jadwal_undian', $data);
    }
    function ubahDataAnggotaMenang($nomor_urut)
    {
        $data = array(
            'status'        => 'MENANG',
            'updated_at'    => date("Y-m-d H:i:s")
        );
        $this->db->where('no_regist', $nomor_urut);
        $this->db->update('tbl_arisan_anggota', $data);
    }
    function updateDataAnggota($data_inputan, $cek_alamat)
    {
        $link_foto_lama   = $data_inputan['foto_ktp_old'];
        $config['upload_path']   = './assets/foto_ktp';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name']  = true;
        $config['overwrite']     = true;
        $config['quality']       = '50%';
        $config['max_size']      = 10024; // 10MB
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('foto_ktp')) :
            $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil merubah data anggota!</div>');
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $cek_alamat['alamat_id'],
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $data_inputan['id_anggota']);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
        else :
            $_FILES['file']['name'] = $_FILES['foto_ktp']['name'];
            $_FILES['file']['type'] = $_FILES['foto_ktp']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['foto_ktp']['tmp_name'];
            $_FILES['file']['size'] = $_FILES['foto_ktp']['size'];
            $uploadData = $this->upload->data();
            // Inputan
            $data_anggota_koperasi = array(
                'nm_anggota'        => htmlspecialchars($this->input->post('nm_anggota')),
                'jk'                => htmlspecialchars($this->input->post('jk')),
                'alamat_lengkap'    => htmlspecialchars($this->input->post('alamat_lengkap')),
                'id_alamat'         => $cek_alamat['alamat_id'],
                'tempat_lahir'      => htmlspecialchars($this->input->post('tempat_lahir')),
                'tgl_lahir'         => htmlspecialchars($this->input->post('tgl_lahir')),
                'pekerjaan'         => htmlspecialchars($this->input->post('pekerjaan')),
                'suami_istri'       => htmlspecialchars($this->input->post('suami_istri')),
                'foto_ktp'          => $uploadData['file_name'],
                'status_anggota'    => 'CALON'
            );
            $this->db->where('id', $data_inputan['id_anggota']);
            $this->db->update('tbl_anggota', $data_anggota_koperasi);
            $berkas_lama = './assets/foto_ktp/' . $link_foto_lama . '';
            unlink($berkas_lama);
            $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil merubah data anggota!</div>');
        endif;
    }
    // Merubah data anggota arisan heboh jadi pemenang
    function ubahStatusAnggotaAH($da_menang)
    {
        $data_pemenang = array(
            'status' => 'MENANG',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('regist_undian', $da_menang['regist_undian']);
        $this->db->update('p_arisan_anggota', $data_pemenang);
    }
    // Merubah data jadwal arisan heboh
    function ubahJadwalSekarang($jadwal_arisan_sekarang)
    {
        $data_ubah = array(
            'status_undian' => 'SELESAI',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('id', $jadwal_arisan_sekarang['id']);
        $this->db->update('p_arisan_jadwal', $data_ubah);
        $data_arisan = $this->db->get_where('p_arisan', ['id' => $jadwal_arisan_sekarang['regist_arisan']])->row_array();
        $undian_baru    =  date('Y-m', strtotime('+1 month', strtotime($jadwal_arisan_sekarang['tgl_undian'])));
        $tgl_baru       = $undian_baru . '-' . $data_arisan['tgl_undian'];
        $regist_arisan  = $jadwal_arisan_sekarang['regist_arisan'];
        $jadwal_baru    = array(
            'regist_arisan'  => $regist_arisan,
            'tgl_undian'     => $tgl_baru,
            'undian_ke'      => $jadwal_arisan_sekarang['undian_ke'] + 1,
            'lelang_ke'      => 0,
            'status_undian'  => 'BELUM'
        );
        $this->db->insert('p_arisan_jadwal', $jadwal_baru);
    }
    // Merubah status anggota arisan motor
    function ubahDataPemenangMotor01($regist_undian)
    {
        $data = array(
            'status'     => 'MENANG',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('regist_undian', $regist_undian);
        $this->db->update('p_arisan_anggota', $data);
    }
    // Merubah dan menambahkan data jadwal baru
    function ubahTambahJadwalMotor01($jadwal_arisan, $data_arisan)
    {
        // Merubah Data Jadwal Arisan
        $data_jadwal = array(
            'status_undian' => 'SELESAI',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('id', $jadwal_arisan['id']);
        $this->db->update('p_arisan_jadwal', $data_jadwal);
        // Menambahkan data jadwal arisan motor baru
        $data_arisan    = $this->db->get_where('p_arisan', ['id' => $jadwal_arisan['regist_arisan']])->row_array();
        $undian_baru    =  date('Y-m', strtotime('+1 month', strtotime($jadwal_arisan['tgl_undian'])));
        $tgl_baru       = $undian_baru . '-' . $data_arisan['tgl_undian'];
        $data = array(
            'regist_arisan'     => $jadwal_arisan['regist_arisan'],
            'tgl_undian'        => $tgl_baru,
            'undian_ke'         => $jadwal_arisan['undian_ke'] + 1,
            'lelang_ke'         => $jadwal_arisan['lelang_ke'] + 1,
            'status_undian'     => 'BELUM'
        );
        $this->db->insert('p_arisan_jadwal', $data);
    }
    // Merubah dan menambahkan data jadwal baru
    function ubahTambahJadwalMotor01Lanjutan($jadwal_arisan)
    {
        // Merubah Data Jadwal Arisan
        $data_jadwal = array(
            'status_undian' => 'SELESAI',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('id', $jadwal_arisan['id']);
        $this->db->update('p_arisan_jadwal', $data_jadwal);
        // Menambahkan data jadwal arisan motor baru
        $data = array(
            'regist_arisan'     => $jadwal_arisan['regist_arisan'],
            'tgl_undian'        => $jadwal_arisan['tgl_undian'],
            'undian_ke'         => $jadwal_arisan['undian_ke'],
            'lelang_ke'         => $jadwal_arisan['lelang_ke'] + 1,
            'status_undian'     => 'BELUM'
        );
        $this->db->insert('p_arisan_jadwal', $data);
    }
    // Merubah status anggota arisan motor 2
    function ubahDataPemenangMotor02($data_lelang)
    {
        $data = array(
            'status'     => 'MENANG',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('regist_undian', $data_lelang['regist_undian']);
        $this->db->update('p_arisan_anggota', $data);
    }
    // Merubah dan menambahkan data jadwal baru 2
    function ubahTambahJadwalMotor02($data_jadwal2, $data_arisan)
    {
        // Merubah Data Jadwal Arisan
        $data_jadwal = array(
            'status_undian' => 'SELESAI',
            'updated_at' => date("Y-m-d H:i:s")
        );
        $this->db->where('id', $data_jadwal2['id']);
        $this->db->update('p_arisan_jadwal', $data_jadwal);
        // Menambahkan data jadwal arisan motor baru
        $data_arisan    = $this->db->get_where('p_arisan', ['id' => $data_jadwal2['regist_arisan']])->row_array();
        $undian_baru    =  date('Y-m', strtotime('+1 month', strtotime($data_jadwal2['tgl_undian'])));
        $tgl_baru       = $undian_baru . '-' . $data_arisan['tgl_undian'];
        $data = array(
            'regist_arisan'     => $data_jadwal2['regist_arisan'],
            'tgl_undian'        => $tgl_baru,
            'undian_ke'         => $data_jadwal2['undian_ke'] + 1,
            'lelang_ke'         => $data_jadwal2['lelang_ke'] + 1,
            'status_undian'     => 'BELUM'
        );
        $this->db->insert('p_arisan_jadwal', $data);
    }
}
