daily pastebin goal
8%
SHARE
TWEET

pembayaran

a guest Feb 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Pembayaran extends CI_Controller {
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.         $this->load->model('pembayaran_model', 'current_model');
  9.         verify_login_status();
  10.     }
  11.     public function index()
  12.     {
  13.         $data['record'] = $this->current_model->get()->result_array();
  14.         //debug($data);
  15.         $this->template->load('main', $this->router->fetch_class().'/record', $data);
  16.     }
  17.  
  18.     public function add()
  19.     {
  20.         $data['form_open'] = form_open_multipart($this->router->fetch_class().'/add_process', array('id' => 'form'));
  21.         $res = $this->db->query("SELECT * FROM pendaftaran WHERE pos > 0 AND pos < 2 AND id_pendaftaran > 0");
  22.         if($res->num_rows() > 0) {
  23.             $result = $res->result();
  24.                 $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
  25.             foreach($result as $row) {
  26.                 $data['option_pendaftaran'][$row->id_pendaftaran] = $row->kode_daftar;
  27.             }
  28.         } else {
  29.             $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
  30.         }
  31.         $this->load->view('pembayaran/form', $data);
  32.     }
  33.  
  34.     public function add_process()
  35.     {
  36.        
  37.         $this->form_validation->set_rules('id_pendaftaran', 'Kode Pendaftaran', 'required');
  38.         $this->form_validation->set_rules('jumlah_bayar', 'Jumlah Bayar', 'required|is_numeric');
  39.         if ($this->form_validation->run() == FALSE) {
  40.             echo json_encode(array('st'=>0,
  41.                 'id_pendaftaran' => form_error('id_pendaftaran'),
  42.                 'jumlah_bayar' => form_error('jumlah_bayar'),
  43.                 ));
  44.         } else {
  45.             $daftar = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $this->input->post('id_pendaftaran')))->row_array();
  46.             if($daftar['pos'] == 0) {
  47.                 echo json_encode('Kode pendaftaran belum diapprove');
  48.                 die();
  49.             }
  50.             //$this->db->update('pendaftaran', array('status_pembayaran' => 1), array('id_pendaftaran' => $this->input->post('id_pendaftaran')));
  51.             $field['id_pendaftaran'] = $this->input->post('id_pendaftaran');
  52.             $field['jumlah'] = $this->input->post('jumlah_bayar');
  53.             $field['tanggal'] = date('Y-m-d');
  54.             $this->current_model->insert($field);
  55.             $id_pendaftaran = $this->input->post('id_pendaftaran');
  56.                     $res = $this->db->query("SELECT SUM(jumlah) as jml_bayar FROM pembayaran WHERE id_pendaftaran = '$id_pendaftaran' ")->row_array();
  57.                     if( $res['jml_bayar'] >= $this->input->post('total_harga_daftar') ) {
  58.                       $this->db->update('pendaftaran', array('pos' => 2), array('id_pendaftaran' => $this->input->post('id_pendaftaran')));
  59.                     }
  60.  
  61.             echo json_encode(array('st'=>1));
  62.         }
  63.     }
  64.  
  65.     function edit($id)
  66.     {
  67.         $data['form_open'] = form_open_multipart($this->router->fetch_class().'/edit_process', array('id' => 'form'));
  68.        
  69.        
  70.         $data['option_pendaftaran'][''] = '--- Pilih Kode Pendaftaran ---';
  71.             $res = $this->db->get('pendaftaran');
  72.             $result = $res->result();
  73.             foreach($result as $row) {
  74.                 $data['option_pendaftaran'][$row->id_pendaftaran] = $row->kode_daftar;
  75.         }
  76.         $edit = $this->current_model->get_by_id($id)->row();
  77.         $edit2 = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $edit->id_pendaftaran))->row();
  78.         $this->session->set_userdata('primary_key', $edit->id_pembayaran);
  79.         $data ['callback'] ['id_pendaftaran'] = $edit->id_pendaftaran;
  80.         $data ['callback'] ['total_bayar'] = $edit2->total_harga;
  81.         $data ['callback'] ['jumlah_bayar'] = $edit->jumlah;
  82.         $this->load->view('pembayaran/edit', $data);
  83.     }
  84.  
  85.     public function edit_process()
  86.     {
  87.         $this->form_validation->set_rules('jumlah_bayar', 'Jumlah Bayar', 'required|is_numeric');
  88.         if ($this->form_validation->run() == FALSE) {
  89.             echo json_encode(array('st'=>0,
  90.                 'jumlah_bayar' => form_error('jumlah_bayar'),
  91.                 ));
  92.         } else {
  93.             $field['jumlah'] = str_replace('.',',',$this->input->post('jumlah_bayar'));
  94.             $this->current_model->update($this->session->userdata('primary_key'), $field);
  95.             echo json_encode(array('st'=>1));
  96.         }
  97.     }
  98.  
  99.     public function get_detail($id)
  100.     {
  101.         $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
  102.         $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
  103.         $data['row'] = $this->db->get_where('pendaftaran', array('id_pendaftaran' => $id))->row_array();
  104.         $this->load->view($this->router->fetch_class().'/detail', $data);
  105.     }
  106.  
  107.    
  108. }
  109.  
  110. /* End of file Pembayaran.php */
  111. /* Location: ./application/controllers/Pembayaran.php */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top