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

class eventhistory extends MY_Controller{
	function __construct(){
        parent::__construct();
        $this->load->model('inviteinevent_model', '', TRUE); 
        $this->load->model('category_model', '', TRUE);   
        $this->load->model('contact_model', '', TRUE); 
        $this->load->model('event_model', '', TRUE); 
        $this->load->model('route_model', '', TRUE);  
    }
    function index(){
        //echo phpinfo();
        $event = $this->event_model->allevent_details();
        
        $html ='';
        foreach ($event as $eventkey => $eventvalue) {
            $eventid= $eventvalue['id'];
            $invitinglist = $this->inviteinevent_model->get_inviting_list($eventid);
            $html .='<tr>';
                $html .='<td>'.ucwords(strtolower($eventvalue['name'])).'</td>';
                $html .='<td>'.intval($invitinglist['tadult']).'</td>';
                $html .='<td>'.intval($invitinglist['tchild']).'</td>';
                $html .='<td>'.intval($invitinglist['ftotal']).'</td>';
                $html .='<td>';
                    $html .='<a href="'.$this->data['base_url'].'eventhistory/eventwiseview/'.$eventid.'">';
                        $html .='<span class="btn btn-primary">
                            <i class="fa fa-eye"></i> View</span>';
                    $html .='</a> ';
                    $html .='<a href="'.$this->data['base_url'].'report/invite_report/'.$eventid.'/ExportinPDF" target="_blank">';
                        $html .='<span class="btn btn-danger">
                            <i class="fa fa-file-pdf-o"></i> Export in PDF</span>';
                    $html .='</a> ';
                    $html .='<a href="'.$this->data['base_url'].'report/invite_report/'.$eventid.'/ExportinExcel" target="_blank">';
                        $html .='<span class="btn btn-success">
                            <i class="fa fa-file-excel-o"></i> Export in Excel</span>';
                    $html .='</a> ';
                    $html .='<a href="'.$this->data['base_url'].'report/invite_report/'.$eventid.'/StickerView" target="_blank">';
                        $html .='<span class="btn btn-info">
                            <i class="fa fa-print"></i> Sticker View</span>';
                    $html .='</a>';

                $html .='</td>';
            $html .='</tr>'; 
        }
        $this->smarty->assign('eventwise',$html);
        $this->smarty->assign('evenininvite',$event);
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']='New inviteinevent';
        $this->data['tpl_name']= "eventhistory.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    }
    function eventwiseview(){
        $eventid = $this->uri->segment(3);
        
        $html ='';
        $eventwiseview = $this->inviteinevent_model->eventwiseview($eventid);
        $grandtotal='0';
        $totaladult='0';
        $totalchild='0';
        foreach ($eventwiseview as $ekey => $eventvalue) {
            $grandtotal =($grandtotal+intval($eventvalue['total']));
            $totaladult =($totaladult+intval($eventvalue['adult']));
            $totalchild =($totalchild+intval($eventvalue['child']));
            $html .='<tr>';
                $html .='<td>'.ucwords(strtolower($eventvalue['name'])).'</td>';
                $html .='<td>'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                $html .='<td>'.ucwords(strtolower($eventvalue['city'])).'</td>';
                $html .='<td>';
                if($eventvalue['categoryid']!=''){
                    $category_details = $this->contact_model->get_category($eventvalue['categoryid']);
                    foreach ($category_details as $cdkey => $cdvalue) {
                        $html .=strtoupper($cdvalue['name'])."<br>";
                    }
                }
                $html .='</td>';
                $html .='<td>'.$eventvalue['adult'].'</td>';
                $html .='<td>'.$eventvalue['child'].'</td>';
                $html .='<td>'.($eventvalue['total']).'</td>';
                $html .='<td> By '.ucwords(strtolower($eventvalue['vehicle'])).'</td>';
                $html .='<td> '.ucwords(strtolower($eventvalue['room'])).'</td>';
                if($eventvalue['roomdate']!='0000-00-00'){
                    $html .='<td> '.date('d-m-Y',strtotime($eventvalue['roomdate'])).'</td>';
                }else{
                    $html .='<td></td>';
                }
                $html .='<td>';
                   
                $html .='</td>';
            $html .='</tr>';
        }
        $totalsection .='<table class="table"><tr>';
            $totalsection .='<td colspan="4" align="right" ><h5><b>Total :</b></h5> </td>';
            $totalsection .='<td><h5><b>Adult<br>'.$totaladult.'</b></h5></td>';
            $totalsection .='<td><h5><b>Child<br>'.$totalchild.'</b></h5></td>';
            $totalsection .='<td><h5><b>Total<br>'.$grandtotal.'</b></h5></td>';
        $totalsection .='</tr></table>';
        $event_details = $this->event_model->single_event_details($eventid); 
        $this->smarty->assign('evenininvite',$html);
        $this->smarty->assign('totalsection',$totalsection);
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']=strtoupper($event_details['name']);
        $this->data['tpl_name']= "eventwiseview.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    }
    
   
   
}
