Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.6 kB
1
Indexable
Never
function pr_user(){
        $nik = $this->session->nik;
        cek_session_akses('pr_user',$this->session->id_session);
        if (isset($_POST['submit1'])){
            if ($this->session->idp == ''){
				$latest_ticket = $this->model_app->get_latest_ticket_pr();
			$cekskrng = date('Ymd');
			$cekdata_akhir = substr($latest_ticket,3,-3);
			
			// Jika tidak ada nomor tiket sebelumnya, mulai dari 1
			if (empty($latest_ticket) OR $cekskrng != $cekdata_akhir) {
				$new_number = 1;
			} else {
				// Mengambil nomor urutan dari nomor tiket terbaru 001
				$last_number = number_format(substr($latest_ticket,-3));
				//$last_number = intval(substr($latest_ticket, 3));
				
				// Menambahkan 1 ke nomor urutan
				$new_number = $last_number + 1;
			}
			
			// Mengonversi nomor urutan ke format 3 digit dengan nol di depan
			$new_number_str = str_pad($new_number, 3, '0', STR_PAD_LEFT);
			
			// Membuat nomor tiket baru dengan nomor urutan yang diperbarui
			$kd_pr = "PR-" . date('Ymd') . $new_number_str;
			//$nik = 
				
                $data = array('kd_pr'=>$kd_pr,
                              'user_create'=>$nik,
                              'tgl_pr' => date('Y-m-d'),
				'kategori_pr' => $this->input->post('kategori_pr'),
				'type_pr' => $this->db->escape_str($this->input->post('type_pr')),
				'no_projek' => $this->db->escape_str($this->input->post('no_projek')),
				'lokasi_projek' => $this->db->escape_str($this->input->post('lokasi_projek')),
				'tgl_kebutuhan' => $this->db->escape_str($this->input->post('tgl_kebutuhan')),
				'status_pr' => $this->db->escape_str($this->input->post('status_pr')),
                'keterangan_pr' => $this->db->escape_str($this->input->post('keterangan_pr')));
                $this->model_app->insert('mst_pembelian',$data);
                //$idp = $this->db->insert_id();
                $this->session->set_userdata(array('kode_pr'=>$kd_pr));
            }else{
                $data = array('kd_pr'=>$this->kd_pr,
                              'user_create'=>$nik,
                              'tgl_pr' => date('Y-m-d'),
				'kategori_pr' => $this->input->post('kategori_pr'),
				'type_pr' => $this->db->escape_str($this->input->post('type_pr')),
				'no_projek' => $this->db->escape_str($this->input->post('no_projek')),
				'lokasi_projek' => $this->db->escape_str($this->input->post('lokasi_projek')),
				'tgl_kebutuhan' => $this->db->escape_str($this->input->post('tgl_kebutuhan')),
				'status_pr' => $this->db->escape_str($this->input->post('status_pr')),
                'keterangan_pr' => $this->db->escape_str($this->input->post('keterangan_pr')));
                $this->model_app->insert('mst_pembelian',$data);
                //$idp = $this->db->insert_id();
                $this->session->set_userdata(array('kode_pr'=>$kd_pr));
                $where = array('kd_pr' => $this->session->kode_pr);
                $this->model_app->update('mst_pembelian', $data, $where);
            }
            // $this->session->set_flashdata('submitted_data', $data);
            redirect('karyawan/pr_user');

        }elseif(isset($_POST['submit1'])){
            if ($this->input->post('idpd')==''){
				//$master_beli = $this->model_app->edit('mst_pembelian')
				$master_beli = $this->model_app->edit('mst_pembelian', array('kd_pr' => $kd_pr))->row_array();
				$id_pembelian = $master_beli['id_pembelian'];
				
                $data = array('id_pembelian'=>$id_pembelian,
                              'kd_pr'=>$this->$kd_pr,
                              'item_barang'=>$this->input->post('item_barang'),
                              'deskripsi_item'=>$this->input->post('deskripsi_item'),
                              'dimension_item'=>$this->input->post('dimension_item'),
                              'jumlah_item'=>$this->input->post('jumlah_item'),
                              'satuan_item'=>$this->input->post('satuan_item'));
                $this->model_app->insert('mst_pembelian_dtl',$data);
            }else{
                $data = array('id_pembelian'=>$id_pembelian,
                              'kd_pr'=>$this->$kd_pr,
                'item_barang'=>$this->input->post('item_barang	'),
                'deskripsi_item'=>$this->input->post('deskripsi_item'),
                'dimension_item'=>$this->input->post('dimension_item'),
                'jumlah_item'=>$this->input->post('jumlah_item'),
                'satuan_item'=>$this->input->post('satuan_item'));
                $where = array('mst_pembelian_dtl' => $this->input->post('idpd'));
                $this->model_app->update('mst_pembelian_dtl', $data, $where);
            }
            redirect('karyawan/pr_user');
        }else{
            $data['rows'] = $this->model_app->view_ordering('mst_pembelian', 'id_pembelian', 'DESC');
            $data['record'] = $this->model_app->view_join_where('mst_pembelian_dtl', 'mst_pembelian', 'kd_pr', 'kd_pr', array('kd_pr' => $this->session->kode_pr), 'DESC');
            // $data['barang'] = $this->model_app->view_where_ordering('rb_produk',array('id_reseller'=>'0'),'id_produk','ASC');
            // $data['supplier'] = $this->model_app->view_ordering('rb_supplier','id_supplier','ASC');
            if ($this->uri->segment(3)!=''){
                $data['row'] = $this->model_app->view_where('mst_pembelian_dtl',array('mst_pembelian_dtl'=>$this->uri->segment(3)))->row_array();
            }
            $this->template->load('karyawan/template','karyawan/mod_pr/pr_user',$data);
        }
    }