<?php

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

//require APPPATH . '/libraries/MY_Controller.php';
//use Restserver\Libraries\MY_Controller;

class Receipt_approval extends CI_Controller
{

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

    public function listing()
    {
        //        log_message('debug','here');
        $request = $this->input->get();
        $data = $this->Receipt_approval_model->listing($request);
        echo json_encode($this->Receipt_approval_model->build_datatables($request['draw'], $this->Receipt_approval_model->totalCount(), $this->Receipt_approval_model->filteredCount($request), $data), JSON_UNESCAPED_UNICODE);
    }

    public function checkout()
    {
        $id = $this->input->get('id');
        $invoiceId = $this->input->get('invoiceId');
        if ($params = $this->input->get()) {
            $this->load->model('Receipt_model');
            $params = array_merge(['payment_type_id' => PaymentType::ATM, 'atm_id' => $id], $params);
            $this->Receipt_model->create_in_checkout($params, $invoiceId);
            $this->Receipt_approval_model->save(['status' => ReceiptApprovalStatus::processed], $id);

            // $this->Receipt_approval_model->trigger_push_notification($params['studentId'], $params['amount']);
            echo json_encode(['success' => true, 'data' => [], JSON_UNESCAPED_UNICODE]);
        }
    }
}
