Untitled

 avatar
unknown
plain_text
2 years ago
6.8 kB
4
Indexable
//controller tambah_pembelian
function tambah_pembelian(){
        // cek_session_akses('pembelian', $this->session->id_session);
        cek_session_karyawan();
    
        if (isset($_POST['submit1'])) {
            $latest_ticket = $this->model_app->get_latest_ticket_pr();
            $cekskrng = date('Ymd');
            $cekdata_akhir = substr($latest_ticket, 3, -3);
    
            if (empty($latest_ticket) || $cekskrng != $cekdata_akhir) {
                $new_number = 1;
            } else {
                $last_number = number_format(substr($latest_ticket, -3));
                $new_number = $last_number + 1;
            }
    
            $new_number_str = str_pad($new_number, 3, '0', STR_PAD_LEFT);
            $kd_pr = "PR-" . date('Ymd') . $new_number_str;
    
            $files = $_FILES;
            $cpt = count($_FILES['userfile']['name']);
            $images = array();
    
            for ($i = 0; $i < $cpt; $i++) {
                $_FILES['userfile']['name'] = $files['userfile']['name'][$i];
                $_FILES['userfile']['type'] = $files['userfile']['type'][$i];
                $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
                $_FILES['userfile']['error'] = $files['userfile']['error'][$i];
                $_FILES['userfile']['size'] = $files['userfile']['size'][$i];
    
                $this->load->library('upload', $_FILES);
                $this->upload->initialize($this->set_upload_optionss());
                $this->upload->do_upload();
    
                $fileName = $this->upload->data()['file_name'];
                $images[] = $fileName;
            }
    
            $fileName = implode(';', $images);
            $fileName = str_replace(' ', '_', $fileName);
    
            if ($this->session->idp == '') {
                $data = array(
                    'kd_pr' => $kd_pr,
                    'tgl_pr' => date('Y-m-d H:i:s'),
                    'user_create' => $this->session->nik,
                    'kategori_pr' => $this->input->post('b'),
                    'type_pr' => $this->input->post('c'),
                    'no_projek' => $this->input->post('d'),
                    'lokasi_projek' => $this->input->post('e'),
                    'tgl_kebutuhan' => $this->input->post('f'),
                    'no_job' => $this->input->post('h'),
                    'keterangan_pr' => $this->input->post('g'),
                    'file' => $fileName,
                    'status_pr' => "Draft"
                );
    
                $this->model_app->insert('mst_pembelian', $data);
                $idp = $this->db->insert_id();
                $this->session->set_userdata(array('idp' => $idp, 'kd' => $kd_pr));
            } else {
                $data = array(
                    'kategori_pr' => $this->input->post('b'),
                    'type_pr' => $this->input->post('c'),
                    'no_projek' => $this->input->post('d'),
                    'lokasi_projek' => $this->input->post('e'),
                    'tgl_kebutuhan' => $this->input->post('f'),
                    'no_job' => $this->input->post('h'),
                    'keterangan_pr' => $this->input->post('g'),
                    'file' => $fileName,
                    'status_pr' => "Draft"
                );
                $where = array('id_pembelian' => $this->session->idp);
                $this->model_app->update('mst_pembelian', $data, $where);
            }
    
            redirect('karyawan/tambah_pembelian');
        } elseif (isset($_POST['submit'])) {
            if ($this->input->post('idpd') == '') {
                $data = array(
                    'id_pembelian' => $this->session->idp,
                    'kd_pr' => $this->session->kd,
                    'kode_item' => $this->input->post('aa'),
                    'deskripsi_item' => $this->input->post('bb'),
                    'dimension_item' => $this->input->post('cc'),
                    'jumlah_item' => $this->input->post('dd'),
                    'satuan_item' => $this->input->post('ee'),
                    'status_item' => "Draft"
                );
                $this->model_app->insert('mst_pembelian_dtl', $data);
            } else {
                $data = array(
                    'id_pembelian' => $this->session->idp,
                    'kd_pr' => $this->session->kd,
                    'kode_item' => $this->input->post('aa'),
                    'deskripsi_item' => $this->input->post('bb'),
                    'dimension_item' => $this->input->post('cc'),
                    'jumlah_item' => $this->input->post('dd'),
                    'satuan_item' => $this->input->post('ee'),
                    'status_item' => "Draft"
                );
                $where = array('id_dpembelian' => $this->input->post('idpd'));
                $this->model_app->update('mst_pembelian_dtl', $data, $where);
            }
            redirect('karyawan/tambah_pembelian');
        } else {
            $data['rows'] = $this->model_app->view_where('mst_pembelian', array('id_pembelian' => $this->session->idp))->row_array();
            //$data['rows'] = $this->model_reseller->view_join_rows('rb_pembelian','rb_supplier','id_supplier',array('id_pembelian'=>$this->session->idp),'id_pembelian','DESC')->row_array();
            $data['record'] = $this->model_app->view_join_where('mst_pembelian_dtl', 'mst_item', 'kode_item', array('id_pembelian' => $this->session->idp), 'id_dpembelian', 'DESC');
            $data['kategori'] = $this->model_app->view_where_ordering('uti_setting', array('sub_modul' => 'kategori_pr'), 'id_uti', 'ASC');
            $data['type'] = $this->model_app->view_where_ordering('uti_setting', array('sub_modul' => 'type_pr'), 'id_uti', 'ASC');
            $data['lokasi'] = $this->model_app->view_where_ordering('uti_setting', array('sub_modul' => 'lokasi'), 'id_uti', 'ASC');
            $data['item'] = $this->model_app->view_where_ordering('mst_item', array('mstatus_item' => '1'), 'id_item', 'ASC');
    
            if ($this->uri->segment(3) != '') {
                $data['row'] = $this->model_app->view_where('mst_pembelian_dtl', array('id_dpembelian' => $this->uri->segment(3)))->row_array();
            }
    
            $this->template->load('karyawan/template', 'karyawan/additional/mod_pembelian/view_pembelian_tambah', $data);
        }
    }

    private function set_upload_optionss()
{
    $config = array();
    $config['upload_path'] = 'asset/foto_pr/';
    $config['allowed_types'] = '*';
    $config['max_size'] = '0'; // kb
    $config['encrypt_name'] = FALSE;

    // Allow multiple file uploads
    $config['multi'] = 'all';

    $this->load->library('upload', $config);
    return $config;
}
Editor is loading...