Files
web-sekolah/application/controllers/Biayaformulir.php
T
2026-06-26 13:37:55 +07:00

401 lines
19 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Biayaformulir extends CI_Controller {
//load model
public function __construct()
{
parent::__construct();
$this->load->model('formulir_model');
$this->load->model('biayaformulir_model');
$this->simple_login->check_login();
//proteksi admin dan peserta
if($this->session->userdata('level') !='Administrator')
{
if($this->session->userdata('level') !='Operator')
{
//kalau bukan adamin, lempar ke login
$this->session->set_flashdata('warning', 'Hak akses anda tidak diijinkan mengakses menu penyerahan berkas');
redirect(base_url('login'),'refresh');
}
}
}
public function search(){
// Ambil data pendaftar yang dikirim via ajax post
$no_pendaftaran = $this->input->post('no_pendaftaran');
$siswa = $this->biayaformulir_model->viewByNo($no_pendaftaran);
if( ! empty($siswa)){ // Jika data siswa ada/ditemukan
// Buat sebuah array
$callback = array(
'status' => 'success', // Set array status dengan success
'nama_lengkap' => $siswa->nama_lengkap, // Set array nama
'sekolah_asal' => $siswa->sekolah_asal, // Set array sekolah
'kompetensi' => $siswa->kompetensi, // Set array kompetensi
'gelombang' => $siswa->gelombang, // Set array kompetensi
);
}else{
$callback = array('status' => 'failed'); // set array status dengan failed
}
echo json_encode($callback); // konversi varibael $callback menjadi JSON
}
public function index()
{
$this->db->select('*');
$this->db->from('tr_formulir');
$this->db->join('data_siswa', 'tr_formulir.no_pendaftaran = data_siswa.no_pendaftaran');
$this->db->order_by('tr_formulir.no_trans', 'DESC');
$query = $this->db->get();
$result = $query->result();
$formulir = $result;
$total = $this->biayaformulir_model->total();
$setting = $this->setting_model->setting();
$setting = array('tgl_sosialisasi' => $setting);
$biaya = $this->db->get("setting")->row()->biaya_for;
$diskon = $this->db->get("setting")->row()->diskon;
// Ambil tanggal saat ini dalam format 'Ymd'
$tanggal_sekarang = date('Ymd');
// Lakukan query untuk mendapatkan nomor urutan terakhir
$query = $this->db->query("SELECT MAX(CAST(RIGHT(no_trans, 5) AS UNSIGNED)) AS max_urutan FROM tr_formulir");
$row = $query->row();
$max_urutan = ($row->max_urutan != null) ? $row->max_urutan : 0;
// Tambahkan 1 ke nomor urutan terakhir
$no_urut = sprintf("%05s", $max_urutan + 1);
// Gabungkan semua elemen menjadi nomor transaksi
$nomor_transaksi = 'FR-' . $tanggal_sekarang . $no_urut;
// Sekarang Anda bisa menggunakan $nomor_transaksi ini untuk menyimpan ke dalam basis data
//validasi input
$valid = $this->form_validation;
//check nama
$this->form_validation->set_rules('nama_lengkap', 'Data tidak dapat disimpan, nama peserta harus terisi ', 'required',
array( 'required' => '%s dengan menekan tombol cari terlebih dahulu'));
$valid->set_rules('no_pendaftaran','Berkas tidak dapat disimpan, ','required|is_unique[tr_data.no_pendaftaran]',
array( 'required' => '%s harus diisi',
'is_unique' => '%s nomor pendaftaran yang diinput sudah menyerahkan data jika ingin menambahkan silahkan di menu edit'));
//jika sudah dicek dan error
if($valid->run()===FALSE) {
$formulir = array( 'title' => 'Data Transaksi Biaya Tes [ '.$total->total.' ]',
'formulir' => $formulir,
'biaya' => $biaya,
'diskon' => $diskon,
'notr' => $nomor_transaksi,
'content' => 'biayaformulir/index'
);
$this->load->view('layout/wrapper', $formulir, FALSE);
//jika validasi oke, masuk database
}else{
$inp = $this->input;
$data = array( 'no_pendaftaran' => $inp->post('no_pendaftaran'),
'tgl_sosialisasi' => date('Y-m-d H:i:s',($inp->post('tgl_sosialisasi'))),
'shun' => $inp->post('shun'),
'akte' => $inp->post('akte'),
'kk' => $inp->post('kk'),
'ktp' => $inp->post('ktp'),
'nisn' => $inp->post('nisn'),
'baik_narkoba' => $inp->post('baik_narkoba'),
'ket_yatim' => $inp->post('ket_yatim'),
'kip' => $inp->post('kip'),
'slip_btn' => $inp->post('slip_btn'),
'skl' => $inp->post('skl'),
'ijazah' => $inp->post('ijazah'),
'tgl_update' => date('Y-m-d H:i:s'),
'petugas' => $this->session->userdata('nama')
);
//proses oleh model
$this->formulir_model->tambah($data);
//notifikasi dan redirect
$this->session->set_flashdata('sukses', 'Data Formulir telah ditambah..!');
redirect(base_url('biayaformulir/cetakberkas/'.$inp->post('no_pendaftaran')),'refresh');
}
}
public function tambah(){
$inp = $this->input;
$data = array( 'no_pendaftaran' => $inp->post('no_pendaftaran'),
'tgl_trans' => date('Y-m-d'),
'no_trans' => $inp->post('no_faktur'),
'biaya' => $inp->post('biaya_tes'),
'diskon' => $inp->post('diskon'),
'bayar' => $inp->post('total'),
'cash' => str_replace('.', '', $this->input->post('bayar')),
'kembali' => $inp->post('kembalian'),
'operator' => $this->session->userdata('nama')
);
$tambah= $this->db->insert("tr_formulir", $data);
$this->session->set_flashdata('sukses', 'Data Calon Siswa Berhasil Ditambahkan..!');
redirect(base_url('biayaformulir'),'refresh');
// redirect(base_url('biayaformulir/cetakberkas/'.$inp->post('no_pendaftaran')),'refresh');
}
//Edit user
public function edit($no_pendaftaran)
{
//panggil data user yang akan diedit
$formulir = $this->formulir_model->detail($no_pendaftaran);
//validasi input
$valid = $this->form_validation;
//check nama
$valid->set_rules('akte','Data penyerahan berkas','required',
array( 'required' => '%s harus diisi'));
//jika sudah dicek dan error
if($valid->run()===FALSE) {
//end validasi
$data= array( 'title' => 'Edit Data Berkas Pendaftar : '.$formulir->no_pendaftaran.' -- '.$formulir->nama_lengkap,
'formulir' => $formulir,
'content' => 'formulir/edit'
);
$this->load->view('layout/wrapper', $data, FALSE);
//jika validasi oke, masuk database
}else{
$inp = $this->input;
$data = array( 'no_pendaftaran' => $no_pendaftaran,
'shun' => $inp->post('shun'),
'akte' => $inp->post('akte'),
'kk' => $inp->post('kk'),
'ktp' => $inp->post('ktp'),
'nisn' => $inp->post('nisn'),
'baik_narkoba' => $inp->post('baik_narkoba'),
'ket_yatim' => $inp->post('ket_yatim'),
'kip' => $inp->post('kip'),
'slip_btn' => $inp->post('slip_btn'),
'skl' => $inp->post('skl'),
'ijazah' => $inp->post('ijazah'),
'tgl_update' => date('Y-m-d H:i:s'),
'petugas' => $this->session->userdata('nama')
);
//proses oleh model
$this->formulir_model->edit($data);
//notifikasi dan redirect
$this->session->set_flashdata('sukses', 'Data berkas '.$formulir->nama_lengkap.' telah diedit.');
redirect(base_url('formulir'),'refresh');
}
//end masuk database
}
//Delete formulir
public function delete($no_pendaftaran)
{
$data = array('no_pendaftaran' => $no_pendaftaran);
//proses hapus
$this->biayaformulir_model->delete($data);
//notifikasi
$this->session->set_flashdata('sukses', 'Data formulir telah dihapus..!');
redirect(base_url('biayaformulir'),'refresh');
}
//EXPORT NILAI KE EXCEL
public function export(){
// Load plugin PHPExcel nya
include APPPATH.'third_party/PHPExcel/PHPExcel.php';
// Panggil class PHPExcel nya
$excel = new PHPExcel();
// Settingan awal fil excel
$excel->getProperties()->setCreator('By : 415 DIL')
->setLastModifiedBy('By : 415 DIL')
->setTitle("Data Transaksi Pembelian Formulir")
->setSubject("Transaksi Pembelian Formulir")
->setDescription("Laporan Data Transaksi Pembelian Formulir")
->setKeywords("Data Transaksi Pembelian Formulir");
// Buat sebuah variabel untuk menampung pengaturan style dari header tabel
$style_col = array(
'font' => array('bold' => true), // Set font nya jadi bold
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, // Set text jadi ditengah secara horizontal (center)
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER // Set text jadi di tengah secara vertical (middle)
),
'borders' => array(
'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border top dengan garis tipis
'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border right dengan garis tipis
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border bottom dengan garis tipis
'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN) // Set border left dengan garis tipis
)
);
// Buat sebuah variabel untuk menampung pengaturan style dari isi tabel
$style_row = array(
'alignment' => array(
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER // Set text jadi di tengah secara vertical (middle)
),
'borders' => array(
'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border top dengan garis tipis
'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border right dengan garis tipis
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), // Set border bottom dengan garis tipis
'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN) // Set border left dengan garis tipis
)
);
$excel->setActiveSheetIndex(0)->setCellValue('A1', "LAPORAN REKAP TRANSAKSI PEMBELIAN FORMULIR PPDB SMK AL-MUHTADIN DEPOK"); // Set kolom A1 dengan tulisan "DATA SISWA"
$excel->getActiveSheet()->mergeCells('A1:P1'); // Set Merge Cell pada kolom A1 sampai E1
$excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(TRUE); // Set bold kolom A1
$excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15); // Set font size 15 untuk kolom A1
$excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // Set text center untuk kolom A1
// Buat header tabel nya pada baris ke 3
$excel->setActiveSheetIndex(0)->setCellValue('A3', "NO."); // Set kolom A3 dengan tulisan "NO"
$excel->setActiveSheetIndex(0)->setCellValue('B3', "NO. PEND"); // Set kolom B3 dengan tulisan "NO.PEND"
$excel->setActiveSheetIndex(0)->setCellValue('C3', "NO. TRANSAKSI"); // Set kolom C3 dengan tulisan "NAMA"
$excel->setActiveSheetIndex(0)->setCellValue('D3', "NAMA LENGKAP"); // Set kolom D3 dengan tulisan "JENIS KELAMIN"
$excel->setActiveSheetIndex(0)->setCellValue('E3', "JENIS KELAMIN"); // Set kolom E3 dengan tulisan "SEKOLAH"
$excel->setActiveSheetIndex(0)->setCellValue('F3', "SEKOLAH ASAL");
$excel->setActiveSheetIndex(0)->setCellValue('G3', "KOMPETENSI");
$excel->setActiveSheetIndex(0)->setCellValue('H3', "BIAYA");
$excel->setActiveSheetIndex(0)->setCellValue('I3', "DISKON");
$excel->setActiveSheetIndex(0)->setCellValue('J3', "TOTAL");
// Apply style header yang telah kita buat tadi ke masing-masing kolom header
$excel->getActiveSheet()->getStyle('A3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('B3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('C3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('D3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('E3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('F3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('G3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('H3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('I3')->applyFromArray($style_col);
$excel->getActiveSheet()->getStyle('J3')->applyFromArray($style_col);
// Panggil function view yang ada di formulir_model untuk menampilkan semua data formulirnya
$formulir = $this->biayaformulir_model->ViewUrut();
$no = 1; // Untuk penomoran tabel, di awal set dengan 1
$numrow = 4; // Set baris pertama untuk isi tabel adalah baris ke 4
foreach($formulir as $data){ // Lakukan looping pada variabel formulir
$excel->setActiveSheetIndex(0)->setCellValue('A'.$numrow, $no);
$excel->setActiveSheetIndex(0)->setCellValue('B'.$numrow, $data->no_pendaftaran);
$excel->setActiveSheetIndex(0)->setCellValue('C'.$numrow, $data->no_trans);
$excel->setActiveSheetIndex(0)->setCellValue('D'.$numrow, $data->nama_lengkap);
$excel->setActiveSheetIndex(0)->setCellValue('E'.$numrow, $data->jkelamin);
$excel->setActiveSheetIndex(0)->setCellValue('F'.$numrow, $data->sekolah_asal);
$excel->setActiveSheetIndex(0)->setCellValue('G'.$numrow, $data->kompetensi);
$excel->setActiveSheetIndex(0)->setCellValue('H'.$numrow, $data->biaya);
$excel->setActiveSheetIndex(0)->setCellValue('I'.$numrow, $data->diskon);
$excel->setActiveSheetIndex(0)->setCellValue('J'.$numrow, $data->bayar);
// Apply style row yang telah kita buat tadi ke masing-masing baris (isi tabel)
$excel->getActiveSheet()->getStyle('A'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('B'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('C'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('D'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('E'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('F'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('G'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('H'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('I'.$numrow)->applyFromArray($style_row);
$excel->getActiveSheet()->getStyle('J'.$numrow)->applyFromArray($style_row);
$no++; // Tambah 1 setiap kali looping
$numrow++; // Tambah 1 setiap kali looping
}
// Set width kolom
$excel->getActiveSheet()->getColumnDimension('A')->setWidth(5); // Set width kolom A
$excel->getActiveSheet()->getColumnDimension('B')->setWidth(12); // Set width kolom B
$excel->getActiveSheet()->getColumnDimension('C')->setWidth(35); // Set width kolom C
$excel->getActiveSheet()->getColumnDimension('D')->setWidth(15); // Set width kolom D
$excel->getActiveSheet()->getColumnDimension('E')->setWidth(35); // Set width kolom E
$excel->getActiveSheet()->getColumnDimension('F')->setWidth(13);
$excel->getActiveSheet()->getColumnDimension('G')->setWidth(13);
$excel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('L')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('M')->setWidth(16);
$excel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('O')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('P')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('Q')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('R')->setWidth(12);
$excel->getActiveSheet()->getColumnDimension('S')->setWidth(18);
$excel->getActiveSheet()->getColumnDimension('T')->setWidth(15);
// Set height semua kolom menjadi auto (mengikuti height isi dari kolommnya, jadi otomatis)
$excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);
// Set orientasi kertas jadi LANDSCAPE
$excel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
// Set judul file excel nya
$excel->getActiveSheet(0)->setTitle("Rekap Pembelian Formulir PPDB");
$excel->setActiveSheetIndex(0);
// Proses file excel
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="Rekap Transaksi Pembelian Formulir PPDB.xlsx"'); // Set nama file excel nya
header('Cache-Control: max-age=0');
$write = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$write->save('php://output');
}
public function cetak(){
$pdf = new FPDF('p','mm','A4');
// membuat halaman baru
$pdf->AddPage();
// setting jenis font yang akan digunakan
$pdf->SetFont('Arial','B',16);
// mencetak string
$pdf->Cell(190,7,'LAPORAN REKAP DATA BERKAS PPDB',0,1,'C');
$pdf->SetFont('Arial','B',12);
$pdf->Cell(190,7,'SMK AL-MUHTADIN DEPOK',0,1,'C');
// Memberikan space kebawah agar tidak terlalu rapat
$pdf->Cell(10,7,'',0,1);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(10,6,'NO.',1,0);
$pdf->Cell(20,6,'NO. PEND',1,0);
$pdf->Cell(85,6,'NAMA SISWA',1,0);
$pdf->Cell(30,6,'TEMPAT LAHIR',1,0);
$pdf->Cell(33,6,'TANGGAL LAHIR',1,1);
$pdf->SetFont('Arial','',10);
$siswa = $this->db->get('data_siswa')->result();
$no = 1;
foreach ($siswa as $row){
$pdf->Cell(10,6,$no++,1,0);
$pdf->Cell(20,6,$row->no_pendaftaran,1,0);
$pdf->Cell(85,6,$row->nama_lengkap,1,0);
$pdf->Cell(30,6,$row->tempat_lahir,1,0);
$pdf->Cell(33,6,$row->tgl_lahir,1,1);
}
$pdf->Output();
}
public function cetakberkas($no_pendaftaran)
{
$data['data'] = $this->db->get_where('v_rpt_trans_formulir',['no_pendaftaran'=>$no_pendaftaran])->row();
$this->load->view('biayaformulir/cetak_berkas',$data);
}
}
/* End of file formulir.php */
/* Location: ./application/controllers/formulir.php */