Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Pembayaran extends CI_Controller {
- public function __construct()
- {
- parent::__construct();
- $this->load->model('pembayaran_model', 'current_model');
- verify_login_status();
- }
- public function index()
- {
- $data['record'] = $this->current_model->get()->result_array();
- //debug($data);
- $this->template->load('main', $this->router->fetch_class().'/record', $data);
- }
- public function add()
- {
- $data['form_open'] = form_open_multipart($this->router->fetch_class().'/add_process', array('id' => 'form'));
- $res = $this->db->query("SELECT * FROM pendaftaran WHERE pos > 0 AND pos < 2 AND id_pendaftaran > 0");
- if($res->num_rows() > 0) {
- $result = $res->result();
- $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
- foreach($result as $row) {
- $data['option_pendaftaran'][$row->id_pendaftaran] = $row->kode_daftar;
- }
- } else {
- $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
- }
- $this->load->view('pembayaran/form', $data);
- }
- public function add_process()
- {
- $this->form_validation->set_rules('id_pendaftaran', 'Kode Pendaftaran', 'required');
- $this->form_validation->set_rules('jumlah_bayar', 'Jumlah Bayar', 'required|is_numeric');
- if ($this->form_validation->run() == FALSE) {
- echo json_encode(array('st'=>0,
- 'id_pendaftaran' => form_error('id_pendaftaran'),
- 'jumlah_bayar' => form_error('jumlah_bayar'),
- ));
- } else {
- $daftar = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $this->input->post('id_pendaftaran')))->row_array();
- if($daftar['pos'] == 0) {
- echo json_encode('Kode pendaftaran belum diapprove');
- die();
- }
- //$this->db->update('pendaftaran', array('status_pembayaran' => 1), array('id_pendaftaran' => $this->input->post('id_pendaftaran')));
- $field['id_pendaftaran'] = $this->input->post('id_pendaftaran');
- $field['jumlah'] = $this->input->post('jumlah_bayar');
- $field['tanggal'] = date('Y-m-d');
- $this->current_model->insert($field);
- $id_pendaftaran = $this->input->post('id_pendaftaran');
- $res = $this->db->query("SELECT SUM(jumlah) as jml_bayar FROM pembayaran WHERE id_pendaftaran = '$id_pendaftaran' ")->row_array();
- if( $res['jml_bayar'] >= $this->input->post('total_harga_daftar') ) {
- $this->db->update('pendaftaran', array('pos' => 2), array('id_pendaftaran' => $this->input->post('id_pendaftaran')));
- }
- echo json_encode(array('st'=>1));
- }
- }
- function edit($id)
- {
- $data['form_open'] = form_open_multipart($this->router->fetch_class().'/edit_process', array('id' => 'form'));
- $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
- $res = $this->db->get('pendaftaran');
- $result = $res->result();
- foreach($result as $row) {
- $data['option_pendaftaran'][$row->id_pendaftaran] = $row->kode_daftar;
- }
- $edit = $this->current_model->get_by_id($id)->row();
- $edit2 = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $edit->id_pendaftaran))->row();
- $this->session->set_userdata('primary_key', $edit->id_pembayaran);
- $data ['callback'] ['id_pendaftaran'] = $edit->id_pendaftaran;
- $data ['callback'] ['total_bayar'] = $edit2->total_harga;
- $data ['callback'] ['jumlah_bayar'] = $edit->jumlah;
- $this->load->view('pembayaran/edit', $data);
- }
- public function edit_process()
- {
- $this->form_validation->set_rules('jumlah_bayar', 'Jumlah Bayar', 'required|is_numeric');
- if ($this->form_validation->run() == FALSE) {
- echo json_encode(array('st'=>0,
- 'jumlah_bayar' => form_error('jumlah_bayar'),
- ));
- } else {
- $field['jumlah'] = str_replace('.',',',$this->input->post('jumlah_bayar'));
- $this->current_model->update($this->session->userdata('primary_key'), $field);
- echo json_encode(array('st'=>1));
- }
- }
- public function get_detail($id)
- {
- $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
- $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
- $data['row'] = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $id))->row_array();
- $this->load->view($this->router->fetch_class().'/detail', $data);
- }
- }
- /* End of file Pembayaran.php */
- /* Location: ./application/controllers/Pembayaran.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement