<?php

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

class Tuition extends MY_BackendController {

    public function __construct() {
        parent::__construct();
        $this->load->model('Tuition_model');
    }

    public function index() {
    	$default = 'month';
//    	$this->load->model('Tuition_label_model');
//		$this->load->model('Course_model');
		$rate_sheet = $this->Tuition_model->get($default);
		if (count($rate_sheet) == 0) {
//			$rate_sheet[] = [
//				'id' => 0,
//				'mode' => $default,
//				'title' => '未命名收費表',
//			];
//			$tuition_label = [
//				'x' => [
//					[
//					'position' => 0,
//					'title' => '未命名',
//					],
//				],
//				'y' => [
//					[
//					'position' => 0,
//					'title' => '未命名',
//					],
//				],
//			];
//			$tuition = [
//				[
//					'x' => 0,
//					'y' => 0,
//					'course_payment' => 0,
//				],
//			];
			$default_rate_sheet = -1;
			$tuition_label = [];
			$tuition = [];
		}
		else {
			$default_rate_sheet = $rate_sheet[0]['id'];
			$this->load->model('Tuition_amount_model');
			$tuition = $this->Tuition_amount_model->get($default_rate_sheet);
	    	$this->load->model('Tuition_label_model');
			$tuition_label = $this->Tuition_label_model->get($default_rate_sheet);
		}
        $this->view('backend/tuition/index', [
        	'mode' => $this->Tuition_model->getMode(),
			'default' => $default,
			'rate_sheet' => $rate_sheet,
			'default_rate_sheet' => $default_rate_sheet,
			'label' => $tuition_label,
			'tuition' => $tuition,
		]);
    }

}
