Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
4.8 kB
0
Indexable
Never
//controller edit_pembelian
function edit_pembelian(){
        //cek_session_akses('pembelian',$this->session->id_session);
        cek_session_karyawan();
		$idp = $this->uri->segment(3);		
		if (isset($_POST['submit1'])){
            $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);

            $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' => $idp);
            $this->model_app->update('mst_pembelian', $data, $where);
            redirect('karyawan/edit_pembelian/'.$idp);

        }elseif(isset($_POST['submit'])){
            if ($this->input->post('idpd')==''){
                $data = array('id_pembelian'=>$this->input->post('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->input->post('idp'),
                              'kd_pr' =>$this->input->post('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/edit_pembelian/'.$this->input->post('idp'));
        }else{
            $data['rows'] = $this->model_app->view_where('mst_pembelian',array('id_pembelian'=>$this->uri->segment(3)))->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->uri->segment(3)),'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(4)!=''){
                $data['row'] = $this->model_app->view_where('mst_pembelian_dtl',array('id_dpembelian'=>$this->uri->segment(4)))->row_array();
            }
            $this->template->load('karyawan/template','karyawan/additional/mod_pembelian/view_pembelian_edit',$data);
        }
    }