<?php  session_start();

if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}

date_default_timezone_set('Asia/Dhaka');
 $date_c = date('Y-m-d H:i:s', time());

$flag= "";

if(isset($_GET['flag']))
{
	$flag = $_GET['flag'];
}

if ($flag == "edit") {
	$msg = "Record Edited Successfully";
}

if ($flag == "add") {
	$msg = "Record Added Successfully";
}
if ($flag == "del") {
	$msg = "Record Deleted Successfully";
}
if ($flag == "success") {
	$msg = "Login Successful";
}






 ?>





<?php  include 'header.php';

include("user.php");


$year=date("Y");
$month=date("m");

$this_month_date=date("Y-m-31");
$six_month_ago_date = date('Y-m-01', strtotime('-6 months', strtotime($this_month_date))); 


$this_month_eventsqr = "SELECT t1.* , t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id WHERE (t2.booking_id!=0 AND t2.status!=2) AND (MONTH(t1.date) = '$month' AND YEAR(t1.date) = '$year') " ;

$this_month_events = mysqli_query($connection,$this_month_eventsqr);
$total_event = mysqli_num_rows($this_month_events);


$this_month_events = "SELECT * FROM `events` WHERE (videoincluded='checked' AND state>0) AND (MONTH(date) = '$month' AND YEAR(date) = '$year')" ;

$this_month_events = mysqli_query($connection,$this_month_events);
$done_event_vd = mysqli_num_rows($this_month_events);

$this_month_events = "SELECT * FROM `events` WHERE (videoincluded!='checked' AND state>0) AND (MONTH(date) = '$month' AND YEAR(date) = '$year')" ;

$this_month_events = mysqli_query($connection,$this_month_events);
$done_event_ph = mysqli_num_rows($this_month_events);

$done_event=$done_event_ph+$done_event_vd;
			






$total_booking = mysqli_query($connection, "
SELECT sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='no') AND (MONTH(t2.approved_at) = '$month' AND YEAR(t2.approved_at) = '$year') ");
$total_booking = mysqli_fetch_object($total_booking);
$total_booking=$total_booking->ev_value;	


$added_later = mysqli_query($connection, "
SELECT sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='yes') AND (MONTH(t1.added_at) = '$month' AND YEAR(t1.added_at) = '$year') ");
$added_later = mysqli_fetch_object($added_later);
$added_later=$added_later->ev_value;	

$total_booking1=$total_booking+$added_later;

$added_inv = mysqli_query($connection, " select sum(t1.inv_amount)-sum(t2.discount) as in_total from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id where (MONTH(t2.date) = '$month' AND YEAR(t2.date) = '$year')
 ");
$added_inv = mysqli_fetch_object($added_inv);
$added_inv=$added_inv->in_total;	

$total_booking=$total_booking1+$added_inv;
 
 
 

 
 $due = mysqli_query($connection, " select w1.*,w2.a_ev_value,w3.in_total,w4.total,w1.t_ev_value+w2.a_ev_value+w3.in_total as total_bk, IFNULL(w1.t_ev_value,0)+IFNULL(w2.a_ev_value,0)+IFNULL(w3.in_total,0)-IFNULL(w4.total,0) as due from (SELECT 1,sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) t_ev_value FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='no')) as w1 left join (SELECT 1,sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) a_ev_value FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='yes')) as w2 on w1.1=w2.1 left join (select 1,sum(t1.inv_amount)-sum(t2.discount) as in_total from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id ) as w3 on w1.1=w3.1 left join (SELECT 1, sum(amount) total FROM `transactions`) as w4 on w1.1=w4.1
 ");
$due = mysqli_fetch_object($due);
$total_bk=$due->total_bk; 
$due=$due->due;

 
 

$total_event_value = mysqli_query($connection, "SELECT sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where t2.status=1 AND (MONTH(t1.date) = '$month' AND YEAR(t1.date) = '$year') ");
$total_event_value = mysqli_fetch_object($total_event_value);
$total_event_value=$total_event_value->ev_value;


$rcvd_this_month = mysqli_query($connection, " SELECT sum(amount) total FROM `transactions` where MONTH(date) = '$month' AND YEAR(date) = '$year' ");
$rcvd_this_month = mysqli_fetch_object($rcvd_this_month);
$rcvd_this_month=$rcvd_this_month->total;





	
  ?>








<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> Wedding Diary</title>
    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">
    <!-- Styles -->
    <link href="assets/css/lib/calendar2/semantic.ui.min.css" rel="stylesheet">
    <link href="assets/css/lib/calendar2/pignose.calendar.min.css" rel="stylesheet">
    <link href="assets/css/lib/chartist/chartist.min.css" rel="stylesheet">
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/owl.carousel.min.css" rel="stylesheet" />
    <link href="assets/css/lib/owl.theme.default.min.css" rel="stylesheet" />
    <link href="assets/css/lib/weather-icons.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/unix.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
</head>

<body>

    <?php include("sidebar.php"); ?>
    <!-- /# sidebar -->

    <?php include("top.php"); ?>
	
	
	
<?php	if ($user_type==4){ 
				  
				  if (isset($_POST['pay_submit'])) {
									  
 
                                    $booking_id = intval($_POST['booking_id']) ;
								   
									$amount = mysqli_real_escape_string($connection, $_POST['amount']);
									$mr_no = mysqli_real_escape_string($connection, $_POST['mr_no']);
									$method = $_POST['method'];
									$details = mysqli_real_escape_string($connection, $_POST['details']);
									$ttype = $_POST['type'];
									$inv_id= 'NULL';
									if($ttype==2){$inv_id = mysqli_real_escape_string($connection, $_POST['inv_no']);}
									$mr_no = mysqli_query($connection, "SELECT max(mr_no) mr FROM `transactions` limit 1");
			                           
			                        $mr_no = mysqli_fetch_object($mr_no);
									$mr_no = $mr_no->mr;
									$mr_no = $mr_no+1;
										
								    $date = date("Y/m/d");
			$booking_ex_qr = mysqli_query($connection, "SELECT * FROM `bookings` where booking_id='$booking_id' limit 1");
			$booking_ex = mysqli_num_rows($booking_ex_qr);
			$temp_id = mysqli_fetch_object($booking_ex_qr);
            $temp_id=$temp_id->id;
			
																		
//**												  
				if($booking_ex==1)		{				  
$sqlinsert = "INSERT INTO `transactions` (`id`, `date`, `temp_booking_id`,`mr_no`, `amount`,`method`,`details`,`type`,`inv_id`, `updated_by`, `added_at`, `updated_at`) VALUES (NULL, '$date', '$temp_id','$mr_no', '$amount','$method','$details','$ttype','$inv_id', '$ad_id', '$date_c', NULL);           
";
$sqlinsert = mysqli_query($connection, $sqlinsert); 
		
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'payment / transaction added from dashboard MR no $mr_no , booking id $booking_id', '$date_c','$temp_id')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 


		
 echo "<div>
 </br>
 </div>";
 include_once('updated.html');	
}		
else {
echo "<div>
 </br>
 </div>";
 include_once('wrong.html');		 }
}	

 } 
	 ?>	
	
	
<?php	if ($user_type==5){ 
				
				 header("refresh:2 , url=booking_list.php"); 
	 } 
	 ?>
    
    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-8 p-r-0 title-margin-right">
                        <div class="page-header">
                            <div class="page-title">
                                <h1>Welcome <span> <?php echo $row->name; ?> !!</span></h1>
								
				  
                            </div>
							
					
				  
                        </div>
                    </div>
                    <!-- /# column -->
                    <div class="col-lg-4 p-l-0 title-margin-left">
                        <div class="page-header">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li>
                                    <li class="active">Home</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                </div>
                <!-- /# row -->
                <section id="main-content">
				
				
				
			
			  <?php 
                    if(!empty($msg)){
			 	 ?>


		<div class="alert alert-info alert-dismissable"> 
                                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                                        <strong> <?php echo $msg; ?> </strong> 
                                    </div>		 
				 
				
					
          

            <?php 
			 	}
			 	  ?>


				  
				   <?php if ($user_type==2){

$doneuSQL = mysqli_query($connection, "SELECT count(t1.id) as done FROM photo_edit as t1 left join events as t2 on t1.event_id=t2.id WHERE (t1.status='checked' OR t1.ph_sp_status='checked') AND ( t1.editor='$ad_id' OR t1.sp_editor='$ad_id' ) order by t1.date desc ");
$doneuSQL = mysqli_fetch_object($doneuSQL);

				
				$number_d=$doneuSQL->done;
                
				   ?>	 
				  
				  
				  <div class="row">
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="media">
                                            <div class="media-body media-text-left">
                                                <h4><?php echo $number; ?></h4>
                                                <p class="color-white">Pedning</p>
                                            </div>
                                            <div class="media-right meida media-middle">
                                                <span><i class="ti-files f-s-48 color-success"></i></span>
                                            </div>
                                        </div>
                                        <div class="progress progress-sm m-t-10">
                                            <div class="progress-bar boxshadow-none  bg-success" role="progressbar" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100" style="width: 85%;"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="media">
                                            <div class="media-body media-text-left">
                                                <h4><?php echo $number_d; ?></h4>
                                                <p class="color-white">Done So Far</p>
                                            </div>
                                            <div class="media-right meida media-middle">
                                                <span><i class="ti-direction-alt f-s-48 color-primary"></i></span>
                                            </div>
                                        </div>
                                        <div class="progress progress-sm m-t-10">
                                            <div class="progress-bar boxshadow-none  bg-primary" role="progressbar" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100" style="width: 85%;"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
				  
				  
				  
				  
				  
				<?php } ?>
				  
				  
				  <?php if ($user_type==3){

$doneuSQL = mysqli_query($connection, "SELECT count(t1.id) as done FROM vd_edit as t1 left join events as t2 on t1.event_id=t2.id WHERE t1.editor ='$ad_id' AND t1.status='checked' order by t1.date desc ");
$doneuSQL = mysqli_fetch_object($doneuSQL);

				
				$number_d=$doneuSQL->done;

				   ?>	 
				  
				  
				  <div class="row">
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="media">
                                            <div class="media-body media-text-left">
                                                <h4><?php echo $number; ?></h4>
                                                <p class="color-white">Pedning</p>
                                            </div>
                                            <div class="media-right meida media-middle">
                                                <span><i class="ti-files f-s-48 color-success"></i></span>
                                            </div>
                                        </div>
                                        <div class="progress progress-sm m-t-10">
                                            <div class="progress-bar boxshadow-none  bg-success" role="progressbar" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100" style="width: 85%;"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="media">
                                            <div class="media-body media-text-left">
                                                <h4><?php echo $number_d; ?></h4>
                                                <p class="color-white">Done So Far</p>
                                            </div>
                                            <div class="media-right meida media-middle">
                                                <span><i class="ti-direction-alt f-s-48 color-primary"></i></span>
                                            </div>
                                        </div>
                                        <div class="progress progress-sm m-t-10">
                                            <div class="progress-bar boxshadow-none  bg-primary" role="progressbar" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100" style="width: 85%;"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
				  
				  
				  
				  
				  
				<?php } ?>
				  
				  
				  
			   <?php if ($user_type==1){  ?>	  
				  
				  <?php
				  
				  if (isset($_POST['pay_submit'])) {
									  
 
                                    $booking_id = intval($_POST['booking_id']) ;
								   
									$amount = mysqli_real_escape_string($connection, $_POST['amount']);
									$mr_no = mysqli_real_escape_string($connection, $_POST['mr_no']);
									$method = $_POST['method'];
									$details = mysqli_real_escape_string($connection, $_POST['details']);
									$ttype = $_POST['type'];
									$inv_id= NULL;
									if($ttype==2){$inv_id = mysqli_real_escape_string($connection, $_POST['inv_no']);}
									
									$mr_no = mysqli_query($connection, "SELECT max(mr_no) mr FROM `transactions` limit 1");
			                           
			                        $mr_no = mysqli_fetch_object($mr_no);
									$mr_no = $mr_no->mr;
									$mr_no = $mr_no+1;
										
								    $date = date("Y/m/d");
			$booking_ex_qr = mysqli_query($connection, "SELECT * FROM `bookings` where booking_id='$booking_id' limit 1");
			$booking_ex = mysqli_num_rows($booking_ex_qr);
			$temp_id = mysqli_fetch_object($booking_ex_qr);
            $temp_id=$temp_id->id;
			
																		
//**												  
				if($booking_ex==1)		{				  
$sqlinsert = "INSERT INTO `transactions` (`id`, `date`, `temp_booking_id`,`mr_no`, `amount`,`method`,`details`,`type`,`inv_id`, `updated_by`, `added_at`, `updated_at`) VALUES (NULL, '$date', '$temp_id','$mr_no', '$amount','$method','$details','$ttype','$inv_id', '$ad_id', '$date_c', NULL);         
";
$sqlinsert = mysqli_query($connection, $sqlinsert); 
											 
 echo "<div>
 </br>
 </div>";
 include_once('updated.html');	
}		
else {
echo "<div>
 </br>
 </div>";
 include_once('wrong.html');		 }
}	
				  
				  
				  
				  
				  
				  
?>				  
				  
				  
				  
				  <button class="btn btn-danger m-b-10" data-toggle="collapse" data-target="#basic-collapse">Summary</button>
				 <a href="event_calendar.php" target="_blank"><button class="btn btn-danger m-b-10">Event Calendar</button> </a>

				 <div id="basic-collapse" class="collapse">
				 
				 
				 
				<div class="row">
				
			
				
				
                        <div class="col-md-4">
                            <div class="card bg-warning">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-check-box color-white"></i></div>
                                    <div class="fb-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Events</div>
                                            <div class="stat-digit">This Month</div>
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-18"><?php echo $done_event; ?>/<?php echo $total_event; ?></span>
											 <div class="stat-digit">Completed</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                       
                        <div class="col-md-4">
                            <div class="card bg-success">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-money color-white"></i></div>
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Bookings</div>
                                            <div class="stat-digit"> This Month</div>
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $total_booking; ?></font></span>
											<div class="stat-digit"><font size="3">&nbsp;&nbsp;&nbsp;in BDT</font> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="card bg-primary">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-stats-up color-white"></i></div>
                                    <div class="linkedin-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Event Value</div>
                                            <div class="stat-digit">This Month</div>
                                        </div>
                                        <div class="all-like dib">
                                           <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo round($total_event_value,0); ?></font></span>
											<div class="stat-digit"><font size="3">&nbsp;&nbsp;&nbsp;in BDT</font> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
 
 
 
                     <div class="row">
				
			
				
				
                        <div class="col-md-4">
                            <div class="card bg-danger">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-money color-white"></i></div>
                                    <div class="fb-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Due</div>
                                            <div class="stat-digit">So Far</div>
                                        </div>
                                        <div class="all-like dib">
                                           <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo round($due,0); ?></font></span>  
											 <div class="stat-digit"><font size="3">&nbsp;&nbsp;&nbsp;in BDT</font> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="card bg-primary">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-money color-white"></i></div>
                                    <div class="twitter-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">POS Sales</div>
                                            <div class="stat-digit">This Month</div>
                                        </div>
                                        <div class="all-like dib">
                                     
											       <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo round($added_inv,0); ?></font></span>  
											<div class="stat-digit"><font size="3">&nbsp;&nbsp;&nbsp;in BDT</font> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                       
                        <div class="col-md-4">
                            <div class="card bg-success">
                                <div class="stat-widget-nine">
                                    <div class="stat-icon"><i class="ti-stats-up color-white"></i></div>
                                    <div class="linkedin-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Payment Received</div>
                                            <div class="stat-digit">This Month</div>
                                        </div>
                                        <div class="all-like dib">
                                           <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $rcvd_this_month; ?></font></span>
											<div class="stat-digit"><font size="3">&nbsp;&nbsp;&nbsp;in BDT</font> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
 
 
 </div>









<div class="row">
				
				        <div class="col-lg-12">
						
						<div class="panel panel-info m-t-15">
                                            <div class="panel-heading">Event Calandar</div>
                                            <div class="panel-body">
											
										<iframe src="event_calendar_inc.php"  scrolling="no" style=" width: 100%; height: 900px;  overflow: hidden;" ></iframe>
						
                   </div>
							
                        </div>
				
				
                        <!-- /# column -->
                        
                    </div>
				
				 </div>







			
				
			<div class="row">
				
				        <div class="col-lg-6">
						
						<div class="panel panel-warning m-t-15">
                                            <div class="panel-heading">Upcoming Events</div>
                                            <div class="panel-body">
						
                           
                                  


                                   

                                            <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-hover ">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Date</th>
                                                    <th>Place</th>
                                                    <th>Name</th>
                                                  
                                                </tr>
                                            </thead>
                                            <tbody>
											
											
											
											<?php
											$sl=0;
											$tdate=date('Y-m-d');
											$sqlUocoming = "select * from (SELECT t1.* , t2.name as client_name FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id WHERE (t2.booking_id!=0 AND t2.status!=2) AND t1.state <1 ) as rr where date >= '$tdate' order by date ASC limit 11 ";

$sqlUocoming = mysqli_query($connection, $sqlUocoming);
while ($list = mysqli_fetch_object($sqlUocoming)) {

                                    
                                   
                                    $idn = $list->id;
								    $date = $list->date;
									$venue = $list->venue;
									$date = date("d.m.y", strtotime($date));
									$client_name = $list->client_name;
									    
										 	
											   
                                  $sl=$sl+1;
								
                                    
                                   
                                ?>
											
											
											
											
											
											
                                                <tr>
                                                    <th scope="row"><?php echo $sl;  ?></th>
                                                    <td><?php echo $date;  ?></td>
                                                    <td><span class="badge badge-primary"><?php echo $venue;  ?></span></td>
                                                   
                                                     <td class="color-danger"> <?php echo $client_name;  ?> </td>
                                                </tr>
<?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                              
                                        
                                       
                                    </div>


                              
							 </div> </div>
							
                        </div>
				
				
                        <div class="col-lg-6">
						
						<div class="panel panel-warning m-t-15">
                                            <div class="panel-heading">Recent Payments</div>
                                            <div class="panel-body">
						



							
						<div class="card-body"> </br>
						<div class="row">
						
						 <form method="post">
						<table width="100%"> <tr>
						
						<td>
						  <input type="text"  placeholder="Booking ID" name="booking_id" size="7">
						</td>
						
						<td>
						<select name="method" placeholder="payment method">
											    <option value=""> </option>
											   <option value="cash"> cash </option>
											   <option value="bkash"> bkash </option>
											   <option value="cheque"> cheque </option>
											   <option value="bank"> bank </option>
											    <option value="card"> card </option>
											   </select>
						</td>
						<td>
						<select name="type" id="type" placeholder="">
											    <option value="1">B</option>
											   <option value="2">I</option>
											   </select>
						 <input hidden="hidden" type="text" id="2" placeholder="Invoice ID" name="inv_no" size="6">
											   
						</td>
						
						
						<td>
						 <input type="text"  placeholder="Description" name="details" size="15">
						</td>
						<td>
						<input type="text"  placeholder="Amount" name="amount" size="6" >
						</td>
						<td>
						<button  type="submit" name="pay_submit" onclick="return confirm('Are you sure you want to add this payment on booking ID ??');" >ADD</button>
						</td>
						</tr>
						</table>
						
						
				       
						 </form>
						  </div>	
						    </div>	
						
						
                                    <div class="table-responsive">
                                        <table class="table table-hover ">
                                            <thead>
                                                <tr>
                                                    <th># ID</th>
													 <th>MR</th>
													 	<th>Method</th>
                                                    <th>Amount</th>
												
                                                    <th>Date</th>
                                                    <th>Edited by</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											
											
											
											<?php

						$sqlSelectedLG = "select f1.* , f2.name from (SELECT t1.*,t2.booking_id FROM `transactions` as t1 left join bookings as t2 on t1.temp_booking_id=t2.id) as f1 left join users as f2 on f1.updated_by = f2.id order by f1.date desc limit 10";

$sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);
while ($list = mysqli_fetch_object($sqlSelectedLG)) {

                                    
                                   
                                    $idn = $list->id;
								    $date = $list->date;
									$date = date("d.m.y", strtotime($date));
									$booking_id = $list->booking_id;
									$amount = $list->amount;
									$mr_no = $list->mr_no;
									$method = $list->method;
									$updated_by = $list->name;
									
								
									     
										 	
											   
                                  
								
                                    
                                   
                                ?>
											
											
											
											
											
											
                                                <tr>
                                                    <th scope="row"><?php echo $booking_id;  ?></th>
													 <td> <a href="print_receipt.php?id=<?php echo $idn;  ?>" target="_blank"><?php echo $mr_no;  ?> 	    </a>  </td>
													 <td><span class="badge badge-success"><?php echo $method;  ?></span></td>
                                                  <td class="color-primary"> <?php echo $amount;  ?> </td>
                                                   
                                                    <td><?php echo $date;  ?></td>
													 <td><span class="badge badge-primary"><?php echo $updated_by;  ?></span></td>
                                                    
                                                </tr>
<?php } ?>        
                                            </tbody>
                                        </table>
                                    </div>
									
									</div>
                                        </div>
                               
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                        
                    </div>
					
					<div class="row">
                        <div class="col-lg-6">
                            <div class="card alert">
                              <canvas id="bar-chart-grouped3" width="800" height="450"></canvas>  
                            </div>
                        </div>
						<div class="col-lg-6">
                            <div class="card alert">
                             <canvas id="bar-chart-grouped2" width="800" height="450"></canvas>   
                            </div>
                        </div>
                    </div>
                    
					
					
					
					
					
					
					
					
				
				<div class="row">
                        <div class="col-lg-6">
                            <div class="card alert">
                              <canvas id="bar-chart-grouped" width="800" height="450"></canvas>  
                            </div>
                        </div>
						<div class="col-lg-6">
                            <div class="card alert">
                             <canvas id="pie-chart" width="800" height="450"></canvas>   
                            </div>
                        </div>
                    </div>
                    
                 
					
					  <?php } ?>
					  
					  
					  
					  
					  <?php if($user_type==4) { ?>
					  
					  <div class="col-lg-6">
						
						<div class="panel panel-warning m-t-15">
                                            <div class="panel-heading">Recent Payments</div>
                                            <div class="panel-body">
						



							
						<div class="card-body"> </br>
						<div class="row">
						
						 <form method="post">
						<table width="100%"> <tr>
						
						<td>
						  <input type="text"  placeholder="Booking ID" name="booking_id" size="10">
						</td>
						
						<td>
						<select name="method" placeholder="payment method">
											    <option value=""> </option>
											   <option value="cash"> cash </option>
											   <option value="bkash"> bkash </option>
											   <option value="cheque"> cheque </option>
											   <option value="bank"> bank </option>
											    <option value="card"> card </option>
											   </select>
						</td>
						<td>
						<select name="type" id="type" placeholder="">
											    <option value="1">B</option>
											   <option value="2">I</option>
											   </select>
						 <input hidden="hidden" type="text" id="2" placeholder="Invoice ID" name="inv_no" size="6">
											   
						</td>
						
						
						<td>
						 <input type="text"  placeholder="Description" name="details" size="15">
						</td>
						<td>
						<input type="text"  placeholder="Amount" name="amount" size="6" >
						</td>
						<td>
						<button  type="submit" name="pay_submit" onclick="return confirm('Are you sure you want to add this payment on booking ID ??');" >ADD</button>
						</td>
						</tr>
						</table>
						
						
				       
						 </form>
						  </div>	
						    </div>	
						
						
                                    <div class="table-responsive">
                                        <table class="table table-hover ">
                                            <thead>
                                                <tr>
                                                    <th># ID</th>
													 <th>MR</th>
													 	<th>Method</th>
                                                    <th>Amount</th>
												
                                                    <th>Date</th>
                                                    <th>Edited by</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											
											
											
											<?php

						$sqlSelectedLG = "select f1.* , f2.name from (SELECT t1.*,t2.booking_id FROM `transactions` as t1 left join bookings as t2 on t1.temp_booking_id=t2.id) as f1 left join users as f2 on f1.updated_by = f2.id order by f1.date desc limit 10";

$sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);
while ($list = mysqli_fetch_object($sqlSelectedLG)) {

                                    
                                   
                                    $idn = $list->id;
								    $date = $list->date;
									$date = date("d.m.y", strtotime($date));
									$booking_id = $list->booking_id;
									$amount = $list->amount;
									$mr_no = $list->mr_no;
									$method = $list->method;
									$updated_by = $list->name;
									
								
									     
										 	
											   
                                  
								
                                    
                                   
                                ?>
											
											
											
											
											
											
                                                <tr>
                                                    <th scope="row"><?php echo $booking_id;  ?></th>
													 <td> <a href="print_receipt.php?id=<?php echo $idn;  ?>" target="_blank"><?php echo $mr_no;  ?> 	    </a>  </td>
													 <td><span class="badge badge-success"><?php echo $method;  ?></span></td>
                                                  <td class="color-primary"> <?php echo $amount;  ?> </td>
                                                   
                                                    <td><?php echo $date;  ?></td>
													 <td><span class="badge badge-primary"><?php echo $updated_by;  ?></span></td>
                                                    
                                                </tr>
<?php } ?>        
                                            </tbody>
                                        </table>
                                    </div>
									
									</div>
                                        </div>
                               
                            <!-- /# card -->
                        </div>
					  
					  
					  <?php } ?>
					 
					
					
					
					
					
					
                    <?php include("footer.php"); ?>
                </section>
            </div>
        </div>
    </div>
   <?php if ($user_type==1){  ?>
  <div id="search">
        <button type="button" class="close">×</button>
        <form action="search.php">
            <input type="search" name="search" value="" placeholder="type keyword(s) here" />
            <button type="submit" class="btn btn-primary">Search</button>
        </form>
    </div>
   
   <?php } ?>
    <!-- jquery vendor -->
   
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    
    <!-- bootstrap -->

    <script src="assets/js/lib/calendar-2/moment.latest.min.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/calendar-2/semantic.ui.min.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/calendar-2/prism.min.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/calendar-2/pignose.calendar.min.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/calendar-2/pignose.init.js"></script>
    <!-- scripit init-->


    <script src="assets/js/lib/weather/jquery.simpleWeather.min.js"></script>
    <script src="assets/js/lib/weather/weather-init.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
    <script src="assets/js/lib/chartist/chartist.min.js"></script>
    <script src="assets/js/lib/chartist/chartist-init.js"></script>
    <script src="assets/js/lib/sparklinechart/jquery.sparkline.min.js"></script>
    <script src="assets/js/lib/sparklinechart/sparkline.init.js"></script>
    <script src="assets/js/lib/owl-carousel/owl.carousel.min.js"></script>
    <script src="assets/js/lib/owl-carousel/owl.carousel-init.js"></script>
    <script src="assets/js/scripts.js"></script>
    <!-- scripit init-->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
	
	
	
	
    <script>
	
		  
		  
		  
		new Chart(document.getElementById("bar-chart-grouped3"), {
    type: 'bar',
    data: {
      labels: [<?php 
	  $bar1 = "select * from (select * from (select w.*,CONCAT(w.yr,'-',w.m, '-', '01') as d  from (select  ( CASE f1.month  WHEN 'January' THEN 1
            WHEN 'February' THEN 2
            WHEN 'March' THEN 3
            WHEN 'April' THEN 4
            WHEN 'May' THEN 5
            WHEN 'June' THEN 6
            WHEN 'July' THEN 7
            WHEN 'August' THEN 8
            WHEN 'September' THEN 9
            WHEN 'October' THEN 10
            WHEN 'November' THEN 11
            WHEN 'December' THEN 12
          END ) as m, f1.month, f1.yr,f1.ap_dt, IFNULL(f1.ev_value,0)+IFNULL(f2.ev_value,0)+IFNULL(f3.in_total,0) t_booking from (SELECT t2.approved_at ap_dt,YEAR(t2.approved_at) as yr,MONTHNAME(t2.approved_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='no') AND (date(t2.approved_at) BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t2.approved_at) order by t2.approved_at) as f1 left join (SELECT MONTHNAME(t1.added_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='yes') AND (t1.added_at BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t1.added_at) order by t1.added_at) as f2 on f1.month=f2.month left join (SELECT MONTHNAME(t2.date) month , sum(t1.inv_amount)-sum(t2.discount) as in_total from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id where t2.date BETWEEN '$six_month_ago_date' AND '$this_month_date' group by MONTHNAME(t2.date) order by t2.date) as f3 on f1.month=f3.month ) as w ) as y order by ap_dt desc limit 6) as gd  order by ap_dt asc";

$bar1 = mysqli_query($connection, $bar1);
while ($list = mysqli_fetch_object($bar1)) {
  $month = $list->month;      
                                ?>
"<?php echo $month; ?>", <?php } ?> ],
      datasets: [
        {
          label: "Booking Value",
          backgroundColor: "#F39C12",
          data: [<?php 
	  $bar2 = "select * from (select * from (select w.*,CONCAT(w.yr,'-',w.m, '-', '01') as d  from (select  ( CASE f1.month  WHEN 'January' THEN 1
            WHEN 'February' THEN 2
            WHEN 'March' THEN 3
            WHEN 'April' THEN 4
            WHEN 'May' THEN 5
            WHEN 'June' THEN 6
            WHEN 'July' THEN 7
            WHEN 'August' THEN 8
            WHEN 'September' THEN 9
            WHEN 'October' THEN 10
            WHEN 'November' THEN 11
            WHEN 'December' THEN 12
          END ) as m, f1.month, f1.yr,f1.ap_dt, IFNULL(f1.ev_value,0)+IFNULL(f2.ev_value,0)+IFNULL(f3.in_total,0) t_booking from (SELECT t2.approved_at ap_dt,YEAR(t2.approved_at) as yr,MONTHNAME(t2.approved_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='no') AND (date(t2.approved_at) BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t2.approved_at) order by t2.approved_at) as f1 left join (SELECT MONTHNAME(t1.added_at) month, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where (t2.status=1 AND t1.added_later='yes') AND (t1.added_at BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t1.added_at) order by t1.added_at) as f2 on f1.month=f2.month left join (SELECT MONTHNAME(t2.date) month , sum(t1.inv_amount)-sum(t2.discount) as in_total from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id where t2.date BETWEEN '$six_month_ago_date' AND '$this_month_date' group by MONTHNAME(t2.date) order by t2.date) as f3 on f1.month=f3.month ) as w ) as y order by ap_dt desc limit 6 ) as gd  order by ap_dt asc";

$bar2 = mysqli_query($connection, $bar2);
while ($list = mysqli_fetch_object($bar2)) {
  $total = $list->t_booking;      
                                ?>
"<?php echo $total; ?>", <?php } ?>]
        }
      ]
    },
    options: {
      title: {
        display: true,
        text: 'Booking Value in Six Month'
      } ,
	  scales: {
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: 0,    // minimum will be 0, unless there is a lower value.
                // OR //
                beginAtZero: true   // minimum value will be 0.
            }
        }]
    }
    }
});
	




	
		  
		  
	
	new Chart(document.getElementById("bar-chart-grouped2"), {
    type: 'bar',
    data: {
      labels: [<?php 
	  $bar1 = " select * from (SELECT  MONTHNAME(t1.date) month, t1.date dd,sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where t2.status=1 AND (t1.date BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t1.date) order by t1.date desc limit 6) as y order by y.dd";

$bar1 = mysqli_query($connection, $bar1);
while ($list = mysqli_fetch_object($bar1)) {
  $month = $list->month;      
                                ?>
"<?php echo $month; ?>", <?php } ?> ],
      datasets: [
        {
          label: "Event Value",
          backgroundColor: "#3e95cd",
          data: [<?php 
	  $bar2 = " select * from (SELECT  MONTHNAME(t1.date) month, t1.date dd, sum(t1.ev_value-((t1.ev_value*t2.discount)/100)) ev_value FROM `events`  as t1 left join bookings as t2 on t1.temp_id=t2.id where t2.status=1 AND (t1.date BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(t1.date) order by t1.date desc limit 6) as y order by y.dd";

$bar2 = mysqli_query($connection, $bar2);
while ($list = mysqli_fetch_object($bar2)) {
  $total = $list->ev_value;      
                                ?>
"<?php echo $total; ?>", <?php } ?>]
        }
      ]
    },
    options: {
      title: {
        display: true,
        text: 'Event Value in Six Month'
      } ,
	  scales: {
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: 0,    // minimum will be 0, unless there is a lower value.
                // OR //
                beginAtZero: true   // minimum value will be 0.
            }
        }]
    }
    }
});
	
	
	
	
	
	

	
	
	
	new Chart(document.getElementById("bar-chart-grouped"), {
    type: 'bar',
    data: {
      labels: [<?php 
	  $bar1 = " select * from (select w1.* from (SELECT ( CASE MONTHNAME(approved_at)  WHEN 'January' THEN 1
            WHEN 'February' THEN 2
            WHEN 'March' THEN 3
            WHEN 'April' THEN 4
            WHEN 'May' THEN 5
            WHEN 'June' THEN 6
            WHEN 'July' THEN 7
            WHEN 'August' THEN 8
            WHEN 'September' THEN 9
            WHEN 'October' THEN 10
            WHEN 'November' THEN 11
            WHEN 'December' THEN 12
          END ) as m , MONTHNAME(approved_at) month,approved_at dd, count(id) total FROM `bookings` where (booking_id!=0 AND status!=2) AND (date(approved_at) BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(approved_at) order by DATE_FORMAT('approved_at', '%m'),Case DATE_FORMAT('approved_at', '%m')
	when 'Jan' then 1
	when 'Feb' then 2
	when 'Mar' then 3
	when 'Apr' then 4
	when 'May' then 5
	when 'Jun' then 6
	when 'Jul' then 7
	when 'Aug' then 8
	when 'Sep' then 9
	when 'Oct' then 10
	when 'Nov' then 11
	when 'Dec' then 12
	Else 99 end ASC ) as w1 order by dd DESC limit 6) as hj order by dd asc";

$bar1 = mysqli_query($connection, $bar1);
while ($list = mysqli_fetch_object($bar1)) {
  $month = $list->month;      
                                ?>
"<?php echo $month; ?>", <?php } ?> ],
      datasets: [
        {
          label: "Bookings",
          backgroundColor: "#3e95cd",
          data: [<?php 
	  $bar2 = " select * from (select w1.* from (SELECT ( CASE MONTHNAME(approved_at)  WHEN 'January' THEN 1
            WHEN 'February' THEN 2
            WHEN 'March' THEN 3
            WHEN 'April' THEN 4
            WHEN 'May' THEN 5
            WHEN 'June' THEN 6
            WHEN 'July' THEN 7
            WHEN 'August' THEN 8
            WHEN 'September' THEN 9
            WHEN 'October' THEN 10
            WHEN 'November' THEN 11
            WHEN 'December' THEN 12
          END ) as m , MONTHNAME(approved_at) month,approved_at dd, count(id) total FROM `bookings` where (booking_id!=0 AND status!=2) AND (date(approved_at) BETWEEN '$six_month_ago_date' AND '$this_month_date') group by MONTHNAME(approved_at) order by DATE_FORMAT('approved_at', '%m'),Case DATE_FORMAT('approved_at', '%m')
	when 'Jan' then 1
	when 'Feb' then 2
	when 'Mar' then 3
	when 'Apr' then 4
	when 'May' then 5
	when 'Jun' then 6
	when 'Jul' then 7
	when 'Aug' then 8
	when 'Sep' then 9
	when 'Oct' then 10
	when 'Nov' then 11
	when 'Dec' then 12
	Else 99 end ASC ) as w1 order by dd DESC limit 6) as hj order by dd asc ";

$bar2 = mysqli_query($connection, $bar2);
while ($list = mysqli_fetch_object($bar2)) {
  $total = $list->total;      
                                ?>
"<?php echo $total; ?>", <?php } ?>]
        }
      ]
    },
    options: {
      title: {
        display: true,
        text: 'Bookings in Six Month'
      } ,
	  scales: {
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: 0,    // minimum will be 0, unless there is a lower value.
                // OR //
                beginAtZero: true   // minimum value will be 0.
            }
        }]
    }
    }
});


   new Chart(document.getElementById("pie-chart"), {
    type: 'pie',
    data: {
      labels: [<?php 
	  $pie1 = " SELECT t2.title , t1.total FROM (SELECT ref, count(id) total FROM `bookings` where booking_id!=0 AND status!=2 group by ref) as t1 left join ref as t2 on t1.ref = t2.id ";

$pie1 = mysqli_query($connection, $pie1);
while ($list = mysqli_fetch_object($pie1)) {
  $title = $list->title;      
                                ?>
"<?php echo $title; ?>", <?php } ?> 
	  ],
      datasets: [{
        label: "Refered From",
        backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9"],
        data: [<?php 
	  $pie1 = " SELECT t2.title , t1.total FROM (SELECT ref, count(id) total FROM `bookings` where booking_id!=0 AND status!=2 group by ref) as t1 left join ref as t2 on t1.ref = t2.id  ";

$pie1 = mysqli_query($connection, $pie1);
while ($list = mysqli_fetch_object($pie1)) {
  $total = $list->total;      
                                ?>
"<?php echo $total; ?>", <?php } ?> ]
      }]
    },
    options: {
      title: {
        display: true,
        text: 'Refered From'
      }
    }
});


	</script>


<script type="text/javascript">
        $(document).on('change',"#type",function () {
            if($("#type").val() === "2") $("#2").show();
            else $("#2").hide();
        })
</script>


	
</body>

</html>