<?php
session_start(); 
		/*User Add Data page */

	include("connect.php");
	include("removespecial.php");
	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	$ftime=0;
	$ttime=23;
	$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	$brmid=$_SESSION['linkarisebranchid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];
	 $lacrmcmpstate = $_SESSION['linkarisecmpstate'];
	
				date_default_timezone_set("Asia/Kolkata");
				$mdate1= date('Y-m-d H:i:s');
				$mdate= date('d-m-Y');
				
				$par1 = $_SESSION['linkariseumobile'];
				$ipaddress = "";
	
				if (getenv('HTTP_CLIENT_IP'))
					$ipaddress = getenv('HTTP_CLIENT_IP');
				else if(getenv('HTTP_X_FORWARDED_FOR'))
					$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
				else if(getenv('HTTP_X_FORWARDED'))
					$ipaddress = getenv('HTTP_X_FORWARDED');
				else if(getenv('HTTP_FORWARDED_FOR'))
					$ipaddress = getenv('HTTP_FORWARDED_FOR');
				else if(getenv('HTTP_FORWARDED'))
					$ipaddress = getenv('HTTP_FORWARDED');
				else if(getenv('REMOTE_ADDR'))
					$ipaddress = getenv('REMOTE_ADDR');
				else
					$ipaddress = 'UNKNOWN';
				
				$userserver=$_SERVER['HTTP_USER_AGENT'];
				$eve1 = "insert into res_user_log (lid,mobile,lastupdatedtime,pagename,taskname,ipaddress,useragentdetail) values(NULL,'$par1','$mdate1','User','Add User','$ipaddress','$userserver')";
				$re1 = mysqli_query($conn, $eve1);
	
		$partymid=$_GET['partymid'];
	$_SESSION['partymid']=$_GET['partymid'];	
	
?>
<!DOCTYPE html>
<!--
Author: Keenthemes
Product Name: Metronic - Bootstrap 5 HTML, VueJS, React, Angular. Laravel, Asp.Net Core, Ruby on Rails, Spring Boot, Blazor, Django, Express Node.js & Flask Admin Dashboard Theme
Purchase: https://1.envato.market/EA4JP
Website: http://www.keenthemes.com
Contact: support@keenthemes.com
Follow: www.twitter.com/keenthemes
Dribbble: www.dribbble.com/keenthemes
Like: www.facebook.com/keenthemes
License: For each use you must have a valid license purchased only from above link in order to legally use the theme for your project.
-->
<html lang="en">
	<!--begin::Head-->
	<head>
		<title>Customer Payment Add</title>
		<meta charset="utf-8" />
		<meta name="description" content="The most advanced Bootstrap Admin Theme on Themeforest trusted by 100,000 beginners and professionals. Multi-demo, Dark Mode, RTL support and complete React, Angular, Vue, Asp.Net Core, Rails, Spring, Blazor, Django, Flask & Laravel versions. Grab your copy now and get life-time updates for free." />
		<meta name="keywords" content="metronic, bootstrap, bootstrap 5, angular, VueJs, React, Asp.Net Core, Rails, Spring, Blazor, Django, Flask & Laravel starter kits, admin themes, web design, figma, web development, free templates, free admin themes, bootstrap theme, bootstrap template, bootstrap dashboard, bootstrap dak mode, bootstrap button, bootstrap datepicker, bootstrap timepicker, fullcalendar, datatables, flaticon" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<meta property="og:locale" content="en_US" />
		<meta property="og:type" content="article" />
		<meta property="og:title" content="Metronic - Bootstrap 5 HTML, VueJS, React, Angular. Laravel, Asp.Net Core, Ruby on Rails, Spring Boot, Blazor, Django, Express Node.js & Flask Admin Dashboard Theme" />
		<meta property="og:url" content="https://keenthemes.com/metronic" />
		<meta property="og:site_name" content="Keenthemes | Metronic" />
		<link rel="canonical" href="https://preview.keenthemes.com/metronic8" />
		<link rel="shortcut icon" href="assets/media/logos/favicon.ico" />
		<!--begin::Fonts(mandatory for all pages)-->
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700" />
		<!--end::Fonts-->
		<!--begin::Vendor Stylesheets(used for this page only)-->
		<link href="assets/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />
		<!--end::Vendor Stylesheets-->
		<!--begin::Global Stylesheets Bundle(mandatory for all pages)-->
		<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
		<link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
		<!--end::Global Stylesheets Bundle-->
	</head>
	<!--end::Head-->
	<!--begin::Body-->
<body id="kt_body" data-kt-app-layout="dark-sidebar" data-kt-app-header-fixed="true" data-kt-app-sidebar-enabled="true"  data-kt-app-sidebar-hoverable="true" data-kt-app-sidebar-push-header="true" data-kt-app-sidebar-push-toolbar="true" data-kt-app-sidebar-push-footer="true" data-kt-app-toolbar-enabled="true"  class="app-default">
		<!--begin::Theme mode setup on page load-->
		<script>var defaultThemeMode = "light"; var themeMode; if ( document.documentElement ) { if ( document.documentElement.hasAttribute("data-theme-mode")) { themeMode = document.documentElement.getAttribute("data-theme-mode"); } else { if ( localStorage.getItem("data-theme") !== null ) { themeMode = localStorage.getItem("data-theme"); } else { themeMode = defaultThemeMode; } } if (themeMode === "system") { themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } document.documentElement.setAttribute("data-theme", themeMode); }</script>
		<!--end::Theme mode setup on page load-->
		<!--begin::Main-->
		<!--begin::Root-->
		<div class="d-flex flex-column flex-root">
			<!--begin::Page-->
			<div class="page d-flex flex-row flex-column-fluid">
				<!--begin::Aside-->
				<?php include('sidebar.php'); ?>
				<!--end::Aside-->
				<!--begin::Wrapper-->
				<div class="wrapper d-flex flex-column flex-row-fluid" id="kt_wrapper">
					<!--begin::Header-->
					<div id="kt_header" style="" class="header align-items-stretch">
						<!--begin::Container-->
						<div class="container-fluid d-flex align-items-stretch justify-content-between">
							<!--begin::Aside mobile toggle-->
							<div class="d-flex align-items-center d-lg-none ms-n3 me-1" title="Show aside menu">
								<div class="btn btn-icon btn-active-color-primary w-40px h-40px" id="kt_aside_toggle">
									<!--begin::Svg Icon | path: icons/duotune/abstract/abs015.svg-->
									<span class="svg-icon svg-icon-1">
										<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
											<path d="M21 7H3C2.4 7 2 6.6 2 6V4C2 3.4 2.4 3 3 3H21C21.6 3 22 3.4 22 4V6C22 6.6 21.6 7 21 7Z" fill="currentColor" />
											<path opacity="0.3" d="M21 14H3C2.4 14 2 13.6 2 13V11C2 10.4 2.4 10 3 10H21C21.6 10 22 10.4 22 11V13C22 13.6 21.6 14 21 14ZM22 20V18C22 17.4 21.6 17 21 17H3C2.4 17 2 17.4 2 18V20C2 20.6 2.4 21 3 21H21C21.6 21 22 20.6 22 20Z" fill="currentColor" />
										</svg>
									</span>
									<!--end::Svg Icon-->
								</div>
							</div>
							<!--end::Aside mobile toggle-->
							<!--begin::Mobile logo-->
							<div class="d-flex align-items-center flex-grow-1 flex-lg-grow-0">
								<a href="../../demo4/dist/index.html" class="d-lg-none">
									<img alt="Logo" src="assets/media/logos/demo4-mobile.svg" class="h-25px" />
								</a>
							</div>
							<!--end::Mobile logo-->
							<div class="d-flex align-items-center" id="kt_header_wrapper">
								<!--begin::Page title-->
								<div class="page-title d-flex flex-column align-items-start justify-content-center flex-wrap me-lg-20 pb-5 pb-lg-0" data-kt-swapper="true" data-kt-swapper-mode="prepend" data-kt-swapper-parent="{default: '#kt_content_container', lg: '#kt_header_wrapper'}">
									<!--begin::Heading-->
									<h1 class="text-dark fw-bold my-1 fs-3 lh-1">Add Customer Payment</h1>
									<!--end::Heading-->
									<!--begin::Breadcrumb-->
									<ul class="breadcrumb fw-semibold fs-8 my-1">
										<li class="breadcrumb-item text-muted">
											<a href="../../demo4/dist/index.html" class="text-muted">Home</a>
										</li>
										<li class="breadcrumb-item text-muted">Sales Management</li>
										<li class="breadcrumb-item text-muted">Customer Payment</li>
									</ul>
									<!--end::Breadcrumb-->
								</div>
								<!--end::Page title=-->
							</div>
							<!--begin::Wrapper-->
							<?php include('header.php'); ?>
							<!--end::Wrapper-->
						</div>
						<!--end::Container-->
					</div>
					<!--end::Header-->
					<!--begin::Content-->
					<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
						<!--begin::Container-->
						<div class="container-xxl" id="kt_content_container">
							<!--begin::Contacts App- Add New Contact-->
							<div class="row g-7">
							<div class="col-xl-2">
							</div>
								<!--begin::Content-->
									<div class="col-xl-12">
									<!--begin::Contacts-->
									<div class="card card-flush h-lg-100" id="kt_contacts_main">
										<!--begin::Card header-->
										<div class="card-header pt-7" id="kt_chat_contacts_header">
											<!--begin::Card title-->
											<div class="card-title">
												<!--begin::Svg Icon | path: icons/duotune/communication/com005.svg-->
												<span class="svg-icon svg-icon-1 me-2">
													<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
														<path d="M20 14H18V10H20C20.6 10 21 10.4 21 11V13C21 13.6 20.6 14 20 14ZM21 19V17C21 16.4 20.6 16 20 16H18V20H20C20.6 20 21 19.6 21 19ZM21 7V5C21 4.4 20.6 4 20 4H18V8H20C20.6 8 21 7.6 21 7Z" fill="currentColor" />
														<path opacity="0.3" d="M17 22H3C2.4 22 2 21.6 2 21V3C2 2.4 2.4 2 3 2H17C17.6 2 18 2.4 18 3V21C18 21.6 17.6 22 17 22ZM10 7C8.9 7 8 7.9 8 9C8 10.1 8.9 11 10 11C11.1 11 12 10.1 12 9C12 7.9 11.1 7 10 7ZM13.3 16C14 16 14.5 15.3 14.3 14.7C13.7 13.2 12 12 10.1 12C8.10001 12 6.49999 13.1 5.89999 14.7C5.59999 15.3 6.19999 16 7.39999 16H13.3Z" fill="currentColor" />
													</svg>
												</span>
												<!--end::Svg Icon-->
												<h2>Add Customer Payment</h2>
											</div>
											<!--end::Card title-->
										</div>
										<!--end::Card header-->
										<!--begin::Card body-->
										<div class="card-body pt-5">
										<?php
						//$partymid="";
						$receiptrefrenceid="";
						$receiptdate="";
						$receiptamount="";
						$receiptmode="";
						$receiptdetail="";
						$invoicenetamount=0;
						$pendingamount=0;
						
						if(isset($_GET['paymentinmid']))
					{
						$paymentinmid=(int)mysqli_real_escape_string($conn,$_GET['paymentinmid']);
						$eve = "select * from res_paymentin_master where paymentinmid=$paymentinmid and cmpmid=$cmpmid";
						$re = mysqli_query($conn, $eve);
						while($rt = mysqli_fetch_assoc($re))
						{
							$partymid=$rt['partymid'];
							$receiptmode=removespecialchar($rt['receiptmode']);
							$receiptrefrenceid=$rt['receiptrefrenceid'];
							$receiptamount=$rt['receiptamount'];
							$receiptdetail=removespecialchar($rt['receiptdetail']);
						}
						}
						
						
					?>
											<!--begin::Form-->
											<form id="kt_ecommerce_settings_general_form" class="form" action="pendingpaymentreceiptadd2.php" method="POST" enctype="multipart/form-data">
													
												<!--begin::Row-->
												<div class="row row-cols-1 row-cols-sm-2 rol-cols-md-1 row-cols-lg-2">
												
												<!--begin::Col-->
													<div class="col">
														<!--begin::Input group-->
															<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="required">Customer Name</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
																<?php 
										 $eve3 = "select * from res_party_master where partymid='$partymid' and cmpmid=$cmpmid";

										$re3 = mysqli_query($conn, $eve3);
										$partyname="";
										while($rt3 = mysqli_fetch_assoc($re3))

										{											
											
											$partymid=$rt3['partymid'];
											//$_SESSION['partymid']=$partymid;
											$partyname=$rt3['partyname'];
																			 
										}
										
										?>     
								<input type="hidden" name="partymid" id="partymid" value="<?php echo $partymid; ?>" class="form-control" readonly>
								<input type="text" name="partyname" class="form-control form-control-solid"id="partyname" value="<?php echo $partyname; ?>" class="form-control" readonly>
															<!--end::Input-->
														</div>
															<!--end::Input-->

														<!--end::Input group-->
													</div>
													<!--end::Col-->
													
											
												<!--begin::Col-->
													<div class="col">
														<!--begin::Input group-->
															<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Reference ID</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
															<select class="form-select form-select-solid" data-control="select2"  name="receiptrefrenceid" id="receiptrefrenceid" for="receiptrefrenceid" onchange="receiptrefrenceid">
													<option value="0">select</option>
														<?php
									
										  $eve="SELECT * FROM res_invoice_master WHERE cmpmid=$cmpmid and customermid= ".$partymid;

    $re = mysqli_query($conn, $eve);
//echo '<option value="'.$eve.'">'.$eve.'</option>';
    //Count total number of rows
 

        while($rt = mysqli_fetch_assoc($re)){
			
			$invoicemid=$rt['invoicemid'];
			$invoicefordisplay=$rt['invoicefordisplay'];
			$invoicedate=$rt['invoicedate'];
			$invoicenetamount=$rt['invoicenetamount'];
			$eve41 = "select sum(receiptamont) as receiptamont from res_paymentin_master where receiptrefrenceid=$invoicemid";

										$re41 = mysqli_query($conn, $eve41);
										$receiptamont=0;
										while($rt41 = mysqli_fetch_assoc($re41))

										{		
											$receiptamont=$rt41['receiptamont'];
											
										}
										$pendingamount=$invoicenetamount-$receiptamont;
										if($pendingamount>0){
										echo '<option value="'.$rt['invoicemid'].'" selected>'.$invoicefordisplay.'  '.$invoicedate.'</option>'; }
									

        }
    
									?>
													</select>
															<!--end::Input-->
														</div>
															<!--end::Input-->

														<!--end::Input group-->
													</div>
													<!--end::Col-->
													
													</div>
												<!--end::Row-->
												<!--begin::Row-->
												<div class="row row-cols-1 row-cols-sm-2 rol-cols-md-1 row-cols-lg-2">
												
												<!--begin::Col-->
													<div class="col">
														<!--begin::Input group-->
														<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Total Amount</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
																<input type="hidden" name="invoicefordisplay" id="dcontact3" value="<?php echo $invoicefordisplay; ?>" class="form-control" readonly>
															<input type="text" class="form-control form-control-solid" name="invoicenetamount" id="dcontact2" value="<?php echo $invoicenetamount; ?>" readonly>
															<!--end::Input-->
														</div>
														<!--end::Input group-->
													</div>
													<!--end::Col-->
													
												<div class="col">
														<!--begin::Input group-->
														<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Pending Amount</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
															
												<input type="text" class="form-control form-control-solid" name="pendingamount" id="dcontact4" value="<?php echo $pendingamount; ?>" readonly>
															<!--end::Input-->
														</div>
														<!--end::Input group-->
													</div>
													
													</div>
												<!--end::Row-->
													<!--begin::Row-->
												<div class="row row-cols-1 row-cols-sm-2 rol-cols-md-1 row-cols-lg-2">
												
												<!--begin::Col-->
													<div class="col">
														<!--begin::Input group-->
														<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Receipt Amount</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
															<input type="text" class="form-control form-control-solid" name="receiptamount" value="<?php echo $receiptamount; ?>">
															<!--end::Input-->
														</div>
														<!--end::Input group-->
													</div>
													<!--end::Col-->
																<div class="col">
														<!--begin::Input group-->
														<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Receipt Mode</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
															
													<select class="form-select form-select-solid" data-control="select2"  name="receiptmode">
													<option value="0">select</option>
													<option>Cash</option>

									<option>Cheque</option>
									
									<option>NEFT</option>
									
									<option>Other</option>
													</select>
													<!--end::Input-->
														</div>
														<!--end::Input group-->
													</div>
										
													
													</div>
													<!--end::Row-->
												<div class="row row-cols-1 row-cols-sm-2 rol-cols-md-1 row-cols-lg-2">
												<!--begin::Row-->
														<div class="col">
														<!--begin::Input group-->
														<div class="fv-row mb-7">
															<!--begin::Label-->
															<label class="fs-6 fw-semibold form-label mt-3">
																<span class="">Receipt Detail</span>
																
															</label>
															<!--end::Label-->
															<!--begin::Input-->
															
												<textarea type="text" class="form-control form-control-solid" name="receiptdetail" value="" ><?php echo $receiptdetail; ?></textarea>
															<!--end::Input-->
														</div>
														<!--end::Input group-->
													</div>
											
													</div>
										
												
												<div class="d-flex justify-content-end">
													<!--begin::Button-->
													<a type="reset" href="pendingreceiptamount.php?partymid=<?php echo $partymid; ?>"  class="btn btn-light me-3">Cancel</a>
													<!--end::Button-->
													<!--begin::Button-->
													<button type="submit"  id="btnsubmite" class="btn btn-primary">
														<span class="indicator-label">Save</span>
														<span class="indicator-progress">Please wait...
														<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
													</button>
													<!--end::Button-->
												</div>
												<!--end::Action buttons-->
											</form>
											<!--end::Form-->
										</div>
										<!--end::Card body-->
									</div>
									<!--end::Contacts-->
								</div>
								<!--end::Content-->
							</div>
							<!--end::Contacts App- Add New Contact-->
						</div>
						<!--end::Container-->
					</div>
					<!--end::Content-->
					<?php include('footer.php'); ?>
					</div>
				<!--end::Wrapper-->
			</div>
			<!--end::Page-->
		</div>
		<!--end::Root-->
		
		<!--end::Main-->
		
		<!--begin::Engage modals-->
		<!--end::Engage modals-->
		<!--begin::Engage toolbar-->
		<!--end::Engage toolbar-->
		<!--begin::Scrolltop-->
		<div id="kt_scrolltop" class="scrolltop" data-kt-scrolltop="true">
			<!--begin::Svg Icon | path: icons/duotune/arrows/arr066.svg-->
			<span class="svg-icon">
				<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
					<rect opacity="0.5" x="13" y="6" width="13" height="2" rx="1" transform="rotate(90 13 6)" fill="currentColor" />
					<path d="M12.5657 8.56569L16.75 12.75C17.1642 13.1642 17.8358 13.1642 18.25 12.75C18.6642 12.3358 18.6642 11.6642 18.25 11.25L12.7071 5.70711C12.3166 5.31658 11.6834 5.31658 11.2929 5.70711L5.75 11.25C5.33579 11.6642 5.33579 12.3358 5.75 12.75C6.16421 13.1642 6.83579 13.1642 7.25 12.75L11.4343 8.56569C11.7467 8.25327 12.2533 8.25327 12.5657 8.56569Z" fill="currentColor" />
				</svg>
			</span>
			<!--end::Svg Icon-->
		</div>
		<!--end::Scrolltop-->
		
		<!--begin::Javascript-->
		<script>var hostUrl = "assets/";</script>
		<!--begin::Global Javascript Bundle(mandatory for all pages)-->
		<script src="assets/plugins/global/plugins.bundle.js"></script>
		<script src="assets/js/scripts.bundle.js"></script>
		<!--end::Global Javascript Bundle-->
		<!--begin::Vendors Javascript(used for this page only)-->
		<script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
		<!--end::Vendors Javascript-->
		<!--begin::Custom Javascript(used for this page only)-->
		<script src="assets/js/custom/apps/contacts/edit-contact.js"></script>
		<script src="assets/js/widgets.bundle.js"></script>
		<script src="assets/js/custom/widgets.js"></script>
		<script src="assets/js/custom/apps/chat/chat.js"></script>
		<script src="assets/js/custom/utilities/modals/upgrade-plan.js"></script>
		<script src="assets/js/custom/utilities/modals/users-search.js"></script>
		<!--end::Custom Javascript-->
		<!--end::Javascript-->
		<script type="text/javascript">
		$(document).ready(function(){
			
			
 $("#kt_daterangepicker_1").flatpickr({
        enableTime:!1,dateFormat:"d-m-Y"
    }
   
);
	$("#kt_daterangepicker_2").flatpickr({
        enableTime:!1,dateFormat:"d-m-Y"
    }
   
);
		});
		</script>
	<script type="text/javascript">
$(document).ready(function(){
$('#partymid').on('change',function(){
var partymid = $(this).val();
//alert(citymid);
if(partymid){
$.ajax({
type:'POST',
url:'invoiceid.php',
data:'partymid='+partymid,
success:function(html){
$('#receiptrefrenceid').html(html);
}
});
}else{
$('#receiptrefrenceid').html('<option value="0">No Data Found</option>');
}
});
});
</script>
<script>
				/* $(function() {
					$( "#skills" ).autocomplete({
						source: 'customersearch.php'
					});
				}); */
				$('#receiptrefrenceid').on('change',function(){


				//make ajax call to action method to get the description for this value
				
				$.get("totalamount.php", { receiptrefrenceid : $(this).val() }, function(response) {

				//alert(response);
				//set the value of description text box
				$('#dcontact2').val( $.trim(response) );

				});
				
				$.get("pendingamount.php", { receiptrefrenceid : $(this).val() }, function(response) {

				//alert(response);
				//set the value of description text box
				$('#dcontact4').val( $.trim(response) );

				});
				
				
				});
			</script>
	</body>
	<!--end::Body-->
</html>