<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Tagihan extends CI_Controller {
    function index() {
        if(isset($_GET['produk']) && !empty($_GET['produk'])) {
            if(isset($_GET['id'])) {
                $this -> load -> model('Payment_model', 'tripay');
                $id   = $_GET['id'] ? $_GET['id'] : redirect('error4x');

                switch($_GET['produk']) {
                    case 'topup_saldo':
                        $data  = $this -> app -> get_detail_topup($id);
                        $title = 'Top up Saldo';
                        break;
                        
                        default:
                        $data  = $this -> app -> get_detail_transaksi($id);
                        $title = 'Bayar Pesanan';
                    break;
                }
                                
                if($data && $data -> status == 0) {
                    $today = time();
                    $exp   = strtotime($data -> kadaluarsa);
                    $bacto = $_GET['produk'] == 'topup_saldo' 
                           ? site_url('akun/saldo?riwayat=topup') 
                           : site_url('akun/pesanan?produk='.$_GET['produk'])
                    ;
    
                    if($exp >= $today) {
                        $conf  = [
                            'title'      => $title . ' | ' . app('app_name'),
                            'page_title' => $title,
                            'backto'     => $bacto,   
                            'data'       => $data
                        ];
        
                        $this -> load -> view('layout/head', $conf);
                        $this -> load -> view('layout/header');
                        $this -> load -> view('tagihan');
                        $this -> load -> view('layout/footer');
                    }
                } else {
                    if($title == 'Top up Saldo') {
                        redirect('akun/saldo');
                    } else {
                        redirect('pesanan?produk='.$_GET['produk']  );
                    }
                }

            } else {
                redirect('error4x');
            }

        } else {
            redirect('error4x');
        }
    }
}

// Controller Tripay
// Kode ini dibuat oleh codelingker