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

class Invoicing extends MY_BackendController
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Invoicing_model');       
    }

    public function index()
    {
    	$request = $this->input->get();
    	$id = 0;
    	if (array_key_exists('studentno', $request)) {
    		$studentno = $request['studentno'];
    		$this->load->model('Student_model');
			$student = $this->Student_model->detail_studentNo($studentno);
			if ($student) {
				$id = $student['id'];
			}
		}
    	$banklist = json_decode(file_get_contents(FCPATH . 'uploads/bank.json'), true);
    	$bank = [];
    	foreach ($banklist as $b) {
    		$bank[] = $b['Bank_Code'] . ' ' . $b['Bank_Name_EN'] . ' ' . $b['Bank_Name_ZH'];
		}
        $this->view('backend/invoicing/index', [
        	'bankinfo' => json_encode($bank, JSON_UNESCAPED_UNICODE),
			'studentno' => $id,
		]);
    }    
   
    public function merge() {         
        $mergedId=$this->Invoicing_model->merge(explode(',',$this->input->post('ids')));
        header('location:/invoicing?mergedId='.$mergedId);
    }
    
    public function unmerge(){
        
         header('location:/invoicing');
    }
}
