<?php session_start(); ob_start(); ?>

<?php  include 'header.php'; ?>

<?php
ini_set('display_errors', 0);

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());
include("user.php");
$t_type=$_GET['type'];
$r=$_GET['r'];

$filter_value_all="checked";

$dayBookDate2=date('Y-m-d');
$dayBookDate2=date('Y-m-d', strtotime($dayBookDate2. ' + 2 days'));


$dayBookDate1=date('Y-m-01', strtotime($dayBookDate1. ' - 1 years'));

if($_SESSION['DATE1']==""){
	$_SESSION['DATE1']=$dayBookDate1;
    $_SESSION['DATE2']=$dayBookDate2;
}

if($_SESSION['mode']==""){
	$_SESSION['mode']="booking";
}
$sub=0;

 if (isset($_POST['submit'])) {
									  
									  
			$ev_id=$_POST['ev_id'];
	        $new_normal_edit_st=$_POST['normal_edit_st'];
			$new_special_edit_st=$_POST['special_edit_st'];
			$new_photo_dvd_st=$_POST['photo_dvd_st'];
			$new_video_dvd_st=$_POST['video_dvd_st'];
			$new_photo_print_st=$_POST['photo_print_st'];
			$new_d_date=$_POST['d_date'];
			$new_d_date_vd=$_POST['d_date_vd'];
			$new_actual_d_date=$_POST['actual_d_date'];
			$new_soft_d_date=$_POST['soft_d_date'];
			$new_client_selection_date=$_POST['client_selection_date'];
	
           $sqlUpdate = mysqli_query($connection, "UPDATE `events` SET 
		   `normal_edit_st` = '$new_normal_edit_st', 
		   `special_edit_st` = '$new_special_edit_st',
		   `photo_dvd_st` = '$new_photo_dvd_st',
		   `video_dvd_st` = '$new_video_dvd_st',
		   `photo_print_st` = '$new_photo_print_st',
		   `d_date` = '$new_d_date',
		   `d_date_vd` = '$new_d_date_vd',
		   `actual_d_date` = '$new_actual_d_date',
		   `soft_d_date` = '$new_soft_d_date',
		   `client_selection_date` = '$new_client_selection_date'
		   WHERE `events`.`id` = '$ev_id';"); 
	
	      
			 }
					


if (isset($_POST['submit_reason'])) {
	$lreason=$_POST['reason'];
	$evn_id=$_POST['evn_id'];
	 $sqlUpdate = mysqli_query($connection, "UPDATE `events` SET 
		   `late_reason` = '$lreason'
		   WHERE `events`.`id` = '$evn_id';");
	
}

if (isset($_POST['day_submit'])) {
	$dayBookDate1=$_POST['date1'];
	$dayBookDate2=$_POST['date2'];
	$_SESSION['DATE1']=$dayBookDate1;
    $_SESSION['DATE2']=$dayBookDate2;
	$sub=2;
	$filter=$_POST['filter'];
	$_SESSION['FILTER']=$filter;
}

$dayBookDate1=$_SESSION['DATE1'];
$dayBookDate2=$_SESSION['DATE2'];
$filter=$_SESSION['FILTER'];

if (isset($_POST['id_submit'])) {
	$temp_booking_id=$_POST['temp_booking_id'];
	$_SESSION['booking_id']=$temp_booking_id;

	$sub=3;
}

$temp_booking_id=$_SESSION['booking_id'];

if (isset($_GET['mode'])) {
	$mode=$_GET['mode'];
if($mode=="search"){
	$sub=2;
	$_SESSION['mode']="search";
}
if($mode=="booking"){
	$sub=3;
	$_SESSION['mode']="booking";
}



}

	$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2') )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(f4.in_amount,0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 ) as k1 where booking_id!=0) as p1) as op2 on op1.booking_id=op2.bk_id order by op1.date DESC limit 500";
						
						if($sub=="2")
								{
									
									if($filter=="all") {
									 $filter_nm="All";	
										
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as op2 on op1.booking_id=op2.bk_id order by op1.date DESC limit 500";
									
										}
										
									if($filter=="upcoming_delivery") {
									 $filter_nm="Upcoming Delivery";	
										
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.d_date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id order by op1.d_date DESC limit 500";
										
										}	
									if($filter=="delivery_date") {
									 $filter_nm="Delivery Date";	
										
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.actual_d_date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id order by op1.actual_d_date DESC limit 500";
										
										}	
                                     if($filter=="normal_pending") {
									 $filter_nm="Normal Edit Pending";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2') order by q1.date DESC )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.ph_status='' AND op1.normal_edit_st<2 order by op1.date DESC limit 500";
										
                                    
									}
 										
									if($filter=="soft_ready") {
									 $filter_nm="Normal Edit SoftCopy Ready";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2') order by q1.date DESC )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.ph_status='checked' AND op1.normal_edit_st<2 order by op1.date DESC limit 500";
										
                                    
									}									
										
									if($filter=="soft_delivered") {
									 $filter_nm="Normal Edit SoftCopy Delivered";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.normal_edit_st>1 order by op1.date DESC";
										
                                    
									}	
										
									
									if($filter=="waiting_for_client") {
									 $filter_nm="Waiting for Client Selection";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where (op1.normal_edit_st>1 AND op1.photo_selection='') AND (op1.sp_editor='' AND op1.ph_sp_status='') order by op1.date DESC";
										
                                    
									}	
									
									if($filter=="special_pending") {
									 $filter_nm="Special Edit Pending";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where (op1.normal_edit_st>1 AND op1.photo_selection!='') AND (op1.sp_editor='' AND op1.ph_sp_status='') order by op1.date DESC";
										
                                    
									}

                                    if($filter=="special_edit_in_panel") {
									 $filter_nm="Special Edit in Panel";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where 
						
						(op1.normal_edit_st>1 ) AND (op1.sp_editor!='' AND op1.ph_sp_status='')
						
						
						 order by op1.date DESC";
										
                                    
									}									
									
									
                                    if($filter=="special_edit_done") {
									 $filter_nm="Special Edit Done";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.sp_editor!='' AND op1.ph_sp_status!='' order by op1.date DESC";
										
                                    
									}	
									
									   if($filter=="waiting_for_song") {
									    $filter_nm="Waiting for Song";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.lock_input=0 AND videoincluded='checked' order by op1.date DESC";
										
                                    
									}
									
									
									 if($filter=="song_accepted") {
									 $filter_nm="Song Accepted";
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.lock_input>0 AND videoincluded='checked' order by op1.date DESC";
										
                                    
									}
									
									
									 if($filter=="photo_dvd_pending") {
										 $filter_nm="Photo DVD Pending";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_dvd_st=0 order by op1.date DESC";
										
                                    
									}
									
									if($filter=="photo_dvd_ready") {
										 $filter_nm="Photo DVD Ready";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_dvd_st=1 order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="photo_dvd_delivered") {
										 $filter_nm="Photo DVD Delivered";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_dvd_st=2 order by op1.date DESC";
										
                                    
									}
									
									if($filter=="video_dvd_pending") {
										 $filter_nm="Video DVD Pending";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.video_dvd_st=0 AND op1.vd_status!='checked' AND op1.videoincluded='checked' order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="video_dvd_ready") {
										 $filter_nm="Video DVD Ready";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.video_dvd_st=1 order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="video_dvd_delivered") {
										 $filter_nm="Photo DVD Delivered";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.video_dvd_st=2 order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="photo_print_pending") {
										 $filter_nm="Photo Print Pending";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_print_st=0 order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="photo_print_ready") {
										 $filter_nm="Photo Print Ready";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_print_st=1 order by op1.date DESC";
										
                                    
									}
									
									if($filter=="photo_print_delivered") {
										 $filter_nm="Photo Print Delivered";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_print_st=2 order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="all_ready") {
										 $filter_nm="All Ready";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_dvd_st=1 AND CASE
          WHEN op1.videoincluded='checked' THEN op1.video_dvd_st=1
          ELSE 1=1
      END
	   AND op1.photo_print_st=1  order by op1.date DESC";
										
                                    
									}
									
									
									if($filter=="all_delivered") {
										 $filter_nm="All Delivered";
									
										$sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1 AND (q1.date BETWEEN '$dayBookDate1' AND '$dayBookDate2')  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.photo_dvd_st=2 AND CASE
          WHEN op1.videoincluded='checked' THEN op1.video_dvd_st=2
          ELSE 1=1
      END
	   AND op1.photo_print_st=2  order by op1.date DESC";
										
                                    
									}
									
									
									}



                       if($sub=="3") {
						   $sqlSelectedLG = "select op1.*,op2.paid,op2.due,op2.ev_total,op2.in_amt from 
						
						(select q1.*,q2.name as ph_editor_name,q3.name as vd_editor_name,q4.name as sp_editor_name from (select h1.* ,h2.editor as ph_editor,h2.sp_editor,h2.ph_sp_status, h2.date as ph_date, h2.hdd as ph_hdd, h2.rg_edit as ph_rg_edit, h2.sp_edit as ph_sp_edit, h2.remarks as ph_remarks, h2.status as ph_status,h3.editor as vd_editor, h3.date as vd_date, h3.hdd as vd_hdd, h3.remarks as vd_remarks, h3.status as vd_status from (SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name,t2.booking_name, t2.booking_id, t2.cell_1,t2.cell_2,t2.status as booking_status FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) group by v1.id ORDER BY TIMESTAMP(v1.date,v1.time)) as h1 left join photo_edit as h2 on h1.id=h2.event_id left join vd_edit as h3 on h1.id=h3.event_id) as q1 left join users as q2 on q1.ph_editor=q2.id left join users as q3 on  q1.vd_editor=q3.id left join users as q4 on q1.sp_editor=q4.id where q1.booking_status=1  )  
						
						as op1 left join (select * from (select booking_id bk_id,cell_1,name,ev_total,in_amt,paid,ev_total+in_amt-paid due from (select f1.* ,IFNULL(SUM(f4.in_amount),0) in_amt,(IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))-((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0))*IFNULL(f1.discount,0)/100) ev_total,((IFNULL(f2.ev_value,0)+IFNULL(f3.added_later,0)+IFNULL(f4.in_amount,0))-IFNULL(f1.paid,0)) as due,f2.ev_value,IFNULL(f3.added_later,0) added_later from (SELECT t1.id, t1.booking_id,t1.booking_name,t1.cell_1,t1.cell_2,t1.name,t1.approved_at,t1.added_at,IFNULL(t1.discount,0) discount,t1.status, IFNULL(t2.paid,0) as paid FROM `bookings` as t1 LEFT JOIN (SELECT temp_booking_id, sum(IFNULL(amount,0)) as paid FROM `transactions` GROUP BY temp_booking_id) as t2 on t1.id=t2.temp_booking_id) as f1 left join (SELECT temp_id, count(id) ev_total, sum(ev_value) ev_value FROM `events` where added_later='no' GROUP BY temp_id) as f2 on f1.id=f2.temp_id left join (SELECT temp_id, IFNULL(count(id),0) ev_total_later, sum(ev_value) added_later FROM `events` where added_later='yes' GROUP BY temp_id) as f3 on f1.id=f3.temp_id left join (select t2.customer_id, IFNULL(t1.inv_amount,0)-IFNULL(t2.discount,0) in_amount 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 f4 on f4.customer_id=f1.id where f1.status!=0 group by f1.booking_id) as k1 where booking_id!=0) as p1 ) as op2 on op1.booking_id=op2.bk_id where op1.temp_id='$temp_booking_id' order by op1.date DESC ";
					   }

?>



<!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>Delivery Status <?php echo $eee; ?></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/data-table/buttons.bootstrap.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">
	  <link href="assets/css/lib/select2/select2.min.css" rel="stylesheet">
</head>

<body>

   
   
   
     <?php include("sidebar.php"); ?>
	
	
    <!-- /# sidebar -->
     <?php include("top.php"); ?>
	<!-- /# topebar --> 
	
	
	
	
	<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
	   <center>
        <h5 class="modal-title" id="exampleModalLongTitle">Late Reason</h5>
        </center>
      </div>
        
      <div class="modal-body" id="reason">
        ...
      </div>
	

	  
    </div>
  </div>
</div>
	
	
	
	
	
	
	
	
	
	
    <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>Hello, <span>Welcome Here</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">
				
				
			
				
				
				
				
				
				<div class="row">
				
				        <div class="col-lg-12">
						
						<div class="panel panel-info m-t-15">
                                            <div class="panel-heading">Delivery Status</div>
                                            <div class="panel-body">
						
								

								   <?php
								  if (isset($_POST['submit'])) {
								
	
	       echo "<div>
			 </br>
				 </div>";
		 include_once('updated.html');
			 }
								  
								  ?>
								  
								  
								 
								  
								  
								  
								  
								  
								  
								  
								  
								  
                                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
							
							
							
							
							
							
							
							
							
							
							
                               
								
								
								
								
								
								
								
								
								
						<?php if ($user_type==1 OR $user_type==4){  ?>
								
								
									
							<div class="row-form clearfix">	


                        <div class="col-sm-12"> 
						   
							<table>
							<tr>
							
							
							 <form action='delivery_status.php?mode=booking'  method='POST'>   
							<td><select class="form-control bg-ash border-none select2" data-placeholder="Select Booking" style="width: 100%;" name="temp_booking_id">
            <option></option>	<?php 
                               
                                $sqlSelectMem = "SELECT * FROM `bookings` where booking_id!=0 ";

                                $sqlSelectMem = mysqli_query($connection, $sqlSelectMem);
                               while ($list = mysqli_fetch_object($sqlSelectMem)) {
                                    $booking_id = $list->booking_id;
									$temp_id = $list->id;
									$name = $list->name;
                                   
                                ?>   <option value="<?php echo $temp_id;  ?>"> <?php echo $booking_id;  ?> -  <?php echo $name;  ?>  </option>
														
							   <?php } ?>
                                 </select>
							</td>
							<td>&nbsp; &nbsp; <input class="submit" type="submit"  name="id_submit"  value="Search" /> </td>
							 </form>	
							 
							 <form action='delivery_status.php?type=export&mode=search'  method='POST'>      
							<td> &nbsp; &nbsp;
							From <input class="date" type="date" value="<?php echo $dayBookDate1; ?>" name="date1" id="datetimepicker2"/>
							</td>
							<td>
							To <input class="date" type="date"  value="<?php echo $dayBookDate2; ?>" name="date2" id="datetimepicker2"/>
							</td>
							
							<td> 
							&nbsp; &nbsp;
							<select name="filter" >
							
							<?php if ($filter!="") { ?>
								
								<option value="<?php echo $filter; ?>"> <?php echo $filter_nm; ?> </option>
								
					<?php		}
							?>
							
							
							<option value="all"> All </option>
                            <option value="upcoming_delivery"> Upcoming Delivery </option>
							<option value="delivery_date"> Delivery Date </option>
							<option value="normal_pending"> Normal Edit Pending </option>
							<option value="soft_ready"> Normal Edit SoftCopy Ready </option>
							<option value="soft_delivered"> Nornal Edit SoftCopy Delivered </option>
							<option value="waiting_for_client"> Waiting for Client Selection </option>
						   <option value="special_pending"> Special Edit Pending </option>
							<option value="special_edit_in_panel"> Special Edit in Panel </option>
							<option value="special_edit_done"> Special Edit Done </option>
							<option value="waiting_for_song"> Waiting for song </option>
							<option value="song_accepted"> Song Accepted </option>
							<option value="photo_dvd_pending"> Photo DVD Pending </option>
							<option value="photo_dvd_ready"> Photo DVD Ready </option>
							<option value="photo_dvd_delivered"> Photo DVD Delivered </option>
							<option value="video_dvd_pending"> Video DVD Pending </option>
							<option value="video_dvd_ready"> Video DVD Ready </option>
							<option value="video_dvd_delivered"> Video DVD Delivered </option>
							<option value="photo_print_pending"> Photo Printing Pending </option>
							<option value="photo_print_ready"> Photo Print Ready </option>
							<option value="photo_print_delivered"> Photo Print Delivered </option>
							<option value="all_ready"> All Ready </option>
							<option value="all_delivered"> All Delivered </option>
							
							
							 </select>
							
							</td>
							
							
					
							
							<td>
							&nbsp; &nbsp; <input class="submit" type="submit"  name="day_submit"  value="Search" /> 
							</td>
							 </form>


                            <td>
							&nbsp; &nbsp; <a href="delivery_status.php?type=export&mode=search&r=1"> <span class="badge badge-info">Easy Export</span></a> 
							</td>
							
							</tr>
							</table>
						   
						   </div>							
							

                           <br><br>
							
							 </div>
								
								
								
								<?php if($t_type=="export") { ?>
								
								 <div class="bootstrap-data-table-panel">
                                    <div class="table-responsive">
                                        <table id="bootstrap-data-table-export" data-page-length="100" class="table table-striped table-bordered">
										
								<?php } ?>	
								
								
								<?php if($t_type!="export") { ?>
								
								<div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
										
								<?php } ?>	
										
                                            <thead>
                                                <tr>
												 <th>SL</th>
												 <th>ID</th>
												  <th>Diary of</th>
												  <th>Date</th>
												 <th>Event Name</th>
												
												 <th>Deliverable (Status) </th>
												 
												<th>NE</th>
												<th>SE</th>
												<th>VE</th>
                                                <th>Due</th>
												<th>E.Delivery</th>
												<th>If Late (Reason)</th>
												
													
													
                                                </tr>
                                            </thead>
                                            <tbody>
											
											<?php
                         $sl=0;
						  $prv_id=0;
						
								
	if($sub!=0)	{		

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

$ev_id = $list->id;


                                    $diary_of = $list->booking_name;
                                    $temp_id = $list->temp_id;
									$booking_id = $list->booking_id;
                                    $cell_1 = $list->cell_1;
									$cell_2 = $list->cell_2;
									$event_type = $list->event_type;
									$date = $list->date;
									$date = date("d.m.y", strtotime($date));
									$ph_date = $list->ph_date;
									$ph_package= $list->ph_package;
                                    $ph_editor_name = $list->ph_editor_name;
									$ph_editor = $list->ph_editor;
									
									$ph_sp_editor_name = $list->sp_editor_name;
									$ph_hdd = $list->ph_hdd;
									$ph_rg_edit = $list->ph_rg_edit;
									$ph_sp_edit = $list->ph_sp_edit;
									$ph_remarks = $list->ph_remarks;
									$ph_names = $list->ph_names;
									$ph_status = $list->ph_status;
									
									$vd_date = $list->vd_date;
                                    $vd_editor_name = $list->vd_editor_name;
									$vd_editor = $list->vd_editor;
									$vd_hdd = $list->vd_hdd;
									$vd_remarks = $list->vd_remarks;
									$vd_names = $list->vd_names;
									$vd_status = $list->vd_status;
									$videoincluded = $list->videoincluded;
									$state = $list->state;
									
															
									$ev_total = $list->ev_total;
									$paid = $list->paid;
								    $due = $list->due;
									$in_amount = $list->in_amt;
									$total_charge = $ev_total+$in_amount;
									
									
									
									
									$eventCT = mysqli_query($connection, "SELECT count(id) e_total FROM `events` WHERE `temp_id` = '$temp_id' ");
									$eventCT = mysqli_fetch_object($eventCT);
									$eventCT= $eventCT->e_total;
									
									if($eventCT==1){$star="&#9733;";}
									if($eventCT==2){$star="&#9733;&#9733;";}
									if($eventCT==3){$star="&#9733;&#9733;&#9733;";}
									if($eventCT==4){$star="&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==5){$star="&#9733;&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==6){$star="&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==7){$star="&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==8){$star="&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==9){$star="&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;";}
									if($eventCT==10){$star="&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;&#9733;";}
									
									
									$d_date = $list->d_date;
									$d_date_vd = $list->d_date_vd;
									$actual_d_date = $list->actual_d_date;
									$client_selection_date = $list->client_selection_date;
									$soft_d_date = $list->soft_d_date;
									
									$late_reason = $list->late_reason;
									$song_status = $list->lock_input;

									
									if($song_status>0){
										$song_color="success";
										$song_msg="Song Accepted";
									}
									if($song_status=="0"){
										$song_color="danger";
										$song_msg="Waiting for Song";
									}
									
									
									$normal_edit_st = $list->normal_edit_st;
									$special_edit_st = $list->special_edit_st;
									$photo_dvd_st = $list->photo_dvd_st;
									$video_dvd_st = $list->video_dvd_st;
									$photo_print_st = $list->photo_print_st;
									
									$photo_selection = $list->photo_selection;
									$ph_sp_editor = $list->sp_editor;
									$ph_sp_status = $list->ph_sp_status;
									
									
									if($ph_status==""){
										$ph_color='red';
										$ph_value=0;
										$normal_edit="Normal Edit Pending";
										$sp_color='';
										$sp_value=0;
										$special_edit="";
										
										
										
										
										}
										
									if($ph_status=="checked"){
										$ph_color='blue';
										$ph_value=1;
										$normal_edit="Normal Edit Soft Copy Ready";
										$sp_waiting="no";
										$sp_color='';
										$sp_value='';
										$special_edit="";
										
										
										
										
										}
										
									if($normal_edit_st>1){
										$ph_color='green';
										$ph_value=2;
										$normal_edit="Normal Edit Soft Copy Delivered";
										
										
										$sp_color='orange';
										$sp_value=0;
										$special_edit="Waiting for Client Selection";
										
										if($photo_selection!=""){
										$sp_color='blue';
										$sp_value=1;
										$special_edit="Special Edit Pending";
										}
										
										
										$ph_sp_count=strlen($ph_sp_editor_name);
										
										if($ph_sp_count>1){
										$sp_color='black';
										$sp_value=2;
										$special_edit="Special Edit in Panel";
										}
									
										
									if($ph_sp_status=="checked"){
										$sp_color='green';
										$sp_value=3;
										$special_edit="Special Edit Done";
										}
										
										
										
										
										
										
										}	
										
                                    
									
									
									
										
									

                                    if($video_dvd_st=="0"){
										$vd_dvd_color='red';
										$video_dvd_value=0;
										$video_dvd="Video DVD Pending";
										}
										
										
                                    if($vd_status=="checked"){
										$vd_dvd_color='blue';
										$video_dvd_value=1;
										$video_dvd="Video DVD Ready for Delivery";
										}
										
                                     if($video_dvd_st=="1"){
										$vd_dvd_color='blue';
										$video_dvd_value=1;
										$video_dvd="Video DVD Ready for Delivery";
										}

                                     if($video_dvd_st=="2"){
										$vd_dvd_color='green';
										$video_dvd_value=2;
										$video_dvd="Video DVD Delivered";
										}										
									
									
									if($photo_dvd_st=="0"){
										$ph_dvd_color='red';
										$photo_dvd_value=0;
										$photo_dvd="Photo DVD Pending";
										}
                                    			
                                     if($photo_dvd_st=="1"){
										$ph_dvd_color='blue';
										$photo_dvd_value=1;
										$photo_dvd="Photo DVD Ready for Delivery";
										}

                                     if($photo_dvd_st=="2"){
										$ph_dvd_color='green';
										$photo_dvd_value=2;
										$photo_dvd="Photo DVD Delivered";
										}
									
									
									if($photo_print_st=="0"){
										$ph_print_color='red';
										$photo_print_value=0;
										$photo_print="Photo Print Pending";
										}
                                    			
                                     if($photo_print_st=="1"){
										$ph_print_color='blue';
										$photo_print_value=1;
										$photo_print="Photo Printed Ready For Delivery";
										}

                                     if($photo_print_st=="2"){
										$ph_print_color='green';
										$photo_print_value=2;
										$photo_print="Photo Printed & Delivered";
										}
										if($photo_dvd_value=='2' ||  $photo_print_value=='2' ) { $booking_color="success";} else {$booking_color="";}
										
										if($videoincluded=="checked") {
											if($video_dvd_value=='2' || $photo_dvd_value=='2' ||  $photo_print_value=='2' ) { $booking_color="success";} else {$booking_color="";}
										}
										
	if($video_dvd_value=='2' || $photo_dvd_value=='2' ||  $photo_print_value=='2' ) { $booking_color="success";} else {$booking_color="";}
									
									    if($booking_id==$prv_id){$show_due="none";} else {$show_due="";}
									    $prv_id=$booking_id;
										$sl=$sl+1;
								
                                    
                                   
                                ?>
											
											
											
										
                                                <tr>
												
													<form method="POST" action="">
												
												<td><?php echo $sl;  ?> 
<?php if($r!="1") { ?>                             <a href="delivery_sms.php?id=<?php echo $ev_id;  ?>">	 <i class="ti-email"></i>    </a>
                                                   <a href="inc/mark_delivered.php?ev_id=<?php echo $ev_id;  ?>" onclick="return confirm('Sure to Mark all delivered??')">	 <i class="ti-check-box"></i>    </a>
                                                   <input type="hidden" name="ev_id" value="<?php echo $ev_id;  ?>">
													<button class="info" type="submit" name="submit"> <i class="ti-save-alt"></i> </button>
<?php		} ?>

												</td>
													<td> <font size="2"> <a href="booking_details.php?id=<?php echo $temp_id;  ?>" target="_blank">
												<span class="badge badge-<?php echo $booking_color; ?>"> <?php echo $booking_id;  ?></span>	
													</a></font></td>
												  <td> <font size="2"> <?php echo $diary_of;  ?> <?php echo " ".$star; ?> <br> <?php echo $cell_1.",</br>".$cell_2.",</br>PG:".$ph_names.",</br>VG:".$vd_names.",</br>".$ph_package; ?></font> <span class="badge badge-info"></span> </td>
												<td> <font size="2"><?php echo $date;  ?></font></td>
												  <td> <font size="2"> <?php echo $event_type;  ?> </font>  </td>
											
											<td>
											
											<?php if($r!="1") { ?>
											
											
											<?php if($videoincluded=="checked") { ?>
											<font size="2">	 <span class="badge badge-<?php echo $song_color; ?>"> <?php echo $song_msg; ?></span>	 </font> <br>
											<?php		} ?>
											
											
											<font size="2" color="<?php echo $ph_color; ?>">
											<select name="normal_edit_st" style="width: 240px !important; min-width: 240px; max-width: 240px;">
											<option value="<?php echo $ph_value; ?>"><?php echo $normal_edit; ?></option>
											<option value="0">Normal Edit Pending </option>
											<option value="2">Normal Edit Soft Copy Delivered </option>
											</select>
											</font> <br>
											
											<font size="2" color="<?php echo $sp_color; ?>">
											<select name="special_edit_st" style="width: 240px !important; min-width: 240px; max-width: 240px;">
                                            <option value="<?php echo $ph_sp_value; ?>"><?php echo $special_edit; ?></option>
										
											</select>
											</font> <br>
											
											<?php if($videoincluded=="checked") { ?>
											<font size="2" color="<?php echo $vd_dvd_color; ?>">
											<select name="video_dvd_st" style="width: 240px !important; min-width: 240px; max-width: 240px;">
                                            <option value="<?php echo $video_dvd_value; ?>"><?php echo $video_dvd; ?></option>
											<option value="0">Video DVD Pedning </option>
											<option value="1">Video DVD Ready For Delivery </option>
											<option value="2">Video DVD Delivered </option>
											</select>
											</font> <br>
							<?php		} ?>
											<font size="2" color="<?php echo $ph_dvd_color; ?>">
											<select name="photo_dvd_st" style="width: 240px !important; min-width: 240px; max-width: 240px;">
                                            <option value="<?php echo $photo_dvd_value; ?>"><?php echo $photo_dvd; ?></option>
											<option value="0">Photo DVD Pedning </option>
											<option value="1">Photo DVD Ready For Delivery </option>
											<option value="2">Photo DVD Delivered </option>
											</select>
											</font> <br>
											
											<font size="2" color="<?php echo $ph_print_color; ?>">
											<select name="photo_print_st" style="width: 240px !important; min-width: 240px; max-width: 240px;">
                                            <option value="<?php echo $photo_print_value; ?>"><?php echo $photo_print; ?></option>
											<option value="0">Photo Printing Pedning </option>
											<option value="1">Photo Printed Ready For Delivery </option>
											<option value="2">Photo Printed & Delivered </option>
											</select>
											</font> <br>
											
											
											
											
											<?php		} ?>
											
												<?php if($r=="1") { ?>
												<font size="2">
												<?php if($videoincluded=="checked") { ?>
												<?php echo $song_msg; ?>;<br>
													<?php		} ?>
												
												
												<?php echo $normal_edit; ?> ;<br>
												<?php echo $special_edit; ?> ;<br>
												
												<?php if($videoincluded=="checked") { ?>
												<?php echo $video_dvd; ?>;<br>
													<?php		} ?>
												<?php echo $photo_dvd; ?> ;<br>
												<?php echo $photo_print; ?> ;<br>
												</font>
											<?php		} ?>
											</td>
											     
												<td> <?php echo $ph_editor_name;  ?> </td>
											
											
												<td> <?php echo $ph_sp_editor_name;  ?> </td>
												
												
													<td> 
												<?php if($videoincluded=="checked") { ?>
												
												<?php echo $vd_editor_name;  ?>
									
							                       <?php		} ?>
												
												
											    	</td>
                                               <td> <?php if($show_due!="none") { ?> <font size="2" color="blue">Event: <?php echo $ev_total; ?> Invoice: <?php echo $in_amount; ?> Total: <?php echo $total_charge; ?> Due: <?php echo $due; ?> </font> <?php } ?> </td>
												
												 <td> 
			<?php if($r!="1") { ?>

                                                <font size="2">  Soft Delivery </font></br>
												 <input type="date" name="soft_d_date" value="<?php echo $soft_d_date; ?>" /> </br>
												<font size="2"> Client Selection </font></br>
											      <input type="date" name="client_selection_date"  value="<?php echo $client_selection_date; ?>" /> </br>
												<font size="2">  Expected Delivery (ph) </font></br>
												 <input type="date" name="d_date" value="<?php echo $d_date; ?>" /> </br>
												 <font size="2">  Expected Delivery (vd) </font></br>
												 <input type="date" name="d_date_vd" value="<?php echo $d_date_vd; ?>" /> </br>
												<font size="2"> Full Delivery Date </font></br>
											      <input type="date" name="actual_d_date"  value="<?php echo $actual_d_date; ?>" /> </br>
					<?php } ?>								 
							<?php if($r=="1") { ?>	 <?php echo $d_date; ?>

	<?php } ?>
							
												 
												 </td>
												  <td> <?php echo $late_reason; ?>
												  
			<?php if($r!="1") { ?>									  
												  
												  
<a href="#" onclick="reasonEdit('<?php echo $ev_id; ?>');" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">Edit</a>

			<?php } ?>
												  </td>
														
													 </form>	 
													
													
                                                </tr>
                                              
												
	<?php } } ?>			
												
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
								
								
								
								
								
								<?php
                   }
					?>
								
								
								
                            </div>
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                    </div>

                                   


							 </div> </div>
							
                        </div>
				
				
                        <!-- /# column -->
                        
                    </div>
				
				
				
				
				
                    <!-- /# row -->
                     <?php include("footer.php"); ?>
                </section>
            </div>
        </div>
    </div>
	
	
	<script type="text/javascript">
 function reasonEdit(ev_id) {
        $.ajax({
            type: "POST",
            url: 'inc/ev_reason.php',
			error: function (request, error) {
            console.log(arguments);
            alert(" Can't do because: " + error);
           },
            data:{
                    ev_id:ev_id
		 },
            success:function(data){
                $("#reason").html(data);

            }
        });
        
    }	       
 
	
</script>
			
			
			
			
<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>

    </div>
    <script src="assets/js/lib/jquery.min.js"></script>
    <!-- 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 -->
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <!-- bootstrap -->
   
    <script src="assets/js/scripts.js"></script>
	
	 <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.dataTables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>

	
	<script>
        $(document).ready(function() {
            $('.select2').select2();
        });
    </script>

		 <script src="assets/js/lib/select2/select2.full.min.js"></script>


</body>

</html>