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

/**
 * @property Slip_model $Slip_model
 * @property Slip_signed_model $Slip_signed_model
 */
class Replyslip extends MY_ApiController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function listing()
    {
        $this->is_get();
        $params = $this->input->get();

        $tenant_no = $params['tenant_no'];
        $student_id = $params['student_id'];

        $this->load->model('Slip_model');
        $this->Slip_model->setTenantNo($tenant_no);
        $replyslips = $this->Slip_model->get_replyslip_by_student_id($student_id);
        $types = $this->Slip_model->types();

        echo $this->respond([
            'replyslips' => $replyslips,
            'types' => $types
        ]);
    }

    public function signed()
    {
        $this->is_post();
        $this->is_json();

        $params = $this->json;
        $tenant_no = $params['tenant_no'];

        $this->load->model('Slip_signed_model');
        $this->Slip_signed_model->setTenantNo($tenant_no);
        try {
            $data = $this->Slip_signed_model->create_slip_signed($params);
            echo $this->respond($data);
        } catch (Exception $e) {
            echo $this->respond(['message' => $e->getMessage()], 400);
        }
    }
}
