<?php 
//<script src="./js/dataTables.colReorder.js" defer></script>
//

echo '
<script src="./js/jquery-2.1.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/jquery-ui.min.js"></script>   
<script src="./js/bootstrap-datepicker.js" ></script> 
<script src="./js/jquery.minimalect.min.js"  defer></script>
<script src="./js/bootbox.min.js"  defer></script> 
<script src="./js/jquery.dataTables.js" ></script> 
 

<script src="./js/dataTables.colVis.js" defer></script>   
<script src="./js/dataTables.scroller.js" defer></script> 
<script src="./js/date-dd-MMM-yyyy.js" defer ></script>  
<script src="./js/moment.js" defer></script> 
<script src="./js/readable-range.js"  defer></script>
<script src="./js/select2.js" defer></script>
<script src="./js/widgets.js" defer></script> 
<script src="./js/autocomplete.js"  defer></script>  
 

'; 


echo '
<script src="./js/tinymce/js/tinymce/tinymce.min.js" defer></script> 
<script src="./js/tinywidgets.js" defer></script>
<script type="text/javascript" defer>
		function loadSelectContractor(selectType,divId,selectClass,condition_value){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&select_condition_value="+encodeURIComponent(condition_value)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate);
						$.post(\'./singleselectcontractor.php\', dataString, function(msg){
								$(divId).html(msg);
								if(selectClass!=\'\' || selectClass!=null){
								 	$(selectClass).select2(); 
								}
						});
		}

		function loadSelectBroker(selectType,divId,selectClass,condition_value){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&select_condition_value="+encodeURIComponent(condition_value)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate);
						$.post(\'./singleselectbroker.php\', dataString, function(msg){
								$(divId).html(msg);
								if(selectClass!=\'\' || selectClass!=null){
									$(selectClass).select2(); 
								}
						});
		}

		function loadSelectRealty(selectType,divId,selectClass,defaultVal){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&defaultval="+encodeURIComponent(defaultVal)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate);
						$.post(\'./singleselectrealty.php\', dataString, function(msg){
								$(divId).html(msg);
								if(selectClass!=\'\' || selectClass!=null){
									$(selectClass).select2(); 
							 	}
						});
		}

		
		function loadSelectAgent(selectType,divId,selectClass,condition_value){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&select_condition_value="+encodeURIComponent(condition_value)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate);
						$.post(\'./singleselectbroker.php\', dataString, function(msg){
								$(divId).html(msg);
								if(selectClass!=\'\' || selectClass!=null){
									$(selectClass).select2(); 
								}
						});
		}
		
		function loadSelect(selectType,divId,selectClass,condition_value){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&select_condition_value="+encodeURIComponent(condition_value)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate);
						$.post(\'./singleselect.php\', dataString, function(msg){
								$(divId).html(msg);

								if(selectClass!=\'\' || selectClass!=null){ 
								 	//$(selectClass).select2();  
								}
						}); 
		}
		
		function loadSelect1(selectType,divId,selectClass,condition_value,default_pricelist){ 
						$(divId).html("<div id=\'loadingmessage\'><img src=\'./images/small_load.gif\' alt=\'Loading...\'></div>");
						var action = $(\'#main_action\').val(); 
						var mid	   = $(\'#main_id\').val(); 
						var mtype  = $(\'#main_type\').val(); 
						var current_model  = $(\'#current_model\').val(); 
						var current_project  = $(\'#current_project\').val(); 
						var rdate  = $(\'#reservation_date\').val();  
						var customprice = $(\'#check_pricelist_date\').prop("checked"); 
						if(customprice===true){
						var custom = "true";
						}else{
						var custom = "false";
						}
						 
						var dataString		=	"select_type="+encodeURIComponent(selectType)+"&select_condition_value="+encodeURIComponent(condition_value)+"&action="+encodeURIComponent(action)+"&mid="+encodeURIComponent(mid)+"&mtype="+encodeURIComponent(mtype)+"&mproj="+encodeURIComponent(current_project)+"&mmodel="+encodeURIComponent(current_model)+"&mrdate="+encodeURIComponent(rdate)+"&custom="+encodeURIComponent(custom)+"&default_pricelist="+encodeURIComponent(default_pricelist);
						
						$.post(\'./singleselect1.php\', dataString, function(msg){
								$(divId).html(msg);
								if(selectClass!=\'\' || selectClass!=null){
									$(selectClass).select2(); 
								}
						});
		}
</script>';
 
 
 
 
echo "<script>";
echo "
function updatePriceList(id){

	var usertype = $('#usertype').val(); 
	bootbox.dialog({ 
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){ 
								if(data==true){ 
									if(usertype=='accounting_officer' || usertype=='admin'){
										window.setTimeout(function() { window.location.href = 'index.php?pg=pricelist&type=pricelist&action=edit&id='+id; }, 1000);	
									}else{
										bootbox.alert('No access');
									} 
								}else{
									bootbox.alert('Invalid Password');
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";






echo "
function updateCaPrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#bpm_less_ca').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#bpm_less_ca').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";
echo "
function updateReservationPrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#bpm_reservation').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#bpm_reservation').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";

echo "
      var usertype = $('#usertype').val();
 		if(usertype=='accounting_officer'){
			$('#bpm_less_discount').attr('readonly',false); 
			$('#bpm_rate').attr('readonly',false); 
			$('#bpm_misc_expense_rate').attr('readonly',false); 
			$('#withholding_tax').attr('readonly',false);  
			$('#bpm_less_ca').attr('readonly',false);
			$('#bpm_reservation').attr('readonly',false);
		}else{ 
			$('#bpm_less_discount').attr('readonly',true); 
			$('#bpm_rate').attr('readonly',true); 
			$('#bpm_misc_expense_rate').attr('readonly',true); 
			$('#withholding_tax').attr('readonly',true);  
			$('#bpm_less_ca').attr('readonly',true);
			$('#bpm_reservation').attr('readonly',true);
		}
      ";
 

echo "
function updateWithholdingPrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#withholding_tax').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#withholding_tax').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";

echo "
function updateMiscPercentagePrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#bpm_misc_expense_rate').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#bpm_misc_expense_rate').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";

echo "
function updateRatePrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#bpm_rate').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#bpm_rate').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";

echo "
function updateDiscountPrice(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data==true){ 
										$('#bpm_less_discount').attr('readonly',false);
								}else{
									bootbox.alert('Invalid Access');
									$('#bpm_less_discount').attr('readonly',true);
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";



//NOV 21, 2021

echo "
function updateBrokerAgentAmount(id){
	 var usertype = $('#usertype').val();
	  
	bootbox.dialog({
		message: \"Username &nbsp;&nbsp;<input type='text' required class='form-control' id='confirm_user'/><br/>Password &nbsp;&nbsp;<input type='password' required class='form-control' id='confirm_pass'/>\",
		title: \"Verify Password\",
		buttons: {
			main: {
				label: \"Confirm\",
				className: \"btn-primary\",
				callback: function() {
					var f = $('#confirm_pass').val(); 
					var uname = $('#confirm_user').val(); 
					
					if(f!=''){
						$.ajax({
							url: './ajax/check_pass_admin_acctg2.php',
							type: 'POST',
							data: {text: f,user:uname},
							success: function(data){  
								if(data=='accountant' || data=='admin'){ 
										$('.broker_amount').attr('readonly',false);
										$('.agent_amount').attr('readonly',false); 
										$('#brokeragentaccess').val(data); 
 
								}else{
									bootbox.alert('Invalid Access');									 
								}
							} 
						});
					}else{
						bootbox.alert('Invalid Password');
					}
				}
			}
		}
	}); 
}";

//NOV 21, 2021
echo "</script>";

if(isset($_GET['type']) && $_GET['type']=="pricelist"){ 
echo '<script src="./js/pricelistwidgets.js" defer></script>';
echo "<script defer>
	loadSelect('terms','#div_terms','select.select2');
	loadSelect('project','#div_project','select.select2');
	loadSelect('detail_terms','#div_detail_terms','select.select2');
</script>";

 }elseif(isset($_GET['type']) && $_GET['type']=="adjustment_pricelist"){ 
echo '<script src="./js/adjustmentpricelistwidgets.js" defer></script>';
echo "<script defer>
	loadSelect('terms','#div_terms','select.select2');
	loadSelect('project','#div_project','select.select2');
	loadSelect('detail_terms','#div_detail_terms','select.select2');
</script>";

 }elseif((isset($_GET['type']) && $_GET['type']=="reservation") || (isset($_GET['type']) && $_GET['type']=="report_reservation")){ 
if(isset($_GET['action']) && $_GET['action']!=""):
echo "<script defer>
		loadSelect('project','#div_project','select.select2');
		loadSelectBroker('broker','#div_broker','select.select2');
		loadSelect('employee_type','#div_employee_type','select.select2'); 
		loadSelect('employee_position','#div_employee_position','select.select2'); 
		loadSelect('buyer_profile','#div_buyer_profile','select.select2'); 
		loadSelect('employee_type_co1','#div_employee_type_co1','select.select2'); 
		loadSelect('employee_type_co2','#div_employee_type_co2','select.select2'); 
		loadSelect('employee_type_co3','#div_employee_type_co3','select.select2'); 
		loadSelect('position_co1','#div_position_co1','select.select2'); 
		loadSelect('position_co2','#div_position_co2','select.select2'); 
		loadSelect('position_co3','#div_position_co3','select.select2');
						var action	   = $('#main_action').val();  
						if(action=='edit' || action=='transfer' || action=='view'){
							var mid	   = $('#main_id').val();  
							var dataString2		=	'action='+encodeURIComponent(action)+'&mainid='+encodeURIComponent(mid); 
							$.post('./ajax/load_reservation.php', dataString2, function(msg){ 
									var obj	= $.parseJSON(msg); 
									var project				=	obj.data[0].project;
									var model				=	obj.data[0].model;
									var reserveDate			=	obj.data[0].reservation_date;  
									var priceDate			=	obj.data[0].pricelist_date;
							});
						}

		//check if there's already existing reservation
		function checkIfReservationExist(ph,bl,lo,proj,mod){

			var first_name 	=  '';
			var last_name 	=  '';
			var middle_name 	=  '';

			var dataString	=	'project='+encodeURIComponent(proj)+'&model='+encodeURIComponent(mod)+'&curphase='+encodeURIComponent(ph)+'&curblock='+encodeURIComponent(bl)+'&curlot='+encodeURIComponent(lo);
			$.post('./checkreserveexist.php', dataString, function(msg){
				var obj	= $.parseJSON(msg);
				 
				if(obj.output[0]!=undefined){
					  first_name	= obj.output[0].first_name;
					  last_name		= obj.output[0].last_name;
					  middle_name	= obj.output[0].middle_name;
					bootbox.alert(last_name+', '+first_name+' '+middle_name+' had already reserved Model '+mod.replace(/_/g, ' ')+' Phase '+ph+' Block '+bl+' Lot '+lo);	
				}
				
			});
		}
		
		function loadPhaseBlockLot(project,model,priceDate,cphase,cblock,clot){
					var action = $('#main_action').val();
					var mid	   = $('#main_id').val();
					var mtype  = $('#main_type').val(); 
					var priceDates  = priceDate;
					var curphase = cphase;
					var curblock = cblock;
					var curlot = clot;		 
					/*var curphase  = $('#current_phase').val(); 
					var curblock  = $('#current_block').val(); 
					var curlot	  = $('#current_lot').val(); 
					 */
			$('#div_phase').html(\"<div id='loadingmessage'><img src='./images/small_load.gif' alt='Loading...'></div>\");
			$('#div_block').html(\"<div id='loadingmessage'><img src='./images/small_load.gif' alt='Loading...'></div>\");
			$('#div_lot').html(\"<div id='loadingmessage'><img src='./images/small_load.gif' alt='Loading...'></div>\");
						var dataString	=	'project='+encodeURIComponent(project)+'&model='+encodeURIComponent(model)+'&pricelist_date='+encodeURIComponent(priceDates)+'&action='+encodeURIComponent(action)+'&mid='+encodeURIComponent(mid)+'&mtype='+encodeURIComponent(mtype)+'&curphase='+encodeURIComponent(curphase)+'&curblock='+encodeURIComponent(curblock)+'&curlot='+encodeURIComponent(curlot);
						$.post('./singlephaseblocklot.php', dataString, function(msg){
								var obj	= $.parseJSON(msg); 
								$('#div_phase').html(obj.output.phase);
								$('#div_block').html(obj.output.block);
								$('#div_lot').html(obj.output.lot);
								$('select.select2').select2();

								var proj = $('#current_project').val();
								var mod = $('#current_model').val();
								var priceDate = $('#pricelist_date').val(); 
  
								$('#current_phase,#current_block,#current_lot').on('change', function() {
									var ph = $('#current_phase').val();
									var bl = $('#current_block').val();
									var lo = $('#current_lot').val();
									var proj = $('#current_project').val();
									var mod = $('#current_model').val();
									var priceDate = $('#pricelist_date').val();  
									
									if(ph!='' && bl!='' && lo!=''){
										checkIfReservationExist(ph,bl,lo,proj,mod);
									}
									
									if(proj!='' && mod!='' && priceDate!=''){ 
										loadPhaseBlockLot(proj,mod,priceDate,ph,bl,lo); 
									}
									
									
								});
								
						});
		}
		
		function loadDiscount(project,model){
			$('#div_promo').html(\"<div id='loadingmessage'><img src='./images/small_load.gif' alt='Loading...'></div>\");
						var action = $('#main_action').val(); 
						var mid	   = $('#main_id').val(); 
						var mtype  = $('#main_type').val(); 
						var phase = $('#current_phase').val();
						var block = $('#current_block').val();
						var lot	  = $('#current_lot').val();  
						var priceDates  = $('#pricelist_date').val();   
					 
						var dataString		=	\"project=\"+encodeURIComponent(project)+\"&model=\"+encodeURIComponent(model)+\"&pricelist_date=\"+encodeURIComponent(priceDates)+\"&phase=\"+encodeURIComponent(phase)+\"&block=\"+encodeURIComponent(block)+\"&lot=\"+encodeURIComponent(lot)+\"&action=\"+encodeURIComponent(action)+\"&mid=\"+encodeURIComponent(mid)+\"&mtype=\"+encodeURIComponent(mtype); 
						$.post('./singlediscount.php', dataString, function(msg){   
								var obj	= $.parseJSON(msg);
								var disc = obj.output.discount; 
							 if(action=='view'){
							 	var vmsg = '<input type=\"text\" disabled name=\"discount\" id=\"discount\" value=\"'+Comma(disc)+'\" class=\"form-control text-right\">';
							 }else{
								var vmsg = '<input type=\"text\" name=\"discount\" id=\"discount\" value=\"'+Comma(disc)+'\" class=\"form-control text-right\">';
							}	
								$('#div_promo').html(vmsg);
						});
		}
		 
		function loadOtherReserveDetails(project,model,priceDate){ 
						var action = $('#main_action').val();  
						var mid	   = $('#main_id').val(); 
						var mtype  = $('#main_type').val(); 
						var priceDates  = priceDate;   
						var phase = $('#current_phase').val();
						var block = $('#current_block').val();
						var lot	  = $('#current_lot').val();
								$('#reserve_predef_pricelist_status').val('');
								$('#reserve_predef_detail_terms').val('');
								$('#reserve_predef_discount').val('');
								$('#reserve_predef_floor_area').val('');
								$('#reserve_predef_lot_size').val('');
								$('#reserve_predef_lot_type').val('');
								$('#reserve_predef_contract_price').val('');
								$('#reserve_predef_loanable_amount').val('');
								$('#reserve_predef_pf_net').val('');
								$('#reserve_predef_pf_payable').val('');
								$('#reserve_predef_amortization').val('');
								$('#reserve_predef_required_gross').val('');
						var dataString	=	\"project=\"+encodeURIComponent(project)+\"&model=\"+encodeURIComponent(model)+\"&pricelist_date=\"+encodeURIComponent(priceDates)+\"&phase=\"+encodeURIComponent(phase)+\"&block=\"+encodeURIComponent(block)+\"&lot=\"+encodeURIComponent(lot)+\"&action=\"+encodeURIComponent(action)+\"&mid=\"+encodeURIComponent(mid)+\"&mtype=\"+encodeURIComponent(mtype);
						$.post('./singleotherdetails.php', dataString, function(msg){  
								 var obj	= $.parseJSON(msg); 
								$('#reserve_predef_pricelist_status').val(obj.output.pricelist_status); 
								$('#reserve_predef_discount').val(obj.output.discount); 
								$('#reserve_predef_detail_terms').val(obj.output.detail_terms); 
								$('#reserve_predef_lot_size').val(obj.output.lot_size); 
								$('#reserve_predef_lot_type').val(obj.output.lot_type); 
								$('#reserve_predef_floor_area').val(obj.output.floor_area); 
								$('#reserve_predef_contract_price').val(obj.output.contract_price);
								$('#reserve_predef_loanable_amount').val(obj.output.loanable_amount);
								$('#reserve_predef_pf_net').val(obj.output.pf_net);
								$('#reserve_predef_pf_payable').val(obj.output.pf_payable); 
								$('#reserve_predef_amortization').val(obj.output.amortization);
								$('#reserve_predef_required_gross').val(obj.output.required_gross); 
						});
		}
</script>";
endif;


echo '<script src="./js/reservationwidgets.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="employee_type"){ 
echo '<script src="./js/employeetypewidgets.js" defer></script> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="buyer_profile"){ 
echo '<script src="./js/buyerprofilewidgets.js" defer></script> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="position"){ 
echo '<script src="./js/positionwidgets.js" defer></script> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="broker"){ 
echo '<script src="./js/brokerwidgets.js"></script defer> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="brokeragent"){ 
echo '<script src="./js/brokeragentwidgets.js"></script defer> ';
}elseif(isset($_GET['type']) && $_GET['type']=="tin"){ 
echo '<script src="./js/tinwidgets.js"></script defer> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="units"){ 
echo '<script src="./js/unitswidgets.js"></script defer> ';
}elseif(isset($_GET['type']) && $_GET['type']=="conversion"){ 
echo '<script src="./js/conversion.js"></script defer> '; 
}elseif(isset($_GET['type']) && $_GET['type']=="conversion_details"){ 
echo '<script src="./js/conversion_details.js"></script defer> '; 
}elseif(isset($_GET['type']) && $_GET['type']=="status_of_accounts_for_conversion"){ 
echo '<script src="./js/conversion.js"></script defer> '; 
}elseif(isset($_GET['type']) && $_GET['type']=="construction_and_utilities"){ 
echo '<script src="./js/construction_and_utilities.js"></script defer> '; 
}elseif(isset($_GET['type']) && $_GET['type']=="permits_and_licenses"){ 
echo '<script src="./js/permits_and_licenses.js"></script defer> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="contractor"){ 
echo '<script src="./js/contractorwidgets.js"></script defer> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="agent"){ 
echo "<script defer>
loadSelectBroker('broker','#div_broker','select.select2'); 
</script>";
echo '<script src="./js/agentwidgets.js" defer></script> ';
 }elseif(isset($_GET['type']) && $_GET['type']=="monitoring_folders"){ 
echo '<script src="./js/monitoringfolderswidgets.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="checklist_of_requirements"){ 
echo '<script src="./js/checklistrequirementswidgets.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="releases_to_broker"){ 
echo '<script src="./js/releases_to_broker.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="releases_to_broker_for_wht"){ 
echo '<script src="./js/releases_to_broker_for_wht.js"></script>';
//}elseif(isset($_GET['type']) && $_GET['type']=="report_releases_to_broker_for_wht"){ 
//echo '<script src="./js/report_releases_to_broker_for_wht.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="partial_commission_releases_schedule"){ 
echo '<script src="./js/partial_commission_releases_schedule.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="releases_to_contractor"){ 
echo '<script src="./js/releases_to_contractor.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="payment_status_to_broker"){ 
echo '<script src="./js/payment_status_to_broker.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="payment_status_to_contractor"){ 
echo '<script src="./js/payment_status_to_contractor.js"></script>';
}elseif(isset($_GET['type']) && $_GET['type']=="buyer_payment_monitoring"){ 
echo '<script src="./js/buyerpaymentmonitoring.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="postdated_pagibig_loan_amortization"){ 
echo '<script src="./js/postdatedpagibigloanamortization.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="buyer_status_monitoring"){ 
echo '<script src="./js/buyerstatusmonitoring.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="buyer_house_renovation_monitoring"){ 
echo '<script src="./js/buyerhouserenovationmonitoring.js"></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="postdated_checks_received"){ 
echo '<script src="./js/postdatedchecksreceived.js" defer></script>';
}elseif(isset($_GET['type']) && $_GET['type']=="postdated_checks_received_past_due"){ 
echo '<script src="./js/postdatedchecksreceivedpastdue.js" defer></script>';
}elseif(isset($_GET['type']) && $_GET['type']=="postdated_pagibig_loan_amortization_details"){ 
echo '<script src="./js/postdatedpagibigloanamortizationdetails.js" defer></script>'; 

 }elseif(isset($_GET['type']) && $_GET['type']=="cheque_for_clearing"){ 
echo '<script src="./js/postdatedchecksreceived.js" defer></script>';
 }elseif(isset($_GET['type']) && $_GET['type']=="buyer_status_folder_pagibig"){ 
echo '<script src="./js/buyerstatusfolderpagibig.js" defer></script>';
}elseif(isset($_GET['type']) && $_GET['type']=="buyer_status_folder_bank"){ 
echo '<script src="./js/buyerstatusfolderbank.js" defer></script>';
}

echo "<script defer> 
     	$(function(){ 
            $('#dLabel').click(function(){  
				var thetitle = $('title').text();
                $('.counter').text('0').hide(); 
				$('title').text(thetitle);
            })
     	});
		
		$('#pdc_status_select').change(function(){
			var status_select = $('#pdc_status_select').val();
			if(status_select=='Returned' || status_select=='Closed'){ //29DEC24
				var replace_option = $('#pdc_replace_option').val(); 
				if(replace_option=='cheque'){
					$('.replace_cheque').show();
				} 
			}
		}); 		 
     </script>";
	 
	 
	 echo "
 <script defer>
 function updateDevDate(){
	var valid = $('#loanid').val();
	var vdate = $('#loandate').val();
	var vtype = $('#loantype').val(); 
	if(vdate!=''){
			var dataString = 'mainid='+encodeURIComponent(valid)+'&checkval='+encodeURIComponent(vdate)+'&vtype='+encodeURIComponent(vtype);
			$.post('./ajax/update_schedule_loan_delivery_date.php', dataString, function(msg){
				var obj	= $.parseJSON(msg);  
				if(obj.output==true){
					bootbox.alert('Successfully Saved.');
					window.setTimeout(function() { window.location.href = 'index.php?pg=reservation&type=schedule_of_loan_folders'; }, 1000);
				}
			});
	}else{
		bootbox.alert('Required Field');
	}
 }
 
 $('#close').click(function(){
		window.setTimeout(function() { window.location.href = 'index.php?pg=reservation&type=schedule_of_loan_folders'; }, 1000);
 });
function updateScheduleLoanChecklist(valid){  
$('.devdate'+valid).show();
	var m = $('#schedule_loan_checklist'+valid+' option:selected').text(); 
	if(m=='Delivered'){
			$('#loan_heart'+valid).show();
			$('#loan_heart'+valid).html('<span style=\"color:#ff0000\" class=\"glyphicon glyphicon-heart\">&nbsp;</span>');
			$('.devdate'+valid).show(); 
			$('#loanid').val(valid);
			$('#loantype').val('delivered');
			$('#modtitle').html(m+' Date'); 
			$('#myModal').modal({
				keyboard: false,
				backdrop: 'static'
			})
    }else{
		if(m=='To be Delivered'){
			$('.devdate'+valid).show(); 
			$('#loantype').val('to_be_delivered');
			$('#loanid').val(valid);
			$('#modtitle').html(m+' Date'); 
			$('#myModal').modal({
				keyboard: false,
				backdrop: 'static'
			})
		}else if(m=='Not Delivered' || m==''){
			$('.devdate'+valid).hide();
		}
		
		$('#loan_heart'+valid).hide();
	}
	var dataString = 'mainid='+encodeURIComponent(valid)+'&checkval='+encodeURIComponent(m);
	$.post('./ajax/update_schedule_loan.php', dataString, function(msg){
		var obj	= $.parseJSON(msg); 
	});	
}

$('#refresh_tcp').click(function(e){
	e.preventDefault();
	var mainid =	$('#main_id').val();
	var dataString = 'mainid='+encodeURIComponent(mainid);
	$.post('./ajax/reload_buyer_payment_monitoring.php', dataString, function(msg){
		var obj			=	$.parseJSON(msg);  
		const tcp			=	parseFloat(obj.data[0].tcp).toFixed(2);
		const discount		=	parseFloat(obj.data[0].discount).toFixed(2);
		const loanable_amount	=	parseFloat(obj.data[0].loanable_amount).toFixed(2);
		const net_equity		=	parseFloat(obj.data[0].net_equity).toFixed(2);
		const terms			=	obj.data[0].payment_terms;
		const pf_payable		=	parseFloat(obj.data[0].pf_payable).toFixed(2);
 
		$('#bpm_tcp').val(Comma(tcp));
		$('#bpm_discount').val(Comma(discount));
		$('#bpm_loanable_amount').val(Comma(loanable_amount));
		$('#bpm_net_equity').val(Comma(net_equity));
		$('#bpm_terms_of_payment').val(terms);
		$('#bpm_monthly_equity').val(Comma(pf_payable));
		computeMonthlyEquity();
		computeNetEquity();
	});
});
$('#bpm_discount').attr('readonly',true);
</script> 
";


echo "
<script>
 
//select all checkboxes
$('#select_all').change(function(){ 
var status = this.checked; // 'select all' checked status
$('.checkbox').each(function(){ //iterate all listed checkbox items
this.checked = status; //change '.checkbox' checked status
});
});


 			var notselectedChecks = new Array();
        	 
function validate(te){
	/*if(te.checked) {  
		if($('.checkbox:checked').length == $('.checkbox').length ){
			$('#select_all')[0].checked = true; //change 'select all' checked status to true
		}
    } */
			var notcheck = $('.checkbox:not(:checked)').length;
 
		
	var ischeck = $(te).is(':checked'); 
    if (ischeck==true){  
 			notselectedChecks = $.grep(notselectedChecks, function(value) {
 	 			return value != te.value;
			});
 
	}else{ 
	        if (notcheck > 0){
	             	notselectedChecks.push(te.value); 
	        } 
	        
	}

	$('#notselected').val(notselectedChecks);  		
		
} 


$('.checkbox').change(function(e){ 
e.preventDefault();  

if(this.checked == false){ //if this item is unchecked
	$('#select_all')[0].checked = false; //change 'select all' checked status to false
}
//check 'select all' if all checkbox items are checked
if($('.checkbox:checked').length == $('.checkbox').length ){
	$('#select_all')[0].checked = true; //change 'select all' checked status to true
}
});



function resetunselect(){ 
		$('#notselected').val('');
		notselectedChecks = [];
		$('.checkbox').prop('checked',true);
}
</script>


";

