<?php  session_start();

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

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



$flag= "";


if ($flag == "success") {
	$msg = "Login Successful";
}






 ?>





<?php  include 'header.php';

include("user.php");







	
  ?>








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

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

<body>

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

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


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

            <?php 
			 	}
			 	  ?>


				




<?php



$bookingtSQL = mysqli_query($connection, "select f1.* , f2.paid from (SELECT v1.*,v2.title as ref_name from (SELECT t1.*,t2.name ev_type FROM `bookings` as t1 left join booking_types as t2 on t1.event_type=t2.id where t1.id='$temp_id') as v1 left join ref as v2 on v1.ref=v2.id) as f1 left join (SELECT temp_booking_id, sum(amount) as paid FROM `transactions` GROUP BY temp_booking_id) as f2 on f1.id=f2.temp_booking_id ");
$list= mysqli_fetch_object($bookingtSQL);
									
                                    $idn = $list->id;
									 $name = $list->name;
									$cell_1 = $list->cell_1;
									$cell_2 = $list->cell_2;
									 $email = $list->email;
									  $address = $list->address;
									 $ev_type = $list->ev_type;
									 
								   
									  $fb= $list->fb;  
									    $ref= $list->ref_name;  
										 $groom_name= $list->groom_name;  
										  $groom_fb= $list->groom_fb;  
										   $groom_email= $list->groom_email;  
										    $groom_father= $list->groom_father;  
											 $groom_mother= $list->groom_mother;  
											  $groom_brother= $list->groom_brother;  
											   $groom_sister= $list->groom_sister;  
											   $bride_name= $list->bride_name;  
											    $bride_fb= $list->bride_fb;  
										   $bride_email= $list->bride_email;  
										    $bride_father= $list->bride_father;  
											 $bride_mother= $list->bride_mother;  
											  $bride_brother= $list->bride_brother;  
											  $bride_sister= $list->bride_sister; 


                               
$booking_id = $list->booking_id;
$booking_name = $list->booking_name;
$additional_notes = $list->additional_notes;
$vas = $list->vas;


$added_at = $list->added_at;	
$updated_at = $list->updated_at;
													  
$discount = $list->discount;
$pkg_charge=0;
$bookingtSQL = mysqli_query($connection, "SELECT id, IFNULL(ev_value,'0') as ev_value FROM `events` WHERE `temp_id` = '$temp_id' ");
 while ($listEV = mysqli_fetch_object($bookingtSQL)) {
		 $ev_value=$listEV->ev_value;
		$pkg_charge=$pkg_charge+$ev_value;
	 }
$paid=0;	 
$bookingtSQL = mysqli_query($connection, "SELECT * FROM `transactions` WHERE `temp_booking_id` = '$temp_id' AND type=1 ");
 while ($listTR = mysqli_fetch_object($bookingtSQL)) {
		 $tramount=$listTR->amount;
		$paid=$paid+$tramount;
	 }
                         
$total_charge=round($pkg_charge-(($pkg_charge*$discount)/100));



$due=$total_charge-$paid;
	
$invSQL = mysqli_query($connection, "select h1.customer_id, sum(h1.inv_amount)-SUM(h1.discount) inv_amount, sum(paid) paid from (select t1.*,IFNULL(t4.paid,0) paid,(t1.inv_amount-IFNULL(t4.paid,0) ) as due, t2.id, t2.date,t2.discount, t2.customer_id,t2.notes, t2.added_at, t2.updated_at 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 (SELECT inv_id, sum(amount) paid FROM `transactions` where type=2 GROUP by inv_id) as t4 on t1.invoice_id=t4.inv_id) as h1 where h1.customer_id='$temp_id' ");
$invSQL_exist = mysqli_num_rows($invSQL);	
$inv_list= mysqli_fetch_object($invSQL);											  
$inv_amount=$inv_list->inv_amount;
$inv_paid=$inv_list->paid;	


?>





 <div class="panel panel-warning m-t-15">
                                            <div class="panel-heading">Booking Details</div>
                                            <div class="panel-body"> 



<div class="card-body">
                                    <div class="table-responsive">
									
							
									
                                        <table class="table table-hover ">
                                           
                                            <tbody>
											
											
											
                                                <tr>
                                                    <th scope="row">Client Name:</th>
                                                    <td><?php echo $name;  ?></td>
													 <td>Booking ID:</td>
                                                    <td><?php echo $booking_id;  ?></td>
                                                     <td></td>
													  <td></td>
                                                </tr>
                                                 <tr>
                                                    <th scope="row">Email:</th>
                                                    <td><?php echo $email;  ?></td>
													 <td>Primary Cell:</td>
                                                    <td><?php echo $cell_1;  ?></td>
                                                     <td></td>
													  <td></td>
                                                </tr>
												<tr>
                                                    <th scope="row">Address:</th>
                                                    <td><?php echo $address;  ?></td>
													  <td>Alternative Cell:</td>
                                                    <td><?php echo $cell_2;  ?></td>
                                                     <td></td>
													  <td></td>
                                                </tr>
												<tr>
                                                    <th scope="row">Facebook:</th>
                                                    <td><?php echo $fb;  ?></td>
													 <td>Diary of:</td>
                                                   <td><?php echo $booking_name;  ?></td>
                                                     <td></td>
													 <td></td>
                                                </tr>
												<tr>
                                                    <th scope="row">Groom:</th>
                                                    <td><?php echo $groom_name;  ?></td>
													 <td>Bride:</td>
                                                    <td><?php echo $bride_name;  ?></td>
                                                     <td></td>
													 <td></td>
                                                </tr>
												
												
												
											
												
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
								</div>
                                </div>
								<div class="row">
							
				        <div class="col-lg-4">
						
						
						<div class="card bg-warning">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Total</div>
                                        
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $total_charge;  ?></font></span>
									
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						
						 
						  <div class="col-lg-4">
						
						
						<div class="card bg-success">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Paid</div>
                                          
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $paid;  ?></font></span>
											
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						 
						 
						 
						 
						   <div class="col-lg-4">
						
						
						<div class="card bg-danger">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Due</div>
                                         
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $due;  ?></font></span>
										
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						 
						 
						 
						  </div>
						  
						  
						  <?php
						  if($inv_amount>0){ ?>
							
<div class="row">
							
				        <div class="col-lg-4">
						
						
						<div class="card bg-warning">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Invoice Total</div>
                                        
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $inv_amount;  ?></font></span>
									
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						
						 
						  <div class="col-lg-4">
						
						
						<div class="card bg-success">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Invoice Paid</div>
                                          
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $inv_paid;  ?></font></span>
											
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						 
						 
						 
						 
						   <div class="col-lg-4">
						
						
						<div class="card bg-danger">
                                <div class="stat-widget-nine">
                                   
                                    <div class="google-plus-card horizontal">
                                        <div class="stat-content m-t-13 dib">
                                            <div class="stat-text">Invoice Due</div>
                                         
                                        </div>
                                        <div class="all-like dib">
                                            <span class="like-count m-t-12"><font size="3">&nbsp;&nbsp;&nbsp;<?php echo $inv_amount-$inv_paid;  ?></font></span>
										
                                        </div>
                                    </div>
                                </div>
                            </div>
						
						 </div>	
						 
						 
						 
						  </div>

							
						<?php  }
						  ?>
						  
						  
						  
						  
						  
						  
						  
						  
						  
						  
						  
						  
						  <div class="panel panel-warning m-t-15">
                                            <div class="panel-heading">Previous Payments</div>
                                            <div class="panel-body">                    
							
				 <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-hover ">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Date</th>
                                                    <th>Payment</th>
                                                    
                                                  
                                                </tr>
                                            </thead>
                                            <tbody>
												<?php
                         $sl=0;
						$sqlSelectedLG = "select f1.* , f2.name from transactions as f1 left join users as f2 on f1.updated_by = f2.id where temp_booking_id = '$temp_id' order by f1.date desc";

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

                                    
                                   
                                    $tr_id = $list->id;
								    $tr_date = $list->date;
								    $sl=$sl+1;
									$amount = $list->amount;
									$updated_by = $list->name;   
										 	
											   
                                  
								
                                    
                                   
                                ?>
									
											
											
											
                                                <tr>
                                                    <th scope="row"><?php echo $sl;  ?></th>
                                                    <td><?php echo $tr_date;  ?></td>
                                                    <td><span class="badge badge-primary"><?php echo $amount;  ?></span></td>
                                                   
                                                   
                                                </tr>
                                              
<?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
								
								
								</div>
								</div>



			
			
				
				
                    
                 
					
					
					 
					
					
					
					
					
					
					
                    <?php include("footer.php"); ?>
                </section>
            </div>
        </div>
    </div>
   
 
   
   
    <!-- jquery vendor -->
   
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    
    <!-- bootstrap -->

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


    <script src="assets/js/lib/weather/jquery.simpleWeather.min.js"></script>
    <script src="assets/js/lib/weather/weather-init.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
    <script src="assets/js/lib/chartist/chartist.min.js"></script>
    <script src="assets/js/lib/chartist/chartist-init.js"></script>
    <script src="assets/js/lib/sparklinechart/jquery.sparkline.min.js"></script>
    <script src="assets/js/lib/sparklinechart/sparkline.init.js"></script>
    <script src="assets/js/lib/owl-carousel/owl.carousel.min.js"></script>
    <script src="assets/js/lib/owl-carousel/owl.carousel-init.js"></script>
    <script src="assets/js/scripts.js"></script>
    <!-- scripit init-->

	
</body>

</html>