<?php

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

class Order_model extends CI_Model{

    function insert_order($data){

        $query = $this->db->insert('orders',$data);

        if($query){
            return TRUE;
        }
        else{
            return FALSE;
        }

    }

    function dash_reports(){

        #this block is for take the number of unseen order
		$this->db->select('count(orderid) as `unseenorder`')
        ->from('orders')
        ->where('status',1);
        $query1 = $this->db->get();
        $res[1] = $query1->result_array();
 

        #this block is for take the number of total order
		$this->db->select('count(orderid) as `totalorder`')
        ->from('orders');
        $query2 = $this->db->get();
        $res[2] = $query2->result_array();

        #this block is for take the number of total client
		$this->db->select('count(logoid) as `clients`')
        ->from('logos')
        ->where('type', 'client&partner');
        $query3 = $this->db->get();
        $res[3] = $query3->result_array();

        #this block is for take the number of total portfolio
		$this->db->select('count(logoid) as `portfolio`')
        ->from('logos')
        ->where('type', 'portfolio');
        $query4 = $this->db->get();
        $res[4] = $query4->result_array();

        return $res;
    }


    function show_orders(){

		$query = $this->db->get('orders');
		$res = $query->result_array();
	 	return $res;

    }

    function make_seen_order($data){

        $update = array(
            'status' => 0
        );
        
        $this->db->where('orderid', $data['orderid']);
        $query = $this->db->update('orders', $update);

        if($query){
            return TRUE;
        }
        else{
            return FALSE;
        }

    }

    function create_invoice($data){
        $query1 = $this->db->get_where('orders', array('orderid' => $data['orderid'] ));
        $res[1] = $query1->result_array();
        
        foreach ($res[1] as $key => $result) {
            $table_identifier = $result['package'];
            $packageid = $result['packageid'];
        }

        if($table_identifier == 'other_packages'){
            $this->db->select('*');
            $this->db->from('orders');
            $this->db->where('orderid',$data['orderid']);
            $this->db->join('packages','packages.packageid = orders.packageid');
            $query2 = $this->db->get();

            // $query2 = $this->db->get_where('packages', array('packageid' => $packageid ));
        }
        elseif($table_identifier == 'web_packages'){
            $this->db->select('*');
            $this->db->from('orders');
            $this->db->where('orderid',$data['orderid']);
            $this->db->join('webpackages','webpackages.webpackageid = orders.packageid');
            $query2 = $this->db->get();
            // $query2 = $this->db->get_where('webpackages', array('webpackageid' => $packageid ));
        }
        else{
            $this->db->select('*');
            $this->db->from('orders');
            $this->db->where('orderid',$data['orderid']);
            $this->db->join('smspackages','smspackages.smspackageid = orders.packageid');
            $query2 = $this->db->get();
            // $query2 = $this->db->get_where('smspackages', array('smspackageid' => $packageid ));
        }


        $res[2] = $query2->result_array();

	 	return $res;
    }

    function delete_orders($data){
        $query = $this->db->delete('orders', array('orderid' => $data['orderid']));

        if($query){
            return TRUE;
        }
        else{
            return FALSE;
        }
    }

    // function show_ecommerce_package(){

	// 	$query = $this->db->get_where('webpackages', array('type' => 'ecommerce'));
	// 	$res = $query->result_array();
	//  	return $res;

    // }
    
    // function update_front_countdown($data){
    //     $array = array(
    //         'total_experience' => $data['total_experience'],
    //         'happy_clients' => $data['happy_clients'],
    //         'projects_done' => $data['projects_done']
    //     );
    
    //     $this->db->where('front_countdownid', $data['front_countdownid']);
    //     $query = $this->db->update('front_countdown', $array);

    //     if($query){
    //         return TRUE;
    //     }
    //     else{
    //         return FALSE;
    //     }
    // }

}

?>