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

class Order extends CI_Controller {

    public function __construct(){
        parent::__construct();

        if(!isset($_SESSION['login'])){
        	
        	redirect('Welcome');
        }
    }

    public function show_order(){
        $this->load->model('order_model');
        $data['results'] = $this->order_model->show_orders();
        $this->load->view('user/list-order', $data);
    }

    public function makeSeen(){
        $data = array(
            'orderid'=> $this->input->get('orderid')
        );
        $this->load->model('order_model');
        $res = $this->order_model->make_seen_order($data);
        if($res == TRUE){
            $this->session->set_flashdata('success', 'Successfully Seen');
            redirect("user/Order/show_order");
        }
        else{
            $this->session->set_flashdata('error', 'Something went wrong');
            redirect("user/Order/show_order");
        }
    }


    public function printInv(){
        $data = array(
            'orderid'=> $this->input->get('orderid')
        );

        $this->load->model('order_model');
        $data['results'] = $this->order_model->create_invoice($data);

        $this->load->view('user/invoice', $data);
    }

    public function printInvoice(){
        $data = array(
            'orderid'=> $this->input->get('orderid')
        );

        $this->load->model('order_model');
        $data['results'] = $this->order_model->create_invoice($data);
        $this->load->view('user/invoice-print', $data);
    }

    public function delete_order(){
        $data = array(
            'orderid'=> $this->input->get('orderid')
        );
        $this->load->model('order_model');

        $res = $this->order_model->delete_orders($data);
        
        if($res == TRUE){
            $this->session->set_flashdata('success', 'Successfully Deleted');
            redirect("user/Order/show_order");
        }
        else{
            $this->session->set_flashdata('error', 'Something went wrong');
            redirect("user/Order/show_order");
        }
        
    }

}

?>