<?php
session_start();
include "connect.php";



		$id = intval($_REQUEST['id']);
		
		
		

?>

						<div class="table-responsive">
														<!--begin::Table-->
														<table class="table align-middle table-row-dashed fs-6 gy-5 mb-0">
															<!--begin::Table head-->
															<thead>
																<tr class="text-start text-gray-400 fw-bold fs-7 text-uppercase gs-0">
																	 <th>Sr No.
                            </th>
                            <th>Service
                            </th>
							<th>Company
                            </th>
							<th>Bank
                            </th>
                            <th>Received  Amount
                            </th>
                            <th>Payment Date
                            </th>
                            <th>Payment Mode
                            </th>
							 <th>Payment Mode Charge
                            </th>
							<th>Final Payment Amount
                            </th>
							
							<th>Payment Proof
                            </th>
                            <th>Remarks
                            </th>
							<th class="min-w-100px">Addedby</th>
<th class="min-w-100px">Addedon</th><th class="min-w-100px">Payment Recevied by</th>

							
																	
																	
																</tr>
															</thead>
															<!--end::Table head-->
															<!--begin::Table body-->
															<tbody class="fw-semibold text-gray-600">
															<?php
															$i=1;
															$tt1=0;
															$evepay = "select * from res_payments_detail where isdid=$id";
															$repay = mysqli_query($conn, $evepay);
															$i=1;
															while($rtpay = mysqli_fetch_assoc($repay))
															{
															$pddid=$rtpay['pddid'];
															$isdid=$rtpay['isdid'];
															$imid=$rtpay['imid'];
															$companymid=$rtpay['companymid'];
															$bankmid=$rtpay['bankmid'];
															$pddocname=$rtpay['pddocname'];
															$paymode=$rtpay['paymode'];
															$paidamount=$rtpay['paidamount'];
															$pdstatus=$rtpay['pdstatus'];
															if($rtpay['paydate'] == '0000-00-00')
															{
																$paydate='';
															}else{
															$paydate=date("d-m-Y", strtotime($rtpay['paydate']));
															}
															 $eve25 = "select *  from res_paymentmode_master where paymentmodemid='$paymode'";
															$re25 = mysqli_query($conn, $eve25);
															$paymentmodename='';
															while($rt25 = mysqli_fetch_assoc($re25))
															{
															$paymentmodename=$rt25['paymentmodename'];
															 $pmodechargetype=$rt25['pmodechargetype'];
															$pmodecharge=$rt25['pmodecharge'];
															}
															$paymodec = $pmodecharge ." (".$pmodechargetype.")";
															$pfinalpayamount=$rtpay['pfinalpayamount'];
															
															
															
															$payremark=$rtpay['payremark'];
															$pdaddedon=date("d-m-Y",strtotime($rtpay['pdaddedon']));
$pdaddedby=$rtpay['pdaddedby'];$pdupdatedon=date("d-m-Y",strtotime($rtpay['pdupdatedon']));
$pdupdatedby=$rtpay['pdupdatedby'];

$ufullname='';
$utype='';
$evea1 = "select ufullname,utype from res_user_master where umid=$pdaddedby";
$rea1 = mysqli_query($conn, $evea1);
if(mysqli_num_rows($rea1) > 0)
{
	while($rta1 = mysqli_fetch_assoc($rea1))
	{
		$ufullname=$rta1['ufullname'];
		$utype=$rta1['utype'];
	}
}

$ufullname1='';
$utype1='';
if($companymid != 0)
{
$evea1 = "select ufullname,utype from res_user_master where umid=$pdupdatedby";
$rea1 = mysqli_query($conn, $evea1);
if(mysqli_num_rows($rea1) > 0)
{
	while($rta1 = mysqli_fetch_assoc($rea1))
	{
		$ufullname1=$rta1['ufullname'];
		$utype1=$rta1['utype'];
	}
}
}else{
$pdupdatedon='';
}
															$total=0;
															
															$eve21 = "select sum(paidamount) as total from res_payments_detail where imid=$imid";
															$re21 = mysqli_query($conn, $eve21);
															$total=0;
															while($rt21 = mysqli_fetch_assoc($re21))
															{
															$total=$rt21['total'];
															}
															$companyname='';
															$eve22 = "select companyname  from res_company_master where companymid=$companymid";
															$re22 = mysqli_query($conn, $eve22);
															
															while($rt22 = mysqli_fetch_assoc($re22))
															{
															$companyname=$rt22['companyname'];
															}
															
															$eve23 = "select bankname  from res_bank_master where bankmid=$bankmid";
															$re23= mysqli_query($conn, $eve23);
															$bankname='';
															while($rt23 = mysqli_fetch_assoc($re23))
															{
															$bankname=$rt23['bankname'];
															}
															
															
															$eve212="select * from res_inquiryservice_detail where  res_inquiryservice_detail.isdid=$isdid";
															$re212=mysqli_query($conn,$eve212);
															$servicename="";
															while($rt212= mysqli_fetch_assoc($re212))
															{
																$ptype=$rt212['ptype'];
															$packagename='';
								if($ptype == 'Branch' || $ptype == 'Country')
								{
									$packagemid=$rt212['packagemid'];
									 $evea3 = "select packagename from res_package_master where packagemid=$packagemid";
									$rea3 = mysqli_query($conn, $evea3);
									if(mysqli_num_rows($rea3) > 0)
									{
									while($rta3 = mysqli_fetch_assoc($rea3))
									{
										$packagename=$rta3['packagename'];
										
									}
									}
								}else if($ptype == 'Application'){
									$clgappmid=$rt212['linkmid'];
									$eve23 = "select * from res_course_master,res_collegeapp_master where res_collegeapp_master.coursemid = res_course_master.coursemid  and  res_collegeapp_master.imid=$imid and  res_collegeapp_master.clgappmid=$clgappmid";
$cmname='';
$coursename="";
									$re23 = mysqli_query($conn, $eve23);

									while($rt23 = mysqli_fetch_assoc($re23))

									{

									$collegemid=$rt23['collegemid'];
									$collegemid=$rt23['collegemid'];
									$cnmid=$rt23['cnmid'];
									$clgappmid=$rt23['clgappmid'];
									
					$eve55= "select * from   res_coursename_master where cnmid=$cnmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$coursename=$rt55['coursename'];
						
					}
					
						$eve55= "select * from   res_college_master where collegemid=$collegemid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$cmname=$rt55['cmname'];
						
					}
									

								}
								$packagename = $cmname."-".$coursename." application";
								}else if($ptype == 'Book Lost'){
									$bookmid=$rt212['linkmid'];
									$eve78 = "select bookname,bookprice from res_book_master where  bookmid=$bookmid";
									$re78 = mysqli_query($conn, $eve78);
									if(mysqli_num_rows($re78) > 0)
									{
										while($rt78 = mysqli_fetch_assoc($re78))
										{
											$bookname=$rt78['bookname'];
											
											
										}
									}
									$packagename = $bookname." Lost";
								}else if($ptype == 'College Admission'){
									$admid=$rt212['linkmid'];
										$eve23 = "select * from res_course_master,res_admission_master where res_admission_master.coursemid = res_course_master.coursemid  and  res_admission_master.imid=$imid and  res_admission_master.admid=$admid";

									$re23 = mysqli_query($conn, $eve23);

									while($rt23 = mysqli_fetch_assoc($re23))

									{

									$collegemid=$rt23['collegemid'];
									$collegemid=$rt23['collegemid'];
									$cnmid=$rt23['cnmid'];
									$admid=$rt23['admid'];
									$coursename="";
					$eve55= "select * from   res_coursename_master where cnmid=$cnmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$coursename=$rt55['coursename'];
						
					}
						$eve55= "select * from   res_college_master where collegemid=$collegemid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$cmname=$rt55['cmname'];
						
					}
									

								}
								$packagename = $cmname."-".$coursename." Admission";
								}
								
															}
															$evepd = "select *, sum(servicefees) as totalamount from res_inquiryservice_detail where imid=$imid";
															$repd = mysqli_query($conn, $evepd);
															$servicefees=0;
															$totalamount=0;
															while($rtpd = mysqli_fetch_assoc($repd))
															{
															$servicefees=$rtpd['servicefees'];
															$totalamount=$rtpd['totalamount'];
															}
															$tt1=$totalamount-$total;
															$payrecived='';
															if($rtpay['pdstatus'] != 'Recevied' && $rtpay['pdstatus'] != 'Approved')
															{
															$payrecived = ' <a href="#" data-bs-toggle="modal" data-bs-target="#view-modal2" class="badge badge-primary"  data-id="'.$pddid.'" id="getUser2">Pending</a>';
															}
															?>
																<tr>
																	
																	 <td>
                              <?php echo $i++;?>
                            </td>
                            <td>
                              <?php echo $packagename;?>
                            </td>
							<td>
                              <?php echo $companyname;?>
                            </td> 
							<td>
                              <?php echo $bankname;?>
                            </td>
                            <td>
                              <?php echo $paidamount;?>
                            </td>
                            <td>
                              <?php echo $paydate;?>
                            </td>
                            <td>
                              <?php echo $paymentmodename;?>
                            </td>
							  <td>
                              <?php echo $paymodec;?>
                            </td>
							   <td>
                              <?php echo $pfinalpayamount;?>
                            </td>
							  <td>
							  <?php if($pdstatus == 'Approved') {?>
                              <a href='./paymentreceipt/<?php echo $pddid.".pdf";?>' target="_blank">Download Now
                              </a>
							  <?php } ?>
                            </td>
                            <td>
                              <?php echo $payremark;?>
                            </td>
							<td><?php echo $ufullname." (".$utype.")"; ?></td>
<td><?php echo $pdaddedon; ?></td>
<td><?php echo $ufullname1." (".$utype1.") - ".$pdupdatedon.""; ?></td>

							
							
																	
																</tr>
															<?php } ?>
																</tbody>
															<!--end::Table head-->
														</table>
																			
