<?php
error_reporting(0);
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
session_start();  
include_once('../config/minho.php');
include_once('../config/autoloadClass.php');
$autoload		=	new autoloadClass(); 
$mecon			=	new condbClass();
$formClass		=	new formClass();
$requestData	=	$_REQUEST; 
$columns = array(
	0	=>	'Id', 
	1	=>	'ReservationDate',
	2	=>	'Block',
	3	=>	'Lot',
	4	=>	'FullName', 
	5	=>	'Broker', 
	//6	=>	'HouseConstruction', 
	6	=>	'Id', 
	7	=>	'ReservationStatus', 
);   
$tobedate 	= isset($_REQUEST['tobe_stat_date'])   ? $_REQUEST['tobe_stat_date']	  : "yes";
$rangeStart = isset($_REQUEST['range_start']) ?  $_REQUEST['range_start'] : date('Y-m-d', strtotime(date('01-m-Y')));
$rangeEnd 	= isset($_REQUEST['range_end'])   ? $_REQUEST['range_end']	  : date("Y-m-t", strtotime(date('Y-m-d')));


$resultQuery 		= "SELECT r.ReservationStatus as ReservationStatus, r.Id as Id, r.Block as Block, r.Lot as Lot, r.Model as Model, r.Project as Project, r.ReservationDate as ReservationDate, r.Phase as Phase, r.PricelistDate as PricelistDate, CONCAT(r.LastName,', ',r.FirstName,' ',r.MiddleName) as FullName, r.Broker as Broker, ck.BuyerStandardReqDetails as BuyerStandardReqDetails, ck.AdditionalReqDetails as AdditionalReqDetails, r.EmployeeType as EmployeeType, r.EmployeeTypeBorrower1 as EmployeeTypeBorrower1, r.EmployeeTypeBorrower2 as EmployeeTypeBorrower2, r.EmployeeTypeBorrower3 as EmployeeTypeBorrower3, ck.CoBorrower1StandardReqDetails as CoBorrower1StandardReqDetails, ck.CoBorrower1AdditionalReqDetails as CoBorrower1AdditionalReqDetails, ck.CoBorrower2StandardReqDetails as CoBorrower2StandardReqDetails, ck.CoBorrower2AdditionalReqDetails as CoBorrower2AdditionalReqDetails, ck.CoBorrower3StandardReqDetails as CoBorrower3StandardReqDetails, ck.CoBorrower3AdditionalReqDetails as CoBorrower3AdditionalReqDetails, r.NoCoBorrower as NoCoBorrower, m.HouseConstruction as HouseConstruction, bsfp.TakeOut as TakeOut FROM reservation r LEFT JOIN checklist ck ON ck.ReservationId=r.Id LEFT JOIN monitoring_folders m ON m.ReservationId=r.Id LEFT JOIN buyer_status_folder_pagibig bsfp ON bsfp.ReservationId=r.Id ";  
 
$sql	=	$resultQuery;
$sql 	.= "  WHERE (bsfp.TakeOut='1970-01-01' OR bsfp.TakeOut IS NULL) 
				AND (r.ReservationStatus!='transferred' AND  r.ReservationStatus!='cancelled') 
				AND r.Status='active' 
				AND (
						(ck.BuyerStandardReqDetails NOT LIKE '%[\"birth_certificate\",\"proof_of_billing\",\"barangay_clearance\",\"photocopy_of_two\",\"photocopy_spouse_id\",\"four_photo\",\"mdf\",\"esav\",\"msvs\",\"tinno\",\"postdated_checks\",\"twenty_four_checks\",\"signed_loan_documents\",\"attended_homeowners_orientation_and_signed_deed_of_restriction\"]%' 
					  		OR ck.BuyerStandardReqDetails IS NULL 
					  		OR (
					  			(ck.AdditionalReqDetails NOT LIKE '%[\"notarized_certificate\",\"latest_pay_slip\",\"income_tax_return\"]%' OR ck.AdditionalReqDetails IS NULL)

 								AND (ck.AdditionalReqDetails NOT LIKE '%[\"employment_contract\",\"employment_contract\",\"salary_certificate\",\"certificate_of_employment\",\"certificate_of_overseas\",\"owwa_membership_certificate\",\"resident_card\",\"photocopy_passport\",\"notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.AdditionalReqDetails IS NULL)

 								AND (ck.AdditionalReqDetails NOT LIKE '%[\"income_tax_return_audited_fs\",\"certificate_of_commission\",\"commission_vouchers\",\"photocopy_bank_statement\",\"dti_registration\",\"mayors_permit\",\"lease_contract\",\"sketch_business_location\"]%' 
  									OR ck.AdditionalReqDetails IS NULL)

  								AND (ck.AdditionalReqDetails NOT LIKE '%[\"employment_contract\",\"certificate_of_employment\",\"work_permit\",\"immigrant_visa\",\"photocopy_of_passport\",\"duly_notarized_spa\",\"photocopy_valid_id_spa\"]%' 
  									OR ck.AdditionalReqDetails IS NULL)

  								AND (ck.AdditionalReqDetails NOT LIKE '%[\"bank_statement\",\"remittances\",\"certificate_of_employment\",\"picture_of_work_station\",\"sketch_map_home_address\",\"google_map\"]%' 
  									OR ck.AdditionalReqDetails IS NULL)	   
   							)
   						) 


  						AND 
  						(ck.CoBorrower1StandardReqDetails NOT LIKE '%[\"birth_certificate\",\"proof_of_billing\",\"barangay_clearance\",\"photocopy_of_two\",\"photocopy_spouse_id\",\"four_photo\",\"mdf\",\"esav\",\"msvs\",\"tinno\"]%' 
  							OR ck.CoBorrower1StandardReqDetails IS NULL 
  							OR (
  									(ck.CoBorrower1AdditionalReqDetails NOT LIKE '%[\"notarized_certificate\",\"latest_pay_slip\",\"income_tax_return\"]%' OR ck.CoBorrower1AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower1AdditionalReqDetails NOT LIKE  '%[\"employment_contract\",\"employment_contract\",\"salary_certificate\",\"certificate_of_employment\",\"certificate_of_overseas\",\"owwa_membership_certificate\",\"resident_card\",\"photocopy_passport\",\"notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower1AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower1AdditionalReqDetails NOT LIKE '%[\"income_tax_return_audited_fs\",\"certificate_of_commission\",\"commission_vouchers\",\"photocopy_bank_statement\",\"dti_registration\",\"mayors_permit\",\"lease_contract\",\"sketch_business_location\"]%' OR ck.CoBorrower1AdditionalReqDetails IS NULL) 

 									AND (ck.CoBorrower1AdditionalReqDetails NOT LIKE '%[\"employment_contract\",\"certificate_of_employment\",\"work_permit\",\"immigrant_visa\",\"photocopy_of_passport\",\"duly_notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower1AdditionalReqDetails IS NULL)

  									AND (ck.CoBorrower1AdditionalReqDetails NOT LIKE '%[\"bank_statement\",\"remittances\",\"certificate_of_employment\",\"picture_of_work_station\",\"sketch_map_home_address\",\"google_map\"]%' OR ck.CoBorrower1AdditionalReqDetails IS NULL)	

 								)
 						) 


  						AND 
  						(ck.CoBorrower2StandardReqDetails NOT LIKE '%[\"birth_certificate\",\"proof_of_billing\",\"barangay_clearance\",\"photocopy_of_two\",\"photocopy_spouse_id\",\"four_photo\",\"mdf\",\"esav\",\"msvs\",\"tinno\"]%' 
  							OR ck.CoBorrower2StandardReqDetails IS NULL 
  							OR (
  									(ck.CoBorrower2AdditionalReqDetails NOT LIKE '%[\"notarized_certificate\",\"latest_pay_slip\",\"income_tax_return\"]%' OR ck.CoBorrower2AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower2AdditionalReqDetails NOT LIKE  '%[\"employment_contract\",\"employment_contract\",\"salary_certificate\",\"certificate_of_employment\",\"certificate_of_overseas\",\"owwa_membership_certificate\",\"resident_card\",\"photocopy_passport\",\"notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower2AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower2AdditionalReqDetails NOT LIKE '%[\"income_tax_return_audited_fs\",\"certificate_of_commission\",\"commission_vouchers\",\"photocopy_bank_statement\",\"dti_registration\",\"mayors_permit\",\"lease_contract\",\"sketch_business_location\"]%' OR ck.CoBorrower2AdditionalReqDetails IS NULL) 

 									AND (ck.CoBorrower2AdditionalReqDetails NOT LIKE '%[\"employment_contract\",\"certificate_of_employment\",\"work_permit\",\"immigrant_visa\",\"photocopy_of_passport\",\"duly_notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower2AdditionalReqDetails IS NULL)

  									AND (ck.CoBorrower2AdditionalReqDetails NOT LIKE '%[\"bank_statement\",\"remittances\",\"certificate_of_employment\",\"picture_of_work_station\",\"sketch_map_home_address\",\"google_map\"]%' OR ck.CoBorrower2AdditionalReqDetails IS NULL)	
 								)
 						) 

  						AND 
  						(ck.CoBorrower3StandardReqDetails NOT LIKE '%[\"birth_certificate\",\"proof_of_billing\",\"barangay_clearance\",\"photocopy_of_two\",\"photocopy_spouse_id\",\"four_photo\",\"mdf\",\"esav\",\"msvs\",\"tinno\"]%' 
  							OR ck.CoBorrower3StandardReqDetails IS NULL 
  							OR (
  									(ck.CoBorrower3AdditionalReqDetails NOT LIKE '%[\"notarized_certificate\",\"latest_pay_slip\",\"income_tax_return\"]%' OR ck.CoBorrower3AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower3AdditionalReqDetails NOT LIKE  '%[\"employment_contract\",\"employment_contract\",\"salary_certificate\",\"certificate_of_employment\",\"certificate_of_overseas\",\"owwa_membership_certificate\",\"resident_card\",\"photocopy_passport\",\"notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower3AdditionalReqDetails IS NULL)

 									AND (ck.CoBorrower3AdditionalReqDetails NOT LIKE '%[\"income_tax_return_audited_fs\",\"certificate_of_commission\",\"commission_vouchers\",\"photocopy_bank_statement\",\"dti_registration\",\"mayors_permit\",\"lease_contract\",\"sketch_business_location\"]%' OR ck.CoBorrower3AdditionalReqDetails IS NULL) 

 									AND (ck.CoBorrower3AdditionalReqDetails NOT LIKE '%[\"employment_contract\",\"certificate_of_employment\",\"work_permit\",\"immigrant_visa\",\"photocopy_of_passport\",\"duly_notarized_spa\",\"photocopy_valid_id_spa\"]%' OR ck.CoBorrower3AdditionalReqDetails IS NULL)

  									AND (ck.CoBorrower3AdditionalReqDetails NOT LIKE '%[\"bank_statement\",\"remittances\",\"certificate_of_employment\",\"picture_of_work_station\",\"sketch_map_home_address\",\"google_map\"]%' OR ck.CoBorrower3AdditionalReqDetails IS NULL)	
 								)
 						) 

					) ";

 

if(!empty($requestData['search']['value']) ) { 
	$arr = explode(" ",$requestData['search']['value']);  
	foreach($arr as $ind){
		$ind = str_replace(',','',$ind);		
		$sql.=" AND (r.Block LIKE '%".$ind."%' ";
		$sql.=" OR m.HouseConstruction LIKE '%".$ind."%' ";
		$sql.=" OR r.Lot LIKE '%".$ind."%' ";
		$sql.=" OR r.Project LIKE '%".$ind."%' ";
		$sql.=" OR r.Model LIKE '%".$ind."%' "; 
		//$sql.=" OR r.Broker LIKE '%".htmlentities($ind)."%' ";   
		//$sql.=" OR r.Broker LIKE '%".str_replace("'","\\\\''",$ind)."%' ";   
		$sql.=" OR r.Broker LIKE '%".addslashes($ind)."%' ";   
		$sql.=" OR CONCAT(r.LastName,', ',r.FirstName,' ',r.MiddleName) LIKE '%".htmlentities($ind)."%' ";
		$sql.=" OR UPPER(DATE_FORMAT(r.ReservationDate,'%m/%d/%Y')) LIKE '%".$ind."%' ";
		$sql.=" OR UPPER(DATE_FORMAT(bsfp.TakeOut,'%m/%d/%Y')) LIKE '%".$ind."%' ";
		$sql.=" OR UPPER(DATE_FORMAT(bsfp.TakeOut,'%d-%b-%Y')) LIKE '%".$ind."%'  ";   
		$sql.=" OR UPPER(DATE_FORMAT(r.ReservationDate,'%d-%b-%Y')) LIKE '%".$ind."%' ) ";   
	}
}       

if($tobedate=="yes"){
		if( !empty($requestData['columns'][0]['search']['value']) && !empty($requestData['columns'][1]['search']['value']) ){
			$sql .= " AND r.ReservationDate BETWEEN ('".date('Y-m-d', strtotime($requestData['columns'][0]['search']['value']))."') AND ('".date('Y-m-d', strtotime($requestData['columns'][1]['search']['value']))."')";
		}else if( !empty($requestData['columns'][0]['search']['value'])){
			$sql .= " AND r.ReservationDate >= ('".date('Y-m-d', strtotime($requestData['columns'][0]['search']['value']))."') ";
		}else if( !empty($requestData['columns'][1]['search']['value'])){
			$sql .= " AND r.ReservationDate <= ('".date('Y-m-d', strtotime($requestData['columns'][1]['search']['value']))."') ";
		}


		if( !empty($rangeStart) && !empty($rangeEnd) ){
			$sql .= " AND r.ReservationDate BETWEEN ('".date('Y-m-d', strtotime($rangeStart))."') AND ('".date('Y-m-d', strtotime($rangeEnd))."')";
		}else if( !empty($rangeStart)){
			$sql .= " AND r.ReservationDate >= ('".date('Y-m-d', strtotime($rangeStart))."') ";
		}else if( !empty($rangeEnd)){
			$sql .= " AND r.ReservationDate <= ('".date('Y-m-d', strtotime($rangeEnd))."') ";
		}
}

$mecon->query($sql);
$result			= $mecon->resultset(); 
$totalData		= count($result);
$totalFiltered	=	$totalData;

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  ,cast(Block as unsigned) asc, cast(Lot as unsigned) asc  LIMIT ".$requestData['start']." ,".$requestData['length']."   "; 
 

$mecon->query($sql);
$result			= $mecon->resultset(); 
  
$data = array();
 


$lack = "";
		for($a=0; $a<count($result); $a++){
			$nestedData	=	array(); 
			//main
			$buyerDetail		= str_replace('""','',$result[$a]['BuyerStandardReqDetails']);
			$decodeBuyerDetail	= json_decode($buyerDetail);  
			$buyerDetailCtr		= count($decodeBuyerDetail);
			
			$additionalbuyerDetail	= str_replace('""','',$result[$a]['AdditionalReqDetails']);
			$decodeAdditionalDetail	= json_decode($additionalbuyerDetail);  
			$additionalDetailCtr	= count($decodeAdditionalDetail);
			
				if($buyerDetailCtr==0 && $additionalDetailCtr==0){
					$lack = "";
				}else{
					if($additionalDetailCtr==0){
						$additionalbuyerDetail = '[]';
					}else if($buyerDetailCtr==0){
						$buyerDetail = '[]';
					} 
					 
					$empType = $result[$a]['EmployeeType'];
					$lacking = getMainLackDoc($buyerDetail,$additionalbuyerDetail,$empType,"primary");
				}
			$noBorrower	= $result[$a]['NoCoBorrower'];	
			
			$buyerDetailCtr1 = "";
			$additionalDetailCtr1 = "";
			
			$buyerDetailCtr2 = "";
			$additionalDetailCtr2 = "";
			
			$buyerDetailCtr3 = "";
			$additionalDetailCtr3 = "";
			
			
			if($noBorrower!=0){
				
				//borrower1
			$buyerDetail1		= $result[$a]['CoBorrower1StandardReqDetails'];
			$decodeBuyerDetail1	= json_decode($buyerDetail1);  
			$buyerDetailCtr1		= count($decodeBuyerDetail1);
			
			$additionalbuyerDetail1	= str_replace('""','',$result[$a]['CoBorrower1AdditionalReqDetails']);
			$decodeAdditionalDetail1	= json_decode($additionalbuyerDetail1);  
			$additionalDetailCtr1	= count($decodeAdditionalDetail1);
			
				if($buyerDetailCtr1==0 && $additionalDetailCtr1==0){
					$lack = "";
				}else{
					if($additionalDetailCtr1==0){
						$additionalbuyerDetail1 = '[]';
					}else if($buyerDetailCtr1==0){
						$buyerDetail1 = '[]';
					} 
					
					
					$empType1 = $result[$a]['EmployeeTypeBorrower1'];
					$lacking .= " [Co-Borrower1] :".getMainLackDoc($buyerDetail1,$additionalbuyerDetail1,$empType1,"coborrower");
				}
				
				//borrower2
			$buyerDetail2		= $result[$a]['CoBorrower2StandardReqDetails'];
			$decodeBuyerDetail2	= json_decode($buyerDetail2);  
			$buyerDetailCtr2		= count($decodeBuyerDetail2);
			
			$additionalbuyerDetail2	= str_replace('""','',$result[$a]['CoBorrower2AdditionalReqDetails']);
			$decodeAdditionalDetail2 = json_decode($additionalbuyerDetail2);
			$additionalDetailCtr2	= count($decodeAdditionalDetail2);
			
				if($buyerDetailCtr2==0 && $additionalDetailCtr2==0){
					$lack = "";
				}else{
					if($additionalDetailCtr2==0){
						$additionalbuyerDetail2 = '[]';
					}else if($buyerDetailCtr2==0){
						$buyerDetail2 = '[]';
					} 
					
					
					$empType2 = $result[$a]['EmployeeTypeBorrower2'];
					$lacking .= " [Co-Borrower2] :".getMainLackDoc($buyerDetail2,$additionalbuyerDetail2,$empType2,"coborrower");
				}
				
				//borrower3
			$buyerDetail3		= $result[$a]['CoBorrower3StandardReqDetails'];
			$decodeBuyerDetail3	= json_decode($buyerDetail3);
			$buyerDetailCtr3	= count($decodeBuyerDetail3);
			
			$additionalbuyerDetail3		= str_replace('""','',$result[$a]['CoBorrower3AdditionalReqDetails']);
			$decodeAdditionalDetail3	= json_decode($additionalbuyerDetail3);  
			$additionalDetailCtr3		= count($decodeAdditionalDetail3);
			
				if($buyerDetailCtr3==0 && $additionalDetailCtr3==0){
					$lack = "";
				}else{
					if($additionalDetailCtr3==0){
						$additionalbuyerDetail3 = '[]';
					}else if($buyerDetailCtr3==0){
						$buyerDetail3 = '[]';
					} 
					
					
					$empType3 = $result[$a]['EmployeeTypeBorrower3'];
					$lacking .= " [Co-Borrower3] :".getMainLackDoc($buyerDetail3,$additionalbuyerDetail3,$empType3,"coborrower");
				}
				 
		 }
		 
		 //start save
				$nestedData[] = $a + 1; 
				$nestedData[] = (($result[$a]['ReservationDate']=='1970-01-01') || ($result[$a]['ReservationDate']=='')) ? "" : date('m/d/Y', strtotime($result[$a]['ReservationDate']));
				$nestedData[] = html_entity_decode(stripslashes($result[$a]['Block']));
				$nestedData[] = html_entity_decode(stripslashes($result[$a]['Lot']));
				$nestedData[] = strtoupper(html_entity_decode(stripslashes($result[$a]['FullName'])));
				//$nestedData[] = html_entity_decode(stripslashes($result[$a]['Broker']));
				$nestedData[] = str_replace("\'","'",$result[$a]['Broker']);
				//$nestedData[] = html_entity_decode(stripslashes($result[$a]['PricelistStatus'])); 
				$pricedate	= html_entity_decode(stripslashes($result[$a]['PricelistDate'])); 
				$phase		= html_entity_decode(stripslashes($result[$a]['Phase'])); 
				$block		= html_entity_decode(stripslashes($result[$a]['Block'])); 
				$lot		= html_entity_decode(stripslashes($result[$a]['Lot'])); 
				$project	= html_entity_decode(stripslashes($result[$a]['Project'])); 
				$models		= html_entity_decode(stripslashes($result[$a]['Model'])); 
				
				
				$other = $formClass->getOtherDetails($pricedate,$models,$project,$phase,$block,$lot);		
				//$nestedData[] = $other['pricelist_status'];
				//$nestedData[] = (!empty($result[$a]['HouseConstruction']) || $result[$a]['HouseConstruction']=NULL) ? $result[$a]['HouseConstruction'] : "";
				//$nestedData[] = (!empty($result[$a]['TakeOut']) || $result[$a]['TakeOut']=NULL) ? $result[$a]['TakeOut'] : "";
				//$nestedData[] = (!empty($result[$a]['HouseConstruction']) || $result[$a]['HouseConstruction']=NULL) ? $result[$a]['HouseConstruction'] : $other['pricelist_status'];
				
				 
				
				$nestedData[] = ($buyerDetailCtr==0 && $additionalDetailCtr==0 && $buyerDetailCtr1==0 && $additionalDetailCtr1==0 && $buyerDetailCtr2==0 && $additionalDetailCtr2==0 && $buyerDetailCtr3==0 && $additionalDetailCtr3==0) ? "New buyer - to submit all Documentary Requirements" : $lacking;
				$nestedData[] = strtoupper(html_entity_decode(stripslashes($result[$a]['ReservationStatus'])));  
			$data[] = $nestedData;
		} 
$json_data = array(
			"draw"            => intval( $requestData['draw'] ),
			"recordsTotal"    => intval( $totalData ),
			"recordsFiltered" => intval( $totalFiltered ),
			"data"            => $data
			);
			 
echo json_encode($json_data);



//MAIN DETAILS
function getMainLackDoc($mainDet,$addDet,$empType,$type){  
	$lack		= "";
	$lack2		= "";
	$lacks		= "";
	$submitArr  = array();
	$submitArr	= json_decode($mainDet);    
	$submitArr2	= json_decode($addDet);    
	
$diffArr  = array();
$completeMainArr  = array();

//Complete MAIN
if($type=='primary'){ 
	$completeMainArr = array("birth_certificate","proof_of_billing","barangay_clearance","photocopy_of_two","photocopy_spouse_id","four_photo","mdf","esav","msvs","tinno","postdated_checks","twenty_four_checks","signed_loan_documents","attended_homeowners_orientation_and_signed_deed_of_restriction");	  
}else if($type=='coborrower'){
	$completeMainArr = array("birth_certificate","proof_of_billing","barangay_clearance","photocopy_of_two","photocopy_spouse_id","four_photo","mdf","esav","msvs","tinno");	 
}
	 

	//COMPLETE ADDITIONAL
if($type=='primary'){ 	
	if($empType=="LOCALLY EMPLOYED"){ //LOCALLY EMPLOYED
		$completeAdditionalArr = array("notarized_certificate","latest_pay_slip","income_tax_return"); 

	}else if($empType=="OFW"){ //OFW 
		$completeAdditionalArr = array("employment_contract","salary_certificate","certificate_of_employment","certificate_of_overseas","owwa_membership_certificate","resident_card","photocopy_passport","notarized_spa","photocopy_valid_id_spa");     

	}else if($empType=="SELF-EMPLOYED / OWNED BUSINESS"){ //SELF-EMPLOYED
		$completeAdditionalArr = array("income_tax_return_audited_fs","certificate_of_commission","commission_vouchers","photocopy_bank_statement","dti_registration","mayors_permit","lease_contract","sketch_business_location");   

	}else if($empType=="ONLINE EMPLOYMENT"){ //ONLINE EMPLOYMENT 
		$completeAdditionalArr = array("bank_statement","remittances","certificate_of_employment","picture_of_work_station","sketch_map_home_address","google_map");     
  
	}else if($empType=="IMMIGRANT"){ //IMMIGRANT 
		$completeAdditionalArr = array("employment_contract","certificate_of_employment","work_permit","immigrant_visa","photocopy_of_passport","duly_notarized_spa","photocopy_valid_id_spa");  
	}else{
		$completeAdditionalArr = array("");
	} 
}else if($type=='coborrower'){
		$completeAdditionalArr = array("");
}	


	$diffArr = array_diff($completeMainArr,$submitArr); 

	$diffArr2 = array_diff($completeAdditionalArr,$submitArr2); 

	
	foreach($diffArr as $key => $val){
		if($val=="birth_certificate"){
			$lack .= " Birth Certificate if Single/Marriage Contract if Married, ";
		}else if($val=="proof_of_billing"){
			$lack .= " Proof of Billing *, ";
		}else if($val=="barangay_clearance"){
			$lack .= " Barangay Clearance *, ";
		}else if($val=="photocopy_of_two"){
			$lack .= " Photocopy of Two (2) Valid ID ( passport, company ID, driver's license, PRC ID, SSS, TIN, etc ) back-to-back; signed 3 times, ";
		}else if($val=="photocopy_spouse_id"){
			$lack .= " Photocopy of valid ID of Spouse (if married); back-to-back; signed 3 times, ";
		}else if($val=="four_photo"){
			$lack .= " Four (4) pcs size 1 x 1 ID photo *, ";
		}else if($val=="mdf"){
			$lack .= " Member's Data Form, ";
		}else if($val=="esav"){
			$lack .= " Employee Statement of Accumulated Value (ESAV) from Pag-ibig, ";
		}else if($val=="msvs"){
			$lack .= " MSVS (Membership Status Verification Slip) signed by borrower *, ";
		}else if($val=="tinno"){
			$lack .= " Tax Identification Number (TIN), ";
		}else if($val=="twenty_four_checks"){
			$lack .= " Twenty four (24) Blank Checks for HDMF Amortization *";
		}else if($val=="postdated_checks"){
			$lack .= " Postdated Checks for Equity *, ";
		}else if($val=="signed_loan_documents"){
			$lack .= " Signed Loan Documents, ";
		}else if($val=="attended_homeowners_orientation_and_signed_deed_of_restriction"){
			$lack .= " Attended Homeowner's Orientation and signed Deed of Restriction, ";
		}

	}

	
	
	
	//ADDITIONAL
	 
	if($empType=="LOCALLY EMPLOYED"){ //LOCALLY EMPLOYED 
		foreach($diffArr2 as $key2 => $val2){
			if($val2=="notarized_certificate"){
				$lack2 .= "  Duly Notarized Latest Certificate of Employment and Compensation *,";
			}else if($val2=="latest_pay_slip"){
				$lack2 .= "  Latest One Month Pay Slip *,";
			}else if($val2=="income_tax_return"){
				$lack2 .= "  Income Tax Return / BIR 2316,";
			} 
		} 
	}else if($empType=="OFW"){ //OFW 
		 foreach($diffArr2 as $key2 => $val2){
			if($val2=="employment_contract"){
				$lack2 .= " Employment Contract,";
			}else if($val2=="salary_certificate"){
				$lack2 .= " Payslip / Salary Certificate,";
			}else if($val2=="certificate_of_employment"){
				$lack2 .= " Certificate of Employment & Compensation,";
			}else if($val2=="certificate_of_overseas"){
				$lack2 .= " Overseas Employment Certificate from POEA,";
			}else if($val2=="owwa_membership_certificate"){
				$lack2 .= " Valid OWWA Membership Certificate,";
			}else if($val2=="resident_card"){
				$lack2 .= " Resident Card / Permit,";
			}else if($val2=="photocopy_passport"){
				$lack2 .= " Photocopy of Passport with appropriate visa, signed 3 times,";
			}else if($val2=="notarized_spa"){
				$lack2 .= " Duly Notarized SPA* / Red Ribbon SPA (if abroad)*,";
			}else if($val2=="photocopy_valid_id_spa"){
				$lack2 .= " Photocopy of Valid ID of SPA, back to back, signed 3 times,";
			} 
		}
	}else if($empType=="SELF-EMPLOYED / OWNED BUSINESS"){ //SELF-EMPLOYED
		 foreach($diffArr2 as $key2 => $val2){
			if($val2=="income_tax_return_audited_fs"){
				$lack2 .= " CTC of Income Tax Return* & Audited Financial Statements with Official Receipt of Tax Payment,";
			}else if($val2=="certificate_of_commission"){
				$lack2 .= " Certificate of Commission* / Certificate of Engagement* / CTC of Transport Franchise,";
			}else if($val2=="commission_vouchers"){
				$lack2 .= " 12 months Commission Vouchers,";
			}else if($val2=="photocopy_bank_statement"){
				$lack2 .= " 12 months Bank Statements* / Photocopy of Passbook,";
			}else if($val2=="dti_registration"){
				$lack2 .= " DTI Registration,";
			}else if($val2=="mayors_permit"){
				$lack2 .= " Mayor's Permit,";
			}else if($val2=="lease_contract"){
				$lack2 .= " Notarized Lease Contract / Proof of Ownership or Rights,";
			}else if($val2=="sketch_business_location"){
				$lack2 .= " Sketch of Business Location,";
			}  
		}
	}else if($empType=="ONLINE EMPLOYMENT"){ //ONLINE EMPLOYMENT
		 foreach($diffArr2 as $key2 => $val2){
			if($val2=="bank_statement"){
				$lack2 .= " 12 month Bank Statement*,";
			}else if($val2=="remittances"){
				$lack2 .= " Latest one (1) year remittances,";
			}else if($val2=="certificate_of_employment"){
				$lack2 .= " Certificate of Employment & Compensation,";
			}else if($val2=="picture_of_work_station"){
				$lack2 .= " Picture of Work Station,";
			}else if($val2=="sketch_map_home_address"){
				$lack2 .= " Sketch Map of Employee's Home Address*,";
			}else if($val2=="google_map"){
				$lack2 .= " Google Map of Employer's Business Location,";
			}  
		}
	}else if($empType=="IMMIGRANT"){ //IMMIGRANT
		foreach($diffArr2 as $key2 => $val2){
			if($val2=="employment_contract"){
				$lack2 .= " Employment Contract,";
			}else if($val2=="certificate_of_employment"){
				$lack2 .= " Certificate of Employment & Compensation,";
			}else if($val2=="work_permit"){
				$lack2 .= " Work Permit / Card,";
			}else if($val2=="immigrant_visa"){
				$lack2 .= " Immigrant Visa / Permanent Resident Card,";
			}else if($val2=="photocopy_of_passport"){
				$lack2 .= " Photocopy of Passport signed 3 times,";
			}else if($val2=="duly_notarized_spa"){
				$lack2 .= " Duly Notarized SPA* / Red Ribbon SPA (if abroad)*,";
			}else if($val2=="photocopy_valid_id_spa"){
				$lack2 .= " Photocopy of Valid ID of SPA, back to back, signed 3 times,";
			}   
		}
	}
	 
	 
	 
	$lacks = $lack . $lack2;
	  
	$output	=	 trim(wordwrap($lacks,180,"<br>\n"), ","); 
	return $output;
} 

 
exit();
ob_end_flush();
