
function resetError() {
	$("div.reportArea input[type='text'], div.reportArea input[type='month'], div.reportArea select").removeClass("highlight");
	$("div.reportArea label.error").css("display", "none");

}
function simplifyFinReport() {
	$("#txtVendor").keyup(function() {
		$("div.suggest").css("display", "none");
		var txtVendor = $("#txtVendor").val();
		if(txtVendor!="") {
			$("div.suggest.two").css("display", "table-row");
			$.post("./includes/report.php?action=searchRec&dest=pickVendor4Rpt",{ vendorName:txtVendor}, function(data) {
				$("div.suggest.two").html(data);
			});
		} else { $("div.suggest.two").css("display", "none"); }
		clearErrors();
	});

	$("#txtClient").keyup(function() {
		$("div.suggest").css("display", "none");
		var txtClient = $("#txtClient").val();
		if(txtClient.length > 0) {
			$("div.suggest.one").css("display", "table-row");
			$.post("./includes/report.php?action=searchRec&dest=pickClient4Rpt",{ passedValue:txtClient, myRole:myRole, myWhouse:myWhouse }, function(data) {
				$("div.suggest.one").html(data);
			});
		} else { $("div.suggest.one").css("display", "none"); }
		clearErrors();
	});


	$("input[type='radio']").on('change', () => {
		resetError();
		$("div.rprtType").find("input[type='radio']").attr("checked", false);
		$(this).parents("div.rprtType").find("input[type='radio']").attr("checked", true);
		$("div.filter").css("display", "none");
		$("#downloadExcel").css("display", "none");


		var rptType = $("input[name='reportType']:checked").val();
		if(rptType=="clientActvty" || rptType=="clientReserv" || rptType=="clientReceipt") {
			$("div.filter").css("display", "none");
			$("div.filter.byClientActvty").css("display", "inline");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="payments") {
			$("div.filter").css("display", "none");
			$("div.filter.byExpense").css("display", "inline");
			$("div.filter.byBankDetails").css("display", "inline");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="cshTrnsfr") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="clientList") {
			$("div.filter").css("display", "none");
			$("div.filter.byWhouse").css("display", "inline");

		} else if(rptType=="reservationRpt") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");

		} else if (rptType=="receiptRpt") {
		    $("div.filter.byBankDetails").css("display", "inline");
		    $("div.filter.byDate").css("display", "inline");


		} else if(rptType=="hotelIncomeRpt") {
			$("div.filter").css("display", "none");
			$("div.filter.byIncStatment").css("display", "inline");

		} else if(rptType=="vndActvty") {
		 	$("div.filter").css("display", "none");
			$("div.filter.byVndActvty").css("display", "inline");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="supplyListing") {
			$("div.filter").css("display", "none");
			$("#downloadExcel").css("display", "inline");
			$("div.filter.byWhouse").css("display", "inline");

		} else if(rptType=="supplyPrchse") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="supplyUsage") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");

		} else if(rptType=="vendorList") {
			$("div.filter").css("display", "none");

		} else if(rptType=="serviceIncome") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");
			$("div.filter.byService4Report").css("display", "inline");
		} else if(rptType=="userLogs") {
			$("div.filter").css("display", "none");
			$("div.filter.byDate").css("display", "inline");
			$("div.filter.byUser4Logs").css("display", "inline");
			$("div.filter.byLogCategory").css("display", "inline");
			$("div.filter.byLogAction").css("display", "inline");
		}
	})

	// for income-statment filter types
	$("#monthTick, #chkIncome4mnth").click(function() {
		document.getElementById("chkIncome4mnth").checked = true;
		document.getElementById("txtIncMonth").disabled = false;
		document.getElementById("slcIncYear").disabled = true;
		$("select#slcIncYear option:first").attr("selected", "selected");
	});
	$("#yearTick, #chkIncome4yr").click(function() {
		document.getElementById("chkIncome4yr").checked = true;
		document.getElementById("slcIncYear").disabled = false;
		document.getElementById("txtIncMonth").disabled = true;
		$("input#txtIncMonth").val('');
		resetError();
	});
}

$("#downloadExcel").on("click",function(){
		var rptType 		= $("[name='reportType']:checked").val();
		var myWhouse  = $("#slcWhouse").val();
		var slcStorageArea = $("#slcWhouse").val();
		
		if (rptType=="supplyListing") {
			window.open(`../libraries/PhpExcel/supplyListing.php?report=supplyListing&myWhouse=${myWhouse}&slcStorageArea=${slcStorageArea}`, '_blank' ).focus();
			return false;
		}
	})

function catchClient4Rpt(clientID, clientName) {
	$("#clientID").val(clientID);
	$("#txtClient").val(clientName);
	$("div.suggest").css("display", "none");
}
function catchWaiter4Rpt(userID, username) {
	$("#txtWaiter").val(username);
	$("div.suggest.waiter").css("display", "none");
}
function catchCashier4Rpt(userID, username) {
	$("#txtCashier").val(username);
	$("div.suggest.cashier").css("display", "none");
}
function catchCustomer4Rpt(clientID, clientName) {
	$("#clientID").val(clientID);
	$("#txtClients").val(clientName);
	$("div.suggest.customer").css("display", "none");
}
function catchBuilder4Rpt(builderID, builderName) {
	$("#builderID").val(builderID);
	$("#txtBuilder").val(builderName);
	$("div.suggest.builder").css("display", "none");
}
function check_reportReservParam() {
	resetError();
	var rptType 		= $("[name='reportType']:checked").val();
	var txtClient		= $("#txtClient").val();
	var clientID		= $("#clientID").val();
	var txtIncMonth		= $("#txtIncMonth").val();

	//
	var startDate		= $("#startDate").val();
	var endDate			= $("#endDate").val();

	if(rptType == "dailyRpt" || rptType == "reservationRpt" || rptType == "receiptRpt" || rptType == "payments" || rptType == "cshTrnsfr" || rptType == "supplyPrchse" || rptType == "supplyUsage" || rptType == "vndActvty" || rptType == "serviceIncome") {
		if(startDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select starting date");
			$("input#startDate").addClass("highlight");
			return false;
		} else { resetError(); }

		if(endDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select ending date");
			$("input#endDate").addClass("highlight");
			return false;
		} else { resetError(); }

	}

	if(rptType == "clientActvty" || rptType == "clientReserv" || rptType == "clientReceipt") {
		if(txtClient.length<1 || clientID=="") {
			$("#error1").css("display", "inline");
			$("#error1").html("Please select customer");
			$("input#txtClient").css("border-color", "#FF0000");
			return false;
		} else { resetError(); }
		if(startDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select starting date");
			$("input#startDate").addClass("highlight");
			return false;
		} else { resetError(); }

		if(endDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select ending date");
			$("input#endDate").addClass("highlight");
			return false;
		} else { resetError(); }

	}
	if(rptType=="hotelIncomeRpt") {
		if(txtIncMonth.length<1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Please select month");
			$("input#txtIncMonth").css("border-color", "#FF0000");
			return false;
		} else { resetError(); }

		window.open('../prints/print.php?report=hotelIncomeRpt&month='+txtIncMonth, '_blank').focus();
		return false;
	}
	if(rptType=="userLogs") {
		let slcUser4Logs 	= $('#slcUser4Logs').val();
		let slcCategory 	= $('#slcCategory').val();
		let slcAction 		= $('#slcAction').val();
		if(startDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select starting date");
			$("input#startDate").addClass("highlight");
			return false;
		} else { resetError(); }

		if(endDate.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select ending date");
			$("input#endDate").addClass("highlight");
			return false;
		} else { resetError(); }

		if(!slcUser4Logs) {
			$("#error1").css("display", "inline");
			$("#error1").html("Select user Please.");
			$("#slcUser4Logs").addClass("highlight");
			return false;
		} else { resetError(); }

		window.open(`../prints/print.php?report=userLogs&slcUser4Logs=${slcUser4Logs}&startDate=${startDate}&endDate=${endDate}&slcCategory=${slcCategory}&slcAction=${slcAction}`, '_blank' ).focus();
		return false;
	}
	$("label#process").css("display", "inline");
	$("#btnDisplay").attr("disabled", true);
	$("#btnDisplay").html("Wait...");
	return true;
}